16 REAL,
ALLOCATABLE :: inland(:,:,:)
17 REAL,
ALLOCATABLE :: land_frac(:,:,:)
18 INTEGER :: i_ctr, j_ctr, tile_beg, tile_end
19 INTEGER :: cs_res, x_res, y_res
20 CHARACTER(len=32) :: arg
24 CHARACTER(len=1) :: reg
26 LOGICAL,
ALLOCATABLE :: done(:,:,:)
29 IF (iargc() /= 3 .AND. iargc() /= 4)
THEN 31 print*, trim(arg),
' [cres(48,96, ...)][nonland cutoff][max recursive depth][regional(r),global(g)]' 36 READ(arg,*,iostat=stat) cs_res
38 READ(arg,*,iostat=stat) cutoff
40 READ(arg,*,iostat=stat) max_rd
44 tile_beg = 1; tile_end = 6
61 CALL idx_init_reg(x_res, y_res)
80 INTEGER,
INTENT(IN) :: cs_res
82 ALLOCATE(done(cs_res,cs_res,6))
83 ALLOCATE(inland(cs_res,cs_res,6))
86 i_ctr = cs_res/2; j_ctr = cs_res/2
100 INTEGER,
INTENT(IN) :: cs_res
101 INTEGER :: i_seed, j_seed
103 ALLOCATE(done(x_res,y_res,1))
104 ALLOCATE(inland(x_res,y_res,1))
110 i_seed = 1; j_seed = y_res/2
113 i_seed = x_res; j_seed = y_res/2
116 i_seed = x_res/3; j_seed = 1
132 INTEGER,
INTENT(IN) :: i, j, t, rd
139 IF (land_frac(i,j,t) <= 0.15)
THEN 145 IF (nrd > max_rd)
RETURN 147 IF (done(i,j,t))
RETURN 148 IF (land_frac(i,j,t) < cutoff)
THEN 151 CALL neighbors(t, i, j, nbs)
169 INTEGER,
INTENT(IN) :: i, j, t, rd
176 IF (land_frac(i,j,t) <= 0.15)
THEN 182 IF (nrd > max_rd)
RETURN 184 IF (done(i,j,t))
RETURN 185 IF (land_frac(i,j,t) < cutoff)
THEN 188 CALL neighbors_reg(i, j, nbs)
204 INTEGER,
INTENT(IN) :: cs_res
206 INTEGER :: tile_sz, tile_num
207 INTEGER :: stat, ncid, varid
208 INTEGER :: land_frac_id, slmsk_id, geolon_id, geolat_id
209 CHARACTER(len=256) :: filename,string
210 CHARACTER(len=1) :: ich
211 CHARACTER(len=4) res_ch
212 CHARACTER(len=8) dimname
215 REAL,
ALLOCATABLE :: var_tmp(:,:)
217 ALLOCATE(var_tmp(cs_res,cs_res))
218 ALLOCATE(land_frac(cs_res,cs_res,6))
220 WRITE(res_ch,
'(I4)') cs_res
221 DO tile_num = tile_beg, tile_end
222 WRITE(ich,
'(I1)') tile_num
223 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc" 224 print *,
'Read, update, and write ',trim(filename)
225 stat = nf90_open(filename, nf90_nowrite, ncid)
226 CALL nc_opchk(stat,
"nf90_open oro_data.nc")
229 stat = nf90_inq_varid(ncid,
"land_frac", land_frac_id)
230 CALL nc_opchk(stat,
"nf90_inq_varid: land_frac")
231 stat = nf90_get_var(ncid, land_frac_id, var_tmp, &
232 start = (/ 1, 1 /), count = (/ cs_res, cs_res /) )
233 CALL nc_opchk(stat,
"nf90_get_var: land_frac")
234 land_frac(:,:,tile_num) = var_tmp(:,:)
235 stat = nf90_close(ncid)
236 CALL nc_opchk(stat,
"nf90_close oro_data.nc")
250 INTEGER,
INTENT(IN) :: cs_res
253 INTEGER :: stat, ncid, x_dimid, y_dimid, varid
254 INTEGER :: land_frac_id, slmsk_id, geolon_id, geolat_id
255 CHARACTER(len=256) :: filename,string
256 CHARACTER(len=1) :: ich
257 CHARACTER(len=4) res_ch
258 CHARACTER(len=8) dimname
261 REAL,
ALLOCATABLE :: var_tmp(:,:)
263 WRITE(res_ch,
'(I4)') cs_res
265 WRITE(ich,
'(I1)') tile_num
266 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc" 267 print *,
'Read, update, and write ',trim(filename)
268 stat = nf90_open(filename, nf90_nowrite, ncid)
269 CALL nc_opchk(stat,
"nf90_open oro_data.nc")
270 stat = nf90_inq_dimid(ncid,
"lon", x_dimid)
271 CALL nc_opchk(stat,
"nf90_inq_dim: x")
272 stat = nf90_inq_dimid(ncid,
"lat", y_dimid)
273 CALL nc_opchk(stat,
"nf90_inq_dim: y")
274 stat = nf90_inquire_dimension(ncid,x_dimid,dimname,len=x_res)
275 CALL nc_opchk(stat,
'nf90_inquire_dimension: lon')
276 stat = nf90_inquire_dimension(ncid,y_dimid,dimname,len=y_res)
277 CALL nc_opchk(stat,
'nf90_inquire_dimension: lon')
280 ALLOCATE(var_tmp(x_res,y_res))
281 ALLOCATE(land_frac(x_res,y_res,1))
282 stat = nf90_inq_varid(ncid,
"land_frac", land_frac_id)
283 CALL nc_opchk(stat,
"nf90_inq_varid: land_frac")
284 stat = nf90_get_var(ncid, land_frac_id, var_tmp, &
285 start = (/ 1, 1 /), count = (/ x_res, y_res /) )
286 CALL nc_opchk(stat,
"nf90_get_var: land_frac")
287 land_frac(:,:,1) = var_tmp(:,:)
288 stat = nf90_close(ncid)
289 CALL nc_opchk(stat,
"nf90_close oro_data.nc")
302 INTEGER,
INTENT(IN) :: cs_res
304 CHARACTER(len=256) :: filename
305 CHARACTER(len=1) :: ich
306 CHARACTER(len=4) res_ch
309 INTEGER :: stat, ncid, x_dimid, y_dimid, inland_id, dimids(2)
310 REAL,
ALLOCATABLE :: var_tmp(:,:)
312 ALLOCATE(var_tmp(cs_res,cs_res))
314 WRITE(res_ch,
'(I4)') cs_res
315 DO tile_num = tile_beg, tile_end
316 WRITE(ich,
'(I1)') tile_num
317 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc" 318 print *,
'write inland to ',trim(filename)
319 stat = nf90_open(filename, nf90_write, ncid)
320 CALL nc_opchk(stat,
"nf90_open oro_data.nc")
321 stat = nf90_inq_dimid(ncid,
"lon", x_dimid)
322 CALL nc_opchk(stat,
"nf90_inq_dim: x")
323 stat = nf90_inq_dimid(ncid,
"lat", y_dimid)
324 CALL nc_opchk(stat,
"nf90_inq_dim: y")
327 dimids = (/ x_dimid, y_dimid /)
330 stat = nf90_inq_varid(ncid,
"inland",inland_id)
331 IF (stat /= nf90_noerr)
THEN 332 stat = nf90_redef(ncid)
334 stat = nf90_def_var(ncid,
"inland",nf90_float,dimids,inland_id)
335 CALL nc_opchk(stat,
"nf90_def_var: inland")
336 stat = nf90_put_att(ncid, inland_id,
'coordinates',
'geolon geolat')
337 CALL nc_opchk(stat,
"nf90_put_att: inland:coordinates")
338 stat = nf90_put_att(ncid, inland_id,
'description', &
339 'inland = 1 indicates grid cells away from coast')
340 CALL nc_opchk(stat,
"nf90_put_att: inland:description")
341 stat = nf90_enddef(ncid)
345 var_tmp(:,:) = inland(:,:,tile_num)
346 stat = nf90_put_var(ncid, inland_id, var_tmp, &
347 start = (/ 1, 1 /), count = (/ cs_res, cs_res /) )
348 CALL nc_opchk(stat,
"nf90_put_var: inland")
350 stat = nf90_close(ncid)
351 CALL nc_opchk(stat,
"nf90_close oro_data.nc")
364 INTEGER,
INTENT(IN) :: cs_res
366 CHARACTER(len=256) :: filename
367 CHARACTER(len=1) :: ich
368 CHARACTER(len=4) res_ch
371 INTEGER :: stat, ncid, x_dimid, y_dimid, inland_id, dimids(2)
372 REAL,
ALLOCATABLE :: var_tmp(:,:)
373 CHARACTER(len=8) dimname
375 ALLOCATE(var_tmp(x_res,y_res))
377 WRITE(res_ch,
'(I4)') cs_res
379 WRITE(ich,
'(I1)') tile_num
380 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc" 381 print*,
'write inland to ',trim(filename)
382 stat = nf90_open(filename, nf90_write, ncid)
383 CALL nc_opchk(stat,
"nf90_open oro_data.nc")
384 stat = nf90_inq_dimid(ncid,
"lon", x_dimid)
385 CALL nc_opchk(stat,
"nf90_inq_dim: x")
386 stat = nf90_inq_dimid(ncid,
"lat", y_dimid)
387 CALL nc_opchk(stat,
"nf90_inq_dim: y")
388 stat = nf90_inquire_dimension(ncid,x_dimid,dimname,len=x_res)
389 CALL nc_opchk(stat,
'nf90_inquire_dimension: lon')
390 stat = nf90_inquire_dimension(ncid,y_dimid,dimname,len=y_res)
391 CALL nc_opchk(stat,
'nf90_inquire_dimension: lon')
394 dimids = (/ x_dimid, y_dimid /)
397 stat = nf90_inq_varid(ncid,
"inland",inland_id)
398 IF (stat /= nf90_noerr)
THEN 399 stat = nf90_redef(ncid)
401 stat = nf90_def_var(ncid,
"inland",nf90_float,dimids,inland_id)
402 CALL nc_opchk(stat,
"nf90_def_var: inland")
403 stat = nf90_put_att(ncid, inland_id,
'coordinates',
'geolon geolat')
404 CALL nc_opchk(stat,
"nf90_put_att: inland:coordinates")
405 stat = nf90_put_att(ncid, inland_id,
'description', &
406 'inland = 1 indicates grid cells away from coast')
407 CALL nc_opchk(stat,
"nf90_put_att: inland:description")
408 stat = nf90_enddef(ncid)
412 var_tmp(:,:) = inland(:,:,1)
413 stat = nf90_put_var(ncid, inland_id, var_tmp, &
414 start = (/ 1, 1 /), count = (/ x_res, y_res /) )
415 CALL nc_opchk(stat,
"nf90_put_var: inland")
417 stat = nf90_close(ncid)
418 CALL nc_opchk(stat,
"nf90_close oro_data.nc")
427 DEALLOCATE(inland, land_frac)
441 CHARACTER(len=*) opname
445 msg = trim(opname) //
' Error, status code and message:' 446 print*,trim(msg), stat, nf90_strerror(stat)
recursive subroutine mark_regional_inland_rec_d(i, j, t, rd)
Recursively walk through neighbors marking inland points for regional grid.
Neighboring cell descriptor.
subroutine mark_inland_reg(cs_res)
Create inland mask for regional grid.
subroutine read_orog(cs_res)
Read in orography (land fraction) data.
subroutine free_mem()
Deallocate module arrays.
recursive subroutine mark_global_inland_rec_d(i, j, t, rd)
Recursively walk through neighbors marking inland points for global grid.
subroutine write_inland(cs_res)
Write inland back to the orography data files for global grid.
subroutine nc_opchk(stat, opname)
Check NetCDF return code and print error message.
program inland_mask
This program creates the inland mask and writes it to the orography data files.
subroutine write_inland_reg(cs_res)
Write inland back to the orography data files for regional grid.
subroutine read_orog_reg(cs_res)
Read in orography (land fraction) data for regional grid.
subroutine mark_global_inland(cs_res)
Create inland mask for global grid.