16 REAL,
ALLOCATABLE :: inland(:,:,:)
17 REAL,
ALLOCATABLE :: land_frac(:,:,:)
18 INTEGER :: 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
80 INTEGER,
INTENT(IN) :: cs_res
81 INTEGER :: i_seed, j_seed
83 ALLOCATE(done(cs_res,cs_res,6))
84 ALLOCATE(inland(cs_res,cs_res,6))
88 i_seed = cs_res/2; j_seed = cs_res/2
92 i_seed =
REAL(cs_res)/32.0*3; j_seed = i_seed
105 INTEGER,
INTENT(IN) :: cs_res
106 INTEGER :: i_seed, j_seed
109 ALLOCATE(done(x_res,y_res,1))
110 ALLOCATE(inland(x_res,y_res,1))
116 i_seed = 1; j_seed = y_res/2
119 i_seed = x_res; j_seed = y_res/2
122 i_seed = x_res/3; j_seed = 1
131 DO i = x_res/2, x_res
162 INTEGER,
INTENT(IN) :: i, j, t, rd
169 IF (land_frac(i,j,t) <= 0.15)
THEN
175 IF (nrd > max_rd)
RETURN
177 IF (done(i,j,t))
RETURN
178 IF (land_frac(i,j,t) < cutoff)
THEN
199 INTEGER,
INTENT(IN) :: i, j, t, rd
206 IF (land_frac(i,j,t) <= 0.15)
THEN
212 IF (nrd > max_rd)
RETURN
214 IF (done(i,j,t))
RETURN
215 IF (land_frac(i,j,t) < cutoff)
THEN
234 INTEGER,
INTENT(IN) :: cs_res
236 INTEGER :: tile_sz, tile_num
237 INTEGER :: stat, ncid, varid
238 INTEGER :: land_frac_id, slmsk_id, geolon_id, geolat_id
239 CHARACTER(len=256) :: filename,string
240 CHARACTER(len=1) :: ich
241 CHARACTER(len=4) res_ch
242 CHARACTER(len=8) dimname
245 REAL,
ALLOCATABLE :: var_tmp(:,:)
247 ALLOCATE(var_tmp(cs_res,cs_res))
248 ALLOCATE(land_frac(cs_res,cs_res,6))
250 WRITE(res_ch,
'(I4)') cs_res
251 DO tile_num = tile_beg, tile_end
252 WRITE(ich,
'(I1)') tile_num
253 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc"
254 print *,
'Read, update, and write ',trim(filename)
255 stat = nf90_open(filename, nf90_nowrite, ncid)
256 CALL
nc_opchk(stat,
"nf90_open oro_data.nc")
259 stat = nf90_inq_varid(ncid,
"land_frac", land_frac_id)
260 CALL
nc_opchk(stat,
"nf90_inq_varid: land_frac")
261 stat = nf90_get_var(ncid, land_frac_id, var_tmp, &
262 start = (/ 1, 1 /), count = (/ cs_res, cs_res /) )
263 CALL
nc_opchk(stat,
"nf90_get_var: land_frac")
264 land_frac(:,:,tile_num) = var_tmp(:,:)
265 stat = nf90_close(ncid)
266 CALL
nc_opchk(stat,
"nf90_close oro_data.nc")
280 INTEGER,
INTENT(IN) :: cs_res
283 INTEGER :: stat, ncid, x_dimid, y_dimid, varid
284 INTEGER :: land_frac_id, slmsk_id, geolon_id, geolat_id
285 CHARACTER(len=256) :: filename,string
286 CHARACTER(len=1) :: ich
287 CHARACTER(len=4) res_ch
288 CHARACTER(len=8) dimname
291 REAL,
ALLOCATABLE :: var_tmp(:,:)
293 WRITE(res_ch,
'(I4)') cs_res
295 WRITE(ich,
'(I1)') tile_num
296 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc"
297 print *,
'Read, update, and write ',trim(filename)
298 stat = nf90_open(filename, nf90_nowrite, ncid)
299 CALL
nc_opchk(stat,
"nf90_open oro_data.nc")
300 stat = nf90_inq_dimid(ncid,
"lon", x_dimid)
301 CALL
nc_opchk(stat,
"nf90_inq_dim: x")
302 stat = nf90_inq_dimid(ncid,
"lat", y_dimid)
303 CALL
nc_opchk(stat,
"nf90_inq_dim: y")
304 stat = nf90_inquire_dimension(ncid,x_dimid,dimname,len=x_res)
305 CALL
nc_opchk(stat,
'nf90_inquire_dimension: lon')
306 stat = nf90_inquire_dimension(ncid,y_dimid,dimname,len=y_res)
307 CALL
nc_opchk(stat,
'nf90_inquire_dimension: lon')
310 ALLOCATE(var_tmp(x_res,y_res))
311 ALLOCATE(land_frac(x_res,y_res,1))
312 stat = nf90_inq_varid(ncid,
"land_frac", land_frac_id)
313 CALL
nc_opchk(stat,
"nf90_inq_varid: land_frac")
314 stat = nf90_get_var(ncid, land_frac_id, var_tmp, &
315 start = (/ 1, 1 /), count = (/ x_res, y_res /) )
316 CALL
nc_opchk(stat,
"nf90_get_var: land_frac")
317 land_frac(:,:,1) = var_tmp(:,:)
318 stat = nf90_close(ncid)
319 CALL
nc_opchk(stat,
"nf90_close oro_data.nc")
332 INTEGER,
INTENT(IN) :: cs_res
334 CHARACTER(len=256) :: filename
335 CHARACTER(len=1) :: ich
336 CHARACTER(len=4) res_ch
339 INTEGER :: stat, ncid, x_dimid, y_dimid, inland_id, dimids(2)
340 REAL,
ALLOCATABLE :: var_tmp(:,:)
342 ALLOCATE(var_tmp(cs_res,cs_res))
344 WRITE(res_ch,
'(I4)') cs_res
345 DO tile_num = tile_beg, tile_end
346 WRITE(ich,
'(I1)') tile_num
347 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc"
348 print *,
'write inland to ',trim(filename)
349 stat = nf90_open(filename, nf90_write, ncid)
350 CALL
nc_opchk(stat,
"nf90_open oro_data.nc")
351 stat = nf90_inq_dimid(ncid,
"lon", x_dimid)
352 CALL
nc_opchk(stat,
"nf90_inq_dim: x")
353 stat = nf90_inq_dimid(ncid,
"lat", y_dimid)
354 CALL
nc_opchk(stat,
"nf90_inq_dim: y")
357 dimids = (/ x_dimid, y_dimid /)
360 stat = nf90_inq_varid(ncid,
"inland",inland_id)
361 IF (stat /= nf90_noerr)
THEN
362 stat = nf90_redef(ncid)
364 stat = nf90_def_var(ncid,
"inland",nf90_float,dimids,inland_id)
365 CALL
nc_opchk(stat,
"nf90_def_var: inland")
366 stat = nf90_put_att(ncid, inland_id,
'coordinates',
'geolon geolat')
367 CALL
nc_opchk(stat,
"nf90_put_att: inland:coordinates")
368 stat = nf90_put_att(ncid, inland_id,
'description', &
369 'inland = 1 indicates grid cells away from coast')
370 CALL
nc_opchk(stat,
"nf90_put_att: inland:description")
371 stat = nf90_enddef(ncid)
375 var_tmp(:,:) = inland(:,:,tile_num)
376 stat = nf90_put_var(ncid, inland_id, var_tmp, &
377 start = (/ 1, 1 /), count = (/ cs_res, cs_res /) )
378 CALL
nc_opchk(stat,
"nf90_put_var: inland")
380 stat = nf90_close(ncid)
381 CALL
nc_opchk(stat,
"nf90_close oro_data.nc")
394 INTEGER,
INTENT(IN) :: cs_res
396 CHARACTER(len=256) :: filename
397 CHARACTER(len=1) :: ich
398 CHARACTER(len=4) res_ch
401 INTEGER :: stat, ncid, x_dimid, y_dimid, inland_id, dimids(2)
402 REAL,
ALLOCATABLE :: var_tmp(:,:)
403 CHARACTER(len=8) dimname
405 ALLOCATE(var_tmp(x_res,y_res))
407 WRITE(res_ch,
'(I4)') cs_res
409 WRITE(ich,
'(I1)') tile_num
410 filename =
"oro.C" // trim(adjustl(res_ch)) //
".tile" // ich //
".nc"
411 print*,
'write inland to ',trim(filename)
412 stat = nf90_open(filename, nf90_write, ncid)
413 CALL
nc_opchk(stat,
"nf90_open oro_data.nc")
414 stat = nf90_inq_dimid(ncid,
"lon", x_dimid)
415 CALL
nc_opchk(stat,
"nf90_inq_dim: x")
416 stat = nf90_inq_dimid(ncid,
"lat", y_dimid)
417 CALL
nc_opchk(stat,
"nf90_inq_dim: y")
418 stat = nf90_inquire_dimension(ncid,x_dimid,dimname,len=x_res)
419 CALL
nc_opchk(stat,
'nf90_inquire_dimension: lon')
420 stat = nf90_inquire_dimension(ncid,y_dimid,dimname,len=y_res)
421 CALL
nc_opchk(stat,
'nf90_inquire_dimension: lon')
424 dimids = (/ x_dimid, y_dimid /)
427 stat = nf90_inq_varid(ncid,
"inland",inland_id)
428 IF (stat /= nf90_noerr)
THEN
429 stat = nf90_redef(ncid)
431 stat = nf90_def_var(ncid,
"inland",nf90_float,dimids,inland_id)
432 CALL
nc_opchk(stat,
"nf90_def_var: inland")
433 stat = nf90_put_att(ncid, inland_id,
'coordinates',
'geolon geolat')
434 CALL
nc_opchk(stat,
"nf90_put_att: inland:coordinates")
435 stat = nf90_put_att(ncid, inland_id,
'description', &
436 'inland = 1 indicates grid cells away from coast')
437 CALL
nc_opchk(stat,
"nf90_put_att: inland:description")
438 stat = nf90_enddef(ncid)
442 var_tmp(:,:) = inland(:,:,1)
443 stat = nf90_put_var(ncid, inland_id, var_tmp, &
444 start = (/ 1, 1 /), count = (/ x_res, y_res /) )
445 CALL
nc_opchk(stat,
"nf90_put_var: inland")
447 stat = nf90_close(ncid)
448 CALL
nc_opchk(stat,
"nf90_close oro_data.nc")
457 DEALLOCATE(inland, land_frac)
471 CHARACTER(len=*) opname
475 msg = trim(opname) //
' Error, status code and message:'
476 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.
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.
subroutine neighbors(tile, i, j, nb)
Get neighbors of cell 'c' at (tile, i, j) for global grid.
Neighboring cell descriptor.
recursive subroutine mark_global_inland_rec_d(i, j, t, rd)
Recursively walk through neighbors marking inland points for global grid.
subroutine idx_init(cres_in)
Initialize inter-panel neighbor index for global grid.
subroutine write_inland(cs_res)
Write inland back to the orography data files for global grid.
subroutine neighbors_reg(i, j, nb)
Get neighbors of cell 'c' at (tile, i, j) for regional 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.
subroutine idx_init_reg(xres_in, yres_in)
Initialize resolution module variables for regional grid.