** TAG CREATION **
[WPS-merge.git] / ungrib / src / ngl / g2 / gridtemplates.f
blob1a6ed998656d6a17d19c09105aad26073515f6d4
1 module gridtemplates
2 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
3 ! . . . .
4 ! MODULE: gridtemplates
5 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-09
7 ! ABSTRACT: This Fortran Module contains info on all the available
8 ! GRIB2 Grid Definition Templates used in Section 3 (GDS).
9 ! Each Template has three parts: The number of entries in the template
10 ! (mapgridlen); A map of the template (mapgrid), which contains the
11 ! number of octets in which to pack each of the template values; and
12 ! a logical value (needext) that indicates whether the Template needs
13 ! to be extended. In some cases the number of entries in a template
14 ! can vary depending upon values specified in the "static" part of
15 ! the template. ( See Template 3.120 as an example )
17 ! This module also contains two subroutines. Subroutine getgridtemplate
18 ! returns the octet map for a specified Template number, and
19 ! subroutine extgridtemplate will calculate the extended octet map
20 ! of an appropriate template given values for the "static" part of the
21 ! template. See docblocks below for the arguments and usage of these
22 ! routines.
24 ! NOTE: Array mapgrid contains the number of octets in which the
25 ! corresponding template values will be stored. A negative value in
26 ! mapgrid is used to indicate that the corresponding template entry can
27 ! contain negative values. This information is used later when packing
28 ! (or unpacking) the template data values. Negative data values in GRIB
29 ! are stored with the left most bit set to one, and a negative number
30 ! of octets value in mapgrid() indicates that this possibility should
31 ! be considered. The number of octets used to store the data value
32 ! in this case would be the absolute value of the negative value in
33 ! mapgrid().
36 ! PROGRAM HISTORY LOG:
37 ! 2000-05-09 Gilbert
38 ! 2003-09-02 Gilbert - Added GDT 3.31 - Albers Equal Area
39 ! 2007-04-24 Vuong - Added GDT 3.204 Curilinear Orthogonal Grids
40 ! 2008-05-29 Vuong - Added GDT 3.32768 Rotate Lat/Lon E-grid
41 ! 2010-05-10 Vuong - Added GDT 3.32769 Rotate Lat/Lon Non E-Stagger grid
43 ! USAGE: use gridtemplates
45 ! ATTRIBUTES:
46 ! LANGUAGE: Fortran 90
47 ! MACHINE: IBM SP
49 !$$$
51 integer,parameter :: MAXLEN=200,MAXTEMP=26
53 type gridtemplate
54 integer :: template_num
55 integer :: mapgridlen
56 integer,dimension(MAXLEN) :: mapgrid
57 logical :: needext
58 end type gridtemplate
60 type(gridtemplate),dimension(MAXTEMP) :: templates
62 data templates(1)%template_num /0/ ! Lat/Lon
63 data templates(1)%mapgridlen /19/
64 data templates(1)%needext /.false./
65 data (templates(1)%mapgrid(j),j=1,19)
66 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
68 data templates(2)%template_num /1/ ! Rotated Lat/Lon
69 data templates(2)%mapgridlen /22/
70 data templates(2)%needext /.false./
71 data (templates(2)%mapgrid(j),j=1,22)
72 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4/
74 data templates(3)%template_num /2/ ! Stretched Lat/Lon
75 data templates(3)%mapgridlen /22/
76 data templates(3)%needext /.false./
77 data (templates(3)%mapgrid(j),j=1,22)
78 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4/
80 data templates(4)%template_num /3/ ! Stretched & Rotated Lat/Lon
81 data templates(4)%mapgridlen /25/
82 data templates(4)%needext /.false./
83 data (templates(4)%mapgrid(j),j=1,25)
84 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4/
86 data templates(5)%template_num /10/ ! Mercator
87 data templates(5)%mapgridlen /19/
88 data templates(5)%needext /.false./
89 data (templates(5)%mapgrid(j),j=1,19)
90 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,-4,4,1,4,4,4/
92 data templates(6)%template_num /20/ ! Polar Stereographic
93 data templates(6)%mapgridlen /18/
94 data templates(6)%needext /.false./
95 data (templates(6)%mapgrid(j),j=1,18)
96 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1/
98 data templates(7)%template_num /30/ ! Lambert Conformal
99 data templates(7)%mapgridlen /22/
100 data templates(7)%needext /.false./
101 data (templates(7)%mapgrid(j),j=1,22)
102 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4/
104 data templates(8)%template_num /40/ ! Gaussian Lat/Lon
105 data templates(8)%mapgridlen /19/
106 data templates(8)%needext /.false./
107 data (templates(8)%mapgrid(j),j=1,19)
108 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
110 data templates(9)%template_num /41/ ! Rotated Gaussian Lat/Lon
111 data templates(9)%mapgridlen /22/
112 data templates(9)%needext /.false./
113 data (templates(9)%mapgrid(j),j=1,22)
114 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4/
116 data templates(10)%template_num /42/ ! Stretched Gaussian Lat/Lon
117 data templates(10)%mapgridlen /22/
118 data templates(10)%needext /.false./
119 data (templates(10)%mapgrid(j),j=1,22)
120 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4/
122 data templates(11)%template_num /43/ ! Strtchd and Rot'd Gaus Lat/Lon
123 data templates(11)%mapgridlen /25/
124 data templates(11)%needext /.false./
125 data (templates(11)%mapgrid(j),j=1,25)
126 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4/
128 data templates(12)%template_num /50/ ! Spherical Harmonic Coefficients
129 data templates(12)%mapgridlen /5/
130 data templates(12)%needext /.false./
131 data (templates(12)%mapgrid(j),j=1,5) /4,4,4,1,1/
133 data templates(13)%template_num /51/ ! Rotated Spherical Harmonic Coeff
134 data templates(13)%mapgridlen /8/
135 data templates(13)%needext /.false./
136 data (templates(13)%mapgrid(j),j=1,8) /4,4,4,1,1,-4,4,4/
138 data templates(14)%template_num /52/ ! Stretch Spherical Harmonic Coeff
139 data templates(14)%mapgridlen /8/
140 data templates(14)%needext /.false./
141 data (templates(14)%mapgrid(j),j=1,8) /4,4,4,1,1,-4,4,-4/
143 data templates(15)%template_num /53/ ! Strch and Rot Spher Harm Coeffs
144 data templates(15)%mapgridlen /11/
145 data templates(15)%needext /.false./
146 data (templates(15)%mapgrid(j),j=1,11) /4,4,4,1,1,-4,4,4,-4,4,-4/
148 data templates(16)%template_num /90/ ! Space view Perspective
149 data templates(16)%mapgridlen /21/
150 data templates(16)%needext /.false./
151 data (templates(16)%mapgrid(j),j=1,21)
152 & /1,1,4,1,4,1,4,4,4,-4,4,1,4,4,4,4,1,4,4,4,4/
154 data templates(17)%template_num /100/ ! Triangular grid (icosahedron)
155 data templates(17)%mapgridlen /11/
156 data templates(17)%needext /.false./
157 data (templates(17)%mapgrid(j),j=1,11) /1,1,2,1,-4,4,4,1,1,1,4/
159 data templates(18)%template_num /110/ ! Equatorial Azimuthal equidistant
160 data templates(18)%mapgridlen /16/
161 data templates(18)%needext /.false./
162 data (templates(18)%mapgrid(j),j=1,16)
163 & /1,1,4,1,4,1,4,4,4,-4,4,1,4,4,1,1/
165 data templates(19)%template_num /120/ ! Azimuth-range
166 data templates(19)%mapgridlen /7/
167 data templates(19)%needext /.true./
168 data (templates(19)%mapgrid(j),j=1,7) /4,4,-4,4,4,4,1/
170 data templates(20)%template_num /1000/ ! Cross Section Grid
171 data templates(20)%mapgridlen /20/
172 data templates(20)%needext /.true./
173 data (templates(20)%mapgrid(j),j=1,20)
174 & /1,1,4,1,4,1,4,4,4,4,-4,4,1,4,4,1,2,1,1,2/
176 data templates(21)%template_num /1100/ ! Hovmoller Diagram Grid
177 data templates(21)%mapgridlen /28/
178 data templates(21)%needext /.false./
179 data (templates(21)%mapgrid(j),j=1,28)
180 & /1,1,4,1,4,1,4,4,4,4,-4,4,1,-4,4,1,4,1,-4,1,1,-4,2,1,1,1,1,1/
182 data templates(22)%template_num /1200/ ! Time Section Grid
183 data templates(22)%mapgridlen /16/
184 data templates(22)%needext /.true./
185 data (templates(22)%mapgrid(j),j=1,16)
186 & /4,1,-4,1,1,-4,2,1,1,1,1,1,2,1,1,2/
188 data templates(23)%template_num /31/ ! Albers Equal Area
189 data templates(23)%mapgridlen /22/
190 data templates(23)%needext /.false./
191 data (templates(23)%mapgrid(j),j=1,22)
192 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4/
194 data templates(24)%template_num /204/ ! Curilinear Orthogonal Grids
195 data templates(24)%mapgridlen /19/
196 data templates(24)%needext /.false./
197 data (templates(24)%mapgrid(j),j=1,19)
198 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
200 data templates(25)%template_num /32768/ ! Rotate Lat/Lon E-grid
201 data templates(25)%mapgridlen /19/
202 data templates(25)%needext /.false./
203 data (templates(25)%mapgrid(j),j=1,19)
204 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
206 data templates(26)%template_num /32769/ ! Rotate Lat/Lon Non-E Stagger grid
207 data templates(26)%mapgridlen /21/
208 data templates(26)%needext /.false./
209 data (templates(26)%mapgrid(j),j=1,21)
210 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,4,4/
212 contains
215 integer function getgridindex(number)
216 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
217 ! . . . .
218 ! SUBPROGRAM: getgridindex
219 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-06-28
221 ! ABSTRACT: This function returns the index of specified Grid
222 ! Definition Template 3.NN (NN=number) in array templates.
224 ! PROGRAM HISTORY LOG:
225 ! 2001-06-28 Gilbert
227 ! USAGE: index=getgridindex(number)
228 ! INPUT ARGUMENT LIST:
229 ! number - NN, indicating the number of the Grid Definition
230 ! Template 3.NN that is being requested.
232 ! RETURNS: Index of GDT 3.NN in array templates, if template exists.
233 ! = -1, otherwise.
235 ! REMARKS: None
237 ! ATTRIBUTES:
238 ! LANGUAGE: Fortran 90
239 ! MACHINE: IBM SP
241 !$$$
242 integer,intent(in) :: number
244 getgridindex=-1
246 do j=1,MAXTEMP
247 if (number.eq.templates(j)%template_num) then
248 getgridindex=j
249 return
250 endif
251 enddo
253 end function
256 subroutine getgridtemplate(number,nummap,map,needext,iret)
257 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
258 ! . . . .
259 ! SUBPROGRAM: getgridtemplate
260 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-09
262 ! ABSTRACT: This subroutine returns grid template information for a
263 ! specified Grid Definition Template 3.NN.
264 ! The number of entries in the template is returned along with a map
265 ! of the number of octets occupied by each entry. Also, a flag is
266 ! returned to indicate whether the template would need to be extended.
268 ! PROGRAM HISTORY LOG:
269 ! 2000-05-09 Gilbert
271 ! USAGE: CALL getgridtemplate(number,nummap,map,needext,iret)
272 ! INPUT ARGUMENT LIST:
273 ! number - NN, indicating the number of the Grid Definition
274 ! Template 3.NN that is being requested.
276 ! OUTPUT ARGUMENT LIST:
277 ! nummap - Number of entries in the Template
278 ! map() - An array containing the number of octets that each
279 ! template entry occupies when packed up into the GDS.
280 ! needext - Logical variable indicating whether the Grid Defintion
281 ! Template has to be extended.
282 ! ierr - Error return code.
283 ! 0 = no error
284 ! 1 = Undefine Grid Template number.
286 ! REMARKS: None
288 ! ATTRIBUTES:
289 ! LANGUAGE: Fortran 90
290 ! MACHINE: IBM SP
292 !$$$
293 integer,intent(in) :: number
294 integer,intent(out) :: nummap,map(*),iret
295 logical,intent(out) :: needext
297 iret=0
299 index=getgridindex(number)
301 if (index.ne.-1) then
302 nummap=templates(index)%mapgridlen
303 needext=templates(index)%needext
304 map(1:nummap)=templates(index)%mapgrid(1:nummap)
305 else
306 nummap=0
307 needext=.false.
308 print *,'getgridtemplate: Grid Template ',number,
309 & ' not defined.'
310 iret=1
311 endif
313 end subroutine
316 subroutine extgridtemplate(number,list,nummap,map)
317 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
318 ! . . . .
319 ! SUBPROGRAM: extgridtemplate
320 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-09
322 ! ABSTRACT: This subroutine generates the remaining octet map for a
323 ! given Grid Definition Template, if required. Some Templates can
324 ! vary depending on data values given in an earlier part of the
325 ! Template, and it is necessary to know some of the earlier entry
326 ! values to generate the full octet map of the Template.
328 ! PROGRAM HISTORY LOG:
329 ! 2000-05-09 Gilbert
331 ! USAGE: CALL extgridtemplate(number,list,nummap,map)
332 ! INPUT ARGUMENT LIST:
333 ! number - NN, indicating the number of the Grid Definition
334 ! Template 3.NN that is being requested.
335 ! list() - The list of values for each entry in
336 ! the Grid Definition Template.
338 ! OUTPUT ARGUMENT LIST:
339 ! nummap - Number of entries in the Template
340 ! map() - An array containing the number of octets that each
341 ! template entry occupies when packed up into the GDS.
343 ! ATTRIBUTES:
344 ! LANGUAGE: Fortran 90
345 ! MACHINE: IBM SP
347 !$$$
348 integer,intent(in) :: number,list(*)
349 integer,intent(out) :: nummap,map(*)
351 index=getgridindex(number)
352 if (index.eq.-1) return
354 if ( .not. templates(index)%needext ) return
355 nummap=templates(index)%mapgridlen
356 map(1:nummap)=templates(index)%mapgrid(1:nummap)
358 if ( number.eq.120 ) then
359 N=list(2)
360 do i=1,N
361 map(nummap+1)=2
362 map(nummap+2)=-2
363 nummap=nummap+2
364 enddo
365 elseif ( number.eq.1000 ) then
366 N=list(20)
367 do i=1,N
368 map(nummap+1)=4
369 nummap=nummap+1
370 enddo
371 elseif ( number.eq.1200 ) then
372 N=list(16)
373 do i=1,N
374 map(nummap+1)=4
375 nummap=nummap+1
376 enddo
377 endif
379 end subroutine
381 integer function getgdtlen(number)
382 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
383 ! . . . .
384 ! SUBPROGRAM: getgdtlen
385 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2004-05-11
387 ! ABSTRACT: This function returns the initial length (number of entries) in
388 ! the "static" part of specified Grid Definition Template 3.number.
390 ! PROGRAM HISTORY LOG:
391 ! 2004-05-11 Gilbert
393 ! USAGE: CALL getgdtlen(number)
394 ! INPUT ARGUMENT LIST:
395 ! number - NN, indicating the number of the Grid Definition
396 ! Template 3.NN that is being requested.
398 ! RETURNS: Number of entries in the "static" part of GDT 3.number
399 ! OR returns 0, if requested template is not found.
401 ! REMARKS: If user needs the full length of a specific template that
402 ! contains additional entries based on values set in the "static" part
403 ! of the GDT, subroutine extgridtemplate can be used.
405 ! ATTRIBUTES:
406 ! LANGUAGE: Fortran 90
407 ! MACHINE: IBM SP
409 !$$$
410 integer,intent(in) :: number
412 getgdtlen=0
414 index=getgridindex(number)
416 if (index.ne.-1) then
417 getgdtlen=templates(index)%mapgridlen
418 endif
420 end function