forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_archiv.F90
1625 lines (1600 loc) · 56.2 KB
/
mod_archiv.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_archiv
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_za ! HYCOM I/O interface
!
implicit none
!
! --- HYCOM archive file processing.
!
character*240, allocatable, dimension(:), &
save, private :: &
cpnts ! names of profile locations
integer, allocatable, dimension(:), &
save, private :: &
ipnts, & ! i-indexes of profile locations
jpnts ! j-indexes of profile locations
integer, save, private :: &
npnts ! number of profile locations
logical, save, private :: &
fpnts ! initialize profile location files
!
integer, parameter, private :: nfields=20 !no. fields in surface archive
character*6, save, private :: c_arch(nfields) !field names
logical, save, private :: l_arch(nfields) !field output flags
!
private archiv_prof_out
contains
subroutine archiv_init
!
! --- initialize surface archive output flags
!
logical lexist
integer ios,k_arch
!
if (mnproc.eq.1) then
write (lp,*) ' now processing archs.input ...'
endif !1st tile
call xcsync(flush_lp)
!
! --- check that archs.input exists
!
inquire(file=trim(flnminp)//'archs.input',exist=lexist)
if (.not.lexist) then
if (mnproc.eq.1) then
write (lp,*) ' output 17 standard surface archive fields.'
endif !1st tile
call xcsync(flush_lp)
!
l_arch( 1:17) = .true.
l_arch(18:20) = .false. !salflx,surtx,surty must be explicitly selected
return
endif
!
! --- list of field names, 6 character versions of 8 character names
!
c_arch( 1) = 'montg1'
c_arch( 2) = 'srfhgt'
c_arch( 3) = 'steric'
c_arch( 4) = 'surflx'
c_arch( 5) = 'wtrflx'
c_arch( 6) = 'bldpth'
c_arch( 7) = 'mldpth'
c_arch( 8) = 'covice'
c_arch( 9) = 'thkice'
c_arch(10) = 'temice'
c_arch(11) = 'ubtrop'
c_arch(12) = 'vbtrop'
c_arch(13) = 'u-vel.'
c_arch(14) = 'v-vel.'
c_arch(15) = 'thknss'
c_arch(16) = 'temp '
c_arch(17) = 'salin ' !end of default list
c_arch(18) = 'salflx' !optional fields output after wtrflx
c_arch(19) = 'surtx '
c_arch(20) = 'surty '
!
! --- read in archs.input.
!
open(unit=uoff+99,file=trim(flnminp)//'archs.input')
do k_arch= 1,nfields
call blkinl(l_arch(k_arch),c_arch(k_arch))
enddo
close (unit=uoff+99)
call xcsync(flush_lp)
return
end subroutine archiv_init
subroutine archiv(n, kkout, iyear,iday,ihour, intvl)
#if defined(STOKES)
use mod_stokes ! Stokes Drift Velocity Module
#endif
!
integer n, kkout, iyear,iday,ihour
character intvl*3
!
# include "stmt_fns.h"
!
! --- write an archive file.
!
character*80 cformat,flnmarcvs
integer i,j,k,ktr,ldot,nop,nopa
real coord,xmin,xmax
!
if (kkout.eq.1) then
flnmarcvs = flnmarcs
else
flnmarcvs = flnmarc
endif
ldot = index(flnmarcvs,'.',back=.true.)
if (ldot.eq.0) then
if (mnproc.eq.1) then
write (lp,*) 'need decimal point in flnmarcvs'
write (lp,*) 'flnmarcvs = ',trim(flnmarcvs)
endif
call xcstop('(flnmarcvs)')
stop '(flnmarcvs)'
endif
ldot = min(ldot,len(flnmarcvs)-11) !need 11 characters for archive date
!
if ((kkout.eq.1 .and. dsurfq.ge.1.0/24.0) .or. &
(kkout.gt.1 .and. diagfq.ge.1.0/24.0) ) then
! --- indicate the archive date
write(flnmarcvs(ldot+1:ldot+11),'(i4.4,a1,i3.3,a1,i2.2)') &
iyear,'_',iday,'_',ihour
ldot=ldot+11
else
! --- indicate the archive time step
write(flnmarcvs(ldot+1:ldot+11),'(i11.11)') nstep
ldot=ldot+11
endif
nopa=13
nop =13+uoff
!
! --- no .[ab] files for 1-D cases (<=6x6) or for dsur1p surface cases.
!
if (max(itdm,jtdm).gt.6 .and. &
.not.(dsur1p .and. kkout.eq.1)) then !not 1-D output
!
call zaiopf(flnmarcvs(1:ldot)//'.a', 'new', nopa)
if (mnproc.eq.1) then
open (unit=nop,file=flnmarcvs(1:ldot)//'.b',status='new') !uoff+13
write(nop,116) ctitle,iversn,iexpt,yrflag,itdm,jtdm
call flush(nop)
endif !1st tile
116 format (a80/a80/a80/a80/ &
i5,4x,'''iversn'' = hycom version number x10'/ &
i5,4x,'''iexpt '' = experiment number x10'/ &
i5,4x,'''yrflag'' = days in year flag'/ &
i5,4x,'''idm '' = longitudinal array size'/ &
i5,4x,'''jdm '' = latitudinal array size'/ &
'field time step model day', &
' k dens min max')
!
! --- surface fields
!
! --- identify the equation of state (sigver,thbase) on the first record
k =sigver
coord=thbase
!
if (kkout.gt.1 .or. l_arch(1)) then
call zaiowr(montg1,ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'montg1 ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(2)) then
call zaiowr(srfhgt,ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'srfhgt ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (sshflg.eq.1) then
! --- write out steric SSH.
if (kkout.gt.1 .or. l_arch(3)) then
call zaiowr(steric,ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'steric ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
endif !sshflg
if (kkout.gt.1) then !3-D archives only
call zaiowr(oneta(1-nbdy,1-nbdy,n),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'oneta ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !kkout>1
!
if (kkout.gt.1 .or. l_arch(4)) then
call zaiowr(surflx,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'surflx ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(5)) then
call zaiowr(wtrflx,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'wtrflx ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(18)) then
call zaiowr(salflx,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'salflx ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
!
! --- surtx and surty only output when selected in archs.input
if (kkout.eq.1 .and. l_arch(19)) then
call zaiowr(surtx, ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'surtx ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.eq.1 .and. l_arch(20)) then
call zaiowr(surty, ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'surty ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
!
if (kkout.gt.1 .or. l_arch(6)) then
call zaiowr(dpbl,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'bl_dpth ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(7)) then
call zaiowr(dpmixl(1-nbdy,1-nbdy,n),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'mix_dpth',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (iceflg.ne.0) then
if (kkout.gt.1 .or. l_arch(8)) then
call zaiowr(covice,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'covice ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(9)) then
if (iceflg.eq.1) then
call zaiowr(thkice,ip,.true., xmin,xmax, nopa, .false.)
else !from coupler
call zaiowr(si_h, ip,.true., xmin,xmax, nopa, .false.)
endif
if (mnproc.eq.1) then
write (nop,117) 'thkice ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(10)) then
call zaiowr(temice,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'temice ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
endif !write ice fields
!
! --- depth averaged fields
!
if (kkout.gt.1 .or. l_arch(11)) then
call zaiowr(ubavg(1-nbdy,1-nbdy,n),iu,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'u_btrop ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(12)) then
call zaiowr(vbavg(1-nbdy,1-nbdy,n),iv,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'v_btrop ',nstep,time,k,coord,xmin,xmax
k =0
coord=0.0
call flush(nop)
endif !1st tile
endif !l_arch
!
! --- dissipation fields
!
if (kkout.eq.1 .and. disp_count.gt.0) then
displd_mn(:,:) = displd_mn(:,:)/real(disp_count)
call zaiowr(displd_mn,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
k =0
coord=0.0
write (nop,117) 'disp_ld ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
dispqd_mn(:,:) = dispqd_mn(:,:)/real(disp_count)
call zaiowr(dispqd_mn,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
k =0
coord=0.0
write (nop,117) 'disp_qd ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
tidepg_mn(:,:) = tidepg_mn(:,:)/real(disp_count)
call zaiowr(tidepg_mn,ip,.true., xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
k =0
coord=0.0
write (nop,117) 'tide_pg ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
!
displd_mn(:,:) = 0.0
dispqd_mn(:,:) = 0.0
tidepg_mn(:,:) = 0.0
disp_count = 0
endif !linear and quadratic drag dissipation
!
! --- layer loop.
!
do 75 k=1,kkout
coord=sigma(k)
if (kkout.gt.1 .or. l_arch(13)) then
call zaiowr(u(1-nbdy,1-nbdy,k,n),iu,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'u-vel. ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(14)) then
call zaiowr(v(1-nbdy,1-nbdy,k,n),iv,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'v-vel. ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(15)) then
call zaiowr(dp(1-nbdy,1-nbdy,k,n),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'thknss ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(16)) then
call zaiowr(temp(1-nbdy,1-nbdy,k,n),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'temp ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !l_arch
if (kkout.gt.1 .or. l_arch(17)) then
call zaiowr(saln(1-nbdy,1-nbdy,k,n),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'salin ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !l_arch
!
! --- no tracers or diffusion for single layer case
!
if (kkout.gt.1) then
do ktr= 1,ntracr
call zaiowr(tracer(1-nbdy,1-nbdy,k,n,ktr),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'tracer ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
enddo !ktr
#if defined(STOKES)
if (stdarc) then
call zaiowr(usdp(1-nbdy,1-nbdy,k),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'tracer ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
call zaiowr(vsdp(1-nbdy,1-nbdy,k),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'tracer ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !stdarc
#endif
if (difout) then
call zaiowr(vcty(1-nbdy,1-nbdy,k+1),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 'viscty ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
call zaiowr(dift(1-nbdy,1-nbdy,k+1),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 't-diff ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
call zaiowr(difs(1-nbdy,1-nbdy,k+1),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,117) 's-diff ',nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
endif !difout
endif !kkout>1
75 continue
!
117 format (a8,' =',i11,f11.3,i3,f7.3,1p2e16.7)
!
! --- output time-averaged mass fluxes, if required
!
if (.not. (mxlkpp .or. mxlmy .or. mxlgiss) .and. kkout.eq.kk) then
do k=1,kk
coord=sigma(k)
call zaiowr(diaflx(1-nbdy,1-nbdy,k),ip,.true., &
xmin,xmax, nopa, .false.)
if (mnproc.eq.1) then
write (nop,118) 'diafx',intvl,nstep,time,k,coord,xmin,xmax
call flush(nop)
endif !1st tile
118 format (a5,a3,' =',i11,f11.3,i3,f7.3,1p2e16.7)
enddo
endif !diaflx
!
close (unit=nop)
call zaiocl(nopa)
!
call xcsync(no_flush)
!
endif !not 1-D
!
if (itest.gt.0 .and. jtest.gt.0) then
open (unit=nop,file=flnmarcvs(1:ldot)//'.txt',status='new') !uoff+13
call archiv_prof_out(n, iyear,iday,ihour, ittest,jttest, nop)
close (unit=nop)
endif !test point tile
!
call xcsync(no_flush)
!ccc
!ccc --- output to line printer
!ccc
!cc call prtmsk(ip,srfhgt,util3,idm,ii,jj,0.,100.0/g,
!cc . 'sea surface height (cm)')
!cc if(mxlkpp) call prtmsk(ip,dpbl,util3,idm,ii,jj,0.,1.*qonem,
!cc . 'turb. b.l. depth (m)')
!cc call prtmsk(ip,dpmixl,util3,idm,ii,jj,0.,1.*qonem,
!cc . 'mixed layer depth (m)')
!cc call prtmsk(ip,tmix,util3,idm,ii,jj,0.,10.,
!cc . 'mix.layer temp. (.1 deg)')
!cc call prtmsk(ip,smix,util3,idm,ii,jj,35.,100.,
!cc . 'mx.lay. salin. (.01 mil)')
!cc!$OMP PARALLEL DO PRIVATE(j,i)
!cc!$OMP& SCHEDULE(STATIC,jblk)
!cc do j=1-margin,jj+margin
!cc do i=1-margin,ii+margin
!cc if (iu(i,j).ne.0) then
!cc util1(i,j)=umix(i,j)+ubavg(i,j,n)
!cc endif !iu
!cc if (iv(i,j).ne.0) then
!cc util2(i,j)=vmix(i,j)+vbavg(i,j,n)
!cc endif !iv
!cc enddo !i
!cc enddo !j
!cc!$OMP END PARALLEL DO
!cc call prtmsk(iu(2,1),util1(2,1),util3,idm,ii-2,jj,0.,1000.,
!cc . 'mix.layer u vel. (mm/s)')
!cc call prtmsk(iv(1,2),util2(1,2),util3,idm,ii,jj-2,0.,1000.,
!cc . 'mix.layer v vel. (mm/s)')
!cc call prtmsk(iu(2,1),ubavg(2,1,n),util3,idm,ii-2,jj,0.,1000.,
!cc . 'barotrop. u vel. (mm/s)')
!cc call prtmsk(iv(2,1),vbavg(1,2,n),util3,idm,ii,jj-2,0.,1000.,
!cc . 'barotrop. v vel. (mm/s)')
return
end subroutine archiv
subroutine archiv_prof_init
!
! --- initialize for multi-location profile output.
!
logical lexist
integer ios,kpnt
!
! --- check that the requried directory exists
! --- not all compilers detect directories, so look for a dummy file.
!
inquire(file='ARCHP/archv.dummy.txt',exist=lexist)
if (.not.lexist) then
if (mnproc.eq.1) then
write (lp,*) 'file ARCHP/archv.dummy.txt must exist'
endif
call xcstop('(archv_prof_init)')
stop '(archv_prof_init)'
endif
!
! --- count the number of locations
!
open(unit=uoff+99,file=trim(flnminp)//'profile.input')
do kpnt= 1,999999
read(uoff+99,*,iostat=ios)
if (ios.ne.0) then
exit
endif
enddo !kpnt
npnts = kpnt - 1
if (npnts.eq.0) then
if (mnproc.eq.1) then
write (lp,*) 'profile.input is empty'
endif
call xcstop('(archv_prof_init)')
stop '(archv_prof_init)'
endif
!
allocate( ipnts(npnts), jpnts(npnts), cpnts(npnts) )
!
! --- profile.input contains one line per profile with 3 entries
! --- i and j array indexes followed by the name of the profile
!
rewind(unit=uoff+99)
do kpnt= 1,npnts
read(uoff+99,*) ipnts(kpnt),jpnts(kpnt),cpnts(kpnt)
enddo !kpnt
close (unit=uoff+99)
!
fpnts = .true. !initialize profile location files
return
end subroutine archiv_prof_init
subroutine archiv_prof(n, kkout, iyear,iday,ihour)
!
integer n, kkout, iyear,iday,ihour
!
# include "stmt_fns.h"
!
! --- multi-location profile output.
!
character*81, save :: flnmarcp !1 extra character for trailing "_"
integer, save :: ldot
integer :: ipnt,jpnt,kpnt,nop
!
if (npnts.eq.0) then
return
endif
!
if (fpnts) then ! initialize profile location files
flnmarcp = flnmarc
ldot = index(flnmarcp,'.',back=.true.)
if (ldot.eq.0) then
if (mnproc.eq.1) then
write (lp,*) 'need decimal point in flnmarcp'
write (lp,*) 'flnmarcp = ',trim(flnmarcp)
endif
call xchalt('(flnmarcp)')
stop '(flnmarcp)'
endif
ldot = min(ldot,len(flnmarcp)-12) !need 12 characters for archive date
!
if (proffq.ge.1.0/24.0) then
! --- indicate the archive date
write(flnmarcp(ldot+1:ldot+12),'(i4.4,a1,i3.3,a1,i2.2,a1)') &
iyear,'_',iday,'_',ihour,'_'
ldot=ldot+12
else
! --- indicate the archive time step
write(flnmarcp(ldot+1:ldot+12),'(i11.11,a1)') nstep,'_'
ldot=ldot+12
endif
endif !fpnts
nop =13+uoff
!
do kpnt= 1,npnts
ipnt = ipnts(kpnt) - i0
jpnt = jpnts(kpnt) - j0
!
if (ipnt.gt.0 .and. ipnt.le.ii .and. &
jpnt.gt.0 .and. jpnt.le.jj ) then
if (fpnts) then ! initialize profile location files
open (unit=nop,status='new', &
action='write',form='formatted', &
file='ARCHP/'//flnmarcp(1:ldot)//trim(cpnts(kpnt))//'.txt')
else !write at the end of existing profile files
open (unit=nop,status='old',position='append', &
action='write',form='formatted', &
file='ARCHP/'//flnmarcp(1:ldot)//trim(cpnts(kpnt))//'.txt')
endif !fpnts
call archiv_prof_out(n, iyear,iday,ihour, &
ipnts(kpnt),jpnts(kpnt), nop)
close (unit=nop)
endif !test point tile
enddo !kpnt
!
fpnts = .false. ! use existing profile location files
!
call xcsync(no_flush) !called on all tiles
return
end subroutine archiv_prof
subroutine archiv_prof_out(n, iyear,iday,ihour, ipoint,jpoint,nop)
#if defined(STOKES)
use mod_stokes ! Stokes Drift Velocity Module
#endif
!
integer n, iyear,iday,ihour, ipoint,jpoint,nop
!
# include "stmt_fns.h"
!
! --- on the owning tile only: write a text profile file to unit nop.
! --- open and close of the I/O unit is done outside this routine.
!
character*80 cformat
integer ipnt,ipnt1,jpnt,jpnt1,k,ktr
real ssha,sshn,sshs,sssc,sstc,ubpnt,upnt,vbpnt,vpnt
real difsp,sshb,opnt,sssa,sihpnt
real*8 sums
#if defined(STOKES)
real ubstk,ustk,ust0,vbstk,vstk,vst0
#endif
!
real, parameter :: difriv = 60.0 !river diffusion, cm**2/s
!
ipnt = ipoint - i0
jpnt = jpoint - j0
!
if (ipnt.gt.0 .and. ipnt.le.ii .and. &
jpnt.gt.0 .and. jpnt.le.jj ) then
! --- owning tile.
write (nop,'(3a / a,6i7,f9.3,f8.3,i7,i5.4,i4.3,i3.2)') &
'## expt idm jdm kdm', &
' iloc jloc lonloc latloc', &
' yrflag year day hr', &
'##',iexpt, itdm, jtdm, kdm, &
ipoint,jpoint, &
mod(plon(ipnt,jpnt),360.0),plat(ipnt,jpnt), &
yrflag,iyear,iday,ihour
!
ssha = srfhgt(ipnt,jpnt)
if (sshflg.eq.1) then
sshs = steric(ipnt,jpnt)
elseif (sshflg.eq.2) then
sshs = montg1(ipnt,jpnt)
else
sshs = ssha !assume all is steric
endif
sshn = ssha - sshs
!
opnt = oneta(ipnt,jpnt,n)
sshb = (opnt - 1.0)*pbot(ipnt,jpnt) !pressure units
!
sssa = (opnt* dp(ipnt,jpnt,1,n)*saln(ipnt,jpnt,1,n) - &
dp0k(1)*saln0)*qonem !layer 1 salt anomaly
sums = 0.d0
do k= 1,kdm
sums = sums + opnt*dp(ipnt,jpnt,k,n)*saln(ipnt,jpnt,k,n)
enddo !k
sums = (sums - pbot(ipnt,jpnt)*saln0)*qonem !salt anomaly, m.psu
!
if (sstflg.le.1) then
if (relaxf) then
sstc = twall(ipnt,jpnt,1,lc0)*wc0+ &
twall(ipnt,jpnt,1,lc1)*wc1+ &
twall(ipnt,jpnt,1,lc2)*wc2+ &
twall(ipnt,jpnt,1,lc3)*wc3
else
sstc = 99.9999
endif !relaxf
else !synoptic observed sst
if (natm.eq.2) then
sstc = seatmp(ipnt,jpnt,l0)*w0+ &
seatmp(ipnt,jpnt,l1)*w1
else
sstc = seatmp(ipnt,jpnt,l0)*w0+ &
seatmp(ipnt,jpnt,l1)*w1+ &
seatmp(ipnt,jpnt,l2)*w2+ &
seatmp(ipnt,jpnt,l3)*w3
endif !natm
endif !sstflg
if (relaxf) then
sssc = swall(ipnt,jpnt,1,lc0)*wc0+ &
swall(ipnt,jpnt,1,lc1)*wc1+ &
swall(ipnt,jpnt,1,lc2)*wc2+ &
swall(ipnt,jpnt,1,lc3)*wc3
else
sssc = 99.9999
endif !relaxf
!
! --- interpolate to the p-grid, but only if it requres no halo points
ipnt1 = min(ipnt+1,ii) !either ipnt+1 or ipnt
jpnt1 = min(jpnt+1,jj) !either jpnt+1 or jpnt
ubpnt = 0.5*(ubavg(ipnt,jpnt,n)+ubavg(ipnt1,jpnt, n))
vbpnt = 0.5*(vbavg(ipnt,jpnt,n)+vbavg(ipnt, jpnt1,n))
upnt = 0.5*( umix(ipnt,jpnt) + umix(ipnt1,jpnt ) ) + ubpnt
vpnt = 0.5*( vmix(ipnt,jpnt) + vmix(ipnt, jpnt1) ) + vbpnt
#if defined(STOKES)
ubstk = 0.5*(usdbavg(ipnt,jpnt)+usdbavg(ipnt1,jpnt ))
vbstk = 0.5*(vsdbavg(ipnt,jpnt)+vsdbavg(ipnt, jpnt1))
ust0 = usds(ipnt,jpnt)
vst0 = vsds(ipnt,jpnt)
!
! --- order is not optimal, constrained by ALL/bin/hycom_profile_list
! --- which only includes the fields up to vbavg (or up to nsterc)
write (nop,'(8a)') &
'## model-day srfhgt surflx', &
' dpbl dpmixl tmix smix thmix', &
' umix vmix ubavg vbavg steric nsterc', &
' oneta tclim sclim', &
' sswflx mixflx sstflx', &
' E-P sssE-P rivE-P bhtflx buoflx', &
' ustar hekman dpbbl', &
' usdbave vsdbave usd0 vsd0'
write (nop,'(a,f11.4,f8.2,f8.1,'// & !...surflx
'2f9.3,3f8.4,'// & !... thmix
'6f8.2,'// & !...nsterc
'3f8.4,'// & !... sclim
'3f8.1,'// & !...sstflx
'3f9.2,2f8.4,'// & !...buoflx
'f9.5, 2f9.3,'// & !... dpbbl
'4f8.2)') & !... vsd0
'#',time, & !model-day
ssha*100.0/g, & !cm
surflx(ipnt,jpnt), & !W/m**2
min( dpbl(ipnt,jpnt) *qonem, 9999.999), & !m
min(dpmixl(ipnt,jpnt,n)*qonem, 9999.999), & !m
tmix(ipnt,jpnt), & !degC
smix(ipnt,jpnt), & !psu
thmix(ipnt,jpnt)+thbase, & !SigmaT
max(-999.99,min(999.99, upnt*100.0)), & !cm/s
max(-999.99,min(999.99, vpnt*100.0)), & !cm/s
max(-999.99,min(999.99,ubpnt*100.0)), & !cm/s
max(-999.99,min(999.99,vbpnt*100.0)), & !cm/s
sshs*100.0/g, & !cm
sshn*100.0/g, & !cm
opnt, & !unitless
sstc, & !degC
sssc, & !psu
sswflx(ipnt,jpnt), & !W/m**2
mixflx(ipnt,jpnt), & !W/m**2
sstflx(ipnt,jpnt), & !W/m**2
wtrflx(ipnt,jpnt)*svref*8.64E7, & !mm/day
sssflx(ipnt,jpnt)*svref*8.64E7/saln(ipnt,jpnt,1,n), & !mm/day
rivflx(ipnt,jpnt)*svref*8.64E7, & !mm/day
bhtflx(ipnt,jpnt)*1.e6, & !1.e6*m**2/sec**3
buoflx(ipnt,jpnt)*1.e6, & !1.e6*m**2/sec**3
ustar(ipnt,jpnt), & !m/s?
min(hekman(ipnt,jpnt), 9999.999), & !m
min( dpbbl(ipnt,jpnt) *qonem, 9999.999), & !m
max(-999.99,min(999.99,ubstk*100.0)), & !cm/s
max(-999.99,min(999.99,vbstk*100.0)), & !cm/s
max(-999.99,min(999.99, ust0*100.0)), & !cm/s
max(-999.99,min(999.99, vst0*100.0)) !cm/s
#else
!
! --- order is not optimal, constrained by ALL/bin/hycom_profile_list
! --- which only includes the fields up to vbavg (or up to nsterc)
write (nop,'(7a)') &
'## model-day srfhgt surflx', &
' dpbl dpmixl tmix smix thmix', &
' umix vmix ubavg vbavg steric nsterc', &
' oneta tclim sclim', &
' sswflx mixflx sstflx', &
' E-P sssE-P rivE-P bhtflx buoflx', &
' ustar hekman dpbbl'
write (nop,'(a,f11.4,f8.2,f8.1,'// & !...surflx
'2f9.3,3f8.4,'// & !... thmix
'6f8.2,'// & !...nsterc
'3f8.4,'// & !... sclim
'3f8.1,'// & !...sstflx
'3f9.2,2f8.4,'// & !...buoflx
'f9.5, 2f9.3)') & !... dpbbl
'#',time, & !model-day
ssha*100.0/g, & !cm
surflx(ipnt,jpnt), & !W/m**2
min( dpbl(ipnt,jpnt) *qonem, 9999.999), & !m
min(dpmixl(ipnt,jpnt,n)*qonem, 9999.999), & !m
tmix(ipnt,jpnt), & !degC
smix(ipnt,jpnt), & !psu
thmix(ipnt,jpnt)+thbase, & !SigmaT
max(-999.99,min(999.99, upnt*100.0)), & !cm/s
max(-999.99,min(999.99, vpnt*100.0)), & !cm/s
max(-999.99,min(999.99,ubpnt*100.0)), & !cm/s
max(-999.99,min(999.99,vbpnt*100.0)), & !cm/s
sshs*100.0/g, & !cm
sshn*100.0/g, & !cm
opnt, & !unitless
sstc, & !degC
sssc, & !psu
sswflx(ipnt,jpnt), & !W/m**2
mixflx(ipnt,jpnt), & !W/m**2
sstflx(ipnt,jpnt), & !W/m**2
wtrflx(ipnt,jpnt)*svref*8.64E7, & !mm/day
sssflx(ipnt,jpnt)*svref*8.64E7/saln(ipnt,jpnt,1,n), & !mm/day
rivflx(ipnt,jpnt)*svref*8.64E7, & !mm/day
bhtflx(ipnt,jpnt)*1.e6, & !1.e6*m**2/sec**3
buoflx(ipnt,jpnt)*1.e6, & !1.e6*m**2/sec**3
ustar(ipnt,jpnt), & !m/s?
min(hekman(ipnt,jpnt), 9999.999), & !m
min( dpbbl(ipnt,jpnt) *qonem, 9999.999) !m
#endif
!
! --- An added line for mass constervation
write (nop,'(2a)') &
'## model-day srfhgt steric nsterc pbavg', &
' oneta salt1.anom salt.anom'
write (nop,'(a,f11.4,4f8.2,f8.5,2f12.2)') &
'#',time, & !model-day
ssha*100.0/g, & !cm
sshs*100.0/g, & !cm
sshn*100.0/g, & !cm
sshb*100.0*qonem, & !cm
opnt, & !1+eta, unitless
sssa, & !m.psu
sums !m.psu
!
if (iceflg.ne.0) then
if (.not.icegln) then
wflfrz(ipnt,jpnt) = wflice(ipnt,jpnt)
endif
if (iceflg.eq.1) then
sihpnt = thkice(ipnt,jpnt) !from icloan
else
sihpnt = si_h(ipnt,jpnt) !from coupler
endif
write (nop,'(2a / a,f11.4, 3f8.2,2f8.1,2f9.2)') &
'## model-day', &
' covice thkice temice flxice fswice iceE-P iceFRZ', &
'#',time, & !model-day
covice(ipnt,jpnt)*100.0, & !%
sihpnt, & !m
temice(ipnt,jpnt), & !degC
flxice(ipnt,jpnt), & !W/m**2
fswice(ipnt,jpnt), & !W/m**2
wflice(ipnt,jpnt)*svref*8.64E7, & !mm/day
wflfrz(ipnt,jpnt)*svref*8.64E7 !mm/day
endif !iceflg
#if defined(STOKES)
if (ntracr.eq.0) then
write(cformat,'(a)') '(4a)'
else
write(cformat,'(a,i2,a)') '(4a,', ntracr, 'a)'
endif
write (nop,cformat) &
'# k', &
' utot vtot p.temp saln p.dens', &
' thkns dpth viscty t-diff s-diff', &
' usdtot vsdtot', &
(' tracer',ktr=1,ntracr)
if (ntracr.eq.0) then
write(cformat,'(a)') &
'(i4,2f8.2,3f8.4,f9.3,f10.3,3f8.2,2f8.2)'
else
write(cformat,'(a,i2,a)') &
'(i4,2f8.2,3f8.4,f9.3,f10.3,3f8.2,2f8.2,', ntracr, 'f8.3)'
endif
#else
if (ntracr.eq.0) then
write(cformat,'(a)') '(3a)'
else
write(cformat,'(a,i2,a)') '(3a,', ntracr, 'a)'
endif
write (nop,cformat) &
'# k', &
' utot vtot p.temp saln p.dens', &
' thkns dpth viscty t-diff s-diff', &
(' tracer',ktr=1,ntracr)
if (ntracr.eq.0) then
write(cformat,'(a)') &
'(i4,2f8.2,3f8.4,f9.3,f10.3,3f8.2)'
else
write(cformat,'(a,i2,a)') &
'(i4,2f8.2,3f8.4,f9.3,f10.3,3f8.2,', ntracr, 'f8.3)'
endif
#endif
do k= 1,kk
upnt = 0.5*(u(ipnt,jpnt,k,n)+u(ipnt1,jpnt, k,n)) + ubpnt
vpnt = 0.5*(v(ipnt,jpnt,k,n)+v(ipnt, jpnt1,k,n)) + vbpnt
#if defined(STOKES)
ustk = 0.5*(usd(ipnt,jpnt,k)+usd(ipnt1,jpnt, k))
vstk = 0.5*(vsd(ipnt,jpnt,k)+vsd(ipnt, jpnt1,k))
#endif
difsp = min(9999.99,difs(ipnt,jpnt,k+1)*1.e4)
if (rivers(ipnt,jpnt, 1).ne.0.0 .and. &
p(ipnt,jpnt,k+1).lt.thkriv ) then
difsp = max(difsp, difriv)
endif
write (nop,cformat) &
k, &
max(-999.99,min(999.99,upnt*100.0)), & !cm/s
max(-999.99,min(999.99,vpnt*100.0)), & !cm/s
temp(ipnt,jpnt,k,n), & !degC
saln(ipnt,jpnt,k,n), & !psu
th3d(ipnt,jpnt,k,n)+thbase, & !SigmaT
dp(ipnt,jpnt,k,n)*qonem, & !m
(p(ipnt,jpnt,k+1)+p(ipnt,jpnt,k))*0.5*qonem, & !m
min(9999.99,vcty(ipnt,jpnt,k+1)*1.e4), & !cm**2/s
min(9999.99,dift(ipnt,jpnt,k+1)*1.e4), & !cm**2/s
difsp, & !cm**2/s
#if defined(STOKES)
max(-999.99,min(999.99,ustk*100.0)), & !cm/s
max(-999.99,min(999.99,vstk*100.0)), & !cm/s
#endif
(tracer(ipnt,jpnt,k,n,ktr),ktr=1,ntracr) !0-999?
enddo !k
else
write (lp,*) 'archiv_prof_out called on wrong tile'
write (lp,*) 'ipoint,jpoint = ',ipoint,jpoint
write (lp,*) 'ipnt, jpnt = ',ipnt, jpnt
write (lp,*)
call xchalt('(archiv_prof_out)')
stop '(archiv_prof_out)'
endif !point tile
return
end subroutine archiv_prof_out
subroutine archiv_tile(n, kkout, iyear,iday,ihour)
#if defined(STOKES)
use mod_stokes ! Stokes Drift Velocity Module
#endif
!
integer n, kkout, iyear,iday,ihour
real sssc,sstc
!
# include "stmt_fns.h"
!
! --- write a partial archive file on a tile by tile basis.
!
character*12 cdir
character*80 cformat
logical lexist
integer i,j,k,ktr,l,ldot,nop,nopa
real coord,xmin,xmax
!
! --- only write archive when the corresponing directory exists
! --- not all compilers detect directories, so look for a dummy file.
!
write(cdir,'(a6,i5.5,a1)') 'ARCHT/',mnproc,'/'
inquire(file=cdir//'archt.dummy.txt',exist=lexist)
if (.not.lexist) then
call xcsync(no_flush) !called on all tiles, see end of routine
return
endif
!
ldot = index(flnmarct,'.',back=.true.)
if (ldot.eq.0) then
if (mnproc.eq.1) then
write (lp,*) 'need decimal point in flnmarct'
write (lp,*) 'flnmarct = ',trim(flnmarct)
endif
call xchalt('(flnmarct)')
stop '(flnmarct)'
endif
ldot = min(ldot,len(flnmarct)-11) !need 11 characters for archive date