44 g2int nbitsd = 0, isign;
45 g2int j, iofst, ival1, ival2, minsd, itemp, l, k, n, non = 0;
46 g2int *ifld, *ifldmiss = 0;
47 g2int *gref, *gwidth, *glen;
48 g2int itype, ngroups, nbitsgref, nbitsgwidth, nbitsglen;
50 float ref, bscale, dscale, rmiss1, rmiss2;
53 LOG((3,
"comunpack lensec %ld idrsnum %ld ndpts %ld", lensec, idrsnum, ndpts));
56 bscale = (float)
int_power(2.0, idrstmpl[1]);
57 dscale = (float)
int_power(10.0, -idrstmpl[2]);
58 nbitsgref = idrstmpl[3];
60 ngroups = idrstmpl[9];
61 nbitsgwidth = idrstmpl[11];
62 nbitsglen = idrstmpl[15];
64 nbitsd = idrstmpl[17] * 8;
69 for (j = 0; j < ndpts; j++)
76 gref = (
g2int *)calloc(ngroups,
sizeof(
g2int));
77 gwidth = (
g2int *)calloc(ngroups,
sizeof(
g2int));
83 rdieee(idrstmpl + 7, &rmiss1, 1);
85 rmiss1 = (float)idrstmpl[7];
91 rdieee(idrstmpl + 7, &rmiss1, 1);
92 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;
133 gbits(cpack, gref, iofst, nbitsgref, 0, ngroups);
134 itemp = nbitsgref * ngroups;
135 iofst = iofst + itemp;
137 iofst = iofst + (8 - (itemp % 8));
141 for (j = 0; j < ngroups; j++)
146 if (nbitsgwidth != 0)
148 gbits(cpack, gwidth, iofst, nbitsgwidth, 0, ngroups);
149 itemp = nbitsgwidth * ngroups;
150 iofst = iofst + itemp;
152 iofst = iofst + (8 - (itemp % 8));
156 for (j = 0; j < ngroups; j++)
160 for (j = 0; j < ngroups; j++)
161 gwidth[j] = gwidth[j] + idrstmpl[10];
164 glen = calloc(ngroups,
sizeof(
g2int));
167 gbits(cpack, glen, iofst, nbitsglen, 0, ngroups);
168 itemp = nbitsglen * ngroups;
169 iofst = iofst + itemp;
171 iofst = iofst + (8 - (itemp % 8));
175 for (j = 0; j < ngroups; j++)
178 for (j = 0; j < ngroups; j++)
179 glen[j] = (glen[j] * idrstmpl[13]) + idrstmpl[12];
180 glen[ngroups - 1] = idrstmpl[14];
186 for (j = 0; j < ngroups; j++)
188 totBit += (gwidth[j] * glen[j]);
193 if (totBit / 8. > lensec)
197 if (idrstmpl[6] == 0)
200 for (j = 0; j < ngroups; j++)
204 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
205 for (k = 0; k < glen[j]; k++)
207 ifld[n] = ifld[n] + gref[j];
213 for (l = n; l < n + glen[j]; l++)
217 iofst = iofst + (gwidth[j] * glen[j]);
220 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
223 ifldmiss = malloc(ndpts *
sizeof(
g2int));
224 for (j = 0; j < ndpts; j++)
228 for (j = 0; j < ngroups; j++)
234 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
235 iofst = iofst + (gwidth[j] * glen[j]);
236 for (k = 0; k < glen[j]; k++)
238 if (ifld[n] == msng1)
240 else if (idrstmpl[6] == 2 && ifld[n] == msng2)
245 ifld[non++] = ifld[n] + gref[j];
254 if (gref[j] == msng1)
256 for (l = n; l < n + glen[j]; l++)
259 else if (idrstmpl[6] == 2 && gref[j] == msng2)
261 for (l = n; l < n + glen[j]; l++)
266 for (l = n; l < n + glen[j]; l++)
268 for (l = non; l < non + glen[j]; l++)
287 if (idrstmpl[16] == 1)
290 if (idrstmpl[6] == 0)
294 for (n = 1; n < itemp; n++)
296 ifld[n] = ifld[n] + minsd;
297 ifld[n] = ifld[n] + ifld[n - 1];
300 else if (idrstmpl[16] == 2)
304 if (idrstmpl[6] == 0)
308 for (n = 2; n < itemp; n++)
310 ifld[n] = ifld[n] + minsd;
311 ifld[n] = ifld[n] + (2 * ifld[n - 1]) - ifld[n - 2];
317 if (idrstmpl[6] == 0)
319 for (n = 0; n < ndpts; n++)
321 fld[n] = (((float)ifld[n] * bscale) + ref) * dscale;
324 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
328 for (n = 0; n < ndpts; n++)
330 if (ifldmiss[n] == 0)
332 fld[n] = (((float)ifld[non++] * bscale) + ref) * dscale;
334 else if (ifldmiss[n] == 1)
336 else if (ifldmiss[n] == 2)