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);
95 rmiss1 = (float)idrstmpl[7];
96 rmiss2 = (float)idrstmpl[8];
106 gbit(cpack, &ival1, iofst, nbitsd);
107 iofst = iofst + nbitsd;
108 if (idrstmpl[16] == 2)
111 gbit(cpack, &ival2, iofst, nbitsd);
112 iofst = iofst + nbitsd;
114 gbit(cpack, &isign, iofst, 1);
116 gbit(cpack, &minsd, iofst, nbitsd - 1);
117 iofst = iofst + nbitsd - 1;
131 gbits(cpack, gref, iofst, nbitsgref, 0, ngroups);
132 itemp = nbitsgref * ngroups;
133 iofst = iofst + itemp;
135 iofst = iofst + (8 - (itemp % 8));
139 for (j = 0; j < ngroups; j++)
144 if (nbitsgwidth != 0) {
145 gbits(cpack, gwidth, iofst, nbitsgwidth, 0, ngroups);
146 itemp = nbitsgwidth * ngroups;
147 iofst = iofst + itemp;
149 iofst = iofst + (8 - (itemp % 8));
152 for (j = 0; j < ngroups; j++)
156 for (j = 0; j < ngroups; j++)
157 gwidth[j] = gwidth[j] + idrstmpl[10];
160 glen = calloc(ngroups,
sizeof(
g2int));
163 gbits(cpack, glen, iofst, nbitsglen, 0, ngroups);
164 itemp = nbitsglen * ngroups;
165 iofst = iofst + itemp;
167 iofst = iofst + (8 - (itemp % 8));
171 for (j = 0; j < ngroups; j++)
174 for (j = 0;j<ngroups;j++)
175 glen[j] = (glen[j]*idrstmpl[13])+idrstmpl[12];
176 glen[ngroups-1] = idrstmpl[14];
182 for (j = 0; j < ngroups; j++)
184 totBit += (gwidth[j] * glen[j]);
189 if (totBit / 8. > lensec)
193 if (idrstmpl[6] == 0)
196 for (j = 0; j < ngroups; j++)
200 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
201 for (k = 0; k < glen[j]; k++)
203 ifld[n] = ifld[n] + gref[j];
209 for (l = n; l < n + glen[j]; l++)
213 iofst = iofst + (gwidth[j] * glen[j]);
216 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
219 ifldmiss = malloc(ndpts *
sizeof(
g2int));
220 for (j = 0; j < ndpts; j++)
224 for (j = 0; j < ngroups; j++)
230 gbits(cpack, ifld + n, iofst, gwidth[j], 0, glen[j]);
231 iofst = iofst + (gwidth[j] * glen[j]);
232 for (k = 0; k < glen[j]; k++)
234 if (ifld[n] == msng1)
236 else if (idrstmpl[6] == 2 && ifld[n] == msng2)
240 ifld[non++] = ifld[n] + gref[j];
249 if (gref[j] == msng1)
251 for (l = n; l < n + glen[j]; l++)
254 else if (idrstmpl[6] == 2 && gref[j] == msng2)
256 for (l = n; l < n + glen[j]; l++)
261 for (l = n; l < n + glen[j]; l++)
263 for (l = non; l < non + glen[j]; l++)
282 if (idrstmpl[16] == 1)
285 if (idrstmpl[6] == 0)
289 for (n = 1; n < itemp; n++)
291 ifld[n] = ifld[n] + minsd;
292 ifld[n] = ifld[n] + ifld[n - 1];
295 else if (idrstmpl[16] == 2)
299 if (idrstmpl[6] == 0)
303 for (n = 2; n < itemp; n++)
305 ifld[n] = ifld[n] + minsd;
306 ifld[n] = ifld[n] + (2 * ifld[n - 1]) - ifld[n - 2];
312 if (idrstmpl[6] == 0)
314 for (n = 0; n <ndpts; n++)
316 fld[n] = (((float)ifld[n] * bscale) + ref) * dscale;
319 else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
323 for (n = 0; n < ndpts; n++)
325 if (ifldmiss[n] == 0)
327 fld[n] = (((float)ifld[non++] * bscale) + ref) * dscale;
329 else if (ifldmiss[n] == 1)
331 else if (ifldmiss[n] == 2)