-
Notifications
You must be signed in to change notification settings - Fork 0
/
diago.F
1722 lines (1722 loc) · 60 KB
/
diago.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
subroutine diago
c
c=======================================================================
c
c write out diagnostic output
c
c=======================================================================
c
#include "param.h"
#include "ctmb.h"
#include "coord.h"
#include "cprnts.h"
#include "cregin.h"
#ifdef tracer_averages
# include "ctavg.h"
#endif
#include "diag.h"
#include "docnam.h"
#include "emode.h"
#include "grdvar.h"
#include "iounit.h"
#include "levind.h"
#include "scalar.h"
#include "stab.h"
#include "switch.h"
#include "tmngr.h"
#include "vmixc.h"
c#define debug_extmode
#if defined stream_function && defined debug_extmode
dimension ext(imt,jmt,2)
#endif
#if defined diagnostic_surf_height && defined stream_function
# include "mw.h"
character*8 bc_symm
c
c psgrad= gradient of sea surface pressure (1,2) = (u,v) component
c dsp = diagnostic sea surface pressure converted to height
c divf = divergence of sea surface pressure gradients
c
dimension psgrad(imt,jmt,2), divf(imt,jmt)
dimension dsp(imt,jmt)
save divf, dsp, numdsp
c
c-----------------------------------------------------------------------
c reconstruct the diagnostic surface pressure
c-----------------------------------------------------------------------
c
# ifdef timing
call tic ('diagnostic', 'diagnostic surf height')
# endif
c
c initialize the surface pressure fields and averaging counter
c
if (first) then
numdsp = 0
do jrow=1,jmt
do i=1,imt
psgrad(i,jrow,1) = c0
psgrad(i,jrow,2) = c0
divf(i,jrow) = c0
dsp(i,jrow) = c0
res(i,jrow) = c0
enddo
enddo
endif
c
c increment the counter for averaging the divergence
c
numdsp = numdsp + 1
c
c construct surface pressure gradients
c (note: uext & vext are returned but not needed)
c
call calc_psgrad (psgrad, uext, vext, 1, jmt, 1, imt)
c
do i=1,imt
psgrad(i,jmt,1) = c0
psgrad(i,jmt,2) = c0
enddo
call setbcx (psgrad(1,1,1), imt, jmt)
call setbcx (psgrad(1,1,2), imt, jmt)
c
c compute the divergence of the sea surface pressure gradients
c
call spforc (psgrad, dxu, dyu, csu, h, res)
c
c accumulate the divergence
c
do jrow=1,jmt
do i=1,imt
divf(i,jrow) = divf(i,jrow) + res(i,jrow)
enddo
enddo
if (dspts) then
c
write (stdout,'(///,40x,a,/)')
& 'D I A G O N O S T I C S U R F A C E H E I G H T'
c
c average the divergence, zero the guess
c
rnum = c1/numdsp
do jrow=1,jmt
do i=1,imt
divf(i,jrow) = rnum*divf(i,jrow)
dsp(i,jrow) = c0
enddo
enddo
c
c initialize coefficients for the conjugate gradient solver
c
call spc9pt (dxu, dyu, csu, h, cf)
npt = 9
type = 'surfpres'
bc_symm = 't even'
c
c number of islands must be zero for surface pressure
c dspcrt = tolerence of solution for dsp
c
nislsp = 0
dspcrt = tolrsp
c
# ifdef timing
call tic ('congrad', 'diagnostic surf press (diago)')
# endif
c
call congr (npt, type, bc_symm, dsp, dsp, divf, res
&, cf
&, mxscan, mdscan, dspcrt
&, imask, iperm, jperm, iofs, nislsp, nippts
&, converged, esterr)
c
write (stdout,'(/a,i5,a,e14.7)')
& '=> diagnostic surface pressure scans=',mdscan,' estimated err='
&, esterr
c
if (.not.converged) then
write (stdout,'(/,a,/)')
& '=> Warning: convergence not reached for diag surface pressure'
converged = .true.
endif
c
# ifdef timing
call toc ('congrad', 'diagnostic surf press (diago)')
# endif
c
c subtract the null space from the surface pressure
c
call checkerboard (dsp, map)
call border (dsp, 't even')
c
c remove mean from the surface pressure
c
call zero_level (dsp, 'surf press', map, dxt, dyt, cst)
call border (dsp, 't even')
c
c convert surface pressure to surface elevation and write out
c
rgrav = c1/grav
do jrow=1,jmt
do i=1,imt
dsp(i,jrow) = rgrav*dsp(i,jrow)
enddo
enddo
c
if (iodsp .eq. stdout .or. iodsp .lt. 0) then
is = indp (slonxy, xt, imt)
ie = indp (elonxy, xt, imt)
js = indp (slatxy, yt, jmt)
je = indp (elatxy, yt, jmt)
scl = c1
write (stdout,'(/1x,a,i5,a)')
& 'Diagnostic surf height is averaged over ',numdsp,' time steps'
write (stdout,7100) 'Diagnostic surface height (cm)'
&, itt, xt(is), xt(ie), yt(js), yt(je), scl
c
call matrix (dsp(1,1), imt, is, ie, -js, -je, scl)
c
7100 format(1x,a30,1x,'ts=',i7
&, ', lon:',f6.2,' ==> ',f6.2,', lat:',f6.2,' ==> ',f6.2
&, ', scaling=',1pg10.3)
c
endif
if (iodsp .ne. stdout .or. iodsp .lt. 0) then
c
call getunit (io, 'diag_surf.dta','u s a ieee')
c
write (stdout,'(a,a,f8.3,a,a,i10,a)')
& ' => Diagnostic surface height (averaged '
&, 'over ',extint,' days) written '
&, 'unformatted to file diag_surf.dta on ts=', itt, ' ',stamp
reltim = prelyr
c
iotext = 'read (iodsp) imt, jmt, reltim, extint, xt, yt'
write (io) pstamp, iotext, expnam
write (io) imt, jmt, reltim, extint, xt, yt
c
iotext = 'read (iodsp) ((dsp(i,j),i=1,imt),j=1,jmt)'
write (io) pstamp, iotext, expnam
call wrufio (io, dsp, imt*jmt)
c
call relunit (io)
endif
c
c reset counter for next average. zero the accumulated divergence
c
numdsp = 0
do jrow=1,jmt
do i=1,imt
divf(i,jrow) = c0
enddo
enddo
endif
# ifdef timing
call toc ('diagnostic', 'diagnostic surf height')
# endif
#endif
c
#ifdef timing
call tic ('diagnostic', 'output (diago)')
#endif
c
#ifdef tracer_averages
c
c-----------------------------------------------------------------------
c compute tracer averages under horizontal regions and write them
c out
c-----------------------------------------------------------------------
c
if (tavgts) then
c
c initialize sums for horizontal regions & tracer averages
c
do m=1,nt
sumgf(m) = c0
avggf(m) = c0
sumgt(m) = c0
avggt(m) = c0
do mask=1,nhreg
sumbt(mask,m) = c0
avgbt(mask,m) = c0
avgbf(mask,m) = c0
enddo
do k=1,km
sumgk(k,m) = c0
avggk(k,m) = c0
enddo
enddo
c
c compute sums for tracer averages over horizontal regions
c
do m=1,nt
do mask=1,nhreg
sumgf(m) = sumgf(m) + sumbf(mask,m)
do k=1,km
sumbt(mask,m) = sumbt(mask,m) + sumbk(mask,k,m)
sumgk(k,m) = sumgk(k,m) + sumbk(mask,k,m)
enddo
sumgt(m) = sumgt(m) + sumbt(mask,m)
enddo
enddo
c
do k=1,km
if (volgk(k) .gt. c0) then
rvolgk = c1 / volgk(k)
do m=1,nt
avggk(k,m) = sumgk(k,m) * rvolgk
do mask=1,nhreg
if (volbk(mask,k) .gt. c0) then
avgbk(mask,k,m) = sumbk(mask,k,m) / volbk(mask,k)
endif
enddo
enddo
endif
enddo
c
rvolgt = c1 / volgt
rareag = c1 / areag
do m=1,nt
avggt(m) = sumgt(m) * rvolgt
avggf(m) = sumgf(m) * rareag
do mask=1,nhreg
if (volbt(mask) .gt. c0) then
avgbt(mask,m) = sumbt(mask,m) / volbt(mask)
endif
if (areab(mask) .gt. c0) then
avgbf(mask,m) = sumbf(mask,m) / areab(mask)
endif
enddo
enddo
c
c write out regional tracer means
c
if (iotavg .eq. stdout .or. iotavg .lt. 0) then
write (stdout,'(//,30x,a,/)') 'T R A C E R A V E R A G E S'
do m=1,nt
write(stdout,9004) trname(m), itt, stamp
write(stdout,9001) (mask,mask=1,nhreg)
do k=1,km
write(stdout,9002) k, avggk(k,m),
& (avgbk(mask,k,m),mask=1,nhreg)
enddo
write(stdout,9003) avggt(m), (avgbt(mask,m),mask=1,nhreg)
write(stdout,9014) m, avggf(m), (avgbf(msk,m),msk=1,nhreg)
enddo
endif
if (iotavg .ne. stdout .or. iotavg .lt. 0) then
c
call getunit (io, 'tracer_avg.dta','u s a ieee')
c
reltim = prelyr
write (stdout,*) ' => Regional tracer averages written'
&, ' unformatted to file tracer_avg.dta on ts=',itt, ' ',stamp
c
iotext = 'read (iotavg) reltim, nt, nhreg, km'
write (io) pstamp, iotext, expnam
write (io) reltim, nt, nhreg, km
c
iotext = 'read (iotavg) ((avggk(k,n),k=1,km),n=1,nt)'
write (io) pstamp, iotext, expnam
call wrufio (io, avggk, km*nt)
c
iotext =
& 'read (iotavg) (((avgbk(l,k,n),l=1,nhreg),k=1,km),n=1,nt)'
write (io) pstamp, iotext, expnam
call wrufio (io, avgbk, nhreg*km*nt)
c
iotext = 'read (iotavg) (avggt(n),n=1,nt)'
write (io) pstamp, iotext, expnam
call wrufio (io, avggt, nt)
c
iotext = 'read (iotavg) (avggf(n),n=1,nt)'
write (io) pstamp, iotext, expnam
call wrufio (io, avggf, nt)
c
iotext = 'read (iotavg) ((avgbt(l,n),l=1,nhreg),n=1,nt)'
write (io) pstamp, iotext, expnam
call wrufio (io, avgbt, nhreg*nt)
c
iotext = 'read (iotavg) ((avgbf(l,n),l=1,nhreg),n=1,nt)'
write (io) pstamp, iotext, expnam
call wrufio (io, avgbf, nhreg*nt)
c
call relunit (io)
endif
endif
9001 format(' k',' All Regions ',9(1x,i7,5x))
9002 format(1x,i4,10(1x,e12.6))
9003 format(' AVG',10(1x,e12.6))
9004 format(/' Volume Weighted Averages for ',a12,' on ts =',i10,a33)
9014 format(/' FLX',i1,10(1x,e12.6),/)
#endif
c
#ifdef time_step_monitor
c
c-----------------------------------------------------------------------
c print integrals for monitoring the time step
c-----------------------------------------------------------------------
c
if (tsits) then
do jrow=2,jmtm1
do k=km,1,-1
ektot(0,1) = ektot(0,1) + ektot(k,jrow)
enddo
do m=1,nt
do k=km,1,-1
tbar(0,m,1) = tbar(0,m,1) + tbar(k,m,jrow)
travar(0,m,1) = travar(0,m,1) + travar(k,m,jrow)
dtabs(0,m,1) = dtabs(0,m,1) + dtabs(k,m,jrow)
enddo
enddo
enddo
ektot(0,1) = ektot(0,1)/ucellv
do m=1,nt
tbar(0,m,1)=tbar(0,m,1)/tcellv
travar(0,m,1)=travar(0,m,1)/tcellv - tbar(0,m,1)**2
dtabs(0,m,1)=dtabs(0,m,1)/tcellv
enddo
if (iotsi .eq. stdout .or. iotsi .lt. 0) then
write (stdout,9601) itt, stamp, ektot(0,1), dtabs(0,1,1)
&, dtabs(0,2,1), tbar(0,1,1), tbar(0,2,1)
&, travar(0,1,1), travar(0,2,1), mscan
endif
if (iotsi .ne. stdout .or. iotsi .lt. 0) then
c
call getunit (io, 'ts_intgrls.dta','u s a ieee')
c
write (stdout,*) ' => Time step integrals written'
&, ' unformatted to file ts_intgrls.dta on ts=',itt, ' ',stamp
reltim = prelyr
totke = ektot(0,1)
tbar1 = tbar(0,1,1)
tbar2 = tbar(0,2,1)
tvar1 = travar(0,1,1)
tvar2 = travar(0,2,1)
dtabs1 = dtabs(0,1,1)
dtabs2 = dtabs(0,2,1)
iotext =
&'read(io) reltim, tke, dtabs, dsabs, tbar, sbar, tvar, tvar, nscn'
write (io) pstamp, iotext, expnam
write (io) reltim, totke, dtabs1, dtabs2, tbar1, tbar2, tvar1
&, tvar2, mscan
c
call relunit (io)
endif
endif
9601 format (1x,'ts=',i7, 1x, a32, ', ke=', 1pe13.6,' |dT|=',1pe13.6
&, ' |dS|=',1pe13.6,' Tbar=',1pe13.6,' Sbar=',1pe13.6
&, ' Tvar=',1pe13.6,' Svar=',1pe13.6, ' scans=',i4)
#endif
c
#ifdef stability_tests
c
c-----------------------------------------------------------------------
c show stability and CFL conditions, reynolds and peclet numbers
c-----------------------------------------------------------------------
c
if (stabts) then
write (stdout,'(///20x,a/15x,a,/)')
& ' S T A B I L I T Y A N A L Y S I S'
&, '(The indicated locations are the most unstable ones)'
c
write (stdout,*) ' longitudinal domain: ',cflons, ' to ',cflone
write (stdout,*) ' latitudinal domain: ',cflats, ' to ',cflate
write (stdout,*) ' depth domain (m) : ',cfldps*0.01
&, ' to ',cfldpe*0.01
c
write (stdout,'(/60x,a/)') ' CFL summary'
write (stdout
&,'(a,g10.3,a,f7.2,a,/a,i4,a,i4,a,i3,a,3x,a,f7.2,a,f7.2,a,f7.0,a)')
& ' Local U velocity (',cflum,') is ',cflup,' % of the CFL limit'
&, ' at location: (i,j,k) = (',icflu,',',jcflu,',',kcflu,')'
&, ' (lon,lat,dpt) = (',xu(icflu),',',yu(jcflu),','
&, 0.01*zt(kcflu),')'
c
write (stdout
&,'(a,g10.3,a,f7.2,a,/a,i4,a,i4,a,i3,a,3x,a,f7.2,a,f7.2,a,f7.0,a)')
& ' Local V velocity (',cflvm,') is ',cflvp,' % of the CFL limit'
&, ' at location: (i,j,k) = (',icflv,',',jcflv,',',kcflv,')'
&, ' (lon,lat,dpt) = (',xu(icflv),',',yu(jcflv),','
&, 0.01*zt(kcflv),')'
c
write (stdout
&,'(a,g10.3,a,f7.2,a,/a,i4,a,i4,a,i3,a,3x,a,f7.2,a,f7.2,a,f7.0,a)')
& ' Local adv_vbu (',cflwum,') is ',cflwup,' % of the CFL limit'
&, ' at location: (i,j,k) = (',icflwu,',',jcflwu,',',kcflwu,')'
&, ' (lon,lat,dpt) = (',xu(icflwu),',',yu(jcflwu),','
&, 0.01*zw(kcflwu),')'
c
write (stdout
&,'(a,g10.3,a,f7.2,a,/a,i4,a,i4,a,i3,a,3x,a,f7.2,a,f7.2,a,f7.0,a)')
& ' Local adv_vbt (',cflwtm,') is ',cflwtp,' % of the CFL limit'
&, ' at location: (i,j,k) = (',icflwt,',',jcflwt,',',kcflwt,')'
&, ' (lon,lat,dpt) = (',xu(icflwt),',',yu(jcflwt),','
&, 0.01*zw(kcflwt),')'
c
fx = 100.0
if (cflup .gt. fx .or. cflvp .gt. fx .or. cflwup .gt. fx .or.
& cflwtp .gt. fx) then
write (stdout,*)
& ' => Warning. CFL exceeded... computational mode exists!'
endif
c
write (stdout,'(/60x,a24/)') ' Reynolds number summary'
c
write (stdout,10300) reynx, ireynx, jreynx, kreynx
&, xu(ireynx), yu(jreynx), 0.01*zt(kreynx)
write (stdout,10310) reynu, reynmu
c
write (stdout,10400) reyny, ireyny, jreyny, kreyny
&, xu(ireyny), yu(jreyny), 0.01*zt(kreyny)
write (stdout,10410) reynv, reynmv
c
write (stdout,10500) reynz, ireynz, jreynz, kreynz
&, xu(ireynz), yu(jreynz), 0.01*zt(kreynz)
write (stdout,10510) reynw, reynmw
c
write (stdout,'(/60x,a22/)') ' Peclet number summary'
c
write (stdout,10600) peclx, ipeclx, jpeclx, kpeclx
&, xu(ipeclx), yu(jpeclx), 0.01*zt(kpeclx)
write (stdout,10610) peclu, peclmu
c
write (stdout,10700) pecly, ipecly, jpecly, kpecly
&, xu(ipecly), yu(jpecly), 0.01*zt(kpecly)
write (stdout,10710) peclv, peclmv
c
write (stdout,10800) peclz, ipeclz, jpeclz, kpeclz
&, xu(ipeclz), yu(jpeclz), 0.01*zt(kpeclz)
write (stdout,10810) peclw, peclmw
c
c show ficticious tracer extremums
c
call getunit (iostab, 'iostab', 'fsr')
rewind iostab
write (stdout,'(/,10x,a/,11x,a,1pe10.3,a/)')
& 'Spurious creation of local tracer extremum (if any) follow:'
&, '(where tracer exceeds local extremum by ',tdig,'*tracer)'
do num=1,1000
read (iostab,'(i4, i4, i4, i2, 3g14.7)', end=101, err=101)
& i, k, jrow, n, tnew, tsml, tbig
write (stdout,'(1x,a,i4,a,i4,a,i4,a,i2,3(a,g14.7))')
& 't(i,k,jrow,n) = t(',i,',',k,',',jrow,',',n, ') = '
&, tnew,' : local min was ',tsml, ' : local max was ', tbig
if (num .eq. 100) then
write (stdout,'(/a/)') 'Bailing out after 100 locations...'
go to 101
endif
enddo
101 continue
call relunit (iostab)
write (stdout,'(/60x,a/)') ' End Stability Analysis'
endif
10300 format (1x,'Maximim zonal Reynolds number is ',1pe9.2
&, ' at location: (i,j,k) = (',i4,',',i4,',',i4,'),'
&, ' (lon,lat,dpt) = (',e9.2,',',e9.2,',',e9.2,')')
10310 format (1x,' local U =',1pe9.2, ' and mixing =',e9.2)
10400 format (1x,'Maximim meridional Reynolds number is ',1pe9.2
&, ' at location: (i,j,k) = (',i4,',',i4,',',i4,'),'
&, ' (lon,lat,dpt) = (',e9.2,',',e9.2,',',e9.2,')')
10410 format (1x,' local V =',1pe9.2, ' and mixing =',e9.2)
10500 format (1x,'Maximim vertical Reynolds number is ',1pe9.2
&, ' at location: (i,j,k) = (',i4,',',i4,',',i4,'),'
&, ' (lon,lat,dpt) = (',e9.2,',',e9.2,',',e9.2,')')
10510 format (1x,' local Wu =',1pe9.2, ' and mixing =',e9.2)
10600 format (1x,'Maximim zonal Peclet number is ',1pe9.2
&, ' at location: (i,j,k) = (',i4,',',i4,',',i4,'),'
&, ' (lon,lat,dpt) = (',e9.2,',',e9.2,',',e9.2,')')
10610 format (1x,' local U =',1pe9.2, ' and mixing =',e9.2)
10700 format (1x,'Maximim meridional Peclet number is ',1pe9.2
&, ' at location: (i,j,k) = (',i4,',',i4,',',i4,'),'
&, ' (lon,lat,dpt) = (',e9.2,',',e9.2,',',e9.2,')')
10710 format (1x,' local V =',1pe9.2, ' and mixing =',e9.2)
10800 format (1x,'Maximim vertical Peclet number is ',1pe9.2
&, ' at location: (i,j,k) = (',i4,',',i4,',',i4,'),'
&, ' (lon,lat,dpt) = (',e9.2,',',e9.2,',',e9.2,')')
10810 format (1x,' local Wt =',1pe9.2, ' and mixing =',e9.2)
#endif
c
#ifdef energy_analysis
c
c-----------------------------------------------------------------------
c add external mode component of total work done
c-----------------------------------------------------------------------
c
if (glents) then
# ifdef timing
call toc ('diagnostic', 'output (diago)')
# endif
call ge3 (c2dtuv)
# ifdef timing
call ticr ('diagnostic', 'output (diago)')
# endif
endif
c
c-----------------------------------------------------------------------
c integrate previously computed energy components vertically
c-----------------------------------------------------------------------
c
if (glents) then
jte = 1
jue = 1
jwte = 1
jwue = 1
do k=1,km
wtlev(k,0) = c0
wulev(k,0) = c0
enddo
do jrow=2,jmt
do k=km,1,-1
buoy(0,1) = buoy(0,1) + buoy(k,jrow)
wtlev(k,0) = wtlev(k,0) + wtlev(k,jrow)
wulev(k,0) = wulev(k,0) + wulev(k,jrow)
enddo
do ll=1,8
do k=km,1,-1
engint(0,ll,1) = engint(0,ll,1) + engint(k,ll,jrow)
enddo
engext(ll,1) = engext(ll,1) + engext(ll,jrow)
enddo
if (abs(tcerr(jrow)) .gt. abs(tcerr(jte))) jte = jrow
if (abs(ucerr(jrow)) .gt. abs(ucerr(jte))) jue = jrow
if (abs(wtbot(jrow)) .gt. abs(wtbot(jwte))) jwte = jrow
if (abs(wubot(jrow)) .gt. abs(wubot(jwue))) jwue = jrow
enddo
buoy(0,1) = buoy(0,1)/ucellv
do ll=1,8
engint(0,ll,1) = engint(0,ll,1)/ucellv
engext(ll,1) = engext(ll,1)/ucellv
enddo
c
plicin = engint(0,1,1) - engint(0,2,1) - engint(0,3,1)
& - engint(0,4,1) - engint(0,5,1) - engint(0,6,1)
plicex = engext(1,1) - engext(2,1) - engext(3,1)
& - engext(4,1) - engext(5,1) - engext(6,1)
buoerr = buoy(0,1) - engint(0,6,1) - engext(6,1)
enleak = engint(0,2,1) + engint(0,3,1) + engext(2,1)
& + engext(3,1)
c
if (ioglen .eq. stdout .or. ioglen .lt. 0) then
write (stdout,'(///40x,a,/)') 'E N E R G Y A N A L Y S I S'
write (stdout,9100)
& 'Globally averaged work done'
&, ' for ts =', itt, stamp, ucellv, ucella(1)
write (stdout,9101) ' time rate of change ',engint(0,1,1)
&, engint(0,1,1), engext(1,1), engext(1,1)
write (stdout,9101) ' horizontal advection', engint(0,2,1)
&, engint(0,2,1), engext(2,1), engext(2,1)
write (stdout,9101) ' vertical advection ',engint(0,3,1)
&, engint(0,3,1), engext(3,1), engext(3,1)
write (stdout,9101) ' horizontal friction ',engint(0,4,1)
&, engint(0,4,1), engext(4,1), engext(4,1)
write (stdout,9101) ' vertical friction ',engint(0,5,1)
&, engint(0,5,1), engext(5,1), engext(5,1)
write (stdout,9101) ' pressure forces ',engint(0,6,1)
&, engint(0,6,1), engext(6,1), engext(6,1)
write (stdout,9101) ' ficticious sources ',plicin
&, plicin, plicex, plicex
write (stdout,9101) ' work by wind ',engint(0,7,1)
&, engint(0,7,1), engext(7,1), engext(7,1)
write (stdout,9101) ' bottom drag ',engint(0,8,1)
&, engint(0,8,1), engext(8,1), engext(8,1)
write (stdout,9110) buoy(0,1), buoy(0,1), buoerr, buoerr
&, enleak, enleak
write (stdout,9111) tcerr(jte), itcerr(jte), jtcerr(jte)
&, ktcerr(jte)
&, ucerr(jue), iucerr(jue), jucerr(jue)
&, kucerr(jue)
write (stdout,9112) wtbot(jwte), iwtbot(jwte), jwtbot(jwte)
&, kwtbot(jwte)
&, wubot(jwue), iwubot(jwue), jwubot(jwue)
&, kwubot(jwue)
c
write (stdout,'(/a,a,//a,a,a,a,a,/1x,a,a)')
& 'Average vertical velocity through bottom of "T" and "u" '
&, 'cells at each level','level', ' adv_vbt err '
&, ' "T" cell area ', ' adv_vbu err ',' "U" cell area'
&, '(Note: adv_vbu err only goes to zero when non-zero values on'
&, ' boundary cells are taken into account)'
do k=1,km
if (tcella(k) .ne. c0) then
wtlev(k,0) = wtlev(k,0)/tcella(k)
else
wtlev(k,0) = c0
endif
if (ucella(k) .ne. c0) then
wulev(k,0) = wulev(k,0)/ucella(k)
else
wulev(k,0) = c0
endif
write (stdout,'(i4,4(2x,e14.7))')
& k, wtlev(k,0), tcella(k), wulev(k,0), ucella(k)
enddo
endif
c
if (ioglen .ne. stdout .or. ioglen .lt. 0) then
c
call getunit (io, 'energy_int.dta','u s a ieee')
c
write (stdout, *)
& ' ==> Global energy integrals written unformatted'
&, ' to file energy_int.dta on ts =', itt, stamp
reltim = prelyr
iotext = 'read(ioglen) reltim,(engint(i),engext(i),i=1,8)'
iotext(46:) = ',plicin,plicex,buoy,buoerr,enleak'
write (io) pstamp, iotext, expnam
write (io) reltim, (engint(0,i,1),engext(i,1),i=1,8)
&, plicin, plicex, buoy(0,1), buoerr, enleak
call relunit (io)
endif
endif
9100 format(///,1x,
&/1x,a,a,i10,a/1x,'ocean volume =',e16.9,' cm**3'
&, ', ocean surface area =',e16.9,' cm**2'//' work by:',14x
&, 'internal mode external mode'/)
9101 format(a21,2(1pe15.6, ' (',z16,' hex)'))
9110 format(/' work by buoyancy forces =',1pe14.6, ' (',z16,' hex)'/
&, ' energy conversion error =',1pe14.6, ' (',z16,' hex)'/
&, ' nonlinear error =',1pe14.6, ' (',z16,' hex)'/)
9111 format(/' max "t" cell continuity error =',1pe14.6, ' at location'
&, ' (i,jrow,k) = ','(',i4,',',i4,',',i4,')'
&, /' max "u" cell continuity error =',1pe14.6, ' at location'
&, ' (i,jrow,k) = ','(',i4,',',i4,',',i4,')')
9112 format(/' max bottom "adv_vbt" (error) =',1pe14.6
&, ' at location', ' (i,jrow,k) = ','(',i4,',',i4,',',i4,')'
&, /' max bottom "adv_vbu" (slope vel) =',1pe14.6
&, ' at location',' (i,jrow,k) = ','(',i4,',',i4,',',i4,')')
#endif
c
c
#ifdef term_balances
c
c-----------------------------------------------------------------------
c add the external mode part of d/dt into the momentum balance,
c the external mode part of the implicit coriolis term, and the
c surface pressure gradients into the specified volumes
c-----------------------------------------------------------------------
c
if (trmbts) then
c
# ifdef timing
call toc ('diagnostic', 'output (diago)')
# endif
call utb3
# ifdef timing
call ticr ('diagnostic', 'output (diago)')
# endif
c
c-----------------------------------------------------------------------
c integrate previously computed term balance components vertically
c-----------------------------------------------------------------------
c
do n=0,numreg
if (n .gt. 0) then
nv = (n-1)/nhreg + 1
ks = llvreg(nv,1)
ke = llvreg(nv,2)
do ll=1,17
do k=ke,ks,-1
termbm(0,ll,1,n) = termbm(0,ll,1,n) + termbm(k,ll,1,n)
termbm(0,ll,2,n) = termbm(0,ll,2,n) + termbm(k,ll,2,n)
enddo
enddo
else
ks = 1
ke = km
endif
do m=1,nt
do ll=1,15
do k=ke,ks,-1
termbt(0,ll,m,n) = termbt(0,ll,m,n) + termbt(k,ll,m,n)
enddo
enddo
c
c construct change due to convection and filtering
c
dtconv = termbt(0,10,m,n) - termbt(0,9,m,n)
dtfilt = termbt(0,1,m,n) - termbt(0,10,m,n)
termbt(0,9,m,n) = dtconv
termbt(0,10,m,n) = dtfilt
enddo
enddo
c
c normalize integrals by appropriate volume (or area)
c
do n=0,numreg
do m=1,nt
if (n .le. nhreg) then
stflx(m,n) = stflx(m,n)*rareat(n)
asst(m,n) = asst(m,n)*rareat(n)
endif
do ll=1,15
termbt(0,ll,m,n) = termbt(0,ll,m,n)*rvolt(n)
enddo
enddo
enddo
c
do n=0,numreg
if (n .le. nhreg) then
smflx(1,0) = smflx(1,0) + smflx(1,n)
smflx(2,0) = smflx(1,0) + smflx(2,n)
smflx(1,n) = smflx(1,n)*rareau(n)
smflx(2,n) = smflx(2,n)*rareau(n)
endif
if (n .gt. 0) then
avgw(n) = avgw(n)*rvolu(n)
do ll=1,17
termbm(0,ll,1,n) = termbm(0,ll,1,n)*rvolu(n)
termbm(0,ll,2,n) = termbm(0,ll,2,n)*rvolu(n)
enddo
endif
enddo
smflx(1,0) = smflx(1,0)*rareau(0)
smflx(2,0) = smflx(2,0)*rareau(0)
c
if (iotrmb .eq. stdout .or. iotrmb .lt. 0) then
c
write (stdout,'(///,40x,a,/)') 'T E R M B A L A N C E S'
c
n = 0
taux = smflx(1,n)
tauy = smflx(2,n)
write (stdout,10106)
& 'All regions added together for ts ='
&, itt, stamp, volt(n), areat(n)
&, volu(n), areau(n)
write (stdout,10104)
write (stdout,10098) n, ' smf(1) = ', taux,' dynes/cm**2 '
write (stdout,10098) n, ' smf(2) = ', tauy,' dynes/cm**2 '
do m=1,nt
write (stdout,10098) n, ustf(m,1), stflx(m,n), ustf(m,2)
enddo
write (stdout,10098) n, ' tot heat = '
&, (termbt(0,15,1,n)*volt(n))
&, ' deg C * cm**3 '
write (stdout,10098) n, ' sst = ',asst(1,n)
&, ' deg C '
c
do n=0,numreg
if (n .eq. 1) then
write (stdout,10050)
& 'Regional averaged Momentum & Tracer Term Balances for ts = '
&, itt, stamp
endif
iv = 0
if (n .gt. 0) then
iv = (n-1)/nhreg + 1
ih = n - (iv-1)*nhreg
write (stdout,10100)
& 'Momentum terms averaged over region #'
&, n, ': ', hregnm(ih), vregnm(iv), volu(n), areau(n)
write (stdout,10104)
write (stdout,10101) n,' dU/dt = ', termbm(0,1,1,n)
&, ' dV/dt = ', termbm(0,1,2,n)
write (stdout,10101) n,' -Px = ', termbm(0,2,1,n)
&, ' -Py = ', termbm(0,2,2,n)
write (stdout,10101) n,' -surf Px= ', termbm(0,12,1,n)
&, ' -surf Py= ', termbm(0,12,2,n)
write (stdout,10101) n,' -(UU)x = ', termbm(0,3,1,n)
&, ' -(UV)x = ', termbm(0,3,2,n)
write (stdout,10101) n,' -(VU)y = ', termbm(0,4,1,n)
&, ' -(VV)y = ', termbm(0,4,2,n)
write (stdout,10101) n,' -(WU)z = ', termbm(0,5,1,n)
&, ' -(WV)z = ', termbm(0,5,2,n)
write (stdout,10101) n,'ADV_Umet = ', termbm(0,13,1,n)
&, '-ADV_Vmet= ', termbm(0,13,2,n)
write (stdout,10101) n,' DIFF_Ux= ', termbm(0,6,1,n)
&, ' DIFF_Vx= ', termbm(0,6,2,n)
write (stdout,10101) n,' DIFF_Uy= ', termbm(0,7,1,n)
&, ' DIFF_Vy= ', termbm(0,7,2,n)
write (stdout,10101) n,' DIFF_Uz= ', termbm(0,8,1,n)
&, ' DIFF_Vz= ', termbm(0,8,2,n)
write (stdout,10101) n,'DIFF_Umet= ', termbm(0,9,1,n)
&, 'DIFF_Vmet= ', termbm(0,9,2,n)
write (stdout,10101) n,' fV = ', termbm(0,10,1,n)
&, ' -fU = ', termbm(0,10,2,n)
write (stdout,10101) n,' source = ', termbm(0,11,1,n)
&, ' source = ', termbm(0,11,2,n)
erru = c0
errv = c0
do lll=2,13
erru = erru + termbm(0,lll,1,n)
errv = errv + termbm(0,lll,2,n)
enddo
write (stdout,10101) n,' error = ', termbm(0,1,1,n)-erru
&, ' error = ', termbm(0,1,2,n)-errv
c
write (stdout,*) ' '
write (stdout,10101) n,' -U(U)x = ', termbm(0,14,1,n)
&, ' -U(V)x = ', termbm(0,14,2,n)
write (stdout,10101) n,' -V(U)y = ', termbm(0,15,1,n)
&, ' -V(V)y = ', termbm(0,15,2,n)
write (stdout,10101) n,' -W(U)z = ', termbm(0,16,1,n)
&, ' -W(V)z = ', termbm(0,16,2,n)
c
c mass conservation within volume: Ux + Vy + Wz
c
contu = (termbm(0,3,1,n) + termbm(0,4,1,n) +
& termbm(0,5,1,n)) - (termbm(0,14,1,n) +
& termbm(0,15,1,n) + termbm(0,16,1,n))
write (stdout,10101) n,' mass err= ', contu
c
write (stdout,10101) n,' ubar = ', termbm(0,17,1,n)
&, ' vbar = ', termbm(0,17,2,n)
&, ' wbar = ', avgw(n)
endif
if (iv .eq. 1) then
write (stdout,10101) n,' surf Uz= ', smflx(1,n)
&, ' surf Vz= ', smflx(2,n)
endif
c
if (n .eq. 0) then
write (stdout,10051)
& 'Global averaged (entire ocean) Tracer Term Balances for ts = '
&, itt, stamp
else
write (stdout,10100)
& 'Tracer terms averaged over region #'
&, n, ': ', hregnm(ih), vregnm(iv), volt(n), areat(n)
endif
c
do m=1,nt
dchg = termbt(0,2,m,n) + termbt(0,3,m,n) +
& termbt(0,4,m,n) + termbt(0,5,m,n) +
& termbt(0,6,m,n) + termbt(0,7,m,n) +
& termbt(0,8,m,n) + termbt(0,9,m,n) +
& termbt(0,10,m,n)
terr(m) = termbt(0,1,m,n) - dchg
enddo
maxm = (nt-1)/7 + 1
do mloop=1,maxm
ms = (mloop-1)*7 + 1
me = min(ms + 6,nt)
write (stdout,10103) (trname(m),m=ms,me)
write (stdout,10102) n,' dT/dt = ', (termbt(0,1,m,n)
&, m=ms,me)
write (stdout,10102) n,' -(UT)x = ', (termbt(0,2,m,n)
&, m=ms,me)
write (stdout,10102) n,' -(VT)y = ', (termbt(0,3,m,n)
&, m=ms,me)
write (stdout,10102) n,' -(WT)z = ', (termbt(0,4,m,n)
&, m=ms,me)
write (stdout,10102) n,' DIFF_Tx= ', (termbt(0,5,m,n)
&, m=ms,me)
write (stdout,10102) n,' DIFF_Ty= ', (termbt(0,6,m,n)
&, m=ms,me)
write (stdout,10102) n,' DIFF_Tz= ', (termbt(0,7,m,n)
&, m=ms,me)
write (stdout,10102) n,' source = ', (termbt(0,8,m,n)
&, m=ms,me)
write (stdout,10102) n,' convct = ', (termbt(0,9,m,n)
&, m=ms,me)
write (stdout,10102) n,' filter = ', (termbt(0,10,m,n)
&, m=ms,me)
write (stdout,10102) n,' error = ', (terr(m)
&, m=ms,me)
c
write (stdout,*) ' '
write (stdout,10102) n,' -U(T)x = ', (termbt(0,11,m,n)
&, m=ms,me)
write (stdout,10102) n,' -V(T)y = ', (termbt(0,12,m,n)
&, m=ms,me)
write (stdout,10102) n,' -W(T)z = ', (termbt(0,13,m,n)
&, m=ms,me)
c
c mass conservation within volume: Ux + Vy + Wz
c
cont = (termbt(0,2,1,n) + termbt(0,3,1,n) +
& termbt(0,4,1,n)) - (termbt(0,11,1,n) +
& termbt(0,12,1,n) + termbt(0,13,1,n))
write (stdout,10102) n,' mass err= ', cont
c
write (stdout,10102) n,' chg var= ', (termbt(0,14,m,n)
&, m=ms,me)
write (stdout,10102) n,' tbar = ', (termbt(0,15,m,n)
&, m=ms,me)
if (iv .eq. 1) then
write (stdout,10102) n,' surflx = ', (stflx(m,n)
&, m=ms,me)
taux = smflx(1,n)
tauy = smflx(2,n)
write (stdout,10105) ' Regionally averaged quantities:'
write (stdout,'(1x)')
write (stdout,10098) n
&, ' smf(1) = ', taux,' dynes/cm**2 '
write (stdout,10098) n
&, ' smf(2) = ', tauy,' dynes/cm**2 '
do m=1,nt
write (stdout,10098) n
&, ustf(m,1), stflx(m,n), ustf(m,2)
enddo
if (ms .eq. 1) then
write (stdout,10098) n, ' tot heat = '
&, (termbt(0,15,1,n)*volt(n)),' deg C * cm**3 '
write (stdout,10098) n
&, ' sst = ', asst(1,n),' deg C '
endif
endif
enddo
enddo
endif
c
if (iotrmb .ne. stdout .or. iotrmb .lt. 0) then
c
call getunit (io, 'term_bal.dta','u s a ieee')
c
write (stdout, *)
& ' ==> Term balances written unformatted to file term_bal.dta'
&, ' for ts =', itt, ' ',stamp
c
reltim = prelyr
c
iotext =' read (iotrmb) reltim, nt, numreg, nhreg, km'
iotext(45:) =', ((ustf*15(n,i),n=1,nt),i=1,2)'
write (io) pstamp, iotext, expnam
write (io) reltim, nt, numreg, nhreg, km, ustf
c
iotext ='read (iotrmb) (hregnm*40(n),n=1,nhreg)'
iotext(39:)=', (vregnm*20(n),n=1,nvreg)'
write (io) pstamp, iotext, expnam
write (io) hregnm, vregnm
c
iotext ='read (iotrmb) (trname*12(n),n=1,nt)'
write (io) pstamp, iotext, expnam
write (io) trname
c
iotext ='read (iotrmb) (volu(l),l=0,numreg)'
write (io) pstamp, iotext, expnam
call wrufio (io, volu, numreg+1)
c
iotext ='read (iotrmb) (volt(l),l=0,numreg)'
write (io) pstamp, iotext, expnam
call wrufio (io, volt, numreg+1)
c
iotext ='read (iotrmb) (areau(l),l=0,numreg)'
write (io) pstamp, iotext, expnam
call wrufio (io, areau, numreg+1)
c
iotext ='read (iotrmb) (areat(l),l=0,numreg)'
write (io) pstamp, iotext, expnam
call wrufio (io, areat, numreg+1)