forked from hschwaiger-usgs/volcano-ash3d-metreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MetReader_NetCDF.f90
3121 lines (2884 loc) · 140 KB
/
MetReader_NetCDF.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
!##############################################################################
!
! MR_Read_Met_DimVars_netcdf
!
! Called once from MR_Read_Met_DimVars
!
! This subroutine reads the variable and dimension IDs, and fills the
! coordinate dimension variables
!
! After this subroutine completes, the following variables will be set:
! All the projection parameters of NWP grid
! Met_dim_names, Met_var_NC_names, Met_var_conversion_factor, Met_var_IsAvailable
! The lengths of all the dimensions of the file
! p_fullmet_sp (converted to Pa)
! x_fullmet_sp, y_fullmet_sp
! IsLatLon_MetGrid, IsGlobal_MetGrid, IsRegular_MetGrid
!
!##############################################################################
subroutine MR_Read_Met_DimVars_netcdf
use MetReader
use netcdf
use projection
implicit none
integer, parameter :: sp = 4 ! single precision
integer, parameter :: dp = 8 ! double precision
integer :: i, k
real(kind=sp) :: xLL_fullmet
real(kind=sp) :: yLL_fullmet
real(kind=sp) :: xUR_fullmet
real(kind=sp) :: yUR_fullmet
integer :: ncid
integer :: ivar,in_var_id,var_ndims
integer :: i_dim,iivar
integer :: xdim_id, ydim_id, tdim_id
integer :: dimlen,maxdimlen
integer :: nSTAT
character(len=NF90_MAX_NAME) :: invar,dimname
integer :: var_xtype,var_id,idx
integer :: xtype, length, attnum
real(kind=dp), parameter :: tol = 1.0e-3_dp
real(kind=dp) :: x_start,y_start
!integer :: NC_version
integer,dimension(:),allocatable :: var_dimIDs
logical :: FoundOldDim
logical :: IsPressureDimension
real(kind=dp),dimension(:), allocatable :: dum1d_dp
real(kind=sp),dimension(:), allocatable :: dum1d_sp
character(len=31) :: ustring
logical :: IsTruncatedDim
character(len=130) :: infile
write(MR_global_production,*)"--------------------------------------------------------------------------------"
write(MR_global_production,*)"---------- MR_Read_Met_DimVars_netcdf ----------"
write(MR_global_production,*)"--------------------------------------------------------------------------------"
if(MR_iwind.eq.5)then
! For the case where variables are in different files, we will just hard-code the
! grid geometry
if (MR_iwindformat.eq.25) then
! NCEP/NCAR reanalysis 2.5 degree files
! https://rda.ucar.edu/datasets/ds090.0
maxdimlen = 17
nlev_coords_detected = 3
allocate(nlevs_fullmet(nlev_coords_detected));nlevs_fullmet(:)=0
nlevs_fullmet(1) = 17
nlevs_fullmet(2) = 12
nlevs_fullmet(3) = 8
allocate(levs_code(nlev_coords_detected));levs_code(:)=0
levs_code(1) = 1
levs_code(2) = 2
levs_code(3) = 2
allocate(levs_fullmet_sp(nlev_coords_detected,maxdimlen));levs_fullmet_sp(:,:)=0
np_fullmet = 17
allocate(p_fullmet_sp(np_fullmet))
levs_fullmet_sp(:,:) = 0.0_sp
p_fullmet_sp(1:np_fullmet) = &
(/1000.0_sp, 925.0_sp, 850.0_sp, 700.0_sp, 600.0_sp, &
500.0_sp, 400.0_sp, 300.0_sp, 250.0_sp, 200.0_sp, &
150.0_sp, 100.0_sp, 70.0_sp, 50.0_sp, 30.0_sp, &
20.0_sp, 10.0_sp /)
z_inverted = .false.
levs_fullmet_sp(1,1:17) = p_fullmet_sp(1:17)*Pressure_Conv_Fac
levs_fullmet_sp(2,1:12) = p_fullmet_sp(1:12)*Pressure_Conv_Fac
levs_fullmet_sp(3,1:8 ) = p_fullmet_sp(1:8 )*Pressure_Conv_Fac
Met_var_zdim_idx( 1) = 1
Met_var_zdim_idx( 2) = 1
Met_var_zdim_idx( 3) = 1
Met_var_zdim_idx( 4) = 2
Met_var_zdim_idx( 5) = 1
Met_var_zdim_idx(30) = 3
IsLatLon_MetGrid = .true.
IsGlobal_MetGrid = .true.
IsRegular_MetGrid = .true.
nx_fullmet = 144
ny_fullmet = 73
allocate(x_fullmet_sp(0:nx_fullmet+1))
allocate(y_fullmet_sp(ny_fullmet))
allocate(MR_dx_met(nx_fullmet))
allocate(MR_dy_met(ny_fullmet))
dx_met_const = 2.5_sp
dy_met_const = 2.5_sp
x_start = 0.0_dp
y_start = 90.0_dp
do i = 0,nx_fullmet+1
x_fullmet_sp(i) = real(x_start + (i-1)*dx_met_const,kind=sp)
enddo
x_inverted = .false.
do i = 1,ny_fullmet
y_fullmet_sp(i) = real(y_start - (i-1)*dy_met_const,kind=sp)
enddo
y_inverted = .true.
do i = 1,nx_fullmet
MR_dx_met(i) = x_fullmet_sp(i+1)-x_fullmet_sp(i)
enddo
do i = 1,ny_fullmet-1
MR_dy_met(i) = y_fullmet_sp(i+1)-y_fullmet_sp(i)
enddo
MR_dy_met(ny_fullmet) = MR_dy_met(ny_fullmet-1)
iwf25_scale_facs = 0.0_sp
iwf25_offsets = 0.0_sp
iwf25_scale_facs(1) = 1.0_sp ; iwf25_offsets(1) = 32066.0_sp ! hgt
iwf25_scale_facs(2) = 0.01_sp ; iwf25_offsets(2) = 202.66_sp ! uwnd
iwf25_scale_facs(3) = 0.01_sp ; iwf25_offsets(3) = 202.66_sp ! vwnd
iwf25_scale_facs(4) = 0.001_sp ; iwf25_offsets(4) = 29.765_sp ! omega
iwf25_scale_facs(5) = 0.01_sp ; iwf25_offsets(5) = 477.66_sp ! air (temperature)
iwf25_scale_facs(6) = 1.0_sp ; iwf25_offsets(6) = 0.0_sp ! level
iwf25_scale_facs(20) = 10.0_sp ; iwf25_offsets(20) = 327650.0_sp ! pres (lcb)
iwf25_scale_facs(21) = 10.0_sp ; iwf25_offsets(21) = 327650.0_sp ! pres (lct)
iwf25_scale_facs(30) = 0.01_sp ; iwf25_offsets(30) = 302.66_sp ! rhum
iwf25_scale_facs(31) = 1.0e-6_sp ; iwf25_offsets(31) = 0.032666_sp ! shum
iwf25_scale_facs(32) = 1.0e-6_sp ; iwf25_offsets(32) = 0.032666_sp ! shum
iwf25_scale_facs(44) = 1.0e-7_sp ; iwf25_offsets(44) = 0.0032765_sp ! prate
iwf25_scale_facs(45) = 1.0e-7_sp ; iwf25_offsets(45) = 0.0031765_sp ! cprat
elseif(MR_iwindformat.eq.26)then
! JRA-55 reanalysis 1.25 degree files
! https://rda.ucar.edu/datasets/ds628.0/
maxdimlen = 37
nlev_coords_detected = 2
allocate(nlevs_fullmet(nlev_coords_detected))
nlevs_fullmet(1) = 37
nlevs_fullmet(2) = 27
allocate(levs_code(nlev_coords_detected))
levs_code(1) = 1
levs_code(2) = 2
allocate(levs_fullmet_sp(nlev_coords_detected,maxdimlen))
np_fullmet = 37
allocate(p_fullmet_sp(np_fullmet))
levs_fullmet_sp(:,:) = 0.0_sp
p_fullmet_sp(1:np_fullmet) = &
(/1000.0_sp, 975.0_sp, 950.0_sp, 925.0_sp, 900.0_sp, &
875.0_sp, 850.0_sp, 825.0_sp, 800.0_sp, 775.0_sp, &
750.0_sp, 700.0_sp, 650.0_sp, 600.0_sp, 550.0_sp, &
500.0_sp, 450.0_sp, 400.0_sp, 350.0_sp, 300.0_sp, &
250.0_sp, 225.0_sp, 200.0_sp, 175.0_sp, 150.0_sp, &
125.0_sp, 100.0_sp, 70.0_sp, 50.0_sp, 30.0_sp, &
20.0_sp, 10.0_sp, 7.0_sp, 5.0_sp, 3.0_sp, &
2.0_sp, 1.0_sp /)
z_inverted = .true.
levs_fullmet_sp(1,1:37) = p_fullmet_sp(1:37)*Pressure_Conv_Fac
levs_fullmet_sp(2,1:27) = p_fullmet_sp(1:27)*Pressure_Conv_Fac
Met_var_zdim_idx( 1) = 1
Met_var_zdim_idx( 2) = 1
Met_var_zdim_idx( 3) = 1
Met_var_zdim_idx( 4) = 1
Met_var_zdim_idx( 5) = 1
Met_var_zdim_idx(30) = 2
IsLatLon_MetGrid = .true.
IsGlobal_MetGrid = .true.
IsRegular_MetGrid = .true.
nx_fullmet = 288
ny_fullmet = 145
allocate(x_fullmet_sp(0:nx_fullmet+1))
allocate(y_fullmet_sp(ny_fullmet))
allocate(MR_dx_met(nx_fullmet))
allocate(MR_dy_met(ny_fullmet))
dx_met_const = 1.25_sp
dy_met_const = 1.25_sp
x_start = 0.0_dp
y_start = 90.0_dp
do i = 0,nx_fullmet+1
x_fullmet_sp(i) = real(x_start + (i-1)*dx_met_const,kind=sp)
enddo
x_inverted = .false.
do i = 1,ny_fullmet
y_fullmet_sp(i) = real(y_start - (i-1)*dy_met_const,kind=sp)
enddo
y_inverted = .true.
do i = 1,nx_fullmet
MR_dx_met(i) = x_fullmet_sp(i+1)-x_fullmet_sp(i)
enddo
do i = 1,ny_fullmet-1
MR_dy_met(i) = y_fullmet_sp(i+1)-y_fullmet_sp(i)
enddo
MR_dy_met(ny_fullmet) = MR_dy_met(ny_fullmet-1)
elseif(MR_iwindformat.eq.27)then
! NOAA-CIRES reanalysis 2.0 degree files :: ds131.2
maxdimlen = 24
nlev_coords_detected = 2
allocate(nlevs_fullmet(nlev_coords_detected))
nlevs_fullmet(1) = 24
nlevs_fullmet(2) = 19
allocate(levs_code(nlev_coords_detected))
levs_code(1) = 1
levs_code(2) = 2
allocate(levs_fullmet_sp(nlev_coords_detected,maxdimlen))
np_fullmet = 24
allocate(p_fullmet_sp(np_fullmet))
levs_fullmet_sp(:,:) = 0.0_sp
p_fullmet_sp(1:np_fullmet) = &
(/1000.0_sp, 950.0_sp, 900.0_sp, 850.0_sp, 800.0_sp, &
750.0_sp, 700.0_sp, 650.0_sp, 600.0_sp, 550.0_sp, &
500.0_sp, 450.0_sp, 400.0_sp, 350.0_sp, 300.0_sp, &
250.0_sp, 200.0_sp, 150.0_sp, 100.0_sp, 70.0_sp, &
50.0_sp, 30.0_sp, 20.0_sp, 10.0_sp /)
if(MR_Use_RDA)then
! Files from rda.ucar.edu/datasets/ds131.2/ converted from grib with ncl_convert2nc
! are top down
z_inverted = .true.
else
! Files from www.esrl.noaa.gov are bottom up
z_inverted = .false.
endif
levs_fullmet_sp(1,1:24) = p_fullmet_sp(1:24)*Pressure_Conv_Fac
levs_fullmet_sp(2,1:19) = p_fullmet_sp(1:19)*Pressure_Conv_Fac
Met_var_zdim_idx( 1) = 1
Met_var_zdim_idx( 2) = 1
Met_var_zdim_idx( 3) = 1
Met_var_zdim_idx( 4) = 2
Met_var_zdim_idx( 5) = 1
IsLatLon_MetGrid = .true.
IsGlobal_MetGrid = .true.
IsRegular_MetGrid = .true.
nx_fullmet = 180
ny_fullmet = 91
allocate(x_fullmet_sp(0:nx_fullmet+1))
allocate(y_fullmet_sp(ny_fullmet))
allocate(MR_dx_met(nx_fullmet))
allocate(MR_dy_met(ny_fullmet))
dx_met_const = 2.0_sp
dy_met_const = 2.0_sp
x_start = 0.0_dp
y_start = 90.0_dp
do i = 0,nx_fullmet+1
x_fullmet_sp(i) = real(x_start + (i-1)*dx_met_const,kind=sp)
enddo
x_inverted = .false.
do i = 1,ny_fullmet
y_fullmet_sp(i) = real(y_start - (i-1)*dy_met_const,kind=sp)
enddo
y_inverted = .true.
do i = 1,nx_fullmet
MR_dx_met(i) = x_fullmet_sp(i+1)-x_fullmet_sp(i)
enddo
do i = 1,ny_fullmet-1
MR_dy_met(i) = y_fullmet_sp(i+1)-y_fullmet_sp(i)
enddo
MR_dy_met(ny_fullmet) = MR_dy_met(ny_fullmet-1)
elseif(MR_iwindformat.eq.29)then
! ECMWF ERA5
maxdimlen = 37
nlev_coords_detected = 1
allocate(nlevs_fullmet(nlev_coords_detected))
nlevs_fullmet(1) = 37
allocate(levs_code(nlev_coords_detected))
levs_code(1) = 1
allocate(levs_fullmet_sp(nlev_coords_detected,maxdimlen))
np_fullmet = 37
allocate(p_fullmet_sp(np_fullmet))
levs_fullmet_sp(:,:) = 0.0_sp
p_fullmet_sp(1:np_fullmet) = &
(/1000.0_sp, 975.0_sp, 950.0_sp, 925.0_sp, 900.0_sp, &
875.0_sp, 850.0_sp, 825.0_sp, 800.0_sp, 775.0_sp, &
750.0_sp, 700.0_sp, 650.0_sp, 600.0_sp, 550.0_sp, &
500.0_sp, 450.0_sp, 400.0_sp, 350.0_sp, 300.0_sp, &
250.0_sp, 225.0_sp, 200.0_sp, 175.0_sp, 150.0_sp, &
125.0_sp, 100.0_sp, 70.0_sp, 50.0_sp, 30.0_sp, &
20.0_sp, 10.0_sp, 7.0_sp, 5.0_sp, 3.0_sp, &
2.0_sp, 1.0_sp /)
z_inverted = .true.
levs_fullmet_sp(1,1:37) = p_fullmet_sp(1:37)*Pressure_Conv_Fac
Met_var_zdim_idx( 1) = 1
Met_var_zdim_idx( 2) = 1
Met_var_zdim_idx( 3) = 1
Met_var_zdim_idx( 4) = 1
Met_var_zdim_idx( 5) = 1
IsLatLon_MetGrid = .true.
IsGlobal_MetGrid = .true.
IsRegular_MetGrid = .false.
allocate(MR_dx_met(nx_fullmet))
allocate(MR_dy_met(ny_fullmet))
do i = 1,nx_fullmet
MR_dx_met(i) = x_fullmet_sp(i+1)-x_fullmet_sp(i)
enddo
do i = 1,ny_fullmet-1
MR_dy_met(i) = y_fullmet_sp(i+1)-y_fullmet_sp(i)
enddo
MR_dy_met(ny_fullmet) = MR_dy_met(ny_fullmet-1)
elseif(MR_iwindformat.eq.30)then
! ECMWF ERA=20c
maxdimlen = 37
nlev_coords_detected = 1
allocate(nlevs_fullmet(nlev_coords_detected))
nlevs_fullmet(1) = 37
allocate(levs_code(nlev_coords_detected))
levs_code(1) = 1
allocate(levs_fullmet_sp(nlev_coords_detected,maxdimlen))
np_fullmet = 37
allocate(p_fullmet_sp(np_fullmet))
levs_fullmet_sp(:,:) = 0.0_sp
p_fullmet_sp(1:np_fullmet) = &
(/1000.0_sp, 975.0_sp, 950.0_sp, 925.0_sp, 900.0_sp, &
875.0_sp, 850.0_sp, 825.0_sp, 800.0_sp, 775.0_sp, &
750.0_sp, 700.0_sp, 650.0_sp, 600.0_sp, 550.0_sp, &
500.0_sp, 450.0_sp, 400.0_sp, 350.0_sp, 300.0_sp, &
250.0_sp, 225.0_sp, 200.0_sp, 175.0_sp, 150.0_sp, &
125.0_sp, 100.0_sp, 70.0_sp, 50.0_sp, 30.0_sp, &
20.0_sp, 10.0_sp, 7.0_sp, 5.0_sp, 3.0_sp, &
2.0_sp, 1.0_sp /)
z_inverted = .true.
levs_fullmet_sp(1,1:37) = p_fullmet_sp(1:37)*Pressure_Conv_Fac
Met_var_zdim_idx( 1) = 1
Met_var_zdim_idx( 2) = 1
Met_var_zdim_idx( 3) = 1
Met_var_zdim_idx( 4) = 1
Met_var_zdim_idx( 5) = 1
IsLatLon_MetGrid = .true.
IsGlobal_MetGrid = .true.
IsRegular_MetGrid = .false.
allocate(MR_dx_met(nx_fullmet))
allocate(MR_dy_met(ny_fullmet))
do i = 1,nx_fullmet
MR_dx_met(i) = x_fullmet_sp(i+1)-x_fullmet_sp(i)
enddo
do i = 1,ny_fullmet-1
MR_dy_met(i) = y_fullmet_sp(i+1)-y_fullmet_sp(i)
enddo
MR_dy_met(ny_fullmet) = MR_dy_met(ny_fullmet-1)
else
stop 1
endif
idx = Met_var_zdim_idx(1)
p_fullmet_sp(1:nlevs_fullmet(idx)) = levs_fullmet_sp(idx,1:nlevs_fullmet(idx))
else ! MR_iwind not equal to 5
if(MR_iwindformat.eq.50)then
! WRF files have a special reader, but we still need to set up
call MR_Get_WRF_grid
else ! MR_iwindformat .ne. 50
!---------------------------------------------------------------------------------
! Checking for dimension length and values for x,y,t,p
! Assume all files have the same format
maxdimlen = 0
infile = adjustl(trim(MR_windfiles(1)))
nSTAT=nf90_open(adjustl(trim(infile)),NF90_NOWRITE, ncid)
if(nSTAT.ne.NF90_NOERR) then
write(MR_global_error,*)'MR ERROR: open NC file: ',nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: open NC file: ',nf90_strerror(nSTAT)
write(MR_global_error,*)'Exiting'
stop 1
endif
do ivar = 1,MR_MAXVARS
if (.not.Met_var_IsAvailable(ivar)) cycle ! Only look at variables that are available
if (Met_var_ndim(ivar).ne.4) cycle ! and only ones with a 'level' dimension
invar = Met_var_NC_names(ivar)
nSTAT = nf90_inq_varid(ncid,invar,in_var_id) ! get the var_id for this named variable
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR WARNING: inq_varid: ',invar,nf90_strerror(nSTAT)
write(MR_global_error,*)' Cannot find variable ',invar
write(MR_global_error,*)' Setting Met_var_IsAvailable to .false.'
write(MR_global_log ,*)'MR WARNING: inq_varid: ',invar,nf90_strerror(nSTAT)
Met_var_IsAvailable(ivar) = .false.
cycle
endif
nSTAT = nf90_inquire_variable(ncid, in_var_id, invar, &
xtype = var_xtype, &
ndims = var_ndims) ! get the number of dimensions
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
stop 1
endif
if (var_ndims.ne.Met_var_ndim(ivar))then
write(MR_global_error,*)'MR ERROR: The actual number of dimensions differs from'
write(MR_global_error,*)' what is expected'
write(MR_global_error,*)' Variable : ',ivar,Met_var_NC_names(ivar)
write(MR_global_error,*)' Expected : ',Met_var_ndim(ivar)
write(MR_global_error,*)' Found : ',var_ndims
stop 1
endif
allocate(var_dimIDs(var_ndims))
nSTAT = nf90_inquire_variable(ncid, in_var_id, invar, &
dimids = var_dimIDs(:var_ndims))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
stop 1
endif
! 3-d transient variables should be in the COORDS convention (time, level, y, x)
! 4 3 2 1
! if ivar = 1 (Geopotential Height), then get the info on x,y and t too
if(ivar.eq.1)then
i_dim = 1 ! get x info
nSTAT = nf90_inquire_dimension(ncid,var_dimIDs(i_dim), &
name = dimname, &
len = dimlen)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
stop 1
endif
if(index(dimname,Met_dim_names(4)).ne.0)then
nx_fullmet = dimlen
xdim_id = var_dimIDs(i_dim)
endif
nSTAT = nf90_inq_varid(ncid,dimname,var_id) ! get the variable associated with this dim
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_varid ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_varid ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! Check if we need to read into a float or a double
nSTAT = nf90_inquire_variable(ncid, var_id, dimname, xtype = var_xtype)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',dimname,nf90_strerror(nSTAT)
stop 1
endif
allocate(x_fullmet_sp(0:nx_fullmet+1))
if(var_xtype.eq.NF90_FLOAT)then
allocate(dum1d_sp(dimlen))
nSTAT = nf90_get_var(ncid,var_id,dum1d_sp, &
start = (/1/),count = (/dimlen/))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! copy to local variable
x_fullmet_sp(1:nx_fullmet) = dum1d_sp(1:nx_fullmet)
deallocate(dum1d_sp)
elseif(var_xtype.eq.NF90_DOUBLE)then
allocate(dum1d_dp(dimlen))
nSTAT = nf90_get_var(ncid,var_id,dum1d_dp, &
start = (/1/),count = (/dimlen/))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! copy to local variable
x_fullmet_sp(1:nx_fullmet) = real(dum1d_dp(1:nx_fullmet),kind=sp)
deallocate(dum1d_dp)
else
write(MR_global_error,*)'MR ERROR: Cannot recognize variable type for x'
stop 1
endif
! Check the units
nSTAT = nf90_Inquire_Attribute(ncid, var_id,&
"units",xtype, length, attnum)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR WARNING: cannot file units ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR WARNING: cannot file units ',dimname,nf90_strerror(nSTAT)
else
nSTAT = nf90_get_att(ncid, var_id,"units",ustring)
if(nSTAT.ne.NF90_NOERR) then
write(MR_global_error,*)'MR ERROR: get_att:',"time",nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_att:',"time",nf90_strerror(nSTAT)
stop 1
endif
if(index(ustring,'km').gt.0.or.&
index(ustring,'kilo').gt.0)then
! This is a projected grid
IsLatLon_MetGrid = .false.
elseif(index(ustring,'deg').gt.0)then
! This is a lon/lat grid
IsLatLon_MetGrid = .true.
else
write(MR_global_error,*)"MR ERROR: Cannot determine if the grid is lon/lat or projected"
stop 1
endif
endif
! Finally, check for orientation
if(x_fullmet_sp(1).lt.x_fullmet_sp(2))then
x_inverted = .false.
else
x_inverted = .true.
endif
allocate(MR_dx_met(nx_fullmet))
x_start = x_fullmet_sp(1)
dx_met_const = x_fullmet_sp(2)-x_fullmet_sp(1)
x_fullmet_sp(0) = x_fullmet_sp(1) - dx_met_const
x_fullmet_sp(nx_fullmet+1) = x_fullmet_sp(nx_fullmet) + dx_met_const
if(abs(x_fullmet_sp(nx_fullmet+1)-360.0-x_fullmet_sp(1)).lt.0.1*dx_met_const)then
IsGlobal_MetGrid = .true.
else
IsGlobal_MetGrid = .false.
endif
do i = 1,nx_fullmet
MR_dx_met(i) = x_fullmet_sp(i+1)-x_fullmet_sp(i)
enddo
i_dim = 2 ! get y info
nSTAT = nf90_inquire_dimension(ncid,var_dimIDs(i_dim), &
name = dimname, &
len = dimlen)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
stop 1
endif
if(index(dimname,Met_dim_names(3)).ne.0)then
ny_fullmet = dimlen
ydim_id = var_dimIDs(i_dim)
endif
nSTAT = nf90_inq_varid(ncid,dimname,var_id) ! get the variable associated with this dim
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_varid ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_varid ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! Check if we need to read into a float or a double
nSTAT = nf90_inquire_variable(ncid, var_id, dimname, xtype = var_xtype)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',dimname,nf90_strerror(nSTAT)
stop 1
endif
allocate(y_fullmet_sp(ny_fullmet))
if(var_xtype.eq.NF90_FLOAT)then
allocate(dum1d_sp(dimlen))
nSTAT = nf90_get_var(ncid,var_id,dum1d_sp, &
start = (/1/),count = (/dimlen/))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! copy to local variable
y_fullmet_sp(1:ny_fullmet) = dum1d_sp(1:ny_fullmet)
deallocate(dum1d_sp)
elseif(var_xtype.eq.NF90_DOUBLE)then
allocate(dum1d_dp(dimlen))
nSTAT = nf90_get_var(ncid,var_id,dum1d_dp, &
start = (/1/),count = (/dimlen/))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! copy to local variable
y_fullmet_sp(1:ny_fullmet) = real(dum1d_dp(1:ny_fullmet),kind=sp)
deallocate(dum1d_dp)
else
write(MR_global_error,*)'MR ERROR: Cannot recognize variable type for x'
stop 1
endif
! Check the units
nSTAT = nf90_Inquire_Attribute(ncid, var_id,&
"units",xtype, length, attnum)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR WARNING: cannot file units ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR WARNING: cannot file units ',dimname,nf90_strerror(nSTAT)
else
nSTAT = nf90_get_att(ncid, var_id,"units",ustring)
if(nSTAT.ne.NF90_NOERR) then
write(MR_global_error,*)'MR ERROR: get_att:',"time",nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_att:',"time",nf90_strerror(nSTAT)
stop 1
endif
if(index(ustring,'km').gt.0.or.&
index(ustring,'kilo').gt.0)then
! This is a projected grid
IsLatLon_MetGrid = .false.
elseif(index(ustring,'deg').gt.0)then
! This is a lon/lat grid
IsLatLon_MetGrid = .true.
else
write(MR_global_error,*)"MR ERROR: Cannot determine if the grid is lon/lat or projected"
stop 1
endif
endif
! check for orientation
if(y_fullmet_sp(1).lt.y_fullmet_sp(2))then
y_inverted = .false.
else
y_inverted = .true.
endif
allocate(MR_dy_met(ny_fullmet))
y_start = y_fullmet_sp(1)
dy_met_const = y_fullmet_sp(2)-y_fullmet_sp(1)
do i = 1,ny_fullmet-1
MR_dy_met(i) = y_fullmet_sp(i+1)-y_fullmet_sp(i)
enddo
MR_dy_met(ny_fullmet) = MR_dy_met(ny_fullmet-1)
! We need to check if this is a regular grid
IsRegular_MetGrid = .true.
do i = 1,nx_fullmet-1
if(abs(MR_dx_met(i+1)-MR_dx_met(i)).gt.tol*MR_dx_met(i))then
IsRegular_MetGrid = .false.
endif
enddo
do i = 1,ny_fullmet-1
if(abs(MR_dy_met(i+1)-MR_dy_met(i)).gt.tol*MR_dy_met(i))then
IsRegular_MetGrid = .false.
endif
enddo
i_dim = 4 ! get t info
nSTAT = nf90_inquire_dimension(ncid,var_dimIDs(i_dim), &
name = dimname, &
len = dimlen)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
stop 1
endif
if(index(dimname,Met_dim_names(1)).ne.0)then
nt_fullmet = dimlen
tdim_id = var_dimIDs(i_dim)
endif
endif
! Now checking level coordinates (pressure, height, depth); third dimension
i_dim = 3
nSTAT = nf90_inquire_dimension(ncid,var_dimIDs(i_dim), &
name = dimname, &
len = dimlen)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',invar,nf90_strerror(nSTAT)
stop 1
endif
if(index(dimname,'lev').ne.0.or.&
index(dimname,'isobaric').ne.0.or.&
index(dimname,'pressure').ne.0.or.&
index(dimname,'height').ne.0.or.&
index(dimname,'depth').ne.0.or.&
index(dimname,'lv_ISBL1').ne.0.or.&
index(dimname,'bottom_top').ne.0.or.&
index(dimname,'bottom_top_stag').ne.0.or.&
index(dimname,'soil_layers_stag').ne.0)then
! Log this level coordinate if it is the first
if (nlev_coords_detected.eq.0)then
nlev_coords_detected = nlev_coords_detected + 1
Met_var_zdim_idx(ivar) = nlev_coords_detected
Met_var_zdim_ncid(ivar) = var_dimIDs(i_dim)
maxdimlen = dimlen
else
! Otherwise, check if this level coordinate has already been logged
FoundOldDim = .false.
do iivar = 1,ivar-1
if (Met_var_zdim_ncid(iivar).eq.var_dimIDs(i_dim))then
FoundOldDim = .true.
Met_var_zdim_idx(ivar) = Met_var_zdim_idx(iivar)
Met_var_zdim_ncid(ivar) = var_dimIDs(i_dim)
exit
endif
enddo
if(.not.FoundOldDim)then
nlev_coords_detected = nlev_coords_detected + 1
Met_var_zdim_idx(ivar) = nlev_coords_detected
Met_var_zdim_ncid(ivar) = var_dimIDs(i_dim)
if (maxdimlen.lt.dimlen) maxdimlen = dimlen
endif
endif
else
write(MR_global_error,*)'MR ERROR: level coordinate is not in pos. 3 for ',invar
write(MR_global_error,*)' Expected one of: lev, isobaric, pressure,'
write(MR_global_error,*)' height, depth, lv_ISBL1, bottom_top,'
write(MR_global_error,*)' bottom_top_stag, soil_layers_stag'
write(MR_global_error,*)' Instead, found: ',Met_dim_names(2)
write(MR_global_log ,*)'MR ERROR: level coordinate is not in pos. 3 for ',invar
stop 1
endif
! tidy up
deallocate(var_dimIDs)
enddo ! ivar
! We have all the level dimension names and dim_ids; now we need to get the sizes
allocate(nlevs_fullmet(nlev_coords_detected))
allocate(levs_code(nlev_coords_detected))
allocate(levs_fullmet_sp(nlev_coords_detected,maxdimlen))
do ivar = 1,MR_MAXVARS
! Check if this variable has a z-dimension (pressure, height, depth, etc.)
if(Met_var_zdim_ncid(ivar).gt.0)then
! log the length of the dimension for this level coordinat
nSTAT = nf90_inquire_dimension(ncid,Met_var_zdim_ncid(ivar), &
name = dimname, &
len = dimlen)
idx = Met_var_zdim_idx(ivar)
nlevs_fullmet(idx) = dimlen
! Now inquire and populate the dimension variable info
nSTAT = nf90_inq_varid(ncid,dimname,var_id)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_varid ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_varid ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! Check if we need to read into a float or a double
nSTAT = nf90_inquire_variable(ncid, var_id, dimname, xtype = var_xtype)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: inq_variable: ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: inq_variable: ',dimname,nf90_strerror(nSTAT)
stop 1
endif
if(var_xtype.eq.NF90_FLOAT)then
allocate(dum1d_sp(dimlen))
nSTAT = nf90_get_var(ncid,var_id,dum1d_sp, &
start = (/1/),count = (/dimlen/))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! copy to local variable
levs_fullmet_sp(idx,1:nlevs_fullmet(idx)) = dum1d_sp(1:nlevs_fullmet(idx))
deallocate(dum1d_sp)
elseif(var_xtype.eq.NF90_DOUBLE)then
allocate(dum1d_dp(dimlen))
nSTAT = nf90_get_var(ncid,var_id,dum1d_dp, &
start = (/1/),count = (/dimlen/))
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_var ',dimname,nf90_strerror(nSTAT)
stop 1
endif
! copy to local variable
levs_fullmet_sp(idx,1:nlevs_fullmet(idx)) = real(dum1d_dp(1:nlevs_fullmet(idx)),kind=sp)
deallocate(dum1d_dp)
endif
! Check the units
nSTAT = nf90_Inquire_Attribute(ncid, var_id,&
"units",xtype, length, attnum)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR WARNING: cannot find dim units ',dimname,nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR WARNING: cannot find dim units ',dimname,nf90_strerror(nSTAT)
IsPressureDimension = .false.
stop 1
else
nSTAT = nf90_get_att(ncid, var_id,"units",ustring)
if(nSTAT.ne.NF90_NOERR) then
write(MR_global_error,*)'MR ERROR: get_att:',"time",nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: get_att:',"time",nf90_strerror(nSTAT)
stop 1
endif
! Note: the variables below are single-valued, not arrays on ivar
! If a pressure is found, the assumption here is that all pressure coordinates will
! be given in the same units (hPa or Pa) and the same orientations (bot to top, or
! inverted.
if(index(ustring,'Pa').gt.0.or.&
index(ustring,'millibar').gt.0)then
! This is a pressure level
IsPressureDimension = .true.
if(index(ustring,'hPa').gt.0.or.&
index(ustring,'millibar').gt.0)then
Pressure_Conv_Fac = 100.0_sp
else
Pressure_Conv_Fac = 1.0_sp
endif
elseif(index(ustring,'level').gt.0)then
! this is a special case for CAM files which are on hybrid levels
Pressure_Conv_Fac = 100.0_sp
IsPressureDimension = .true.
else
IsPressureDimension = .false.
endif
endif
! Finally, check for orientation
if(IsPressureDimension.and. & ! We are only concerned with orientation in pressure
nlevs_fullmet(idx).gt.1)then ! Neglect single-valued pressure coordinates
if(levs_fullmet_sp(idx,1).lt.levs_fullmet_sp(idx,2))then
z_inverted = .true.
else
z_inverted = .false.
endif
endif
endif
enddo ! ivar
! Close file
nSTAT = nf90_close(ncid)
if(nSTAT.ne.NF90_NOERR)then
write(MR_global_error,*)'MR ERROR: close file: ',nf90_strerror(nSTAT)
write(MR_global_log ,*)'MR ERROR: close file: ',nf90_strerror(nSTAT)
stop 1
endif
endif ! MR_iwindformat.eq.50
!-----------------------------------------
write(MR_global_production,*)" Found these levels"
write(MR_global_production,*)" VaribleID LevelIdx dimID length"
do ivar = 1,MR_MAXVARS
if (Met_var_IsAvailable(ivar))then
if(Met_var_zdim_idx(ivar).eq.0)then
write(MR_global_production,*)ivar,Met_var_zdim_idx(ivar),Met_var_zdim_ncid(ivar),0
else
write(MR_global_production,*)ivar,Met_var_zdim_idx(ivar),Met_var_zdim_ncid(ivar),&
nlevs_fullmet(Met_var_zdim_idx(ivar))
endif
endif
enddo
if(.not.allocated(p_fullmet_sp))then
! Now invert if necessary and convert to Pa
allocate(p_fullmet_sp(maxdimlen))
do idx = 1,nlev_coords_detected
if(z_inverted)then
do i = 1,nlevs_fullmet(idx)
p_fullmet_sp(nlevs_fullmet(idx)+1-i) = levs_fullmet_sp(idx,i)*Pressure_Conv_Fac
enddo
else
p_fullmet_sp(1:nlevs_fullmet(idx)) = levs_fullmet_sp(idx,1:nlevs_fullmet(idx))*Pressure_Conv_Fac
endif
levs_fullmet_sp(idx,:) = 0.0_sp
levs_fullmet_sp(idx,1:nlevs_fullmet(idx)) = p_fullmet_sp(1:nlevs_fullmet(idx))
enddo
deallocate(p_fullmet_sp)
endif
levs_code(1:nlev_coords_detected) = 0
levs_code(1) = 1 ! The first var checked (GPH) should have a one-to-one mapping
! Check how each of the pressure coordinates map onto the GPH grid
if (nlev_coords_detected.gt.1)then
! Only bother if there are multiple pressure coordinates
do idx = 2,nlev_coords_detected
if (nlevs_fullmet(idx).gt.nlevs_fullmet(1))then
! This coordinate has more values than the GPH pressure coordinate
levs_code(idx) = 4
elseif (nlevs_fullmet(idx).lt.nlevs_fullmet(1))then
! It there are fewer levels, check if this is a truncated coordinate (code = 2)
! or one with missing levels that requires interpolation (code = 3)
IsTruncatedDim = .true.
do i=1,nlevs_fullmet(idx)
if(abs(levs_fullmet_sp(idx,i)-levs_fullmet_sp(1,i)).gt.MR_EPS_SMALL)then
IsTruncatedDim = .false.
exit
endif
enddo
if(IsTruncatedDim)then
levs_code(idx) = 2
else
levs_code(idx) = 3
endif
else
! This coordinate has the same dimension as the GPH pressure coordinate.
! They are probably the same
levs_code(idx) = 1
endif
enddo
endif
! Now assign these levels to the working arrays
np_fullmet = nlevs_fullmet(Met_var_zdim_idx(1)) ! Assign fullmet the length of H,U,V
! Geopotential
if(.not.allocated(p_fullmet_sp)) allocate(p_fullmet_sp(np_fullmet))
idx = Met_var_zdim_idx(1)
p_fullmet_sp(1:nlevs_fullmet(idx)) = levs_fullmet_sp(idx,1:nlevs_fullmet(idx))
endif ! MR_iwind.eq.5
!---------------------------------------------------------------------------------
if(MR_iwindformat.eq.0)then
! Template windfile (example for nam198)
! Need to populate
call MR_Set_Met_Dims_Template_netcdf
endif
allocate(z_approx(np_fullmet))
do k=1,np_fullmet
! Calculate heights for US Std Atmos while pressures are still in mbars
! or hPa
z_approx(k) = MR_Z_US_StdAtm(p_fullmet_sp(k))
enddo
MR_Max_geoH_metP_predicted = z_approx(np_fullmet)
write(MR_global_info,*)"Dimension info:"
write(MR_global_info,*)" record (time): ",nt_fullmet
write(MR_global_info,*)" level (z) : ",np_fullmet
write(MR_global_info,*)" y : ",ny_fullmet
write(MR_global_info,*)" x : ",nx_fullmet
!************************************************************************
! assign boundaries of mesoscale model
if(x_inverted)then
! I know of no windfiles with x-coordinate reversed
xLL_fullmet = x_fullmet_sp(nx_fullmet)
xUR_fullmet = x_fullmet_sp(1)
else
xLL_fullmet = x_fullmet_sp(1)
xUR_fullmet = x_fullmet_sp(nx_fullmet)
endif
if(y_inverted)then
! Most lon/lat grids have y reversed
yLL_fullmet = y_fullmet_sp(ny_fullmet)
yUR_fullmet = y_fullmet_sp(1)
else
! Projected grids have y not reversed
yLL_fullmet = y_fullmet_sp(1)
yUR_fullmet = y_fullmet_sp(ny_fullmet)
endif
write(MR_global_production,*)"--------------------------------------------------------------------------------"
end subroutine MR_Read_Met_DimVars_netcdf
!##############################################################################
!##############################################################################
!
! MR_Get_WRF_grid
!
! Called once from MR_Read_Met_DimVars_netcdf
!
! This subroutine reads the variable and dimension IDs, and fills the
! coordinate dimension variables, just like MR_Read_Met_DimVars_netcdf,
! but WRF files are a bit more complicated than most since the grid/projection can
! vary and state variables (U,V,W,Gph) are each on grids staggered in the
! relevant direction.
!
! After this subroutine completes, the following variables will be set:
! All the projection parameters of NWP grid
! Met_dim_names, Met_var_NC_names, Met_var_conversion_factor, Met_var_IsAvailable
! The lengths of all the dimensions of the file
! p_fullmet_sp (converted to Pa)
! x_fullmet_sp, y_fullmet_sp
! IsLatLon_MetGrid, IsGlobal_MetGrid, IsRegular_MetGrid
!
!##############################################################################
subroutine MR_Get_WRF_grid
use MetReader
use netcdf
use projection
implicit none
integer, parameter :: sp = 4 ! single precision
integer, parameter :: dp = 8 ! double precision
integer :: nSTAT
integer :: ncid
character(len = nf90_max_name) :: name_dum
integer :: t_dim_id = 0 ! x or lon
integer :: x_dim_id = 0 ! x or lon
integer :: y_dim_id = 0 ! y or lat
integer :: z_dim_id = 0 ! x or lon
integer :: lon_var_id
integer :: lat_var_id
integer :: PB_var_id
integer :: Ppert_var_id
integer :: Map_Proj
real(kind=sp) :: WRF_dx,WRF_dy
real(kind=sp) :: Cen_lat,Stand_Lon,Truelat1,Truelat2
real(kind=sp),dimension(:,:,:) ,allocatable :: dum3d_sp
real(kind=sp),dimension(:,:,:,:),allocatable :: dum4d_sp
integer :: i
real(kind=dp) :: x_start,y_start
real(kind=dp) :: lat_in,lon_in
! MAP_PROJ - Model projection 1=Lambert, 2=polar stereographic,
! 3=mercator, 6=lat-lon