20 integer,
parameter :: kdbl=selected_real_kind(p=13,r=200)
21 character(len=255) :: filename_full
22 character(len=255) :: filename_shaved
23 integer :: idim_compute,jdim_compute,halo
24 integer :: i_count_compute,j_count_compute &
25 ,i_count_super,j_count_super
34 integer :: n,na,ncid_in,ncid_out,nd,ndims,ngatts &
38 integer :: dim_id,len_dim,len_x,len_y,var_id,xdim_id,xdim_id_out &
41 integer,
dimension(1:2) :: dimids=(/0,0/)
42 real,
dimension(:) ,
allocatable :: var_1d_with_halo
43 real,
dimension(:,:),
allocatable :: var_2d_with_halo
44 real(kind=kdbl),
dimension(:,:),
allocatable :: var_2d_dbl_with_halo
46 character(len=50) :: file,name_dim,name_xdim,name_ydim &
48 character(len=50) :: name_att
49 character(len=50) :: name_var
50 character(len=255) :: att=
' '
51 character(len=255),
dimension(:),
allocatable :: var_1d_char
56 read(5,*)idim_compute,jdim_compute,halo,filename_full,filename_shaved
57 write(6,*)
' id ',idim_compute,
' jd ',jdim_compute,
' halo ',halo
58 write(6,*)
' fn_f ',trim(filename_full)
59 write(6,*)
' fn_s ',trim(filename_shaved)
60 i_count_compute=idim_compute+2*halo
61 j_count_compute=jdim_compute+2*halo
62 i_count_super =2*i_count_compute
63 j_count_super =2*j_count_compute
68 call
check(nf90_open(filename_full,nf90_nowrite,ncid_in))
69 call
check(nf90_inquire(ncid_in,ndims,nvars,ngatts,unlimdimid))
75 call
check(nf90_create(filename_shaved &
76 ,or(nf90_classic_model,nf90_netcdf4) &
89 call
check(nf90_inquire_dimension(ncid_in,nd,name_dim,len_dim))
90 select case (name_dim)
96 len_dim=i_count_super+1
101 len_dim=j_count_super+1
103 len_dim=i_count_compute
107 len_dim=j_count_compute
111 call
check(nf90_def_dim(ncid_out,name_dim,len_dim,dim_id))
121 call
check(nf90_inquire_variable(ncid_in,var_id,name_var,nctype &
122 ,ndims,dimids,natts))
124 call
check(nf90_def_var(ncid_out,name_var,nctype,dimids(1),var_id))
126 call
check(nf90_def_var(ncid_out,name_var,nctype,dimids,var_id))
134 call
check(nf90_inq_attname(ncid_in,var_id,na,name_att))
135 call
check(nf90_copy_att(ncid_in,var_id,name_att,ncid_out,var_id))
144 call
check(nf90_inq_attname(ncid_in,nf90_global,n,name_att))
145 call
check(nf90_copy_att(ncid_in,nf90_global,name_att,ncid_out,nf90_global))
147 call
check(nf90_enddef(ncid_out))
153 call
check(nf90_inq_dimid(ncid_in,xdim,xdim_id))
154 call
check(nf90_inq_dimid(ncid_in,ydim,ydim_id))
155 call
check(nf90_inquire_dimension(ncid_in,xdim_id,name_xdim,len_x))
156 call
check(nf90_inquire_dimension(ncid_in,ydim_id,name_ydim,len_y))
157 if(trim(file)==
'orog_file')
then
158 i_start=(len_x-idim_compute)/2-halo+1
159 j_start=(len_y-jdim_compute)/2-halo+1
161 elseif(trim(file)==
'grid_file')
then
162 i_start=(len_x-2*idim_compute)/2-2*halo+1
163 j_start=(len_y-2*jdim_compute)/2-2*halo+1
179 var_loop:
do n=1,nvars
181 call
check(nf90_inquire_variable(ncid_in,var_id,name_var,nctype &
182 ,ndims,dimids,natts))
183 call
check(nf90_inquire_dimension(ncid_in,dimids(1),name_xdim,len_x))
185 call
check(nf90_inquire_dimension(ncid_in,dimids(2),name_ydim,len_y))
196 if(nctype==nf90_char)
then
199 allocate(var_1d_char(1:n_count),stat=istat)
200 call
check(nf90_get_var(ncid_in,var_id,var_1d_char(:) &
203 call
check(nf90_put_var(ncid_out,var_id,var_1d_char))
204 deallocate(var_1d_char)
211 n_count=len_dim-2*n_shave
212 allocate(var_1d_with_halo(1:n_count),stat=istat)
213 call
check(nf90_get_var(ncid_in,var_id,var_1d_with_halo(:) &
216 call
check(nf90_put_var(ncid_out,var_id,var_1d_with_halo))
217 deallocate(var_1d_with_halo)
224 if(trim(file)==
'orog_file')
then
225 i_start=(len_x-idim_compute)/2-halo+1
226 j_start=(len_y-jdim_compute)/2-halo+1
227 i_count=i_count_compute
228 j_count=j_count_compute
229 elseif(trim(file)==
'grid_file')
then
230 i_start=(len_x-2*idim_compute)/2-2*halo+1
231 j_start=(len_y-2*jdim_compute)/2-2*halo+1
232 i_count=i_count_super
233 j_count=j_count_super
234 if(trim(name_xdim)==
'nxp')
then
237 if(trim(name_ydim)==
'nyp')
then
241 if(nctype==nf90_float)
then
242 allocate(var_2d_with_halo(i_count,j_count),stat=istat)
243 call
check(nf90_get_var(ncid_in,var_id,var_2d_with_halo(:,:) &
244 ,start=(/i_start,j_start/) &
245 ,count=(/i_count,j_count/)))
246 call
check(nf90_put_var(ncid_out,var_id,var_2d_with_halo))
247 deallocate(var_2d_with_halo)
248 elseif(nctype==nf90_double)
then
249 allocate(var_2d_dbl_with_halo(i_count,j_count),stat=istat)
250 call
check(nf90_get_var(ncid_in,var_id,var_2d_dbl_with_halo(:,:) &
251 ,start=(/i_start,j_start/) &
252 ,count=(/i_count,j_count/)))
253 call
check(nf90_put_var(ncid_out,var_id,var_2d_dbl_with_halo))
254 deallocate(var_2d_dbl_with_halo)
258 call
check(nf90_close(ncid_out))
259 call
check(nf90_close(ncid_in))
267 integer,
intent(in) :: status
268 if(status /= nf90_noerr)
then
269 print *, trim(nf90_strerror(status))
program shave_nc
The grid driver step in FV3 preprocessing generates a grid_tile file and an oro_tile file for the reg...
subroutine check(status)
Check results of netCDF call.