52 REAL :: tinyreal=tiny(1.0)
67 REAL,
PARAMETER :: SLAT=60.0
69 real :: dx, dy, hi, hj
70 integer :: iproj, iscan, jscan
72 associate(kgds => g1_desc%gds)
73 self%ELLIPTICAL=mod(kgds(6)/64,2).EQ.1
75 if (.not. self%elliptical)
then
77 self%eccen_squared = 0d0
86 self%RLAT1=kgds(4)*1.e-3
87 self%RLON1=kgds(5)*1.e-3
89 self%IROT=mod(kgds(6)/8,2)
93 self%ORIENT=kgds(7)*1.e-3
98 iproj=mod(kgds(10)/128,2)
99 iscan=mod(kgds(11)/128,2)
100 jscan=mod(kgds(11)/64,2)
106 IF(abs(self%H+1.).LT.tinyreal) self%ORIENT=self%ORIENT+180.
114 self%nscan = mod(kgds(11) / 32, 2)
115 self%nscan_field_pos = self%nscan
130 type(grib2_descriptor),
intent(in) :: g2_desc
132 real :: slat, dx, dy, hi, hj
133 integer :: iproj, iscan, jscan
135 associate(igdtmpl => g2_desc%gdt_tmpl, igdtlen => g2_desc%gdt_len)
136 call earth_radius(igdtmpl, igdtlen, self%rerth, self%eccen_squared)
138 self%ELLIPTICAL = self%eccen_squared > 0.0
143 self%RLAT1=float(igdtmpl(10))*1.e-6
144 self%RLON1=float(igdtmpl(11))*1.e-6
146 self%IROT=mod(igdtmpl(12)/8,2)
148 slat=float(abs(igdtmpl(13)))*1.e-6
151 self%ORIENT=float(igdtmpl(14))*1.e-6
153 dx=float(igdtmpl(15))*1.e-3
154 dy=float(igdtmpl(16))*1.e-3
156 iproj=mod(igdtmpl(17)/128,2)
157 iscan=mod(igdtmpl(18)/128,2)
158 jscan=mod(igdtmpl(18)/64,2)
167 self%nscan = mod(igdtmpl(18) / 32, 2)
168 self%nscan_field_pos = self%nscan
240 FILL,XPTS,YPTS,RLON,RLAT,NRET, &
241 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
246 INTEGER,
INTENT(IN ) :: IOPT, NPTS
247 INTEGER,
INTENT( OUT) :: NRET
249 REAL,
INTENT(IN ) :: FILL
250 REAL,
INTENT(INOUT) :: RLON(NPTS),RLAT(NPTS)
251 REAL,
INTENT(INOUT) :: XPTS(NPTS),YPTS(NPTS)
252 REAL,
OPTIONAL,
INTENT( OUT) :: CROT(NPTS),SROT(NPTS)
253 REAL,
OPTIONAL,
INTENT( OUT) :: XLON(NPTS),XLAT(NPTS)
254 REAL,
OPTIONAL,
INTENT( OUT) :: YLON(NPTS),YLAT(NPTS),AREA(NPTS)
259 LOGICAL :: ELLIPTICAL, LROT, LMAP, LAREA
261 REAL :: ALAT, ALAT1, ALONG, DIFF
263 REAL :: DR, E, E_OVER_2
265 REAL :: RLAT1, RLON1, RHO, T, TC
266 REAL :: XMAX, XMIN, YMAX, YMIN
269 IF(
PRESENT(crot)) crot=fill
270 IF(
PRESENT(srot)) srot=fill
271 IF(
PRESENT(xlon)) xlon=fill
272 IF(
PRESENT(xlat)) xlat=fill
273 IF(
PRESENT(ylon)) ylon=fill
274 IF(
PRESENT(ylat)) ylat=fill
275 IF(
PRESENT(area)) area=fill
277 elliptical = self%elliptical
293 e2 = self%eccen_squared
296 IF (.NOT.elliptical)
THEN
297 de=(1.+sin(slatr))*
rerth
298 dr=de*cos(rlat1/dpr)/(1+
h*sin(rlat1/dpr))
306 along = (rlon1-
orient)/dpr
307 t=tan(pi4-alat/2.)/((1.-e*sin(alat))/ &
308 (1.+e*sin(alat)))**(e_over_2)
309 tc=tan(pi4-slatr/2.)/((1.-e*sin(slatr))/ &
310 (1.+e*sin(slatr)))**(e_over_2)
311 mc=cos(slatr)/sqrt(1.0-
e2*(sin(slatr)**2))
313 yp = 1.0 + rho*cos(
h*along)/
dys
314 xp = 1.0 - rho*sin(
h*along)/
dxs
321 IF(
PRESENT(crot).AND.
PRESENT(srot))
THEN
326 IF(
PRESENT(xlon).AND.
PRESENT(xlat).AND.
PRESENT(ylon).AND.
PRESENT(ylat))
THEN
331 IF(
PRESENT(area))
THEN
338 IF(iopt.EQ.0.OR.iopt.EQ.1)
THEN
339 IF(.NOT.elliptical)
THEN
342 IF(xpts(n).GE.xmin.AND.xpts(n).LE.xmax.AND. &
343 ypts(n).GE.ymin.AND.ypts(n).LE.ymax)
THEN
347 IF(dr2.LT.
de2*1.e-6)
THEN
351 rlon(n)=mod(
orient+
h*dpr*atan2(di,-dj)+3600,360.)
352 rlat(n)=
h*dpr*asin((
de2-dr2)/(
de2+dr2))
357 xlon(n),xlat(n),ylon(n),ylat(n))
369 IF(xpts(n).GE.xmin.AND.xpts(n).LE.xmax.AND. &
370 ypts(n).GE.ymin.AND.ypts(n).LE.ymax)
THEN
373 rho=sqrt(di*di+dj*dj)
374 t=(rho*tc)/(
rerth*mc)
375 IF(abs(ypts(n)-yp)<0.01)
THEN
377 IF(di<=0.0) along=
orient-
h*90.0
379 along=
orient+
h*atan(di/(-dj))*dpr
380 IF(dj>0) along=along+180.
382 alat1=pi2-2.0*atan(t)
384 alat = pi2 - 2.0*atan(t*(((1.0-e*sin(alat1))/ &
385 (1.0+e*sin(alat1)))**(e_over_2)))
386 diff = abs(alat-alat1)*dpr
387 IF (diff < 0.000001)
EXIT
392 IF(rlon(n)<0.0) rlon(n)=rlon(n)+360.
393 IF(rlon(n)>360.0) rlon(n)=rlon(n)-360.0
405 ELSEIF(iopt.EQ.-1)
THEN
406 IF(.NOT.elliptical)
THEN
409 IF(abs(rlon(n)).LT.(360.+tinyreal).AND.abs(rlat(n)).LT.(90.+tinyreal).AND. &
410 abs(
h*rlat(n)+90).GT.tinyreal)
THEN
411 dr=de*tan((90-
h*rlat(n))/2/dpr)
414 ypts(n)=yp-cos((rlon(n)-
orient)/dpr)*dr/
dys
415 IF(xpts(n).GE.xmin.AND.xpts(n).LE.xmax.AND. &
416 ypts(n).GE.ymin.AND.ypts(n).LE.ymax)
THEN
420 xlon(n),xlat(n),ylon(n),ylat(n))
435 IF(abs(rlon(n)).LT.(360+tinyreal).AND.abs(rlat(n)).LT.(90+tinyreal).AND. &
436 abs(
h*rlat(n)+90).GT.tinyreal)
THEN
438 along = (rlon(n)-
orient)/dpr
439 t=tan(pi4-alat*0.5)/((1.-e*sin(alat))/ &
440 (1.+e*sin(alat)))**(e_over_2)
442 xpts(n)= xp + rho*sin(
h*along) /
dxs
443 ypts(n)= yp - rho*cos(
h*along) /
dys
444 IF(xpts(n).GE.xmin.AND.xpts(n).LE.xmax.AND. &
445 ypts(n).GE.ymin.AND.ypts(n).LE.ymax)
THEN
485 REAL,
INTENT(IN ) :: RLON
486 REAL,
INTENT( OUT) :: CROT, SROT
490 srot=sin((rlon-
orient)/dpr)
523 REAL,
INTENT(IN ) :: RLON, RLAT, DR2
524 REAL,
INTENT( OUT) :: XLON, XLAT, YLON, YLAT
528 IF(dr2.LT.
de2*1.e-6)
THEN
531 xlat=-sin((rlon-
orient)/dpr)/dpr*de/
dxs/2
538 xlat=-sin((rlon-
orient)/dpr)/dpr*dr/
dxs/clat
566 REAL,
INTENT(IN ) :: RLAT, DR2
567 REAL,
INTENT( OUT) :: AREA
571 IF(dr2.LT.
de2*1.e-6)
THEN
void gdswzd(int igdtnum, int *igdtmpl, int igdtlen, int iopt, int npts, float fill, float *xpts, float *ypts, float *rlon, float *rlat, int *nret, float *crot, float *srot, float *xlon, float *xlat, float *ylon, float *ylat, float *area)
gdswzd() interface for C for _4 build of library.
Determine earth radius and shape.
Module containing common constants.
real, parameter pi2
PI / 2.0.
real, parameter pi4
PI / 4.0.
real, parameter rerth_wgs84
Radius of the Earth defined by WGS-84.
real, parameter dpr
Radians to degrees.
real, parameter e2_wgs84
Eccentricity squared of Earth defined by WGS-84.
Users derived type grid descriptor objects to abstract away the raw GRIB1 and GRIB2 grid definitions.
GDS wizard for polar stereographic azimuthal.
integer irot
Local copy of irot.
subroutine polar_stereo_grid_area(RLAT, DR2, AREA)
Grid box area for polar stereographic grids.
real rerth
Radius of the Earth.
subroutine polar_stereo_map_jacob(RLON, RLAT, DR2, XLON, XLAT, YLON, YLAT)
Map jacobians for polar stereographic grids.
subroutine init_grib2(self, g2_desc)
Initializes a polar stereographic grid given a grib2_descriptor object.
subroutine init_grib1(self, g1_desc)
Initializes a polar stereographic grid given a grib1_descriptor object.
real orient
Local copy of orient.
subroutine polar_stereo_vect_rot(RLON, CROT, SROT)
Vector rotation fields for polar stereographic grids.
real e2
Eccentricity squared.
real dxs
Local copy of dxs.
subroutine gdswzd_polar_stereo(self, IOPT, NPTS, FILL, XPTS, YPTS, RLON, RLAT, NRET, CROT, SROT, XLON, XLAT, YLON, YLAT, AREA)
GDS wizard for polar stereographic azimuthal.
real dys
Local copy of dys.
Descriptor representing a grib1 grib descriptor section (GDS) with an integer array.
Abstract grid that holds fields and methods common to all grids.