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 g2float ref, bscale, dscale, rmiss1, rmiss2;
57 nbitsgref = idrstmpl[3];
59 ngroups = idrstmpl[9];
60 nbitsgwidth = idrstmpl[11];
61 nbitsglen = idrstmpl[15];
63 nbitsd=idrstmpl[17] * 8;
68 for (j = 0; j < ndpts; j++)
75 gref = (
g2int *)calloc(ngroups,
sizeof(
g2int));
76 gwidth = (
g2int *)calloc(ngroups,
sizeof(
g2int));
82 rdieee(idrstmpl+7,&rmiss1,1);
90 rdieee(idrstmpl+7,&rmiss1,1);
91 rdieee(idrstmpl+8,&rmiss2,1);
105 gbit(cpack, &ival1, iofst, nbitsd);
106 iofst = iofst + nbitsd;
107 if (idrstmpl[16] == 2)
110 gbit(cpack, &ival2, iofst, nbitsd);
111 iofst = iofst + nbitsd;
113 gbit(cpack, &isign, iofst, 1);
115 gbit(cpack, &minsd, iofst, nbitsd - 1);
116 iofst = iofst + nbitsd - 1;
130 gbits(cpack, gref, iofst, nbitsgref, 0, ngroups);
131 itemp = nbitsgref * ngroups;
132 iofst = iofst + itemp;
134 iofst = iofst + (8 - (itemp % 8));
138 for (j = 0; j < ngroups; j++)
143 if (nbitsgwidth != 0) {
144 gbits(cpack, gwidth, iofst, nbitsgwidth, 0, ngroups);
145 itemp = nbitsgwidth * ngroups;
146 iofst = iofst + itemp;
148 iofst = iofst + (8 - (itemp % 8));
151 for (j = 0; j < ngroups; j++)
155 for (j = 0; j < ngroups; j++)
156 gwidth[j] = gwidth[j] + idrstmpl[10];
159 glen = calloc(ngroups,
sizeof(
g2int));
162 gbits(cpack, glen, iofst, nbitsglen, 0, ngroups);
163 itemp = nbitsglen * ngroups;
164 iofst = iofst + itemp;
166 iofst = iofst + (8 - (itemp % 8));
170 for (j = 0; j < ngroups; j++)
173 for (j = 0;j<ngroups;j++)
174 glen[j] = (glen[j]*idrstmpl[13])+idrstmpl[12];
175 glen[ngroups-1] = idrstmpl[14];
181 for (j = 0; j < ngroups; j++)
183 totBit += (gwidth[j] * glen[j]);
188 if (totBit / 8. > lensec)
192 if (idrstmpl[6] == 0)
195 for (j = 0; j < ngroups; j++)
199 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
200 for (k = 0; k < glen[j]; k++)
202 ifld[n] = ifld[n] + gref[j];
208 for (l = n; l < n + glen[j]; l++)
212 iofst = iofst + (gwidth[j] * glen[j]);
215 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
218 ifldmiss = malloc(ndpts *
sizeof(
g2int));
219 for (j = 0; j < ndpts; j++)
223 for (j = 0; j < ngroups; j++)
229 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
230 iofst = iofst + (gwidth[j] * glen[j]);
231 for (k = 0; k < glen[j]; k++)
233 if (ifld[n] == msng1)
235 else if (idrstmpl[6] == 2 && ifld[n] == msng2)
239 ifld[non++] = ifld[n] + gref[j];
248 if (gref[j] == msng1)
250 for (l = n; l < n + glen[j]; l++)
253 else if (idrstmpl[6] == 2 && gref[j] == msng2)
255 for (l = n; l < n + glen[j]; l++)
260 for (l = n; l < n + glen[j]; l++)
262 for (l = non; l < non + glen[j]; l++)
281 if (idrstmpl[16] == 1)
284 if (idrstmpl[6] == 0)
288 for (n = 1; n < itemp; n++)
290 ifld[n] = ifld[n] + minsd;
291 ifld[n] = ifld[n] + ifld[n - 1];
294 else if (idrstmpl[16] == 2)
298 if (idrstmpl[6] == 0)
302 for (n = 2; n < itemp; n++)
304 ifld[n] = ifld[n] + minsd;
305 ifld[n] = ifld[n] + (2 * ifld[n - 1]) - ifld[n - 2];
311 if (idrstmpl[6] == 0)
313 for (n = 0; n <ndpts; n++)
315 fld[n] = (((
g2float)ifld[n] * bscale) + ref) * dscale;
318 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
322 for (n = 0; n < ndpts; n++)
324 if (ifldmiss[n] == 0)
326 fld[n] = (((
g2float)ifld[non++] * bscale) + ref) * dscale;
328 else if (ifldmiss[n] == 1)
330 else if (ifldmiss[n] == 2)
int comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, g2float *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 nbyte)
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 nbyte, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
double int_power(double x, g2int y)
Function similar to C pow() power function.
void rdieee(g2int *rieee, g2float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.