-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalio.F
1951 lines (1777 loc) · 74.1 KB
/
globalio.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------
! Global IO module.
!
! This module exists to write out global output files on
! parallel machines and one file on uniproc machines.
!--------------------------------------------------------------
module global_io
use SIZES
use VERSION
use GLOBAL
use MESH, ONLY : NP, AGRID
#ifdef CMPI
#ifdef HAVE_MPI_MOD
use mpi
#endif
#endif
contains
C--------------------------------------------------------------------
C S U B R O U T I N E
C A L L O C A T E F U L L D O M A I N I O A R R A Y S
C--------------------------------------------------------------------
C jgf49.44: Allocates memory for the full domain arrays for i/o
C purposes; these arrays are both read from and written to hotstart
C files. Arrays that are only written are allocated in the
C subroutine that does the writing.
C
C jgf51.46: Just to clarify, these arrays are needed during
C hotstart initialization, to read in the previous state of the
C fulldomain simulation.a So, they need to be allocated prior
C to hotstart initialization. These arrays may also be needed
C to write fulldomain output, but care should be taken so they
C are not allocated more than once, i.e., in write_output.F
C or global.F.
C
C--------------------------------------------------------------------
SUBROUTINE allocateFullDomainIOArrays()
IMPLICIT NONE
C
call setMessageSource("allocateFullDomainIOArrays")
#if defined(GLOBAL_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
ALLOCATE(labels_g(NP_G))
ALLOCATE(ETA1_g(NP_G))
ALLOCATE(ETA2_g(NP_G))
ALLOCATE(UU2_g(NP_G))
ALLOCATE(VV2_g(NP_G))
IF (IM.eq.10) THEN
ALLOCATE(CH1_g(NP_G))
ENDIF
ALLOCATE(EtaDisc_g(NP_G))
ALLOCATE(NodeCode_g(NP_G))
ALLOCATE(NOFF_g(NE_G))
ALLOCATE(NNodeCode_g(NP_G))
C
#if defined(GLOBAL_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
C--------------------------------------------------------------------
END SUBROUTINE allocateFullDomainIOArrays
C--------------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E
! C O L L E C T F U L L D O M A I N A R R A Y
!--------------------------------------------------------------
! jgf48.03 Collects array data from each subdomain.
!--------------------------------------------------------------
subroutine collectFullDomainArray(descript, pack_cmd, unpack_cmd)
USE SIZES
USE GLOBAL
implicit none
#ifdef CMPI
#ifndef HAVE_MPI_MOD
include 'mpif.h'
#endif
#endif
type (OutputDataDescript_t) :: descript
external pack_cmd
external unpack_cmd
#ifdef CMPI
! the subroutine used to write the file
integer :: ierr, status(MPI_STATUS_SIZE), request
integer, save:: tagbase = 6000
integer :: iproc
integer :: bufsize
integer :: ibucket
integer :: iremainder ! after dividing bufsize by array rank
integer :: istart ! vector tuple to start with
integer :: iend ! vector tuple to end on
integer :: tag
! number of vector tuples in the buffer
integer :: num
integer :: i, j, k
C
call setMessageSource("collectFullDomainArray")
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
bufsize = min(BUFSIZE_MAX,
& descript % num_items_per_record * descript % num_fd_records)
C num will be less than the number of full domain records if the
C buffer is too small to hold all the records in the full domain,
C in this case it is the number of records passed back to proc 0
C on each iteration of the while loop below
!
! jgf51.50: What if the bufsize is not evenly divisible by the
! number of items per record? Need to check the remainder.
iremainder = modulo(bufsize, descript % num_items_per_record)
num = ( bufsize - iremainder ) / descript % num_items_per_record
iend = num
istart = 1
if (tagbase == 5000) then
tagbase = 6000
else
tagbase = 5000
endif
ibucket = 0
do while (istart.le.iend)
!------------------------------------------------------------
! Initialize
!------------------------------------------------------------
if ( descript % isInteger .eqv. .true. ) then
integerBuffer(:) = int(descript % initial_value)
else
buf(:) = descript % initial_value
endif
ibucket = ibucket + 1
tag = tagbase + mod(ibucket, 8)
C now pack the buffer
call pack_cmd(descript, istart, iend)
C now send data to processor 0
if ( descript % isInteger .eqv. .true. ) then
call mpi_reduce(integerBuffer, integerResultBuffer, bufsize,
& MPI_INTEGER, MPI_SUM, 0, COMM, ierr)
else
call mpi_reduce(buf, resultBuf, bufsize, float_type, MPI_SUM,
& 0, COMM, ierr)
endif
if (myproc == 0) then
call unpack_cmd(descript, istart, iend)
end if
C set new starting position to just after the
C current ending position in full domain array
istart = iend + 1
C set new ending position to either the current start plus the
C number of records that will fit in the buffer (minus 1),
C or to the end of the full domain array, whichever is less
iend = min(istart + num - 1, descript % num_fd_records)
num = iend - istart + 1
end do
#endif
C! CMPI
1000 format(2x, i8, 2x, 1pE20.10E3, 1pE20.10E3, 1pE20.10E3, 1pE20.10E3)
1100 FORMAT(2x,1pE20.10E3,5X,I10)
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
!--------------------------------------------------------------
end subroutine collectFullDomainArray
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E P A C K O N E
!--------------------------------------------------------------
! jgf48.03 Subroutine to store a single array of real numbers
! to a buffer
!--------------------------------------------------------------
subroutine packOne(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, j, istart, iend, iglobal
integer :: ioffset
call setMessageSource("packOne")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
! jgf51.21.24: Updated and generalized to take into account wet/dry
! if needed
#ifdef CMPI
ioffset = istart - 1
if ( descript % isInteger .eqv. .true. ) then
do i = 1, descript % num_records_this
iglobal = descript % imap(i)
if (istart <= iglobal .and. iglobal <= iend) then
integerBuffer(iglobal-ioffset) = descript % iarray(i)
end if
end do
else
do i = 1, descript % num_records_this
iglobal = descript % imap(i)
if (istart <= iglobal .and. iglobal <= iend) then
buf(iglobal - ioffset ) = descript % array(i)
! jgf51.21.24: Updated and generalized to take into account wet/dry
! jgf52.25: Station data that should take wet dry state
! into account have already done so in subroutine stationArrayInterp()
! in module write_output.F. For stations, it doesn't make
! sense to check the nodecode.
if ( descript % considerWetDry.eqv..true. ) then
if ( descript % isStation.eqv..false. ) then
if ( nodecode(i).eq.0 ) then
buf(iglobal-ioffset) = descript % alternate_value
endif
endif
endif
endif
end do
endif
#endif
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine packOne
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E U N P A C K O N E
!--------------------------------------------------------------
! Subroutine to retrieve a single array of real numbers
! from a buffer
!--------------------------------------------------------------
subroutine unpackOne(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, j, istart, iend, iglobal
integer :: ioffset
call setMessageSource("unpackOne")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
j = 1
if ( descript % isInteger .eqv. .true. ) then
do i = istart, iend
descript % iarray_g(i) = integerResultBuffer(j)
j = j + 1
end do
else
do i = istart, iend
descript % array_g(i) = resultBuf(j)
j = j + 1
end do
endif
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
!--------------------------------------------------------------
end subroutine unpackOne
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E P A C K T W O
!--------------------------------------------------------------
! Subroutine to pack two interleaved arrays of real
! numbers into a buffer
!--------------------------------------------------------------
subroutine packTwo(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, istart, iend, iglobal
integer :: ioffset, j
call setMessageSource("packTwo")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
ioffset = istart - 1
do i = 1, descript % num_records_this
iglobal = descript % imap(i)
if (istart <= iglobal .and. iglobal <= iend) then
j = 2*(iglobal - ioffset) - 1
if(descript%considerWetDry.and.nodecode(i).eq.0.and.
& (.not.descript%isStation))then
buf(j) = descript % alternate_value
buf(j + 1) = descript % alternate_value
else
buf(j) = descript % array(i)
buf(j + 1) = descript % array2(i)
endif
end if
end do
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
1000 format(2x, i8, 2x, 1pE20.10E3, 1pE20.10E3)
!--------------------------------------------------------------
end subroutine packTwo
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E U N P A C K T W O
!--------------------------------------------------------------
! Subroutine to unpack two interleaved arrays of real
! numbers into a buffer
!--------------------------------------------------------------
subroutine unpackTwo(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, j, istart, iend
call setMessageSource("unpackTwo")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
j = 1
do i = istart, iend
descript % array_g(i) = resultBuf(j)
descript % array2_g(i) = resultBuf(j+1)
j = j + 2
end do
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine unpackTwo
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E P A C K M B Y N P
!--------------------------------------------------------------
! Subroutine to pack an m x np array of real
! numbers into a buffer
!--------------------------------------------------------------
subroutine packMbyNP(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, istart, iend, iglobal
integer :: ioffset, j
integer :: k ! frequency counter
C
call setMessageSource("packMbyNP")
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
ioffset = istart - 1
do i = 1, descript % num_records_this
iglobal = descript % imap(i)
if (istart <= iglobal .and. iglobal <= iend) then
j = descript%num_items_per_record * (iglobal-ioffset)
& - (descript%num_items_per_record - 1 )
do k = 0, ( descript % num_items_per_record - 1 )
buf(j+k) = descript % array2D(k+1,i)
end do
end if
end do
C
1000 format(2x, i8, 2x, 1pE20.10E3, 1pE20.10E3)
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine packMbyNP
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E U N P A C K M B Y N P
!--------------------------------------------------------------
! Subroutine to unpack an m x np array of real
! numbers out of a buffer
!--------------------------------------------------------------
subroutine unpackMbyNP(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, j, istart, iend
integer k ! frequency counter
call setMessageSource("unpackMbyNP")
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
j = 1
do i = istart, iend
do k = 1, descript % num_items_per_record
descript % array2D_g(k,i) = resultBuf(j)
j = j + 1
end do
end do
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine unpackMbyNP
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E P A C K N P B Y M
!--------------------------------------------------------------
! Subroutine to pack an np x m array of real
! numbers into a buffer
!--------------------------------------------------------------
subroutine packNPbyM(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, istart, iend, iglobal
integer :: ioffset, j
integer :: k ! frequency counter
C
call setMessageSource("packNPbyM")
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
ioffset = istart - 1
do i = 1, descript % num_records_this
iglobal = descript % imap(i)
if (istart <= iglobal .and. iglobal <= iend) then
j = descript%num_items_per_record * (iglobal-ioffset)
& - (descript%num_items_per_record - 1 )
do k = 0, ( descript % num_items_per_record - 1 )
buf(j+k) = descript % array2D(i,k+1)
end do
end if
end do
C
1000 format(2x, i8, 2x, 1pE20.10E3, 1pE20.10E3)
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine packNPbyM
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E U N P A C K N P B Y M
!--------------------------------------------------------------
! Subroutine to unpack an np x m array of real
! numbers out of a buffer
!--------------------------------------------------------------
subroutine unpackNPbyM(descript, istart, iend)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, j, istart, iend
integer k ! frequency counter
call setMessageSource("unpackNPbyM")
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
j = 1
do i = istart, iend
do k = 1, descript % num_items_per_record
descript % array2D_g(i,k) = resultBuf(j)
j = j + 1
end do
end do
#if defined(GLOBALIO_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine unpackNPbyM
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E O P E N _ G B L _ F I L E
!--------------------------------------------------------------
! Open Global File: opens the file, opens the write_header
! routine and closes the file
!--------------------------------------------------------------
subroutine open_gbl_file(lun, filename, size_g, size_this,
& write_header)
USE SIZES
USE GLOBAL
implicit none
external write_header ! subroutine used to actually write the header
integer :: lun, size_this, size_g, szz
character(*) :: filename
call setMessageSource("open_gbl_file")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
szz = size_g
if (mnproc == 1 .or. WRITE_LOCAL_FILES) szz = size_this
if (myproc == 0 .or. WRITE_LOCAL_FILES) then
open(lun, file=trim(filename), status='UNKNOWN')
call write_header(lun,szz)
close(lun)
end if
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine open_gbl_file
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E O P E N _ M I N M A X _ F I L E
!--------------------------------------------------------------
! Open Global File: opens the file, replacing the existing file,
! executes the write_header routine and closes
! the file.
!--------------------------------------------------------------
subroutine open_minmax_file(lun, filename, size_g, size_this,
& nrecs_this,write_header)
USE SIZES
USE GLOBAL
implicit none
external write_header ! subroutine used to actually write the header
integer :: lun, size_this, size_g, szz
integer :: nrecs_this !tcm v51.20.06
character(*) :: filename
call setMessageSource("open_minmax_file")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
szz = size_g
if (mnproc == 1 .or. WRITE_LOCAL_FILES) szz = size_this
if (myproc == 0 .or. WRITE_LOCAL_FILES) then
open(lun, file=trim(filename), status='REPLACE')
call write_header(lun,szz,nrecs_this)
close(lun)
end if
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
!--------------------------------------------------------------
end subroutine open_minmax_file
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E W R I T E F U L L F O R M A T
!--------------------------------------------------------------
! Subroutine to write full format ASCII output files
!--------------------------------------------------------------
subroutine writeFullFormat(descript, TimeLoc, it, write_cmd)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
real(8), intent(in) :: TimeLoc
integer, intent(in) :: it
external write_cmd
#ifdef CMPI
#ifndef HAVE_MPI_MOD
include 'mpif.h'
#endif
integer :: ierr, status(MPI_STATUS_SIZE), request
integer :: nGWetNodes
integer :: iglobal
#endif
integer :: nLWetNodes
integer :: num, i, j, k
integer, save:: tagbase = 6000
integer :: iproc
integer :: bufsize, ibucket
integer :: istart, iend, tag
call setMessageSource("writeFullFormat")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
! serial or writing local files
if ((mnproc.eq.1).or.(WRITE_LOCAL_FILES)) then
open(descript%lun, file=trim(descript%file_name),
& access='SEQUENTIAL', position='APPEND')
write(descript%lun, 1101) TimeLoc, it
call write_cmd(descript % lun, descript, 1, descript % num_records_this)
close(descript % lun)
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
else
#ifdef CMPI
if (myproc == 0) then
open(descript%lun, file=trim(descript%file_name),
& access='SEQUENTIAL', position='APPEND')
write(descript%lun, 1101) TimeLoc, it
endif
bufsize = min(BUFSIZE_MAX,
& descript % num_items_per_record * descript % num_fd_records)
num = bufsize / descript % num_items_per_record
iend = num
istart = 1
if (tagbase == 5000) then
tagbase = 6000
else
tagbase = 5000
endif
ibucket = 0
do while (istart < iend)
!------------------------------------------------------------
! Initialize
!------------------------------------------------------------
buf(:) = descript % initial_value
ibucket = ibucket + 1
tag = tagbase + mod(ibucket, 8)
call write_cmd(descript%lun, descript, istart, iend)
if(descript%isInteger)then
call mpi_reduce(integerbuffer, integerresultBuffer, bufsize, mpi_int, MPI_SUM, 0,
& COMM, ierr)
else
call mpi_reduce(buf, resultBuf, bufsize, float_type, MPI_SUM, 0,
& COMM, ierr)
endif
if (myproc == 0) then
do i = istart, iend
j = 1 + (i-istart)*descript % num_items_per_record
if(descript%isInteger)then
write(descript % lun, 1001) labels_g(i), (integerResultBuffer(k), k = j, j +
& descript % num_items_per_record - 1)
else
write(descript % lun, 1000) labels_g(i), (resultBuf(k), k = j, j +
& descript % num_items_per_record - 1)
endif
end do
end if
istart = iend + 1
iend = min(istart + num - 1, descript % num_fd_records)
num = iend - istart + 1
end do
if (myproc == 0) then
close(descript%lun)
endif
#endif
endif
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
1000 FORMAT(2x, i8, 2x, 1pE20.10E3, 1pE20.10E3, 1pE20.10E3, 1pE20.10E3)
1001 FORMAT(2x, i8, 2x, i8, 2X, i8, 2X, i8, 2X, i8)
1100 FORMAT(2x,1pE20.10E3,5X,I10)
1101 FORMAT(2x,1pE20.10E3,5X,I10,5X,I10,5X,1pE20.10E3)
!--------------------------------------------------------------
end subroutine writeFullFormat
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E W R I T E B I N A R Y F O R M A T
!--------------------------------------------------------------
! Subroutine to write binary format output files
!--------------------------------------------------------------
subroutine writeBinaryFormat(descript,timeloc,it)
use global
use sizes
implicit none
type(outputdatadescript_t),intent(in) :: descript
integer,intent(in) :: it
real(sz) :: timeloc
integer :: i
IF ( (MNPROC.gt.1).and.(MyProc.eq.0)
& .and.(.not.WRITE_LOCAL_FILES)) THEN
OPEN(descript%lun,FILE=trim(descript%file_name),
& ACCESS='DIRECT',RECL=NBYTE)
WRITE(descript % lun,REC=descript % filepos+1) TimeLoc
WRITE(descript % lun,REC=descript % filepos+2) IT
descript%filepos = descript%filepos + 2
IF ( descript % num_items_per_record .eq. 1 ) THEN
DO I=1, descript % num_fd_records
WRITE(descript % lun,REC=descript % filepos+I)
& descript % array_g(I)
END DO
ENDIF
IF ( descript % num_items_per_record .eq. 2 ) THEN
DO I=1, descript % num_fd_records
WRITE(descript % lun,REC=descript % filepos+2*I-1)
& descript % array_g(I)
WRITE(descript % lun,REC=descript % filepos+2*I)
& descript % array2_g(I)
END DO
ENDIF
CLOSE(descript%lun)
ENDIF
IF ((MNPROC.eq.1).or.(WRITE_LOCAL_FILES)) THEN
OPEN(descript % lun,FILE=TRIM(descript % file_name),
& ACCESS='DIRECT',RECL=NBYTE)
WRITE(descript % lun,REC=descript % filepos+1) TimeLoc
WRITE(descript % lun,REC=descript % filepos+2) IT
descript % filepos = descript % filepos + 2
IF ( descript % num_items_per_record .eq. 1 ) THEN
IF ((trim(descript % field_name) .eq. 'Elev').and.
& (descript % ConsiderWetDry .EQV. .TRUE.)) THEN
DO I=1, descript % num_records_this
if(NODECODE(I).EQ.1) THEN
WRITE(descript % lun,REC=descript % filepos+I) descript % array(I)
ELSE
WRITE(descript % lun,REC=descript % filepos+I)
& descript % alternate_value !-99999.0 for dry nodes
ENDIF
END DO
ELSE
DO I=1, descript % num_records_this
WRITE(descript % lun,REC=descript % filepos+I) descript % array(I)
END DO
ENDIF
ENDIF
IF ( descript % num_items_per_record .eq. 2 ) THEN
DO I=1, descript % num_records_this
!tcmv48.4618 -- changed from array_g to array
WRITE(descript % lun,REC=descript % filepos+2*I-1) descript % array(I)
!tcmv48.4618 -- changed from array2_g to array2
WRITE(descript % lun,REC=descript % filepos+2*I) descript % array2(I)
END DO
ENDIF
CLOSE(descript % lun)
ENDIF
descript % filepos = descript % filepos + descript % num_records_this
return
!--------------------------------------------------------------
end subroutine writeBinaryFormat
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E W R I T E S P A R S E
!--------------------------------------------------------------
! jgf51.21.24: Writes sparse ascii format.
!--------------------------------------------------------------
subroutine writeSparse(descript, TimeLoc, it, write_cmd)
USE SIZES
USE GLOBAL
implicit none
type (OutputDataDescript_t) :: descript
real(8), intent(in) :: TimeLoc
integer, intent(in) :: it
external write_cmd
#ifdef CMPI
#ifndef HAVE_MPI_MOD
include 'mpif.h'
#endif
integer :: ierr, status(MPI_STATUS_SIZE), request
integer :: nGWetNodes
integer :: iglobal
#endif
integer :: nLWetNodes
integer :: num, i, j, k
integer, save:: tagbase = 6000
integer :: iproc
integer :: bufsize, ibucket
integer :: istart, iend, tag
call setMessageSource("writeSparse")
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Enter")
#endif
! serial or writing local files
if ((mnproc.eq.1).or.(WRITE_LOCAL_FILES)) then
open(descript%lun, file=trim(descript%file_name),
& access='SEQUENTIAL', position='APPEND')
nLWetNodes=0
do i=1,np
if(descript%considerWetDry)then
if(nodecode(i) == 0)cycle
nLWetNodes=nLWetNodes+1
else
if(descript%num_items_per_record==1)then
if(descript%isInteger)then
if(descript%iarray(i)==int(descript%alternate_value))cycle
else
if(descript%array(i)==descript%alternate_value)cycle
endif
elseif(descript%num_items_per_record==2)then
if(descript%array(i)==descript%alternate_value .and.
& descript%array2(i)==descript%alternate_value)cycle
endif
nLWetNodes=nLWetNodes+1
endif
enddo
write(descript%lun, 1101) TimeLoc, it, nLWetNodes, descript%alternate_value
call write_cmd(descript % lun, descript, 1, descript % num_records_this)
close(descript % lun)
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
return
else
#ifdef CMPI
! Count the number of wet nodes
nLWetNodes = 0
do i=1,np
iglobal = descript%imap(i)
if(iglobal.le.0) cycle ! cycle if node i is ghost
if(descript%considerWetDry)then
if(nodecode(i) == 0) cycle ! cycle if node i is dry
else
if(descript%num_items_per_record==1)then
if(descript%isInteger)then
if(descript%iarray(i)==int(descript%alternate_value))cycle
else
if(descript%array(i)==descript%alternate_value)cycle
endif
elseif(descript%num_items_per_record==2)then
if(descript%array(i)==descript%alternate_value .AND.
& descript%array2(i)==descript%alternate_value)cycle
endif
endif
nLWetNodes=nLWetNodes+1
enddo
call mpi_reduce(nLWetNodes, nGWetNodes, 1, MPI_INTEGER,
& MPI_SUM, 0, comm, ierr)
if (myproc == 0) then
open(descript%lun, file=trim(descript%file_name),
& access='SEQUENTIAL', position='APPEND')
write(descript%lun, 1101) TimeLoc, it, nGWetNodes, descript%alternate_value
endif
bufsize = min(BUFSIZE_MAX,
& descript % num_items_per_record * descript % num_fd_records)
num = bufsize / descript % num_items_per_record
iend = num
istart = 1
if (tagbase == 5000) then
tagbase = 6000
else
tagbase = 5000
endif
ibucket = 0
do while (istart < iend)
!------------------------------------------------------------
! Initialize
!------------------------------------------------------------
buf(:) = descript % initial_value
ibucket = ibucket + 1
tag = tagbase + mod(ibucket, 8)
call write_cmd(descript%lun, descript, istart, iend)
call mpi_reduce(buf, resultBuf, bufsize, float_type, MPI_SUM, 0,
& COMM, ierr)
if (myproc == 0) then
do i = istart, iend
j = 1 + (i-istart)*descript % num_items_per_record
!If values are eqaul to the default value, skip this node
if(descript%num_items_per_record.eq.2)then
if(resultBuf(j ).eq.descript % alternate_value .and.
& resultBuf(j+1).eq.descript % alternate_value) cycle
else
if(resultBuf(j).eq.descript % alternate_value) cycle
endif
write(descript % lun, 1000) labels_g(i), (resultBuf(k), k = j, j +
& descript % num_items_per_record - 1)
end do
end if
istart = iend + 1
iend = min(istart + num - 1, descript % num_fd_records)
num = iend - istart + 1
end do
if (myproc == 0) then
close(descript%lun)
endif
#endif
endif
#ifdef GLOBALIO_TRACE
call allMessage(DEBUG,"Return")
#endif
call unsetMessageSource()
1000 format(2x, i8, 2x, 1pE20.10E3, 1pE20.10E3, 1pE20.10E3, 1pE20.10E3)
1100 FORMAT(2x,1pE20.10E3,5X,I10)
1101 FORMAT(2x,1pE20.10E3,5X,I10,5X,I10,5X,1pE20.10E3)
!--------------------------------------------------------------
end subroutine writeSparse
!--------------------------------------------------------------
!--------------------------------------------------------------
! S U B R O U T I N E S T O R E O N E
!--------------------------------------------------------------
! jgf47.05: Subroutine to store a single array of real numbers
! +to disk in text format if WRITE_LOCAL_FILES is .true.
! +to a buffer if we are running in parallel
!--------------------------------------------------------------
subroutine storeOne(lun, descript, istart, iend)
USE SIZES
USE GLOBAL
USE MESH,ONLY:labels
implicit none
type (OutputDataDescript_t) :: descript
integer :: i, istart, iend, iglobal, lun
integer :: ioffset
if (mnproc.eq.1.or.WRITE_LOCAL_FILES) then
do i = 1, descript % num_records_this
if(ABS(descript % specifier)==SPARSE_ASCII)then
if(descript%considerWetDry)then
if(nodecode(i)==0)cycle
if(descript%isInteger)then
write(lun , 1001) labels(i), descript % iarray(i)
else
write(lun , 1000) labels(i), descript % array(i)
endif
else
if(descript%isInteger)then
if(descript%iarray(i)==int(descript%alternate_value))cycle
write(lun , 1001) labels(i), descript % iarray(i)
else