forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forfun.F90
4956 lines (4950 loc) · 166 KB
/
forfun.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
subroutine datefor(wday, iyr,mon,idy,ihr, yrflag)
use mod_xc ! HYCOM communication interface
implicit none
!
real*8 wday
integer iyr,mon,idy,ihr,yrflag
!
!**********
!*
! 1) convert date into 'model day', for yrflag=2,3,4 only.
!
! 2) for yrflag==4, all years are 365 days.
! for example:
! a) iyr=1,mon=1,idy=1 is the 1st day of the run,
! so wday would be 1.0.
! b) iyr=1,mon=1,idy=2 is the 2nd day of the run,
! so wday would be 2.0.
!
! 3) for yrflag==3, the 'model day' is the number of days since
! 001/1901 (which is model day 1.0).
! for example:
! a) iyr=1901,mon=1,idy=1, represents 0000z hrs on 01/01/1901
! so wday would be 1.0.
! a) iyr=1901,mon=1,idy=2, represents 0000z hrs on 02/01/1901
! so wday would be 2.0.
! year must be no less than 1901.0, and no greater than 2099.0.
! note that year 2000 is a leap year (but 1900 and 2100 are not).
!
! 4) for yrflag==2, all years are leap years.
! for example:
! a) iyr=1,mon=1,idy=1 is the 1st day of the run,
! so wday would be 1.0.
! a) iyr=1,mon=1,idy=2 is the 2nd day of the run,
! so wday would be 2.0.
!*
!**********
!
integer nleap
!
integer month(13)
data month / 0, 31, 59, 90, 120, 151, 181, &
212, 243, 273, 304, 334, 365 /
!
if (yrflag.eq.4) then
wday = 365.d0*(iyr-1) + month(mon) + idy-1 + ihr/24.0d0
elseif (yrflag.eq.3) then
nleap = (iyr-1901)/4
wday = 365.0d0*(iyr-1901) + nleap + month(mon) + idy + ihr/24.0d0
if (mod(iyr,4).eq.0 .and. mon.gt.2) then
wday = wday + 1.0d0
endif
elseif (yrflag.eq.2) then
wday = 366.d0*(iyr-1) + month(mon) + idy-1 + ihr/24.0d0
if (mon.gt.2) then
wday = wday + 1.0d0
endif
else
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in datefor - unsupported yrflag value'
write(lp,*)
endif !1st tile
call xcstop('(datefor)')
stop '(datefor)'
endif !yrflag
return
! end of datefor
end
!
!
subroutine forday(dtime,yrflag, iyear,iday,ihour)
use mod_xc ! HYCOM communication interface
implicit none
!
real*8 dtime
integer yrflag, iyear,iday,ihour
!
! --- converts model day to "calendar" date (year,ordinal-day,hour).
!
real*8 dtim1,day
integer iyr,nleap
!
if (yrflag.eq.0) then
! --- 360 days per model year, starting Jan 16
iyear = int((dtime+15.001d0)/360.d0) + 1
iday = mod( dtime+15.001d0 ,360.d0) + 1
ihour = (mod( dtime+15.001d0 ,360.d0) + 1.d0 - iday)*24.d0
!
elseif (yrflag.eq.1) then
! --- 366 days per model year, starting Jan 16
iyear = int((dtime+15.001d0)/366.d0) + 1
iday = mod( dtime+15.001d0 ,366.d0) + 1
ihour = (mod( dtime+15.001d0 ,366.d0) + 1.d0 - iday)*24.d0
!
elseif (yrflag.eq.2) then
! --- 366 days per model year, starting Jan 01
iyear = int((dtime+ 0.001d0)/366.d0) + 1
iday = mod( dtime+ 0.001d0 ,366.d0) + 1
ihour = (mod( dtime+ 0.001d0 ,366.d0) + 1.d0 - iday)*24.d0
!
elseif (yrflag.eq.3) then
! --- model day is calendar days since 01/01/1901
iyr = (dtime-1.d0)/365.25d0
nleap = iyr/4
dtim1 = 365.d0*iyr + nleap + 1.d0
day = dtime - dtim1 + 1.d0
if (dtim1.gt.dtime) then
iyr = iyr - 1
elseif (day.ge.367.d0) then
iyr = iyr + 1
elseif (day.ge.366.d0 .and. mod(iyr,4).ne.3) then
iyr = iyr + 1
endif
nleap = iyr/4
dtim1 = 365.d0*iyr + nleap + 1.d0
!
iyear = 1901 + iyr
iday = dtime - dtim1 + 1.001d0
ihour = (dtime - dtim1 + 1.001d0 - iday)*24.d0
!
elseif (yrflag.eq.4) then
! --- 365 days per model year, starting Jan 01 -No Leap year-
iyear = int((dtime+ 0.001d0)/365.d0) + 1
iday = mod( dtime+ 0.001d0 ,365.d0) + 1
ihour = (mod( dtime+ 0.001d0 ,365.d0) + 1.d0 - iday)*24.d0
!
else
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in forday - unsupported yrflag value'
write(lp,*)
endif !1st tile
call xcstop('(forday)')
stop '(forday)'
endif
return
end
!
!
subroutine fordate(dtime,yrflag, iyear,month,iday,ihour)
implicit none
!
real*8 dtime
integer yrflag, iyear,month,iday,ihour
!
! --- converts model day to "calendar" date (year,month,day,hour).
!
integer jday,k,m
!
integer month0(13,3)
data month0 / 1, 31, 61, 91, 121, 151, 181, &
211, 241, 271, 301, 331, 361, &
1, 32, 60, 91, 121, 152, 182, &
213, 244, 274, 305, 335, 366, &
1, 32, 61, 92, 122, 153, 183, &
214, 245, 275, 306, 336, 367 /
!
call forday(dtime,yrflag, iyear,jday,ihour)
!
if (yrflag.eq.3) then
if (mod(iyear,4).eq.0) then
k = 3 !leap year
else
k = 2 !standard year
endif
elseif (yrflag.eq.4) then
k = 2 !365-day year
elseif (yrflag.eq.0) then
k = 1 !360-day year
else
k = 3 !leap year
endif
do m= 1,12
if (jday.ge.month0(m, k) .and. &
jday.lt.month0(m+1,k) ) then
month = m
iday = jday - month0(m,k) + 1
endif
enddo
return
end
!
!
subroutine forfuna
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_za ! HYCOM I/O interface
implicit none
!
! --- initialize input of atmospheric forcing fields
!
! --- units of tau_x are N/m^2 (positive eastwards w.r.t. the grid)
! --- units of tau_y are N/m^2 (positive northwards w.r.t. the grid)
! --- units of wnd_x are m/s (positive eastwards w.r.t. the grid)
! --- units of wnd_y are m/s (positive northwards w.r.t. the grid)
! --- units of wndspd are m/s
! --- units of ustar are m/s
! --- units of airtmp are degC
! --- units of surtmp are degC
! --- units of seatmp are degC
! --- units of vapmix are kg/k
! --- units of spchum are kg/k
! --- units of mslprs are Pa (anomaly, offset from total by prsbas)
! --- units of precip are m/s (positive into ocean)
! --- units of radflx are w/m^2 (positive into ocean)
! --- units of swflx are w/m^2 (positive into ocean)
! --- units of offlux are w/m^2 (positive into ocean)
! --- units of oftaux are N/m^2 (positive eastwards w.r.t. the grid)
! --- units of oftauy are N/m^2 (positive northwards w.r.t. the grid)
!
! --- tau_x and tau_y are either on u&v grids or both on the p grid,
! --- depending on the value of blkdat input parameter "wndflg".
! --- in any case, they are always oriented along the local grid
! --- which need not be east-west and north-south.
! --- all other fields, including wnd* and ustar, are always on the p grid.
!
! --- I/O and array I/O units 899-910 are reserved for the entire run.
!
! --- all input fields must be defined at all grid points
!
integer mreca,mrecc,mreck,mrecr
common/rdforfi/ mreca,mrecc,mreck,mrecr
save /rdforfi/
!
integer lgth,mo
character preambl(5)*79
real pcmax,one,oneps
integer i,j
!
mreca=1
if (mnproc.eq.1) then
write (lp,*) ' now opening forcing fields ...'
endif !1st tile
call xcsync(flush_lp)
!
lgth = len_trim(flnmfor)
!
if (mslprf .or. flxflg.eq.6) then
call zaiopf(flnmfor(1:lgth)//'forcing.mslprs.a', 'old', 899)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+899,file=flnmfor(1:lgth)//'forcing.mslprs.b', &
status='old', action='read')
read (uoff+899,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 899)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1., &
!diag 'mslprs (Pa)')
endif !mslprf
!
if (windf) then
!
if (wndflg.lt.4) then
call zaiopf(flnmfor(1:lgth)//'forcing.tauewd.a', 'old', 901)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+901,file=flnmfor(1:lgth)//'forcing.tauewd.b', &
status='old', action='read')
read (uoff+901,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 901)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1000., &
!diag 'tau_x (x 1000 N/m^2 ) ')
!
call zaiopf(flnmfor(1:lgth)//'forcing.taunwd.a', 'old', 902)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+902,file=flnmfor(1:lgth)//'forcing.taunwd.b', &
status='old', action='read')
read (uoff+902,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 902)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1000., &
!diag 'tau_y (x 1000 N/m^2 ) ')
else !read 10m wind components
call zaiopf(flnmfor(1:lgth)//'forcing.wndewd.a', 'old', 901)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+901,file=flnmfor(1:lgth)//'forcing.wndewd.b', &
status='old', action='read')
read (uoff+901,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 901)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1., &
!diag 'wnd_x (m/s ) ')
!
call zaiopf(flnmfor(1:lgth)//'forcing.wndnwd.a', 'old', 902)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+902,file=flnmfor(1:lgth)//'forcing.wndnwd.b', &
status='old', action='read')
read (uoff+902,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 902)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1., &
!diag 'wnd_y (m/s) ')
endif !stress:wind
!
if (stroff) then
call zaiopf(flnmfor(1:lgth)//'forcing.ofstrs.a', 'old', 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+916,file=flnmfor(1:lgth)//'forcing.ofstrs.b', &
status='old', action='read')
read (uoff+916,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(oftaux, 916)
call rdmonth(oftauy, 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
close( unit=uoff+916)
endif
call zaiocl(916)
!diag call prtmsk(ip,oftaux,util2,idm,idm,jdm, 0.,1.0, &
!diag 'taux offset (N) ')
!diag call prtmsk(ip,oftauy,util2,idm,idm,jdm, 0.,1.0, &
!diag 'tauy offset (N) ')
else
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
oftaux(i,j) = 0.0
oftauy(i,j) = 0.0
enddo !i
enddo !j
endif !stroff:else
!
endif ! windf = .true.
!
if (thermo) then
!
if (ustflg.eq.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.ustar.a', 'old', 900)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+900,file=flnmfor(1:lgth)//'forcing.ustar.b', &
status='old', action='read')
read (uoff+900,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 900)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1000., &
!diag 'ustar (x 1000 ???)')
endif !ustflg.eq.3
!
if (wndflg.lt.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.wndspd.a', 'old', 903)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+903,file=flnmfor(1:lgth)//'forcing.wndspd.b', &
status='old', action='read')
read (uoff+903,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 903)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,10., &
!diag 'wind speed (x 10 m/s)')
endif !wndflg.lt.3
!
if (flxflg.ne.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.airtmp.a', 'old', 904)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+904,file=flnmfor(1:lgth)//'forcing.airtmp.b', &
status='old', action='read')
read (uoff+904,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 904)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,10., &
!diag 'air temperature (0.1 c)')
!
if (flxflg.ne.5) then
call zaiopf(flnmfor(1:lgth)//'forcing.vapmix.a', 'old', 905)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+905,file=flnmfor(1:lgth)//'forcing.vapmix.b', &
status='old', action='read')
read (uoff+905,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 905)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,10000., &
!diag 'mixing ratio (0.1 g/kg)')
else !flgflg==5
call zaiopf(flnmfor(1:lgth)//'forcing.spchum.a', 'old', 905)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+905,file=flnmfor(1:lgth)//'forcing.spchum.b', &
status='old', action='read')
read (uoff+905,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 905)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,10000., &
!diag 'specific humidity (0.1 g/kg)')
endif !flxflg 4,5
endif !flxflg.ne.3
!
if (pcipf) then
call zaiopf(flnmfor(1:lgth)//'forcing.precip.a', 'old', 906)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+906,file=flnmfor(1:lgth)//'forcing.precip.b', &
status='old', action='read')
read (uoff+906,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
pcmax = -huge(pcmax)
call rdmonth(util1, 906)
do j=1,jj
do i=1,ii
pcmax = max(pcmax,util1(i,j))
enddo
enddo
call xcmaxr(pcmax)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,86400.*36000., &
!diag 'precipitation (cm/year) ')
!
! --- zero fields implies no surface salinity flux
pcipf = pcmax.ne.0.0
if (.not.pcipf) then
if (mnproc.eq.1) then
write (lp,*)
write (lp,*) '***** no surface salinity flux *****'
write (lp,*)
endif !1st tile
call xcsync(flush_lp)
endif !pcipf actually .false.
endif !pcipf initially .true.
!
call zaiopf(flnmfor(1:lgth)//'forcing.radflx.a', 'old', 907)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+907,file=flnmfor(1:lgth)//'forcing.radflx.b', &
status='old', action='read')
read (uoff+907,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 907)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1.0, &
!diag 'net radiation (w/m^2 ) ')
!
call zaiopf(flnmfor(1:lgth)//'forcing.shwflx.a', 'old', 908)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+908,file=flnmfor(1:lgth)//'forcing.shwflx.b', &
status='old', action='read')
read (uoff+908,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 908)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1.0, &
!diag 'sw radiation (w/m^2 ) ')
!
endif ! thermo = .true.
!
if (lwflag.eq.2 .or. sstflg.eq.2 .or. &
icmflg.eq.2 .or. ticegr.eq.0.0 ) then
call zaiopf(flnmfor(1:lgth)//'forcing.surtmp.a', 'old', 909)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+909,file=flnmfor(1:lgth)//'forcing.surtmp.b', &
status='old', action='read')
read (uoff+909,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 909)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1.0, &
!diag 'SST from lw rad (degC) ')
endif !surtmp
!
if (sstflg.eq.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.seatmp.a', 'old', 910)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+910,file=flnmfor(1:lgth)//'forcing.seatmp.b', &
status='old', action='read')
read (uoff+910,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(util1, 910)
!diag call prtmsk(ip,util1,util2,idm,idm,jdm, 0.,1.0, &
!diag 'SST from obs. (degC) ')
endif !sstflg.eq.3
!
if (flxoff) then
call zaiopf(flnmfor(1:lgth)//'forcing.offlux.a', 'old', 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+916,file=flnmfor(1:lgth)//'forcing.offlux.b', &
status='old', action='read')
read (uoff+916,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(offlux, 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
close( unit=uoff+916)
endif
call zaiocl(916)
!diag call prtmsk(ip,offlux,util2,idm,idm,jdm, 0.,1.0, &
!diag 'heat flux offset (w/m^2 ) ')
else
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
offlux(i,j) = 0.0
enddo !i
enddo !j
endif !flxoff:else
!
! --- jerlov used in call to swfrac_ij
if (jerlv0.gt.0) then
! --- calculate jerlov water type,
! --- which governs the penetration depth of shortwave radiation.
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
! --- map shallow depths to high jerlov numbers
jerlov(i,j)=6-max(1,min(5,int(depths(i,j)/15.0)))
jerlov(i,j)=max(jerlv0,jerlov(i,j))
enddo
enddo
else
! --- jerlv0= 0 uses an input annual/monthly kpar field
! --- jerlv0=-1 uses an input annual/monthly chl field
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
jerlov(i,j)=jerlv0
enddo
enddo
endif
!
if (mnproc.eq.1) then
write (lp,*) ' ...finished opening forcing fields'
endif !1st tile
call xcsync(flush_lp)
!
return
end
!
!
subroutine forfund(tiddrg)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_za ! HYCOM I/O interface
implicit none
!
integer tiddrg
!
! --- initialize tidal drag tensor
!
! --- units of dragrh and drgten are m/s on the p-grid.
! --- dragrh and drgten should be positive.
!
! --- I/O and array I/O unit 925 used here, but not reserved.
!
! --- all input fields must be defined at all grid points
!
integer i,j,k,l,lgth
!
if (mnproc.eq.1) then
if (tiddrg.eq.1) then
write (lp,*) ' now opening tidal drag rh field ...'
else
write (lp,*) ' now opening tidal drag tensor fields ...'
endif !tiddrg
endif !1st tile
call xcsync(flush_lp)
!
lgth = len_trim(flnmfor)
!
if (tiddrg.eq.1) then
! --- original filename, 1 field (rh)
call zaiopf(flnmfor(1:lgth)//'tidal.rh.a', 'old', 925)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+925,file=flnmfor(1:lgth)//'tidal.rh.b', &
status='old', action='read')
endif !1st tile
call rdmonth(util1, 925)
call xctilr( util1,1,1, nbdy,nbdy, halo_ps)
! --- cast scalar to tensor drag.
drgten(1,1,:,:) = drgscl*util1(:,:) !uu
drgten(1,2,:,:) = 0.0 !uv
drgten(2,1,:,:) = 0.0 !vu
drgten(2,2,:,:) = drgscl*util1(:,:) !vv
else
! --- drag tensor filename, 4 fields uu, uv, vv, vu
call zaiopf(flnmfor(1:lgth)//'tidal.tensor.a', 'old', 925)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+925,file=flnmfor(1:lgth)//'tidal.tensor.b', &
status='old', action='read')
endif !1st tile
call rdmonth(util1, 925)
call xctilr( util1,1,1, nbdy,nbdy, halo_ps)
drgten(1,1,:,:) = drgscl*util1(:,:) !uu
call rdmonth(util1, 925)
call xctilr( util1,1,1, nbdy,nbdy, halo_ps)
drgten(1,2,:,:) = drgscl*util1(:,:) !uv
call rdmonth(util1, 925)
call xctilr( util1,1,1, nbdy,nbdy, halo_ps)
drgten(2,1,:,:) = drgscl*util1(:,:) !vu
call rdmonth(util1, 925)
call xctilr( util1,1,1, nbdy,nbdy, halo_ps)
drgten(2,2,:,:) = drgscl*util1(:,:) !vv
endif !tiddrg
if (mnproc.eq.1) then ! .b file from 1st tile only
close (unit=uoff+925)
endif
call zaiocl(925)
!
if (mnproc.eq.1) then
if (tiddrg.eq.1) then
write (lp,*) ' ...finished opening tidal drag rh field'
else
write (lp,*) ' ...finished opening tidal drag tensor fields'
endif !tiddrg
endif !1st tile
call xcsync(flush_lp)
!
return
end
!
!
subroutine forfunh(dtime)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_za ! HYCOM I/O interface
implicit none
!
real*8 dtime
!
! --- high frequency atmospheric forcing field processing.
!
! --- units of tau_x are N/m^2 (positive eastwards w.r.t. the grid)
! --- units of tau_y are N/m^2 (positive northwards w.r.t. the grid)
! --- units of wnd_x are m/s (positive eastwards w.r.t. the grid)
! --- units of wnd_y are m/s (positive northwards w.r.t. the grid)
! --- units of wndspd are m/s
! --- units of ustar are m/s
! --- units of airtmp are degC
! --- units of surtmp are degC
! --- units of seatmp are degC
! --- units of stoc_t are degC/hr
! --- units of stoc_s are psu/hr
! --- units of stoc_u are m/s/hr on the u-grid
! --- units of stoc_v are m/s/hr on the v-grid
! --- units of vapmix are kg/kg
! --- units of spchum are kg/k
! --- units of mslprs are Pa (anomaly, offset from total by prsbas)
! --- units of precip are m/s (positive into ocean)
! --- units of radflx are w/m^2 (positive into ocean)
! --- units of swflx are w/m^2 (positive into ocean)
! --- units of offlux are w/m^2 (positive into ocean)
!
! --- tau_x and tau_y are either on u&v grids or both on the p grid,
! --- depending on the value of blkdat input parameter "wndflg".
! --- in any case, they are always oriented along the local grid
! --- which need not be east-west and north-south.
! --- all other fields, including wnd* and ustar, are always on the p grid.
!
! --- I/O and array I/O units 895-910 are reserved for the entire run.
!
! --- all input fields must be defined at all grid points
!
real*8 dtime0,dtime1
save dtime0,dtime1
!
character preambl(5)*79,cline*80
real pcmax
integer i,ios,iunit,j,lgth,nrec
! ESPC --- add
#if ! defined(ESPC_ATM) && ! defined(ESPC_NAVGEM) && ! defined(ESPC_DATA_ATM)
!
! --- w0 negative on first call only.
if (w0.lt.-1.0) then
!
! --- initialize forcing fields
!
if (.not.windf) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in forfunh - windf must be .true.'
write(lp,*)
endif !1st tile
call xcstop('(forfunh)')
stop '(forfunh)'
elseif (.not.thermo) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in forfunh - thermo must be .true.'
write(lp,*)
endif !1st tile
call xcstop('(forfunh)')
stop '(forfunh)'
endif
!
if (natm.eq.4) then
! --- linear interpolation in time, so slots 3 and 4 are zero.
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
taux(i,j,natm-1) = 0.0
taux(i,j,natm) = 0.0
tauy(i,j,natm-1) = 0.0
tauy(i,j,natm) = 0.0
wndspd(i,j,natm-1) = 0.0
wndspd(i,j,natm) = 0.0
ustara(i,j,natm-1) = 0.0
ustara(i,j,natm) = 0.0
airtmp(i,j,natm-1) = 0.0
airtmp(i,j,natm) = 0.0
vapmix(i,j,natm-1) = 0.0
vapmix(i,j,natm) = 0.0
mslprs(i,j,natm-1) = 0.0
mslprs(i,j,natm) = 0.0
precip(i,j,natm-1) = 0.0
precip(i,j,natm) = 0.0
radflx(i,j,natm-1) = 0.0
radflx(i,j,natm) = 0.0
swflx(i,j,natm-1) = 0.0
swflx(i,j,natm) = 0.0
surtmp(i,j,natm-1) = 0.0
surtmp(i,j,natm) = 0.0
seatmp(i,j,natm-1) = 0.0
seatmp(i,j,natm) = 0.0
stoc_t(i,j,natm-1) = 0.0
stoc_t(i,j,natm) = 0.0
stoc_s(i,j,natm-1) = 0.0
stoc_s(i,j,natm) = 0.0
stoc_u(i,j,natm-1) = 0.0
stoc_u(i,j,natm) = 0.0
stoc_v(i,j,natm-1) = 0.0
stoc_v(i,j,natm) = 0.0
enddo
enddo
endif !natm.eq.4
!
! --- open all forcing files.
if (mnproc.eq.1) then
write (lp,*) ' now initializing forcing fields ...'
endif !1st tile
call xcsync(flush_lp)
!
lgth = len_trim(flnmfor)
!
if (stfflg.gt.0) then
call zaiopf(flnmfor(1:lgth)//'forcing.stoc_t.a', 'old', 896)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+896,file=flnmfor(1:lgth)//'forcing.stoc_t.b', &
status='old', action='read')
read (uoff+896,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call zaiopf(flnmfor(1:lgth)//'forcing.stoc_s.a', 'old', 897)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+897,file=flnmfor(1:lgth)//'forcing.stoc_s.b', &
status='old', action='read')
read (uoff+897,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !stfflg>0
!
if (stfflg.eq.2) then
call zaiopf(flnmfor(1:lgth)//'forcing.stoc_u.a', 'old', 895)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+895,file=flnmfor(1:lgth)//'forcing.stoc_u.b', &
status='old', action='read')
read (uoff+895,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call zaiopf(flnmfor(1:lgth)//'forcing.stoc_v.a', 'old', 898)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+898,file=flnmfor(1:lgth)//'forcing.stoc_v.b', &
status='old', action='read')
read (uoff+898,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !stfflg==2
!
if (mslprf .or. flxflg.eq.6) then
call zaiopf(flnmfor(1:lgth)//'forcing.mslprs.a', 'old', 899)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+899,file=flnmfor(1:lgth)//'forcing.mslprs.b', &
status='old', action='read')
read (uoff+899,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !mslprf
!
if (wndflg.lt.4) then
call zaiopf(flnmfor(1:lgth)//'forcing.tauewd.a', 'old', 901)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+901,file=flnmfor(1:lgth)//'forcing.tauewd.b', &
status='old', action='read')
read (uoff+901,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
!
call zaiopf(flnmfor(1:lgth)//'forcing.taunwd.a', 'old', 902)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+902,file=flnmfor(1:lgth)//'forcing.taunwd.b', &
status='old', action='read')
read (uoff+902,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
else !read 10m wind components
call zaiopf(flnmfor(1:lgth)//'forcing.wndewd.a', 'old', 901)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+901,file=flnmfor(1:lgth)//'forcing.wndewd.b', &
status='old', action='read')
read (uoff+901,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
!
call zaiopf(flnmfor(1:lgth)//'forcing.wndnwd.a', 'old', 902)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+902,file=flnmfor(1:lgth)//'forcing.wndnwd.b', &
status='old', action='read')
read (uoff+902,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !stress:wind
!
if (stroff) then
call zaiopf(flnmfor(1:lgth)//'forcing.ofstrs.a', 'old', 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+916,file=flnmfor(1:lgth)//'forcing.ofstrs.b', &
status='old', action='read')
read (uoff+916,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(oftaux, 916)
call rdmonth(oftauy, 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
close( unit=uoff+916)
endif
call zaiocl(916)
!diag call prtmsk(ip,oftaux,util2,idm,idm,jdm, 0.,1.0, &
!diag 'taux offset (N) ')
!diag call prtmsk(ip,oftauy,util2,idm,idm,jdm, 0.,1.0, &
!diag 'tauy offset (N) ')
else
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
oftaux(i,j) = 0.0
oftauy(i,j) = 0.0
enddo !i
enddo !j
endif !stroff:else
!
if (ustflg.eq.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.ustar.a', 'old', 900)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+900,file=flnmfor(1:lgth)//'forcing.ustar.b', &
status='old', action='read')
read (uoff+900,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !ustflg.eq.3
!
if (wndflg.lt.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.wndspd.a', 'old', 903)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+903,file=flnmfor(1:lgth)//'forcing.wndspd.b', &
status='old', action='read')
read (uoff+903,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !wndflg.lt.3
!
if (flxflg.ne.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.airtmp.a', 'old', 904)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+904,file=flnmfor(1:lgth)//'forcing.airtmp.b', &
status='old', action='read')
read (uoff+904,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
!
if (flxflg.ne.5) then
call zaiopf(flnmfor(1:lgth)//'forcing.vapmix.a', 'old', 905)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+905,file=flnmfor(1:lgth)//'forcing.vapmix.b', &
status='old', action='read')
read (uoff+905,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
else !flgflg==5
call zaiopf(flnmfor(1:lgth)//'forcing.spchum.a', 'old', 905)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+905,file=flnmfor(1:lgth)//'forcing.spchum.b', &
status='old', action='read')
read (uoff+905,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !flxflg 4,5
endif !flxflg.ne.3
!
if (pcipf) then
call zaiopf(flnmfor(1:lgth)//'forcing.precip.a', 'old', 906)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+906,file=flnmfor(1:lgth)//'forcing.precip.b', &
status='old', action='read')
read (uoff+906,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !pcipf
!
call zaiopf(flnmfor(1:lgth)//'forcing.radflx.a', 'old', 907)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+907,file=flnmfor(1:lgth)//'forcing.radflx.b', &
status='old', action='read')
read (uoff+907,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
!
call zaiopf(flnmfor(1:lgth)//'forcing.shwflx.a', 'old', 908)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+908,file=flnmfor(1:lgth)//'forcing.shwflx.b', &
status='old', action='read')
read (uoff+908,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
!
if (lwflag.eq.2 .or. sstflg.eq.2 .or. &
icmflg.eq.2 .or. ticegr.eq.0.0 ) then
call zaiopf(flnmfor(1:lgth)//'forcing.surtmp.a', 'old', 909)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+909,file=flnmfor(1:lgth)//'forcing.surtmp.b', &
status='old', action='read')
read (uoff+909,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif !surtmp
!
if (sstflg.eq.3) then
call zaiopf(flnmfor(1:lgth)//'forcing.seatmp.a', 'old', 910)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+910,file=flnmfor(1:lgth)//'forcing.seatmp.b', &
status='old', action='read')
read (uoff+910,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
endif
!
! ESPC --- add
# endif
if (flxoff) then
call zaiopf(flnmfor(1:lgth)//'forcing.offlux.a', 'old', 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+916,file=flnmfor(1:lgth)//'forcing.offlux.b', &
status='old', action='read')
read (uoff+916,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
call rdmonth(offlux, 916)
if (mnproc.eq.1) then ! .b file from 1st tile only
close( unit=uoff+916)
endif
call zaiocl(916)
else
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
offlux(i,j) = 0.0
enddo !i
enddo !j
endif !flxoff:else
! ESPC ---add
#if ! defined(ESPC_ATM) && ! defined(ESPC_NAVGEM) && ! defined(ESPC_DATA_ATM)
!
! --- skip ahead to the start time.
nrec = 0
dtime1 = huge(dtime1)
do ! infinate loop, with exit at end
dtime0 = dtime1
nrec = nrec + 1
call zagetc(cline,ios, uoff+901)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in forfunh - hit end of input'
write(lp,*) 'dtime0,dtime1 = ',dtime0,dtime1
write(lp,*) 'dtime = ',dtime
write(lp,*)
endif !1st tile
call xcstop('(forfunh)')
stop '(forfunh)'
endif
i = index(cline,'=')
read (cline(i+1:),*) dtime1
if (yrflag.eq.2) then
if (nrec.eq.1 .and. abs(dtime1-1096.0d0).gt.0.01) then
!
! --- climatology must start on wind day 1096.0, 01/01/1904.
if (mnproc.eq.1) then
write(lp,'(a)') cline
write(lp,'(/ a,a / a,g15.6 /)') &