20 integer :: i_thomp_mp_climo
22 integer :: j_thomp_mp_climo
24 integer,
public :: lev_thomp_mp_climo
27 type(esmf_grid
) :: thomp_mp_climo_grid
30 type(esmf_field
),
public :: qnifa_climo_input_grid
33 type(esmf_field
),
public :: qnwfa_climo_input_grid
36 type(esmf_field
),
public :: thomp_pres_climo_input_grid
53 integer :: error, ncid, rc, clb(2), cub(2)
54 integer :: i, j, localpet, npets, id_var
55 integer :: jda(8), jdow, jdoy, jday, id_dim
56 integer :: mm, mmm, mmp, mon1, mon2
58 real(esmf_kind_r8),
allocatable :: dummy3d(:,:,:)
59 real(esmf_kind_r8),
allocatable :: dummy3d_mon1(:,:,:)
60 real(esmf_kind_r8),
allocatable :: dummy3d_mon2(:,:,:)
61 real(esmf_kind_r8),
pointer :: lat_ptr(:,:), lon_ptr(:,:)
62 real(esmf_kind_r8),
allocatable :: lons(:), lats(:)
63 real :: rjday, dayhf(13), wei1m, wei2m
67 type(esmf_polekind_flag
) :: polekindflag(2)
69 data dayhf/ 15.5, 45.0, 74.5,105.0,135.5,166.0, &
70 196.5,227.5,258.0,288.5,319.0,349.5,380.5/
76 print*,
"- READ THOMP_MP_CLIMO_FILE: ", trim(thomp_mp_climo_file)
77 error=nf90_open(trim(thomp_mp_climo_file),nf90_nowrite,ncid)
78 call
netcdf_err(error,
'opening: '//trim(thomp_mp_climo_file) )
80 error=nf90_inq_dimid(ncid,
'lat', id_dim)
82 error=nf90_inquire_dimension(ncid,id_dim,len=j_thomp_mp_climo)
85 error=nf90_inq_dimid(ncid,
'lon', id_dim)
87 error=nf90_inquire_dimension(ncid,id_dim,len=i_thomp_mp_climo)
90 error=nf90_inq_dimid(ncid,
'plev', id_dim)
92 error=nf90_inquire_dimension(ncid,id_dim,len=lev_thomp_mp_climo)
95 allocate(lons(i_thomp_mp_climo))
96 allocate(lats(j_thomp_mp_climo))
97 error=nf90_inq_varid(ncid,
'lon', id_var)
98 call
netcdf_err(error,
'reading lon field id' )
99 error=nf90_get_var(ncid, id_var, lons)
100 call
netcdf_err(error,
'reading grid longitude' )
101 error=nf90_inq_varid(ncid,
'lat', id_var)
102 call
netcdf_err(error,
'reading lat field id' )
103 error=nf90_get_var(ncid, id_var, lats)
104 call
netcdf_err(error,
'reading grid latitude' )
110 print*,
"- CALL VMGetGlobal"
111 call esmf_vmgetglobal(vm, rc=rc)
112 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
115 print*,
"- CALL VMGet"
116 call esmf_vmget(vm, localpet=localpet, petcount=npets, rc=rc)
117 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
120 polekindflag(1:2) = esmf_polekind_monopole
122 print*,
"- CALL GridCreate1PeriDim FOR THOMP MP CLIMO GRID."
123 thomp_mp_climo_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
124 maxindex=(/i_thomp_mp_climo,j_thomp_mp_climo/), &
125 polekindflag=polekindflag, &
128 coordsys=esmf_coordsys_sph_deg, &
129 regdecomp=(/1,npets/), &
130 indexflag=esmf_index_global, rc=rc)
131 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
134 print*,
"- CALL GridAddCoord FOR THOMP MP CLIMO GRID."
135 call esmf_gridaddcoord(thomp_mp_climo_grid, &
136 staggerloc=esmf_staggerloc_center, rc=rc)
137 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
144 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
146 call esmf_gridgetcoord(thomp_mp_climo_grid, &
147 staggerloc=esmf_staggerloc_center, &
149 farrayptr=lon_ptr, rc=rc)
150 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
153 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
155 call esmf_gridgetcoord(thomp_mp_climo_grid, &
156 staggerloc=esmf_staggerloc_center, &
158 computationallbound=clb, &
159 computationalubound=cub, &
160 farrayptr=lat_ptr, rc=rc)
161 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
164 do i = clb(1), cub(1)
165 lon_ptr(i,:) = lons(i)
168 do j = clb(2), cub(2)
169 lat_ptr(:,j) = lats(j)
176 print*,
"- CALL FieldCreate FOR QNIFA INPUT CLIMO."
177 qnifa_climo_input_grid = esmf_fieldcreate(thomp_mp_climo_grid, &
178 typekind=esmf_typekind_r8, &
179 staggerloc=esmf_staggerloc_center, &
180 ungriddedlbound=(/1/), &
181 ungriddedubound=(/lev_thomp_mp_climo/), rc=rc)
182 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
185 print*,
"- CALL FieldCreate FOR QNWFA INPUT CLIMO."
186 qnwfa_climo_input_grid = esmf_fieldcreate(thomp_mp_climo_grid, &
187 typekind=esmf_typekind_r8, &
188 staggerloc=esmf_staggerloc_center, &
189 ungriddedlbound=(/1/), &
190 ungriddedubound=(/lev_thomp_mp_climo/), rc=rc)
191 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
194 print*,
"- CALL FieldCreate FOR THOMP PRESS CLIMO."
195 thomp_pres_climo_input_grid = esmf_fieldcreate(thomp_mp_climo_grid, &
196 typekind=esmf_typekind_r8, &
197 staggerloc=esmf_staggerloc_center, &
198 ungriddedlbound=(/1/), &
199 ungriddedubound=(/lev_thomp_mp_climo/), rc=rc)
200 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
210 if (cycle_mon == 2 .and. cycle_day == 29)
then
222 call w3doxdat(jda,jdow,jdoy,jday)
223 rjday = float(jdoy) + float(jda(5)) / 24.
224 if(rjday < dayhf(1)) rjday = rjday + 365.
229 if(rjday >= dayhf(mmm) .and. rjday < dayhf(mmp))
then
236 wei1m = (dayhf(mon2)-rjday)/(dayhf(mon2)-dayhf(mon1))
241 print*,
"- BOUNDING MONTHS AND INTERPOLATION WEIGHTS: ", mon1, wei1m, mon2, wei2m
248 if (localpet == 0)
then
249 allocate(dummy3d(i_thomp_mp_climo, j_thomp_mp_climo, lev_thomp_mp_climo))
251 allocate(dummy3d_mon1(i_thomp_mp_climo, j_thomp_mp_climo, lev_thomp_mp_climo))
253 allocate(dummy3d_mon2(i_thomp_mp_climo, j_thomp_mp_climo, lev_thomp_mp_climo))
256 allocate(dummy3d(0,0,0))
257 allocate(dummy3d_mon1(0,0,0))
258 allocate(dummy3d_mon2(0,0,0))
261 if (localpet == 0)
then
262 print*,
"- READ QNIFA FOR BOUNDING MONTH 1"
263 error=nf90_inq_varid(ncid,
'nifa', id_var)
264 call
netcdf_err(error,
'reading nifa field id' )
265 error=nf90_get_var(ncid, id_var, dummy3d_mon1, start=(/1,1,1,mon1/), &
266 count=(/i_thomp_mp_climo,j_thomp_mp_climo,lev_thomp_mp_climo,1/) )
267 call
netcdf_err(error,
'reading nifa month1 field' )
268 print*,
"- READ QNIFA FOR BOUNDING MONTH 2"
269 error=nf90_get_var(ncid, id_var, dummy3d_mon2, start=(/1,1,1,mon2/), &
270 count=(/i_thomp_mp_climo,j_thomp_mp_climo,lev_thomp_mp_climo,1/) )
271 call
netcdf_err(error,
'reading nifa month2 field' )
272 dummy3d(:,:,:) = wei1m * dummy3d_mon1 + wei2m * dummy3d_mon2
275 print*,
"- CALL FieldScatter FOR qnifa input climo."
276 call esmf_fieldscatter(qnifa_climo_input_grid, dummy3d, rootpet=0, rc=rc)
277 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
280 if (localpet == 0)
then
281 print*,
"- READ QNWFA FOR BOUNDING MONTH 1"
282 error=nf90_inq_varid(ncid,
'nwfa', id_var)
283 call
netcdf_err(error,
'reading nwfa field id' )
284 error=nf90_get_var(ncid, id_var, dummy3d_mon1, start=(/1,1,1,mon1/), &
285 count=(/i_thomp_mp_climo,j_thomp_mp_climo,lev_thomp_mp_climo,1/) )
286 call
netcdf_err(error,
'reading nwfa month1 field' )
287 print*,
"- READ QNWFA FOR BOUNDING MONTH 2"
288 error=nf90_get_var(ncid, id_var, dummy3d_mon2, start=(/1,1,1,mon2/), &
289 count=(/i_thomp_mp_climo,j_thomp_mp_climo,lev_thomp_mp_climo,1/) )
290 call
netcdf_err(error,
'reading nwfa month2 field' )
291 dummy3d(:,:,:) = wei1m * dummy3d_mon1 + wei2m * dummy3d_mon2
294 print*,
"- CALL FieldScatter FOR qnwfa input climo."
295 call esmf_fieldscatter(qnwfa_climo_input_grid, dummy3d, rootpet=0, rc=rc)
296 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
299 if (localpet == 0)
then
300 print*,
"- READ PRESSURE FOR BOUNDING MONTH 1"
301 error=nf90_inq_varid(ncid,
'prs', id_var)
302 call
netcdf_err(error,
'reading prs field id' )
303 error=nf90_get_var(ncid, id_var, dummy3d_mon1, start=(/1,1,1,mon1/), &
304 count=(/i_thomp_mp_climo,j_thomp_mp_climo,lev_thomp_mp_climo,1/) )
305 call
netcdf_err(error,
'reading prs month1 field' )
306 print*,
"- READ PRESSURE FOR BOUNDING MONTH 2"
307 error=nf90_get_var(ncid, id_var, dummy3d_mon2, start=(/1,1,1,mon2/), &
308 count=(/i_thomp_mp_climo,j_thomp_mp_climo,lev_thomp_mp_climo,1/) )
309 call
netcdf_err(error,
'reading prs month2 field' )
310 dummy3d(:,:,:) = wei1m * dummy3d_mon1 + wei2m * dummy3d_mon2
313 print*,
"- CALL FieldScatter FOR thomp press."
314 call esmf_fieldscatter(thomp_pres_climo_input_grid, dummy3d, rootpet=0, rc=rc)
315 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
318 error=nf90_close(ncid)
320 deallocate(lons, lats, dummy3d, dummy3d_mon1, dummy3d_mon2)
333 call esmf_griddestroy(thomp_mp_climo_grid, rc=rc)
334 call esmf_fielddestroy(thomp_pres_climo_input_grid, rc=rc)
335 call esmf_fielddestroy(qnifa_climo_input_grid, rc=rc)
336 call esmf_fielddestroy(qnwfa_climo_input_grid, rc=rc)
subroutine, public cleanup_thomp_mp_climo_input_data
Free up memory associated with this module.
Module to read the Thompson climatological MP data file and set up the associated esmf field and grid...
subroutine netcdf_err(err, string)
Error handler for netcdf.
subroutine, public read_thomp_mp_climo_data
Read Thompson climatological MP data file and time interpolate data to current cycle time...
subroutine error_handler(string, rc)
General error handler.
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...