merge standard release WRF/WPS V3.0.1.1 into wrffire
[wrffire.git] / WPS / ungrib / src / ngl / g2 / gridtemplates.f
blobd3527e6de85aa932782a8aec8eb6688438583d93
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
41 ! USAGE: use gridtemplates
43 ! ATTRIBUTES:
44 ! LANGUAGE: Fortran 90
45 ! MACHINE: IBM SP
47 !$$$
49 integer,parameter :: MAXLEN=200,MAXTEMP=24
51 type gridtemplate
52 integer :: template_num
53 integer :: mapgridlen
54 integer,dimension(MAXLEN) :: mapgrid
55 logical :: needext
56 end type gridtemplate
58 type(gridtemplate),dimension(MAXTEMP) :: templates
60 data templates(1)%template_num /0/ ! Lat/Lon
61 data templates(1)%mapgridlen /19/
62 data templates(1)%needext /.false./
63 data (templates(1)%mapgrid(j),j=1,19)
64 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
66 data templates(2)%template_num /1/ ! Rotated Lat/Lon
67 data templates(2)%mapgridlen /22/
68 data templates(2)%needext /.false./
69 data (templates(2)%mapgrid(j),j=1,22)
70 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4/
72 data templates(3)%template_num /2/ ! Stretched Lat/Lon
73 data templates(3)%mapgridlen /22/
74 data templates(3)%needext /.false./
75 data (templates(3)%mapgrid(j),j=1,22)
76 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4/
78 data templates(4)%template_num /3/ ! Stretched & Rotated Lat/Lon
79 data templates(4)%mapgridlen /25/
80 data templates(4)%needext /.false./
81 data (templates(4)%mapgrid(j),j=1,25)
82 & /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/
84 data templates(5)%template_num /10/ ! Mercator
85 data templates(5)%mapgridlen /19/
86 data templates(5)%needext /.false./
87 data (templates(5)%mapgrid(j),j=1,19)
88 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,-4,4,1,4,4,4/
90 data templates(6)%template_num /20/ ! Polar Stereographic
91 data templates(6)%mapgridlen /18/
92 data templates(6)%needext /.false./
93 data (templates(6)%mapgrid(j),j=1,18)
94 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1/
96 data templates(7)%template_num /30/ ! Lambert Conformal
97 data templates(7)%mapgridlen /22/
98 data templates(7)%needext /.false./
99 data (templates(7)%mapgrid(j),j=1,22)
100 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4/
102 data templates(8)%template_num /40/ ! Gaussian Lat/Lon
103 data templates(8)%mapgridlen /19/
104 data templates(8)%needext /.false./
105 data (templates(8)%mapgrid(j),j=1,19)
106 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
108 data templates(9)%template_num /41/ ! Rotated Gaussian Lat/Lon
109 data templates(9)%mapgridlen /22/
110 data templates(9)%needext /.false./
111 data (templates(9)%mapgrid(j),j=1,22)
112 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4/
114 data templates(10)%template_num /42/ ! Stretched Gaussian Lat/Lon
115 data templates(10)%mapgridlen /22/
116 data templates(10)%needext /.false./
117 data (templates(10)%mapgrid(j),j=1,22)
118 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4/
120 data templates(11)%template_num /43/ ! Strtchd and Rot'd Gaus Lat/Lon
121 data templates(11)%mapgridlen /25/
122 data templates(11)%needext /.false./
123 data (templates(11)%mapgrid(j),j=1,25)
124 & /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/
126 data templates(12)%template_num /50/ ! Spherical Harmonic Coefficients
127 data templates(12)%mapgridlen /5/
128 data templates(12)%needext /.false./
129 data (templates(12)%mapgrid(j),j=1,5) /4,4,4,1,1/
131 data templates(13)%template_num /51/ ! Rotated Spherical Harmonic Coeff
132 data templates(13)%mapgridlen /8/
133 data templates(13)%needext /.false./
134 data (templates(13)%mapgrid(j),j=1,8) /4,4,4,1,1,-4,4,4/
136 data templates(14)%template_num /52/ ! Stretch Spherical Harmonic Coeff
137 data templates(14)%mapgridlen /8/
138 data templates(14)%needext /.false./
139 data (templates(14)%mapgrid(j),j=1,8) /4,4,4,1,1,-4,4,-4/
141 data templates(15)%template_num /53/ ! Strch and Rot Spher Harm Coeffs
142 data templates(15)%mapgridlen /11/
143 data templates(15)%needext /.false./
144 data (templates(15)%mapgrid(j),j=1,11) /4,4,4,1,1,-4,4,4,-4,4,-4/
146 data templates(16)%template_num /90/ ! Space view Perspective
147 data templates(16)%mapgridlen /21/
148 data templates(16)%needext /.false./
149 data (templates(16)%mapgrid(j),j=1,21)
150 & /1,1,4,1,4,1,4,4,4,-4,4,1,4,4,4,4,1,4,4,4,4/
152 data templates(17)%template_num /100/ ! Triangular grid (icosahedron)
153 data templates(17)%mapgridlen /11/
154 data templates(17)%needext /.false./
155 data (templates(17)%mapgrid(j),j=1,11) /1,1,2,1,-4,4,4,1,1,1,4/
157 data templates(18)%template_num /110/ ! Equatorial Azimuthal equidistant
158 data templates(18)%mapgridlen /16/
159 data templates(18)%needext /.false./
160 data (templates(18)%mapgrid(j),j=1,16)
161 & /1,1,4,1,4,1,4,4,4,-4,4,1,4,4,1,1/
163 data templates(19)%template_num /120/ ! Azimuth-range
164 data templates(19)%mapgridlen /7/
165 data templates(19)%needext /.true./
166 data (templates(19)%mapgrid(j),j=1,7) /4,4,-4,4,4,4,1/
168 data templates(20)%template_num /1000/ ! Cross Section Grid
169 data templates(20)%mapgridlen /20/
170 data templates(20)%needext /.true./
171 data (templates(20)%mapgrid(j),j=1,20)
172 & /1,1,4,1,4,1,4,4,4,4,-4,4,1,4,4,1,2,1,1,2/
174 data templates(21)%template_num /1100/ ! Hovmoller Diagram Grid
175 data templates(21)%mapgridlen /28/
176 data templates(21)%needext /.false./
177 data (templates(21)%mapgrid(j),j=1,28)
178 & /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/
180 data templates(22)%template_num /1200/ ! Time Section Grid
181 data templates(22)%mapgridlen /16/
182 data templates(22)%needext /.true./
183 data (templates(22)%mapgrid(j),j=1,16)
184 & /4,1,-4,1,1,-4,2,1,1,1,1,1,2,1,1,2/
186 data templates(23)%template_num /31/ ! Albers Equal Area
187 data templates(23)%mapgridlen /22/
188 data templates(23)%needext /.false./
189 data (templates(23)%mapgrid(j),j=1,22)
190 & /1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4/
192 data templates(24)%template_num /204/ ! Curilinear Orthogonal Grids
193 data templates(24)%mapgridlen /19/
194 data templates(24)%needext /.false./
195 data (templates(24)%mapgrid(j),j=1,19)
196 & /1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1/
198 contains
201 integer function getgridindex(number)
202 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
203 ! . . . .
204 ! SUBPROGRAM: getgridindex
205 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-06-28
207 ! ABSTRACT: This function returns the index of specified Grid
208 ! Definition Template 3.NN (NN=number) in array templates.
210 ! PROGRAM HISTORY LOG:
211 ! 2001-06-28 Gilbert
213 ! USAGE: index=getgridindex(number)
214 ! INPUT ARGUMENT LIST:
215 ! number - NN, indicating the number of the Grid Definition
216 ! Template 3.NN that is being requested.
218 ! RETURNS: Index of GDT 3.NN in array templates, if template exists.
219 ! = -1, otherwise.
221 ! REMARKS: None
223 ! ATTRIBUTES:
224 ! LANGUAGE: Fortran 90
225 ! MACHINE: IBM SP
227 !$$$
228 integer,intent(in) :: number
230 getgridindex=-1
232 do j=1,MAXTEMP
233 if (number.eq.templates(j)%template_num) then
234 getgridindex=j
235 return
236 endif
237 enddo
239 end function
242 subroutine getgridtemplate(number,nummap,map,needext,iret)
243 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
244 ! . . . .
245 ! SUBPROGRAM: getgridtemplate
246 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-09
248 ! ABSTRACT: This subroutine returns grid template information for a
249 ! specified Grid Definition Template 3.NN.
250 ! The number of entries in the template is returned along with a map
251 ! of the number of octets occupied by each entry. Also, a flag is
252 ! returned to indicate whether the template would need to be extended.
254 ! PROGRAM HISTORY LOG:
255 ! 2000-05-09 Gilbert
257 ! USAGE: CALL getgridtemplate(number,nummap,map,needext,iret)
258 ! INPUT ARGUMENT LIST:
259 ! number - NN, indicating the number of the Grid Definition
260 ! Template 3.NN that is being requested.
262 ! OUTPUT ARGUMENT LIST:
263 ! nummap - Number of entries in the Template
264 ! map() - An array containing the number of octets that each
265 ! template entry occupies when packed up into the GDS.
266 ! needext - Logical variable indicating whether the Grid Defintion
267 ! Template has to be extended.
268 ! ierr - Error return code.
269 ! 0 = no error
270 ! 1 = Undefine Grid Template number.
272 ! REMARKS: None
274 ! ATTRIBUTES:
275 ! LANGUAGE: Fortran 90
276 ! MACHINE: IBM SP
278 !$$$
279 integer,intent(in) :: number
280 integer,intent(out) :: nummap,map(*),iret
281 logical,intent(out) :: needext
283 iret=0
285 index=getgridindex(number)
287 if (index.ne.-1) then
288 nummap=templates(index)%mapgridlen
289 needext=templates(index)%needext
290 map(1:nummap)=templates(index)%mapgrid(1:nummap)
291 else
292 nummap=0
293 needext=.false.
294 print *,'getgridtemplate: Grid Template ',number,
295 & ' not defined.'
296 iret=1
297 endif
299 end subroutine
302 subroutine extgridtemplate(number,list,nummap,map)
303 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
304 ! . . . .
305 ! SUBPROGRAM: extgridtemplate
306 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-09
308 ! ABSTRACT: This subroutine generates the remaining octet map for a
309 ! given Grid Definition Template, if required. Some Templates can
310 ! vary depending on data values given in an earlier part of the
311 ! Template, and it is necessary to know some of the earlier entry
312 ! values to generate the full octet map of the Template.
314 ! PROGRAM HISTORY LOG:
315 ! 2000-05-09 Gilbert
317 ! USAGE: CALL extgridtemplate(number,list,nummap,map)
318 ! INPUT ARGUMENT LIST:
319 ! number - NN, indicating the number of the Grid Definition
320 ! Template 3.NN that is being requested.
321 ! list() - The list of values for each entry in
322 ! the Grid Definition Template.
324 ! OUTPUT ARGUMENT LIST:
325 ! nummap - Number of entries in the Template
326 ! map() - An array containing the number of octets that each
327 ! template entry occupies when packed up into the GDS.
329 ! ATTRIBUTES:
330 ! LANGUAGE: Fortran 90
331 ! MACHINE: IBM SP
333 !$$$
334 integer,intent(in) :: number,list(*)
335 integer,intent(out) :: nummap,map(*)
337 index=getgridindex(number)
338 if (index.eq.-1) return
340 if ( .not. templates(index)%needext ) return
341 nummap=templates(index)%mapgridlen
342 map(1:nummap)=templates(index)%mapgrid(1:nummap)
344 if ( number.eq.120 ) then
345 N=list(2)
346 do i=1,N
347 map(nummap+1)=2
348 map(nummap+2)=-2
349 nummap=nummap+2
350 enddo
351 elseif ( number.eq.1000 ) then
352 N=list(20)
353 do i=1,N
354 map(nummap+1)=4
355 nummap=nummap+1
356 enddo
357 elseif ( number.eq.1200 ) then
358 N=list(16)
359 do i=1,N
360 map(nummap+1)=4
361 nummap=nummap+1
362 enddo
363 endif
365 end subroutine
367 integer function getgdtlen(number)
368 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
369 ! . . . .
370 ! SUBPROGRAM: getgdtlen
371 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2004-05-11
373 ! ABSTRACT: This function returns the initial length (number of entries) in
374 ! the "static" part of specified Grid Definition Template 3.number.
376 ! PROGRAM HISTORY LOG:
377 ! 2004-05-11 Gilbert
379 ! USAGE: CALL getgdtlen(number)
380 ! INPUT ARGUMENT LIST:
381 ! number - NN, indicating the number of the Grid Definition
382 ! Template 3.NN that is being requested.
384 ! RETURNS: Number of entries in the "static" part of GDT 3.number
385 ! OR returns 0, if requested template is not found.
387 ! REMARKS: If user needs the full length of a specific template that
388 ! contains additional entries based on values set in the "static" part
389 ! of the GDT, subroutine extgridtemplate can be used.
391 ! ATTRIBUTES:
392 ! LANGUAGE: Fortran 90
393 ! MACHINE: IBM SP
395 !$$$
396 integer,intent(in) :: number
398 getgdtlen=0
400 index=getgridindex(number)
402 if (index.ne.-1) then
403 getgdtlen=templates(index)%mapgridlen
404 endif
406 end function