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