grid_tools  1.5.0
 All Data Structures Files Functions Variables
regional_esg_grid.f90
Go to the documentation of this file.
1 
5 
19 
20  use pkind, only: dp
21  use pietc, only: dtor,rtod
22  use pesg
23  use netcdf
24 
25  implicit none
26 
27  ! namelist variables
28  real(dp) :: plat,plon,pazi=0.0
29  real(dp) :: delx,dely
30  integer :: lx,ly
31  namelist /regional_grid_nml/ plat,plon,pazi,delx,dely,lx,ly
32 
33  real(dp),parameter :: re=6371000.0
34  real(dp),parameter :: lam=0.8
35 
36  integer :: nxh,nyh, nx,ny, nxm,nym
37  logical :: ff
38 
39  real(dp),dimension(:,:),allocatable:: glat,glon
40  real(dp),dimension(:,:),allocatable:: garea
41  real(dp),dimension(:,:),allocatable:: dx,dy,angle_dx,angle_dy
42 
43  character(len=256) :: nml_fname
44 
45  ! netcdf
46  integer :: ncid
47  integer :: string_dimid, nxp_dimid, nyp_dimid, nx_dimid, ny_dimid
48  integer :: tile_varid, x_varid, y_varid, area_varid
49  integer :: dx_varid, dy_varid, angle_dx_varid, angle_dy_varid
50  integer, dimension(2) :: dimids
51 
52  real(dp) :: a,k,m_arcx,m_arcy,q
53  real(dp) :: m_delx,m_dely, delxre,delyre
54  real(dp) :: arcx,arcy
55 
56 !=============================================================================
57 
58  if (command_argument_count() == 1) then
59  call get_command_argument(1, nml_fname)
60  else
61  nml_fname = "regional_grid.nml"
62  end if
63 
64  open(10,file=trim(nml_fname),status="old",action="read")
65  read(10,nml=regional_grid_nml)
66  close(10)
67 
68  nxh=-lx
69  nyh=-ly
70  nx=2*nxh
71  ny=2*nyh
72  nxm=nx-1
73  nym=ny-1
74 
75  allocate(glat(0:nx,0:ny))
76  allocate(glon(0:nx,0:ny))
77  allocate(garea(0:nxm,0:nym))
78 
79  allocate(dx(0:nxm,0:ny))
80  allocate(dy(0:nx,0:nym))
81  allocate(angle_dx(0:nx,0:ny))
82  allocate(angle_dy(0:nx,0:ny))
83 
84  arcx=delx*nxh
85  arcy=dely*nyh
86  print'("arcx, arcy ",f8.4,f8.4)',arcx,arcy
87  call bestesg_geo(lam,arcx,arcy, a,k,m_arcx,m_arcy,q,ff)
88  if(ff)stop 'Failure flag returned from get_bestesg'
89  print'("For lam=",f8.2," the best [smallest possible]")',lam
90  print'("optimality criterion, Q, for this domain: ",e13.6 )',q
91  print'("The corresponding optimal A and K:",2(1x,f8.4))',a,k
92  print'("The corresponding m_arcx,y:",2(1x,e20.13))',m_arcx,m_arcy
93 
94  m_delx=m_arcx/nxh ! Map-space grid steps in x
95  m_dely=m_arcy/nyh ! Map-space grid steps in y
96  print'("x and y central grid resolution in map units:",2(1x,e12.5))',m_delx,m_dely
97 
98  print'("Get additional diagnostics from hgrid_ak_rr")'
99 
100  delxre=m_delx*re
101  delyre=m_dely*re
102 
103  call hgrid_ak(lx,ly, nx,ny, a,k, plat*dtor,plon*dtor,pazi*dtor, re,delxre,delyre, &
104  glat,glon,garea, dx,dy,angle_dx,angle_dy, ff)
105  if(ff)stop 'Failure flag raised in hgrid routine'
106 
107  glon = glon*rtod
108  glat = glat*rtod
109  where (glon < 0.0) glon = glon + 360.0
110 
111  call check( nf90_create("regional_grid.nc", nf90_64bit_offset, ncid) )
112  call check( nf90_def_dim(ncid, "string", 255, string_dimid) )
113  call check( nf90_def_dim(ncid, "nx", nx, nx_dimid) )
114  call check( nf90_def_dim(ncid, "ny", ny, ny_dimid) )
115  call check( nf90_def_dim(ncid, "nxp", nx+1, nxp_dimid) )
116  call check( nf90_def_dim(ncid, "nyp", ny+1, nyp_dimid) )
117 
118  call check( nf90_def_var(ncid, "tile", nf90_char, [string_dimid], tile_varid) )
119  call check( nf90_put_att(ncid, tile_varid, "standard_name", "grid_tile_spec") )
120 
121  dimids = (/ nxp_dimid, nyp_dimid /)
122  call check( nf90_def_var(ncid, "x", nf90_double, dimids, x_varid) )
123  call check( nf90_put_att(ncid, x_varid, "standard_name", "geographic_longitude") )
124  call check( nf90_put_att(ncid, x_varid, "units", "degree_east") )
125  call check( nf90_put_att(ncid, x_varid, "hstagger", "C") )
126  call check( nf90_def_var(ncid, "y", nf90_double, dimids, y_varid) )
127  call check( nf90_put_att(ncid, y_varid, "standard_name", "geographic_latitude") )
128  call check( nf90_put_att(ncid, y_varid, "units", "degree_north") )
129  call check( nf90_put_att(ncid, y_varid, "hstagger", "C") )
130  dimids = (/ nx_dimid, ny_dimid /)
131  call check( nf90_def_var(ncid, "area", nf90_double, dimids, area_varid) )
132  call check( nf90_put_att(ncid, area_varid, "standard_name", "grid_cell_area") )
133  call check( nf90_put_att(ncid, area_varid, "units", "m2") )
134  call check( nf90_put_att(ncid, area_varid, "hstagger", "H") )
135 
136  dimids = (/ nx_dimid, nyp_dimid /)
137  call check( nf90_def_var(ncid, "dx", nf90_double, dimids, dx_varid) )
138  call check( nf90_put_att(ncid, dx_varid, "standard_name", "dx") )
139  call check( nf90_put_att(ncid, dx_varid, "units", "m") )
140  call check( nf90_put_att(ncid, dx_varid, "hstagger", "H") )
141 
142  dimids = (/ nxp_dimid, ny_dimid /)
143  call check( nf90_def_var(ncid, "dy", nf90_double, dimids, dy_varid) )
144  call check( nf90_put_att(ncid, dy_varid, "standard_name", "dy") )
145  call check( nf90_put_att(ncid, dy_varid, "units", "m") )
146  call check( nf90_put_att(ncid, dy_varid, "hstagger", "H") )
147 
148  dimids = (/ nxp_dimid, nyp_dimid /)
149  call check( nf90_def_var(ncid, "angle_dx", nf90_double, dimids, angle_dx_varid) )
150  call check( nf90_put_att(ncid, angle_dx_varid, "standard_name", "angle_dx") )
151  call check( nf90_put_att(ncid, angle_dx_varid, "units", "deg") )
152  call check( nf90_put_att(ncid, angle_dx_varid, "hstagger", "C") )
153  call check( nf90_def_var(ncid, "angle_dy", nf90_double, dimids, angle_dy_varid) )
154  call check( nf90_put_att(ncid, angle_dy_varid, "standard_name", "angle_dy") )
155  call check( nf90_put_att(ncid, angle_dy_varid, "units", "deg") )
156  call check( nf90_put_att(ncid, angle_dy_varid, "hstagger", "C") )
157 
158  call check( nf90_put_att(ncid, nf90_global, "history", "gnomonic_ed") )
159  call check( nf90_put_att(ncid, nf90_global, "source", "FV3GFS") )
160  call check( nf90_put_att(ncid, nf90_global, "grid", "akappa") )
161  call check( nf90_put_att(ncid, nf90_global, "plat", plat) )
162  call check( nf90_put_att(ncid, nf90_global, "plon", plon) )
163  call check( nf90_put_att(ncid, nf90_global, "pazi", pazi) )
164  call check( nf90_put_att(ncid, nf90_global, "delx", m_delx*rtod) )
165  call check( nf90_put_att(ncid, nf90_global, "dely", m_dely*rtod) )
166  call check( nf90_put_att(ncid, nf90_global, "lx", lx) )
167  call check( nf90_put_att(ncid, nf90_global, "ly", ly) )
168  call check( nf90_put_att(ncid, nf90_global, "a", a) )
169  call check( nf90_put_att(ncid, nf90_global, "k", k) )
170 
171  call check( nf90_enddef(ncid) )
172 
173  call check( nf90_put_var(ncid, tile_varid, "tile7") )
174  call check( nf90_put_var(ncid, x_varid, glon) )
175  call check( nf90_put_var(ncid, y_varid, glat) )
176  call check( nf90_put_var(ncid, area_varid, garea) )
177  call check( nf90_put_var(ncid, dx_varid, dx) )
178  call check( nf90_put_var(ncid, dy_varid, dy) )
179  call check( nf90_put_var(ncid, angle_dx_varid, angle_dx) )
180  call check( nf90_put_var(ncid, angle_dy_varid, angle_dy) )
181 
182  call check( nf90_close(ncid) )
183 
184 end program regional_grid
185 
190 subroutine check(status)
191 use netcdf
192 integer,intent(in) :: status
193 !
194 if(status /= nf90_noerr) then
195  write(0,*)' check netcdf status=',status
196  write(0,'("error ", a)')trim(nf90_strerror(status))
197  stop "Stopped"
198 endif
199 end subroutine check
Suite of routines to perform the 2-parameter family of Extended Schmidt Gnomonic (ESG) regional grid ...
Definition: pesg.f90:15
Standard integer, real, and complex single and double precision kinds.
Definition: pkind.f90:7
Some of the commonly used constants (pi etc) mainly for double-precision subroutines.
Definition: pietc.f90:14
program regional_grid
Driver routine to compute geo-referencing parameters for the Extended Schmidt Gnomonic (ESG) regional...
subroutine check(status)
Check results of netCDF call.