47 integer,
parameter :: I_TILE = 1
48 integer,
parameter :: I_GrADS = 2
49 integer :: CNV2D_ftype
54 real(RP),
allocatable :: data_org(:,:)
55 real(RP),
allocatable :: LAT_org (:,:)
56 real(RP),
allocatable :: LON_org (:,:)
57 real(RP),
allocatable :: LAT_1d (:)
58 real(RP),
allocatable :: LON_1d (:)
62 integer,
allocatable :: idx_i(:,:,:)
63 integer,
allocatable :: idx_j(:,:,:)
64 real(RP),
allocatable :: hfact(:,:,:)
65 logical :: zonal, pole
67 logical :: first = .true.
70 character(len=H_SHORT) :: CNV2D_tile_dtype
71 character(len=H_LONG) :: CNV2D_tile_dir
72 real(RP) :: TILE_DLAT, TILE_DLON
75 character(len=H_LONG),
allocatable :: TILE_fname(:)
76 logical,
allocatable :: TILE_hit (:)
77 integer,
allocatable :: TILE_JS (:)
78 integer,
allocatable :: TILE_JE (:)
79 integer,
allocatable :: TILE_IS (:)
80 integer,
allocatable :: TILE_IE (:)
82 integer :: dom_is, dom_ie, dom_js, dom_je
86 integer :: CNV2D_grads_fid
87 integer :: CNV2D_grads_vid
101 log_info(
"CNV2D_setup",*)
'Setup'
134 file_tiledata_get_data
139 character(len=*),
intent(in) :: dtype
140 real(rp),
intent(in) :: dlat, dlon
141 character(len=*),
intent(in) :: dir
142 character(len=*),
intent(in) :: catalogue
143 character(len=*),
intent(in) :: interp_type
145 integer,
intent(in),
optional :: interp_level
146 integer,
intent(in),
optional :: nmax
148 real(rp) :: domain_lats, domain_late
149 real(rp) :: domain_lons, domain_lone
151 character(len=H_LONG) :: fname
157 if (
present(nmax) )
then
163 domain_lats = minval( latxv(:,:) )
164 domain_late = maxval( latxv(:,:) )
165 domain_lons = minval( lonuy(:,:) )
166 domain_lone = maxval( lonuy(:,:) )
168 log_info(
"CNV2D_setup",*)
'Domain Information'
169 log_info_cont(*)
'Domain (LAT) :', domain_lats/d2r, domain_late/d2r
170 log_info_cont(*)
' (LON) :', domain_lons/d2r, domain_lone/d2r
172 tile_dlat = dlat * d2r
173 tile_dlon = dlon * d2r
175 if ( .not. first )
then
176 deallocate( tile_fname, tile_hit )
177 deallocate( tile_js, tile_je, tile_is, tile_ie )
178 deallocate( lat_1d, lon_1d )
181 allocate( tile_fname(tile_nlim), tile_hit(tile_nlim) )
182 allocate( tile_js(tile_nlim), tile_je(tile_nlim), tile_is(tile_nlim), tile_ie(tile_nlim) )
185 fname = trim(dir)//
'/'//trim(catalogue)
188 tile_dlat, tile_dlon, &
189 domain_lats, domain_late, domain_lons, domain_lone, &
193 tile_fname(:), tile_hit(:), &
194 tile_js(:), tile_je(:), tile_is(:), tile_ie(:), &
195 nlat, nlon, dom_js, dom_je, dom_is, dom_ie, &
198 allocate( lat_1d(nlat) )
199 allocate( lon_1d(nlon) )
203 tile_dlat, tile_dlon, &
204 lat_1d(:), lon_1d(:) )
207 cnv2d_tile_dtype = dtype
210 call cnv2d_init( interp_type, &
211 interp_level = interp_level, &
229 file_grads_get_shape, &
236 character(len=*),
intent(in) :: file_name
237 character(len=*),
intent(in) :: var_name
238 character(len=*),
intent(in) :: lat_name
239 character(len=*),
intent(in) :: lon_name
240 character(len=*),
intent(in) :: interp_type
241 integer,
intent(in),
optional :: interp_level
242 real(rp),
intent(in),
optional :: search_limit
243 character(len=*),
intent(in),
optional :: postfix
245 integer :: file_id, var_id
253 call file_grads_get_shape( file_id, var_name, &
258 if ( .not. first )
deallocate( lat_org, lon_org, lat_1d, lon_1d )
259 allocate( lat_org(nlon,nlat), lon_org(nlon,nlat) )
260 allocate( lat_1d(nlat), lon_1d(nlon) )
266 call file_grads_read( file_id, var_id, &
271 lat_org(i,j) = lat_1d(j) * d2r
275 call file_grads_read( file_id, var_id, &
281 lat_org(i,j) = lat_org(i,j) * d2r
290 call file_grads_read( file_id, var_id, &
295 lon_org(i,j) = lon_1d(i) * d2r
299 call file_grads_read( file_id, var_id, &
305 lon_org(i,j) = lon_org(i,j) * d2r
313 cnv2d_ftype = i_grads
314 cnv2d_grads_fid = file_id
315 cnv2d_grads_vid = var_id
317 call cnv2d_init( interp_type, &
318 interp_level = interp_level, &
319 search_limit = search_limit, &
320 ll_struct = .false. )
331 file_tiledata_get_data
337 real(rp),
intent(out) :: var(
ia,
ja)
338 integer,
intent(in),
optional :: step
339 real(rp),
intent(in),
optional :: min_value
340 logical,
intent(in),
optional :: yrevers
342 select case ( cnv2d_ftype )
344 call file_tiledata_get_data( nlat, nlon, &
348 tile_dlat, tile_dlon, &
349 tile_fname(:), tile_hit(:), &
350 tile_js(:), tile_je(:), tile_is(:), tile_ie(:), &
351 dom_js, dom_je, dom_is, dom_ie, &
355 min_value = min_value, yrevers = yrevers )
357 call file_grads_read( cnv2d_grads_fid, cnv2d_grads_vid, &
366 idx_i(:,:,:), idx_j(:,:,:), &
377 subroutine cnv2d_init( &
391 mapprojection_lonlat2xy
400 character(len=*),
intent(in) :: interp_type
401 integer,
intent(in),
optional :: interp_level
402 real(rp),
intent(in),
optional :: search_limit
403 logical,
intent(in),
optional :: ll_struct
405 real(rp),
allocatable :: x_org(:,:), y_org(:,:)
408 if ( .not. first )
deallocate( idx_i, idx_j, hfact, data_org )
410 select case ( interp_type )
413 case (
'DIST-WEIGHT' )
414 if (
present(interp_level) )
then
415 itp_lev = interp_level
417 log_error(
'CNV2D_init',*)
'INTERP_LEVEL is required for the DIST-WEIGHT interpolation'
421 log_error(
'CNV2D_init',*)
'INTERP_TYPE is invalid: ', trim(interp_type)
426 allocate( idx_i(
ia,
ja,itp_lev) )
427 allocate( idx_j(
ia,
ja,itp_lev) )
428 allocate( hfact(
ia,
ja,itp_lev) )
430 select case ( interp_type )
432 if ( ll_struct )
then
435 lon_1d(:), lat_1d(:), &
436 lon(:,:), lat(:,:), &
437 idx_i(:,:,:), idx_j(:,:,:), &
440 allocate( x_org(nlon,nlat), y_org(nlon,nlat) )
441 call mapprojection_lonlat2xy( nlon, 1, nlon, nlat, 1, nlat, &
442 lon_org(:,:), lat_org(:,:), &
443 x_org(:,:), y_org(:,:) )
445 zonal = ( maxval(lon_org) - minval(lat_org) ) > 2.0_rp * pi * 0.9_rp
446 pole = ( maxval(lat_org) > pi * 0.5_rp * 0.9_rp ) .or. ( minval(lat_org) < - pi * 0.5_rp * 0.9_rp )
449 x_org(:,:), y_org(:,:), &
451 idx_i(:,:,:), idx_j(:,:,:), &
453 zonal = zonal, pole = pole )
454 deallocate( x_org, y_org )
456 case (
'DIST-WEIGHT' )
460 lon_org(:,:), lat_org(:,:), &
461 lon(:,:), lat(:,:), &
462 idx_i(:,:,:), idx_j(:,:,:), &
464 latlon_structure = ll_struct, &
465 lon_1d = lon_1d(:), &
466 lat_1d = lat_1d(:), &
467 search_limit = search_limit )
470 allocate( data_org(nlon,nlat) )
475 end subroutine cnv2d_init