2 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2001-04-03
7 ! ABSTRACT
: This Fortran Module contains info on all the available
8 ! GRIB2 Data Representation Templates used in Section
5 (DRS
).
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
5.1 as an example
)
17 ! This module also contains two subroutines
. Subroutine getdrstemplate
18 ! returns the octet map
for a specified Template number
, and
19 ! subroutine extdrstemplate 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 ! 2002-12-11 Gilbert
- Added templates
for JPEG2000 and PNG encoding
40 ! USAGE
: use drstemplates
43 ! LANGUAGE
: Fortran
90
48 integer,parameter :: MAXLEN
=200,MAXTEMP
=9
51 integer :: template_num
53 integer,dimension(MAXLEN
) :: mapdrs
57 type
(drstemplate
),dimension(MAXTEMP
) :: templates
59 data templates
(1)%template_num
/0/ ! Simple Packing
60 data templates
(1)%mapdrslen
/5/
61 data templates
(1)%needext
/.false
./
62 data
(templates
(1)%mapdrs
(j
),j
=1,5)
65 data templates
(2)%template_num
/2/ ! Complex Packing
66 data templates
(2)%mapdrslen
/16/
67 data templates
(2)%needext
/.false
./
68 data
(templates
(2)%mapdrs
(j
),j
=1,16)
69 & /4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1/
71 data templates
(3)%template_num
/3/ ! Complex Packing
- Spatial Diff
72 data templates
(3)%mapdrslen
/18/
73 data templates
(3)%needext
/.false
./
74 data
(templates
(3)%mapdrs
(j
),j
=1,18)
75 & /4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1,1,1/
77 data templates
(4)%template_num
/50/ ! Simple Packing
- Spectral Data
78 data templates
(4)%mapdrslen
/5/
79 data templates
(4)%needext
/.false
./
80 data
(templates
(4)%mapdrs
(j
),j
=1,5)
83 data templates
(5)%template_num
/51/ ! Complex Packing
- Spectral Data
84 data templates
(5)%mapdrslen
/10/
85 data templates
(5)%needext
/.false
./
86 data
(templates
(5)%mapdrs
(j
),j
=1,10)
87 & /4,-2,-2,1,-4,2,2,2,4,1/
89 data templates
(6)%template_num
/40000/ ! JPEG2000 Encoding
90 data templates
(6)%mapdrslen
/7/
91 data templates
(6)%needext
/.false
./
92 data
(templates
(6)%mapdrs
(j
),j
=1,7)
95 data templates
(7)%template_num
/40010/ ! PNG Encoding
96 data templates
(7)%mapdrslen
/5/
97 data templates
(7)%needext
/.false
./
98 data
(templates
(7)%mapdrs
(j
),j
=1,5)
101 data templates
(8)%template_num
/40/ ! JPEG2000 Encoding
102 data templates
(8)%mapdrslen
/7/
103 data templates
(8)%needext
/.false
./
104 data
(templates
(8)%mapdrs
(j
),j
=1,7)
107 data templates
(9)%template_num
/41/ ! PNG Encoding
108 data templates
(9)%mapdrslen
/5/
109 data templates
(9)%needext
/.false
./
110 data
(templates
(9)%mapdrs
(j
),j
=1,5)
113 ! data templates
(5)%template_num
/1/ ! Simple Packing
- Matrix
114 ! data templates
(5)%mapdrslen
/15/
115 ! data templates
(5)%needext
/.true
./
116 ! data
(templates
(5)%mapdrs
(j
),j
=1,15)
117 ! & /4,-2,-2,1,1,1,4,2,2,1,1,1,1,1,1/
122 integer function getdrsindex
(number
)
123 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
125 ! SUBPROGRAM
: getdrsindex
126 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2001-06-28
128 ! ABSTRACT
: This
function returns the index of specified Data
129 ! Representation Template
5.NN
(NN
=number
) in array templates
.
131 ! PROGRAM HISTORY LOG
:
134 ! USAGE
: index
=getdrsindex
(number
)
135 ! INPUT ARGUMENT LIST
:
136 ! number
- NN
, indicating the number of the Data Representation
137 ! Template
5.NN that is being requested
.
139 ! RETURNS
: Index of DRT
5.NN in array templates
, if template exists
.
145 ! LANGUAGE
: Fortran
90
149 integer,intent
(in
) :: number
154 if (number
.eq
.templates
(j
)%template_num
) then
163 subroutine getdrstemplate
(number
,nummap
,map
,needext
,iret
)
164 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
166 ! SUBPROGRAM
: getdrstemplate
167 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2000-05-11
169 ! ABSTRACT
: This
subroutine returns DRS template information
for a
170 ! specified Data Representation Template
5.NN
.
171 ! The number of entries in the template is returned along with a map
172 ! of the number of octets occupied by each entry
. Also
, a flag is
173 ! returned
to indicate whether the template would need
to be extended
.
175 ! PROGRAM HISTORY LOG
:
178 ! USAGE
: CALL getdrstemplate
(number
,nummap
,map
,needext
,iret
)
179 ! INPUT ARGUMENT LIST
:
180 ! number
- NN
, indicating the number of the Data Representation
181 ! Template
5.NN that is being requested
.
183 ! OUTPUT ARGUMENT LIST
:
184 ! nummap
- Number of entries in the Template
185 ! map
() - An array containing the number of octets that each
186 ! template entry occupies when packed up into the DRS
.
187 ! needext
- Logical variable indicating whether the Data Representation
188 ! Template has
to be extended
.
189 ! ierr
- Error
return code
.
191 ! 1 = Undefined Data Representation Template number
.
196 ! LANGUAGE
: Fortran
90
200 integer,intent
(in
) :: number
201 integer,intent
(out
) :: nummap
,map
(*),iret
202 logical,intent
(out
) :: needext
206 index
=getdrsindex
(number
)
208 if (index
.ne
.-1) then
209 nummap
=templates
(index
)%mapdrslen
210 needext
=templates
(index
)%needext
211 map
(1:nummap
)=templates
(index
)%mapdrs
(1:nummap
)
215 print
*,'getdrstemplate: DRS Template ',number
,
222 subroutine extdrstemplate
(number
,list
,nummap
,map
)
223 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
225 ! SUBPROGRAM
: extdrstemplate
226 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2000-05-11
228 ! ABSTRACT
: This
subroutine generates the remaining octet map
for a
229 ! given Data Representation Template
, if required
. Some Templates can
230 ! vary depending on data values given in an earlier part of the
231 ! Template
, and it is necessary
to know some of the earlier entry
232 ! values
to generate the full octet map of the Template
.
234 ! PROGRAM HISTORY LOG
:
237 ! USAGE
: CALL extdrstemplate
(number
,list
,nummap
,map
)
238 ! INPUT ARGUMENT LIST
:
239 ! number
- NN
, indicating the number of the Data Representation
240 ! Template
5.NN that is being requested
.
241 ! list
() - The list of values
for each entry in the
242 ! the Data Representation Template
5.NN
.
244 ! OUTPUT ARGUMENT LIST
:
245 ! nummap
- Number of entries in the Template
246 ! map
() - An array containing the number of octets that each
247 ! template entry occupies when packed up into the GDS
.
250 ! LANGUAGE
: Fortran
90
254 integer,intent
(in
) :: number
,list
(*)
255 integer,intent
(out
) :: nummap
,map
(*)
257 index
=getdrsindex
(number
)
258 if (index
.eq
.-1) return
260 if ( .not
. templates
(index
)%needext
) return
261 nummap
=templates
(index
)%mapdrslen
262 map
(1:nummap
)=templates
(index
)%mapdrs
(1:nummap
)
264 if ( number
.eq
.1 ) then