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
68 character(len=H_SHORT) :: CNV2D_tile_dtype
69 character(len=H_LONG) :: CNV2D_tile_dir
70 real(RP) :: TILE_DLAT, TILE_DLON
73 character(len=H_LONG),
allocatable :: TILE_fname(:)
74 logical,
allocatable :: TILE_hit (:)
75 integer,
allocatable :: TILE_JS (:)
76 integer,
allocatable :: TILE_JE (:)
77 integer,
allocatable :: TILE_IS (:)
78 integer,
allocatable :: TILE_IE (:)
80 integer :: dom_is, dom_ie, dom_js, dom_je
84 integer :: CNV2D_grads_fid
85 integer :: CNV2D_grads_vid
99 log_info(
"CNV2D_setup",*)
'Setup'
132 file_tiledata_get_data
137 character(len=*),
intent(in) :: dtype
138 real(rp),
intent(in) :: dlat, dlon
139 character(len=*),
intent(in) :: dir
140 character(len=*),
intent(in) :: catalogue
141 character(len=*),
intent(in) :: interp_type
143 integer,
intent(in),
optional :: interp_level
144 integer,
intent(in),
optional :: nmax
146 real(rp) :: domain_lats, domain_late
147 real(rp) :: domain_lons, domain_lone
149 character(len=H_LONG) :: fname
155 if (
present(nmax) )
then
161 domain_lats = minval( latxv(:,:) )
162 domain_late = maxval( latxv(:,:) )
163 domain_lons = minval( lonuy(:,:) )
164 domain_lone = maxval( lonuy(:,:) )
166 log_info(
"CNV2D_setup",*)
'Domain Information'
167 log_info_cont(*)
'Domain (LAT) :', domain_lats/d2r, domain_late/d2r
168 log_info_cont(*)
' (LON) :', domain_lons/d2r, domain_lone/d2r
170 tile_dlat = dlat * d2r
171 tile_dlon = dlon * d2r
173 if (
allocated(tile_fname))
deallocate(tile_fname)
174 if (
allocated(tile_hit))
deallocate(tile_hit)
175 if (
allocated(tile_js))
deallocate(tile_js)
176 if (
allocated(tile_je))
deallocate(tile_je)
177 if (
allocated(tile_is))
deallocate(tile_is)
178 if (
allocated(tile_ie))
deallocate(tile_ie)
179 if (
allocated(lat_1d))
deallocate(lat_1d)
180 if (
allocated(lon_1d))
deallocate(lon_1d)
182 allocate( tile_fname(tile_nlim), tile_hit(tile_nlim) )
183 allocate( tile_js(tile_nlim), tile_je(tile_nlim), tile_is(tile_nlim), tile_ie(tile_nlim) )
186 fname = trim(dir)//
'/'//trim(catalogue)
189 tile_dlat, tile_dlon, &
190 domain_lats, domain_late, domain_lons, domain_lone, &
194 tile_fname(:), tile_hit(:), &
195 tile_js(:), tile_je(:), tile_is(:), tile_ie(:), &
196 nlat, nlon, dom_js, dom_je, dom_is, dom_ie, &
199 allocate( lat_1d(nlat) )
200 allocate( lon_1d(nlon) )
204 tile_dlat, tile_dlon, &
205 lat_1d(:), lon_1d(:) )
208 cnv2d_tile_dtype = dtype
211 call cnv2d_init( interp_type, &
212 interp_level = interp_level, &
230 file_grads_get_shape, &
237 character(len=*),
intent(in) :: file_name
238 character(len=*),
intent(in) :: var_name
239 character(len=*),
intent(in) :: lat_name
240 character(len=*),
intent(in) :: lon_name
241 character(len=*),
intent(in) :: interp_type
242 integer,
intent(in) :: interp_level
243 real(rp),
intent(in),
optional :: search_limit
244 character(len=*),
intent(in),
optional :: postfix
246 integer :: file_id, var_id
254 call file_grads_get_shape( file_id, var_name, &
259 if (
allocated(lat_org))
deallocate(lat_org)
260 if (
allocated(lon_org))
deallocate(lon_org)
261 if (
allocated(lat_1d))
deallocate(lat_1d)
262 if (
allocated(lon_1d))
deallocate(lon_1d)
263 allocate( lat_org(nlon,nlat), lon_org(nlon,nlat) )
264 allocate( lat_1d(nlat), lon_1d(nlon) )
270 call file_grads_read( file_id, var_id, &
275 lat_org(i,j) = lat_1d(j) * d2r
279 call file_grads_read( file_id, var_id, &
285 lat_org(i,j) = lat_org(i,j) * d2r
294 call file_grads_read( file_id, var_id, &
299 lon_org(i,j) = lon_1d(i) * d2r
303 call file_grads_read( file_id, var_id, &
309 lon_org(i,j) = lon_org(i,j) * d2r
317 cnv2d_ftype = i_grads
318 cnv2d_grads_fid = file_id
319 cnv2d_grads_vid = var_id
321 call cnv2d_init( interp_type, &
322 interp_level = interp_level, &
323 search_limit = search_limit, &
324 ll_struct = .false. )
335 file_tiledata_get_data
341 real(rp),
intent(out) :: var(
ia,
ja)
342 integer,
intent(in),
optional :: step
343 real(rp),
intent(in),
optional :: min_value
344 logical,
intent(in),
optional :: yrevers
346 select case ( cnv2d_ftype )
348 call file_tiledata_get_data( nlat, nlon, &
352 tile_dlat, tile_dlon, &
353 tile_fname(:), tile_hit(:), &
354 tile_js(:), tile_je(:), tile_is(:), tile_ie(:), &
355 dom_js, dom_je, dom_is, dom_ie, &
359 min_value = min_value, yrevers = yrevers )
361 call file_grads_read( cnv2d_grads_fid, cnv2d_grads_vid, &
370 idx_i(:,:,:), idx_j(:,:,:), &
381 subroutine cnv2d_init( &
395 mapprojection_lonlat2xy
404 character(len=*),
intent(in) :: interp_type
405 integer,
intent(in),
optional :: interp_level
406 real(rp),
intent(in),
optional :: search_limit
407 logical,
intent(in),
optional :: ll_struct
409 real(rp),
allocatable :: x_org(:,:), y_org(:,:)
412 if (
allocated(idx_i))
deallocate(idx_i)
413 if (
allocated(idx_j))
deallocate(idx_j)
414 if (
allocated(hfact))
deallocate(hfact)
415 if (
allocated(data_org))
deallocate(data_org)
417 select case ( interp_type )
420 case (
'DIST-WEIGHT' )
421 if (
present(interp_level) )
then
422 itp_lev = interp_level
424 log_error(
'CNV2D_init',*)
'INTERP_LEVEL is required for the DIST-WEIGHT interpolation'
428 log_error(
'CNV2D_init',*)
'INTERP_TYPE is invalid: ', trim(interp_type)
433 allocate( idx_i(
ia,
ja,itp_lev) )
434 allocate( idx_j(
ia,
ja,itp_lev) )
435 allocate( hfact(
ia,
ja,itp_lev) )
437 select case ( interp_type )
439 if ( ll_struct )
then
442 lon_1d(:), lat_1d(:), &
443 lon(:,:), lat(:,:), &
444 idx_i(:,:,:), idx_j(:,:,:), &
447 allocate( x_org(nlon,nlat), y_org(nlon,nlat) )
448 call mapprojection_lonlat2xy( nlon, 1, nlon, nlat, 1, nlat, &
449 lon_org(:,:), lat_org(:,:), &
450 x_org(:,:), y_org(:,:) )
452 zonal = ( maxval(lon_org) - minval(lat_org) ) > 2.0_rp * pi * 0.9_rp
453 pole = ( maxval(lat_org) > pi * 0.5_rp * 0.9_rp ) .or. ( minval(lat_org) < - pi * 0.5_rp * 0.9_rp )
456 x_org(:,:), y_org(:,:), &
458 idx_i(:,:,:), idx_j(:,:,:), &
460 zonal = zonal, pole = pole, &
462 deallocate( x_org, y_org )
464 case (
'DIST-WEIGHT' )
468 lon_org(:,:), lat_org(:,:), &
469 lon(:,:), lat(:,:), &
470 idx_i(:,:,:), idx_j(:,:,:), &
472 latlon_structure = ll_struct, &
473 lon_1d = lon_1d(:), &
474 lat_1d = lat_1d(:), &
475 search_limit = search_limit )
478 allocate( data_org(nlon,nlat) )
481 end subroutine cnv2d_init