1 #include <stdlib.h>
2 #include "grib2.h"
3 #include "drstemplates.h"
4
5 /* GDAL: in original g2clib, this is in drstemplates.h */
6 static const struct drstemplate templatesdrs[MAXDRSTEMP] = {
7 // 5.0: Grid point data - Simple Packing
8 { 0, 5, 0, {4,-2,-2,1,1} },
9 // 5.2: Grid point data - Complex Packing
10 { 2, 16, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1} },
11 // 5.3: Grid point data - Complex Packing and spatial differencing
12 { 3, 18, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1,1,1} },
13 // 5.4: Grid point data - IEEE Floating Point Data
14 { 4, 1, 0, {1} },
15 // 5.50: Spectral Data - Simple Packing
16 { 50, 5, 0, {4,-2,-2,1,4} },
17 // 5.51: Spherical Harmonics data - Complex packing
18 { 51, 10, 0, {4,-2,-2,1,-4,2,2,2,4,1} },
19 // // 5.1: Matrix values at gridpoint - Simple packing
20 // { 1, 15, 1, {4,-2,-2,1,1,1,4,2,2,1,1,1,1,1,1} },
21 // 5.40: Grid point data - JPEG2000 encoding
22 { 40, 7, 0, {4,-2,-2,1,1,1,1} },
23 // 5.41: Grid point data - PNG encoding
24 { 41, 5, 0, {4,-2,-2,1,1} },
25 // 5.40000: Grid point data - JPEG2000 encoding
26 { 40000, 7, 0, {4,-2,-2,1,1,1,1} },
27 // 5.40010: Grid point data - PNG encoding
28 { 40010, 5, 0, {4,-2,-2,1,1} }
29 } ;
30
get_templatesdrs()31 const struct drstemplate *get_templatesdrs()
32 {
33 return templatesdrs;
34 }
35
36
getdrsindex(g2int number)37 g2int getdrsindex(g2int number)
38 /*!$$$ SUBPROGRAM DOCUMENTATION BLOCK
39 ! . . . .
40 ! SUBPROGRAM: getdrsindex
41 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-06-28
42 !
43 ! ABSTRACT: This function returns the index of specified Data
44 ! Representation Template 5.NN (NN=number) in array templates.
45 !
46 ! PROGRAM HISTORY LOG:
47 ! 2001-06-28 Gilbert
48 !
49 ! USAGE: index=getdrsindex(number)
50 ! INPUT ARGUMENT LIST:
51 ! number - NN, indicating the number of the Data Representation
52 ! Template 5.NN that is being requested.
53 !
54 ! RETURNS: Index of DRT 5.NN in array templates, if template exists.
55 ! = -1, otherwise.
56 !
57 ! REMARKS: None
58 !
59 ! ATTRIBUTES:
60 ! LANGUAGE: C
61 ! MACHINE: IBM SP
62 !
63 !$$$*/
64 {
65 g2int j,l_getdrsindex=-1;
66
67 for (j=0;j<MAXDRSTEMP;j++) {
68 if (number == templatesdrs[j].template_num) {
69 l_getdrsindex=j;
70 return(l_getdrsindex);
71 }
72 }
73
74 return(l_getdrsindex);
75 }
76
77
getdrstemplate(g2int number)78 gtemplate *getdrstemplate(g2int number)
79 /*!$$$ SUBPROGRAM DOCUMENTATION BLOCK
80 ! . . . .
81 ! SUBPROGRAM: getdrstemplate
82 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-11
83 !
84 ! ABSTRACT: This subroutine returns DRS template information for a
85 ! specified Data Representation Template 5.NN.
86 ! The number of entries in the template is returned along with a map
87 ! of the number of octets occupied by each entry. Also, a flag is
88 ! returned to indicate whether the template would need to be extended.
89 !
90 ! PROGRAM HISTORY LOG:
91 ! 2000-05-11 Gilbert
92 ! 2009-01-14 Vuong Changed structure name template to gtemplate
93 !
94 ! USAGE: new=getdrstemplate(number);
95 ! INPUT ARGUMENT LIST:
96 ! number - NN, indicating the number of the Data Representation
97 ! Template 5.NN that is being requested.
98 !
99 ! RETURN VALUE:
100 ! - Pointer to the returned template struct.
101 ! Returns NULL pointer, if template not found.
102 !
103 ! REMARKS: None
104 !
105 ! ATTRIBUTES:
106 ! LANGUAGE: C
107 ! MACHINE: IBM SP
108 !
109 !$$$*/
110 {
111 g2int l_index;
112 gtemplate *new;
113
114 l_index=getdrsindex(number);
115
116 if (l_index != -1) {
117 new=(gtemplate *)malloc(sizeof(gtemplate));
118 new->type=5;
119 new->num=templatesdrs[l_index].template_num;
120 new->maplen=templatesdrs[l_index].mapdrslen;
121 new->needext=templatesdrs[l_index].needext;
122 new->map=(g2int *)templatesdrs[l_index].mapdrs;
123 new->extlen=0;
124 new->ext=0; //NULL
125 return(new);
126 }
127 else {
128 printf("getdrstemplate: DRS Template 5.%d not defined.\n",(int)number);
129 return(0); //NULL
130 }
131
132 return(0); //NULL
133 }
134
extdrstemplate(g2int number,g2int * list)135 gtemplate *extdrstemplate(g2int number,g2int *list)
136 /*!$$$ SUBPROGRAM DOCUMENTATION BLOCK
137 ! . . . .
138 ! SUBPROGRAM: extdrstemplate
139 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-11
140 !
141 ! ABSTRACT: This subroutine generates the remaining octet map for a
142 ! given Data Representation Template, if required. Some Templates can
143 ! vary depending on data values given in an earlier part of the
144 ! Template, and it is necessary to know some of the earlier entry
145 ! values to generate the full octet map of the Template.
146 !
147 ! PROGRAM HISTORY LOG:
148 ! 2000-05-11 Gilbert
149 ! 2009-01-14 Vuong Changed structure name template to gtemplate
150 !
151 ! USAGE: new=extdrstemplate(number,list);
152 ! INPUT ARGUMENT LIST:
153 ! number - NN, indicating the number of the Data Representation
154 ! Template 5.NN that is being requested.
155 ! list() - The list of values for each entry in the
156 ! the Data Representation Template 5.NN.
157 !
158 ! RETURN VALUE:
159 ! - Pointer to the returned template struct.
160 ! Returns NULL pointer, if template not found.
161 !
162 ! ATTRIBUTES:
163 ! LANGUAGE: C
164 ! MACHINE: IBM SP
165 !
166 !$$$*/
167 {
168 gtemplate *new;
169 g2int l_index,i;
170
171 l_index=getdrsindex(number);
172 if (l_index == -1) return(0);
173
174 new=getdrstemplate(number);
175 if (new == NULL) return NULL;
176
177 if ( ! new->needext ) return(new);
178
179 if ( number == 1 ) {
180 new->extlen=list[10]+list[12];
181 new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
182 for (i=0;i<new->extlen;i++) {
183 new->ext[i]=4;
184 }
185 }
186 return(new);
187
188 }
189
190