58 character(len=*),
intent(in) :: input_file
60 integer,
intent(in) :: localpet, npets
62 character(len=50) :: vname
64 integer :: dimid, dims(1), ncid, status
65 integer :: count, num_vars, n
66 integer :: rc, varid, i, j, i_src_corner
67 integer(esmf_kind_i4),
pointer :: mask_ptr(:,:)
68 integer :: clb(2), cub(2)
69 integer :: clb_corner(2), cub_corner(2)
71 real(esmf_kind_r4),
allocatable :: mask_global(:,:)
72 real(esmf_kind_r8),
allocatable :: lat_global(:)
73 real(esmf_kind_r8),
allocatable :: lon_global(:)
74 real(esmf_kind_r8),
allocatable :: lat_corner_global(:)
75 real(esmf_kind_r8),
allocatable :: lon_corner_global(:)
76 real(esmf_kind_r4),
pointer :: mask_field_ptr(:,:)
77 real(esmf_kind_r8),
pointer :: lat_ptr(:,:)
78 real(esmf_kind_r8),
pointer :: lon_ptr(:,:)
79 real(esmf_kind_r8),
pointer :: lat_corner_ptr(:,:)
80 real(esmf_kind_r8),
pointer :: lon_corner_ptr(:,:)
82 real(esmf_kind_r4) :: missing
84 type(esmf_field) :: mask_field
85 type(esmf_polekind_flag) :: polekindflag(2)
87 print*,
"- OPEN FILE: ", trim(input_file)
88 status = nf90_open(input_file, nf90_nowrite, ncid)
89 call netcdf_err(status,
"OPENING INPUT SOURCE FILE")
91 status = nf90_get_att(ncid, nf90_global,
'source',
source)
92 if (status /= nf90_noerr)
source=
"unknown" 94 if(localpet == 0) print*,
'- SOURCE OF DATA IS: ', trim(
source)
96 status = nf90_inq_dimid(ncid,
'idim', dimid)
97 call netcdf_err(status,
"READING I DIMENSION ID OF SOURCE DATA")
98 status = nf90_inquire_dimension(ncid, dimid, len=
i_src)
99 call netcdf_err(status,
"READING I DIMENSION OF SOURCE DATA")
101 status = nf90_inq_dimid(ncid,
'jdim', dimid)
102 call netcdf_err(status,
"READING J DIMENSION ID OF SOURCE DATA")
103 status = nf90_inquire_dimension(ncid, dimid, len=
j_src)
104 call netcdf_err(status,
"READING J DIMENSION OF SOURCE DATA")
106 if(localpet == 0) print*,
'- I/J DIMENSION OF SOURCE DATA: ',
i_src,
j_src 108 allocate(lat_global(
j_src))
109 status = nf90_inq_varid(ncid,
'lat', varid)
110 call netcdf_err(status,
"READING SOURCE DATA LATITUDE ID")
111 status = nf90_get_var(ncid, varid, lat_global)
112 call netcdf_err(status,
"READING SOURCE DATA LATITUDES")
114 allocate(lon_global(
i_src))
115 status = nf90_inq_varid(ncid,
'lon', varid)
116 call netcdf_err(status,
"READING SOURCE DATA LONGITUDE ID")
117 status = nf90_get_var(ncid, varid, lon_global)
118 call netcdf_err(status,
"READING SOURCE DATA LONGITUDE")
120 allocate(lat_corner_global(
j_src+1))
121 status = nf90_inq_varid(ncid,
'lat_corner', varid)
122 call netcdf_err(status,
"READING SOURCE DATA CORNER LATITUDE ID")
123 status = nf90_get_var(ncid, varid, lat_corner_global)
124 call netcdf_err(status,
"READING SOURCE DATA CORNER LATITUDE")
131 status = nf90_inq_varid(ncid,
'lon_corner', varid)
132 call netcdf_err(status,
"READING SOURCE DATA CORNER LONGITUDE ID")
133 status = nf90_inquire_variable(ncid, varid, dimids=dims)
134 call netcdf_err(status,
"READING SOURCE DATA CORNER LONGITUDE DIMIDS")
135 status = nf90_inquire_dimension(ncid, dims(1), len=i_src_corner)
136 call netcdf_err(status,
"READING SOURCE DATA CORNER LONGITUDE DIMS")
137 allocate(lon_corner_global(i_src_corner))
138 status = nf90_get_var(ncid, varid, lon_corner_global)
139 call netcdf_err(status,
"READING SOURCE DATA CORNER LONGITUDE")
141 status = nf90_inq_dimid(ncid,
'time', dimid)
142 call netcdf_err(status,
"READING SOURCE DATA TIME ID")
143 status = nf90_inquire_dimension(ncid, dimid, len=
num_time_recs)
144 call netcdf_err(status,
"READING SOURCE DATA NUM TIME PERIODS")
147 status = nf90_inq_varid(ncid,
'time', varid)
148 call netcdf_err(status,
"READING SOURCE DATA TIME VARID")
149 status = nf90_get_var(ncid, varid,
day_of_rec)
150 call netcdf_err(status,
"READING SOURCE DATA DAY OF RECORD")
152 print*,
'- SOURCE DATA DAYS OF RECORD: ',
day_of_rec 154 status = nf90_inquire(ncid, nvariables=num_vars)
155 call netcdf_err(status,
"READING NUMBER OF VARIABLES SOURCE DATA")
171 status = nf90_inquire_variable(ncid, n, name=vname)
172 call netcdf_err(status,
"READING FIELD NAMES")
174 if (trim(vname) ==
'time') cycle
175 if (trim(vname) ==
'lon') cycle
176 if (trim(vname) ==
'lon_corner') cycle
177 if (trim(vname) ==
'lat') cycle
178 if (trim(vname) ==
'lat_corner') cycle
185 if(localpet==0) print*,
'- FIELDS TO BE PROCESSED: ',
field_names 187 if (localpet == 0)
then 189 status = nf90_inq_varid(ncid,
field_names(1), varid)
191 status = nf90_get_var(ncid, varid, mask_global)
194 allocate(mask_global(0,0))
202 status = nf90_inq_varid(ncid,
field_names(1), varid)
204 status=nf90_get_att(ncid, varid,
'missing_value', missing)
205 call netcdf_err(status,
"READING MISSING VALUE")
207 status = nf90_close(ncid)
220 lon_extent = mod((lon_global(
i_src)-lon_global(1))-1+3600,360.)+1.0
222 if (lon_extent < 350.0)
then 224 print*,
"- CALL GridCreateNoPeriDim FOR SOURCE GRID" 225 grid_src = esmf_gridcreatenoperidim(minindex=(/1,1/), &
227 coordsys=esmf_coordsys_sph_deg, &
228 regdecomp=(/1,npets/), &
229 name=
"source_grid", &
230 indexflag=esmf_index_global, rc=rc)
231 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
236 polekindflag(1:2) = esmf_polekind_monopole
238 print*,
"- CALL GridCreate1PeriDim FOR SOURCE GRID" 239 grid_src = esmf_gridcreate1peridim(minindex=(/1,1/), &
241 polekindflag=polekindflag, &
244 coordsys=esmf_coordsys_sph_deg, &
245 regdecomp=(/1,npets/), &
246 name=
"source_grid", &
247 indexflag=esmf_index_global, rc=rc)
248 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
253 print*,
"- CALL FieldCreate FOR SOURCE GRID LANDMASK." 254 mask_field = esmf_fieldcreate(
grid_src, &
255 typekind=esmf_typekind_r4, &
256 staggerloc=esmf_staggerloc_center, &
257 name=
"source grid land mask", &
259 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
262 print*,
"- CALL FieldScatter FOR SOURCE GRID MASK." 263 call esmf_fieldscatter(mask_field, mask_global, rootpet=0, rc=rc)
264 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
267 print*,
"- CALL GridAddItem FOR SOURCE GRID MASK." 269 itemflag=esmf_griditem_mask, &
270 staggerloc=esmf_staggerloc_center, &
272 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
275 print*,
"- CALL GridGetItem FOR SOURCE GRID MASK." 278 itemflag=esmf_griditem_mask, &
279 farrayptr=mask_ptr, &
283 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
286 print*,
"- CALL FieldGet FOR SOURCE GRID LANDMASK." 287 nullify(mask_field_ptr)
288 call esmf_fieldget(mask_field, &
289 farrayptr=mask_field_ptr, &
291 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
294 do j = clb(2), cub(2)
295 do i = clb(1), cub(1)
296 if ( abs(mask_field_ptr(i,j)-missing) < 0.001)
then 304 deallocate(mask_global)
306 print*,
"- CALL FieldDestroy FOR SOURCE GRID LAND MASK." 307 call esmf_fielddestroy(mask_field,rc=rc)
308 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
313 print*,
"- CALL GridAddCoord FOR SOURCE GRID CENTER LOCATION." 315 staggerloc=esmf_staggerloc_center, rc=rc)
316 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
319 print*,
"- CALL GridGetCoord FOR SOURCE GRID CENTER LONGITUDE." 322 staggerloc=esmf_staggerloc_center, &
324 farrayptr=lon_ptr, rc=rc)
325 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
328 print*,
"- CALL GridGetCoord FOR SOURCE GRID CENTER LATITUDE." 331 staggerloc=esmf_staggerloc_center, &
333 farrayptr=lat_ptr, rc=rc)
334 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
337 do j = clb(2), cub(2)
338 lat_ptr(:,j) = lat_global(j)
341 do i = clb(1), cub(1)
342 lon_ptr(i,:) = lon_global(i)
345 print*,
"- CALL GridAddCoord FOR SOURCE GRID CORNER LOCATION." 347 staggerloc=esmf_staggerloc_corner, &
349 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
352 print*,
"- CALL GridGetCoord FOR SOURCE GRID CORNER LONGITUDE." 353 nullify(lon_corner_ptr)
355 staggerloc=esmf_staggerloc_corner, &
357 farrayptr=lon_corner_ptr, &
359 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
362 print*,
"- CALL GridGetCoord FOR SOURCE GRID CORNER LATITUDE." 363 nullify(lat_corner_ptr)
365 staggerloc=esmf_staggerloc_corner, &
367 computationallbound=clb_corner, &
368 computationalubound=cub_corner, &
369 farrayptr=lat_corner_ptr, &
371 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
374 do j = clb_corner(2), cub_corner(2)
375 lat_corner_ptr(:,j) = lat_corner_global(j)
378 do i = clb_corner(1), cub_corner(1)
379 lon_corner_ptr(i,:) = lon_corner_global(i)
382 deallocate(lat_global)
383 deallocate(lon_global)
384 deallocate(lat_corner_global)
385 deallocate(lon_corner_global)
398 print*,
"- CALL GridDestroy FOR SOURCE GRID." 399 call esmf_griddestroy(
grid_src,rc=rc)
integer, public j_src
j dimension of the source grid.
character(len=50), dimension(:), allocatable, public field_names
Names of fields to be processed.
Read grid specs, date information and land/sea mask for the source data that will be interpolated to ...
integer, public num_time_recs
Number of time records.
subroutine, public define_source_grid(localpet, npets, input_file)
Defines esmf grid object for source grid.
subroutine, public source_grid_cleanup
Free up memory associated with this module.
integer, dimension(:), allocatable, public day_of_rec
Day of each time record with respect to Jan 1.
integer, public i_src
i dimension of the source grid.
integer, public num_records
Number of fields times time records.
subroutine, public error_handler(string, rc)
Handle errors.
integer, public num_fields
Number of fields in the file.
subroutine, public netcdf_err(err, string)
Handle netCDF error codes.
type(esmf_grid), public grid_src
ESMF grid object for the source grid.
character(len=75), public source
Original source of the data.