45 g2int nbitsd=0, isign;
46 g2int j, iofst, ival1, ival2, minsd, itemp, l, k, n, non=0;
47 g2int *ifld, *ifldmiss=0;
48 g2int *gref, *gwidth, *glen;
49 g2int itype, ngroups, nbitsgref, nbitsgwidth, nbitsglen;
51 float ref, bscale, dscale, rmiss1, rmiss2;
54 LOG((3,
"comunpack lensec %ld idrsnum %ld ndpts %ld", lensec, idrsnum, ndpts));
57 bscale = (float)
int_power(2.0, idrstmpl[1]);
58 dscale = (float)
int_power(10.0, -idrstmpl[2]);
59 nbitsgref = idrstmpl[3];
61 ngroups = idrstmpl[9];
62 nbitsgwidth = idrstmpl[11];
63 nbitsglen = idrstmpl[15];
65 nbitsd=idrstmpl[17] * 8;
70 for (j = 0; j < ndpts; j++)
77 gref = (
g2int *)calloc(ngroups,
sizeof(
g2int));
78 gwidth = (
g2int *)calloc(ngroups,
sizeof(
g2int));
84 rdieee(idrstmpl+7,&rmiss1,1);
86 rmiss1 = (float)idrstmpl[7];
92 rdieee(idrstmpl+7,&rmiss1,1);
93 rdieee(idrstmpl+8,&rmiss2,1);
96 rmiss1 = (float)idrstmpl[7];
97 rmiss2 = (float)idrstmpl[8];
107 gbit(cpack, &ival1, iofst, nbitsd);
108 iofst = iofst + nbitsd;
109 if (idrstmpl[16] == 2)
112 gbit(cpack, &ival2, iofst, nbitsd);
113 iofst = iofst + nbitsd;
115 gbit(cpack, &isign, iofst, 1);
117 gbit(cpack, &minsd, iofst, nbitsd - 1);
118 iofst = iofst + nbitsd - 1;
132 gbits(cpack, gref, iofst, nbitsgref, 0, ngroups);
133 itemp = nbitsgref * ngroups;
134 iofst = iofst + itemp;
136 iofst = iofst + (8 - (itemp % 8));
140 for (j = 0; j < ngroups; j++)
145 if (nbitsgwidth != 0) {
146 gbits(cpack, gwidth, iofst, nbitsgwidth, 0, ngroups);
147 itemp = nbitsgwidth * ngroups;
148 iofst = iofst + itemp;
150 iofst = iofst + (8 - (itemp % 8));
153 for (j = 0; j < ngroups; j++)
157 for (j = 0; j < ngroups; j++)
158 gwidth[j] = gwidth[j] + idrstmpl[10];
161 glen = calloc(ngroups,
sizeof(
g2int));
164 gbits(cpack, glen, iofst, nbitsglen, 0, ngroups);
165 itemp = nbitsglen * ngroups;
166 iofst = iofst + itemp;
168 iofst = iofst + (8 - (itemp % 8));
172 for (j = 0; j < ngroups; j++)
175 for (j = 0;j<ngroups;j++)
176 glen[j] = (glen[j]*idrstmpl[13])+idrstmpl[12];
177 glen[ngroups-1] = idrstmpl[14];
183 for (j = 0; j < ngroups; j++)
185 totBit += (gwidth[j] * glen[j]);
190 if (totBit / 8. > lensec)
194 if (idrstmpl[6] == 0)
197 for (j = 0; j < ngroups; j++)
201 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
202 for (k = 0; k < glen[j]; k++)
204 ifld[n] = ifld[n] + gref[j];
210 for (l = n; l < n + glen[j]; l++)
214 iofst = iofst + (gwidth[j] * glen[j]);
217 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
220 ifldmiss = malloc(ndpts *
sizeof(
g2int));
221 for (j = 0; j < ndpts; j++)
225 for (j = 0; j < ngroups; j++)
231 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
232 iofst = iofst + (gwidth[j] * glen[j]);
233 for (k = 0; k < glen[j]; k++)
235 if (ifld[n] == msng1)
237 else if (idrstmpl[6] == 2 && ifld[n] == msng2)
241 ifld[non++] = ifld[n] + gref[j];
250 if (gref[j] == msng1)
252 for (l = n; l < n + glen[j]; l++)
255 else if (idrstmpl[6] == 2 && gref[j] == msng2)
257 for (l = n; l < n + glen[j]; l++)
262 for (l = n; l < n + glen[j]; l++)
264 for (l = non; l < non + glen[j]; l++)
283 if (idrstmpl[16] == 1)
286 if (idrstmpl[6] == 0)
290 for (n = 1; n < itemp; n++)
292 ifld[n] = ifld[n] + minsd;
293 ifld[n] = ifld[n] + ifld[n - 1];
296 else if (idrstmpl[16] == 2)
300 if (idrstmpl[6] == 0)
304 for (n = 2; n < itemp; n++)
306 ifld[n] = ifld[n] + minsd;
307 ifld[n] = ifld[n] + (2 * ifld[n - 1]) - ifld[n - 2];
313 if (idrstmpl[6] == 0)
315 for (n = 0; n <ndpts; n++)
317 fld[n] = (((float)ifld[n] * bscale) + ref) * dscale;
320 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
324 for (n = 0; n < ndpts; n++)
326 if (ifldmiss[n] == 0)
328 fld[n] = (((float)ifld[non++] * bscale) + ref) * dscale;
330 else if (ifldmiss[n] == 1)
332 else if (ifldmiss[n] == 2)
int comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float *fld)
This subroutine unpacks a data field that was packed using a complex packing algorithm as defined in ...
void gbit(unsigned char *in, g2int *iout, g2int iskip, g2int nbits)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
void gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
int64_t g2int
Long integer type.
Header file with internal function prototypes NCEPLIBS-g2c library.
double int_power(double x, g2int y)
Function similar to C pow() power function.
#define LOG(e)
Ignore logging to stdout.
void rdieee(g2int *rieee, float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.