5 use misc_definitions_module
10 character (len=MAX_FILENAME_LEN) :: filename
14 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18 subroutine read_met_init(fg_source, source_is_constant, datestr, istatus)
23 integer, intent(out) :: istatus
24 logical, intent(in) :: source_is_constant
25 character (len=*), intent(in) :: fg_source
26 character (len=*), intent(in) :: datestr
34 ! 1) BUILD FILENAME BASED ON TIME
36 if (.not. source_is_constant) then
37 write(filename, '(a)') trim(fg_source)//':'//trim(datestr)
39 write(filename, '(a)') trim(fg_source)
44 inquire(unit=input_unit, opened=is_used)
45 if (.not. is_used) exit
47 call mprintf((input_unit > 100),ERROR,'In read_met_init(), couldn''t find an available Fortran unit.')
48 open(unit=input_unit, file=trim(filename), status='old', form='unformatted', iostat=io_status)
50 if (io_status > 0) istatus = 1
55 end subroutine read_met_init
58 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59 ! Name: read_next_met_field
61 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
62 subroutine read_next_met_field(fg_data, istatus)
67 type (met_data), intent(inout) :: fg_data
68 integer, intent(out) :: istatus
71 character (len=8) :: startloc
75 ! 1) READ FORMAT VERSION
76 read(unit=input_unit,err=1001,end=1001) fg_data % version
79 if (fg_data % version == 3) then
81 read(unit=input_unit) fg_data % hdate, &
91 fg_data % map_source = ' '
93 if (fg_data % field == 'HGT ') fg_data % field = 'GHT '
95 fg_data % starti = 1.0
96 fg_data % startj = 1.0
98 ! Cylindrical equidistant
99 if (fg_data % iproj == 0) then
100 fg_data % iproj = PROJ_LATLON
101 read(unit=input_unit,err=1001,end=1001) fg_data % startlat, &
102 fg_data % startlon, &
103 fg_data % deltalat, &
107 else if (fg_data % iproj == 1) then
108 fg_data % iproj = PROJ_MERC
109 read(unit=input_unit,err=1001,end=1001) fg_data % startlat, &
110 fg_data % startlon, &
116 else if (fg_data % iproj == 3) then
117 fg_data % iproj = PROJ_LC
118 read(unit=input_unit,err=1001,end=1001) fg_data % startlat, &
119 fg_data % startlon, &
123 fg_data % truelat1, &
126 ! Polar stereographic
127 else if (fg_data % iproj == 5) then
128 fg_data % iproj = PROJ_PS
129 read(unit=input_unit,err=1001,end=1001) fg_data % startlat, &
130 fg_data % startlon, &
138 call mprintf(.true.,ERROR,'Unrecognized projection code %i when reading from %s', &
139 i1=fg_data % iproj, s1=filename)
143 fg_data % earth_radius = EARTH_RADIUS_M / 1000.
145 #if (defined _GEOGRID) || (defined _METGRID)
146 fg_data % dx = fg_data % dx * 1000.
147 fg_data % dy = fg_data % dy * 1000.
149 if (fg_data % xlonc > 180.) fg_data % xlonc = fg_data%xlonc - 360.
151 if (fg_data % startlon > 180.) fg_data % startlon = fg_data%startlon - 360.
153 if (fg_data % startlat < -90.) fg_data % startlat = -90.
154 if (fg_data % startlat > 90.) fg_data % startlat = 90.
157 fg_data % is_wind_grid_rel = .true.
159 allocate(fg_data % slab(fg_data % nx, fg_data % ny))
160 read(unit=input_unit,err=1001,end=1001) fg_data % slab
165 else if (fg_data % version == 4) then
167 read(unit=input_unit) fg_data % hdate, &
169 fg_data % map_source, &
178 if (fg_data % field == 'HGT ') fg_data % field = 'GHT '
180 ! Cylindrical equidistant
181 if (fg_data % iproj == 0) then
182 fg_data % iproj = PROJ_LATLON
183 read(unit=input_unit,err=1001,end=1001) startloc, &
184 fg_data % startlat, &
185 fg_data % startlon, &
186 fg_data % deltalat, &
190 else if (fg_data % iproj == 1) then
191 fg_data % iproj = PROJ_MERC
192 read(unit=input_unit,err=1001,end=1001) startloc, &
193 fg_data % startlat, &
194 fg_data % startlon, &
200 else if (fg_data % iproj == 3) then
201 fg_data % iproj = PROJ_LC
202 read(unit=input_unit,err=1001,end=1001) startloc, &
203 fg_data % startlat, &
204 fg_data % startlon, &
208 fg_data % truelat1, &
211 ! Polar stereographic
212 else if (fg_data % iproj == 5) then
213 fg_data % iproj = PROJ_PS
214 read(unit=input_unit,err=1001,end=1001) startloc, &
215 fg_data % startlat, &
216 fg_data % startlon, &
224 call mprintf(.true.,ERROR,'Unrecognized projection code %i when reading from %s', &
225 i1=fg_data % iproj, s1=filename)
229 if (startloc == 'CENTER ') then
230 fg_data % starti = real(fg_data % nx)/2.
231 fg_data % startj = real(fg_data % ny)/2.
232 else if (startloc == 'SWCORNER') then
233 fg_data % starti = 1.0
234 fg_data % startj = 1.0
237 fg_data % earth_radius = EARTH_RADIUS_M / 1000.
239 #if (defined _GEOGRID) || (defined _METGRID)
240 fg_data % dx = fg_data % dx * 1000.
241 fg_data % dy = fg_data % dy * 1000.
243 if (fg_data % xlonc > 180.) fg_data % xlonc = fg_data % xlonc - 360.
245 if (fg_data % startlon > 180.) fg_data % startlon = fg_data % startlon - 360.
247 if (fg_data % startlat < -90.) fg_data % startlat = -90.
248 if (fg_data % startlat > 90.) fg_data % startlat = 90.
251 fg_data % is_wind_grid_rel = .true.
253 allocate(fg_data % slab(fg_data % nx, fg_data % ny))
254 read(unit=input_unit,err=1001,end=1001) fg_data % slab
259 else if (fg_data % version == 5) then
261 read(unit=input_unit) fg_data % hdate, &
263 fg_data % map_source, &
272 if (fg_data % field == 'HGT ') fg_data % field = 'GHT '
274 ! Cylindrical equidistant
275 if (fg_data % iproj == 0) then
276 fg_data % iproj = PROJ_LATLON
277 read(unit=input_unit,err=1001,end=1001) startloc, &
278 fg_data % startlat, &
279 fg_data % startlon, &
280 fg_data % deltalat, &
281 fg_data % deltalon, &
282 fg_data % earth_radius
285 else if (fg_data % iproj == 1) then
286 fg_data % iproj = PROJ_MERC
287 read(unit=input_unit,err=1001,end=1001) startloc, &
288 fg_data % startlat, &
289 fg_data % startlon, &
292 fg_data % truelat1, &
293 fg_data % earth_radius
296 else if (fg_data % iproj == 3) then
297 fg_data % iproj = PROJ_LC
298 read(unit=input_unit,err=1001,end=1001) startloc, &
299 fg_data % startlat, &
300 fg_data % startlon, &
304 fg_data % truelat1, &
305 fg_data % truelat2, &
306 fg_data % earth_radius
309 else if (fg_data % iproj == 4) then
310 fg_data % iproj = PROJ_GAUSS
311 read(unit=input_unit,err=1001,end=1001) startloc, &
312 fg_data % startlat, &
313 fg_data % startlon, &
314 fg_data % deltalat, &
315 fg_data % deltalon, &
316 fg_data % earth_radius
318 ! Polar stereographic
319 else if (fg_data % iproj == 5) then
320 fg_data % iproj = PROJ_PS
321 read(unit=input_unit,err=1001,end=1001) startloc, &
322 fg_data % startlat, &
323 fg_data % startlon, &
327 fg_data % truelat1, &
328 fg_data % earth_radius
332 call mprintf(.true.,ERROR,'Unrecognized projection code %i when reading from %s', &
333 i1=fg_data % iproj, s1=filename)
337 if (startloc == 'CENTER ') then
338 fg_data % starti = real(fg_data % nx)/2.
339 fg_data % startj = real(fg_data % ny)/2.
340 else if (startloc == 'SWCORNER') then
341 fg_data % starti = 1.0
342 fg_data % startj = 1.0
345 #if (defined _GEOGRID) || (defined _METGRID)
346 fg_data % dx = fg_data % dx * 1000.
347 fg_data % dy = fg_data % dy * 1000.
349 if (fg_data % xlonc > 180.) fg_data % xlonc = fg_data % xlonc - 360.
351 if (fg_data % startlon > 180.) fg_data % startlon = fg_data % startlon - 360.
353 if (fg_data % startlat < -90.) fg_data % startlat = -90.
354 if (fg_data % startlat > 90.) fg_data % startlat = 90.
357 read(unit=input_unit,err=1001,end=1001) fg_data % is_wind_grid_rel
359 allocate(fg_data % slab(fg_data % nx, fg_data % ny))
360 read(unit=input_unit,err=1001,end=1001) fg_data % slab
365 call mprintf(.true.,ERROR,'Didn''t recognize format version of data in %s.\n'// &
366 'Found version %i but expected either 3, 4, or 5. This could be an endian problem.', &
367 s1=filename, i1=fg_data % version)
374 end subroutine read_next_met_field
377 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
378 ! Name: read_met_close
380 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
381 subroutine read_met_close()
385 close(unit=input_unit)
386 filename = 'UNINITIALIZED_FILENAME'
388 end subroutine read_met_close
390 end module read_met_module