forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_pipe.F90
1553 lines (1546 loc) · 54.7 KB
/
mod_pipe.F90
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
module mod_pipe
use mod_xc ! HYCOM communication interface
!
! --- HYCOM (named pipe based) debugging interface
!
logical, save, public :: lpipe
!
integer, save, private :: ipunit,lpunit,ishift,jshift,nsym, &
nstep_start
logical, save, private :: ldebug,ldebugpnt, &
ldebugiso,ldebugsum,ldebugmas, &
ldebugssh, &
lmaster,lpipeio,lshift,lslave, &
lsym,lnan, &
ltracer,ltracernan,ltracermax, &
lpipe_fatal,lpipe_anyfailed, &
lnan_anyfailed
real, save, private :: trcmax(mxtrcr)
!
real, allocatable, dimension(:,:), &
save, private :: field1,field2,tmask,vmask,amask
contains
!
! --- this set of routines facilitates output comparison from two HYCOM
! --- versions running side by side. one model, the 'slave', writes its
! --- output into a named pipe. the other model, the 'master', reads
! --- from the pipe and compares.
! --- differences are recorded in 'PIPE_base.out'.
!
! --- call 'pipe_fatal_on' to exit on differences (this is the default)
! --- call 'pipe_fatal_off' to continue on differences
!
! --- call 'pipe_init' at start of main program.
!
! --- if the file 'PIPE_MASTER' exists then this is the master,
! --- if the file 'PIPE_SLAVE' exists then this is the slave,
! --- if the file 'PIPE_SYM' exists then this is master and slave,
! --- if the file 'PIPE_NAN' exists then this is master and slave,
! --- if the file 'PIPE_TRACER' exists then this is master and slave,
! --- otherwise there is no comparison made.
!
! --- if the file 'PIPE_SHIFT' exists for the slave, then it
! --- is a single-line plain text file containing two integers
! --- specifiying how much to periodically shift the slave arrays
! --- before sending them to the master. it is an error for
! --- 'PIPE_SHIFT' to exist (a) on the master and (b) when not
! --- making a comparison.
!
! --- if the file 'PIPE_SYM' exists, there is no slave and the
! --- master compares its own fields for various symmetries.
! --- it is a single-line plain text file containing an integer
! --- specifiying what kind of symmetries to test for (0=constant,
! --- 1=transpose, 2=constant-in-j, -2=arctic, 4=4-way, 8=8-way).
! --- it is an error for 'PIPE_SYM' to exist when making a
! --- master/slave comparison.
!
! --- if the file 'PIPE_NAN' exists, there is no slave and the
! --- master checks that all appropriate fields are free of
! --- NaNs and Infs.
!
! --- if the file 'PIPE_TRACER' exists, there is no slave and the
! --- master checks that all appropriate tracers are non-negative
! --- and compares temperature to any "temperature" tracer.
!
! --- if the file 'PIPE_DEBUG' exists then debugging printout
! --- is produced for point itest,jtest (>0, see blkdat.f).
! --- if itest=-1 the min/max/iospycnal of th3d are printed.
! --- if jtest=-1 the basin-wide means are printed.
! --- this works with or without a pipe for comparison.
! --- if the file 'PIPE_DEBUG_ISO' exists then min/max/iospycnal of th3d
! --- are printed (alternative to itest=-1 that allows point printout).
! --- if the file 'PIPE_DEBUG_SUM' exists then basin-wide means are
!--- printed (alternative to jtest=-1 that allows point printout).
! --- if the file 'PIPE_DEBUG_MAS' exists then "dp", rather than
!--- the usual "dp'" is used as the vertical coordinate.
!
! --- if the file 'PIPE_DEBUG_SSH' exists then debugging printout
! --- is produced for SSH at point itest,jtest. in addition, SSH
! --- is checked everywhere for NaN and/or Infs.
! --- this works with or without a pipe for comparison.
!
! --- the 'PIPE_MASTER' and 'PIPE_SLAVE' files contain the location
! --- of an existing named-pipe. the 'PIPE_SHIFT' file contains the
! --- periodic shift to apply on the slave. the 'PIPE_SYM' file
! --- contains the kind of symmetries to test for. the contents of
! --- the 'PIPE_DEBUG' and 'PIPE_DEBUG_SSH' files are ignored.
!
! --- call 'pipe_compare' (from master and slave) anywhere in the code
! --- to check whether data stored in a single array are identical
!
! --- call 'pipe_compare_sym1' anywhere in the code to check whether
! --- data stored in a single p-grid array are symmetrical.
! --- note that this can be used in place of 'pipe_compare', since
! --- it will call the latter in master/slave mode.
!
! --- call 'pipe_compare_sym2' anywhere in the code to check whether
! --- data stored in vector u and v grid arrays are symmetrical.
! --- note that this can be used in place of 'pipe_compare', since
! --- it will call the latter twice (for u and v) in master/slave mode.
!
! --- call 'pipe_comparall' (from master and slave) after major routines
! --- to check whether data stored in all major arrays are identical or
! --- symmetric.
!
subroutine pipe_fatal_on
implicit none
lpipe_fatal = .true.
return
end subroutine pipe_fatal_on
!
subroutine pipe_fatal_off
implicit none
lpipe_fatal = .false.
return
end subroutine pipe_fatal_off
!
subroutine pipe_init
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
character*256 cpipe
!
character*12 cinfo
integer irecl
logical ltstep
!
#if defined(OCEANS2)
! --- master and slave in the same mpi executable
lmaster = nocean.eq.1
lslave = nocean.eq.2
!
lshift = .false.
lsym = .false.
lnan = .false.
ltracer = .false.
ltracernan = .false.
ltracermax = .false.
ldebug = .false.
ldebugmas = .false.
ldebugiso = .false.
ldebugsum = .false.
ldebugssh = .false.
#else
inquire(file=trim(flnminp)//'PIPE_MASTER', exist=lmaster)
inquire(file=trim(flnminp)//'PIPE_SLAVE', exist=lslave)
inquire(file=trim(flnminp)//'PIPE_SHIFT', exist=lshift)
inquire(file=trim(flnminp)//'PIPE_SYM', exist=lsym)
inquire(file=trim(flnminp)//'PIPE_NAN', exist=lnan)
inquire(file=trim(flnminp)//'PIPE_TRACER', exist=ltracer)
inquire(file=trim(flnminp)//'PIPE_TRACERNAN', exist=ltracernan)
inquire(file=trim(flnminp)//'PIPE_TRACERMAX', exist=ltracermax)
inquire(file=trim(flnminp)//'PIPE_DEBUG', exist=ldebug)
inquire(file=trim(flnminp)//'PIPE_DEBUG_MAS', exist=ldebugmas)
inquire(file=trim(flnminp)//'PIPE_DEBUG_ISO', exist=ldebugiso)
inquire(file=trim(flnminp)//'PIPE_DEBUG_SUM', exist=ldebugsum)
inquire(file=trim(flnminp)//'PIPE_DEBUG_SSH', exist=ldebugssh)
ldebugpnt = ldebug
if (ldebug) then
if (ittest.eq.-1) then
ldebugiso = .true.
ldebugpnt = .false.
endif
if (jttest.eq.-1) then
ldebugsum = .true.
ldebugpnt = .false.
endif
endif !ldebug
#endif
!
if (lmaster .and. lslave) then
call xchalt('pipe_init: (master/slave ambiguity)')
stop 'pipe_init: (master/slave ambiguity)'
endif
if (lsym .and. (lmaster .or. lslave)) then
call xchalt('pipe_init: (sym/master/slave ambiguity)')
stop 'pipe_init: (sym/master/slave ambiguity)'
endif
if (lnan .and. lsym) then
call xchalt('pipe_init: (nan/sym ambiguity)')
stop 'pipe_init: (nan/sym ambiguity)'
endif
if (lnan .and. (lmaster .or. lslave)) then
call xchalt('pipe_init: (nan/master/slave ambiguity)')
stop 'pipe_init: (nan/master/slave ambiguity)'
endif
lpipe = lmaster .or. lslave .or. lsym .or. lnan .or. ldebug
lpipeio = lmaster .or. lslave
if (lshift .and. .not.lslave) then
call xchalt('pipe_init: (shift ambiguity)')
stop 'pipe_init: (shift ambiguity)'
endif
!
lpipe_fatal = .true. !by default, exit on detecting differences
lpipe_anyfailed = .false. !no differences detected yet
lnan_anyfailed = .false. !no NaN's detected yet
!
if (ltracermax) then
ltracer = .true.
open(unit=uoff+99,file=trim(flnminp)//'PIPE_TRACERMAX') !on all nodes
read(uoff+99,*) trcmax(1:ntracr)
close(unit=uoff+99) !file='PIPE_TRACERMAX'
else
trcmax(1:ntracr) = huge(trcmax(1))
endif
!
if (lpipeio) then
inquire(file=trim(flnminp)//'PIPE_START', exist=ltstep)
if (ltstep) then
open(unit=uoff+99,file=trim(flnminp)//'PIPE_START') !on all nodes
read(uoff+99,*) nstep_start
close(unit=uoff+99) !file='PIPE_START'
else
nstep_start = 0
endif
endif
!
if (lpipe .or. ltracer) then
!
! --- allocate arrays for comparison
!
allocate( field1(itdm,jtdm) )
allocate( field2(itdm,jtdm) )
call mem_stat_add( 2*itdm*jtdm )
if (.not.lslave) then
allocate( tmask( itdm,jtdm) )
call mem_stat_add( itdm*jtdm )
allocate( amask( 1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy) )
call mem_stat_add( (idm+2*nbdy)*(jdm+2*nbdy) )
endif
if (lsym .or. lnan) then
allocate( vmask( itdm,jtdm) )
call mem_stat_add( itdm*jtdm )
endif
endif ! pipe
!
#if defined(OCEANS2)
if (lpipeio) then
!
! --- open some output files
!
lpunit=19
!
if (mnproc.eq.1) then
if (lmaster) then
open (unit=lpunit,file=trim(flnminp)//'PIPE_base.out', &
status='unknown')
else ! slave
open (unit=lpunit,file=trim(flnminp)//'PIPE_test.out', &
status='unknown')
endif ! master/slave
endif !1st tile only.
call xcsync(flush_lp)
endif ! pipeio
#else
if (lpipeio) then
!
! --- open the pipe and some output files
! --- note that named pipe buffers are small, typically 64KB
!
ipunit=18
lpunit=19
!
if (mnproc.eq.1) then
if (lmaster) then
open (unit=17,file=trim(flnminp)//'PIPE_MASTER', &
status='old',form='formatted')
read ( 17,'(a)') cpipe
close(unit=17)
write(lp,'(a,a)') 'master opening pipe for reading: ', &
cpipe(1:len_trim(cpipe))
call flush(lp)
#if defined(ALPHA)
! --- work-around a compiler bug by skipping irecl
open (unit=ipunit,file=cpipe,status='old', &
action='read', &
form='unformatted')
#else
cinfo=' ' !removes spurious compiler warning message
inquire( iolength=irecl ) cinfo,field1(:,1)
open (unit=ipunit,file=cpipe,status='old', &
action='read',recl=irecl, &
form='unformatted')
#endif
open (unit=lpunit,file=trim(flnminp)//'PIPE_base.out', &
status='unknown')
else ! slave
open (unit=17,file=trim(flnminp)//'PIPE_SLAVE', &
status='old',form='formatted')
read ( 17,'(a)') cpipe
close(unit=17)
write(lp,'(a,a)') 'slave opening pipe for writing: ', &
cpipe(1:len_trim(cpipe))
call flush(lp)
#if defined(ALPHA)
! --- work-around a compiler bug by skipping irecl
open (unit=ipunit,file=cpipe,status='old', &
action='write', &
form='unformatted')
#else
cinfo=' ' !removes spurious compiler warning message
inquire( iolength=irecl ) cinfo,field1(:,1)
open (unit=ipunit,file=cpipe,status='old', &
action='write',recl=irecl, &
form='unformatted')
#endif
open (unit=lpunit,file=trim(flnminp)//'PIPE_test.out', &
status='unknown')
!
if (lshift) then
open (unit=17,file=trim(flnminp)//'PIPE_SHIFT', &
status='old',form='formatted')
read ( 17,*) ishift,jshift
close(unit=17)
write(lp,'(a,2i5)') 'slave periodic shift is:', &
ishift,jshift
call flush(lp)
endif ! shift
endif ! master/slave
endif !1st tile only.
call xcsync(flush_lp)
endif ! pipeio
#endif /* OCEANS2:else */
!
if (lsym) then
open (unit=17,file=trim(flnminp)//'PIPE_SYM', &
status='old',form='formatted')
read ( 17,*) nsym
close(unit=17)
if (mnproc.eq.1) then
lpunit=19
open (unit=lpunit,file=trim(flnminp)//'PIPE_base.out', &
status='unknown')
write(lpunit,'(a,i2)') 'symmetry type is:',nsym
write(lp, '(a,i2)') 'symmetry type is:',nsym
call flush(lpunit)
endif
if (nsym.ne. 0 .and. &
nsym.ne. 1 .and. &
nsym.ne. 2 .and. &
nsym.ne.-2 ) then
if (mnproc.eq.1) then
write(lp,'(a)') 'symmetry type is not supported'
endif
call xcstop('(pipe_init)')
stop '(pipe_init)'
endif
call xcsync(flush_lp)
endif ! sym
!
return
end subroutine pipe_init
!
#if defined(OCEANS2)
subroutine pipe_compare(field,mask,what)
use mod_cb_arrays ! HYCOM saved arrays, for nstep
implicit none
!
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: field
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: mask
character*12, &
intent(in) :: what
!
! --- call this routine from anywhere in the code (from both versions, of
! --- course) to check whether data stored in 'field' are identical
! --- master and slave in same executable, uses xcpipe to exchange fields
!
integer i,i1,j,j1
logical fail
character*12 which
real fnan !target for huge
!
if (lpipeio .and. nstep.ge.nstep_start) then
if (lmaster) then
do j=1,jj
do i=1,ii
amask(i,j) = mask(i,j)
enddo
enddo
call xcaget(tmask, amask, 1)
endif !master
call xcaget(field2, field, 1)
!
if (mnproc.eq.1) then
if (lslave) then
write (lpunit,'(2a)') 'writing for comparison: ',what
call flush(lpunit)
call xcpipe(field1,which, field2,what)
else ! master
call xcpipe(field1,which, field2,what)
write (lpunit,'(2a)') 'reading for comparison: ',which
call flush(lpunit)
if (what.ne.which) then
write (lpunit,'(4a)') 'out of sync -- trying to compare ', &
what,' to ',which
call xchalt('(pipe_compare)')
stop '(pipe_compare)'
endif
!
fail=.false.
do j=1,jtdm
do i=1,itdm
if (tmask(i,j).gt.0.0 .and. &
field2(i,j).ne.field1(i,j)) then
!-----------------if (hycom_isnaninf(field2(i,j))) then
if (.not. &
(field2(i,j).ge.-huge(fnan) .and. &
field2(i,j).le. huge(fnan) )) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' master:',field2(i,j), &
' slave:', field1(i,j),what
else
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' master:',field2(i,j), &
' error:', field2(i,j)-field1(i,j),what
endif
fail=.true.
endif
enddo
enddo
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call xchalt('(pipe_compare)')
stop '(pipe_compare)'
endif
endif !slave:master
endif !1st tile
call xcsync(no_flush) ! wait for 1st tile
endif !lpipeio
return
end subroutine pipe_compare
#else
subroutine pipe_compare(field,mask,what)
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: field
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: mask
character*12, &
intent(in) :: what
!
! --- call this routine from anywhere in the code (from both versions, of
! --- course) to check whether data stored in 'field' are identical
! --- uses short reads and writes to a named pipe
!
integer i,i1,j,j1
logical fail
character*12 which
real fnan !target for huge
!
if (lpipeio .and. nstep.ge.nstep_start) then
if (lmaster) then
do j=1,jj
do i=1,ii
amask(i,j) = mask(i,j)
enddo
enddo
call xcaget(tmask, amask, 1)
endif !master
call xcaget(field2, field, 1)
!
if (mnproc.eq.1) then
if (lslave) then
if (.not.lshift) then
write (lpunit,'(2a)') 'writing for comparison: ',what
call flush(lpunit)
do j= 1,jtdm
write (ipunit) what, field2(:,j)
enddo !j
else ! shift slave array by ishift,jshift
do j=1,jtdm
j1 = mod( j-1+jshift+jtdm, jtdm ) + 1
do i=1,itdm
i1 = mod( i-1+ishift+itdm, itdm ) + 1
field1(i1,j1) = field2(i,j)
enddo
enddo
write (lpunit,'(2a)') 'writing for comparison: ',what
call flush(lpunit)
do j= 1,jtdm
write (ipunit) what, field1(:,j)
enddo !j
endif
else ! master
do j= 1,jtdm
read (ipunit) which,field1(:,j)
enddo !j
write (lpunit,'(2a)') 'reading for comparison: ',which
call flush(lpunit)
if (what.ne.which) then
write (lpunit,'(4a)') 'out of sync -- trying to compare ', &
what,' to ',which
call xchalt('(pipe_compare)')
stop '(pipe_compare)'
endif
!
fail=.false.
do j=1,jtdm
do i=1,itdm
if (tmask(i,j).gt.0.0 .and. &
field2(i,j).ne.field1(i,j)) then
!-----------------if (hycom_isnaninf(field2(i,j))) then
if (.not. &
(field2(i,j).ge.-huge(fnan) .and. &
field2(i,j).le. huge(fnan) )) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' master:',field2(i,j), &
' slave:', field1(i,j),what
else
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' master:',field2(i,j), &
' error:', field2(i,j)-field1(i,j),what
endif
fail=.true.
endif
enddo
enddo
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call xchalt('(pipe_compare)')
stop '(pipe_compare)'
endif
endif !slave:master
endif !1st tile
call xcsync(no_flush) ! wait for 1st tile
endif !lpipeio
! if (ldebugpnt) then
! if (i0.lt.ittest .and. i0+ii.ge.ittest .and.
! & j0.lt.jttest .and. j0+jj.ge.jttest ) then
! write (lp,'(a,2i5,2x,a,a,1pg24.10)')
! & 'i,j=',itest+i0,jtest+j0,
! & what,': ',
! & field(itest,jtest)
! endif
! endif
return
end subroutine pipe_compare
#endif /* OCEANS2:else */
subroutine pipe_compare_sym1(field,mask,what)
implicit none
!
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: field
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: mask
character*12, &
intent(in) :: what
!
! --- call this routine from anywhere in the code
! --- to check whether data stored in 'field' is symmetric or
! --- contains NaNs or Infs.
!
! --- pass through to pipe_compare when in master/slave mode.
!
integer i,io,j,jo
logical fail
real fnan !target for huge
!
if (lpipeio .or. ldebug) then
call pipe_compare(field,mask,what)
elseif (lsym) then
do j=1,jj
do i=1,ii
amask(i,j) = mask(i,j)
enddo
enddo
call xcaget(tmask, amask, 1)
call xcaget(field1, field, 1)
if (mnproc.eq.1) then
write (lpunit,'(2a)') 'comparing: ',what
call flush(lpunit)
fail=.false.
if (nsym.eq.-2) then !arctic
j = jtdm
jo = jtdm-1
do i=1,itdm
io = itdm-mod(i-1,itdm)
if (tmask(i,j).gt.0.0 .and. &
field1(i,j).ne.field1(io,jo)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field1(io,jo),what
fail=.true.
endif
enddo !i
else !standard symteries
do j=1,jtdm
do i=1,itdm
if (tmask(i,j).gt.0.0) then
if (nsym.eq.0) then ! constant field
if (field1(i,j).ne.field1(1,1)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field1(1,1),what
fail=.true.
endif
elseif (nsym.eq.2) then ! constant field in j direction
if (field1(i,j).ne.field1(i,1)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field1(i,1),what
fail=.true.
endif
elseif (nsym.eq.1) then ! p=p.transpose
if (tmask(i,j).gt.0.0 .and. &
field1(i,j).ne.field1(j,i)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field1(j,i),what
fail=.true.
endif
endif !nsym
endif !mask
enddo !i
enddo !j
endif !nsym==-2:else
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call flush(lpunit)
call xchalt('(pipe_compare_sym1)')
stop '(pipe_compare_sym1)'
endif
endif !1st tile
call xcsync(no_flush) ! wait for 1st tile
elseif (lnan) then
if (mnproc.eq.1) then
write (lpunit,'(2a)') 'checking: ',what
call flush(lpunit)
endif !1st tile
call xcsync(flush_lp)
! --- do the NaN checking on the local tile
do j=1,jj
do i=1,ii
if (mask(i,j).gt.0) then
!-------------if (hycom_isnaninf(field(i,j))) then
if (.not. &
(field(i,j).ge.-huge(fnan) .and. &
field(i,j).le. huge(fnan) )) then
write (lpunit,'(a,a,2i5)') &
what,' (NaN): i,j=',i+i0,j+j0
lnan_anyfailed = .true. !local fail
endif
endif
enddo !i
enddo !j
call xcsync(flush_lp)
endif !lpipeio:sym:nan
return
end subroutine pipe_compare_sym1
subroutine pipe_compare_sym2(field_u,mask_u,what_u, &
field_v,mask_v,what_v)
implicit none
!
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: field_u,field_v
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: mask_u,mask_v
character*12, &
intent(in) :: what_u,what_v
!
! --- call this routine from anywhere in the code
! --- to check whether data stored in 'field_[uv]' is symmetric or
! --- contains NaNs or Infs.
!
! --- pass through to pipe_compare when in master/slave mode.
!
integer i,io,j,jo
logical fail
!
if (lpipeio .or. ldebug) then
call pipe_compare(field_u,mask_u,what_u)
call pipe_compare(field_v,mask_v,what_v)
elseif (lnan) then
call pipe_compare_sym1(field_u,mask_u,what_u)
call pipe_compare_sym1(field_v,mask_v,what_v)
elseif (lsym) then
do j=1,jj
do i=1,ii
amask(i,j) = mask_u(i,j)
enddo
enddo
call xcaget(tmask, amask, 1)
call xcaget(field1, field_u, 1)
call xcaget(field2, field_v, 1)
if (nsym.eq.-2) then !arctic
do j=1,jj
do i=1,ii
amask(i,j) = mask_v(i,j)
enddo
enddo
call xcaget(vmask, amask, 1)
endif
if (mnproc.eq.1) then
write (lpunit,'(4a)') 'comparing: ',what_u,' and ',what_v
call flush(lpunit)
fail=.false.
if (nsym.eq.-2) then !arctic
j = jtdm
jo = jtdm-1
do i=1,itdm
io = mod(itdm-(i-1),itdm)+1
if (tmask(i,j).gt.0.0 .and. &
field1(i,j).ne.-field1(io,jo)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)+field1(io,jo),what_u
fail=.true.
endif
enddo !i
j = jtdm
jo = jtdm
do i=1,itdm
io = itdm-mod(i-1,itdm)
if (vmask(i,j).gt.0.0 .and. &
field2(i,j).ne.-field2(io,jo)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field2(i,j), &
' error:',field2(i,j)+field2(io,jo),what_v
fail=.true.
endif
enddo !i
else !standard symteries
do j=1,jtdm
do i=1,itdm
if (nsym.eq.0) then ! constant field
if (field1(i,j).ne.field1(1,1)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field1(1,1),what_u
fail=.true.
endif
if (field2(i,j).ne.field2(1,1)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field2(i,j), &
' error:',field2(i,j)-field2(1,1),what_v
fail=.true.
endif
elseif (nsym.eq.2) then ! constant field in j direction
if (field1(i,j).ne.field1(i,1)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field1(i,1),what_u
fail=.true.
endif
if (field2(i,j).ne.field2(i,1)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field2(i,j), &
' error:',field2(i,j)-field2(i,1),what_v
fail=.true.
endif
elseif (nsym.eq.1) then ! u==v.transpose
if (tmask(i,j).gt.0.0 .and. &
field1(i,j).ne.field2(j,i)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' uvel :',field1(i,j), &
' error:',field1(i,j)-field2(j,i),what_u
fail=.true.
endif
endif
enddo !i
enddo !j
endif
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call xchalt('(pipe_compare_sym2)')
stop '(pipe_compare_sym2)'
endif
endif !1st tile
call xcsync(no_flush) ! wait for 1st tile
endif !lpipeio:nan:sym
return
end subroutine pipe_compare_sym2
subroutine pipe_compare_same(fielda,fieldb,mask,what)
implicit none
!
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: fielda,fieldb
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: mask
character*12, &
intent(in) :: what
!
! --- call this routine from anywhere in the code
! --- to check whether data stored in 'fielda' and 'fieldb'
! --- are identical.
!
! --- only active in PIPE_TRACER mode.
! --- typically fielda is temp and fieldb is a "temperature" tracer.
!
integer i,j
logical fail
!
if (ltracer) then
do j=1,jj
do i=1,ii
amask(i,j) = mask(i,j)
enddo
enddo
call xcaget(tmask, amask, 1)
call xcaget(field1, fielda, 1)
call xcaget(field2, fieldb, 1)
if (mnproc.eq.1) then
write (lpunit,'(2a)') 'comparing: ',what
call flush(lpunit)
fail=.false.
do j=1,jtdm
do i=1,itdm
if (tmask(i,j).gt.0.0 .and. &
field1(i,j).ne.field2(i,j)) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field2(i,j),what
fail=.true.
endif
enddo
enddo
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call xchalt('(pipe_compare_same)')
stop '(pipe_compare_same)'
endif
endif !1st tile
call xcsync(no_flush) ! wait for 1st tile
endif !ltracer
return
end subroutine pipe_compare_same
subroutine pipe_compare_notneg(field,mask,what,field_max)
implicit none
!
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: field
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
intent(in) :: mask
character*12, &
intent(in) :: what
real, &
intent(in) :: field_max
!
! --- call this routine from anywhere in the code
! --- to check whether data stored in 'field' is non-negative.
!
! --- only active in PIPE_TRACER mode.
! --- typically field is a tracer.
!
integer i,j
logical fail
real fnan !target for huge
!
if (ltracernan) then
if (mnproc.eq.1) then
write (lpunit,'(2a)') 'checking: ',what
call flush(lpunit)
endif !1st tile
call xcsync(flush_lp)
! --- do the NaN checking on the local tile
fail=.false.
do j=1,jj
do i=1,ii
if (mask(i,j).gt.0) then
!-------------if (hycom_isnaninf(field(i,j))) then
if (.not. &
(field(i,j).ge.-huge(fnan) .and. &
field(i,j).le. huge(fnan) )) then
write (lpunit,'(a,a,2i5)') &
what,' (NaN): i,j=',i+i0,j+j0
fail=.true.
endif
endif
enddo !i
enddo !j
call xcsync(flush_lp)
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call xchalt('(pipe_compare_notneg)')
stop '(pipe_compare_notneg)'
endif
endif
!
if (ltracer) then
do j=1,jj
do i=1,ii
amask(i,j) = mask(i,j)
enddo
enddo
call xcaget(tmask, amask, 1)
call xcaget(field1, field, 1)
if (mnproc.eq.1) then
write (lpunit,'(2a)') 'comparing: ',what
call flush(lpunit)
fail=.false.
do j=1,jtdm
do i=1,itdm
if (tmask(i,j).gt.0.0) then
if (field1(i,j).lt.0.0) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j),what
fail=.true.
elseif (field1(i,j).gt.field_max) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j)-field_max,what
fail=.true.
!---------------elseif (hycom_isnaninf(field1(i,j))) then
elseif (.not. &
(field1(i,j).ge.-huge(fnan) .and. &
field1(i,j).le. huge(fnan) )) then
write (lpunit,'(a,2i5,1p,2(a,e12.5),4x,a)') &
'i,j=',i,j, &
' orig :',field1(i,j), &
' error:',field1(i,j),what
fail=.true.
endif !errors
endif !tmask.gt.0
enddo
enddo
lpipe_anyfailed = lpipe_anyfailed .or. fail
if (lpipe_fatal .and. fail) then ! exit
call xchalt('(pipe_compare_notneg)')
stop '(pipe_compare_notneg)'
endif
endif !1st tile
call xcsync(no_flush) ! wait for 1st tile
endif !ltracer
return
end subroutine pipe_compare_notneg
subroutine pipe_comparall(m,n, cinfo)
use mod_cb_arrays ! HYCOM saved arrays
#if defined(STOKES)
use mod_stokes ! HYCOM Stokes drift
#endif
implicit none
!
integer, intent(in) :: m,n
character*12, &
intent(in) :: cinfo
!
! --- write out a standard menu of arrays for testing
!
logical hycom_isnaninf !function to detect NaN and Inf
!
character*99 cformat
character*12 txt1,txt2
integer i,imax,imin,j,jmax,jmin,k,ktr,l,mnp
real diso,dmax,dmin,damax,damin,etap1,sshb
real*8 tmean,smean,sanom,pmean,rmean,salt1
real*8 da,d1,d2,d3,d4,d5
real r1,r2,r3,r4
real fnan !target for huge
!
real*8 tmean0,smean0,rmean0, &
tmean1,smean1,rmean1
save tmean0,smean0,rmean0, &
tmean1,smean1,rmean1
data tmean0,smean0,rmean0 / 3*0.0d0 /
!
!diag if (mnproc.eq.1) then
!diag write(lp,'(a,i10)') cinfo,nstep
!diag call flush(lp)
!diag endif
!
if (ldebugssh) then
!
! --- printout SSH in cm at point itest,jtest.
!
if (min(ittest,jttest).le.0) then
call xcstop('(pipe_comparall: debug_ssh ambiguity)')
stop '(pipe_comparall: debug_ssh ambiguity)'
endif
if (i0.lt.ittest .and. i0+ii.ge.ittest .and. &
j0.lt.jttest .and. j0+jj.ge.jttest ) then
! ssh,montg,svref*pbavg (cm)