46 REAL,
ALLOCATABLE ::
blat(:)
66 associate(kgds => g1_desc%gds)
68 self%eccen_squared = 0.0
72 self%RLAT1=kgds(4)*1.e-3
73 self%RLON1=kgds(5)*1.e-3
74 self%RLON2=kgds(8)*1.e-3
76 iscan=mod(kgds(11)/128,2)
77 self%JSCAN=mod(kgds(11)/64,2)
79 self%JH=(-1)**self%JSCAN
80 self%DLON=self%HI*(mod(self%HI*(self%RLON2-self%RLON1)-1+3600,360.)+1)/(self%IM-1)
85 self%nscan = mod(kgds(11) / 32, 2)
86 self%nscan_field_pos = self%nscan
89 self%iwrap=nint(360 / abs(self%dlon))
90 if(self%im < self%iwrap) self%iwrap = 0
92 if(self%iwrap > 0 .and. mod(self%iwrap, 2) == 0)
then
94 if(self%jm == self%jg)
then
96 self%jwrap2 = 2 * self%jm + 1
111 type(grib2_descriptor),
intent(in) :: g2_desc
113 integer :: iscale, iscan, jg
115 associate(igdtmpl => g2_desc%gdt_tmpl, igdtlen => g2_desc%gdt_len)
116 call earth_radius(igdtmpl, igdtlen, self%rerth, self%eccen_squared)
120 iscale=igdtmpl(10)*igdtmpl(11)
121 IF(iscale==0) iscale=10**6
122 self%RLAT1=float(igdtmpl(12))/float(iscale)
123 self%RLON1=float(igdtmpl(13))/float(iscale)
124 self%RLON2=float(igdtmpl(16))/float(iscale)
125 self%JG=igdtmpl(18)*2
126 iscan=mod(igdtmpl(19)/128,2)
127 self%JSCAN=mod(igdtmpl(19)/64,2)
129 self%JH=(-1)**self%JSCAN
130 self%DLON=self%HI*(mod(self%HI*(self%RLON2-self%RLON1)-1+3600,360.)+1)/(self%IM-1)
133 self%iwrap = nint(360 / abs(self%dlon))
134 if(self%im < self%iwrap) self%iwrap = 0
137 if(self%iwrap > 0 .and. mod(self%iwrap, 2) == 0)
then
139 if(self%jm == jg)
then
141 self%jwrap2 = 2 * self%jm + 1
144 self%nscan = mod(igdtmpl(19) / 32, 2)
145 self%nscan_field_pos = self%nscan
196 XPTS,YPTS,RLON,RLAT,NRET, &
197 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
201 INTEGER,
INTENT(IN ) :: IOPT, NPTS
202 INTEGER,
INTENT( OUT) :: NRET
204 REAL,
INTENT(IN ) :: FILL
205 REAL,
INTENT(INOUT) :: RLON(NPTS),RLAT(NPTS)
206 REAL,
INTENT(INOUT) :: XPTS(NPTS),YPTS(NPTS)
207 REAL,
OPTIONAL,
INTENT( OUT) :: CROT(NPTS),SROT(NPTS)
208 REAL,
OPTIONAL,
INTENT( OUT) :: XLON(NPTS),XLAT(NPTS)
209 REAL,
OPTIONAL,
INTENT( OUT) :: YLON(NPTS),YLAT(NPTS),AREA(NPTS)
211 INTEGER :: JSCAN, IM, JM
215 LOGICAL :: LROT, LMAP, LAREA
217 REAL,
ALLOCATABLE :: ALAT(:), ALAT_JSCAN(:)
218 REAL,
ALLOCATABLE :: ALAT_TEMP(:),BLAT_TEMP(:)
219 REAL :: HI, RLATA, RLATB, RLAT1, RLON1, RLON2
220 REAL :: XMAX, XMIN, YMAX, YMIN, YPTSA, YPTSB
223 IF(
PRESENT(crot)) crot=fill
224 IF(
PRESENT(srot)) srot=fill
225 IF(
PRESENT(xlon)) xlon=fill
226 IF(
PRESENT(xlat)) xlat=fill
227 IF(
PRESENT(ylon)) ylon=fill
228 IF(
PRESENT(ylat)) ylat=fill
229 IF(
PRESENT(area)) area=fill
231 IF(
PRESENT(crot).AND.
PRESENT(srot))
THEN
236 IF(
PRESENT(xlon).AND.
PRESENT(xlat).AND.
PRESENT(ylon).AND.
PRESENT(ylat))
THEN
241 IF(
PRESENT(area))
THEN
262 ALLOCATE(alat_temp(jg))
263 ALLOCATE(blat_temp(jg))
264 CALL splat(4,jg,alat_temp,blat_temp)
265 ALLOCATE(alat(0:jg+1))
266 ALLOCATE(
blat(0:jg+1))
269 alat(ja)=real(dpr*asin(alat_temp(ja)))
270 blat(ja)=blat_temp(ja)
273 DEALLOCATE(alat_temp,blat_temp)
279 DO WHILE(
j1.LT.jg.AND.rlat1.LT.(alat(
j1)+alat(
j1+1))/2)
283 ALLOCATE(alat_jscan(jg))
285 alat_jscan(
j1+
jh*(ja-1))=alat(ja)
289 ylat_row(ja)=2.0/(alat_jscan(ja+1)-alat_jscan(ja-1))
291 ylat_row(1)=1.0/(alat_jscan(2)-alat_jscan(1))
293 ylat_row(jg)=1.0/(alat_jscan(jg)-alat_jscan(jg-1))
295 DEALLOCATE(alat_jscan)
299 IF(im.EQ.nint(360/abs(
dlon))) xmax=im+2
305 IF(iopt.EQ.0.OR.iopt.EQ.1)
THEN
308 IF(xpts(n).GE.xmin.AND.xpts(n).LE.xmax.AND. &
309 ypts(n).GE.ymin.AND.ypts(n).LE.ymax)
THEN
310 rlon(n)=mod(rlon1+
dlon*(xpts(n)-1)+3600,360.)
313 rlata=alat(
j1+
jh*(j-1))
315 rlat(n)=rlata+wb*(rlatb-rlata)
319 xlon(n),xlat(n),ylon(n),ylat(n))
329 ELSEIF(iopt.EQ.-1)
THEN
334 IF(abs(rlon(n)).LE.360.AND.abs(rlat(n)).LE.90)
THEN
335 xpts(n)=1+hi*mod(hi*(rlon(n)-rlon1)+3600,360.)/
dlon
336 ja=min(int((jg+1)/180.*(90-rlat(n))),jg)
337 IF(rlat(n).GT.alat(ja)) ja=max(ja-2,0)
338 IF(rlat(n).LT.alat(ja+1)) ja=min(ja+2,jg)
339 IF(rlat(n).GT.alat(ja)) ja=ja-1
340 IF(rlat(n).LT.alat(ja+1)) ja=ja+1
343 wb=(alat(ja)-rlat(n))/(alat(ja)-alat(ja+1))
344 ypts(n)=yptsa+wb*(yptsb-yptsa)
345 IF(xpts(n).GE.xmin.AND.xpts(n).LE.xmax.AND. &
346 ypts(n).GE.ymin.AND.ypts(n).LE.ymax)
THEN
350 xlon(n),xlat(n),ylon(n),ylat(n))
360 DEALLOCATE(alat,
blat)
380 REAL,
INTENT( OUT) :: CROT, SROT
400 REAL,
INTENT(IN ) :: YPTS
401 REAL,
INTENT( OUT) :: XLON, XLAT, YLON, YLAT
420 REAL,
INTENT(IN ) :: YPTS
421 REAL,
INTENT( OUT) :: AREA
425 REAL :: WB, WLAT, WLATA, WLATB
431 wlat=wlata+wb*(wlatb-wlata)
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.
Gaussian grid coordinate transformations.
real, dimension(:), allocatable ylat_row
dy/dlat for each row in 1/degrees.
integer jh
Scan mode flag in 'j' direction.
subroutine gdswzd_gaussian(self, IOPT, NPTS, FILL, XPTS, YPTS, RLON, RLAT, NRET, CROT, SROT, XLON, XLAT, YLON, YLAT, AREA)
Calculates Earth coordinates (iopt = 1) or grid coorindates (iopt = -1) for Gaussian grids.
real rerth
Radius of the earth.
real dlon
"i"-direction increment.
subroutine init_grib1(self, g1_desc)
Initializes a gaussian grid given a grib1_descriptor object.
subroutine gaussian_grid_area(YPTS, AREA)
Computes the grid box area for a gaussian cylindrical grid.
subroutine gaussian_vect_rot(CROT, SROT)
Computes the vector rotation sines and cosines for a gaussian cylindrical grid.
subroutine gaussian_map_jacob(YPTS, XLON, XLAT, YLON, YLAT)
Computes the map jacobians for a gaussian cylindrical grid.
subroutine init_grib2(self, g2_desc)
Initializes a gaussian grid given a grib2_descriptor object.
real, dimension(:), allocatable blat
Gaussian latitude for each parallel.
integer j1
'j' index of first grid point within the global array of latitudes.
Users derived type grid descriptor objects to abstract away the raw GRIB1 and GRIB2 grid definitions.
subroutine splat(IDRT, JMAX, SLAT, WLAT)
Computes cosines of colatitude and Gaussian weights for one of the following specific global sets of ...
Descriptor representing a grib1 grib descriptor section (GDS) with an integer array.
Abstract grid that holds fields and methods common to all grids.