23 character(len=128) :: outfile
24 character(len=20) :: title
25 character(len=5) :: idim_ch, jdim_ch, jdimp_ch
26 character(len=6) :: cres
28 integer :: header_buffer_val = 16384
29 integer :: fsize=65536, inital = 0
30 integer :: error, ncid
31 integer :: i, j, idim, jdim, ijdim
32 integer :: jdimp, num_ch
33 integer :: dim_size, dim_corners, dim_rank
34 integer :: id_dims, id_center_lat, id_center_lon
35 integer :: id_imask, id_corner_lat, id_corner_lon
36 integer :: num_corners = 4
38 integer(kind=4),
allocatable :: mask(:)
40 real(kind=8) :: corner_lon_src
41 real(kind=8) :: dx_src, lat_edge
42 real(kind=8),
allocatable :: lats(:,:), lons(:,:), dum1d(:)
43 real(kind=8),
allocatable :: dum2d(:,:), latsp(:,:), lonsp(:,:)
44 real(kind=8),
allocatable :: lats_corner(:,:,:), lons_corner(:,:,:)
45 real(kind=8),
allocatable :: latsp_corner(:,:,:), lonsp_corner(:,:,:)
46 real(kind=8),
allocatable :: slat(:), wlat(:)
52 select case (trim(cres))
95 case (
"c1152",
"C1152")
102 case (
"c3072",
"C3072")
110 print*,
'- Resolution not supported ', trim(cres)
115 dx_src = 360.0 / float(idim)
121 call splat(4, jdim, slat, wlat)
123 allocate(lats(idim,jdim))
124 allocate(lats_corner(num_corners,idim,jdim))
125 allocate(lons(idim,jdim))
126 allocate(lons_corner(num_corners,idim,jdim))
129 lats(:,j) = 90.0 - (acos(slat(j))* 180.0 / (4.*atan(1.)))
132 deallocate(slat, wlat)
148 lats_corner(1,:,1) = 90.0
149 lats_corner(2,:,1) = 90.0
151 lats_corner(3,:,jdim) = -90.0
152 lats_corner(4,:,jdim) = -90.0
155 lat_edge = (lats(1,j) + lats(1,j+1)) / 2.0
156 lats_corner(3,:,j) = lat_edge
157 lats_corner(4,:,j) = lat_edge
158 lats_corner(1,:,j+1) = lat_edge
159 lats_corner(2,:,j+1) = lat_edge
163 lons(i,:) = corner_lon_src + float(i-1)*dx_src
164 lons_corner(1,i,:) = lons(i,:) + (dx_src*0.5)
165 lons_corner(2,i,:) = lons(i,:) - (dx_src*0.5)
166 lons_corner(3,i,:) = lons(i,:) - (dx_src*0.5)
167 lons_corner(4,i,:) = lons(i,:) + (dx_src*0.5)
172 print*,
'center ',lats(i,j),lons(i,j)
173 print*,
'corner 1 ',lats_corner(1,i,j),lons_corner(1,i,j)
174 print*,
'corner 2 ',lats_corner(2,i,j),lons_corner(2,i,j)
175 print*,
'corner 3 ',lats_corner(3,i,j),lons_corner(3,i,j)
176 print*,
'corner 4 ',lats_corner(4,i,j),lons_corner(4,i,j)
180 print*,
'center ',lats(i,j),lons(i,j)
181 print*,
'corner 1 ',lats_corner(1,i,j),lons_corner(1,i,j)
182 print*,
'corner 2 ',lats_corner(2,i,j),lons_corner(2,i,j)
183 print*,
'corner 3 ',lats_corner(3,i,j),lons_corner(3,i,j)
184 print*,
'corner 4 ',lats_corner(4,i,j),lons_corner(4,i,j)
188 print*,
'center ',lats(i,j),lons(i,j)
189 print*,
'corner 1 ',lats_corner(1,i,j),lons_corner(1,i,j)
190 print*,
'corner 2 ',lats_corner(2,i,j),lons_corner(2,i,j)
191 print*,
'corner 3 ',lats_corner(3,i,j),lons_corner(3,i,j)
192 print*,
'corner 4 ',lats_corner(4,i,j),lons_corner(4,i,j)
196 print*,
'center ',lats(i,j),lons(i,j)
197 print*,
'corner 1 ',lats_corner(1,i,j),lons_corner(1,i,j)
198 print*,
'corner 2 ',lats_corner(2,i,j),lons_corner(2,i,j)
199 print*,
'corner 3 ',lats_corner(3,i,j),lons_corner(3,i,j)
200 print*,
'corner 4 ',lats_corner(4,i,j),lons_corner(4,i,j)
202 allocate(mask(ijdim))
208 outfile =
"./gaussian." // trim(idim_ch) //
"." // trim(jdim_ch) //
".nc"
210 title =
"gaussian." // trim(idim_ch) //
"." // trim(jdim_ch)
213 error = nf__create(outfile, ior(nf_netcdf4,nf_classic_model), inital, fsize, ncid)
214 print*,
'error after open ', error
217 error = nf_def_dim(ncid,
'grid_size', ijdim, dim_size)
218 error = nf_def_dim(ncid,
'grid_corners', num_corners, dim_corners)
219 error = nf_def_dim(ncid,
'grid_rank', rank, dim_rank)
222 error = nf_def_var(ncid,
'grid_dims', nf_int, 1, (/dim_rank/), id_dims)
223 error = nf_def_var(ncid,
'grid_center_lat', nf_double, 1, (/dim_size/), id_center_lat)
224 error = nf_put_att_text(ncid, id_center_lat,
"units", 7,
"degrees")
225 error = nf_def_var(ncid,
'grid_center_lon', nf_double, 1, (/dim_size/), id_center_lon)
226 error = nf_put_att_text(ncid, id_center_lon,
"units", 7,
"degrees")
227 error = nf_def_var(ncid,
'grid_imask', nf_int, 1, (/dim_size/), id_imask)
228 error = nf_put_att_text(ncid, id_imask,
"units", 8,
"unitless")
229 error = nf_def_var(ncid,
'grid_corner_lat', nf_double, 2, (/dim_corners,dim_size/), id_corner_lat)
230 error = nf_put_att_text(ncid, id_corner_lat,
"units", 7,
"degrees")
231 error = nf_def_var(ncid,
'grid_corner_lon', nf_double, 2, (/dim_corners,dim_size/), id_corner_lon)
232 error = nf_put_att_text(ncid, id_corner_lon,
"units", 7,
"degrees")
233 num_ch = len_trim(title)
234 error = nf_put_att_text(ncid, nf_global,
"title", num_ch, trim(title))
235 error = nf__enddef(ncid, header_buffer_val,4,0,4)
238 error = nf_put_var_int( ncid, id_dims, (/idim,jdim/))
240 allocate(dum1d(ijdim))
241 dum1d = reshape(lats, (/ijdim/))
242 error = nf_put_var_double( ncid, id_center_lat, dum1d)
243 dum1d = reshape(lons, (/ijdim/))
244 error = nf_put_var_double( ncid, id_center_lon, dum1d)
247 error = nf_put_var_int( ncid, id_imask, mask)
250 allocate(dum2d(num_corners,ijdim))
251 dum2d = reshape(lats_corner, (/num_corners,ijdim/))
252 error = nf_put_var_double( ncid, id_corner_lat, dum2d)
254 dum2d = reshape(lons_corner, (/num_corners,ijdim/))
255 error = nf_put_var_double( ncid, id_corner_lon, dum2d)
258 error = nf_close(ncid)
265 outfile =
"./gaussian." // trim(idim_ch) //
"." // trim(jdimp_ch) //
".nc"
267 title =
"gaussian." // trim(idim_ch) //
"." // trim(jdimp_ch)
271 allocate(latsp(idim,jdimp))
272 allocate(lonsp(idim,jdimp))
275 latsp(:,j) = lats(:,j-1)
276 lonsp(:,j) = lons(:,j-1)
282 latsp(:,jdimp) = -90.0_8
283 lonsp(:,jdimp) = 0.0_8
285 deallocate(lats, lons)
287 allocate(latsp_corner(num_corners,idim,jdimp))
288 allocate(lonsp_corner(num_corners,idim,jdimp))
290 latsp_corner(:,:,1) = 89.5_8
291 latsp_corner(:,:,jdimp) = -89.5_8
293 lonsp_corner(1,:,1) = 0.0_8
294 lonsp_corner(2,:,1) = 90.0_8
295 lonsp_corner(3,:,1) = 180.0_8
296 lonsp_corner(4,:,1) = 270.0_8
298 lonsp_corner(1,:,jdimp) = 0.0_8
299 lonsp_corner(2,:,jdimp) = 90.0_8
300 lonsp_corner(3,:,jdimp) = 180.0_8
301 lonsp_corner(4,:,jdimp) = 270.0_8
304 latsp_corner(:,:,j) = lats_corner(:,:,j-1)
305 lonsp_corner(:,:,j) = lons_corner(:,:,j-1)
308 deallocate(lats_corner, lons_corner)
311 error = nf__create(outfile, ior(nf_netcdf4,nf_classic_model), inital, fsize, ncid)
312 print*,
'error after open ', error
315 error = nf_def_dim(ncid,
'grid_size', ijdim, dim_size)
316 error = nf_def_dim(ncid,
'grid_corners', num_corners, dim_corners)
317 error = nf_def_dim(ncid,
'grid_rank', rank, dim_rank)
320 error = nf_def_var(ncid,
'grid_dims', nf_int, 1, (/dim_rank/), id_dims)
321 error = nf_def_var(ncid,
'grid_center_lat', nf_double, 1, (/dim_size/), id_center_lat)
322 error = nf_put_att_text(ncid, id_center_lat,
"units", 7,
"degrees")
323 error = nf_def_var(ncid,
'grid_center_lon', nf_double, 1, (/dim_size/), id_center_lon)
324 error = nf_put_att_text(ncid, id_center_lon,
"units", 7,
"degrees")
325 error = nf_def_var(ncid,
'grid_imask', nf_int, 1, (/dim_size/), id_imask)
326 error = nf_put_att_text(ncid, id_imask,
"units", 8,
"unitless")
327 error = nf_def_var(ncid,
'grid_corner_lat', nf_double, 2, (/dim_corners,dim_size/), id_corner_lat)
328 error = nf_put_att_text(ncid, id_corner_lat,
"units", 7,
"degrees")
329 error = nf_def_var(ncid,
'grid_corner_lon', nf_double, 2, (/dim_corners,dim_size/), id_corner_lon)
330 error = nf_put_att_text(ncid, id_corner_lon,
"units", 7,
"degrees")
331 num_ch = len_trim(title)
332 error = nf_put_att_text(ncid, nf_global,
"title", num_ch, trim(title))
333 error = nf__enddef(ncid, header_buffer_val,4,0,4)
336 error = nf_put_var_int( ncid, id_dims, (/idim,jdimp/))
338 allocate(dum1d(ijdim))
339 dum1d = reshape(latsp, (/ijdim/))
340 error = nf_put_var_double( ncid, id_center_lat, dum1d)
341 dum1d = reshape(lonsp, (/ijdim/))
342 error = nf_put_var_double( ncid, id_center_lon, dum1d)
345 allocate(mask(ijdim))
347 error = nf_put_var_int( ncid, id_imask, mask)
350 allocate(dum2d(num_corners,ijdim))
351 dum2d = reshape(latsp_corner, (/num_corners,ijdim/))
352 print*,
'lat corner check ',maxval(dum2d),minval(dum2d)
353 error = nf_put_var_double( ncid, id_corner_lat, dum2d)
354 deallocate(latsp_corner)
356 dum2d = reshape(lonsp_corner, (/num_corners,ijdim/))
357 error = nf_put_var_double( ncid, id_corner_lon, dum2d)
358 deallocate(dum2d, lonsp_corner)
360 error = nf_close(ncid)
program scrip
Create "scrip" files that describes a gaussian grid.