1 module write_met_module
4 use misc_definitions_module
9 character (len=MAX_FILENAME_LEN) :: met_out_filename
13 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 ! Name: write_met_init
16 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 subroutine write_met_init(fg_source, source_is_constant, datestr, istatus)
22 integer, intent(out) :: istatus
23 logical, intent(in) :: source_is_constant
24 character (len=*), intent(in) :: fg_source
25 character (len=*), intent(in) :: datestr
33 ! 1) BUILD FILENAME BASED ON TIME
34 met_out_filename = ' '
35 if (.not. source_is_constant) then
36 write(met_out_filename, '(a)') trim(fg_source)//':'//trim(datestr)
38 write(met_out_filename, '(a)') trim(fg_source)
43 inquire(unit=output_unit, opened=is_used)
44 if (.not. is_used) exit
46 call mprintf((output_unit > 100),ERROR,'In write_met_init(), couldn''t find an available Fortran unit.')
47 open(unit=output_unit, file=trim(met_out_filename), status='unknown', form='unformatted', iostat=io_status)
49 if (io_status > 0) istatus = 1
54 end subroutine write_met_init
57 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
58 ! Name: write_next_met_field
60 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61 subroutine write_next_met_field(fg_data, istatus)
66 type (met_data), intent(in) :: fg_data
67 integer, intent(out) :: istatus
70 character (len=8) :: startloc
71 character (len=9) :: local_field
75 ! 1) WRITE FORMAT VERSION
76 write(unit=output_unit) fg_data % version
78 local_field = fg_data % field
79 if (local_field == 'GHT ') local_field = 'HGT '
82 if (fg_data % version == 3) then
84 ! Cylindrical equidistant
85 if (fg_data % iproj == PROJ_LATLON) then
86 write(unit=output_unit) fg_data % hdate, &
95 write(unit=output_unit) fg_data % startlat, &
101 else if (fg_data % iproj == PROJ_MERC) then
102 write(unit=output_unit) fg_data % hdate, &
111 write(unit=output_unit) fg_data % startlat, &
112 fg_data % startlon, &
118 else if (fg_data % iproj == PROJ_LC) then
119 write(unit=output_unit) fg_data % hdate, &
128 write(unit=output_unit) fg_data % startlat, &
129 fg_data % startlon, &
133 fg_data % truelat1, &
136 ! Polar stereographic
137 else if (fg_data % iproj == PROJ_PS) then
138 write(unit=output_unit) fg_data % hdate, &
147 write(unit=output_unit) fg_data % startlat, &
148 fg_data % startlon, &
156 call mprintf(.true.,ERROR,'Unrecognized projection code %i when reading from %s.', &
157 i1=fg_data % iproj,s1=met_out_filename)
161 write(unit=output_unit) fg_data % slab
166 else if (fg_data % version == 4) then
168 if (fg_data % starti == 1.0 .and. fg_data % startj == 1.0) then
174 ! Cylindrical equidistant
175 if (fg_data % iproj == PROJ_LATLON) then
176 write(unit=output_unit) fg_data % hdate, &
178 fg_data % map_source, &
186 write(unit=output_unit) startloc, &
187 fg_data % startlat, &
188 fg_data % startlon, &
189 fg_data % deltalat, &
193 else if (fg_data % iproj == PROJ_MERC) then
194 write(unit=output_unit) fg_data % hdate, &
196 fg_data % map_source, &
204 write(unit=output_unit) startloc, &
205 fg_data % startlat, &
206 fg_data % startlon, &
212 else if (fg_data % iproj == PROJ_LC) then
213 write(unit=output_unit) fg_data % hdate, &
215 fg_data % map_source, &
223 write(unit=output_unit) startloc, &
224 fg_data % startlat, &
225 fg_data % startlon, &
229 fg_data % truelat1, &
232 ! Polar stereographic
233 else if (fg_data % iproj == PROJ_PS) then
234 write(unit=output_unit) fg_data % hdate, &
236 fg_data % map_source, &
244 write(unit=output_unit) startloc, &
245 fg_data % startlat, &
246 fg_data % startlon, &
254 call mprintf(.true.,ERROR,'Unrecognized projection code %i when reading from %s.', &
255 i1=fg_data % iproj,s1=met_out_filename)
259 write(unit=output_unit) fg_data % slab
264 else if (fg_data % version == 5) then
266 if (fg_data % starti == 1.0 .and. fg_data % startj == 1.0) then
272 ! Cylindrical equidistant
273 if (fg_data % iproj == PROJ_LATLON) then
274 write(unit=output_unit) fg_data % hdate, &
276 fg_data % map_source, &
284 write(unit=output_unit) startloc, &
285 fg_data % startlat, &
286 fg_data % startlon, &
287 fg_data % deltalat, &
288 fg_data % deltalon, &
289 fg_data % earth_radius
292 else if (fg_data % iproj == PROJ_MERC) then
293 write(unit=output_unit) fg_data % hdate, &
295 fg_data % map_source, &
303 write(unit=output_unit) startloc, &
304 fg_data % startlat, &
305 fg_data % startlon, &
308 fg_data % truelat1, &
309 fg_data % earth_radius
312 else if (fg_data % iproj == PROJ_LC) then
313 write(unit=output_unit) fg_data % hdate, &
315 fg_data % map_source, &
323 write(unit=output_unit) startloc, &
324 fg_data % startlat, &
325 fg_data % startlon, &
329 fg_data % truelat1, &
330 fg_data % truelat2, &
331 fg_data % earth_radius
334 else if (fg_data % iproj == PROJ_GAUSS) then
335 write(unit=output_unit) fg_data % hdate, &
337 fg_data % map_source, &
345 write(unit=output_unit) startloc, &
346 fg_data % startlat, &
347 fg_data % startlon, &
348 fg_data % deltalat, &
349 fg_data % deltalon, &
350 fg_data % earth_radius
352 ! Polar stereographic
353 else if (fg_data % iproj == PROJ_PS) then
354 write(unit=output_unit) fg_data % hdate, &
356 fg_data % map_source, &
364 write(unit=output_unit) startloc, &
365 fg_data % startlat, &
366 fg_data % startlon, &
370 fg_data % truelat1, &
371 fg_data % earth_radius
375 call mprintf(.true.,ERROR,'Unrecognized projection code %i when reading from %s.', &
376 i1=fg_data % iproj,s1=met_out_filename)
380 write(unit=output_unit) fg_data % is_wind_grid_rel
382 write(unit=output_unit) fg_data % slab
387 call mprintf(.true.,ERROR,'Didn''t recognize format number %i.', i1=fg_data % version)
392 end subroutine write_next_met_field
395 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
396 ! Name: write_met_close
398 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
399 subroutine write_met_close()
403 close(unit=output_unit)
404 met_out_filename = 'UNINITIALIZED_FILENAME'
406 end subroutine write_met_close
408 end module write_met_module