NCEPLIBS-ip 5.3.0
All Data Structures Namespaces Files Functions Variables Pages
ipxwafs3.F90
Go to the documentation of this file.
1!> @file
2!> @brief Expand or contract wafs grids using neighbor interpolation
3!> and accout for bitmapped data.
4!> @author Trojan @date 7-7-13
5
6!> Expand or contract wafs grids using neighbor interpolation
7!> and accout for bitmapped data.
8!>
9!> This subprogram transforms between the thinned wafs grids used for
10!> transmitting to the aviation community and their full expansion as
11!> used for general interpolation and graphics. The thinned wafs grids
12!> are latitude-longitude grids where the number of points in each row
13!> decrease toward the pole. This information is stored in the grib 2
14!> grid definition template (section 3) starting at octet 73.
15!>
16!> The full grid counterparts have an equal number of points per row.
17!>
18!> The transform between the full and thinned wafs wafs grid is done
19!> by linear interpolation and is not reversible. This routine works
20!> with bitmapped data.
21!>
22!> This subroutine is similar to:
23!> - ipxwafs() which uses linear interpolation.
24!> - ipxwafs2() which uses linear interpolation and accounts for
25!> - bitmapped data.
26!>
27!> ### Program History Log
28!> Date | Programmer | Comments
29!> -----|------------|---------
30!> 07-07-13 | Trojan | initial version based on ipxwafs2
31!> 2015-jul | gayno | convert to grib 2
32!>
33!> @param[in] idir integer transform option
34!> - 1 to expand thinned fields to full fields
35!> - -1 to contract full fields to thinned fields
36!> @param[in] numpts_thin integer number of grid points - thinned
37!> grid. Must be 3447.
38!> @param[in] numpts_full integer number of grid points - full
39!> grid. Must be 5329.
40!> @param[in] km integer number of fields to transform
41!> @param[in] num_opt integer number of values to describe the thinned
42!> grid. must be 73. dimension of array opt_pts.
43!> @param[inout] opt_pts integer (num_opt) number of grid points per row -
44!> thinned grid - if idir=+1
45!> @param[in] igdtlen integer grid defintion template array length.
46!> must be 19 for lat/lon grids. corresponds to the gfld%igdtlen
47!> component of the ncep g2 library gridmod data structure. same for
48!> thin and full grids which are both lat/lon.
49!> @param[in] igdtmpl_thin integer (igdtlen) grid definition template
50!> array - thinned grid - if idir=+1. corresponds to the gfld%igdtmpl
51!> component of the ncep g2 library gridmod data structure (section 3
52!> info):
53!> - 1 shape of earth, octet 15
54!> - 2 scale factor of spherical earth radius, octet 16
55!> - 3 scaled value of radius of spherical earth, octets 17-20
56!> - 4 scale factor of major axis of elliptical earth, octet 21
57!> - 5 scaled value of major axis of elliptical earth, octets 22-25
58!> - 6 scale factor of minor axis of elliptical earth, octet 26
59!> - 7 scaled value of minor axis of elliptical earth, octets 27-30
60!> - 8 set to missing for thinned grid., octs 31-34
61!> - 9 number of points along a meridian, octs 35-38
62!> - 10 basic angle of initial production domain, octets 39-42.
63!> - 11 subdivisions of basic angle, octets 43-46
64!> - 12 latitude of first grid point, octets 47-50
65!> - 13 longitude of first grid point, octets 51-54
66!> - 14 resolution and component flags, octet 55
67!> - 15 latitude of last grid point, octets 56-59
68!> - 16 longitude of last grid point, octets 60-63
69!> - 17 set to missing for thinned grid, octets 64-67
70!> - 18 j-direction increment, octets 68-71
71!> - 19 scanning mode, octet 72
72!> @param[inout] data_thin real (numpts_thin,km) thinned grid fields if idir=+1
73!> @param[inout] ib_thin integer (km) bitmap flags thinned grid - if idir=+1
74!> @param[inout] bitmap_thin logical (numpts_thin,km) bitmap fields thin grid - if idir=+1
75!> @param[inout] igdtmpl_full integer (igdtlen) grid definition template
76!> array - full grid - if idir=-1. corresponds to the gfld%igdtmpl
77!> component of the ncep g2 library gridmod data structure. same as
78!> igdtmpl_thin except: (8): number of points along a parallel, octs
79!> 31-34 (17): i-direction increment, octets 64-67
80!> @param[inout] data_full real (numpts_full,km) full grid fields if idir=-1
81!> @param[inout] ib_full integer (km) bitmap flags full grid - if idir=-1
82!> @param[inout] bitmap_full logical (numpts_full,km) bitmap fields full grid - if idir=-1
83!> @param[out] iret integer return code
84!> - 0 successful transformation
85!> - 1 improper grid specification
86!>
87!> @author Trojan @date 7-7-13
88SUBROUTINE ipxwafs3(IDIR, NUMPTS_THIN, NUMPTS_FULL, KM, NUM_OPT, OPT_PTS, &
89 IGDTLEN, IGDTMPL_THIN, DATA_THIN, IB_THIN, BITMAP_THIN, &
90 IGDTMPL_FULL, DATA_FULL, IB_FULL, BITMAP_FULL, IRET)
91 IMPLICIT NONE
92!
93 INTEGER, INTENT(IN ) :: NUM_OPT
94 INTEGER, INTENT(INOUT) :: OPT_PTS(NUM_OPT)
95 INTEGER, INTENT(IN ) :: IDIR, KM, NUMPTS_THIN, NUMPTS_FULL
96 INTEGER, INTENT(IN ) :: IGDTLEN
97 INTEGER, INTENT(INOUT) :: IGDTMPL_THIN(IGDTLEN)
98 INTEGER, INTENT(INOUT) :: IGDTMPL_FULL(IGDTLEN)
99 INTEGER, INTENT(INOUT) :: IB_THIN(KM), IB_FULL(KM)
100 INTEGER, INTENT( OUT) :: IRET
101!
102 LOGICAL(KIND=1), INTENT(INOUT) :: BITMAP_THIN(NUMPTS_THIN,KM)
103 LOGICAL(KIND=1), INTENT(INOUT) :: BITMAP_FULL(NUMPTS_FULL,KM)
104!
105 REAL, INTENT(INOUT) :: DATA_THIN(NUMPTS_THIN,KM)
106 REAL, INTENT(INOUT) :: DATA_FULL(NUMPTS_FULL,KM)
107!
108 INTEGER, PARAMETER :: MISSING=-1
109!
110 INTEGER :: SCAN_MODE, I, J, K, IDLAT, IDLON
111 INTEGER :: IA, IB, IM, IM1, IM2, NPWAFS(73)
112 INTEGER :: IS1, IS2, ISCAN, ISCALE
113!
114 LOGICAL :: TEST1, TEST2
115!
116 REAL :: DLON, HI
117 REAL :: RAT1, RAT2, RLON1, RLON2
118 REAL :: WA, WB, X1, X2
119!
120 DATA npwafs/ &
121 73, 73, 73, 73, 73, 73, 73, 73, 72, 72, 72, 71, 71, 71, 70,&
122 70, 69, 69, 68, 67, 67, 66, 65, 65, 64, 63, 62, 61, 60, 60,&
123 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43,&
124 42, 40, 39, 38, 36, 35, 33, 32, 30, 29, 28, 26, 25, 23, 22,&
125 20, 19, 17, 16, 14, 12, 11, 9, 8, 6, 5, 3, 2/
126! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127! TRANSFORM GDS
128 iret=0
129! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130! REG LAT/LON GRIDS HAVE 19 GDT ELEMENTS.
131 IF (igdtlen /= 19 .OR. numpts_thin/=3447 .OR. numpts_full/=5329) THEN
132 iret=1
133 RETURN
134 ENDIF
135! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136! EXPAND THINNED GDS TO FULL GDS
137 IF(idir.GT.0) THEN
138 scan_mode=igdtmpl_thin(19)
139 iscale=igdtmpl_thin(10)*igdtmpl_thin(11)
140 IF(iscale==0) iscale=10**6
141 idlat=nint(1.25*float(iscale))
142 test1=all(opt_pts==npwafs)
143 test2=all(opt_pts==npwafs(73:1:-1))
144! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145! SOME CHECKS TO ENSURE THIS IS A WAFS GRID
146 IF(scan_mode==64 .AND. igdtmpl_thin(9)==73 .AND. &
147 idlat==igdtmpl_thin(18) .AND. (test1 .OR. test2) ) THEN
148 igdtmpl_full=igdtmpl_thin
149 im=73
150 igdtmpl_full(8)=im
151 rlon1=float(igdtmpl_full(13))/float(iscale)
152 rlon2=float(igdtmpl_full(16))/float(iscale)
153 iscan=mod(igdtmpl_full(19)/128,2)
154 hi=(-1.)**iscan
155 dlon=hi*(mod(hi*(rlon2-rlon1)-1+3600,360.)+1)/(im-1)
156 igdtmpl_full(17)=nint(dlon*float(iscale))
157 ELSE
158 iret=1
159 ENDIF
160! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161! CONTRACT FULL GDS TO THINNED GDS
162 ELSEIF(idir.LT.0) THEN
163 scan_mode=igdtmpl_full(19)
164 iscale=igdtmpl_full(10)*igdtmpl_full(11)
165 IF(iscale==0) iscale=10**6
166 idlat=nint(1.25*float(iscale))
167 idlon=idlat
168! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169! SOME CHECKS TO ENSURE THIS IS A WAFS GRID
170 IF(scan_mode==64 .AND. igdtmpl_full(8)==73 .AND. igdtmpl_full(9)==73 .AND. &
171 num_opt==73 .AND. idlat==igdtmpl_full(18) .AND. idlon==igdtmpl_full(17))THEN
172 igdtmpl_thin=igdtmpl_full
173 igdtmpl_thin(8)=missing
174 igdtmpl_thin(17)=missing
175 IF(igdtmpl_thin(12)==0) THEN ! IS LATITUDE OF ROW 1 THE EQUATOR?
176 opt_pts=npwafs
177 ELSE
178 opt_pts=npwafs(73:1:-1)
179 ENDIF
180 ELSE
181 iret=1
182 ENDIF
183 ENDIF
184! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185! TRANSFORM FIELDS
186 IF(iret.EQ.0) THEN
187! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
188! EXPAND THINNED FIELDS TO FULL FIELDS
189 IF(idir.EQ.1) THEN
190 DO k=1,km
191 is1=0
192 is2=0
193 ib_full(k)=0
194 DO j=1,igdtmpl_full(9)
195 im1=opt_pts(j)
196 im2=igdtmpl_full(8)
197 rat1=float(im1-1)/float(im2-1)
198 DO i=1,im2
199 x1=(i-1)*rat1+1
200 ia=int(x1)
201 ia=min(max(ia,1),im1-1)
202 ib=ia+1
203 wa=ib-x1
204 wb=x1-ia
205 IF(wa.GE.wb) THEN
206 IF(ib_thin(k).EQ.0.OR.bitmap_thin(is1+ia,k)) THEN
207 data_full(is2+i,k)=data_thin(is1+ia,k)
208 bitmap_full(is2+i,k)=.true.
209 ELSE
210 data_full(is2+i,k)=0.0
211 bitmap_full(is2+i,k)=.false.
212 ib_full(k)=1
213 ENDIF
214 ELSE
215 IF(ib_thin(k).EQ.0.OR.bitmap_thin(is1+ib,k)) THEN
216 data_full(is2+i,k)=data_thin(is1+ib,k)
217 bitmap_full(is2+i,k)=.true.
218 ELSE
219 data_full(is2+i,k)=0.0
220 bitmap_full(is2+i,k)=.false.
221 ib_full(k)=1
222 ENDIF
223 ENDIF
224 ENDDO
225 is1=is1+im1
226 is2=is2+im2
227 ENDDO
228 ENDDO
229! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
230! CONTRACT FULL FIELDS TO THINNED FIELDS
231 ELSEIF(idir.EQ.-1) THEN
232 DO k=1,km
233 is1=0
234 is2=0
235 ib_thin(k)=0
236 DO j=1,igdtmpl_full(9)
237 im1=opt_pts(j)
238 im2=igdtmpl_full(8)
239 rat2=float(im2-1)/float(im1-1)
240 DO i=1,im1
241 x2=(i-1)*rat2+1
242 ia=int(x2)
243 ia=min(max(ia,1),im2-1)
244 ib=ia+1
245 wa=ib-x2
246 wb=x2-ia
247 IF(wa.GE.wb) THEN
248 IF(ib_full(k).EQ.0.OR.bitmap_full(is2+ia,k)) THEN
249 data_thin(is1+i,k)=data_full(is2+ia,k)
250 bitmap_thin(is1+i,k)=.true.
251 ELSE
252 data_thin(is1+i,k)=0.0
253 bitmap_thin(is1+i,k)=.false.
254 ib_thin(k)=1
255 ENDIF
256 ELSE
257 IF(ib_full(k).EQ.0.OR.bitmap_full(is2+ib,k)) THEN
258 data_thin(is1+i,k)=data_full(is2+ib,k)
259 bitmap_thin(is1+i,k)=.true.
260 ELSE
261 data_thin(is1+i,k)=0.0
262 bitmap_thin(is1+i,k)=.false.
263 ib_thin(k)=1
264 ENDIF
265 ENDIF
266 ENDDO
267 is1=is1+im1
268 is2=is2+im2
269 ENDDO
270 ENDDO
271 ENDIF
272 ENDIF
273! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
274 END SUBROUTINE ipxwafs3
subroutine ipxwafs3(idir, numpts_thin, numpts_full, km, num_opt, opt_pts, igdtlen, igdtmpl_thin, data_thin, ib_thin, bitmap_thin, igdtmpl_full, data_full, ib_full, bitmap_full, iret)
Expand or contract wafs grids using neighbor interpolation and accout for bitmapped data.
Definition ipxwafs3.F90:91