-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWRF3D_pp.F90
1545 lines (1490 loc) · 79.9 KB
/
WRF3D_pp.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
! #############################################################################
!
! The purpose of this program is to post-process WRF 3D data. Non-standard WRF
! outputs (e.g IVT and freezing-level height) are computed and output to a
! netCDF file. Inputs/Outputs controlled by input_namelist, wrf3d_pp_nl.txt.
!
! Dustin Swales (4/2017) - Initial version (dustin.swales@noaa.gov)
!
! To compile:
! ifort -I/usr/local/ifort/include -L/usr/local/ifort/lib -lnetcdff WRF3D_pp.F90 -o WRF3D_pp.o
!
! #############################################################################
program WRF3D_pp
use netcdf
implicit none
! Parameters
character(len=128),parameter :: &
input_namelist = 'wrf3d_pp_nl.txt'
real,parameter :: &
output_fill_value = -999.
! Namelist
character(len=256) :: &
fileIN, & ! Input file
fileOUT ! Output file
logical :: &
verbose, & ! Turn on/off info print to screen
toa2sfc, & ! If vertical ordering is from TOA-2_SFC, set to .true.
l_ivt, & ! Compute IVT?
l_z0k, & ! Compute freezing level height?
l_smois, & ! Output soil moisture?
l_tslb, & ! Output soil temperature?
l_rainnc,& ! Extract accumulated grid-scale precipitations?
l_rainc, & ! Extract accumulated grid-scale cummulus precipitation?
l_psfc, & ! Output surface pressure?
l_tskin, & ! Output skin temperature?
l_sst, & ! Output SST?
l_snowe, & ! Output Snow water equivalent?
l_z1000, & ! Output 1000hPa geopotential?
l_z950, & ! Output 950hPa geopotential?
l_z900, & ! Output 900hPa geopotential?
l_z850, & ! Output 850hPa geopotential?
l_z800, & ! Output 800hPa geopotential?
l_z750, & ! Output 750hPa geopotential?
l_z700, & ! Output 700hPa geopotential?
l_z600, & ! Output 600hPa geopotential?
l_z500, & ! Output 500hPa geopotential?
l_z250, & ! Output 250hPa geopotential?
l_q1000, & ! Output 1000hPa specific-humidity?
l_q950, & ! Output 950hPa specific-humidity?
l_q900, & ! Output 900hPa specific-humidity?
l_q850, & ! Output 850hPa specific-humidity?
l_q800, & ! Output 800hPa specific-humidity?
l_q750, & ! Output 750hPa specific-humidity?
l_q700, & ! Output 700hPa specific-humidity?
l_q600, & ! Output 600hPa specific-humidity?
l_q500, & ! Output 500hPa specific-humidity?
l_q250, & ! Output 250hPa specific-humidity?
l_q2m, & ! Output 2m specific-humidity?
l_u1000, & ! Output 1000hPa U-component of wind?
l_u950, & ! Output 950hPa U-component of wind?
l_u900, & ! Output 900hPa U-component of wind?
l_u850, & ! Output 850hPa U-component of wind?
l_u800, & ! Output 800hPa U-component of wind?
l_u750, & ! Output 750hPa U-component of wind?
l_u700, & ! Output 700hPa U-component of wind?
l_u600, & ! Output 600hPa U-component of wind?
l_u500, & ! Output 500hPa U-component of wind?
l_u250, & ! Output 250hPa U-component of wind?
l_u10m, & ! Output 10m U-component of wind?
l_v1000, & ! Output 1000hPa V-component of wind?
l_v950, & ! Output 950hPa V-component of wind?
l_v900, & ! Output 900hPa V-component of wind?
l_v850, & ! Output 850hPa V-component of wind?
l_v800, & ! Output 800hPa V-component of wind?
l_v750, & ! Output 750hPa V-component of wind?
l_v700, & ! Output 700hPa V-component of wind?
l_v600, & ! Output 600hPa V-component of wind?
l_v500, & ! Output 500hPa V-component of wind?
l_v250, & ! Output 250hPa V-component of wind?
l_v10m, & ! Output 10m V-component of wind?
l_t1000, & ! Output 1000hPa temperature?
l_t950, & ! Output 950hPa temperature?
l_t900, & ! Output 900hPa temperature?
l_t850, & ! Output 850hPa temperature?
l_t800, & ! Output 800hPa temperature?
l_t750, & ! Output 750hPa temperature?
l_t700, & ! Output 700hPa temperature?
l_t600, & ! Output 600hPa temperature?
l_t500, & ! Output 500hPa temperature?
l_t250, & ! Output 250hPa temperature?
l_t2m ! Output 2m temperature?
namelist/nmlist/fileIN, fileOUT, verbose, toa2sfc, l_ivt, l_z0k, l_smois, l_tslb, l_rainnc, &
l_rainc, l_psfc, l_tskin, l_sst,l_snowe, &
l_z1000, l_z950, l_z900, l_z850, l_z800, l_z750, l_z700, l_z600, l_z500, l_z250, &
l_q1000, l_q950, l_q900, l_q850, l_q800, l_q750, l_q700, l_q600, l_q500, l_q250, l_q2m, &
l_u1000, l_u950, l_u900, l_u850, l_u800, l_u750, l_u700, l_u600, l_u500, l_u250, l_u10m, &
l_v1000, l_v950, l_v900, l_v850, l_v800, l_v750, l_v700, l_v600, l_v500, l_v250, l_v10m, &
l_t1000, l_t950, l_t900, l_t850, l_t800, l_t750, l_t700, l_t600, l_t500, l_t250, l_t2m
! WRF fields
integer :: &
nTime, & ! WRF file dimension: Number of times
nLon, & ! WRF file dimension: Number of longitudes
nLat, & ! WRF file dimension: Number of latitudes
nLev, & ! WRF file dimension: Number of vertical levels
nLon_stag, & ! WRF file dimension: Number of longitudes (staggerd grid)
nLat_stag, & ! WRF file dimension: Number of latitude (staggerd grid)
nLev_stag, & ! WRF file dimension: Number of vertical levels (staggerd grid)
DateStrLen,& ! WRF file dimension: String length for date.
nSoil_stag ! WRF file dimension: Number of soil layers (staggered grid)
real,dimension(:,:,:,:),allocatable :: &! WRF NAME UNITS
q, & ! WRF input field: Water vapor mixing ratio (QVAPOR) (kg/kg)
u, & ! WRF input field: Zonal component of the wind (U) (m/s)
v, & ! WRF input field: Meridional component of the wind (V) (m/s)
pp, & ! WRF input field: Pertubation pressure (P) (Pa)
pb, & ! WRF input field: Base state pressure (PB) (Pa)
ta, & ! WRF input field: Pertubation potential temp. (T) (K)
ph, & ! WRF input field: Pertubation geopotential (PH) (m2/s2)
phb, & ! WRF input field: Base-state geopotential (PHB) (m2/s2)
smois, & ! WRF input field: Soil mosisture (SMOIS) (m3/m3)
tslb ! WRF input field: Soil temperature (TSLB) (K)
real,dimension(:,:,:),allocatable :: &
lon, & ! WRF input field: Longitude (XLONG) (degree_east)
lat, & ! WRF input field: Latitude (XLAT) (degree_north)
lon_u, & ! WRF input field: Longitude (staggerd u-grid) (XLONG_U) (degree_east)
lat_u, & ! WRF input field: Latitude (staggerd u-grid) (XLAT_U) (degree_north)
lon_v, & ! WRF input field: Longitude (staggerd v-grid) (XLONG_V) (degree_east)
lat_v, & ! WRF input field: Latitude (staggerd v-grid) (XLAT_V) (degree_north)
psfc, & ! WRF input field: Surface pressure (PSFC) (Pa)
t2m, & ! WRF input field: Temperature @ 2m (T2) (K)
q2m, & ! WRF input field: Specific humidity @ 2m (Q2) (kg/kg)
tsk, & ! WRF input field: Skin temperature (TSK) (K)
sst, & ! WRF input field: SST (SNOW (kg/m2)
snowe, & ! WRF input field: SNOW (SST) (K)
v10m, & ! WRF input field: v-wind @ 10m (U10) (m/s)
u10m, & ! WRF input field: v-wind @ 10m (V10) (m/s)
terrainZ ! WRF input field: Terrain height (HGT) (m)
real,dimension(:),allocatable :: &
t00, & ! WRF input field: Base state temperature (T00) (K)
zs ! WRF input field: Soil levels (ZS) (m)
character(len=19),dimension(:),allocatable :: &
times ! WRF file time.
integer,dimension(:),allocatable :: &
year, & ! WRF data year
month, & ! WRF data month
day, & ! WRF data day
hour ! WRF data hour
! Local fields
real,dimension(:,:,:,:),allocatable :: &
p, & ! WRF pressue (computed from pp and pb) (pa)
hgt ! WRF heights (computed from ph and phb) (m)
real,dimension(:,:,:),allocatable :: &
ivtU, & ! WRF IVT (u-component) (kg/m/s)
ivtV, & ! WRF IVT (v-component) (kg/m/s)
z0k, & ! WRF Freezing level height (m)
rainnc, & ! WRF total precipitaion (mm)
rainc, & ! WRF total cummulus precipitaion (mm)
z1000, & ! WRF geopotential height @ 1000hPa (m)
z950, & ! WRF geopotential height @ 950hPa (m)
z900, & ! WRF geopotential height @ 900hPa (m)
z850, & ! WRF geopotential height @ 850hPa (m)
z800, & ! WRF geopotential height @ 800hPa (m)
z750, & ! WRF geopotential height @ 750hPa (m)
z700, & ! WRF geopotential height @ 700hPa (m)
z600, & ! WRF geopotential height @ 600hPa (m)
z500, & ! WRF geopotential height @ 500hPa (m)
z250, & ! WRF geopotential height @ 2500hPa (m)
q1000, & ! WRF specific-humidity @ 1000hPa (kg/kg)
q950, & ! WRF specific-humidity @ 950hPa (kg/kg)
q900, & ! WRF specific-humidity @ 900hPa (kg/kg)
q850, & ! WRF specific-humidity @ 850hPa (kg/kg)
q800, & ! WRF specific-humidity @ 800hPa (kg/kg)
q750, & ! WRF specific-humidity @ 750hPa (kg/kg)
q700, & ! WRF specific-humidity @ 700hPa (kg/kg)
q600, & ! WRF specific-humidity @ 600hPa (kg/kg)
q500, & ! WRF specific-humidity @ 500hPa (kg/kg)
q250, & ! WRF specific-humidity @ 250hPa (kg/kg)
u1000, & ! WRF u-wind @ 1000hPa (m/s)
u950, & ! WRF u-wind @ 950hPa (m/s)
u900, & ! WRF u-wind @ 900hPa (m/s)
u850, & ! WRF u-wind @ 850hPa (m/s)
u800, & ! WRF u-wind @ 800hPa (m/s)
u750, & ! WRF u-wind @ 750hPa (m/s)
u700, & ! WRF u-wind @ 700hPa (m/s)
u600, & ! WRF u-wind @ 600hPa (m/s)
u500, & ! WRF u-wind @ 500hPa (m/s)
u250, & ! WRF u-wind @ 250hPa (m/s)
v1000, & ! WRF v-wind @ 1000hPa (m/s)
v950, & ! WRF v-wind @ 950hPa (m/s)
v900, & ! WRF v-wind @ 900hPa (m/s)
v850, & ! WRF v-wind @ 850hPa (m/s)
v800, & ! WRF v-wind @ 800hPa (m/s)
v750, & ! WRF v-wind @ 750hPa (m/s)
v700, & ! WRF v-wind @ 700hPa (m/s)
v600, & ! WRF v-wind @ 600hPa (m/s)
v500, & ! WRF v-wind @ 500hPa (m/s)
v250, & ! WRF v-wind @ 250hPa (m/s)
t1000, & ! WRF temperature @ 1000hPa (K)
t950, & ! WRF temperature @ 950hPa (K)
t900, & ! WRF temperature @ 900hPa (K)
t850, & ! WRF temperature @ 850hPa (K)
t800, & ! WRF temperature @ 800hPa (K)
t750, & ! WRF temperature @ 750hPa (K)
t700, & ! WRF temperature @ 700hPa (K)
t600, & ! WRF temperature @ 600hPa (K)
t500, & ! WRF temperature @ 500hPa (K)
t250 ! WRF temperature @ 250hPa (K)
integer,dimension(:,:,:) ,allocatable:: &
i_rainnc, & ! WRF total precipitaion bucket (1)
i_rainc ! WRF total cummulus precipitaion bucket (1)
integer,dimension(80) :: dimID,varIDout
character(len=19) :: tempTime
integer :: status,fileID,varID,ii,ij,ik,il
real,dimension(:),allocatable :: ui,vi,temp,phm,a,b
real :: wt1,dp,wt2,Bucket_size
integer,dimension(1) :: xi,xf
! By default, turn all output to off.
logical :: &
lread_QVAPOR = .false., &
lread_Q2M = .false., &
lread_U = .false., &
lread_U10 = .false., &
lread_V10 = .false., &
lread_V = .false., &
lread_PSFC = .false., &
lread_PB = .false., &
lread_P = .false., &
lread_PH = .false., &
lread_PHB = .false., &
lread_T = .false., &
lread_T00 = .false., &
lread_T2M = .false., &
lread_TSK = .false., &
lread_HGT = .false., &
lread_ZS = .false., &
lread_SMOIS = .false., &
lread_TSLB = .false., &
lread_RAINNC = .false., &
lread_RAINC = .false., &
lread_SST = .false., &
lread_SNOWE = .false.
! #############################################################################
! A) Read in namelist
! #############################################################################
open(10,file=trim(input_namelist),status='unknown')
read(10,nml=nmlist)
close(10)
! #############################################################################
! B) What WRF fields need to be read in?
! #############################################################################
if (l_ivt) then
lread_QVAPOR = .true.
lread_U = .true.
lread_V = .true.
lread_PSFC = .true.
lread_PB = .true.
lread_P = .true.
endif
if (l_z0k) then
lread_T = .true.
lread_T00 = .true.
lread_HGT = .true.
lread_PB = .true.
lread_P = .true.
lread_PH = .true.
lread_PHB = .true.
endif
if (l_smois) then
lread_ZS = .true.
lread_SMOIS = .true.
endif
if (l_tslb) then
lread_ZS = .true.
lread_TSLB = .true.
endif
if (l_u10m) then
lread_U10 = .true.
endif
if (l_v10m) then
lread_V10 = .true.
endif
if (l_q2m) then
lread_Q2M = .true.
endif
if (l_t2m) then
lread_T2M = .true.
endif
if (l_rainnc) then
Lread_RAINNC = .true.
endif
if (l_rainc) then
Lread_RAINC = .true.
endif
if (l_tskin) then
Lread_TSK = .true.
endif
if (l_sst) then
Lread_SST = .true.
endif
if (l_snowe) then
Lread_SNOWE = .true.
endif
if (any([l_z1000,l_z950,l_z900,l_z850,l_z800,l_z750,l_z700,l_z600,l_z500,l_z250])) then
lread_PB = .true.
lread_P = .true.
lread_PH = .true.
lread_PHB = .true.
lread_HGT = .true.
lread_PSFC = .true.
endif
if (any([l_q1000,l_q950,l_q900,l_q850,l_q800,l_q750,l_q700,l_q600,l_q500,l_q250])) then
lread_QVAPOR = .true.
lread_PB = .true.
lread_P = .true.
lread_PSFC = .true.
lread_HGT = .true.
endif
if (any([l_u1000,l_u950,l_u900,l_u850,l_u800,l_u750,l_u700,l_u600,l_u500,l_u250])) then
lread_U = .true.
lread_PSFC = .true.
lread_HGT = .true.
endif
if (any([l_v1000,l_v950,l_v900,l_v850,l_v800,l_v750,l_v700,l_v600,l_v500,l_v250])) then
lread_V = .true.
lread_PSFC = .true.
lread_HGT = .true.
endif
if (any([l_t1000,l_t950,l_t900,l_t850,l_t800,l_t750,l_t700,l_t600,l_t500,l_t250])) then
lread_T = .true.
lread_T00 = .true.
lread_PB = .true.
lread_P = .true.
lread_PSFC = .true.
lread_HGT = .true.
endif
! #############################################################################
! C) Data ingest
! #############################################################################
if (verbose) print*,'Reading in data ....'
! 0) Open file
status = nf90_open(trim(fileIN),nf90_NoWrite,fileID)
if (status /= nf90_NoErr) then
print*,'ERROR: Cannot open input file ',trim(fileIN)
print*,'EXITING!!!'
goto 101
end if
! 1) Get dimensions
! "Time"
status = nf90_inq_dimid(fileID,"Time",dimID(1))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, Time'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(1),len=nTime)
endif
! "west_east"
status = nf90_inq_dimid(fileID,"west_east",dimID(2))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, west_east'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(2),len=nLon)
endif
! "south_north"
status = nf90_inq_dimid(fileID,"south_north",dimID(3))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, south_north'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(3),len=nLat)
endif
! "bottom_top"
status = nf90_inq_dimid(fileID,"bottom_top",dimID(4))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, bottom_top'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(4),len=nLev)
endif
! "west_east_stag"
status = nf90_inq_dimid(fileID,"west_east_stag",dimID(5))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, west_east_stag'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(5),len=nLon_stag)
endif
! "south_north_stag"
status = nf90_inq_dimid(fileID,"south_north_stag",dimID(6))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, south_north_stag'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(6),len=nLat_stag)
endif
! "bottom_top_stag"
status = nf90_inq_dimid(fileID,"bottom_top_stag",dimID(7))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, bottom_top_stag'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(7),len=nLev_stag)
endif
! "soil_layers_stag"
status = nf90_inq_dimid(fileID,"soil_layers_stag",dimID(8))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, soil_layers_stag'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(8),len=nSoil_stag)
endif
! "DateStrLen"
status = nf90_inq_dimid(fileID,"soil_layers_stag",dimID(9))
if (status /= nf90_NoErr) print*,'ERROR: Dimension not present in file, DateStrLen'
if (status == nf90_NoErr) then
status = nf90_inquire_dimension(fileID,dimID(9),len=DateStrLen)
endif
! 2) Read in fields
! Times
status = nf90_inq_varid(fileID,"Times",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, Times'
if (status == nf90_NoErr) then
allocate(times(nTime),year(nTime),month(nTime),day(nTime),hour(nTime))
status = nf90_get_var(fileID,varID,times)
! Pull out year, month, day and hour from timestamp
do ij=1,nTime
tempTime = times(ij)
call str2int(tempTime(1:4), year(ij), stat=status)
call str2int(tempTime(6:7), month(ij),stat=status)
call str2int(tempTime(9:10), day(ij), stat=status)
call str2int(tempTime(12:13),hour(ij), stat=status)
end do
endif
! Longitude
status = nf90_inq_varid(fileID,"XLONG",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, XLONG'
if (status == nf90_NoErr) then
allocate(lon(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,lon)
endif
! Latitude
status = nf90_inq_varid(fileID,"XLAT",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, XLAT'
if (status == nf90_NoErr) then
allocate(lat(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,lat)
endif
! Longitude (staggered in zonal)
status = nf90_inq_varid(fileID,"XLONG_U",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, XLONG_U'
if (status == nf90_NoErr) then
allocate(lon_u(nLon_stag,nLat,nTime))
status = nf90_get_var(fileID,varID,lon_u)
endif
! Latitude (staggered in zonal)
status = nf90_inq_varid(fileID,"XLAT_U",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, XLAT_U'
if (status == nf90_NoErr) then
allocate(lat_u(nLon_stag,nLat,nTime))
status = nf90_get_var(fileID,varID,lat_u)
endif
! Longitude (staggered in meridional)
status = nf90_inq_varid(fileID,"XLONG_V",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, XLONG_V'
if (status == nf90_NoErr) then
allocate(lon_v(nLon,nLat_stag,nTime))
status = nf90_get_var(fileID,varID,lon_v)
endif
! Latitude (staggered in meridional)
status = nf90_inq_varid(fileID,"XLAT_V",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, XLAT_V'
if (status == nf90_NoErr) then
allocate(lat_v(nLon,nLat_stag,nTime))
status = nf90_get_var(fileID,varID,lat_v)
endif
! Only read in fields which are required for requested computations.
if (lread_QVAPOR) then
! Water vapor mixing-ratio.
status = nf90_inq_varid(fileID,"QVAPOR",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, QVAPOR'
if (status == nf90_NoErr) then
allocate(q(nLon,nLat,nLev,nTime))
status = nf90_get_var(fileID,varID,q,count=(/nLon,nLat,nLev,nTime/))
endif
endif
if (lread_U) then
! Eastward component of wind
status = nf90_inq_varid(fileID,"U",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, U'
if (status == nf90_NoErr) then
allocate(u(nLon_stag,nLat,nLev,nTime))
status = nf90_get_var(fileID,varID,u,count=(/nLon_stag,nLat,nLev,nTime/))
endif
endif
if (lread_V) then
! Northward component of wind
status = nf90_inq_varid(fileID,"V",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, V'
if (status == nf90_NoErr) then
allocate(v(nLon,nLat_stag,nLev,nTime))
status = nf90_get_var(fileID,varID,v,count=(/nLon,nLat_stag,nLev,nTime/))
endif
endif
if (lread_PSFC) then
! Surface pressure
status = nf90_inq_varid(fileID,"PSFC",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, PSFC'
if (status == nf90_NoErr) then
allocate(psfc(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,psfc,count=(/nLon,nLat,nTime/))
endif
endif
if (lread_T00) then
! Base temperature
status = nf90_inq_varid(fileID,"T00",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, T00'
if (status == nf90_NoErr) then
allocate(t00(nTime))
status = nf90_get_var(fileID,varID,t00)
endif
endif
if (lread_T) then
! Temperature
status = nf90_inq_varid(fileID,"T",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, T'
if (status == nf90_NoErr) then
allocate(ta(nLon,nLat,nLev,nTime))
status = nf90_get_var(fileID,varID,ta,count=(/nLon,nLat,nLev,nTime/))
endif
endif
if (lread_HGT) then
! Terrain height
status = nf90_inq_varid(fileID,"HGT",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, HGT'
if (status == nf90_NoErr) then
allocate(terrainZ(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,terrainZ)
endif
endif
if (lread_PB) then
! Base state (reference) pressure
status = nf90_inq_varid(fileID,"PB",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, PB'
if (status == nf90_NoErr) then
allocate(pb(nLon,nLat,nLev,nTime))
status = nf90_get_var(fileID,varID,pb,count=(/nLon,nLat,nLev,nTime/))
endif
endif
if (lread_P) then
! Pertubation pressure
status = nf90_inq_varid(fileID,"P",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, P'
if (status == nf90_NoErr) then
allocate(pp(nLon,nLat,nLev,nTime))
status = nf90_get_var(fileID,varID,pp,count=(/nLon,nLat,nLev,nTime/))
endif
endif
if (lread_PHB) then
! Base state (reference) height
status = nf90_inq_varid(fileID,"PHB",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, PHB'
if (status == nf90_NoErr) then
allocate(phb(nLon,nLat,nLev_stag,nTime))
status = nf90_get_var(fileID,varID,phb,count=(/nLon,nLat,nLev_stag,nTime/))
endif
endif
if (lread_PH) then
! Pertubation height
status = nf90_inq_varid(fileID,"PH",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, PH'
if (status == nf90_NoErr) then
allocate(ph(nLon,nLat,nLev_stag,nTime))
status = nf90_get_var(fileID,varID,ph,count=(/nLon,nLat,nLev_stag,nTime/))
endif
endif
if (lread_ZS) then
! Soil depth (staggered in vertical)
status = nf90_inq_varid(fileID,"ZS",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, ZS'
if (status == nf90_NoErr) then
allocate(zs(nSoil_stag))
status = nf90_get_var(fileID,varID,zs,count=(/nSoil_stag,1/))
endif
endif
if (lread_SMOIS) then
! Soil moisture
status = nf90_inq_varid(fileID,"SMOIS",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, SMOIS'
if (status == nf90_NoErr) then
allocate(smois(nLon,nLat,nSoil_stag,nTime))
status = nf90_get_var(fileID,varID,smois)
endif
endif
if (lread_TSLB) then
! Soil temperature
status = nf90_inq_varid(fileID,"TSLB",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, TSLB'
if (status == nf90_NoErr) then
allocate(tslb(nLon,nLat,nSoil_stag,nTime))
status = nf90_get_var(fileID,varID,tslb)
endif
endif
if (lread_RAINNC) then
! Accumulated total grid scale precipitaiton.
status = nf90_inq_varid(fileID,"RAINNC",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, RAINNC'
if (status == nf90_NoErr) then
allocate(rainnc(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,rainnc)
endif
! Bucket count
status = nf90_inq_varid(fileID,"I_RAINNC",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, I_RAINNC'
if (status == nf90_NoErr) then
allocate(i_rainnc(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,i_rainnc)
endif
! Read in global attribute desribing "bucket size"
status = nf90_get_att(fileID, NF90_GLOBAL, "BUCKET_MM", bucket_size)
if (status /= nf90_NoErr) then
print*,'ERROR: Requested global attribute not in file, BUCKET_MM, setting to default vaule of 100. mm'
bucket_size = 100.
endif
! Compute precipitation.
where(i_rainnc .gt. 0) rainnc = rainnc+i_rainnc*bucket_size
endif
if (lread_RAINC) then
! Accumulated total grid scale cummulus precipitaiton.
status = nf90_inq_varid(fileID,"RAINC",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, RAINC'
if (status == nf90_NoErr) then
allocate(rainc(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,rainc)
endif
! Bucket count
status = nf90_inq_varid(fileID,"I_RAINC",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, I_RAINC'
if (status == nf90_NoErr) then
allocate(i_rainc(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,i_rainc)
endif
! Read in global attribute desribing "bucket size"
status = nf90_get_att(fileID, NF90_GLOBAL, "BUCKET_MM", bucket_size)
if (status /= nf90_NoErr) then
print*,'ERROR: Requested global attribute not in file, BUCKET_MM, setting to default vaule of 100. mm'
bucket_size = 100.
endif
! Compute precipitation.
where(i_rainc .gt. 0) rainc = rainc+i_rainc*bucket_size
endif
if (lread_T2M) then
! Temperature @ 2 meters
status = nf90_inq_varid(fileID,"T2",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, T2'
if (status == nf90_NoErr) then
allocate(t2m(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,t2m)
endif
endif
if (lread_Q2M) then
! Temperature @ 2 meters
status = nf90_inq_varid(fileID,"Q2",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, Q2'
if (status == nf90_NoErr) then
allocate(q2m(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,q2m)
endif
endif
if (lread_TSK) then
! Skin temperature
status = nf90_inq_varid(fileID,"TSK",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, TSK'
if (status == nf90_NoErr) then
allocate(tsk(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,tsk)
endif
endif
if (lread_SST) then
! SST
status = nf90_inq_varid(fileID,"SST",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, SST'
if (status == nf90_NoErr) then
allocate(sst(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,sst)
endif
endif
if (lread_SNOWE) then
! SNOW
status = nf90_inq_varid(fileID,"SNOW",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, SNOW'
if (status == nf90_NoErr) then
allocate(snowe(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,snowe)
endif
endif
if (lread_U10) then
! Zonal wind @ 10 meters
status = nf90_inq_varid(fileID,"U10",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, U10'
if (status == nf90_NoErr) then
allocate(u10m(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,u10m)
endif
endif
if (lread_V10) then
! Meridional wind @ 10 meters
status = nf90_inq_varid(fileID,"V10",varID)
if (status /= nf90_NoErr) print*,'ERROR: Requested variable not in file, V10'
if (status == nf90_NoErr) then
allocate(v10m(nLon,nLat,nTime))
status = nf90_get_var(fileID,varID,v10m)
endif
endif
! 4) Close file
status=nf90_close(fileID)
if (status /= nf90_NoErr) print*,'ERROR: Could not close file, ',trim(fileiN)
if (verbose) print*,'Finished reading in data'
! #############################################################################
! Part B: Computations.
! #############################################################################
! Compute pressure and height.
if (allocated(pb) .and. allocated(pp)) then
allocate(p(nLon,nLat,nLev,nTime))
p = pb+pp
endif
if (allocated(ph) .and. allocated(phb)) then
allocate(hgt(nLon,nLat,nLev_stag,nTime))
hgt = (ph+phb)/9.8
endif
! Allocate space.
allocate(ui(nLev),vi(nLev),temp(nLev),phm(nLev))
if (l_ivt) allocate(ivtU(nLon, nLat, nTime))
if (l_ivt) allocate(ivtV(nLon, nLat, nTime))
if (l_z0k) allocate(z0k( nLon, nLat, nTime))
if (l_z1000) then
allocate(z1000(nlon, nLat, nTime))
z1000(:,:,:) = output_fill_value
endif
if (l_z950) then
allocate(z950(nLon, nLat, nTime))
z950(:,:,:) = output_fill_value
endif
if (l_z900) then
allocate(z900(nLon, nLat, nTime))
z900(:,:,:) = output_fill_value
endif
if (l_z850) then
allocate(z850(nLon, nLat, nTime))
z850(:,:,:) = output_fill_value
endif
if (l_z800) then
allocate(z800(nLon, nLat, nTime))
z800(:,:,:) = output_fill_value
endif
if (l_z750) then
allocate(z750(nLon, nLat, nTime))
z750(:,:,:) = output_fill_value
endif
if (l_z700) then
allocate(z700(nLon, nLat, nTime))
z700(:,:,:) = output_fill_value
endif
if (l_z600) then
allocate(z600(nLon, nLat, nTime))
z600(:,:,:) = output_fill_value
endif
if (l_z500) then
allocate(z500(nLon, nLat, nTime))
z500(:,:,:) = output_fill_value
endif
if (l_z250) then
allocate(z250(nLon, nLat, nTime))
z250(:,:,:) = output_fill_value
endif
if (l_q1000) then
allocate(q1000(nlon, nLat, nTime))
q1000(:,:,:) = output_fill_value
endif
if (l_q950) then
allocate(q950(nLon, nLat, nTime))
q950(:,:,:) = output_fill_value
endif
if (l_q900) then
allocate(q900(nLon, nLat, nTime))
q900(:,:,:) = output_fill_value
endif
if (l_q850) then
allocate(q850(nLon, nLat, nTime))
q850(:,:,:) = output_fill_value
endif
if (l_q800) then
allocate(q800(nLon, nLat, nTime))
q800(:,:,:) = output_fill_value
endif
if (l_q750) then
allocate(q750(nLon, nLat, nTime))
q750(:,:,:) = output_fill_value
endif
if (l_q700) then
allocate(q700(nLon, nLat, nTime))
q700(:,:,:) = output_fill_value
endif
if (l_q600) then
allocate(q600(nLon, nLat, nTime))
q600(:,:,:) = output_fill_value
endif
if (l_q500) then
allocate(q500(nLon, nLat, nTime))
q500(:,:,:) = output_fill_value
endif
if (l_q250) then
allocate(q250(nLon, nLat, nTime))
q250(:,:,:) = output_fill_value
endif
if (l_u1000) then
allocate(u1000(nlon, nLat, nTime))
u1000(:,:,:) = output_fill_value
endif
if (l_u950) then
allocate(u950(nLon, nLat, nTime))
u950(:,:,:) = output_fill_value
endif
if (l_u900) then
allocate(u900(nLon, nLat, nTime))
u900(:,:,:) = output_fill_value
endif
if (l_u850) then
allocate(u850(nLon, nLat, nTime))
u850(:,:,:) = output_fill_value
endif
if (l_u800) then
allocate(u800(nLon, nLat, nTime))
u800(:,:,:) = output_fill_value
endif
if (l_u750) then
allocate(u750(nLon, nLat, nTime))
u750(:,:,:) = output_fill_value
endif
if (l_u700) then
allocate(u700(nLon, nLat, nTime))
u700(:,:,:) = output_fill_value
endif
if (l_u600) then
allocate(u600(nLon, nLat, nTime))
u600(:,:,:) = output_fill_value
endif
if (l_u500) then
allocate(u500(nLon, nLat, nTime))
u500(:,:,:) = output_fill_value
endif
if (l_u250) then
allocate(u250(nLon, nLat, nTime))
u250(:,:,:) = output_fill_value
endif
if (l_v1000) then
allocate(v1000(nlon, nLat, nTime))
v1000(:,:,:) = output_fill_value
endif
if (l_v950) then
allocate(v950(nLon, nLat, nTime))
v950(:,:,:) = output_fill_value
endif
if (l_v900) then
allocate(v900(nLon, nLat, nTime))
v900(:,:,:) = output_fill_value
endif
if (l_v850) then
allocate(v850(nLon, nLat, nTime))
v850(:,:,:) = output_fill_value
endif
if (l_v800) then
allocate(v800(nLon, nLat, nTime))
v800(:,:,:) = output_fill_value
endif
if (l_v750) then
allocate(v750(nLon, nLat, nTime))
v750(:,:,:) = output_fill_value
endif
if (l_v700) then
allocate(v700(nLon, nLat, nTime))
v700(:,:,:) = output_fill_value
endif
if (l_v600) then
allocate(v600(nLon, nLat, nTime))
v600(:,:,:) = output_fill_value
endif
if (l_v500) then
allocate(v500(nLon, nLat, nTime))
v500(:,:,:) = output_fill_value
endif
if (l_v250) then
allocate(v250(nLon, nLat, nTime))
v250(:,:,:) = output_fill_value
endif
if (l_t1000) then
allocate(t1000(nlon, nLat, nTime))
t1000(:,:,:) = output_fill_value
endif
if (l_t950) then
allocate(t950(nLon, nLat, nTime))
t950(:,:,:) = output_fill_value
endif
if (l_t900) then
allocate(t900(nLon, nLat, nTime))
t900(:,:,:) = output_fill_value
endif
if (l_t850) then
allocate(t850(nLon, nLat, nTime))
t850(:,:,:) = output_fill_value
endif
if (l_t800) then
allocate(t800(nLon, nLat, nTime))
t800(:,:,:) = output_fill_value
endif
if (l_t750) then
allocate(t750(nLon, nLat, nTime))
t750(:,:,:) = output_fill_value
endif
if (l_t700) then
allocate(t700(nLon, nLat, nTime))
t700(:,:,:) = output_fill_value
endif
if (l_t600) then
allocate(t600(nLon, nLat, nTime))
t600(:,:,:) = output_fill_value
endif
if (l_t500) then
allocate(t500(nLon, nLat, nTime))
t500(:,:,:) = output_fill_value
endif
if (l_t250) then
allocate(t250(nLon, nLat, nTime))
t250(:,:,:) = output_fill_value
endif
! Loop over all points/times.
if (verbose) print*,'Begin computations... '
do ii=1,nTime
if (verbose) write(*,"(a12,i2,a4,i2)"),' @Timestep ',ii,' of ',nTime
do ij=1,nLon
do ik=1,nLat
! If needed, put winds on mass centered grid points, in WRF the velocity components are on staggered grids.
! Eastward component of wind (on mass-centered point)
if (any([l_u1000,l_u950,l_u900,l_u850,l_u800,l_u750,l_u700,l_u600,l_u500,l_u250]) .or. l_ivt) then
wt1 = (lon_u(ij+1,ik,ii)-lon(ij,ik,ii))/(lon_u(ij+1,ik,ii)-lon_u(ij,ik,ii))
ui = wt1*u(ij,ik,:,ii)+(1-wt1)*u(ij+1,ik,:,ii)
endif
! Northward component of wind (on mass-centered point)
if (any([l_v1000,l_v950,l_v900,l_v850,l_v800,l_v750,l_v700,l_v600,l_v500,l_v250]) .or. l_ivt) then
wt1 = (lat_v(ij,ik+1,ii)-lat(ij,ik,ii)) / (lat_v(ij,ik+1,ii)-lat_v(ij,ik,ii))
vi = wt1*v(ij,ik,:,ii)+(1-wt1)*v(ij,ik+1,:,ii)
endif
! If needed, compute temperature from pertubation potential temperature.
if (any([l_t1000,l_t950,l_t900,l_t850,l_t800,l_t750,l_t700,l_t600,l_t500,l_t250]) .or. l_z0k) then
temp = (ta(ij,ik,:,ii)+t00(ii))*(101325.0/p(ij,ik,:,ii))**(-0.286)
endif
! Geopotential heights are on a staggerd vertical grid, so compute mass-
! centered geopotential height.
if (any([l_u1000,l_u950,l_u900,l_u850,l_u800,l_u750,l_u700,l_u600,l_u500,l_u250]) .or. &
any([l_v1000,l_v950,l_v900,l_v850,l_v800,l_v750,l_v700,l_v600,l_v500,l_v250]) .or. &
any([l_t1000,l_t950,l_t900,l_t850,l_t800,l_t750,l_t700,l_t600,l_t500,l_t250]) .or. &
any([l_q1000,l_q950,l_q900,l_q850,l_q800,l_q750,l_q700,l_q600,l_q500,l_q250]) .or. &
any([l_z1000,l_z950,l_z900,l_z850,l_z800,l_z750,l_z700,l_z600,l_z500,l_z250]) .or. &
l_z0k) then
phm = (hgt(ij,ik,1:nlev_stag-1,ii)+hgt(ij,ik,2:nlev_stag,ii))*0.5
endif
! ######################################################################
! Compute integrated vapor transport (IVT)
! ######################################################################
if (l_ivt) then
do il=1,nLev
! Compute pressure change across layer.
if (.not. toa2sfc) then
if (il .eq. 1) dp = psfc(ij,ik,ii)-sum(p(ij,ik,il:il+1,ii))/2. ! Bottom level
if (il .ne. 1 .and. il .ne. nLev) dp = sum(p(ij,ik,il-1:il,ii))/2.-sum(p(ij,ik,il:il+1,ii))/2. ! Middle levels
if (il .eq. nLev) dp = 0. ! Top level
else
if (il .eq. 1) dp = 0. ! Top level
if (il .ne. 1 .and. il .ne. nLev) dp = sum(p(ij,ik,il-1:il,ii))/2.-sum(p(ij,ik,il:il+1,ii))/2. ! Middle levels
if (il .eq. nLev) dp = psfc(ij,ik,ii)-sum(p(ij,ik,il:il+1,ii))/2. ! Bottom level