22 integer,
parameter :: dp = kind(1.0d0)
23 real(dp),
parameter :: pi_geom = 4.0*atan(1.0), &
24 radius_earth = 6371200.0
26 character(len=256) :: grid_fn
27 integer :: ncid, nxsg_dimid, nysg_dimid, dasg_varid, num_args
28 integer :: nxsg, nysg, nx, ny, res_equiv
29 real(dp) :: avg_cell_size, min_cell_size, max_cell_size
30 real(dp),
dimension(:,:),
allocatable :: &
31 quarter_da_ll, quarter_da_lr, quarter_da_ur, quarter_da_ul, &
43 num_args = command_argument_count()
44 if (num_args == 1)
then
45 call get_command_argument(1, grid_fn)
48 WRITE(*,500)
"Exactly one argument must be specified to program global_equiv_resol."
51 WRITE(*,500)
" global_equiv_resol path_to_grid_file"
53 WRITE(*,500)
"where path_to_grid_file is the path to the NetCDF grid file. Actual "
54 WRITE(*,500)
"number of specified command line arguments is:"
55 WRITE(*,510)
" num_args = ", num_args
56 WRITE(*,500)
"Stopping."
76 WRITE(*,500)
"Opening NetCDF grid file for reading/writing:"
77 WRITE(*,500)
" grid_fn = " // trim(grid_fn)
79 call
check( nf90_open(trim(grid_fn), nf90_write, ncid) )
81 call
check( nf90_inq_dimid(ncid,
"nx", nxsg_dimid) )
82 call
check( nf90_inquire_dimension(ncid, nxsg_dimid, len=nxsg) )
84 call
check( nf90_inq_dimid(ncid,
"ny", nysg_dimid) )
85 call
check( nf90_inquire_dimension(ncid, nysg_dimid, len=nysg) )
88 WRITE(*,500)
"Dimensions of supergrid are:"
89 WRITE(*,520)
" nxSG = ", nxsg
90 WRITE(*,520)
" nySG = ", nysg
101 allocate(dasg(0:nxsg-1, 0:nysg-1))
102 call
check( nf90_inq_varid(ncid,
"area", dasg_varid) )
103 call
check( nf90_get_var(ncid, dasg_varid, dasg) )
109 WRITE(*,500)
"Dimensions of (actual, i.e. computational) grid are:"
110 WRITE(*,520)
" nx = ", nx
111 WRITE(*,520)
" ny = ", ny
113 allocate(quarter_da_ll(0:nx-1, 0:ny-1))
114 allocate(quarter_da_lr(0:nx-1, 0:ny-1))
115 allocate(quarter_da_ul(0:nx-1, 0:ny-1))
116 allocate(quarter_da_ur(0:nx-1, 0:ny-1))
118 quarter_da_ll = dasg(0:nxsg-1:2, 0:nysg-1:2)
119 quarter_da_lr = dasg(0:nxsg-1:2, 1:nysg-1:2)
120 quarter_da_ur = dasg(1:nxsg-1:2, 1:nysg-1:2)
121 quarter_da_ul = dasg(1:nxsg-1:2, 0:nysg-1:2)
123 allocate(da(0:nx-1, 0:ny-1))
124 allocate(sqrt_da(0:nx-1, 0:ny-1))
126 da = quarter_da_ll + quarter_da_lr + quarter_da_ur + quarter_da_ul
137 min_cell_size = minval(sqrt_da)
138 max_cell_size = maxval(sqrt_da)
139 avg_cell_size = sum(sqrt_da)/(nx*ny)
142 WRITE(*,500)
"Minimum, maximum, and average cell sizes are (based on square"
143 WRITE(*,500)
"root of cell area):"
144 WRITE(*,530)
" min_cell_size = ", min_cell_size
145 WRITE(*,530)
" max_cell_size = ", max_cell_size
146 WRITE(*,530)
" avg_cell_size = ", avg_cell_size
159 res_equiv = nint( (2.0*pi_geom*radius_earth)/(4.0*avg_cell_size) )
162 WRITE(*,500)
"Equivalent global uniform cubed-sphere resolution is:"
163 WRITE(*,*)
" RES_equiv = ", res_equiv
173 WRITE(*,500)
"Writing avg_cell_size and RES_equiv to the grid specification"
174 WRITE(*,500)
"file as global attributes..."
176 call
check( nf90_redef(ncid) )
177 call
check( nf90_put_att(ncid, nf90_global,
"avg_cell_size", avg_cell_size) )
178 call
check( nf90_put_att(ncid, nf90_global,
"RES_equiv", res_equiv) )
179 call
check( nf90_enddef(ncid) )
181 call
check( nf90_close(ncid) )
194 integer,
intent(in) :: status
196 if(status /= nf90_noerr)
then
197 write(0,*)
' check netcdf status = ', status
198 write(0,
'("error ", a)') trim(nf90_strerror(status))
program global_equiv_resol
Compute the global equivalent resolution for regional grids using the average model grid cell size in...
subroutine check(status)
Check results of netCDF call.