42 private :: cnvuser_prepare_tile
43 private :: cnvuser_prepare_grads
44 private :: cnvuser_prepare_grads_3d
45 private :: cnvuser_execute_grads_3d
46 private :: cnvuser_execute_tile_grads
47 private :: cnvuser_write
53 logical :: CNVUSER_OUT_AGGREGATE
55 type,
abstract :: t_param
56 character(len=H_SHORT) :: INTERP_TYPE
57 integer :: INTERP_LEVEL
59 character(len=H_LONG) :: OUT_BASENAME
60 character(len=H_MID) :: OUT_TITLE
61 character(len=H_SHORT) :: OUT_VARNAME
62 character(len=H_MID) :: OUT_VARDESC
63 character(len=H_SHORT) :: OUT_VARUNIT
64 character(len=H_SHORT) :: OUT_DTYPE
71 type,
extends(t_param) :: t_tile
72 character(len=H_SHORT) :: TILE_DTYPE
75 character(len=H_LONG) :: TILE_DIR
76 character(len=H_LONG) :: TILE_CATALOGUE
80 type,
extends(t_param) :: t_grads
81 character(len=H_LONG) :: GrADS_FILENAME
82 character(len=H_SHORT) :: GrADS_VARNAME
83 character(len=H_SHORT) :: GrADS_LATNAME
84 character(len=H_SHORT) :: GrADS_LONNAME
88 type,
extends(t_param) :: t_grads_3d
89 character(len=H_LONG) :: GrADS_FILENAME
90 character(len=H_SHORT) :: GrADS_VARNAME
91 character(len=H_SHORT) :: GrADS_LATNAME
92 character(len=H_SHORT) :: GrADS_LONNAME
93 character(len=H_SHORT) :: GrADS_LEVNAME
94 character(len=H_SHORT) :: GrADS_HEIGHT_PLEV
98 class(t_param),
allocatable :: param
99 end type t_param_wrapper
101 type(t_param_wrapper),
allocatable :: params(:)
112 character(len=H_SHORT) :: cnvuser_file_type
113 character(len=H_SHORT) :: cnvuser_interp_type
114 integer :: cnvuser_interp_level
116 character(len=H_LONG) :: cnvuser_out_basename
117 character(len=H_MID) :: cnvuser_out_title
118 character(len=H_SHORT) :: cnvuser_out_varname
119 character(len=H_MID) :: cnvuser_out_vardesc
120 character(len=H_SHORT) :: cnvuser_out_varunit
121 character(len=H_SHORT) :: cnvuser_out_dtype
122 real(
dp) :: cnvuser_out_dt
124 integer :: cnvuser_nsteps
127 character(len=H_SHORT) :: cnvuser_tile_dtype
128 real(
rp) :: cnvuser_tile_dlat
129 real(
rp) :: cnvuser_tile_dlon
130 character(len=H_LONG) :: cnvuser_tile_dir
131 character(len=H_LONG) :: cnvuser_tile_catalogue
134 character(len=H_LONG) :: cnvuser_grads_filename
135 character(len=H_SHORT) :: cnvuser_grads_varname
136 character(len=H_SHORT) :: cnvuser_grads_latname
137 character(len=H_SHORT) :: cnvuser_grads_lonname
138 character(len=H_SHORT) :: cnvuser_grads_levname
139 character(len=H_SHORT) :: cnvuser_grads_height_plev
141 namelist / param_cnvuser / &
144 cnvuser_interp_type, &
145 cnvuser_interp_level, &
146 cnvuser_tile_dtype, &
150 cnvuser_tile_catalogue, &
151 cnvuser_grads_filename, &
152 cnvuser_grads_varname, &
153 cnvuser_grads_latname, &
154 cnvuser_grads_lonname, &
155 cnvuser_grads_levname, &
156 cnvuser_grads_height_plev, &
157 cnvuser_out_basename, &
159 cnvuser_out_varname, &
160 cnvuser_out_vardesc, &
161 cnvuser_out_varunit, &
165 integer :: ierr, n_vars
169 log_info(
"CNVUSER_setup",*)
'Setup'
177 cnvuser_file_type =
''
181 elseif( ierr > 0 )
then
182 log_error(
"CNVUSER_setup",*)
'Not appropriate names in namelist PARAM_CNVUSER. Check!'
185 if (cnvuser_file_type ==
"") cycle
189 allocate(params(n_vars))
194 cnvuser_file_type =
''
195 cnvuser_interp_type =
'LINEAR'
196 cnvuser_interp_level = 5
198 cnvuser_out_basename =
''
199 cnvuser_out_title =
'SCALE-RM User Boundary'
200 cnvuser_out_varname =
''
201 cnvuser_out_vardesc =
''
202 cnvuser_out_varunit =
''
203 cnvuser_out_dtype =
'DEFAULT'
204 cnvuser_out_dt = -1_dp
209 cnvuser_tile_dtype =
'real4'
210 cnvuser_tile_dlat = -1
211 cnvuser_tile_dlon = -1
212 cnvuser_tile_dir =
''
213 cnvuser_tile_catalogue =
''
216 cnvuser_grads_filename =
''
217 cnvuser_grads_varname =
''
218 cnvuser_grads_latname =
'lat'
219 cnvuser_grads_lonname =
'lon'
220 cnvuser_grads_levname =
''
221 cnvuser_grads_height_plev =
'HGT'
225 log_nml(param_cnvuser)
226 if (cnvuser_file_type ==
"") cycle
230 select case (cnvuser_file_type)
232 allocate(t_tile::params(n_vars)%param)
234 allocate(t_grads::params(n_vars)%param)
236 allocate(t_grads_3d::params(n_vars)%param)
238 log_error(
'CNVUSER_setup',*)
'CNVUSER_FILE_TYPE is invalid: ', cnvuser_file_type
239 log_error_cont(*)
'It must be "TILE" or "GrADS".'
243 associate(param => params(n_vars)%param)
244 param%INTERP_TYPE = cnvuser_interp_type
245 param%INTERP_LEVEL = cnvuser_interp_level
246 param%OUT_BASENAME = cnvuser_out_basename
247 param%OUT_TITLE = cnvuser_out_title
248 param%OUT_VARNAME = cnvuser_out_varname
249 param%OUT_VARDESC = cnvuser_out_vardesc
250 param%OUT_VARUNIT = cnvuser_out_varunit
251 param%OUT_DTYPE = cnvuser_out_dtype
252 param%OUT_DT = cnvuser_out_dt
253 param%NSTEPS = cnvuser_nsteps
256 select type (param => params(n_vars)%param)
258 param%TILE_DTYPE = cnvuser_tile_dtype
259 param%TILE_DLAT = cnvuser_tile_dlat
260 param%TILE_DLON = cnvuser_tile_dlon
261 param%TILE_DIR = cnvuser_tile_dir
262 param%TILE_CATALOGUE = cnvuser_tile_catalogue
264 param%GrADS_FILENAME = cnvuser_grads_filename
265 param%GrADS_VARNAME = cnvuser_grads_varname
266 param%GrADS_LATNAME = cnvuser_grads_latname
267 param%GrADS_LONNAME = cnvuser_grads_lonname
268 if ( param%OUT_VARNAME ==
'' ) param%OUT_VARNAME = param%GrADS_VARNAME
270 param%GrADS_FILENAME = cnvuser_grads_filename
271 param%GrADS_VARNAME = cnvuser_grads_varname
272 param%GrADS_LATNAME = cnvuser_grads_latname
273 param%GrADS_LONNAME = cnvuser_grads_lonname
274 param%GrADS_LEVNAME = cnvuser_grads_levname
275 param%GrADS_HEIGHT_PLEV = cnvuser_grads_height_plev
276 if ( param%OUT_VARNAME ==
'' ) param%OUT_VARNAME = param%GrADS_VARNAME
288 do i = 1,
size(params)
289 associate(param => params(i)%param)
290 if ( param%OUT_BASENAME ==
'' .or. param%OUT_VARNAME ==
'' )
then
291 log_error(
'CNVUSER',*)
'CNVUSER_OUT_BASENAME and CNVUSER_OUT_VARNAME are required'
297 call cnvuser_prepare_tile(param)
298 call cnvuser_execute_tile_grads(param)
300 call cnvuser_prepare_grads(param)
301 call cnvuser_execute_tile_grads(param)
303 call cnvuser_prepare_grads_3d(param)
304 call cnvuser_execute_grads_3d(param)
314 subroutine cnvuser_prepare_tile(tile)
317 type(t_tile),
intent(in) :: tile
320 tile%TILE_DLAT, tile%TILE_DLON, &
322 tile%TILE_CATALOGUE, &
324 interp_level = tile%INTERP_LEVEL )
325 end subroutine cnvuser_prepare_tile
327 subroutine cnvuser_prepare_grads(grads)
330 type(t_grads),
intent(inout) :: grads
333 grads%GrADS_VARNAME, &
334 grads%GrADS_LATNAME, &
335 grads%GrADS_LONNAME, &
338 end subroutine cnvuser_prepare_grads
340 subroutine cnvuser_prepare_grads_3d(grads_3d)
341 type(t_grads_3d),
intent(inout) :: grads_3d
343 end subroutine cnvuser_prepare_grads_3d
345 subroutine cnvuser_execute_grads_3d(grads_3d)
352 file_cartesc_write_var, &
357 file_grads_get_shape, &
375 mapprojection_lonlat2xy
377 type(t_grads_3d),
intent(inout) :: grads_3d
379 integer :: i, j, k, step
380 integer :: file_id, var_id
381 integer :: data_shape(3)
384 real(rp) :: var_3d(ka,ia,ja,1)
387 integer :: nlev, nlon, nlat
388 logical :: zonal, pole
390 integer,
allocatable :: idx_i (:,:,:)
391 integer,
allocatable :: idx_j (:,:,:)
392 real(rp),
allocatable :: hfact (:,:,:)
393 integer,
allocatable :: idx_k (:,:,:,:,:)
394 real(rp),
allocatable :: vfact (:,:,:,:)
395 real(rp),
allocatable :: data_org (:,:,:)
396 real(rp),
allocatable :: x_org (:,:)
397 real(rp),
allocatable :: y_org (:,:)
398 real(rp),
allocatable :: lat_org (:,:)
399 real(rp),
allocatable :: lon_org (:,:)
400 real(rp),
allocatable :: lev_org (:,:,:)
401 real(rp),
allocatable :: lat_1d (:)
402 real(rp),
allocatable :: lon_1d (:)
403 real(rp),
allocatable :: lev_1d (:)
408 call file_grads_get_shape( file_id, &
409 grads_3d%GrADS_VARNAME, &
416 select case ( trim(grads_3d%INTERP_TYPE) )
418 grads_3d%INTERP_LEVEL = 4
419 case (
'DIST-WEIGHT' )
423 allocate( idx_i( ia,ja,grads_3d%INTERP_LEVEL) )
424 allocate( idx_j( ia,ja,grads_3d%INTERP_LEVEL) )
425 allocate( hfact( ia,ja,grads_3d%INTERP_LEVEL) )
426 allocate( idx_k(ka,2,ia,ja,grads_3d%INTERP_LEVEL) )
427 allocate( vfact(ka, ia,ja,grads_3d%INTERP_LEVEL) )
429 allocate( data_org( nlev, nlon, nlat ) )
430 allocate( x_org( nlon, nlat ) )
431 allocate( y_org( nlon, nlat ) )
432 allocate( lat_org( nlon, nlat ) )
433 allocate( lon_org( nlon, nlat ) )
434 allocate( lev_org( nlev, nlon, nlat ) )
435 allocate( lat_1d( nlat ) )
436 allocate( lon_1d( nlon ) )
437 allocate( lev_1d( nlev ) )
441 grads_3d%GrADS_LATNAME, &
445 call file_grads_read( file_id, &
452 lat_org(i,j) = lat_1d(j) * d2r
456 call file_grads_read( file_id, &
463 lat_org(i,j) = lat_org(i,j) * d2r
470 grads_3d%GrADS_LONNAME, &
474 call file_grads_read( file_id, &
481 lon_org(i,j) = lon_1d(i) * d2r
485 call file_grads_read( file_id, &
492 lon_org(i,j) = lon_org(i,j) * d2r
498 select case ( trim(grads_3d%GrADS_LEVNAME) )
501 grads_3d%GrADS_LEVNAME, &
504 call file_grads_read( file_id, &
512 lev_org(k,i,j) = lev_1d(k)
518 grads_3d%GrADS_HEIGHT_PLEV, &
521 call file_grads_read( file_id, &
525 log_error(
"CNVUSER_execute_GrADS_3D",*)
'Invalid property in grads_3d%GrADS_LEVNAME: ', trim(grads_3d%GrADS_LEVNAME),
' for ', trim(grads_3d%GrADS_VARNAME)
531 grads_3d%GrADS_VARNAME, &
534 select case ( grads_3d%INTERP_TYPE )
536 call mapprojection_lonlat2xy( nlon, 1, nlon, &
543 zonal = ( maxval(lon_org(:,:)) - minval(lat_org(:,:)) ) > 2.0_rp * pi * 0.9_rp
544 pole = ( maxval(lat_org(:,:)) > pi * 0.5_rp * 0.9_rp ) .or. ( minval(lat_org(:,:)) < - pi * 0.5_rp * 0.9_rp )
564 case (
'DIST-WEIGHT' )
584 grads_3d%OUT_TITLE, &
585 grads_3d%OUT_DTYPE, &
588 haszcoord = .true., &
589 aggregate = cnvuser_out_aggregate )
592 grads_3d%OUT_VARNAME, &
593 grads_3d%OUT_VARDESC, &
594 grads_3d%OUT_VARUNIT, &
596 grads_3d%OUT_DTYPE, &
598 timeintv = grads_3d%OUT_DT, &
599 nsteps = grads_3d%NSTEPS )
607 grads_3d%GrADS_VARNAME, &
610 do step = 1, grads_3d%NSTEPS
611 log_progress(*)
'step = ', step
612 timeofs = ( step - 1 ) * grads_3d%OUT_DT
614 call file_grads_read( file_id, var_id, &
633 call file_cartesc_write_var( fid, vid, &
635 grads_3d%OUT_VARNAME, &
650 deallocate( data_org )
653 deallocate( lat_org )
654 deallocate( lon_org )
655 deallocate( lev_org )
659 end subroutine cnvuser_execute_grads_3d
661 subroutine cnvuser_execute_tile_grads(param)
673 class(t_param),
intent(in) :: param
675 real(rp) :: var(ia, ja)
685 haszcoord = .false., &
686 aggregate = cnvuser_out_aggregate )
695 timeintv = param%OUT_DT, &
696 nsteps = param%NSTEPS )
700 do step = 1, param%NSTEPS
701 log_progress(*)
'step = ', step
705 call cnvuser_write( param%OUT_VARNAME, fid, vid, var(:,:), param%OUT_DT, step )
710 end subroutine cnvuser_execute_tile_grads
712 subroutine cnvuser_write( &
713 CNVUSER_OUT_VARNAME, &
719 file_cartesc_write_var
721 character(len=H_SHORT),
intent(in) :: cnvuser_out_varname
722 integer,
intent(in) :: fid, vid
723 real(rp),
intent(in) :: var(ia,ja,1)
724 real(dp),
intent(in) :: timeintv
725 integer,
intent(in) :: istep
730 timeofs = ( istep - 1 ) * timeintv
731 call file_cartesc_write_var( fid, vid, &
733 cnvuser_out_varname, &
740 end subroutine cnvuser_write