forked from DOI-USGS/volcano-ash3d-metreader
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMetReader.F90
5799 lines (5200 loc) · 274 KB
/
MetReader.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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! This file is a component of the volcanic ash transport and dispersion model Ash3d,
! written at the U.S. Geological Survey by Hans F. Schwaiger ([email protected]),
! Larry G. Mastin ([email protected]), and Roger P. Denlinger ([email protected]).
!
! The model and its source code are products of the U.S. Federal Government and therefore
! bear no copyright. They may be copied, redistributed and freely incorporated
! into derivative products. However as a matter of scientific courtesy we ask that
! you credit the authors and cite published documentation of this model (below) when
! publishing or distributing derivative products.
!
! Schwaiger, H.F., Denlinger, R.P., and Mastin, L.G., 2012, Ash3d, a finite-
! volume, conservative numerical model for ash transport and tephra deposition,
! Journal of Geophysical Research, 117, B04204, doi:10.1029/2011JB008968.
!
! Although this program has been used by the USGS, no warranty, expressed or
! implied, is made by the USGS or the United States Government as to the accuracy
! and functioning of the program and related program material nor shall the fact of
! distribution constitute any such warranty, and no responsibility is assumed by
! the USGS in connection therewith.
!
! We make no guarantees, expressed or implied, as to the usefulness of the software
! and its documentation for any purpose. We assume no responsibility to provide
! technical support to users of this software.
!
!
!
! contains:
! subroutine MR_Reset_Memory
! subroutine MR_Allocate_FullMetFileList(iw,iwf,igrid,idf,iwfiles)
! subroutine MR_Read_Met_DimVars(iy)
! subroutine MR_Set_CompProjection(LL_flag,ipf,lam0,phi0,phi1,phi2,ko,Re)
! subroutine MR_Initialize_Met_Grids(nx,ny,nz,dumx_sp,dumy_sp,dumz_sp,periodic)
! subroutine MR_Set_SigmaAlt_Scaling(nz,dums_sp)
! subroutine MR_Set_Met_Times(eStartHour,Duration)
! subroutine MR_Read_HGT_arrays(istep,reset_first_time)
! subroutine MR_Read_3d_MetP_Variable(ivar,istep)
! subroutine MR_Read_3d_MetH_Variable(ivar,istep)
! subroutine MR_Read_3d_Met_Variable_to_CompP(ivar,istep,IsNext)
! subroutine MR_Read_3d_Met_Variable_to_CompH(ivar,istep,IsNext)
! subroutine MR_Read_2d_Met_Variable(ivar,istep)
! subroutine MR_Read_2d_Met_Variable_to_CompGrid(ivar,istep)
! subroutine MR_Rotate_UV_GR2ER_Met(istep,SetComp)
! subroutine MR_Rotate_UV_ER2GR_Comp(istep)
! subroutine MR_Regrid_MetP_to_CompH(istep)
! subroutine MR_Regrid_MetP_to_MetH(istep)
! subroutine MR_Regrid_Met2d_to_Comp2d()
! subroutine MR_DelMetP_Dx()
! subroutine MR_DelMetP_Dy()
! subroutine MR_QC_3dvar(ivar,nx_max,ny_max,nz1_max,z_array_sp,nz2_max,&
! dum_array_sp,fill_val_sp,bc_low_sp, bc_high_sp)
! subroutine MR_Check_Prerequsites(test_allocate,test_dimvars,test_compproj,&
! test_initmetgrid,test_setmettimes)
! subroutine MR_FileIO_Error_Handler(ios,linebuffer080)
! function MR_Temp_US_StdAtm(zin)
! function MR_Z_US_StdAtm(pin)
! function MR_Pres_US_StdAtm(zin)
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module MetReader
! This module requires Fortran 2003 or later
use ieee_arithmetic, only : &
ieee_is_nan
implicit none
! Set everything to private by default
private
! Publicly available subroutines/functions
public MR_Reset_Memory,MR_Allocate_FullMetFileList,MR_Set_CompProjection,&
MR_Read_Met_DimVars,MR_Set_Met_Times,MR_Initialize_Met_Grids,MR_Read_HGT_arrays,&
MR_Read_3d_Met_Variable_to_CompP,MR_Read_3d_Met_Variable_to_CompH,&
MR_Set_SigmaAlt_Scaling,MR_Read_3d_MetP_Variable,MR_Read_3d_MetH_Variable,&
MR_Read_2d_Met_Variable,MR_Read_2d_Met_Variable_to_CompGrid,&
MR_Rotate_UV_GR2ER_Met,MR_Rotate_UV_ER2GR_Comp,&
MR_Regrid_MetP_to_CompH,MR_Regrid_MetP_to_MetH,MR_Regrid_Met2d_to_Comp2d,&
MR_DelMetP_Dx,MR_DelMetP_Dy,&
MR_Temp_US_StdAtm,MR_Z_US_StdAtm,MR_Pres_US_StdAtm,&
MR_QC_3dvar,MR_FileIO_Error_Handler
integer, parameter,private :: sp = selected_real_kind( 6, 37) ! single precision
integer, parameter,private :: dp = selected_real_kind(15, 307) ! double precision
integer, parameter,private :: qp = selected_real_kind(33, 4931) ! quad precision
! Publicly available variables
#include "MR_version.h"
! This file (MR_version.h) is the output of the simple script
!get_version.sh
! echo -n " character(len=40),parameter,public :: MR_GitComID ='" > MR_version.h
! git log -n 1 | grep commit | cut -f 2 -d' ' | tr -d $'\n' >> MR_version.h
! echo -n "'" >> MR_version.h
! which sets the variable containing the git commit ID : MR_GitComID
#ifdef USENETCDF
integer ,public :: NCv_datafile
character(len=80),public :: NCv_lib
#endif
integer ,parameter,public :: MR_MAXVARS = 50 ! Maximum number of variables in fixed arrays
real(kind=sp),parameter,public :: MR_EPS_SMALL = 1.0e-7_sp ! Small number
real(kind=sp),parameter,public :: MR_RAD_EARTH = 6371.229_sp ! Radius of Earth in km
real(kind=sp),parameter,public :: MR_DEG2RAD = 1.7453292519943295e-2_sp
real(kind=sp),parameter :: MR_MIN_DZ = 1.0e-4_sp ! used in reassigning z for low-level negative GPH
! These output levels and stream IDs can be changed by the calling program
! default verbosity is 3
! This will write everything from verbosity_log to verbosity_error to both stdout and stdlog
integer,dimension(2),public :: VB = (/3,3/) ! Verbosity level for stdout and logfile, respectively
integer,public :: MR_VERB = 3
integer,public :: stdin = 5
integer,public :: MR_nio = 1 ! Number of output streams to use: 1 for just stdout,stderr or 2 to include a logfile
integer,dimension(2),public :: outlog = (/6,9/) ! Assumes stdin=6, logfile=9
integer,dimension(2),public :: errlog = (/0,9/) ! Assumes sterr=0, logfile=9
integer,parameter,public :: verbosity_debug2 = 1 ! Additional debugging information only written to stdout
integer,parameter,public :: verbosity_debug1 = 2 ! Debugging information only written to stdout
integer,parameter,public :: verbosity_log = 3 ! Time step information (this is the limit for writing to logfile)
integer,parameter,public :: verbosity_info = 4 ! Additional information on run set up and shutdown
integer,parameter,public :: verbosity_statistics = 5 ! Details on health of run (timing, mass conservation)
integer,parameter,public :: verbosity_production = 6 ! Major program flow info
integer,parameter,public :: verbosity_essential = 7 ! Only start up and shutdown messages
integer,parameter,public :: verbosity_error = 8 ! No logging to stdout, only stderr (and logfile)
integer,parameter,public :: verbosity_silent = 9 ! No logging to stdout,stderr. Logfile written as normal
integer,parameter,public :: verbosity_dark = 10 ! No logging to stdout,stderr or logfile
logical ,public :: MR_useCompGrid = .true. ! Reset this to .false. if you only need the Met grid
logical ,public :: MR_useCompTime = .true. ! Reset this to .false. if you only need the time of the file
logical ,public :: MR_useCompH = .true.
logical ,public :: MR_useCompP = .true.
logical ,public :: MR_useCompS = .false.
integer,public :: MR_iwind ! MR_IWIND specifies the type of wind input to the model:
! MR_IWIND=1 if a 1-D wind sounding is use,
! =2 if a 3-D grid is read from a ASCII file.
! =3 if a single, multistep 3-D file is used
! =4 if multiple 3-D NetCDF files are used
! =5 if multiple file with multiple steps are used
integer,public :: MR_iwindformat ! MR_iwindformat specifies the NWP product
! 0 Custom format based on template
! 1 ASCII profile
! 2 Radiosonde data
! 3 NARR3D 32 km North America files (32 km) :: ds608.0
! 4 NAM Regional North America 221 (32 km)
! 5 NAM AK 216 (45 km)
! 6 NAM Regional 104 (90 km)
! 7 NAM CONUS 212 (40 km)
! 8 NAM CONUS 218 (12 km)
! 9 NAM CONUS 227 (5.08 km)
! 10 NAM AK 242 (11.25 km)
! 11 NAM HI 196 (2.5 km)
! 12 NAM AK 198 (5.953 km)
! 13 NAM AK 91 (2.976 km)
! 14 NAM CONUS 1227 (3.0 km)
! 20 GFS 0.5
! 21 GFS 1.0
! 22 GFS 0.25
! 23 NCEP / DOE reanalysis 2.5 degree files :: ds091.0
! 24 NASA-MERRA-2 reanalysis 0.625/0.5 degree files
! 25 NCEP/NCAR reanalysis 2.5 degree files :: ds090.0 iwind=4 or 5
! 26 JRA-55 :: ds628.0 iwind=5
! 27 NOAA-CIRES reanalysis 2.0 degree files :: ds131.2,3 iwind=5
! 28 ECMWF Interim Reanalysis (ERA-Interim) :: ds627.0 requires catted GRIB files
! 29 ECMWF ERA5 :: ds633.0 iwind=5
! 30 ECMWF 20-Century (ERA-20C) :: ds626.0 iwind=5
! 31 NAM Caribbean 181 (0.108 deg)
! 32 Air Force Weather Agency subcenter = 0
! 33 CCSM3.0 Community Atmosphere Model (CAM)
! 40 NASA-GEOS Cp
! 41 NASA-GEOS Np
! 50 WRF - output
logical,public :: MR_Use_RDA = .false. ! If reanalysis products were aquired via RDA, this flag can be changed
integer,public :: MR_RDAcode = -1 ! This allows the calling program to specify older versions of data
integer,public :: MR_iversion = -1 ! version of the product; sometimes the grid used changes with newer
! versions. -1 indicates latest version, but can be overridden here
integer,public :: MR_iGridCode ! MR_iGridCode specifies the NCEP grid described in:
! http://www.nco.ncep.noaa.gov/pmb/docs/on388/tableb.html
integer,public :: MR_idataFormat ! Specifies the data model used
! =1 ASCII
! =2 NetCDF
! =3 GRIB1 or GRIB2
! These variables describe the full list of windfiles read
integer ,public :: MR_iwindfiles ! number of files provided
character(len=130) ,public :: MR_iw5_root
character(len=42) ,public :: MR_iw5_prefix
character(len=24) ,public :: MR_iw5_suffix1 ! e.g. 1912060100_1912063021.nc
character(len=24) ,public :: MR_iw5_suffix2
real(kind=dp) ,public :: MR_iw5_hours_per_file
#if USEPOINTERS
! character(len=130),dimension(:) ,pointer,public :: fc_windfilename
character(len=130),dimension(:) ,pointer,public :: MR_windfiles => null() ! name of file
real(kind=dp) ,dimension(:) ,pointer,public :: MR_windfile_starthour => null()
real(kind=dp) ,dimension(:,:),pointer,public :: MR_windfile_stephour => null()
integer ,dimension(:) ,pointer,public :: MR_windfiles_nt_fullmet => null() ! number of steps in files
logical ,dimension(:) ,pointer,public :: MR_windfiles_Have_GRIB_index => null()
character(len=130),dimension(:) ,pointer,public :: MR_windfiles_GRIB_index => null() ! name of GRIB index file`
#else
! character(len=130), allocatable,dimension(:) ,public :: fc_windfilename
character(len=130),dimension(:) ,allocatable,public :: MR_windfiles ! name of file
real(kind=dp) ,dimension(:) ,allocatable,public :: MR_windfile_starthour ! start hour of the file
real(kind=dp) ,dimension(:,:),allocatable,public :: MR_windfile_stephour ! offset hours of step
integer ,dimension(:) ,allocatable,public :: MR_windfiles_nt_fullmet ! number of steps in files
logical ,dimension(:) ,allocatable,public :: MR_windfiles_Have_GRIB_index
character(len=130),dimension(:) ,allocatable,public :: MR_windfiles_GRIB_index ! name of GRIB index file
#endif
character(len=80) ,public :: MR_iwf_template ! name of the template file
logical ,public :: MR_Reannalysis = .false.
logical ,public :: MR_Save_Velocities = .false.
! These variables are a list of the same data above, but specific to the simulation
! duration
integer ,public :: MR_MetSteps_Total
integer ,public :: MR_iMetStep_Now
#ifdef USEPOINTERS
character(len=130),dimension(:),pointer,public :: MR_MetStep_File => null()
integer ,dimension(:),pointer,public :: MR_MetStep_findex => null()
integer ,dimension(:),pointer,public :: MR_MetStep_tindex => null()
real(kind=dp) ,dimension(:),pointer,public :: MR_MetStep_Hour_since_baseyear => null()
real(kind=dp) ,dimension(:),pointer,public :: MR_MetStep_Interval => null()
integer ,dimension(:),pointer,public :: MR_MetStep_year => null()
integer ,dimension(:),pointer,public :: MR_MetStep_month => null()
integer ,dimension(:),pointer,public :: MR_MetStep_day => null()
integer ,dimension(:),pointer,public :: MR_MetStep_DOY => null()
real(kind=dp) ,dimension(:),pointer,public :: MR_MetStep_Hour_Of_Day => null()
integer ,dimension(:),pointer,public :: MR_iwind5_year => null()
#else
character(len=130),dimension(:),allocatable,public :: MR_MetStep_File
integer ,dimension(:),allocatable,public :: MR_MetStep_findex
integer ,dimension(:),allocatable,public :: MR_MetStep_tindex
real(kind=dp) ,dimension(:),allocatable,public :: MR_MetStep_Hour_since_baseyear
real(kind=dp) ,dimension(:),allocatable,public :: MR_MetStep_Interval
integer ,dimension(:),allocatable,public :: MR_MetStep_year
integer ,dimension(:),allocatable,public :: MR_MetStep_month
integer ,dimension(:),allocatable,public :: MR_MetStep_day
integer ,dimension(:),allocatable,public :: MR_MetStep_DOY
real(kind=dp) ,dimension(:),allocatable,public :: MR_MetStep_Hour_Of_Day
integer ,dimension(:),allocatable,public :: MR_iwind5_year
#endif
! Native grid of Met file using Pressure as vertical coordinate
#ifdef USEPOINTERS
integer ,dimension(:,:) ,pointer, public :: MR_dum2d_met_int => null() ! Used for categorical variables
real(kind=sp),dimension(:,:) ,pointer, public :: MR_dum2d_met => null() ! Used for surface variables
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d_metP => null()
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d2_metP => null()
real(kind=sp),dimension(:,:,:),pointer, public :: MR_geoH_metP_last => null() ! These are needed for compH interpolation
real(kind=sp),dimension(:,:,:),pointer, public :: MR_geoH_metP_next => null()
real(kind=sp),dimension(:,:,:),pointer, public :: MR_vx_metP_last => null() !These might need to be stored to avoid a
real(kind=sp),dimension(:,:,:),pointer, public :: MR_vx_metP_next => null() !second reading
real(kind=sp),dimension(:,:,:),pointer, public :: MR_vy_metP_last => null()
real(kind=sp),dimension(:,:,:),pointer, public :: MR_vy_metP_next => null()
#else
integer ,dimension(:,:) ,allocatable, public :: MR_dum2d_met_int ! Used for categorical variables
real(kind=sp),dimension(:,:) ,allocatable, public :: MR_dum2d_met ! Used for surface variables
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d_metP
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d2_metP
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_geoH_metP_last ! These are needed for compH interpolation
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_geoH_metP_next
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_vx_metP_last !These might need to be stored to avoid a
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_vx_metP_next !second reading
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_vy_metP_last
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_vy_metP_next
#endif
real(kind=sp), public :: MR_Max_geoH_metP_predicted ! Highest expected height in Met file, based on pressure
real(kind=sp) :: Max_geoH_metP_last
real(kind=sp) :: Max_geoH_metP_next
real(kind=sp) :: Max_geoH_metP
real(kind=sp) :: Suppl_H
!Parameter iHeightHandler specifies what to do if the maximum height
!of the simulation region exceeds the maximum height in the wind files.
!If iHeightHandler = 1, stop the program if the plume height exceeds mesoscale height
! 2, wind direction at levels above the highest node
! equal that of the highest node. Temperatures in the
! upper nodes don't change between 11 and 20 km; above
! 20 km they increase by 2 C/km, as in the Standard
! atmosphere. A warning is written to the log file.
integer ,public :: MR_iHeightHandler = 2
! The following are used for sonde data
integer ,public :: num_RadSnd_Stat
#ifdef USEPOINTERS
character(len=4 ),dimension(:) ,pointer,public :: MR_Snd_cd => null() ! Station code
integer ,dimension(:) ,pointer,public :: MR_Snd_id => null() ! WMO station ID
real(kind=sp) ,dimension(:) ,pointer,public :: MR_Snd_lt => null() ! Station latitude
real(kind=sp) ,dimension(:) ,pointer,public :: MR_Snd_ln => null() ! Station longitude
real(kind=sp) ,dimension(:) ,pointer,public :: MR_Snd_el => null() ! Station elevation
character(len=25),dimension(:) ,pointer,public :: MR_Snd_lnm => null() ! Station long name
character(len=2 ),dimension(:) ,pointer,public :: MR_Snd_st => null() ! Station state
character(len=2 ),dimension(:) ,pointer,public :: MR_Snd_ct => null() ! Station country
integer ,dimension(:) ,pointer,public :: Snd_idx => null() ! Index of radiosonde in master list
real(kind=sp) ,dimension(:,:,:,:),pointer,public :: MR_SndVars_metP => null() ! (MR_nSnd_Locs,MR_Snd_nt_fullmet,MR_Snd_nvars,300)
integer ,dimension(:,:) ,pointer,public :: MR_Snd_np_fullmet => null() ! Number of pressure values for each location/time
integer ,dimension(:) ,pointer,public :: MR_SndVarsID => null() ! Lists which vars are in which columns of MR_SndVars_metP
real(kind=sp) ,dimension(:,:,:) ,pointer,public :: MR_Snd2Comp_map_wgt=> null() ! weights of nearby sondes for every comp point
integer ,dimension(:,:,:) ,pointer,public :: MR_Snd2Comp_map_idx=> null() ! sonde index of weights
#else
character(len=4 ),dimension(:) ,allocatable,public :: MR_Snd_cd ! Station code
integer ,dimension(:) ,allocatable,public :: MR_Snd_id ! WMO station ID
real(kind=sp) ,dimension(:) ,allocatable,public :: MR_Snd_lt ! Station latitude
real(kind=sp) ,dimension(:) ,allocatable,public :: MR_Snd_ln ! Station longitude
real(kind=sp) ,dimension(:) ,allocatable,public :: MR_Snd_el ! Station elevation
character(len=25),dimension(:) ,allocatable,public :: MR_Snd_lnm ! Station long name
character(len=2 ),dimension(:) ,allocatable,public :: MR_Snd_st ! Station state
character(len=2 ),dimension(:) ,allocatable,public :: MR_Snd_ct ! Station country
integer ,dimension(:) ,allocatable,public :: Snd_idx ! Index of radiosonde in master list
real(kind=sp) ,dimension(:,:,:,:),allocatable,public :: MR_SndVars_metP ! (MR_nSnd_Locs,MR_Snd_nt_fullmet,MR_Snd_nvars,300)
integer ,dimension(:,:) ,allocatable,public :: MR_Snd_np_fullmet ! Number of pressure values for each location/time
integer ,dimension(:) ,allocatable,public :: MR_SndVarsID ! Lists which vars are in which columns of MR_SndVars_metP
real(kind=sp) ,dimension(:,:,:) ,allocatable,public :: MR_Snd2Comp_map_wgt ! weights of nearby sondes for every comp point
integer ,dimension(:,:,:) ,allocatable,public :: MR_Snd2Comp_map_idx ! sonde index of weights
#endif
integer,public :: MR_nSnd_Locs = 1 ! Number of Sonde locations
integer,public :: MR_Snd_nt_fullmet = 1 ! Number of times at the Sonde locations
integer,public :: MR_Snd_nvars = 5 ! Number of Sonde variables (P,H,U,V,T,+user-specified)
logical,public :: Snd_Have_PT = .false. ! 3-col ASCII input do not have pres and temp
logical,public :: Snd_Have_Coord = .false. ! If the 1-d data have the optional projection params
! then it will be used, otherwise vel will be relative
! to comp grid.
integer , public :: MR_nstat = 8 ! number of stations to consider (0 for all)
real(kind=sp) , public :: MR_pexp = 4.0_sp ! exponent for inverse distance calculation
! Native grid of Met file using Height as vertical coordinate
! (resampled onto z-gridpoints of computational grid)
#ifdef USEPOINTERS
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d_metH => null()
real(kind=sp),dimension(:,:,:),pointer, public :: MR_u_ER_metP => null()! For the cases where Met is proj and comp
real(kind=sp),dimension(:,:,:),pointer, public :: MR_v_ER_metP => null()! different we need to rotate so these
! store Earth-Relative velocities on MetP
#else
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d_metH
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_u_ER_metP ! For the cases where Met is proj and comp
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_v_ER_metP ! different we need to rotate so these
! store Earth-Relative velocities on MetP
#endif
! Computations grid
#ifdef USEPOINTERS
integer ,dimension(:,:) ,pointer, public :: MR_dum2d_comp_int => null() ! Used for categorical variables
real(kind=sp),dimension(:,:) ,pointer, public :: MR_dum2d_comp => null() ! Used for surface variables
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d_compP => null() !
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d_compP_2 => null() !
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d_compH => null() !
real(kind=sp),dimension(:,:,:),pointer, public :: MR_dum3d_compH_2 => null() ! Used only when a vector field
! rotation is needed
#else
integer ,dimension(:,:) ,allocatable, public :: MR_dum2d_comp_int ! Used for categorical variables
real(kind=sp),dimension(:,:) ,allocatable, public :: MR_dum2d_comp ! Used for surface variables
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d_compP !
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d_compP_2 !
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d_compH !
real(kind=sp),dimension(:,:,:),allocatable, public :: MR_dum3d_compH_2 ! Used only when a vector field
! rotation is needed
#endif
integer,public :: nt_fullmet ! length of t of file
integer,public :: nx_fullmet ! length of x or lon of full met grid
integer,public :: ny_fullmet ! length of y or lat of full met grid
integer,public :: np_fullmet ! length of pressure of full met grid for H,U,V
integer :: np_fullmet_pad = 1 ! We might need to pad the top of the pressure grid.
integer,public :: neta_fullmet ! Only used by WRF
real(kind=sp),public :: Pressure_Conv_Fac = 100.0_sp ! factor for converting from Met file units to Pa
#ifdef USEPOINTERS
real(kind=sp),dimension(:), pointer,public :: x_fullmet_sp => null() ! x-coordinates of full met grid
real(kind=sp),dimension(:), pointer,public :: y_fullmet_sp => null() ! y-coordinates of full met grid
real(kind=sp),dimension(:), pointer,public :: p_fullmet_sp => null() ! z-coordinates of full met grid for H
real(kind=sp),dimension(:,:), pointer,public :: levs_fullmet_sp => null() ! This hold each of the numbered level coordinates:
! i.e. isobaric, isobaric1, isobaric2, but also
! height_above_ground, depth_below_surface_layer, etc.
! p_fullmet_sp,p_fullmet_[Vz,RH]sp are copies of one
! of the slices
integer,dimension(:), pointer,public :: nlevs_fullmet ! length of z coordinate
integer,dimension(:), pointer,public :: levs_code ! code indicating how to map to the GPH grid
! 0 = no mapping (not a pressure coordinate)
! 1 = one-to-one mapping (U,V)
! 2 = upper truncation (missing upper levels)
! 3 = interpolation (missing mid-levels)
! 4 = more levels than GPH grid
#else
real(kind=sp),dimension(:), allocatable,public :: x_fullmet_sp ! x-coordinates of full met grid
real(kind=sp),dimension(:), allocatable,public :: y_fullmet_sp ! y-coordinates of full met grid
real(kind=sp),dimension(:), allocatable,public :: p_fullmet_sp ! z-coordinates of full met grid for H
real(kind=sp),dimension(:,:),allocatable,public :: levs_fullmet_sp ! This hold each of the numbered level coordinates:
! i.e. isobaric, isobaric1, isobaric2, but also
! height_above_ground, depth_below_surface_layer, etc.
! p_fullmet_sp,p_fullmet_[Vz,RH]sp are copies of one
! of the slices
integer,dimension(:), allocatable,public :: nlevs_fullmet
integer,dimension(:), allocatable,public :: levs_code ! code indicating how to map to the GPH grid
! 0 = no mapping (not a pressure coordinate)
! 1 = one-to-one mapping (U,V)
! 2 = upper truncation (missing upper levels)
! 3 = interpolation (missing mid-levels)
! 4 = more levels than GPH grid
#endif
logical,public :: IsLatLon_MetGrid
logical,public :: IsGlobal_MetGrid = .false. ! Not all Lon/Lat grids are periodic
logical,public :: IsLatLon_CompGrid
logical,public :: IsPeriodic_CompGrid = .false.
logical,public :: UseFullMetGrid = .false. ! This is the special case where the comp grid
! equals the Met grid
logical,public :: isGridRelative = .true. ! Most windfiles, whether Lat/Lon or projected, give
! velocities relative to the grid of the file. Some (NARR)
! give velocities relative to earth coordinates and need to
! be rotated
logical,public :: IsRegular_MetGrid ! True if the grid-spacing is uniform
real(kind=sp),public :: dx_met_const
real(kind=sp),public :: dy_met_const
integer,public :: nx_submet ! length of x or lon of sub-grid
integer,public :: ny_submet ! length of y or lat of sub-grid
#ifdef USEPOINTERS
real(kind=sp),dimension(:), pointer,public :: x_submet_sp => null() ! x-coordinates of met sub-grid
real(kind=sp),dimension(:), pointer,public :: y_submet_sp => null() ! y-coordinates of met sub-grid
real(kind=sp),dimension(:), pointer,public :: z_approx => null() ! approximate altidue from STD Atmos and press (in km)
real(kind=dp),dimension(:,:),pointer,public :: theta_Met => null() ! Earth to grid
real(kind=dp),dimension(:,:),pointer,public :: theta_Comp => null() ! Earth to grid
real(kind=dp),dimension(:,:),pointer,public :: MR_xy2ll_xlon => null() ! holds longitude of projected grid
real(kind=dp),dimension(:,:),pointer,public :: MR_xy2ll_ylat => null() ! holds latitude of projected grid
#else
real(kind=sp),dimension(:) ,allocatable,public :: x_submet_sp ! x-coordinates of met sub-grid
real(kind=sp),dimension(:) ,allocatable,public :: y_submet_sp ! y-coordinates of met sub-grid
real(kind=sp),dimension(:) ,allocatable,public :: z_approx ! approximate altitude from STD Atmos and press (in km)
real(kind=dp),dimension(:,:),allocatable,public :: theta_Met ! Earth to grid
real(kind=dp),dimension(:,:),allocatable,public :: theta_Comp ! Earth to grid
real(kind=dp),dimension(:,:),allocatable,public :: MR_xy2ll_xlon ! holds longitude of projected grid
real(kind=dp),dimension(:,:),allocatable,public :: MR_xy2ll_ylat ! holds latitude of projected grid
#endif
real(kind=sp),public :: MR_lonmin,MR_lonmax
real(kind=sp),public :: MR_latmin,MR_latmax
logical,public :: x_inverted = .false.
logical,public :: y_inverted = .false. ! Some LatLon grids start at the North Pole and increment down
logical,public :: z_inverted = .false. ! Some grids give top pressure first
logical,public :: y_pad_North = .false. ! Some computational grids will require values above the top met point
logical,public :: y_pad_South = .false. !
! Met copies of projection variables, used for proj call on Met Grid
character(len=4),public :: Met_gridtype
integer ,public :: Met_iprojflag
real(kind=8),public :: Met_Re
real(kind=8),public :: Met_k0
real(kind=8),public :: Met_phi0 ! latitude of projection point
real(kind=8),public :: Met_phi1
real(kind=8),public :: Met_phi2
real(kind=8),public :: Met_lam0 ! longitude of projection point
real(kind=8),public :: Met_lam1
real(kind=8),public :: Met_lam2
character(len=80),public :: Met_proj4
integer ,public :: Comp_iprojflag
real(kind=8),public :: Comp_Re
real(kind=8),public :: Comp_k0
real(kind=8),public :: Comp_phi0 ! latitude of projection point
real(kind=8),public :: Comp_phi1
real(kind=8),public :: Comp_phi2
real(kind=8),public :: Comp_lam0 ! longitude of projection point
real(kind=8),public :: Comp_lam1
real(kind=8),public :: Comp_lam2
character(len=100),public :: Comp_proj4
integer ,public :: Map_Case
! Some geometry terms
#ifdef USEPOINTERS
real(kind=sp),dimension(:,:) ,pointer :: rdphi_MetP_sp => null()
real(kind=sp),dimension(:,:,:) ,pointer :: rdlambda_MetP_sp => null()
real(kind=sp),dimension(:) ,pointer ,public :: MR_dx_met => null()
real(kind=sp),dimension(:) ,pointer ,public :: MR_dx_submet => null()
real(kind=sp),dimension(:) ,pointer ,public :: MR_dy_met => null()
real(kind=sp),dimension(:) ,pointer ,public :: MR_dy_submet => null()
real(kind=sp),dimension(:,:) ,pointer ,public :: MR_sigma_nz_submet => null()
#else
real(kind=sp),dimension(:,:) ,allocatable :: rdphi_MetP_sp
real(kind=sp),dimension(:,:,:) ,allocatable :: rdlambda_MetP_sp
real(kind=sp),dimension(:) ,allocatable,public :: MR_dx_met
real(kind=sp),dimension(:) ,allocatable,public :: MR_dx_submet
real(kind=sp),dimension(:) ,allocatable,public :: MR_dy_met
real(kind=sp),dimension(:) ,allocatable,public :: MR_dy_submet
real(kind=sp),dimension(:,:) ,allocatable,public :: MR_sigma_nz_submet
#endif
real(kind=sp),public :: MR_minlen = 100000.0_sp ! minimum length of the met subgrid (m)
! There are some computational grid variables we might need, so make local copies
integer ,public :: MR_BaseYear = 1900 ! This should be reset in calling program
logical ,public :: MR_useLeap = .true. ! This too
integer ,public :: MR_Comp_StartYear
integer ,public :: MR_Comp_StartMonth
integer ,public :: MR_Comp_StartDay
real(kind=dp),public :: MR_Comp_StartHour = 0.0_dp ! Note that these must be double-precision to
real(kind=dp),public :: MR_Comp_Time_in_hours = 0.0_dp ! be passed correctly to HoursSince
integer ,public :: nx_comp
integer ,public :: ny_comp
integer ,public :: nz_comp
real(kind=sp) :: dx_comp,dy_comp
real(kind=sp) :: MaxZ_comp_sp
#ifdef USEPOINTERS
real(kind=sp),dimension(:), pointer,public :: x_comp_sp => null() ! x-coordinates of computational grid
real(kind=sp),dimension(:), pointer,public :: y_comp_sp => null() ! y-coordinates of computational grid
real(kind=sp),dimension(:), pointer,public :: z_comp_sp => null() ! z-coordinates of computational grid
real(kind=sp),dimension(:,:), pointer,public :: CompPoint_X_on_Met_sp => null() ! x-coord (on Met grid) of comp point
real(kind=sp),dimension(:,:), pointer,public :: CompPoint_Y_on_Met_sp => null() ! y-coord (on Met grid) of comp point
integer ,dimension(:,:,:),pointer,public :: CompPoint_on_subMet_idx => null() ! index on met sub-grid of comp point
real(kind=sp),dimension(:,:,:),pointer,public :: bilin_map_wgt => null()
#else
real(kind=sp),dimension(:), allocatable,public :: x_comp_sp ! x-coordinates of computational grid
real(kind=sp),dimension(:), allocatable,public :: y_comp_sp ! y-coordinates of computational grid
real(kind=sp),dimension(:), allocatable,public :: z_comp_sp ! z-coordinates of computational grid
real(kind=sp),dimension(:,:), allocatable,public :: CompPoint_X_on_Met_sp ! x-coord (on Met grid) of comp point
real(kind=sp),dimension(:,:), allocatable,public :: CompPoint_Y_on_Met_sp ! y-coord (on Met grid) of comp point
integer ,dimension(:,:,:),allocatable,public :: CompPoint_on_subMet_idx ! index on met sub-grid of comp point
real(kind=sp),dimension(:,:,:),allocatable,public :: bilin_map_wgt
#endif
! Here are a few variables needed for sigma-altitude coordinates
logical ,public :: MR_useTopo = .false.
integer ,public :: MR_ZScaling_ID = 0 ! = 0 for no scaling (i.e. s = z)
! = 1 for shifted-altitude (s=z-zsurf)
! = 2 for sigma-altitude (s=Ztop*(z-zsurf)/(ztop-zsurf))
real(kind=sp) ,public :: MR_ztop
#ifdef USEPOINTERS
real(kind=sp),dimension(:) ,pointer, public :: s_comp_sp => null() ! s-coordinates (scaled z) of comp. grid
real(kind=sp),dimension(:,:) ,pointer, public :: MR_Topo_met => null()
real(kind=sp),dimension(:,:) ,pointer, public :: MR_Topo_comp => null()
real(kind=sp),dimension(:,:) ,pointer, public :: MR_jacob_met => null() ! Jacobian of trans. = MR_ztop-MR_Topo_met
real(kind=sp),dimension(:,:) ,pointer, public :: MR_jacob_comp => null()
#else
real(kind=sp),dimension(:) ,allocatable, public :: s_comp_sp ! s-coordinates (scaled z) of computational grid
real(kind=sp),dimension(:,:) ,allocatable, public :: MR_Topo_met
real(kind=sp),dimension(:,:) ,allocatable, public :: MR_Topo_comp
real(kind=sp),dimension(:,:) ,allocatable, public :: MR_jacob_met ! Jacobian of trans. = MR_ztop-MR_Topo_met
real(kind=sp),dimension(:,:) ,allocatable, public :: MR_jacob_comp
#endif
logical ,public :: FoundFillVAttr = .false.
real(kind=sp),public :: fill_value_sp = -9999.0_sp ! Initialize to the commonly used fill value
character(len=30),dimension(9),public :: Met_dim_names ! name of dimension
logical ,dimension(9),public :: Met_dim_IsAvailable
real(kind=sp) ,dimension(9),public :: Met_dim_fac = 1.0_sp
! Here is the list of variables that can be read. Each iwindformat will
! have just a sub-set available with specific names. For now, allocate
! space for 50 variable names
! Mechanical / State variables
! 1 = Geopotential Height
! 2 = Vx : m/s
! 3 = Vy : m/s
! 4 = Vz : m/s
! 5 = Temperature : K
! 6 = pressure (when 3d for eta grids) : Pa
! 7 = PVV (Pressure Vertical Vel.) : Pa/s
! Surface
! 10 = Planetary Boundary Layer Height
! 11 = U @ 10m
! 12 = V @ 10m
! 13 = Friction velocity
! 15 = Snow cover
! 16 = Soil moisture
! 17 = Surface Roughness
! 18 = Wind gust speed
! 19 = surface temperature
! Atmospheric Structure
! 20 = pressure at lower cloud base
! 21 = pressure at lower cloud top
! 22 = temperature at lower cloud top
! 23 = Total Cloud cover
! 24 = Cloud cover (low)
! 25 = Cloud cover (convective)
! Moisture
! 30 = Rel. Hum
! 31 = QV (specific humidity)
! 32 = QL (liquid)
! 33 = QI (ice)
! Precipitation
! 40 = Categorical rain
! 41 = Categorical snow
! 42 = Categorical frozen rain
! 43 = Categorical ice
! 44 = Precipitation rate large-scale (liquid)
! 45 = Precipitation rate convective (liquid)
! 46 = Precipitation rate large-scale (ice)
! 47 = Precipitation rate convective (ice)
logical ,dimension(MR_MAXVARS),public :: Met_var_IsAvailable ! true if iwf contains the var
character(len=80),dimension(MR_MAXVARS),public :: Met_var_NC_names ! name in the file
character(len=80),dimension(MR_MAXVARS),public :: Met_var_GRIB_names ! name in the file
character(len=5) ,dimension(MR_MAXVARS),public :: Met_var_WMO_names ! WMO version of the name
integer ,dimension(MR_MAXVARS),public :: Met_var_ndim ! number of expected dimensions for this variable
integer ,dimension(MR_MAXVARS),public :: Met_var_zdim_idx ! The index of this coordinate (used in Met_var_nlevs)
integer ,dimension(MR_MAXVARS),public :: Met_var_zdim_ncid ! The dimID of the dimension in the nc file
integer ,public :: nlev_coords_detected = 0
integer ,dimension(MR_MAXVARS,4),public :: Met_var_GRIB2_DPcPnSt ! Grib2 files have variables identified by
! discpln,param_cat,param_num,surf_class
integer ,dimension(MR_MAXVARS),public :: Met_var_GRIB1_Param ! indicatorOfParameter
integer ,dimension(MR_MAXVARS),public :: Met_var_GRIB1_Table ! table2Version
character(len=3) ,dimension(MR_MAXVARS),public :: Met_var_GRIB1_St ! level type: pl (100), sfc (001), etc
integer ,public :: MR_GRIB_Version = 0
real(kind=sp) ,dimension(MR_MAXVARS),public :: Met_var_conversion_factor
integer ,dimension(MR_MAXVARS) :: Met_var_nlevs
! Variables needed by netcdf reader
real(kind=sp),public :: iwf25_scale_facs(MR_MAXVARS)
real(kind=sp),public :: iwf25_offsets(MR_MAXVARS)
integer,public :: istart
integer,public :: iend
integer,public :: jstart
integer,public :: jend
integer,public :: ilhalf_fm_l
integer,public :: ilhalf_fm_r
integer,public :: irhalf_fm_l
integer,public :: irhalf_fm_r
integer,public :: ilhalf_nx
integer,public :: irhalf_nx
logical,public :: wrapgrid
#ifdef USEPOINTERS
character ,dimension(:) ,pointer,public :: temp1d_byte => null()
character ,dimension(:) ,pointer,public :: temp1d_char => null()
integer(kind=2) ,dimension(:) ,pointer,public :: temp1d_intS => null()
integer(kind=4) ,dimension(:) ,pointer,public :: temp1d_intL => null()
real(kind=sp) ,dimension(:) ,pointer,public :: temp1d_sp => null()
real(kind=dp) ,dimension(:) ,pointer,public :: temp1d_dp => null()
real(kind=sp) ,dimension(:,:,:) ,pointer,public :: temp2d_sp => null()
real(kind=sp) ,dimension(:,:,:,:) ,pointer,public :: temp3d_sp => null()
integer(kind=sp),dimension(:,:,:) ,pointer,public :: temp2d_int => null()
integer(kind=sp),dimension(:,:,:) ,pointer :: temp2d_short => null()
integer(kind=sp),dimension(:,:,:,:) ,pointer,public :: temp3d_short => null()
real(kind=dp) ,dimension(:,:,:,:) ,pointer,public :: temp3d_dp => null()
real(kind=4) ,dimension(:,:) ,pointer,public :: Met_Proj_lat => null()
real(kind=4) ,dimension(:,:) ,pointer,public :: Met_Proj_lon => null()
#else
character ,dimension(:) ,allocatable,public :: temp1d_byte
character ,dimension(:) ,allocatable,public :: temp1d_char
integer(kind=2) ,dimension(:) ,allocatable,public :: temp1d_intS
integer(kind=4) ,dimension(:) ,allocatable,public :: temp1d_intL
real(kind=sp) ,dimension(:) ,allocatable,public :: temp1d_sp
real(kind=dp) ,dimension(:) ,allocatable,public :: temp1d_dp
real(kind=sp) ,dimension(:,:,:) ,allocatable,public :: temp2d_sp
real(kind=sp) ,dimension(:,:,:,:) ,allocatable,public :: temp3d_sp
integer(kind=sp),dimension(:,:,:) ,allocatable,public :: temp2d_int
integer(kind=sp),dimension(:,:,:) ,allocatable :: temp2d_short
real(kind=dp) ,dimension(:,:,:,:) ,allocatable,public :: temp3d_dp
integer(kind=sp),dimension(:,:,:,:) ,allocatable,public :: temp3d_short
real(kind=4) ,dimension(:,:) ,allocatable,public :: Met_Proj_lat
real(kind=4) ,dimension(:,:) ,allocatable,public :: Met_Proj_lon
#endif
! Status variables for error-checking
logical :: Check_prereq_conditions = .true.
logical :: CALLED_MR_Allocate_FullMetFileList = .false.
logical :: CALLED_MR_Read_Met_DimVars = .false.
logical :: CALLED_MR_Set_CompProjection = .false.
logical :: CALLED_MR_Initialize_Met_Grids = .false.
logical :: CALLED_MR_Set_Met_Times = .false.
! Info on how to build file paths
! Defaults to linux-style, but this can be changed in the calling program
integer ,public :: MR_OS_TYPE = 1 ! 1=Linux, 2=MacOS, 3=MS Windows
character (len=2),public :: MR_DirPrefix = ''
character (len=1),public :: MR_DirDelim = '/'
contains
!##############################################################################
!
! MR_Reset_Memory
!
! This subroutine reinitializes MetReader by deallocating all MR variables.
! This is useful if a program needs to use multiple types of wind files.
!
!##############################################################################
subroutine MR_Reset_Memory
integer :: io ! Index for output streams
do io=1,MR_nio;if(VB(io).le.verbosity_production)then
write(outlog(io),*)"-------------------------------------------------------"
write(outlog(io),*)"-------- Resetting all MetReader Memory ---------------"
write(outlog(io),*)"-------------------------------------------------------"
endif;enddo
#ifdef USEPOINTERS
if(associated(MR_windfile_starthour ))deallocate(MR_windfile_starthour)
if(associated(MR_windfile_stephour ))deallocate(MR_windfile_stephour)
if(associated(MR_windfiles_nt_fullmet ))deallocate(MR_windfiles_nt_fullmet)
if(associated(MR_windfiles_Have_GRIB_index ))deallocate(MR_windfiles_Have_GRIB_index)
if(associated(MR_windfiles_GRIB_index ))deallocate(MR_windfiles_GRIB_index)
if(associated(MR_MetStep_File ))deallocate(MR_MetStep_File)
if(associated(MR_MetStep_findex ))deallocate(MR_MetStep_findex)
if(associated(MR_MetStep_tindex ))deallocate(MR_MetStep_tindex)
if(associated(MR_MetStep_Hour_since_baseyear))deallocate(MR_MetStep_Hour_since_baseyear)
if(associated(MR_MetStep_Interval ))deallocate(MR_MetStep_Interval)
if(associated(MR_MetStep_year ))deallocate(MR_MetStep_year)
if(associated(MR_MetStep_month ))deallocate(MR_MetStep_month)
if(associated(MR_MetStep_day ))deallocate(MR_MetStep_day)
if(associated(MR_MetStep_DOY ))deallocate(MR_MetStep_DOY)
if(associated(MR_MetStep_Hour_Of_Day ))deallocate(MR_MetStep_Hour_Of_Day)
if(associated(MR_iwind5_year ))deallocate(MR_iwind5_year)
if(associated(MR_windfiles ))deallocate(MR_windfiles)
if(associated(MR_dum2d_met_int ))deallocate(MR_dum2d_met_int)
if(associated(MR_dum2d_met ))deallocate(MR_dum2d_met)
if(associated(MR_dum3d_metP ))deallocate(MR_dum3d_metP)
if(associated(MR_dum3d2_metP ))deallocate(MR_dum3d2_metP)
if(associated(MR_geoH_metP_last ))deallocate(MR_geoH_metP_last)
if(associated(MR_geoH_metP_next ))deallocate(MR_geoH_metP_next)
if(associated(MR_vx_metP_last ))deallocate(MR_vx_metP_last)
if(associated(MR_vx_metP_next ))deallocate(MR_vx_metP_next)
if(associated(MR_vy_metP_last ))deallocate(MR_vy_metP_last)
if(associated(MR_vy_metP_next ))deallocate(MR_vy_metP_next)
if(associated(MR_dum3d_metH ))deallocate(MR_dum3d_metH)
if(associated(MR_dum2d_comp_int ))deallocate(MR_dum2d_comp_int)
if(associated(MR_dum2d_comp ))deallocate(MR_dum2d_comp)
if(associated(MR_dum3d_compP ))deallocate(MR_dum3d_compP)
if(associated(MR_dum3d_compP_2 ))deallocate(MR_dum3d_compP_2)
if(associated(MR_dum3d_compH ))deallocate(MR_dum3d_compH)
if(associated(MR_dum3d_compH_2 ))deallocate(MR_dum3d_compH_2)
if(associated(x_fullmet_sp ))deallocate(x_fullmet_sp)
if(associated(y_fullmet_sp ))deallocate(y_fullmet_sp)
if(associated(p_fullmet_sp ))deallocate(p_fullmet_sp)
if(associated(x_submet_sp ))deallocate(x_submet_sp)
if(associated(y_submet_sp ))deallocate(y_submet_sp)
if(associated(levs_fullmet_sp ))deallocate(levs_fullmet_sp)
if(associated(nlevs_fullmet ))deallocate(nlevs_fullmet)
if(associated(levs_code ))deallocate(levs_code)
if(associated(z_approx ))deallocate(z_approx)
if(associated(rdphi_MetP_sp ))deallocate(rdphi_MetP_sp)
if(associated(rdlambda_MetP_sp ))deallocate(rdlambda_MetP_sp)
if(associated(MR_dx_met ))deallocate(MR_dx_met)
if(associated(MR_dx_submet ))deallocate(MR_dx_submet)
if(associated(MR_dy_met ))deallocate(MR_dy_met)
if(associated(MR_dy_submet ))deallocate(MR_dy_submet)
if(associated(MR_sigma_nz_submet ))deallocate(MR_sigma_nz_submet)
if(associated(x_comp_sp ))deallocate(x_comp_sp)
if(associated(y_comp_sp ))deallocate(y_comp_sp)
if(associated(z_comp_sp ))deallocate(z_comp_sp)
if(associated(CompPoint_X_on_Met_sp ))deallocate(CompPoint_X_on_Met_sp)
if(associated(CompPoint_Y_on_Met_sp ))deallocate(CompPoint_Y_on_Met_sp)
if(associated(CompPoint_on_subMet_idx ))deallocate(CompPoint_on_subMet_idx)
if(associated(bilin_map_wgt ))deallocate(bilin_map_wgt)
if(associated(s_comp_sp ))deallocate(s_comp_sp)
if(associated(MR_Topo_met ))deallocate(MR_Topo_met)
if(associated(MR_jacob_met ))deallocate(MR_jacob_met)
if(associated(MR_Topo_comp ))deallocate(MR_Topo_comp)
if(associated(MR_jacob_comp ))deallocate(MR_jacob_comp)
if(associated(MR_u_ER_metP ))deallocate(MR_u_ER_metP)
if(associated(MR_v_ER_metP ))deallocate(MR_v_ER_metP)
if(associated(theta_Met ))deallocate(theta_Met)
if(associated(theta_Comp ))deallocate(theta_Comp)
if(associated(MR_xy2ll_xlon ))deallocate(MR_xy2ll_xlon)
if(associated(MR_xy2ll_ylat ))deallocate(MR_xy2ll_ylat)
if(associated(temp1d_sp ))deallocate(temp1d_sp)
if(associated(temp2d_sp ))deallocate(temp2d_sp)
if(associated(temp3d_sp ))deallocate(temp3d_sp)
if(associated(temp2d_int ))deallocate(temp2d_int)
if(associated(temp2d_short ))deallocate(temp2d_short)
if(associated(temp3d_short ))deallocate(temp3d_short)
if(associated(Met_Proj_lat ))deallocate(Met_Proj_lat)
if(associated(Met_Proj_lon ))deallocate(Met_Proj_lon)
if(associated(MR_SndVars_metP ))deallocate(MR_SndVars_metP)
if(associated(MR_SndVarsID ))deallocate(MR_SndVarsID)
if(associated(MR_Snd_np_fullmet ))deallocate(MR_Snd_np_fullmet)
if(associated(MR_Snd2Comp_map_wgt ))deallocate(MR_Snd2Comp_map_wgt)
if(associated(MR_Snd2Comp_map_idx ))deallocate(MR_Snd2Comp_map_idx)
if(associated(Snd_idx ))deallocate(Snd_idx)
if(associated(MR_Snd_cd ))deallocate(MR_Snd_cd)
if(associated(MR_Snd_id ))deallocate(MR_Snd_id)
if(associated(MR_Snd_lt ))deallocate(MR_Snd_lt)
if(associated(MR_Snd_ln ))deallocate(MR_Snd_ln)
if(associated(MR_Snd_el ))deallocate(MR_Snd_el)
if(associated(MR_Snd_lnm ))deallocate(MR_Snd_lnm)
if(associated(MR_Snd_st ))deallocate(MR_Snd_st)
if(associated(MR_Snd_ct ))deallocate(MR_Snd_ct)
#else
if(allocated(MR_windfile_starthour ))deallocate(MR_windfile_starthour)
if(allocated(MR_windfile_stephour ))deallocate(MR_windfile_stephour)
if(allocated(MR_windfiles_nt_fullmet ))deallocate(MR_windfiles_nt_fullmet)
if(allocated(MR_windfiles_Have_GRIB_index ))deallocate(MR_windfiles_Have_GRIB_index)
if(allocated(MR_windfiles_GRIB_index ))deallocate(MR_windfiles_GRIB_index)
if(allocated(MR_MetStep_File ))deallocate(MR_MetStep_File)
if(allocated(MR_MetStep_findex ))deallocate(MR_MetStep_findex)
if(allocated(MR_MetStep_tindex ))deallocate(MR_MetStep_tindex)
if(allocated(MR_MetStep_Hour_since_baseyear ))deallocate(MR_MetStep_Hour_since_baseyear)
if(allocated(MR_MetStep_Interval ))deallocate(MR_MetStep_Interval)
if(allocated(MR_MetStep_year ))deallocate(MR_MetStep_year)
if(allocated(MR_MetStep_month ))deallocate(MR_MetStep_month)
if(allocated(MR_MetStep_day ))deallocate(MR_MetStep_day)
if(allocated(MR_MetStep_DOY ))deallocate(MR_MetStep_DOY)
if(allocated(MR_MetStep_Hour_Of_Day ))deallocate(MR_MetStep_Hour_Of_Day)
if(allocated(MR_iwind5_year ))deallocate(MR_iwind5_year)
if(allocated(MR_windfiles ))deallocate(MR_windfiles)
if(allocated(MR_dum2d_met_int ))deallocate(MR_dum2d_met_int)
if(allocated(MR_dum2d_met ))deallocate(MR_dum2d_met)
if(allocated(MR_dum3d_metP ))deallocate(MR_dum3d_metP)
if(allocated(MR_dum3d2_metP ))deallocate(MR_dum3d2_metP)
if(allocated(MR_geoH_metP_last ))deallocate(MR_geoH_metP_last)
if(allocated(MR_geoH_metP_next ))deallocate(MR_geoH_metP_next)
if(allocated(MR_vx_metP_last ))deallocate(MR_vx_metP_last)
if(allocated(MR_vx_metP_next ))deallocate(MR_vx_metP_next)
if(allocated(MR_vy_metP_last ))deallocate(MR_vy_metP_last)
if(allocated(MR_vy_metP_next ))deallocate(MR_vy_metP_next)
if(allocated(MR_dum3d_metH ))deallocate(MR_dum3d_metH)
if(allocated(MR_dum2d_comp_int ))deallocate(MR_dum2d_comp_int)
if(allocated(MR_dum2d_comp ))deallocate(MR_dum2d_comp)
if(allocated(MR_dum3d_compP ))deallocate(MR_dum3d_compP)
if(allocated(MR_dum3d_compP_2 ))deallocate(MR_dum3d_compP_2)
if(allocated(MR_dum3d_compH ))deallocate(MR_dum3d_compH)
if(allocated(MR_dum3d_compH_2 ))deallocate(MR_dum3d_compH_2)
if(allocated(x_fullmet_sp ))deallocate(x_fullmet_sp)
if(allocated(y_fullmet_sp ))deallocate(y_fullmet_sp)
if(allocated(p_fullmet_sp ))deallocate(p_fullmet_sp)
if(allocated(x_submet_sp ))deallocate(x_submet_sp)
if(allocated(y_submet_sp ))deallocate(y_submet_sp)
if(allocated(levs_fullmet_sp ))deallocate(levs_fullmet_sp)
if(allocated(nlevs_fullmet ))deallocate(nlevs_fullmet)
if(allocated(levs_code ))deallocate(levs_code)
if(allocated(z_approx ))deallocate(z_approx)
if(allocated(rdphi_MetP_sp ))deallocate(rdphi_MetP_sp)
if(allocated(rdlambda_MetP_sp ))deallocate(rdlambda_MetP_sp)
if(allocated(MR_dx_met ))deallocate(MR_dx_met)
if(allocated(MR_dx_submet ))deallocate(MR_dx_submet)
if(allocated(MR_dy_met ))deallocate(MR_dy_met)
if(allocated(MR_dy_submet ))deallocate(MR_dy_submet)
if(allocated(MR_sigma_nz_submet ))deallocate(MR_sigma_nz_submet)
if(allocated(x_comp_sp ))deallocate(x_comp_sp)
if(allocated(y_comp_sp ))deallocate(y_comp_sp)
if(allocated(z_comp_sp ))deallocate(z_comp_sp)
if(allocated(CompPoint_X_on_Met_sp ))deallocate(CompPoint_X_on_Met_sp)
if(allocated(CompPoint_Y_on_Met_sp ))deallocate(CompPoint_Y_on_Met_sp)
if(allocated(CompPoint_on_subMet_idx ))deallocate(CompPoint_on_subMet_idx)
if(allocated(bilin_map_wgt ))deallocate(bilin_map_wgt)
if(allocated(s_comp_sp ))deallocate(s_comp_sp)
if(allocated(MR_Topo_met ))deallocate(MR_Topo_met)
if(allocated(MR_jacob_met ))deallocate(MR_jacob_met)
if(allocated(MR_Topo_comp ))deallocate(MR_Topo_comp)
if(allocated(MR_jacob_comp ))deallocate(MR_jacob_comp)
if(allocated(MR_u_ER_metP ))deallocate(MR_u_ER_metP)
if(allocated(MR_v_ER_metP ))deallocate(MR_v_ER_metP)
if(allocated(theta_Met ))deallocate(theta_Met)
if(allocated(theta_Comp ))deallocate(theta_Comp)
if(allocated(MR_xy2ll_xlon ))deallocate(MR_xy2ll_xlon)
if(allocated(MR_xy2ll_ylat ))deallocate(MR_xy2ll_ylat)
if(allocated(temp1d_sp ))deallocate(temp1d_sp)
if(allocated(temp2d_sp ))deallocate(temp2d_sp)
if(allocated(temp3d_sp ))deallocate(temp3d_sp)
if(allocated(temp2d_int ))deallocate(temp2d_int)
if(allocated(temp2d_short ))deallocate(temp2d_short)
if(allocated(temp3d_short ))deallocate(temp3d_short)
if(allocated(Met_Proj_lat ))deallocate(Met_Proj_lat)
if(allocated(Met_Proj_lon ))deallocate(Met_Proj_lon)
if(allocated(MR_SndVars_metP ))deallocate(MR_SndVars_metP)
if(allocated(MR_SndVarsID ))deallocate(MR_SndVarsID)
if(allocated(MR_Snd_np_fullmet ))deallocate(MR_Snd_np_fullmet)
if(allocated(MR_Snd2Comp_map_wgt ))deallocate(MR_Snd2Comp_map_wgt)
if(allocated(MR_Snd2Comp_map_idx ))deallocate(MR_Snd2Comp_map_idx)
if(allocated(Snd_idx ))deallocate(Snd_idx)
if(allocated(MR_Snd_cd ))deallocate(MR_Snd_cd)
if(allocated(MR_Snd_id ))deallocate(MR_Snd_id)
if(allocated(MR_Snd_lt ))deallocate(MR_Snd_lt)
if(allocated(MR_Snd_ln ))deallocate(MR_Snd_ln)
if(allocated(MR_Snd_el ))deallocate(MR_Snd_el)
if(allocated(MR_Snd_lnm ))deallocate(MR_Snd_lnm)
if(allocated(MR_Snd_st ))deallocate(MR_Snd_st)
if(allocated(MR_Snd_ct ))deallocate(MR_Snd_ct)
#endif
nlev_coords_detected = 0
end subroutine MR_Reset_Memory
!##############################################################################
!
! MR_Allocate_FullMetFileList
!
! This subroutine allocates the list of windfiles and does some
! error-checking based on iwind and iwindfiles.
!
! From the calling program, this is called once the information about
! the NWP files is available (e.g. the iwind, iwindformat, grid ID, data
! format, and number of windfiles.
!
! Variables allocated:
! MR_windfiles(MR_iwindfiles)
! MR_windfiles_nt_fullmet(MR_iwindfiles)
! and possibly:
! MR_windfiles_Have_GRIB_index(MR_iwindfiles)
! MR_windfiles_GRIB_index(MR_iwindfiles)
!
! The next step is for the calling program to populate MR_windfiles
!
!##############################################################################
subroutine MR_Allocate_FullMetFileList(iw,iwf,igrid,idf,iwfiles)
integer,intent(in) :: iw
integer,intent(in) :: iwf
integer,intent(in) :: igrid
integer,intent(in) :: idf
integer,intent(in) :: iwfiles
integer :: i
integer :: io ! Index for output streams
MR_iwind = iw
MR_iwindformat = iwf
MR_iGridCode = igrid
MR_idataFormat = idf
MR_iwindfiles = iwfiles
! This should be the first subroutine called so reset verbosity levels
! in case this was changed in the calling program
VB(1:2) = (/MR_VERB,MR_VERB/)
do io=1,MR_nio;if(VB(io).le.verbosity_production)then
write(outlog(io),*)"-----------------------------------------------------------------------"
write(outlog(io),*)"---------- MR_Allocate_FullMetFileList ----------"
write(outlog(io),*)"-----------------------------------------------------------------------"
endif;enddo
if ((MR_iwind.ne.1).and.(MR_iwind.ne.2).and. &
(MR_iwind.ne.3).and.(MR_iwind.ne.4).and. &
(MR_iwind.ne.5)) then
do io=1,MR_nio;if(VB(io).le.verbosity_error)then
write(errlog(io),*)'MR_iwind must be between 1 and 5. Program stopped'
write(errlog(io),*)' MR_iwind = ',MR_iwind
write(errlog(io),*)' MR_IWIND OPTIONS:'
write(errlog(io),*)' MR_iwind = 1 read from a 1-D wind sounding'
write(errlog(io),*)' 2 read from 3D gridded ASCII files'
write(errlog(io),*)' 3 read from a single, multistep file'
write(errlog(io),*)' 4 read from multiple files'
write(errlog(io),*)' 5 read variables from separate files'
endif;enddo
stop 1
endif
! Initialize the dimension and variable arrays. Select slots in these arrays will be
! overwritten from the calls in the case block below
Met_dim_IsAvailable = .false.
Met_var_IsAvailable = .false.
Met_var_IsAvailable(1:MR_MAXVARS) = .false.
Met_var_zdim_idx(1:MR_MAXVARS) = 0
Met_var_zdim_ncid(1:MR_MAXVARS) = 0
Met_var_GRIB2_DPcPnSt(1:MR_MAXVARS,1:4) = 0
Met_var_GRIB1_Param(1:MR_MAXVARS) = 0
Met_var_GRIB1_St(1:MR_MAXVARS) = ""
Met_var_conversion_factor(1:MR_MAXVARS) = 1.0_sp
Met_var_nlevs(1:MR_MAXVARS) = 0
isGridRelative = .true.
!--------------------------------
! Dimensions
!--------------------------------
! Assume the critical dimensions are available
! Dimension names for NC files are read from the first file so do not need
! to be set here. These could be populated by the template file.
Met_dim_IsAvailable(1)=.true.; Met_dim_names(1)="unset name for t"
Met_dim_IsAvailable(2)=.true.; Met_dim_names(2)="unset name for p"
Met_dim_IsAvailable(3)=.true.; Met_dim_names(3)="unset name for y"
Met_dim_IsAvailable(4)=.true.; Met_dim_names(4)="unset name for x"
!--------------------------------
! Mechanical / State variables
!--------------------------------
! Note: All default names are that assigned by netcdf-java in the grib-to-nc conversion
! Command used :: java -Xmx2048m -classpath ~/ncj/netcdfAll-4.5.jar ucar.nc2.dataset.NetcdfDataset \
! -in ${GribFile} -out ${NCFile} -IsLargeFile
!
! Alternatively, one could use ncl_convert2nc ${GribFile} -L
! This creates variable names such as HGT_P0_L100_GLL0; i.e. WMOname_P[param_class]_L[surf_class]_[gridtype]
! where gridtype is one of:
! Met_gridtype = "GLL0" ! Latitude/Longitude
! Met_gridtype = "GME0" ! Mercator
! Met_gridtype = "GLC0" ! Lambert Conformal
! Met_gridtype = "GST0" ! Polar stereographic
!
! The NC_names listed are the names written by netcdf-java when converting GRIB forecast
! files to netcdf. Reanalysis files might be provided in netcdf format directly, in
! which case, the names are overwritten below. Since these name occasionally change,
! know variants are checked if the expected name is not found in
! Geopotential Height (m^2/s^2)
Met_var_NC_names(1) = "Geopotential_height_isobaric"
Met_var_GRIB_names(1) = "gh"
Met_var_WMO_names(1) = "HGT"
Met_var_GRIB2_DPcPnSt(1,1:4) = (/0, 3, 5, 100/) ! discpln,param_cat,param_num,surf_class
Met_var_GRIB1_Param(1) = 7
Met_var_GRIB1_St(1) = "pl"
Met_var_ndim(1) = 4
! Velocity component in x (or E) direction (m/s)
Met_var_NC_names(2) = "u-component_of_wind_isobaric"