Coverage Report

Created: 2026-02-14 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/grib/degrib/g2clib/drstemplates.c
Line
Count
Source
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
const struct drstemplate *get_templatesdrs()
34
67.0k
{
35
67.0k
    return templatesdrs;
36
67.0k
}
37
38
39
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
27.3k
{
67
27.3k
           g2int j,l_getdrsindex=-1;
68
69
45.9k
           for (j=0;j<MAXDRSTEMP;j++) {
70
45.9k
              if (number == templatesdrs[j].template_num) {
71
27.3k
                 l_getdrsindex=j;
72
27.3k
                 return(l_getdrsindex);
73
27.3k
              }
74
45.9k
           }
75
76
0
           return(l_getdrsindex);
77
27.3k
}
78
79
80
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
13.9k
{
113
13.9k
           g2int l_index;
114
13.9k
           gtemplate *new;
115
116
13.9k
           l_index=getdrsindex(number);
117
118
13.9k
           if (l_index != -1) {
119
13.9k
              new=(gtemplate *)malloc(sizeof(gtemplate));
120
13.9k
              new->type=5;
121
13.9k
              new->num=templatesdrs[l_index].template_num;
122
13.9k
              new->maplen=templatesdrs[l_index].mapdrslen;
123
13.9k
              new->needext=templatesdrs[l_index].needext;
124
13.9k
              new->map=(g2int *)templatesdrs[l_index].mapdrs;
125
13.9k
              new->extlen=0;
126
13.9k
              new->ext=0;        //NULL
127
13.9k
              return(new);
128
13.9k
           }
129
0
           else {
130
0
             printf("getdrstemplate: DRS Template 5.%d not defined.\n",(int)number);
131
0
           }
132
133
0
         return(0);        //NULL
134
13.9k
}
135
136
gtemplate *extdrstemplate(g2int number,g2int *list)
137
/*!$$$  SUBPROGRAM DOCUMENTATION BLOCK
138
!                .      .    .                                       .
139
! SUBPROGRAM:    extdrstemplate
140
!   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2000-05-11
141
!
142
! ABSTRACT: This subroutine generates the remaining octet map for a
143
!   given Data Representation Template, if required.  Some Templates can
144
!   vary depending on data values given in an earlier part of the
145
!   Template, and it is necessary to know some of the earlier entry
146
!   values to generate the full octet map of the Template.
147
!
148
! PROGRAM HISTORY LOG:
149
! 2000-05-11  Gilbert
150
! 2009-01-14  Vuong     Changed structure name template to gtemplate
151
!
152
! USAGE:    new=extdrstemplate(number,list);
153
!   INPUT ARGUMENT LIST:
154
!     number   - NN, indicating the number of the Data Representation
155
!                Template 5.NN that is being requested.
156
!     list()   - The list of values for each entry in the
157
!                the Data Representation Template 5.NN.
158
!
159
!   RETURN VALUE:
160
!        - Pointer to the returned template struct.
161
!          Returns NULL pointer, if template not found.
162
!
163
! ATTRIBUTES:
164
!   LANGUAGE: C
165
!   MACHINE:  IBM SP
166
!
167
!$$$*/
168
0
{
169
0
           gtemplate *new;
170
0
           g2int l_index,i;
171
172
0
           l_index=getdrsindex(number);
173
0
           if (l_index == -1) return(0);
174
175
0
           new=getdrstemplate(number);
176
0
           if (new == NULL) return NULL;
177
178
0
           if ( ! new->needext ) return(new);
179
180
0
           if ( number == 1 ) {
181
0
              new->extlen=list[10]+list[12];
182
0
              new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen);
183
0
              for (i=0;i<new->extlen;i++) {
184
0
                new->ext[i]=4;
185
0
              }
186
0
           }
187
0
           return(new);
188
189
0
}
190