1 subroutine gdt2gds(igds,igdstmpl,idefnum,ideflist,kgds,
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: Gilbert ORG: W/NP11 DATE: 2003-06-17
8 C ABSTRACT: This routine converts grid information from a GRIB2
9 C Grid Description Section as well as its
10 C Grid Definition Template to GRIB1 GDS info. In addition,
11 C a check is made to determine if the grid is an NCEP
14 C PROGRAM HISTORY LOG:
16 C 2004-04-27 Gilbert - Added support for gaussian grids.
18 C USAGE: CALL gdt2gds(igds,igdstmpl,idefnum,ideflist,kgds,igrid,iret)
19 C INPUT ARGUMENT LIST:
20 C igds() - Contains information read from the appropriate GRIB Grid
21 C Definition Section 3 for the field being returned.
22 C Must be dimensioned >= 5.
23 C igds(1)=Source of grid definition (see Code Table 3.0)
24 C igds(2)=Number of grid points in the defined grid.
25 C igds(3)=Number of octets needed for each
26 C additional grid points definition.
27 C Used to define number of
28 C points in each row ( or column ) for
30 C = 0, if using regular grid.
31 C igds(4)=Interpretation of list for optional points
32 C definition. (Code Table 3.11)
33 C igds(5)=Grid Definition Template Number (Code Table 3.1)
34 C igdstmpl() - Grid Definition Template values for GDT 3.igds(5)
35 C idefnum - The number of entries in array ideflist.
36 C i.e. number of rows ( or columns )
37 C for which optional grid points are defined.
38 C ideflist() - Optional integer array containing
39 C the number of grid points contained in each row (or column).
41 C OUTPUT ARGUMENT LIST: (INCLUDING WORK ARRAYS)
42 C kgds() - GRIB1 GDS as described in w3fi63 format.
43 C igrid - NCEP predifined GRIB1 grid number
44 C set to 255, if not NCEP grid
45 C iret - Error return value:
47 C 1 = Unrecognized GRIB2 GDT number 3.igds(5)
49 C REMARKS: LIST CAVEATS, OTHER HELPFUL HINTS OR INFORMATION
52 C LANGUAGE: INDICATE EXTENSIONS, COMPILER OPTIONS
57 integer,intent(in) :: idefnum
58 integer,intent(in) :: igds(*),igdstmpl(*),ideflist(*)
59 integer,intent(out) :: kgds(*),igrid,iret
61 integer :: kgds72(200),kgds71(200),idum(200),jdum(200)
64 if (igds(5).eq.0) then ! Lat/Lon grid
66 kgds(2)=igdstmpl(8) ! Ni
67 kgds(3)=igdstmpl(9) ! Nj
68 kgds(4)=igdstmpl(12)/1000 ! Lat of 1st grid point
69 kgds(5)=igdstmpl(13)/1000 ! Long of 1st grid point
70 kgds(6)=0 ! resolution and component flags
71 if (igdstmpl(1)==2 ) kgds(6)=64
72 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) )
74 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
75 kgds(7)=igdstmpl(15)/1000 ! Lat of last grid point
76 kgds(8)=igdstmpl(16)/1000 ! Long of last grid point
77 kgds(9)=igdstmpl(17)/1000 ! Di
78 kgds(10)=igdstmpl(18)/1000 ! Dj
79 kgds(11)=igdstmpl(19) ! Scanning mode
92 ! Process irreg grid stuff, if necessary
94 if ( idefnum.ne.0 ) then
95 if ( igdstmpl(8).eq.-1 ) then
99 if ( igdstmpl(9).eq.-1 ) then
105 if ( kgds(1).eq.1.OR.kgds(1).eq.3 ) kgds(20)=43
106 kgds(21)=igds(2) ! num of grid points
108 kgds(21+j)=ideflist(j)
111 elseif (igds(5).eq.10) then ! Mercator grid
112 kgds(1)=1 ! Grid Definition Template number
113 kgds(2)=igdstmpl(8) ! Ni
114 kgds(3)=igdstmpl(9) ! Nj
115 kgds(4)=igdstmpl(10)/1000 ! Lat of 1st grid point
116 kgds(5)=igdstmpl(11)/1000 ! Long of 1st grid point
117 kgds(6)=0 ! resolution and component flags
118 if (igdstmpl(1)==2 ) kgds(6)=64
119 if ( btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5) )
120 & kgds(6)=kgds(6)+128
121 if ( btest(igdstmpl(12),3) ) kgds(6)=kgds(6)+8
122 kgds(7)=igdstmpl(14)/1000 ! Lat of last grid point
123 kgds(8)=igdstmpl(15)/1000 ! Long of last grid point
124 kgds(9)=igdstmpl(13)/1000 ! Lat intersects earth
126 kgds(11)=igdstmpl(16) ! Scanning mode
127 kgds(12)=igdstmpl(18)/1000 ! Di
128 kgds(13)=igdstmpl(19)/1000 ! Dj
138 elseif (igds(5).eq.30) then ! Lambert Conformal Grid
140 kgds(2)=igdstmpl(8) ! Nx
141 kgds(3)=igdstmpl(9) ! Ny
142 kgds(4)=igdstmpl(10)/1000 ! Lat of 1st grid point
143 kgds(5)=igdstmpl(11)/1000 ! Long of 1st grid point
144 kgds(6)=0 ! resolution and component flags
145 if (igdstmpl(1)==2 ) kgds(6)=64
146 if ( btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5) )
147 & kgds(6)=kgds(6)+128
148 if ( btest(igdstmpl(12),3) ) kgds(6)=kgds(6)+8
149 kgds(7)=igdstmpl(14)/1000 ! Lon of orientation
150 kgds(8)=igdstmpl(15)/1000 ! Dx
151 kgds(9)=igdstmpl(16)/1000 ! Dy
152 kgds(10)=igdstmpl(17) ! Projection Center Flag
153 kgds(11)=igdstmpl(18) ! Scanning mode
154 kgds(12)=igdstmpl(19)/1000 ! Lat in 1
155 kgds(13)=igdstmpl(20)/1000 ! Lat in 2
156 kgds(14)=igdstmpl(21)/1000 ! Lat of S. Pole of projection
157 kgds(15)=igdstmpl(22)/1000 ! Lon of S. Pole of projection
165 elseif (igds(5).eq.40) then ! Gaussian Lat/Lon grid
167 kgds(2)=igdstmpl(8) ! Ni
168 kgds(3)=igdstmpl(9) ! Nj
169 kgds(4)=igdstmpl(12)/1000 ! Lat of 1st grid point
170 kgds(5)=igdstmpl(13)/1000 ! Long of 1st grid point
171 kgds(6)=0 ! resolution and component flags
172 if (igdstmpl(1)==2 ) kgds(6)=64
173 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) )
174 & kgds(6)=kgds(6)+128
175 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
176 kgds(7)=igdstmpl(15)/1000 ! Lat of last grid point
177 kgds(8)=igdstmpl(16)/1000 ! Long of last grid point
178 kgds(9)=igdstmpl(17)/1000 ! Di
179 kgds(10)=igdstmpl(18) ! N - Number of parallels
180 kgds(11)=igdstmpl(19) ! Scanning mode
192 elseif (igds(5).eq.20) then ! Polar Stereographic Grid
194 kgds(2)=igdstmpl(8) ! Nx
195 kgds(3)=igdstmpl(9) ! Ny
196 kgds(4)=igdstmpl(10)/1000 ! Lat of 1st grid point
197 kgds(5)=igdstmpl(11)/1000 ! Long of 1st grid point
198 kgds(6)=0 ! resolution and component flags
199 if (igdstmpl(1)==2 ) kgds(6)=64
200 if ( btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5) )
201 & kgds(6)=kgds(6)+128
202 if ( btest(igdstmpl(12),3) ) kgds(6)=kgds(6)+8
203 kgds(7)=igdstmpl(14)/1000 ! Lon of orientation
204 kgds(8)=igdstmpl(15)/1000 ! Dx
205 kgds(9)=igdstmpl(16)/1000 ! Dy
206 kgds(10)=igdstmpl(17) ! Projection Center Flag
207 kgds(11)=igdstmpl(18) ! Scanning mode
220 Print *,'gdt2gds: Unrecognized GRIB2 GDT = 3.',igds(5)
226 ! Can we determine NCEP grid number ?
233 call w3fi71(j,kgds71,ierr)
234 if ( ierr.ne.0 ) cycle
235 ! convert W to E for longitudes
236 if ( kgds71(3).eq.0 ) then ! lat/lon
237 if ( kgds71(7).lt.0 ) kgds71(7)=360000+kgds71(7)
238 if ( kgds71(10).lt.0 ) kgds71(10)=360000+kgds71(10)
239 elseif ( kgds71(3).eq.1 ) then ! mercator
240 if ( kgds71(7).lt.0 ) kgds71(7)=360000+kgds71(7)
241 if ( kgds71(10).lt.0 ) kgds71(10)=360000+kgds71(10)
242 elseif ( kgds71(3).eq.3 ) then ! lambert conformal
243 if ( kgds71(7).lt.0 ) kgds71(7)=360000+kgds71(7)
244 if ( kgds71(9).lt.0 ) kgds71(9)=360000+kgds71(9)
245 if ( kgds71(18).lt.0 ) kgds71(18)=360000+kgds71(18)
246 elseif ( kgds71(3).eq.4 ) then ! Guassian lat/lon
247 if ( kgds71(7).lt.0 ) kgds71(7)=360000+kgds71(7)
248 if ( kgds71(10).lt.0 ) kgds71(10)=360000+kgds71(10)
249 elseif ( kgds71(3).eq.5 ) then ! polar stereographic
250 if ( kgds71(7).lt.0 ) kgds71(7)=360000+kgds71(7)
251 if ( kgds71(9).lt.0 ) kgds71(9)=360000+kgds71(9)
253 call r63w72(idum,kgds,jdum,kgds72)
254 if ( kgds72(3).eq.3 ) kgds72(14)=0 ! lambert conformal fix
255 if ( kgds72(3).eq.1 ) kgds72(15:18)=0 ! mercator fix
256 if ( kgds72(3).eq.5 ) kgds72(14:18)=0 ! polar str fix
257 !print *,'SAGT71:',(kgds71(k),k=1,30)
258 !print *,'SAGT72:',(kgds72(k),k=1,30)
259 if ( all(kgds71.eq.kgds72) ) then