-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmetdata_ecmwf.f90
1677 lines (1472 loc) · 64.4 KB
/
metdata_ecmwf.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
!//=========================================================================
!// Oslo CTM3
!//=========================================================================
!// Based on UCI CTM core p-7.1 (1/2013).
!//
!// Ole Amund Sovde, November 2015
!//=========================================================================
!// Routine for reading meteorological data from ECMWF, from nedCDF4 files.
!//=========================================================================
module metdata_ecmwf
!//-----------------------------------------------------------------------
!// MODULE: metdata_ecmwf
!// DESCRIPTION: Routine for reading meteorological data from ECMWF,
!// stored on nedCDF4 format.
!//
!// Contains
!// subroutine update_metdata
!// subroutine fluxfilter2
!// subroutine data2mpblocks
!// subroutine gotData
!// subroutine skipData
!//-----------------------------------------------------------------------
use cmn_size, only: LPAR
!//-----------------------------------------------------------------------
implicit none
!//-----------------------------------------------------------------------
integer :: LMAP(LPAR+1)
!// ----------------------------------------------------------------------
character(len=*), parameter, private :: f90file = 'metdata_ecmwf.f90'
!//-----------------------------------------------------------------------
save
private
public update_metdata
!//-----------------------------------------------------------------------
contains
!//-----------------------------------------------------------------------
subroutine update_metdata(ILOOP, DTMET, NMET)
!//---------------------------------------------------------------------
!// Read input data. This version reads netCDF4 files, where all data
!// for one time step (NMET) is located in a single file.
!//
!// This routine assumes meteorology is to be updated each NMET.
!//
!// Ole Amund Sovde, April 2015
!//---------------------------------------------------------------------
use cmn_precision, only: r8, r4
use cmn_size, only: IPARW, JPARW, LPARW, LWEPARW, &
IPAR, JPAR, IDGRD, JDGRD, &
LPAR, LWEPAR, LWDPAR, &
LOSLOCHEM, LOSLOCTROP, NRMETD, LDUST
use cmn_ctm, only: JYEAR, JMON, JDAY, JDATE, GMTAU, &
JDATE_NEXT, JMON_NEXT, JYEAR_NEXT, &
LMMAP, XLMMAP, TMON, TMET, &
ALP, ALPV, TRIG, IFAX, LDEG, ZDEGI, ZDEGJ, IMAP, JMAP, &
XYZA, XYZB, IMEPZ, DD, SS, ETAAW, ETABW, ETAA, ETAB, &
WGLYE, WGLYG, YDGRD, AREAXYW, AREAXY, PLAND, LFIXMET
use cmn_met, only: P, U, V, T, Q, CWETN, CWETE, CWETD, CENTU, CENTD, &
PRECCNV, PRECLS, ZOFLE, &
CLDFR, CLDLWC, CLDIWC, &
SLH, SHF, SMF, SFT, SFQ, SFU, SFV, BLH, BLH_CUR, BLH_NEXT, LBLH, &
SA, PVU, UMS, VMS, CI, SD, SMLT, ES, SNFL, PhotActRad, MSLP, USTR, &
SWVL1, SWVL3, STL1, &
PMEAN, PMEANW, MYEAR, &
metTYPE, MPATH1, MPATH2, MFILE3
use cmn_parameters, only: M_AIR, R_UNIV, R_AIR, R_H2O, A0, CPI
use cloudjx, only: SWSTORE, CLDSTORE, TYPSTORE, RAN4, IRAN0, &
LCLDAVG, LCLDQMD, LCLDQMN, LCLDRANA, LCLDRANQ
use regridding, only: TRUNG4, TRUNG8
use utilities, only: ctmExitC, CFRMIN,CIWMIN
use ncutils, only: get_netcdf_var_2d, get_netcdf_var_3d
use dust_oslo, only: dust_set_ssrd, dust_set_strd, dust_set_SWVL1
use physics_oslo, only: get_pvu, ijlw2lij
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
integer, intent(in) :: ILOOP, & ! <=0, init, > 0 ordinary run
NMET ! the meteorological timestep
real(r8), intent(in) :: DTMET ! meteorological time step [s]
!//---------------------------------------------------------------------
logical, parameter :: VERBOSE = .false.
real(r8), parameter :: EPS = 0.01_r8 ! minimum cloud fraction
!// Limits for convective fluxes
real(r8), parameter :: mincwetelim = 3.8e-4_r8
real(r8), parameter :: maxcwetdlim = -2.0e-5_r8
real(r8), parameter :: mincdetulim = 1.e-4_r8
real(r8), parameter :: mincdetdlim = 1.e-6_r8
!// Local parameters
real(r8) :: &
VEDGE, BAND, DETA, DETB, DELP, &
ZCOS, ZDT, SFTD, LV, ESAT, SDEN, &
DELZ, QMIN, ZTOP, ZBOT, ZMID, &
DMASS, PSRF, &
POFLE(LPAR+1)
!// Indices
integer :: I,J,II,JJ,L,LL
!// To be read from file
logical :: fex
!// Filename for metdata
character(len=160) :: FNAME, FNAME_NEXT
character(len=2) :: CMON, CDATE, CUTC
integer :: NMET_NEXT
!//---------------------------------------------------------------------
!// Allocatable arrays - double precision
real(r8), dimension(:), allocatable :: &
UTMP(:)
real(r8), dimension(:,:), allocatable :: &
VTMP, PW, EWSS, NSSS, W2D, R8XY
!real(r8), dimension(:,:), allocatable :: &
! LSPREC, CNVPREC
real(r8), dimension(:,:,:), allocatable :: &
TW, QW, CLDFRW, CLDIWCW, CLDLWCW, CDETU, CDETD, &
ZOFLEW, W3Da, W3Db, R8XYZ
!// --------------------------------------------------------------------
character(len=*), parameter :: subr = 'update_metdata'
!//---------------------------------------------------------------------
!// Allocate 3D arrays - native resolution
allocate( VTMP(IPARW,JPARW), UTMP(IPARW), &
W3Da(IPARW,JPARW,LPARW), W3Db(IPARW,JPARW,LPARW), &
CLDFRW(IPARW,JPARW,LWEPAR), &
CLDIWCW(IPARW,JPARW,LWEPAR), CLDLWCW(IPARW,JPARW,LWEPAR) )
!// Allocate 3D arrays - native horizontal resolution
allocate( ZOFLEW(LPAR+1,IPARW,JPARW), QW(IPARW,JPARW,LPAR), &
TW(IPARW,JPARW,LPAR) )
!// Allocate 3D arrays - window resolution (IPAR/JPAR)
allocate( CDETU(IPAR,JPAR,LWEPAR), CDETD(IPAR,JPAR,LWDPAR), &
R8XYZ(IPAR,JPAR,LPARW) )
!// Allocate 2D arrays - native resolution
allocate( PW(IPARW,JPARW), W2D(IPARW,JPARW) )
!// Allocate 2D arrays - window resolution (IPAR/JPAR)
allocate( EWSS(IPAR,JPAR), NSSS(IPAR,JPAR), R8XY(IPAR,JPAR) )
!allocate( LSPREC(IPAR,JPAR),CNVPREC(IPAR,JPAR) )
!//---------------------------------------------------------------------
!// Initialize
!// Time step for meteorological data is DTMET
ZDT = 1._r8 / DTMET
!// Define minimum humidity QMIN in kg/kg
QMIN = 3.e-6_r8 * 18._r8 / M_AIR
!//UPDATE
!// locate the position of random number sequence based on year/day/hour
IRAN0 = 1 + 3*(JYEAR - 1900) + 7*JDAY + 11*nint(GMTAU)
!// File name for this DAY/NMET
write(CUTC(1:2),'(i2.2)') (NMET - 1) * 24/NRMETD ! Time UTC
write(CDATE(1:2),'(i2.2)') JDATE ! Date
write(CMON(1:2),'(i2.2)') JMON ! Month
write(MPATH2(1:4),'(i4.4)') MYEAR ! Year
if (trim(metTYPE) .eq. 'ECMWF_oIFSnc4') then
!// ECMWF Open IFS netcdf4 file
!// Date yYYYYmMMdDDhHH
!// Filename: ECopenIFSc38r1_yYYYYmMMdDDhHH_T159N80L60.nc
write(MFILE3(16:29),'(a1,i4.4,a1,i2.2,a1,a2,a1,a2)') &
'y',MYEAR,'m',JMON,'d',CDATE,'h',CUTC
FNAME = trim(MPATH1)//trim(MPATH2)//'/'//CMON//'/'// &
trim(MFILE3)//'.nc'
!// File for next time step
if (NMET .eq. 8) then
NMET_NEXT = 1
write(CUTC(1:2),'(i2.2)') (NMET_NEXT - 1) * 24/NRMETD ! Time UTC
write(CDATE(1:2),'(i2.2)') JDATE_NEXT ! Date
write(CMON(1:2),'(i2.2)') JMON_NEXT ! Month
if (.not.LFIXMET) then
i = JYEAR_NEXT
else
i = MYEAR
end if
write(MPATH2(1:4),'(i4.4)') i ! Year
else
NMET_NEXT = NMET + 1
if (.not.LFIXMET) then
i = JYEAR
else
i = MYEAR
end if
write(CUTC(1:2),'(i2.2)') (NMET_NEXT - 1) * 24/NRMETD ! Time UTC
end if
write(MFILE3(16:29),'(a1,i4.4,a1,i2.2,a1,a2,a1,a2)') &
'y',i,'m',JMON_NEXT,'d',CDATE,'h',CUTC
FNAME_NEXT = trim(MPATH1)//trim(MPATH2)//'/'//CMON//'/'// &
trim(MFILE3)//'.nc'
else
write(6,'(a)') f90file//':'//subr// &
': Not set up for metTYPE: '//trim(metTYPE)
if (trim(metTYPE) .eq. 'ECMWF_oIFS') then
write(6,'(a)') '* If you do not want netcdf4 files, you '// &
'should use metdata_ecmwf_uioformat.f90 instead'
end if
stop
end if
!// Check if files exist
inquire(FILE=trim(FNAME), exist=fex)
if (.not. fex) then
write(6,'(a)') f90file//':'//subr// &
': No such file: '//trim(FNAME)
stop
end if
!//---------------------------------------------------------------------
!// Initial step - setup P, T and Q
!//---------------------------------------------------------------------
if (ILOOP .le. 0) then
!// Set up level weightings if vertical resolution degraded
do LL = LPARW+1, 1, -1
L = LMMAP(LL)
LMAP(L) = LL
end do
write(6,'(a)') 'Initializing meteorological data'
write(6,'(2x,a)') trim(FNAME)
!// Pressure field --------------------------------------------------
!// -----------------------------------------------------------------
call get_netcdf_var_2d(FNAME, 'pres_sfc',PW, IPARW, JPARW)
!// Put PW into P, degrading or not
call TRUNG8(PW, P, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
if (verbose) call gotData('SFC','Surface pressure (P)')
!// Temperature -----------------------------------------------------
!// -----------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'temperature', W3Da, &
IPARW, JPARW, LPARW)
!// Collapse layers
TW(:,:,:) = 0._r8
do L = 1, LPAR
do LL = LMAP(L), LMAP(L+1) - 1
do J = 1, JPARW
do I = 1, IPARW
TW(I,J,L) = TW(I,J,L) + W3Da(I,J,LL) * XLMMAP(LL)
end do
end do
end do
end do
!// Put TW into T, degrading or not
call TRUNG8(TW, T, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LPAR, 1)
!// Test to check temperature field
if (minval(W3Da(:,:,1)) .le. 0._r8) then
write(6,'(a)') f90file//':'//subr// &
': Surface temperature is <= 0?'
write(6,'(a,f9.3)') ' MIN sfc T: ',minval(W3Da(:,:,1))
stop
end if
if (verbose) call gotData('3di','Temperature (T)')
!// Water vapour ----------------------------------------------------
!// -----------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'qhum', W3Da, &
IPARW, JPARW, LPARW)
!// Collapse layers
QW(:,:,:) = 0._r8
do L = 1,LPAR
do LL = LMAP(L),LMAP(L+1)-1
do J = 1,JPARW
do I = 1,IPARW
QW(I,J,L) = QW(I,J,L) + W3Da(I,J,LL) * XLMMAP(LL)
end do
end do
end do
end do
!// There may be some entries of small negative numbers
if (minval(QW) .lt. 0._r8) then
print*,'update_metdata: min QW:',minval(QW),', setting to',QMIN
do L = 1, LPAR
do J = 1, JPARW
do I = 1, IPARW
if (QW(I,J,L) .lt. 0._r8) QW(I,J,L) = QMIN
end do
end do
end do
end if
!// Put QW into Q, degrading or not
call TRUNG8(QW, Q, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LPAR,1)
if (verbose) call gotData('3di','Specific humidity (Q)')
!// Polar cap filtering
call EPZ_TQ(T, Q, XYZA, XYZB, P, IMEPZ,IPAR,JPAR,LPAR,IPAR,JPAR,LPAR)
call EPZ_P(P, IMEPZ, IPAR,JPAR, IPAR, JPAR)
!// Initialization is done - these steps are for all time steps
return
end if !// if (ILOOP .le. 0) then
!//---------------------------------------------------------------------
!// All time steps - update all meteorological fields
!//---------------------------------------------------------------------
if (verbose) then
write(6,'(a,i5)') f90file//':'//subr// &
': Reading new metdata JDAY: '//TMET//', NMET:',NMET
write(6,'(2x,a)') trim(FNAME)
end if
!// Clear arrays
U(:,:,:) = 0._r8
V(:,:,:) = 0._r8
T(:,:,:) = 0._r8
Q(:,:,:) = 0._r8
CWETN(:,:,:) = 0._r8
CWETE(:,:,:) = 0._r8
CWETD(:,:,:) = 0._r8
CENTU(:,:,:) = 0._r8
CENTD(:,:,:) = 0._r8
CDETU(:,:,:) = 0._r8
CDETD(:,:,:) = 0._r8
PRECCNV(:,:,:) = 0._r8
PRECLS(:,:,:) = 0._r8
CLDFR(:,:,:) = 0._r8
CLDLWC(:,:,:) = 0._r8
CLDIWC(:,:,:) = 0._r8
!// No need to clear 2D arrays; they are fully updated below
SLH(:,:) = 0._r8
SHF(:,:) = 0._r8
SMF(:,:) = 0._r8
SFT(:,:) = 0._r8
SFQ(:,:) = 0._r8
SFU(:,:) = 0._r8
SFV(:,:) = 0._r8
BLH(:,:) = 0._r8
MSLP(:,:) = 0._r8
SA(:,:) = 0._r8
!//---------------------------------------------------------------------
!// 3D GRIDDED DATA - INSTANTANEOUS
!//---------------------------------------------------------------------
!// Pressure field -----------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_2d(FNAME, 'pres_sfc',PW, IPARW, JPARW)
!// Put PW into P, degrading or not
call TRUNG8(PW, P, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
if (verbose) call gotData('SFC','Surface pressure (P)')
!// Temperature --------------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'temperature', W3Da, &
IPARW, JPARW, LPARW)
!// Collapse layers
TW(:,:,:) = 0._r8
do L = 1, LPAR
do LL = LMAP(L), LMAP(L+1) - 1
do J = 1, JPARW
do I = 1, IPARW
TW(I,J,L) = TW(I,J,L) + W3Da(I,J,LL) * XLMMAP(LL)
end do
end do
end do
end do
!// Put TW into T, degrading or not
call TRUNG8(TW, T, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LPAR, 1)
if (verbose) call gotData('3di','Temperature (T)')
!// Zonal wind (U) -----------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'U', W3Da, IPARW, JPARW, LPARW)
!// scale from U=u*cos() to u and to flux [kg/s]
do L = 1, LPARW
DETA = ETAAW(L) - ETAAW(L+1)
DETB = ETABW(L) - ETABW(L+1)
do J = 1, JPARW
BAND = A0 * (WGLYE(J+1) - WGLYE(J))
ZCOS = 1._r8 / COS(WGLYG(J))
do I = 1, IPARW
UTMP(I) = W3Da(I,J,L) * ZCOS * BAND
!// Save center values for m/s
W3Db(I,J,L) = W3Da(I,J,L) * ZCOS !// Save U(m/s)
end do
!// Get edge values (unit conversion needs pressure on edge)
do I = 2, IPARW
DELP = DETA + DETB * (PW(I-1,J) + PW(I,J)) * 0.5_r8
W3Da(I,J,L) = (UTMP(I-1) + UTMP(I)) * 0.5_r8 * DELP
end do
DELP = DETA + DETB * (PW(1,J) + PW(IPARW,J)) * 0.5_r8
W3Da(1,J,L) = (UTMP(IPARW) + UTMP(1)) * 0.5_r8 * DELP
end do
end do
if (ldeg) then
do L = 1, LPAR
do LL = LMAP(L),LMAP(L+1)-1
do I = 1, IPAR
II = IMAP(1,I)
do J = 1, JPAR
do JJ = 1, JDGRD
U(I,J,L) = U(I,J,L) + W3Da(II,JMAP(JJ,J),LL)
end do
end do
end do
end do
end do
else
do L = 1, LPAR
do LL = LMAP(L),LMAP(L+1)-1
do J = 1, JPAR
do I = 1, IPAR
U(I,J,L) = U(I,J,L) + W3Da(I,J,LL)
end do
end do
end do
end do
end if
if (verbose) call gotData('3di','Zonal wind (U)')
!// Save UMS -----------------------------------------------------------
!//---------------------------------------------------------------------
!// Degrade vertically and horizontally, put into (LPAR,IPAR,JPAR)
call ijlw2lij(W3Db, LMAP, XLMMAP, IPAR, JPAR, LPAR, IPARW, &
JPARW, LPARW, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, JDGRD, UMS)
!// Meridional wind (V) ------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'V', W3Db, IPARW, JPARW, LPARW)
!// scale from V=v*cos() to v (remember V is on edge already)
do L = 1, LPARW
DETA = ETAAW(L) - ETAAW(L+1)
DETB = ETABW(L) - ETABW(L+1)
VTMP(:,:) = 0._r8 !// Needed for getting VMSW
!// W3Db does not start at SP, but at the J=2. It means
!// W3Db is flux out of box J, not into J.
!// Given all edge points, the number of boxes should be
!// JPARW+1, covering 1:JPARW+1. But both the poles should
!// have zero wind, so we only need JPARW-1 boxes.
!//
!// But in addition, the values at JPARW/2 and JPARW/2+1
!// are duplicated, both representing wind across Equator.
!// So W3Db has the size JPARW instead of JPARW-1.
!//
!// A bit confusing, the CTM uses V as flux into J-box instead of
!// out of it. This will be taken care of at the end.
!// SH flux out of J-box:
do J = 1, JPARW/2
ZCOS = 1._r8 / COS(WGLYE(J+1))
do I = 1, IPARW
VTMP(I,J) = W3Db(I,J,L) * ZCOS
end do
end do
!// Now VTMP covers the V up to Equator, starting at the
!// models index J=2, but stored in VTMP at J=1.
!// NH flux out of J-box (JPARW/2 and JPARW/2+1 are duplicated):
do J = JPARW/2 + 2, JPARW
ZCOS = 1._r8 / COS(WGLYE(J))
do I = 1, IPARW
VTMP(I,J-1) = W3Db(I,J,L) * ZCOS
end do
end do
!// Thus, at J=JPARW, VTMP (with its indicing) represents NP
!// and is therefore zero.
!//change unit, m/s ==> Kg/s (100./G0 is done in pdyn0.f)
!// Save center values for m/s J=1 (assume V=0 at SP)
W3Da(:,1,L) = VTMP(:,1) * 0.5_r8
!// Map the VTMP back to correct model edge grid (from J to J+1),
!// i.e. converting from flux out of J-1 to flux into J.
do J = 2, JPARW
VEDGE = 2._r8 * CPI * A0 * COS(WGLYE(J)) / real(IPARW, r8)
do I = 1, IPARW
DELP = DETA + DETB * (PW(I,J-1) + PW(I,J)) * 0.5_r8
!// Save center values for m/s J>1
W3Da(I,J,L) = (VTMP(I,J) + VTMP(I,J-1)) * 0.5_r8
W3Db(I,J,L) = VTMP(I,J-1) * VEDGE * DELP
end do
end do
end do
if (ldeg) then
do L = 1, LPAR
do LL = LMAP(L),LMAP(L+1)-1
do J = 1, JPAR
JJ = JMAP(1,J)
do I = 1, IPAR
do II = 1, IDGRD
V(I,J,L) = V(I,J,L) + W3Db(IMAP(II,I),JJ,LL)
end do
end do
end do
end do
end do
else
do L = 1, LPAR
do LL = LMAP(L),LMAP(L+1)-1
do J = 1, JPAR
do I = 1, IPAR
V(I,J,L) = V(I,J,L) + W3Db(I,J,LL)
end do
end do
end do
end do
end if
if (verbose) call gotData('3di','Meridional wind (V)')
!// Save VMS -----------------------------------------------------------
!//---------------------------------------------------------------------
!// Degrade vertically and horizontally, put into (LPAR,IPAR,JPAR)
call ijlw2lij(W3Da, LMAP, XLMMAP, IPAR, JPAR, LPAR, IPARW, &
JPARW, LPARW, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, JDGRD, VMS)
!//---------------------------------------------------------------------
!// 3-d GRID POINT DATA
!//---------------------------------------------------------------------
!// Water vapour -------------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'qhum', W3Da, IPARW, JPARW, LPARW)
!// Collapse layers
QW(:,:,:) = 0._r8
do L = 1, LPAR
do LL = LMAP(L), LMAP(L+1)-1
do J = 1, JPARW
do I = 1, IPARW
QW(I,J,L) = QW(I,J,L) + W3Da(I,J,LL) * XLMMAP(LL)
end do
end do
end do
end do
if (minval(QW) .lt. 0._r8) then
print*,'update_metdata: min QW:',minval(QW),', setting to',QMIN
do L = 1, LPAR
do J = 1, JPARW
do I = 1, IPARW
if (QW(I,J,L) .lt. 0._r8) QW(I,J,L) = QMIN
end do
end do
end do
end if
!// Put QW into Q, degrading or not
call TRUNG8(QW, Q, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LPAR, 1)
if (verbose) call gotData('3di','Specific humidity (Q)')
!// Altitudes - calculated ---------------------------------------------
!// --------------------------------------------------------------------
!// R = 287.*(1-Q) + 461.5*Q -- assume 0.5% bl w.v.==> R = 288.
!// delta-z (m) = dln(P) * R * T / g where R/g = 288/9.81 = 29.36
!// CTM3: We use Q directly instead of assuming 0.5%;
!// Using Rd=287 and Tv=T*(1 + 0.6*q); 287/9.80665=29.26586
do J = 1, JPAR
do I = 1, IPAR
PSRF = P(I,J)
!// Surface pressure; must be set for DELZ to be calculated
POFLE(1) = PSRF
!// Height of box bottom, above sea level (acts as topography)
ZOFLE(1,I,J) = 16.e3_r8 * log10(1013.25_r8 / PMEAN(I,J))
if (ZOFLE(1,I,J) .ne. ZOFLE(1,I,J)) then
write(6,'(a,i3,2i5,2es12.2)') f90file//':'//subr// &
': ZOFLE a',1,i,j,PMEAN(I,J),PMEANW(I,J)
write(6,*) pmean(:,j)
stop
end if
do L = 2, LPAR + 1
!// Pressure of box bottom
POFLE(L) = ETAA(L) + ETAB(L) * PSRF
!DELZ = -29.36_r8 * T(I,J,L-1) * log(POFLE(L)/POFLE(L-1))
!// Thickness of layer (L-1) (remember ZOFLE starts at topography)
DELZ = -29.26586_r8 * T(I,J,L-1) * (1._r8 + 0.6_r8 * Q(I,J,L-1)) &
* log(POFLE(L)/POFLE(L-1))
!// Add DELZ of (L-1) to get box bottom height of L
ZOFLE(L,I,J) = ZOFLE(L-1,I,J) + DELZ
if (ZOFLE(L,I,J) .ne. ZOFLE(L,I,J)) then
write(6,'(a,i3,2i5,4es12.2)') f90file//':'//subr// &
': ZOFLE b',l,i,j,delz,q(i,j,l-1),&
T(I,J,L-1),psrf
stop
end if
end do
end do
end do
!// Also set up ZOFLEW for metdata grid
do J = 1, JPARW
do I = 1, IPARW
PSRF = PW(I,J)
POFLE(1) = PSRF
ZOFLEW(1,I,J) = 16e3_r8 * log10(1013.25_r8 / PMEANW(I,J))
do L = 2, LPAR + 1
POFLE(L) = ETAA(L) + ETAB(L)*PSRF
!DELZ = -29.36_r8 * TW(I,J,L-1) * log(POFLE(L)/POFLE(L-1))
!// Thickness of layer below
DELZ = -29.26586_r8 * TW(I,J,L-1)*(1._r8 + 0.6_r8*QW(I,J,L-1)) &
* log(POFLE(L)/POFLE(L-1))
ZOFLEW(L,I,J) = ZOFLEW(L-1,I,J) + DELZ
end do
end do
end do
!// Potantial vorticity ------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_3d(FNAME, 'PV', W3Da, IPARW, JPARW, LPARW)
!// Convert to PVU
W3Da(:,:,:) = W3Da(:,:,:) * 1.e6_r8
if (maxval(W3Da) .eq. 0._r8) then
!// PV was not on available.
!// Generate PV on model resolution and convert to PVU
call get_pvu()
else
!// Transform into PVU-array
call ijlw2lij(W3Da, LMAP, XLMMAP, IPAR, JPAR, LPAR, IPARW, &
JPARW, LPARW, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, JDGRD, PVU)
end if
!// Cloud Liquid Water Content [Kg/Kg] - midpoint value ----------------
!// --------------------------------------------------------------------
!// Cloud routine needs CLDLWCW in any case, so we calculate
!// that first. Could repeat with R8XYZ, but rather do
!// degradation of CLDLWCW.
call get_netcdf_var_3d(FNAME, 'lwc', W3Da, IPARW, JPARW, LPARW)
CLDLWCW(:,:,:) = 0._r8
do L = 1, LWEPAR
do LL = LMAP(L), LMAP(L+1)-1
do J = 1, JPARW
do I = 1, IPARW
CLDLWCW(I,J,L) = CLDLWCW(I,J,L) + W3Da(I,J,LL) * XLMMAP(LL)
end do
end do
end do
end do
!// Put CLDLWCW into LCDLWC, degrading or not
call TRUNG8(CLDLWCW, CLDLWC, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LWEPAR, 1)
!// Cloud Ice Water Content [Kg/Kg] - midpoint value -------------------
!// --------------------------------------------------------------------
!// Cloud routine needs CLDIWCW in any case, so we calculate
!// that first.
call get_netcdf_var_3d(FNAME, 'iwc', W3Da, IPARW, JPARW, LPARW)
CLDIWCW(:,:,:) = 0._r8
do L = 1, LWEPAR
do LL = LMAP(L), LMAP(L+1)-1
do J = 1, JPARW
do I = 1, IPARW
CLDIWCW(I,J,L) = CLDIWCW(I,J,L) + W3Da(I,J,LL) * XLMMAP(LL)
end do
end do
end do
end do
!// Put CLDIWCW into LCDIWC, degrading or not
call TRUNG8(CLDIWCW, CLDIWC, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LWEPAR, 1)
!// Cloud Fraction [0,1] - midpoint value ------------------------------
!// --------------------------------------------------------------------
!// Cloud routine needs CLDFRW in any case, so we calculate
!// that first.
call get_netcdf_var_3d(FNAME, 'cfr', W3Da, IPARW, JPARW, LPARW)
CLDFRW(:,:,:) = 0._r8
do L = 1, LWEPAR
do LL = LMAP(L), LMAP(L+1)-1
do J = 1, JPARW
do I = 1, IPARW
CLDFRW(I,J,L) = CLDFRW(I,J,L) &
+ max(min(W3Da(I,J,LL),1._r8),0._r8) * XLMMAP(LL)
end do
end do
end do
end do
!// Put CLDFRW into LCDFR, degrading or not
call TRUNG8(CLDFRW, CLDFR, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, LWEPAR, 1)
!//---------------------------------------------------------------------
!// 3D GRIDDED DATA - ACCUMULATED
!//---------------------------------------------------------------------
!// Mass Flux updrafts [accumulated kg/(m^2*s)] ------------------------
!// --------------------------------------------------------------------
!// - Mass flux is through BOTTOM EDGE of grid box (i.e. model
!// half layers).
!// - EC-data are stored from half layer 2, since the flux into
!// layer 1 is always zero (no flux in through surface).
!// - Scale with area and dt --> [kg/s]
call get_netcdf_var_3d(FNAME, 'cflxu', W3Da, IPARW, JPARW, LPARW)
W3Da(:,:,LWEPARW+1:LPARW) = 0._r8
!// Possibly degrade without collapsing
call TRUNG8(W3Da, R8XYZ, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD,IPARW,JPARW,IPAR,JPAR,LPARW,1)
CWETE(:,:,:) = 0._r8 !// No flux up from surface
!// Start retrieval at layer 2
do L = 2, LWEPAR
!// LMAP is full-level, but for since mass fluxes are not stored
!// for surface, and starts at layer 2, we need to subtract 1.
!// What comes into L=2, comes from LMAP(2)-1.
!// For L40, L=2 and LMAP(2)-1 = 1, while
!// for L37, L=2 and LMAP(2)-1 = 3
LL = LMAP(L) - 1
do J = 1, JPAR
do I = 1, IPAR
!// Filter values. File data has minimum values less than zero.
!// Hence we treat values less that that as as zero
if (R8XYZ(I,J,LL) .gt. mincwetelim) then
CWETE(I,J,L) = R8XYZ(I,J,LL) * AREAXY(I,J) * ZDT
else
CWETE(I,J,L) = 0._r8
end if
end do
end do
end do
!// Mass Flux downdrafts [accumulated kg/(m^2*s)] ----------------------
!// --------------------------------------------------------------------
!// - Mass flux is through BOTTOM EDGE of grid box (i.e. model
!// half layers).
!// This means that the flux for layer 1 is zero, and that
!// downward flux is NEGATIVE, going out at the bottom of the box.
!// - EC-data are stored from half layer 2, since the flux into
!// layer 1 is always zero (no flux in through surface).
!// - For a grid box in layer L, -FD(L) goes out at bottom
!// and -FD(L+1) comes in from above (FD is negative). The
!// balance with entrainment E and detrainment D is:
!// FD(L) - FD(L+1) = E - D
!// - Scale with area and dt --> [kg/s]
call get_netcdf_var_3d(FNAME, 'cflxd', W3Da, IPARW, JPARW, LPARW)
W3Da(:,:,LWEPARW+1:LPARW) = 0._r8
!// Possibly degrade without collapsing
call TRUNG8(W3Da, R8XYZ, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD,IPARW,JPARW,IPAR,JPAR,LPARW,1)
CWETD(:,:,:) = 0._r8 !// No flux down to surface
!// Start retrieval at layer 2
do L = 2, LWDPAR
!// See Case(212) for comment on LMAP
LL = LMAP(L) - 1
do J = 1, JPAR
do I = 1, IPAR
if (R8XYZ(I,J,LL) .lt. maxcwetdlim) then
CWETD(I,J,L) = R8XYZ(I,J,LL) * AREAXY(I,J) * ZDT
else
CWETD(I,J,L) = 0._r8
end if
end do
end do
end do
!// Updrafts detrainment rate [accumulated kg/(m3*s)] ------------------
!// [i.e. kg/(m2*s) per gridbox height] ------------------
!// --------------------------------------------------------------------
!// - Entrainment has to be built from detrainment.
!// - The rate is per height, so we have to multiply with dZ and area.
!// - Detrainment/entrainment rates are given at GRID CENTER
!// (i.e. model full layers).
!// - Detrainment must be summed up when collapsing layers!
!// - Scale with box height, area and dt --> [kg/s]
call get_netcdf_var_3d(FNAME, 'cdetu', W3Da, IPARW, JPARW, LPARW)
W3Da(:,:,LWEPARW+1:LPARW) = 0._r8
!// Possibly degrade without collapsing
call TRUNG8(W3Da, R8XYZ, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD,IPARW,JPARW,IPAR,JPAR,LPARW,1)
CDETU(:,:,:) = 0._r8
do J = 1, JPAR
do I = 1, IPAR
do L = 1, LWEPAR
do LL = LMAP(L), LMAP(L+1) - 1
!// Detrainment must be summed up when collapsing layers
if (R8XYZ(I,J,LL) .gt. mincdetulim) then
CDETU(I,J,L) = CDETU(I,J,L) &
+ R8XYZ(I,J,LL) * XLMMAP(LL) &
* (ZOFLE(L+1,I,J) - ZOFLE(L,I,J)) &
* AREAXY(I,J) * ZDT
end if
end do
end do
end do
end Do
!// Downdrafts detrainment rate [acc. kg/(m3*s)] -----------------------
!// [i.e. kg/(m2*s) per gridbox height] -----------------------
!// --------------------------------------------------------------------
!// - Entrainment has to be built from detrainment.
!// - The rate is per height, so we have to multiply with dZ and
!// area.
!// - Detrainment/entrainment rates are given at GRID CENTER
!// (i.e. model full layers).
!// - Detrainment must be summed up when collapsing layers!
!// - Scale with box height and dt --> [kg/s]
call get_netcdf_var_3d(FNAME, 'cdetd', W3Da, IPARW, JPARW, LPARW)
W3Da(:,:,LWEPARW+1:LPARW) = 0._r8
!// Possibly degrade without collapsing
call TRUNG8(W3Da, R8XYZ, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD,IPARW,JPARW,IPAR,JPAR,LPARW,1)
CDETD(:,:,:) = 0._r8
do J = 1, JPAR
do I = 1, IPAR
do L = 1, LWDPAR
do LL = LMAP(L),LMAP(L+1)-1
if (R8XYZ(I,J,LL) .gt. mincdetdlim) then
CDETD(I,J,L) = CDETD(I,J,L) &
+ R8XYZ(I,J,LL) * XLMMAP(LL) &
* (ZOFLE(L+1,I,J) - ZOFLE(L,I,J)) &
* AREAXY(I,J) * ZDT
end if
end do
end do
end do
end do
!// CONVECTIVE RAINFALL [kg/(m^2)] (accumulated kg/(m^2*s)) ------------
!// --------------------------------------------------------------------
!// EDGE VALUE
!// Scale with area and dt or re-initialize --> [kg/s]
call get_netcdf_var_3d(FNAME, 'convrain', W3Da, IPARW, JPARW, LPARW)
W3Da(:,:,LWEPARW+1:LPARW) = 0._r8
!// Possibly degrade without collapsing
call TRUNG8(W3Da, R8XYZ, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD,IPARW,JPARW,IPAR,JPAR,LPARW,1)
PRECCNV(:,:,:) = 0._r8
do L = 1, LWEPAR
LL = LMAP(L)
do J = 1, JPAR
do I = 1, IPAR
PRECCNV(I,J,L) = &
max(0._r8, R8XYZ(I,J,LL) * AREAXY(I,J) * ZDT)
end do
end do
end do
!// LARGE SCALE RAINFALL [kg/(m^2)] (accumulated kg/(m^2*s)) -----------
!// --------------------------------------------------------------------
!// EDGE VALUE
!// Scale with area and dt or re-initialize --> [kg/s]
call get_netcdf_var_3d(FNAME, 'lsrain', W3Da, IPARW, JPARW, LPARW)
W3Da(:,:,LWEPARW+1:LPARW) = 0._r8
!// Possibly degrade without collapsing
call TRUNG8(W3Da, R8XYZ, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD,IPARW,JPARW,IPAR,JPAR,LPARW,1)
PRECLS(:,:,:) = 0._r8
do L = 1, LWEPAR
LL = LMAP(L)
do J = 1, JPAR
do I = 1, IPAR
PRECLS(I,J,L) = &
max(0._r8, R8XYZ(I,J,LL) * AREAXY(I,J) * ZDT)
end do
end do
end do
!//---------------------------------------------------------------------
!// Cloud cover routines - Only needed for J-values, i.e. chemistry.
! if (LOSLOCHEM) &
if (LOSLOCTROP) &
!// New cloud treatment (qcode_60a)
call CLOUD(CLDFRW,CLDIWCW,CLDLWCW,PW,TW,ETAA,ETAB,AREAXYW, &
ZOFLEW,ZDEGI,ZDEGJ,IMAP,JMAP, &
SWSTORE,CLDSTORE,TYPSTORE,RAN4,IRAN0, &
LCLDAVG,LCLDQMD,LCLDQMN,LCLDRANA,LCLDRANQ)
!//---------------------------------------------------------------------
!//---------------------------------------------------------------------
!// 2-d SURFACE GRID POINT DATA
!//---------------------------------------------------------------------
!// SEA ICE COVER (CI) -------------------------------------------------
!// --------------------------------------------------------------------
call get_netcdf_var_2d(FNAME, 'CI',W2D, IPARW, JPARW)
call TRUNG8(W2D, CI, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
if (verbose) call gotData('2di','Sea ice (CI)')
!// Snow Evaporation (ES) (accumulated) --------------------------------
!// --------------------------------------------------------------------
!// Unit: m/s water equivalent, accumulated (m w.eq.)
!// Snow evaporation may actually also be negative, for some reason
call get_netcdf_var_2d(FNAME, 'ES',W2D, IPARW, JPARW)
call TRUNG8(W2D, R8XY, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
R8XY(:,:) = R8XY(:,:) * ZDT
call data2mpblocks(R8XY, ES)
if (verbose) call gotData('2da','Snow Evaporation (ES)')
!// Snow Melt (SMLT) (accumulated) -------------------------------------
!// --------------------------------------------------------------------
!// Unit: m/s water equivalent, accumulated (m w.eq.)
call get_netcdf_var_2d(FNAME, 'SMLT',W2D, IPARW, JPARW)
call TRUNG8(W2D, R8XY, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
R8XY(:,:) = max(0._r8, R8XY(:,:) * ZDT) !// Limit to positive values
call data2mpblocks(R8XY, SMLT)
if (verbose) call gotData('2da','Snow Melt (SMLT)')
!// Photosynthetically active radiation @ sfc (PhotActRad) (accumulated)
!// --------------------------------------------------------------------
!// Unit: (W/m2)*s, accumulated. Divide by ZDT to get W/m2.
call get_netcdf_var_2d(FNAME, 'PAR',W2D, IPARW, JPARW)
call TRUNG8(W2D, R8XY, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
PhotActRad(:,:) = max(0._r8, R8XY(:,:) * ZDT) !// Limit to positive values
if (verbose) call gotData('2da','Photosyn. act. rad. sfc (PhotActRad)')
!// Snow depth (SD) ----------------------------------------------------
!// --------------------------------------------------------------------
!// Unit: m water equivalent
call get_netcdf_var_2d(FNAME, 'SD',W2D, IPARW, JPARW)
call TRUNG8(W2D, SD, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
if (verbose) call gotData('2di','Snow depth (SD)')
!// Large Scale Precipitation (stratiform) (accumulated) ---------------
!// --------------------------------------------------------------------
!call get_netcdf_var_2d(FNAME, 'LSPREC',W2D, IPARW, JPARW)
!call TRUNG8(W2D, R8XY, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
! JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
!LSPREC(:,:) = R8XY(:,:) * ZDT
!if (verbose) call gotData('2da','Large Scale Precip. (LSPREC)')
!// Convective Precipitation (accumulated) -----------------------------
!// --------------------------------------------------------------------
!call get_netcdf_var_2d(FNAME, 'CONVPREC',W2D, IPARW, JPARW)
!call TRUNG8(W2D, R8XY, ZDEGI, ZDEGJ, IMAP, JMAP, IDGRD, &
! JDGRD, IPARW, JPARW, IPAR, JPAR, 1, 1)
!CNVPREC(:,:) = R8XY(:,:) * ZDT
!if (verbose) call gotData('2da','Conv. Precip. (CONVPREC)')
!// SnowFall SF (accumulated) ------------------------------------------