2 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2000-05-11
7 ! ABSTRACT
: This Fortran Module contains info on all the available
8 ! GRIB2 Product Definition Templates used in Section
4 (PDS
).
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
4.3 as an example
)
17 ! This module also contains two subroutines
. Subroutine getpdstemplate
18 ! returns the octet map
for a specified Template number
, and
19 ! subroutine extpdstemplate 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
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
36 ! PROGRAM HISTORY LOG
:
38 ! 2001-12-04 Gilbert
- Added Templates
4.12, 4.12, 4.14,
39 ! 4.1000, 4.1001, 4.1002, 4.1100 and
4.1101
40 ! 2009-05-21 VUONG
- Allow negative scale factors and limits
for
41 ! Templates
4.5 and
4.9
42 ! 2009-12-14 VUONG
- Added Templates
(Satellite Product
) 4.31
43 ! Added Templates
(ICAO WAFS
) 4.15
44 ! 2010-08-03 VUONG
- Added Templates
4.40,4.41,4.42,.4.43
45 ! 2010-12-08 Vuong
- Corrected Product Definition Template
4.42 and
4.43
47 ! USAGE
: use pdstemplates
50 ! LANGUAGE
: Fortran
90
55 integer,parameter :: MAXLEN
=200,MAXTEMP
=29
58 integer :: template_num
60 integer,dimension(MAXLEN
) :: mappds
64 type
(pdstemplate
),dimension(MAXTEMP
) :: templates
66 data templates
(1)%template_num
/0/ ! Fcst at Level
/Layer
67 data templates
(1)%mappdslen
/15/
68 data templates
(1)%needext
/.false
./
69 data
(templates
(1)%mappds
(j
),j
=1,15)
70 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4/
72 data templates
(2)%template_num
/1/ ! Ens fcst at level
/layer
73 data templates
(2)%mappdslen
/18/
74 data templates
(2)%needext
/.false
./
75 data
(templates
(2)%mappds
(j
),j
=1,18)
76 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1/
78 data templates
(3)%template_num
/2/ ! Derived Ens fcst at level
/layer
79 data templates
(3)%mappdslen
/17/
80 data templates
(3)%needext
/.false
./
81 data
(templates
(3)%mappds
(j
),j
=1,17)
82 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1/
84 data templates
(4)%template_num
/3/ ! Ens cluster fcst rect
. area
85 data templates
(4)%mappdslen
/31/
86 data templates
(4)%needext
/.true
./
87 data
(templates
(4)%mappds
(j
),j
=1,31)
88 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,-4,4,4,
91 data templates
(5)%template_num
/4/ ! Ens cluster fcst circ
. area
92 data templates
(5)%mappdslen
/30/
93 data templates
(5)%needext
/.true
./
94 data
(templates
(5)%mappds
(j
),j
=1,30)
95 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,4,4,
98 data templates
(6)%template_num
/5/ ! Prob fcst at level
/layer
99 data templates
(6)%mappdslen
/22/
100 data templates
(6)%needext
/.false
./
101 data
(templates
(6)%mappds
(j
),j
=1,22)
102 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,-1,-4,-1,-4/
104 data templates
(7)%template_num
/6/ ! Percentile fcst at level
/layer
105 data templates
(7)%mappdslen
/16/
106 data templates
(7)%needext
/.false
./
107 data
(templates
(7)%mappds
(j
),j
=1,16)
108 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1/
110 data templates
(8)%template_num
/7/ ! Error at level
/layer
111 data templates
(8)%mappdslen
/15/
112 data templates
(8)%needext
/.false
./
113 data
(templates
(8)%mappds
(j
),j
=1,15)
114 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4/
116 data templates
(9)%template_num
/8/ ! Ave or Accum at level
/layer
117 data templates
(9)%mappdslen
/29/
118 data templates
(9)%needext
/.true
./
119 data
(templates
(9)%mappds
(j
),j
=1,29)
120 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,2,1,1,1,1,1,1,4,1,1,1,4,1,4/
122 data templates
(10)%template_num
/9/ ! Prob over time interval
123 data templates
(10)%mappdslen
/36/
124 data templates
(10)%needext
/.true
./
125 data
(templates
(10)%mappds
(j
),j
=1,36)
126 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,-1,-4,-1,-4,2,1,1,1,
127 & 1,1,1,4,1,1,1,4,1,4/
129 data templates
(11)%template_num
/10/ ! Percentile over time interval
130 data templates
(11)%mappdslen
/30/
131 data templates
(11)%needext
/.true
./
132 data
(templates
(11)%mappds
(j
),j
=1,30)
133 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,2,1,1,1,1,1,1,4,
136 data templates
(12)%template_num
/11/ ! Ens member over time interval
137 data templates
(12)%mappdslen
/32/
138 data templates
(12)%needext
/.true
./
139 data
(templates
(12)%mappds
(j
),j
=1,32)
140 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,2,1,1,1,1,1,1,
143 data templates
(13)%template_num
/12/ ! Derived Ens fcst over time int
144 data templates
(13)%mappdslen
/31/
145 data templates
(13)%needext
/.true
./
146 data
(templates
(13)%mappds
(j
),j
=1,31)
147 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,
148 & 2,1,1,1,1,1,1,4,1,1,1,4,1,4/
150 data templates
(14)%template_num
/13/ ! Ens cluster fcst rect
. area
151 data templates
(14)%mappdslen
/45/
152 data templates
(14)%needext
/.true
./
153 data
(templates
(14)%mappds
(j
),j
=1,45)
154 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,-4,4,4,
155 & 1,-1,4,-1,4,2,1,1,1,1,1,1,4,1,1,1,4,1,4/
157 data templates
(15)%template_num
/14/ ! Ens cluster fcst circ
. area
158 data templates
(15)%mappdslen
/44/
159 data templates
(15)%needext
/.true
./
160 data
(templates
(15)%mappds
(j
),j
=1,44)
161 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,4,4,
162 & 1,-1,4,-1,4,2,1,1,1,1,1,1,4,1,1,1,4,1,4/
164 data templates
(16)%template_num
/20/ ! Radar Product
165 data templates
(16)%mappdslen
/19/
166 data templates
(16)%needext
/.false
./
167 data
(templates
(16)%mappds
(j
),j
=1,19)
168 & /1,1,1,1,1,-4,4,2,4,2,1,1,1,1,1,2,1,3,2/
170 data templates
(17)%template_num
/30/ ! Satellite Product
171 data templates
(17)%mappdslen
/5/
172 data templates
(17)%needext
/.true
./
173 data
(templates
(17)%mappds
(j
),j
=1,5)
176 data templates
(18)%template_num
/254/ ! CCITTIA5
Character String
177 data templates
(18)%mappdslen
/3/
178 data templates
(18)%needext
/.false
./
179 data
(templates
(18)%mappds
(j
),j
=1,3)
182 data templates
(19)%template_num
/1000/ ! Cross section
183 data templates
(19)%mappdslen
/9/
184 data templates
(19)%needext
/.false
./
185 data
(templates
(19)%mappds
(j
),j
=1,9)
186 & /1,1,1,1,1,2,1,1,4/
188 data templates
(20)%template_num
/1001/ ! Cross section over time
189 data templates
(20)%mappdslen
/16/
190 data templates
(20)%needext
/.false
./
191 data
(templates
(20)%mappds
(j
),j
=1,16)
192 & /1,1,1,1,1,2,1,1,4,4,1,1,1,4,1,4/
194 data templates
(21)%template_num
/1002/ ! Cross section processed time
195 data templates
(21)%mappdslen
/15/
196 data templates
(21)%needext
/.false
./
197 data
(templates
(21)%mappds
(j
),j
=1,15)
198 & /1,1,1,1,1,2,1,1,4,1,1,1,4,4,2/
200 data templates
(22)%template_num
/1100/ ! Hovmoller grid
201 data templates
(22)%mappdslen
/15/
202 data templates
(22)%needext
/.false
./
203 data
(templates
(22)%mappds
(j
),j
=1,15)
204 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4/
206 data templates
(23)%template_num
/1101/ ! Hovmoller with stat proc
207 data templates
(23)%mappdslen
/22/
208 data templates
(23)%needext
/.false
./
209 data
(templates
(23)%mappds
(j
),j
=1,22)
210 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,4,1,1,1,4,1,4/
212 data templates
(24)%template_num
/31/ ! Satellite Product
213 data templates
(24)%mappdslen
/5/
214 data templates
(24)%needext
/.true
./
215 data
(templates
(24)%mappds
(j
),j
=1,5)
218 data templates
(25)%template_num
/15/ ! Ave or Accum at level
/layer
219 data templates
(25)%mappdslen
/18/ ! For ICAO WAFS products
220 data templates
(25)%needext
/.false
./
221 data
(templates
(25)%mappds
(j
),j
=1,18)
222 & /1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1/
224 data templates
(26)%template_num
/40/ ! Analysis or Forecast at a horizontal or in a
225 data templates
(26)%mappdslen
/16/ ! horizontal layer at a point in time
for
226 data templates
(26)%needext
/.false
./ ! atmospheric chemical constituents
227 data
(templates
(26)%mappds
(j
),j
=1,16)
228 & /1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4/
230 data templates
(27)%template_num
/41/ ! Individual ensemble forecast
, control and
231 data templates
(27)%mappdslen
/19/ ! perturbed
, at horizontal level or
232 data templates
(27)%needext
/.false
./ ! in a horizontal layer at a point in time
for
233 data
(templates
(27)%mappds
(j
),j
=1,19) ! atmospheric chemical constituents
234 & /1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1/
236 data templates
(28)%template_num
/42/ ! Average
, Accumulation
, and
/or extreme values or other
237 data templates
(28)%mappdslen
/30/ ! statistically
-processed values at horizontal level or
238 data templates
(28)%needext
/.true
./ ! in a horizontal layer in contnunuous or non
-continuous time
239 data
(templates
(28)%mappds
(j
),j
=1,30) ! interval
for atmospheric chemical constituents
240 & /1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,2,1,1,1,1,1,1,4,
243 data templates
(29)%template_num
/43/ ! Individual ensemble forecast
, control and
244 data templates
(29)%mappdslen
/33/ ! perturbed
, at horizontal level or in a horizontal
245 data templates
(29)%needext
/.true
./ ! layer at a point in a continuous or non
-continuous time
246 data
(templates
(29)%mappds
(j
),j
=1,33) ! interval
for atmospheric chemical constituents
247 & /1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,2,1,1,1,1,1,1,4,
252 integer function getpdsindex
(number
)
253 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
255 ! SUBPROGRAM
: getpdsindex
256 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2001-06-28
258 ! ABSTRACT
: This
function returns the index of specified Product
259 ! Definition Template
4.NN
(NN
=number
) in array templates
.
261 ! PROGRAM HISTORY LOG
:
264 ! USAGE
: index
=getpdsindex
(number
)
265 ! INPUT ARGUMENT LIST
:
266 ! number
- NN
, indicating the number of the Product Definition
267 ! Template
4.NN that is being requested
.
269 ! RETURNS
: Index of PDT
4.NN in array templates
, if template exists
.
275 ! LANGUAGE
: Fortran
90
279 integer,intent
(in
) :: number
284 if (number
.eq
.templates
(j
)%template_num
) then
293 subroutine getpdstemplate
(number
,nummap
,map
,needext
,iret
)
294 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
296 ! SUBPROGRAM
: getpdstemplate
297 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2000-05-11
299 ! ABSTRACT
: This
subroutine returns PDS template information
for a
300 ! specified Product Definition Template
4.NN
.
301 ! The number of entries in the template is returned along with a map
302 ! of the number of octets occupied by each entry
. Also
, a flag is
303 ! returned
to indicate whether the template would need
to be extended
.
305 ! PROGRAM HISTORY LOG
:
307 ! 2010-08-03 VUONG
- Added Templates
4.40,4.41,4.42,.4.43
308 ! 2010-12-08 Vuong
- Corrected Product Definition Template
4.42 and
4.43
310 ! USAGE
: CALL getpdstemplate
(number
,nummap
,map
,needext
,iret
)
311 ! INPUT ARGUMENT LIST
:
312 ! number
- NN
, indicating the number of the Product Definition
313 ! Template
4.NN that is being requested
.
315 ! OUTPUT ARGUMENT LIST
:
316 ! nummap
- Number of entries in the Template
317 ! map
() - An array containing the number of octets that each
318 ! template entry occupies when packed up into the PDS
.
319 ! needext
- Logical variable indicating whether the Product Defintion
320 ! Template has
to be extended
.
321 ! ierr
- Error
return code
.
323 ! 1 = Undefine Product Template number
.
328 ! LANGUAGE
: Fortran
90
332 integer,intent
(in
) :: number
333 integer,intent
(out
) :: nummap
,map
(*),iret
334 logical,intent
(out
) :: needext
338 index
=getpdsindex
(number
)
340 if (index
.ne
.-1) then
341 nummap
=templates
(index
)%mappdslen
342 needext
=templates
(index
)%needext
343 map
(1:nummap
)=templates
(index
)%mappds
(1:nummap
)
347 print
*,'getpdstemplate: PDS Template ',number
,
354 subroutine extpdstemplate
(number
,list
,nummap
,map
)
355 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
357 ! SUBPROGRAM
: extpdstemplate
358 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2000-05-11
360 ! ABSTRACT
: This
subroutine generates the remaining octet map
for a
361 ! given Product Definition Template
, if required
. Some Templates can
362 ! vary depending on data values given in an earlier part of the
363 ! Template
, and it is necessary
to know some of the earlier entry
364 ! values
to generate the full octet map of the Template
.
366 ! PROGRAM HISTORY LOG
:
368 ! 2010-08-03 VUONG
- Added Templates
4.40,4.41,4.42,.4.43
369 ! 2010-12-08 Vuong
- Corrected Product Definition Template
4.42 and
4.43
371 ! USAGE
: CALL extpdstemplate
(number
,list
,nummap
,map
)
372 ! INPUT ARGUMENT LIST
:
373 ! number
- NN
, indicating the number of the Product Definition
374 ! Template
4.NN that is being requested
.
375 ! list
() - The list of values
for each entry in the
376 ! the Product Definition Template
4.NN
.
378 ! OUTPUT ARGUMENT LIST
:
379 ! nummap
- Number of entries in the Template
380 ! map
() - An array containing the number of octets that each
381 ! template entry occupies when packed up into the GDS
.
384 ! LANGUAGE
: Fortran
90
388 integer,intent
(in
) :: number
,list
(*)
389 integer,intent
(out
) :: nummap
,map
(*)
391 index
=getpdsindex
(number
)
392 if (index
.eq
.-1) return
394 if ( .not
. templates
(index
)%needext
) return
395 nummap
=templates
(index
)%mappdslen
396 map
(1:nummap
)=templates
(index
)%mappds
(1:nummap
)
398 if ( number
.eq
.3 ) then
404 elseif
( number
.eq
.4 ) then
410 elseif
( number
.eq
.8 ) then
411 if ( list
(22).gt
.1 ) then
414 map
(nummap
+k
)=map
(23+k
)
419 elseif
( number
.eq
.9 ) then
420 if ( list
(29).gt
.1 ) then
423 map
(nummap
+k
)=map
(30+k
)
428 elseif
( number
.eq
.10 ) then
429 if ( list
(23).gt
.1 ) then
432 map
(nummap
+k
)=map
(24+k
)
437 elseif
( number
.eq
.11 ) then
438 if ( list
(25).gt
.1 ) then
441 map
(nummap
+k
)=map
(26+k
)
446 elseif
( number
.eq
.12 ) then
447 if ( list
(24).gt
.1 ) then
450 map
(nummap
+k
)=map
(25+k
)
455 elseif
( number
.eq
.13 ) then
456 if ( list
(38).gt
.1 ) then
459 map
(nummap
+k
)=map
(39+k
)
469 elseif
( number
.eq
.14 ) then
470 if ( list
(37).gt
.1 ) then
473 map
(nummap
+k
)=map
(38+k
)
483 elseif
( number
.eq
.30 ) then
492 elseif
( number
.eq
.31 ) then
501 elseif
( number
.eq
.42 ) then
502 if ( list
(23).gt
.1 ) then
505 map
(nummap
+k
)=map
(24+k
)
510 elseif
( number
.eq
.43 ) then
511 if ( list
(26).gt
.1 ) then
514 map
(nummap
+k
)=map
(27+k
)
523 integer function getpdtlen
(number
)
524 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
526 ! SUBPROGRAM
: getpdtlen
527 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2004-05-11
529 ! ABSTRACT
: This
function returns the initial length
(number of entries
) in
530 ! the
"static" part of specified Product Definition Template
4.number
.
532 ! PROGRAM HISTORY LOG
:
535 ! USAGE
: CALL getpdtlen
(number
)
536 ! INPUT ARGUMENT LIST
:
537 ! number
- NN
, indicating the number of the Product Definition
538 ! Template
4.NN that is being requested
.
540 ! RETURNS
: Number of entries in the
"static" part of PDT
4.number
541 ! OR returns
0, if requested template is not found
.
543 ! REMARKS
: If user needs the full length of a specific template that
544 ! contains additional entries based on values set in the
"static" part
545 ! of the PDT
, subroutine extpdstemplate can be used
.
548 ! LANGUAGE
: Fortran
90
552 integer,intent
(in
) :: number
556 index
=getpdsindex
(number
)
558 if (index
.ne
.-1) then
559 getpdtlen
=templates
(index
)%mappdslen