NCEPLIBS-ip 5.3.0
All Data Structures Namespaces Files Functions Variables Pages
gdswzd_mod.F90
Go to the documentation of this file.
1!> @file
2!! @brief Driver module for gdswzd routines.
3!!
4!! @date Jan 2015
5!! @author George Gayno, Kyle Gerheiser
6
7!> @brief Driver module for gdswzd routines.
8!!
9!! These routines do the following for several map projections:
10!! - Convert from earth to grid coordinates or vice versa.
11!! - Compute vector rotation sines and cosines.
12!! - Compute map jacobians.
13!! - Compute grid box area.
14!!
15!! Map projections include:
16!! - Equidistant Cyclindrical
17!! - Mercator Cylindrical
18!! - Gaussian Cylindrical
19!! - Polar stereographic
20!! - Lambert Conformal Conic
21!! - Rotated Equidistant Cyclindrical ("E" and non-"E" staggers)
22!!
23!! @author Mark Iredell, George Gayno, Kyle Gerheiser
24!! @date Jan 2015
27 use ip_grids_mod
28 use ip_grid_mod
30
31 IMPLICIT NONE
32
33 PRIVATE
34
36
37 INTERFACE gdswzd
38 MODULE PROCEDURE gdswzd_1d_array
39 MODULE PROCEDURE gdswzd_2d_array
40 MODULE PROCEDURE gdswzd_scalar
41 module procedure gdswzd_grib1
42 module procedure gdswzd_2d_array_grib1
43 module procedure gdswzd_grid
44 END INTERFACE gdswzd
45
46CONTAINS
47
48 !> Returns one of the following for a grid object:
49 !! - iopt=0 Grid and earth coordinates of all grid points.
50 !! - iopt=+1 Earth coordinates of selected grid coordinates.
51 !! - iopt=-1 Grid coordinates of selected earth coordinates.
52 !!
53 !! If the selected coordinates are more than one gridpoint
54 !! beyond the the edges of the grid domain, then the relevant
55 !! output elements are set to fill values. Also if iopt=0,
56 !! if the number of grid points exceeds the number allotted,
57 !! then all the output elements are set to fill values.
58 !!
59 !! The actual number of valid points computed is returned too.
60 !!
61 !! Optionally, the vector rotations, map jacobians and
62 !! grid box areas may be returned.
63 !!
64 !! To compute the vector rotations, the optional arguments 'srot' and 'crot'
65 !! must be present. To compute the map jacobians, the
66 !! optional arguments 'xlon', 'xlat', 'ylon', 'ylat' must be present.
67 !!
68 !! To compute the grid box areas, the optional argument
69 !! 'area' must be present.
70 !!
71 !! @param[in] grid Grid to call gdswzd on.
72 !!
73 !! @param[in] iopt Option flag.
74 !! - 0 Earth coords of all the grid points.
75 !! - 1 Earth coords of selected grid coords.
76 !! - -1 Grid coords of selected earth coords
77 !!
78 !! @param[in] npts Maximum number of coordinates.
79 !! @param[in] fill Fill value to set invalid output data.
80 !! Must be impossible value; suggested value: -9999.
81 !! @param[inout] xpts Grid x point coordinates.
82 !! @param[inout] ypts Grid y point coordinates.
83 !! @param[inout] rlon Earth longitudes in degrees E.
84 !! (Acceptable range: -360. to 360.)
85 !!
86 !! @param[inout] rlat Earth latitudes in degrees N.
87 !! (Acceptable range: -90. to 90.)
88 !!
89 !! @param[out] nret Number of valid points computed.
90 !! @param[out] crot Clockwise vector rotation cosines.
91 !! @param[out] srot Clockwise vector rotation sines.
92 !! ugrid=crot*uearth-srot*vearth;
93 !! vgrid=srot*uearth+crot*vearth)
94 !!
95 !! @param[out] xlon dx/dlat in 1/degrees
96 !! @param[out] xlat dy/dlon in 1/degrees
97 !! @param[out] ylon dy/dlon in 1/degrees
98 !! @param[out] ylat dy/dlat in 1/degrees
99 !! @param[out] area Area weights in m^2.
100 !! Proportional to the square of the map factor in the case of
101 !! conformal projections
102 !!
103 !! @author Kyle Gerheiser
104 !! @date July 2021
105 subroutine gdswzd_grid(grid,IOPT,NPTS,FILL, &
106 XPTS,YPTS,RLON,RLAT,NRET, &
107 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
108
109 class(ip_grid), intent(in) :: grid
110 INTEGER, INTENT(IN ) :: IOPT, NPTS
111 INTEGER, INTENT( OUT) :: NRET
112 !
113 REAL, INTENT(IN ) :: FILL
114 REAL, INTENT(INOUT) :: RLON(NPTS),RLAT(NPTS)
115 REAL, INTENT(INOUT) :: XPTS(NPTS),YPTS(NPTS)
116 REAL, OPTIONAL, INTENT( OUT) :: CROT(NPTS),SROT(NPTS)
117 REAL, OPTIONAL, INTENT( OUT) :: XLON(NPTS),XLAT(NPTS)
118 REAL, OPTIONAL, INTENT( OUT) :: YLON(NPTS),YLAT(NPTS),AREA(NPTS)
119
120 INTEGER :: IS1, IM, JM, NM, KSCAN, NSCAN, N
121 INTEGER :: IOPF, NN, I, J
122
123 ! COMPUTE GRID COORDINATES FOR ALL GRID POINTS
124 IF(iopt.EQ.0) THEN
125 iopf=1
126
127 if(grid%descriptor%grid_num.eq.-1)then
128 nm = npts
129 else
130 im = grid%im
131 jm = grid%jm
132 nm = im * jm
133 endif
134 nscan = grid%nscan
135 kscan = grid%kscan
136
137 if (nm > npts) then
138 rlat=fill
139 rlon=fill
140 xpts=fill
141 ypts=fill
142 return
143 end if
144
145 select type(grid)
146 type is(ip_rot_equid_cylind_egrid)
147 if(kscan == 0) then
148 is1 = (jm + 1) / 2
149 else
150 is1 = jm / 2
151 end if
152
153 DO n=1,nm
154 IF(nscan.EQ.0) THEN
155 j=(n-1)/im+1
156 i=(n-im*(j-1))*2-mod(j+kscan,2)
157 ELSE
158 nn=(n*2)-1+kscan
159 i = (nn-1)/jm + 1
160 j = mod(nn-1,jm) + 1
161 IF (mod(jm,2)==0.AND.mod(i,2)==0.AND.kscan==0) j = j + 1
162 IF (mod(jm,2)==0.AND.mod(i,2)==0.AND.kscan==1) j = j - 1
163 ENDIF
164 xpts(n)=is1+(i-(j-kscan))/2
165 ypts(n)=(i+(j-kscan))/2
166 ENDDO
167 type is(ip_station_points_grid)
168 DO n=1,nm
169 xpts(n)=fill
170 ypts(n)=fill
171 ENDDO
172 class default
173 DO n=1,nm
174 IF(nscan.EQ.0) THEN
175 j=(n-1)/im+1
176 i=n-im*(j-1)
177 ELSE
178 i=(n-1)/jm+1
179 j=n-jm*(i-1)
180 ENDIF
181 xpts(n)=i
182 ypts(n)=j
183 ENDDO
184 end select
185
186 DO n=nm+1,npts
187 xpts(n)=fill
188 ypts(n)=fill
189 ENDDO
190
191 ELSE ! IOPT /= 0
192 iopf=iopt
193 ENDIF ! IOPT CHECK
194
195 call grid%gdswzd(iopf,npts,fill, &
196 xpts,ypts,rlon,rlat,nret, &
197 crot,srot,xlon,xlat,ylon,ylat,area)
198
199 end subroutine gdswzd_grid
200
201
202 !> Decodes the grib 2 grid definition template and returns
203 !! one of the following (for scalars):
204 !! - iopt=0 Grid and earth coordinates of all grid points.
205 !! - iopt=+1 Earth coordinates of selected grid coordinates.
206 !! - iopt=-1 Grid coordinates of selected earth coordinates.
207 !!
208 !! The current code recognizes the following projections,
209 !! where "igdtnum" is the grid definition template number:
210 !! - igdtnum=00 Equidistant Cylindrical
211 !! - igdtnum=01 Rotated Equidistant Cylindrical. "E" and non-"E" staggered
212 !! - igdtnum=10 Mercator Cyclindrical
213 !! - igdtnum=20 Polar Stereographic Azimuthal
214 !! - igdtnum=30 Lambert Conformal Conical
215 !! - igdtnum=40 Gaussian Equidistant Cyclindrical
216 !!
217 !! If the selected coordinates are more than one gridpoint
218 !! beyond the the edges of the grid domain, then the relevant
219 !! output elements are set to fill values. Also if iopt=0,
220 !! if the number of grid points exceeds the number allotted,
221 !! then all the output elements are set to fill values.
222 !!
223 !! The actual number of valid points computed is returned too.
224 !!
225 !! Optionally, the vector rotations, map jacobians and
226 !! grid box areas may be returned.
227 !!
228 !! To compute the vector rotations, the optional arguments 'srot' and 'crot'
229 !! must be present. To compute the map jacobians, the
230 !! optional arguments 'xlon', 'xlat', 'ylon', 'ylat' must be present.
231 !!
232 !! To compute the grid box areas, the optional argument
233 !! 'area' must be present.
234 !!
235 !! @param[in] igdtnum Grid definition template number.
236 !!
237 !! @param[in] igdtmpl Grid definition template array.
238 !! Corresponds to the gfld%igdtmpl component of the
239 !! NCEPLIBS-g2 gridmod data structure
240 !! See igdtmpl definition in gdswzd_1d_array() for full details.
241 !!
242 !! @param[in] igdtlen Number of elements of the grid definition
243 !! template array. Corresponds to the gfld%igdtlen
244 !! component of the ncep g2 library gridmod data structure.
245 !!
246 !! @param[in] iopt Option flag.
247 !! - 0 Earth coords of all the grid points.
248 !! - 1 Earth coords of selected grid coords.
249 !! - -1 Grid coords of selected earth coords
250 !!
251 !! @param[in] npts Maximum number of coordinates.
252 !! @param[in] fill Fill value to set invalid output data.
253 !! Must be impossible value; suggested value: -9999.
254 !! @param[inout] xpts Grid x point coordinates.
255 !! @param[inout] ypts Grid y point coordinates.
256 !! @param[inout] rlon Earth longitudes in degrees E.
257 !! (Acceptable range: -360. to 360.)
258 !!
259 !! @param[inout] rlat Earth latitudes in degrees N.
260 !! (Acceptable range: -90. to 90.)
261 !!
262 !! @param[out] nret Number of valid points computed.
263 !! @param[out] crot Clockwise vector rotation cosines.
264 !! @param[out] srot Clockwise vector rotation sines.
265 !! ugrid=crot*uearth-srot*vearth;
266 !! vgrid=srot*uearth+crot*vearth)
267 !!
268 !! @param[out] xlon dx/dlat in 1/degrees
269 !! @param[out] xlat dy/dlon in 1/degrees
270 !! @param[out] ylon dy/dlon in 1/degrees
271 !! @param[out] ylat dy/dlat in 1/degrees
272 !! @param[out] area Area weights in m^2.
273 !! Proportional to the square of the map factor in the case of
274 !! conformal projections
275 !!
276 !! @author George Gayno, Mark Iredell
277 !! @date Jan 2015
278 SUBROUTINE gdswzd_scalar(IGDTNUM,IGDTMPL,IGDTLEN,IOPT,NPTS,FILL, &
279 XPTS,YPTS,RLON,RLAT,NRET, &
280 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
281
282 IMPLICIT NONE
283 !
284 INTEGER, INTENT(IN ) :: IGDTNUM, IGDTLEN
285 INTEGER, INTENT(IN ) :: IGDTMPL(IGDTLEN)
286 INTEGER, INTENT(IN ) :: IOPT, NPTS
287 INTEGER, INTENT( OUT) :: NRET
288 !
289 REAL, INTENT(IN ) :: FILL
290 REAL, INTENT(INOUT) :: RLON, RLAT
291 REAL, INTENT(INOUT) :: XPTS, YPTS
292 REAL, OPTIONAL, INTENT( OUT) :: CROT, SROT
293 REAL, OPTIONAL, INTENT( OUT) :: XLON, XLAT
294 REAL, OPTIONAL, INTENT( OUT) :: YLON, YLAT, AREA
295
296 REAL :: RLONA(1),RLATA(1)
297 REAL :: XPTSA(1),YPTSA(1)
298 REAL :: CROTA(1),SROTA(1)
299 REAL :: XLONA(1),XLATA(1)
300 REAL :: YLONA(1),YLATA(1),AREAA(1)
301
302 rlona(1) = rlon
303 rlata(1) = rlat
304 xptsa(1) = xpts
305 yptsa(1) = ypts
306
307 nret = 0
308
309 ! CALL WITHOUT EXTRA FIELDS.
310
311 IF (.NOT. PRESENT(crot) .AND. &
312 .NOT. PRESENT(srot) .AND. &
313 .NOT. PRESENT(xlon) .AND. &
314 .NOT. PRESENT(xlat) .AND. &
315 .NOT. PRESENT(ylon) .AND. &
316 .NOT. PRESENT(ylat) .AND. &
317 .NOT. PRESENT(area) ) THEN
318
319 CALL gdswzd_1d_array(igdtnum,igdtmpl,igdtlen,iopt,npts,fill, &
320 xptsa,yptsa,rlona,rlata,nret)
321
322 rlon = rlona(1)
323 rlat = rlata(1)
324 xpts = xptsa(1)
325 ypts = yptsa(1)
326
327 ENDIF
328
329 ! MIMIC CALL TO OLD 'GDSWIZ' ROUTINES.
330
331 IF (PRESENT(crot) .AND. &
332 PRESENT(srot) .AND. &
333 .NOT. PRESENT(xlon) .AND. &
334 .NOT. PRESENT(xlat) .AND. &
335 .NOT. PRESENT(ylon) .AND. &
336 .NOT. PRESENT(ylat) .AND. &
337 .NOT. PRESENT(area) ) THEN
338
339 CALL gdswzd_1d_array(igdtnum,igdtmpl,igdtlen,iopt,npts,fill, &
340 xptsa,yptsa,rlona,rlata,nret,crota,srota)
341
342 rlon = rlona(1)
343 rlat = rlata(1)
344 xpts = xptsa(1)
345 ypts = yptsa(1)
346 crot = crota(1)
347 srot = srota(1)
348
349 ENDIF
350
351 ! MIMIC CALL TO OLD 'GDSWZD' ROUTINES.
352
353 IF (PRESENT(crot) .AND. &
354 PRESENT(srot) .AND. &
355 PRESENT(xlon) .AND. &
356 PRESENT(xlat) .AND. &
357 PRESENT(ylon) .AND. &
358 PRESENT(ylat) .AND. &
359 PRESENT(area) ) THEN
360
361 CALL gdswzd_1d_array(igdtnum,igdtmpl,igdtlen,iopt,npts,fill, &
362 xptsa,yptsa,rlona,rlata,nret, &
363 crota,srota,xlona,xlata,ylona,ylata,areaa)
364
365 rlon = rlona(1)
366 rlat = rlata(1)
367 xpts = xptsa(1)
368 ypts = yptsa(1)
369 crot = crota(1)
370 srot = srota(1)
371 xlon = xlona(1)
372 xlat = xlata(1)
373 ylon = ylona(1)
374 ylat = ylata(1)
375 area = areaa(1)
376
377 ENDIF
378
379 RETURN
380
381 END SUBROUTINE gdswzd_scalar
382
383 !> Decodes the grib 2 grid definition template and returns
384 !! one of the following (for 2d-arrays):
385 !! - iopt=0 Grid and earth coordinates of all grid points.
386 !! - iopt=+1 Earth coordinates of selected grid coordinates.
387 !! - iopt=-1 Grid coordinates of selected earth coordinates.
388 !!
389 !! The current code recognizes the following projections,
390 !! where "igdtnum" is the grid definition template number:
391 !! - igdtnum=00 Equidistant Cylindrical
392 !! - igdtnum=01 Rotated Equidistant Cylindrical. "E" and non-"E" staggered
393 !! - igdtnum=10 Mercator Cyclindrical
394 !! - igdtnum=20 Polar Stereographic Azimuthal
395 !! - igdtnum=30 Lambert Conformal Conical
396 !! - igdtnum=40 Gaussian Equidistant Cyclindrical
397 !!
398 !! If the selected coordinates are more than one gridpoint
399 !! beyond the the edges of the grid domain, then the relevant
400 !! output elements are set to fill values. Also if iopt=0,
401 !! if the number of grid points exceeds the number allotted,
402 !! then all the output elements are set to fill values.
403 !!
404 !! The actual number of valid points computed is returned too.
405 !!
406 !! Optionally, the vector rotations, map jacobians and
407 !! grid box areas may be returned.
408 !!
409 !! To compute the vector rotations, the optional arguments 'srot' and 'crot'
410 !! must be present. To compute the map jacobians, the
411 !! optional arguments 'xlon', 'xlat', 'ylon', 'ylat' must be present.
412 !!
413 !! To compute the grid box areas, the optional argument
414 !! 'area' must be present.
415 !!
416 !! @param[in] igdtnum Grid definition template number.
417 !!
418 !! @param[in] igdtmpl Grid definition template array.
419 !! Corresponds to the gfld%igdtmpl component of the
420 !! NCEPLIBS-g2 gridmod data structure.
421 !! See igdtmpl definition in gdswzd_1d_array() for full details.
422 !!
423 !! @param[in] igdtlen Number of elements of the grid definition
424 !! template array. Corresponds to the gfld%igdtlen
425 !! component of the ncep g2 library gridmod data structure.
426 !!
427 !! @param[in] iopt Option flag.
428 !! - 0 Earth coords of all the grid points.
429 !! - 1 Earth coords of selected grid coords.
430 !! - -1 Grid coords of selected earth coords
431 !!
432 !! @param[in] npts Maximum number of coordinates.
433 !! @param[in] fill Fill value to set invalid output data.
434 !! Must be impossible value; suggested value: -9999.
435 !! @param[inout] xpts Grid x point coordinates.
436 !! @param[inout] ypts Grid y point coordinates.
437 !! @param[inout] rlon Earth longitudes in degrees E.
438 !! (Acceptable range: -360. to 360.)
439 !!
440 !! @param[inout] rlat Earth latitudes in degrees N.
441 !! (Acceptable range: -90. to 90.)
442 !!
443 !! @param[out] nret Number of valid points computed.
444 !! @param[out] crot Clockwise vector rotation cosines.
445 !! @param[out] srot Clockwise vector rotation sines.
446 !! ugrid=crot*uearth-srot*vearth;
447 !! vgrid=srot*uearth+crot*vearth)
448 !!
449 !! @param[out] xlon dx/dlat in 1/degrees
450 !! @param[out] xlat dy/dlon in 1/degrees
451 !! @param[out] ylon dy/dlon in 1/degrees
452 !! @param[out] ylat dy/dlat in 1/degrees
453 !! @param[out] area Area weights in m^2.
454 !! Proportional to the square of the map factor in the case of
455 !! conformal projections
456 !!
457 !! @author George Gayno, Mark Iredell
458 !! @date Jan 2015
459 SUBROUTINE gdswzd_2d_array(IGDTNUM,IGDTMPL,IGDTLEN,IOPT,NPTS,FILL, &
460 XPTS,YPTS,RLON,RLAT,NRET, &
461 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
462
463 IMPLICIT NONE
464 !
465 INTEGER, INTENT(IN ) :: IGDTNUM, IGDTLEN
466 INTEGER, INTENT(IN ) :: IGDTMPL(IGDTLEN)
467 INTEGER, INTENT(IN ) :: IOPT, NPTS
468 INTEGER, INTENT( OUT) :: NRET
469 !
470 REAL, INTENT(IN ) :: FILL
471 REAL, INTENT(INOUT) :: RLON(:,:),RLAT(:,:)
472 REAL, INTENT(INOUT) :: XPTS(:,:),YPTS(:,:)
473 REAL, OPTIONAL, INTENT( OUT) :: CROT(:,:),SROT(:,:)
474 REAL, OPTIONAL, INTENT( OUT) :: XLON(:,:),XLAT(:,:)
475 REAL, OPTIONAL, INTENT( OUT) :: YLON(:,:),YLAT(:,:),AREA(:,:)
476
477 CALL gdswzd_1d_array(igdtnum,igdtmpl,igdtlen,iopt,npts,fill, &
478 xpts,ypts,rlon,rlat,nret, &
479 crot,srot,xlon,xlat,ylon,ylat,area)
480
481 END SUBROUTINE gdswzd_2d_array
482
483 !> Decodes the grib 2 grid definition template and returns one of the following:
484 !! - iopt=0 Grid and earth coordinates of all grid points.
485 !! - iopt=+1 Earth coordinates of selected grid coordinates.
486 !! - iopt=-1 Grid coordinates of selected earth coordinates.
487 !!
488 !! The current code recognizes the following projections,
489 !! where "igdtnum" is the grid definition template number:
490 !! - igdtnum=00 Equidistant Cylindrical
491 !! - igdtnum=01 Rotated Equidistant Cylindrical. "E" and non-"E" staggered
492 !! - igdtnum=10 Mercator Cyclindrical
493 !! - igdtnum=20 Polar Stereographic Azimuthal
494 !! - igdtnum=30 Lambert Conformal Conical
495 !! - igdtnum=40 Gaussian Equidistant Cyclindrical
496 !!
497 !! If the selected coordinates are more than one gridpoint
498 !! beyond the the edges of the grid domain, then the relevant
499 !! output elements are set to fill values. Also if iopt=0,
500 !! if the number of grid points exceeds the number allotted,
501 !! then all the output elements are set to fill values.
502 !!
503 !! The actual number of valid points computed is returned too.
504 !!
505 !! Optionally, the vector rotations, map jacobians and
506 !! grid box areas may be returned.
507 !!
508 !! To compute the vector rotations, the optional arguments 'srot' and 'crot'
509 !! must be present. To compute the map jacobians, the
510 !! optional arguments 'xlon', 'xlat', 'ylon', 'ylat' must be present.
511 !!
512 !! To compute the grid box areas, the optional argument
513 !! 'area' must be present.
514 !!
515 !! @param[in] igdtnum Grid definition template number.
516 !! Corresponds to the gfld%igdtnum component of the ncep g2 library
517 !! gridmod data structure:
518 !! - 00 - Equidistant Cylindrical
519 !! - 01 - Rotated Equidistant Cylindrical. "E" and non-"E" staggered
520 !! - 10 - Mercator Cyclindrical
521 !! - 20 - Polar Stereographic Azimuthal
522 !! - 30 - Lambert Conformal Conical
523 !! - 40 - Gaussian Equidistant Cyclindrical
524 !!
525 !! @param[in] igdtmpl Grid definition template array.
526 !! Corresponds to the gfld%igdtmpl component of the
527 !! NCEPLIBS-g2 gridmod data structure
528 !!
529 !! Section 3 Info:
530 !!
531 !! All Map Projections:
532 !! - 1: Shape of earth, octet 15.
533 !! - 2: Scale factor of spherical earth radius, octet 16.
534 !! - 3: Scaled value of radius of spherical earth, octets 17-20.
535 !! - 4: Scale factor of major axis of elliptical earth, octet 21.
536 !! - 5: Scaled value of major axis of elliptical earth, octets 22-25.
537 !! - 6: Scale factor of minor axis of elliptical earth, octet 26.
538 !! - 7: Scaled value of minor axis of elliptical earth, octets 27-30.
539 !!
540 !! Equidistant Cyclindrical:
541 !! - 8: Number of points along a parallel, octs 31-34.
542 !! - 9: Number of points along a meridian, octs 35-38.
543 !! - 10: Basic angle of initial production domain, octets 39-42.
544 !! - 11: Subdivisions of basic angle, octets 43-46.
545 !! - 12: Latitude of first grid point, octets 47-50.
546 !! - 13: Longitude of first grid point, octets 51-54.
547 !! - 14: Resolution and component flags, octet 55.
548 !! - 15: Latitude of last grid point, octets 56-59.
549 !! - 16: Longitude of last grid point, octets 60-63.
550 !! - 17: i-direction increment, octets 64-67.
551 !! - 18: j-direction increment, octets 68-71.
552 !! - 19: Scanning mode, octet 72.
553 !!
554 !! Mercator Cyclindrical:
555 !! - 8: Number of points along a parallel, octs 31-34.
556 !! - 9: Number of points along a meridian, octs 35-38.
557 !! - 10: Latitude of first point, octets 39-42.
558 !! - 11: Longitude of first point, octets 43-46.
559 !! - 12: Resolution and component flags, octet 47.
560 !! - 13: Tangent latitude, octets 48-51.
561 !! - 14: Latitude of last point, octets 52-55.
562 !! - 15: Longitude of last point, octets 56-59.
563 !! - 16: Scanning mode flags, octet 60.
564 !! - 17: Orientation of grid, octets 61-64.
565 !! - 18: Longitudinal grid length, octets 65-68.
566 !! - 19: Latitudinal grid length, octets 69-72.
567 !!
568 !! Lambert Conformal Conical:
569 !! - 8: Number of points along x-axis, octs 31-34.
570 !! - 9: Number of points along y-axis, octs 35-38.
571 !! - 10: Latitude of first point, octets 39-42.
572 !! - 11: Longitude of first point, octets 43-46.
573 !! - 12: Resolution of component flag, octet 47.
574 !! - 13: Latitude where grid lengths specified,octets 48-51.
575 !! - 14: Longitude of meridian that is parallel to y-axis, octets 52-55.
576 !! - 15: x-direction grid length, octets 56-59.
577 !! - 16: y-direction grid length, octets 60-63.
578 !! - 17: Projection center flag, octet 64.
579 !! - 18: Scanning mode, octet 65.
580 !! - 19: First tangent latitude from pole, octets 66-69.
581 !! - 20: Second tangent latitude from pole, octets 70-73.
582 !! - 21: Latitude of south pole of projection, octets 74-77.
583 !! - 22: Longitude of south pole of projection, octets 78-81.
584 !!
585 !! Gaussian Cylindrical:
586 !! - 8: Number of points along a parallel, octs 31-34.
587 !! - 9: Number of points along a meridian, octs 35-38.
588 !! - 10: Basic angle of initial production domain, octets 39-42.
589 !! - 11: Subdivisions of basic angle, octets 43-46.
590 !! - 12: Latitude of first grid point, octets 47-50.
591 !! - 13: Longitude of first grid point, octets 51-54.
592 !! - 14: Resolution and component flags, octet 55.
593 !! - 15: Latitude of last grid point, octets 56-59.
594 !! - 16: Longitude of last grid point, octets 60-63.
595 !! - 17: i-direction increment, octets 64-67.
596 !! - 18: Number of parallels between pole and equator, octets 68-71.
597 !! - 19: Scanning mode, octet 72.
598 !!
599 !! Polar Stereographic Azimuthal:
600 !! - 8: Number of points along x-axis, octets 31-34.
601 !! - 9: Number of points along y-axis, octets 35-38.
602 !! - 10: Latitude of first grid point, octets 39-42.
603 !! - 11: Longitude of first grid point, octets 43-46.
604 !! - 12: Resolution and component flags, octet 47.
605 !! - 13: True latitude, octets 48-51.
606 !! - 14: Orientation longitude, octets 52-55.
607 !! - 15: x-direction grid length, octets 56-59.
608 !! - 16: y-direction grid length, octets 60-63.
609 !! - 17: Projection center flag, octet 64.
610 !! - 18: Scanning mode flags, octet 65.
611 !!
612 !! Rotated Equidistant Cyclindrical:
613 !! - 8: Number of points along a parallel, octs 31-34.
614 !! - 9: Number of points along a meridian, octs 35-38.
615 !! - 10: Basic angle of initial production domain, octets 39-42.
616 !! - 11: Subdivisions of basic angle, octets 43-46.
617 !! - 12: Latitude of first grid point, octets 47-50.
618 !! - 13: Longitude of first grid point, octets 51-54.
619 !! - 14: Resolution and component flags, octet 55.
620 !! - 15: Latitude of last grid point, octets 56-59.
621 !! - 16: Longitude of last grid point, octets 60-63.
622 !! - 17: i-direction increment, octets 64-67.
623 !! - 18: j-direction increment, octets 68-71.
624 !! - 19: Scanning mode, octet 72.
625 !! - 20: Latitude of southern pole of projection, octets 73-76.
626 !! - 21: Longitude of southern pole of projection, octets 77-80.
627 !! - 22: Angle of rotation of projection, octs 81-84.
628 !!
629 !! @param[in] igdtlen Number of elements of the grid definition
630 !! template array. Corresponds to the gfld%igdtlen
631 !! component of the ncep g2 library gridmod data structure.
632 !!
633 !! @param[in] iopt Option flag.
634 !! - 0 Earth coords of all the grid points.
635 !! - 1 Earth coords of selected grid coords.
636 !! - -1 Grid coords of selected earth coords
637 !!
638 !! @param[in] npts Maximum number of coordinates.
639 !! @param[in] fill Fill value to set invalid output data.
640 !! Must be impossible value; suggested value: -9999.
641 !! @param[inout] xpts Grid x point coordinates.
642 !! @param[inout] ypts Grid y point coordinates.
643 !! @param[inout] rlon Earth longitudes in degrees E.
644 !! (Acceptable range: -360. to 360.)
645 !!
646 !! @param[inout] rlat Earth latitudes in degrees N.
647 !! (Acceptable range: -90. to 90.)
648 !!
649 !! @param[out] nret Number of valid points computed.
650 !! @param[out] crot Clockwise vector rotation cosines.
651 !! @param[out] srot Clockwise vector rotation sines.
652 !! ugrid=crot*uearth-srot*vearth;
653 !! vgrid=srot*uearth+crot*vearth)
654 !!
655 !! @param[out] xlon dx/dlat in 1/degrees
656 !! @param[out] xlat dy/dlon in 1/degrees
657 !! @param[out] ylon dy/dlon in 1/degrees
658 !! @param[out] ylat dy/dlat in 1/degrees
659 !! @param[out] area Area weights in m^2.
660 !! Proportional to the square of the map factor in the case of
661 !! conformal projections
662 !!
663 !! @author George Gayno, Mark Iredell
664 !! @date Jan 2015
665 SUBROUTINE gdswzd_1d_array(IGDTNUM,IGDTMPL,IGDTLEN,IOPT,NPTS,FILL, &
666 XPTS,YPTS,RLON,RLAT,NRET, &
667 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
668 INTEGER, INTENT(IN ) :: IGDTNUM, IGDTLEN
669 INTEGER, INTENT(IN ) :: IGDTMPL(IGDTLEN)
670 INTEGER, INTENT(IN ) :: IOPT, NPTS
671 INTEGER, INTENT( OUT) :: NRET
672 !
673 REAL, INTENT(IN ) :: FILL
674 REAL, INTENT(INOUT) :: RLON(NPTS),RLAT(NPTS)
675 REAL, INTENT(INOUT) :: XPTS(NPTS),YPTS(NPTS)
676 REAL, OPTIONAL, INTENT( OUT) :: CROT(NPTS),SROT(NPTS)
677 REAL, OPTIONAL, INTENT( OUT) :: XLON(NPTS),XLAT(NPTS)
678 REAL, OPTIONAL, INTENT( OUT) :: YLON(NPTS),YLAT(NPTS),AREA(NPTS)
679
680 type(grib2_descriptor) :: desc
681 class(ip_grid), allocatable :: grid
682
683 desc = init_descriptor(igdtnum, igdtlen, igdtmpl)
684 call init_grid(grid, desc)
685
686 call gdswzd_grid(grid,iopt,npts,fill, &
687 xpts,ypts,rlon,rlat,nret, &
688 crot,srot,xlon,xlat,ylon,ylat,area)
689
690 END SUBROUTINE gdswzd_1d_array
691
692 !> Decodes the grib grid description section and
693 !! returns one of the following (for 1-d arrays):
694 !! - iopt=0 Grid and earth coordinates of all grid points.
695 !! - iopt=+1 Earth coordinates of selected grid coordinates.
696 !! - iopt=-1 Grid coordinates of selected earth coordinates.
697 !!
698 !! If the selected coordinates are more than one gridpoint
699 !! beyond the the edges of the grid domain, then the relevant
700 !! output elements are set to fill values. Also if iopt=0,
701 !! if the number of grid points exceeds the number allotted,
702 !! then all the output elements are set to fill values.
703 !!
704 !! The actual number of valid points computed is returned too.
705 !!
706 !! Optionally, the vector rotations, map jacobians and
707 !! grid box areas may be returned.
708 !!
709 !! To compute the vector rotations, the optional arguments 'srot' and 'crot'
710 !! must be present. To compute the map jacobians, the
711 !! optional arguments 'xlon', 'xlat', 'ylon', 'ylat' must be present.
712 !!
713 !! To compute the grid box areas, the optional argument
714 !! 'area' must be present.
715 !!
716 !! The current code recognizes the following projections:
717 !! - kgds(1)=000 Equidistant Cylindrical
718 !! - kgds(1)=001 Mercator Cylindrical
719 !! - kgds(1)=003 lambert Conformal Conical
720 !! - kgds(1)=004 Gaussian Cylindrical
721 !! - kgds(1)=005 Polar Stereographic azimuthal
722 !! - kgds(1)=203 E-staggered Rotated Equidistant Cylindrical
723 !! - kgds(1)=205 B-staggered Rotated Equidistant Cylindrical
724 !!
725 !! @param[in] kgds GDS parameters as decoded by w3fi63.
726 !! @param[in] iopt Option flag.
727 !! - 0 Earth coords of all the grid points.
728 !! - 1 Earth coords of selected grid coords.
729 !! - -1 Grid coords of selected earth coords
730 !!
731 !! @param[in] npts Maximum number of coordinates.
732 !! @param[in] fill Fill value to set invalid output data.
733 !! Must be impossible value; suggested value: -9999.
734 !! @param[inout] xpts Grid x point coordinates.
735 !! @param[inout] ypts Grid y point coordinates.
736 !! @param[inout] rlon Earth longitudes in degrees E.
737 !! (Acceptable range: -360. to 360.)
738 !!
739 !! @param[inout] rlat Earth latitudes in degrees N.
740 !! (Acceptable range: -90. to 90.)
741 !!
742 !! @param[out] nret Number of valid points computed.
743 !! @param[out] crot Clockwise vector rotation cosines.
744 !! @param[out] srot Clockwise vector rotation sines.
745 !! ugrid=crot*uearth-srot*vearth;
746 !! vgrid=srot*uearth+crot*vearth)
747 !!
748 !! @param[out] xlon dx/dlat in 1/degrees
749 !! @param[out] xlat dy/dlon in 1/degrees
750 !! @param[out] ylon dy/dlon in 1/degrees
751 !! @param[out] ylat dy/dlat in 1/degrees
752 !! @param[out] area Area weights in m^2.
753 !! Proportional to the square of the map factor in the case of
754 !! conformal projections
755 !!
756 !! @author George Gayno, Mark Iredell
757 !! @date April 1996
758 SUBROUTINE gdswzd_grib1(KGDS,IOPT,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET, &
759 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
760 INTEGER, INTENT(IN ) :: IOPT, KGDS(200), NPTS
761 INTEGER, INTENT( OUT) :: NRET
762 !
763 REAL, INTENT(IN ) :: FILL
764 REAL, INTENT(INOUT) :: RLON(NPTS),RLAT(NPTS)
765 REAL, INTENT(INOUT) :: XPTS(NPTS),YPTS(NPTS)
766 REAL, OPTIONAL, INTENT( OUT) :: CROT(NPTS),SROT(NPTS)
767 REAL, OPTIONAL, INTENT( OUT) :: XLON(NPTS),XLAT(NPTS)
768 REAL, OPTIONAL, INTENT( OUT) :: YLON(NPTS),YLAT(NPTS),AREA(NPTS)
769
770
771 type(grib1_descriptor) :: desc
772 class(ip_grid), allocatable :: grid
773
774 desc = init_descriptor(kgds)
775 call init_grid(grid, desc)
776
777 call gdswzd_grid(grid,iopt,npts,fill, &
778 xpts,ypts,rlon,rlat,nret, &
779 crot,srot,xlon,xlat,ylon,ylat,area)
780
781 END SUBROUTINE gdswzd_grib1
782
783
784 !> Decodes the grib grid description section and returns
785 !! one of the following (for 2-d arrays):
786 !! - iopt=0 Grid and earth coordinates of all grid points.
787 !! - iopt=+1 Earth coordinates of selected grid coordinates.
788 !! - iopt=-1 Grid coordinates of selected earth coordinates.
789 !!
790 !! If the selected coordinates are more than one gridpoint
791 !! beyond the the edges of the grid domain, then the relevant
792 !! output elements are set to fill values. Also if iopt=0,
793 !! if the number of grid points exceeds the number allotted,
794 !! then all the output elements are set to fill values.
795 !!
796 !! The actual number of valid points computed is returned too.
797 !!
798 !! Optionally, the vector rotations, map jacobians and
799 !! grid box areas may be returned.
800 !!
801 !! To compute the vector rotations, the optional arguments 'srot' and 'crot'
802 !! must be present. To compute the map jacobians, the
803 !! optional arguments 'xlon', 'xlat', 'ylon', 'ylat' must be present.
804 !!
805 !! To compute the grid box areas, the optional argument
806 !! 'area' must be present.
807 !!
808 !! The current code recognizes the following projections:
809 !! - kgds(1)=000 Equidistant Cylindrical
810 !! - kgds(1)=001 Mercator Cylindrical
811 !! - kgds(1)=003 lambert Conformal Conical
812 !! - kgds(1)=004 Gaussian Cylindrical
813 !! - kgds(1)=005 Polar Stereographic azimuthal
814 !! - kgds(1)=203 E-staggered Rotated Equidistant Cylindrical
815 !! - kgds(1)=205 B-staggered Rotated Equidistant Cylindrical
816 !!
817 !! @param[in] kgds GDS parameters as decoded by w3fi63.
818 !! @param[in] iopt Option flag.
819 !! - 0 Earth coords of all the grid points.
820 !! - 1 Earth coords of selected grid coords.
821 !! - -1 Grid coords of selected earth coords
822 !!
823 !! @param[in] npts Maximum number of coordinates.
824 !! @param[in] fill Fill value to set invalid output data.
825 !! Must be impossible value; suggested value: -9999.
826 !! @param[inout] xpts Grid x point coordinates.
827 !! @param[inout] ypts Grid y point coordinates.
828 !! @param[inout] rlon Earth longitudes in degrees E.
829 !! (Acceptable range: -360. to 360.)
830 !!
831 !! @param[inout] rlat Earth latitudes in degrees N.
832 !! (Acceptable range: -90. to 90.)
833 !!
834 !! @param[out] nret Number of valid points computed.
835 !! @param[out] crot Clockwise vector rotation cosines.
836 !! @param[out] srot Clockwise vector rotation sines.
837 !! ugrid=crot*uearth-srot*vearth;
838 !! vgrid=srot*uearth+crot*vearth)
839 !!
840 !! @param[out] xlon dx/dlat in 1/degrees
841 !! @param[out] xlat dy/dlon in 1/degrees
842 !! @param[out] ylon dy/dlon in 1/degrees
843 !! @param[out] ylat dy/dlat in 1/degrees
844 !! @param[out] area Area weights in m^2.
845 !! Proportional to the square of the map factor in the case of
846 !! conformal projections
847 !!
848 !! @author George Gayno, Mark Iredell
849 !! @date April 1996
850 SUBROUTINE gdswzd_2d_array_grib1(KGDS,IOPT,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET, &
851 CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
852
853 !$$$
854 INTEGER, INTENT(IN ) :: IOPT, KGDS(200), NPTS
855 INTEGER, INTENT( OUT) :: NRET
856 !
857 REAL, INTENT(IN ) :: FILL
858 REAL, INTENT(INOUT) :: RLON(:,:),RLAT(:,:)
859 REAL, INTENT(INOUT) :: XPTS(:,:),YPTS(:,:)
860 REAL, OPTIONAL, INTENT( OUT) :: CROT(:,:),SROT(:,:)
861 REAL, OPTIONAL, INTENT( OUT) :: XLON(:,:),XLAT(:,:)
862 REAL, OPTIONAL, INTENT( OUT) :: YLON(:,:),YLAT(:,:),AREA(:,:)
863
864
865 type(grib1_descriptor) :: desc
866 class(ip_grid), allocatable :: grid
867
868 desc = init_descriptor(kgds)
869 call init_grid(grid, desc)
870
871 call gdswzd_grid(grid,iopt,npts,fill, &
872 xpts,ypts,rlon,rlat,nret, &
873 crot,srot,xlon,xlat,ylon,ylat,area)
874
875 END SUBROUTINE gdswzd_2d_array_grib1
876
877
878
879END MODULE gdswzd_mod
Driver module for gdswzd routines.
subroutine gdswzd_grid(grid, iopt, npts, fill, xpts, ypts, rlon, rlat, nret, crot, srot, xlon, xlat, ylon, ylat, area)
Returns one of the following for a grid object:
subroutine gdswzd_1d_array(igdtnum, igdtmpl, igdtlen, iopt, npts, fill, xpts, ypts, rlon, rlat, nret, crot, srot, xlon, xlat, ylon, ylat, area)
Decodes the grib 2 grid definition template and returns one of the following:
subroutine, public gdswzd_grib1(kgds, iopt, npts, fill, xpts, ypts, rlon, rlat, nret, crot, srot, xlon, xlat, ylon, ylat, area)
Decodes the grib grid description section and returns one of the following (for 1-d arrays):
subroutine gdswzd_scalar(igdtnum, igdtmpl, igdtlen, iopt, npts, fill, xpts, ypts, rlon, rlat, nret, crot, srot, xlon, xlat, ylon, ylat, area)
Decodes the grib 2 grid definition template and returns one of the following (for scalars):
subroutine, public gdswzd_2d_array_grib1(kgds, iopt, npts, fill, xpts, ypts, rlon, rlat, nret, crot, srot, xlon, xlat, ylon, ylat, area)
Decodes the grib grid description section and returns one of the following (for 2-d arrays):
subroutine gdswzd_2d_array(igdtnum, igdtmpl, igdtlen, iopt, npts, fill, xpts, ypts, rlon, rlat, nret, crot, srot, xlon, xlat, ylon, ylat, area)
Decodes the grib 2 grid definition template and returns one of the following (for 2d-arrays):
Users derived type grid descriptor objects to abstract away the raw GRIB1 and GRIB2 grid definitions.
Routines for creating an ip_grid given a Grib descriptor.
Abstract ip_grid type.
Re-export the individual grids.
Descriptor representing a grib1 grib descriptor section (GDS) with an integer array.
Grib-2 descriptor containing a grib2 GDT represented by an integer array.
Abstract grid that holds fields and methods common to all grids.