1 tplarson 1.8 char *cvsinfo_jretile_manytofew = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile_manytofew.c,v 1.7 2013/07/02 20:33:38 tplarson Exp $";
|
2 tplarson 1.6
|
3 tplarson 1.1 int jretile_manytofew(void)
4 {
5 int newstat = 0;
6 int status = DRMS_SUCCESS;
7 int fetchstat = DRMS_SUCCESS;
8 DRMS_RecChunking_t chunkstat = kRecChunking_None;
9
10 char *inrecquery = NULL;
11 char *outseries = NULL;
12 char *segnamein = NULL;
13 char *segnameout = NULL;
14 DRMS_RecordSet_t *inrecset = NULL;
15 DRMS_RecordSet_t *outrecset = NULL;
16 int irecin, irecout, nrecsin=0, nrecsout=0, nlchunks;
17 DRMS_Record_t *inrec = NULL;
18 DRMS_Record_t *outrec = NULL;
19 DRMS_Segment_t *segin = NULL;
20 DRMS_Segment_t *segout = NULL;
21 DRMS_Array_t *inarr = NULL;
22 DRMS_Array_t *outarr = NULL;
23 DRMS_RecLifetime_t lifetime;
24 tplarson 1.1 DRMS_Type_t usetype = DRMS_TYPE_FLOAT;
25 int length[2], startind[2], endind[2], totallength[2];
26 float *inptr, *outptr;
27 long long histrecnum=-1;
28 int quality;
29 int mapmmax=-1;
30 int sinbdivs=-1;
31 double cadence=0;
|
32 tplarson 1.5 int i;
|
33 tplarson 1.1
34 TIME tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */
35 char tstartstr[100], tscrstr[100];
36
37 double tstart, tepoch, tstep, tround, tstop, tstartin, tstopin, tstepin, tstartuse, tstopuse, nseconds, chunksecs;
38 char *ttotal, *tchunk;
39 int ndt;
40 int lmin, lmax, lminin, lmaxin, lminuse, lmaxuse, lchunk, lchunksize, lchunkfirst, lchunklast;
41 int ntimechunks, nmodes, npts, imode, itime;
42 int out_time_offset, out_modes_offset, out_offset, in_time_offset, in_modes_offset, in_offset, out_index, in_index;
43 int iset, lminout, lmaxout;
44 double tstartout, tstopout;
45 float *arrptr;
46
47 int errbufstat=setvbuf(stderr, NULL, _IONBF, BUFSIZ);
48 int outbufstat=setvbuf(stdout, NULL, _IONBF, BUFSIZ);
49
50 double wt0, wt1, wt2, wt3, wt;
51 double ut0, ut1, ut2, ut3, ut;
52 double st0, st1, st2, st3, st;
53 double ct0, ct1, ct2, ct3, ct;
54 tplarson 1.1
55 wt0=getwalltime();
56 ct0=getcputime(&ut0, &st0);
57
58 inrecquery = (char *)cmdparams_save_str(&cmdparams, "in", &newstat);
59 outseries = (char *)cmdparams_save_str(&cmdparams, "out", &newstat);
60 segnamein = (char *)cmdparams_save_str(&cmdparams, "segin", &newstat);
61 segnameout = (char *)cmdparams_save_str(&cmdparams, "segout", &newstat);
62 int seginflag = strcmp(kNOTSPECIFIED, segnamein);
63 int segoutflag = strcmp(kNOTSPECIFIED, segnameout);
64 int verbflag = cmdparams_save_int(&cmdparams, "VERB", &newstat);
65 int permflag = cmdparams_save_int(&cmdparams, "PERM", &newstat);
66 if (permflag)
67 lifetime = DRMS_PERMANENT;
68 else
69 lifetime = DRMS_TRANSIENT;
|
70 tplarson 1.5 unsigned short calverkey = (unsigned short)cmdparams_save_int(&cmdparams, "CALVERKEY", &newstat);
|
71 tplarson 1.1
72 char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat);
73
74 tstart=cmdparams_save_time(&cmdparams, "TSTART", &newstat);
75 sprint_time(tstartstr, tstart, "TAI", 0);
76 ttotal=(char *)cmdparams_save_str(&cmdparams, "TTOTAL", &newstat);
77 status=drms_names_parseduration(&ttotal, &nseconds, 1);
|
78 tplarson 1.3 if (status != DRMS_SUCCESS)
|
79 tplarson 1.1 {
80 // newstat = newstat | CPSAVE_UNKNOWN_ERROR;
81 fprintf(stderr, "ERROR: problem parsing TTOTAL, = %s\n", ttotal);
82 return 1;
83 }
84 tchunk=(char *)cmdparams_save_str(&cmdparams, "TCHUNK", &newstat);
85 if (strcmp(kNOTSPECIFIED, tchunk))
86 {
87 status=drms_names_parseduration(&tchunk, &chunksecs, 1);
|
88 tplarson 1.3 if (status != DRMS_SUCCESS)
|
89 tplarson 1.1 newstat = newstat | CPSAVE_UNKNOWN_ERROR;
90 }
91 else
92 chunksecs=0;
93
94 lmin=cmdparams_save_int(&cmdparams, "LMIN", &newstat);
95 lmax=cmdparams_save_int(&cmdparams, "LMAX", &newstat);
96 lchunksize=cmdparams_save_int(&cmdparams, "LCHUNK", &newstat);
97 if (lchunksize == 0)
98 lchunksize=lmax+1;
99
100 if (newstat)
101 {
102 fprintf(stderr, "ERROR: problem with input arguments, status = %d, diagnosis follows\n", newstat);
103 cpsave_decode_error(newstat);
104 return 1;
105 }
106 else if (savestrlen != strlen(savestr))
107 {
108 fprintf(stderr, "ERROR: problem with savestr, savestrlen = %d, strlen(savestr) = %d\n", savestrlen, (int)strlen(savestr));
109 return 1;
110 tplarson 1.1 }
111
112 DRMS_Record_t *tempoutrec = drms_create_record(drms_env,
113 outseries,
114 DRMS_TRANSIENT,
115 &status);
116
117 if (status != DRMS_SUCCESS)
118 {
119 fprintf(stderr,"ERROR: couldn't open a record in output dataseries %s, status = %d\n", outseries, status);
120 return 1;
121 }
122
123 // set up ancillary dataseries for processing metadata
|
124 tplarson 1.8 // char *cvsinfo = strdup("$Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile_manytofew.c,v 1.7 2013/07/02 20:33:38 tplarson Exp $");
|
125 tplarson 1.1 DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname);
126 if (histlink != NULL)
127 {
|
128 tplarson 1.6 histrecnum=set_history(histlink);
|
129 tplarson 1.1 if (histrecnum < 0)
130 {
131 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
132 return 1;
133 }
134 }
135 else
136 {
137 fprintf(stderr,"WARNING: could not find history link in output dataseries\n");
138 }
139
140 // these must be present in the output dataseries and variable, not links or constants
141 // now done in DoIt() that calls this function
142 /*
143 char *outchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "NDT"};
144 DRMS_Keyword_t *outkeytest;
145 int itest;
146 for (itest=0; itest < ARRLENGTH(outchecklist); itest++)
147 {
148 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, outchecklist[itest]);
149 if (outkeytest == NULL || outkeytest->info->islink || outkeytest->info->recscope == 1)
150 tplarson 1.1 {
151 fprintf(stderr, "ERROR: output keyword %s is either missing, constant, or a link\n", outchecklist[itest]);
152 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
153 return 1;
154 }
155 }
156 */
157
158 tepoch=drms_getkey_time(tempoutrec, "T_START_epoch", &status);
159 tstep=drms_getkey_float(tempoutrec, "T_START_step", &status);
160 tround=drms_getkey_float(tempoutrec, "T_START_round", &status);
161 cadence=drms_getkey_float(tempoutrec, "T_STEP", &status);
162 if (fmod(tstart-tepoch,tstep) > tround/2)
163 {
164 sprint_time(tscrstr, tepoch, "TAI", 0);
165 fprintf(stderr, "ERROR: output dataseries seems incompatible with input parameters (tstep must divide tstart-tepoch): TSTART = %s, T_START_epoch = %s, tstep = %f\n",
166 tstartstr, tscrstr, tstep);
167 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
168 return 1;
169 }
170 if (chunksecs == 0.0)
171 tplarson 1.1 chunksecs = tstep;
172 else if (fmod(chunksecs,tstep))
173 {
174 fprintf(stderr, "ERROR: output dataseries seems incompatible with input parameters (tstep must divide chunksecs): chunksecs = %f, tstep = %f\n", chunksecs, tstep);
175 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
176 return 1;
177 }
178 if (fmod(nseconds,chunksecs) != 0.0)
179 {
180 fprintf(stderr, "ERROR: input parameters seem incompatible (chunksecs must divide totalsecs): totalsecs = %f, chunksecs = %f\n", nseconds, chunksecs);
181 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
182 return 1;
183 }
184 ntimechunks=nseconds/chunksecs;
185 ndt=chunksecs/cadence;
186 if (verbflag)
187 {
188 printf("%d timechunks, %.1f seconds per chunk\n", ntimechunks, chunksecs);
189 }
190
191 int mapmmaxout=-1;
192 tplarson 1.1 int sinbdivsout=-1;
193 DRMS_Keyword_t *outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "MAPMMAX");
194 if (outkeytest != NULL && outkeytest->info->recscope == 1)
195 mapmmaxout=drms_getkey_int(tempoutrec, "MAPMMAX", &status);
196 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "SINBDIVS");
197 if (outkeytest != NULL && outkeytest->info->recscope == 1)
198 sinbdivsout=drms_getkey_int(tempoutrec, "SINBDIVS", &status);
199
200 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
201
202 char *inchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "T_STEP"};
203 DRMS_Keyword_t *inkeytest;
204 int itest;
205 inrecset = drms_open_recordset(drms_env, inrecquery, &status);
206 // inrecset = drms_open_records(drms_env, inrecquery, &status);
207
208 if (status != DRMS_SUCCESS || inrecset == NULL)
209 {
210 fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);
211 return 1;
212 }
|
213 tplarson 1.5 // nrecsin = inrecset->n;
214 nrecsin = drms_count_records(drms_env, inrecquery, &status);
215 if (status != DRMS_SUCCESS)
216 {
217 fprintf(stderr, "ERROR: problem counting input records: status = %d, nrecs = %d\n", status, nrecsin);
218 return 1;
219 }
|
220 tplarson 1.1
221 if (verbflag)
222 printf("input recordset opened, nrecs = %d\n", nrecsin);
223
224 int noinput=0;
225 if (nrecsin == 0)
226 {
227 printf("WARNING: input recordset contains no records\n");
228 noinput=1;
229 goto skip1;
230 // return 1;
231 }
232
233 inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);
234 // inrec = inrecset->records[0];
235
236 for (itest=0; itest < ARRLENGTH(inchecklist); itest++)
237 {
238 inkeytest = hcon_lookup_lower(&inrec->keywords, inchecklist[itest]);
239 if (inkeytest == NULL)
240 {
241 tplarson 1.1 fprintf(stderr, "ERROR: required input keyword %s is missing\n", inchecklist[itest]);
242 drms_close_records(inrecset, DRMS_FREE_RECORD);
243 return 1;
244 }
245 }
246
247 if (cadence != drms_getkey_float(inrec, "T_STEP", &status))
248 {
249 fprintf(stderr, "ERROR: input T_STEP does not equal output T_STEP\n");
250 drms_close_records(inrecset, DRMS_FREE_RECORD);
251 return 1;
252 }
253
254 inkeytest = hcon_lookup_lower(&inrec->keywords, "MAPMMAX");
255 if (inkeytest != NULL)
256 mapmmax=drms_getkey_int(inrec, "MAPMMAX", &status);
257 if (mapmmaxout != -1 && mapmmaxout != mapmmax)
258 {
259 fprintf(stderr, "ERROR: input MAPMMAX does not equal output MAPMMAX, in=%d, out=%d\n", mapmmax, mapmmaxout);
260 drms_close_records(inrecset, DRMS_FREE_RECORD);
261 return 1;
262 tplarson 1.1 }
263
264 inkeytest = hcon_lookup_lower(&inrec->keywords, "SINBDIVS");
265 if (outkeytest != NULL)
266 sinbdivs=drms_getkey_int(inrec, "SINBDIVS", &status);
267 if (sinbdivsout != -1 && sinbdivsout != sinbdivs)
268 {
269 fprintf(stderr, "ERROR: input SINBDIVS does not equal output SINBDIVS, in=%d, out=%d\n", sinbdivs, sinbdivsout);
270 drms_close_records(inrecset, DRMS_FREE_RECORD);
271 return 1;
272 }
273
274 status=drms_stage_records(inrecset, 1, 0);
275 if (status != DRMS_SUCCESS)
276 {
277 fprintf(stderr, "ERROR: drms_stage_records returned status = %d\n", status);
278 return 1;
279 }
280
281 skip1:
282
283 tplarson 1.1 lchunkfirst = lmin/lchunksize;
284 lchunklast = lmax/lchunksize;
285
286 nlchunks = (lchunklast - lchunkfirst) + 1;
287 nrecsout = nlchunks*ntimechunks;
288 outrecset = drms_create_records(drms_env, nrecsout, outseries, lifetime, &status);
289 if (status != DRMS_SUCCESS || outrecset == NULL)
290 {
291 fprintf(stderr,"ERROR: unable to create records record in output dataseries %s, status = %d\n", outseries, status);
292 drms_close_records(inrecset, DRMS_FREE_RECORD);
293 return 1;
294 }
295
|
296 tplarson 1.5 unsigned long long calversout, calvers;
297 int fixflagarr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
298 for (i=0;i<16;i++)
299 {
300 if (getbits(calverkey,i,1))
301 fixflagarr[i]=1;
302 }
303
304 unsigned int *nybblearrout = (unsigned int *)malloc(16*nrecsout*sizeof(unsigned int));
305 int *mixflagarr = (int *)calloc(16*nrecsout,sizeof(int));
306 int *calverssetarr = (int *)calloc(16*nrecsout,sizeof(int));
307 unsigned long long *calversoutarr = (unsigned long long *)malloc(nrecsout*sizeof(unsigned long long));
|
308 tplarson 1.1
|
309 tplarson 1.2 int firsttimethrough=1;
|
310 tplarson 1.1 int *nskiparr=(int *)calloc(nrecsout,sizeof(int));
311 for (irecin=0; irecin < nrecsin; irecin++)
312 {
313 // move to end of loop when using drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);
314 // inrec = inrecset->records[irecin];
315 tstartin=drms_getkey_time(inrec, "T_START", &status);
316 tstopin=drms_getkey_time(inrec, "T_STOP", &status);
317 lminin=drms_getkey_int(inrec, "LMIN", &status);
318 lmaxin=drms_getkey_int(inrec, "LMAX", &status);
319 tstepin=tstopin-tstartin;
320
|
321 tplarson 1.5 if (verbflag > 1)
322 {
323 sprint_time(tscrstr, tstartin, "TAI", 0);
324 printf("processing input %d, tstart = %s, lmin = %d, lmax = %d\n", irecin, tscrstr, lminin, lmaxin);
325 }
326
|
327 tplarson 1.1 quality=drms_getkey_int(inrec, "QUALITY", &status);
328 if (status != DRMS_SUCCESS || (quality & QUAL_NODATA)) //may want stricter test on quality here
329 {
330 if (verbflag > 2)
331 {
|
332 tplarson 1.5 // sprint_time(tscrstr, tstartin, "TAI", 0);
|
333 tplarson 1.8 printf("SKIP: input data not used due to quality: T_START = %s, LMIN = %d, LMAX = %d, recnum = %lld, irec = %d, status = %d, quality = %08x\n",
334 tscrstr, lminin, lmaxin, inrec->recnum, irecin, status, quality);
|
335 tplarson 1.1 }
336 for (irecout=0; irecout < nrecsout; irecout++)
337 nskiparr[irecout]++;
338 goto continue_outer_loop;
339 // continue;
340 }
341
342 if (seginflag)
343 segin = drms_segment_lookup(inrec, segnamein);
344 else
345 segin = drms_segment_lookupnum(inrec, 0);
|
346 tplarson 1.3 if (segin != NULL)
|
347 tplarson 1.1 inarr = drms_segment_read(segin, usetype, &status);
348 // inarr = drms_segment_readslice(segin, usetype, startind, endind, &status);
349 if (status != DRMS_SUCCESS || inarr == NULL || segin == NULL)
350 {
351 sprint_time(tscrstr, tstartin, "TAI", 0);
352 fprintf(stderr, "ERROR: problem reading input segment, T_START = %s, LMIN = %d, LMAX = %d, recnum = %lld, irec = %d, status = %d\n",
353 tscrstr, lminin, lmaxin, inrec->recnum, irecin, status);
354 drms_close_records(inrecset, DRMS_FREE_RECORD);
355 drms_close_records(outrecset, DRMS_FREE_RECORD);
356 return 0;
357 }
358 else
359 {
360 inptr=(float *)(inarr->data);
361 }
362
|
363 tplarson 1.5
364 calvers=drms_getkey_longlong(inrec, "CALVER64", &status);
365 if (status != DRMS_SUCCESS)
366 calvers = 0;
367
|
368 tplarson 1.1 irecout=0;
369 for (iset=0; iset < ntimechunks; iset++)
370 {
371 tstartout=tstart + iset * chunksecs;
372 tstopout=tstartout+chunksecs;
373 sprint_time(tstartstr, tstartout, "TAI", 0);
374
375 for (lchunk = lchunkfirst; lchunk <= lchunklast; lchunk++)
376 {
377 lminout = lchunk * lchunksize;
378 lmaxout = lminout + lchunksize - 1;
379 lminout = MAXIMUM(lminout,lmin);
380 lmaxout = MINIMUM(lmaxout,lmax);
|
381 tplarson 1.2 outrec = outrecset->records[irecout];
382
383 if (firsttimethrough)
384 {
|
385 tplarson 1.3 if (histlink != NULL)
|
386 tplarson 1.2 drms_setlink_static(outrec, histlinkname, histrecnum);
387 drms_copykeys(outrec, inrec, 0, kDRMS_KeyClass_Explicit);
|
388 tplarson 1.5 // copykeys takes care of MAPMMAX, SINBDIVS, etc. that should be constant across the input
|
389 tplarson 1.2 drms_setkey_int(outrec, "LMIN", lminout);
390 drms_setkey_int(outrec, "LMAX", lmaxout);
391 drms_setkey_time(outrec, "T_START", tstartout);
392 drms_setkey_time(outrec, "T_STOP", tstopout);
393 drms_setkey_time(outrec, "T_OBS", tstartout+chunksecs/2);
394 drms_setkey_int(outrec, "NDT", ndt);
395 }
|
396 tplarson 1.1
397 if (tstartin >= tstopout || tstopin <= tstartout || lminin > lmaxout || lmaxin < lminout)
398 {
399 nskiparr[irecout++]++;
400 continue;
401 }
402
|
403 tplarson 1.5 int index0 = 16*irecout;
404
405 if (!calverssetarr[irecout])
406 {
407 calversoutarr[irecout]=calvers;
408 calverssetarr[irecout]=1;
409 for (i=0;i<16;i++)
410 nybblearrout[index0 + i]=getbits(calvers,4*i+3,4);
411 }
412
413 for (i=0;i<16;i++)
414 {
415 int nybble=getbits(calvers,4*i+3,4);
416 if (fixflagarr[i])
417 {
418 if (nybble != nybblearrout[index0 + i])
419 {
420 fprintf(stderr, "ERROR: input data has mixed values for field %d of CALVER64: %d and %d, recnum = %lld, histrecnum = %lld\n", i, nybblearrout[i], nybble, inrec->recnum, histrecnum);
421 return 0;
422 }
423 }
424 tplarson 1.5 else
425 {
426 if (nybble < nybblearrout[index0 + i])
427 nybblearrout[index0 + i]=nybble;
428 }
429 }
430
431 if (!mixflagarr[irecout] && (quality & QUAL_MIXEDCALVER || calvers != calversoutarr[irecout]))
432 mixflagarr[irecout]=1;
433
|
434 tplarson 1.1 if (segoutflag)
435 segout = drms_segment_lookup(outrec, segnameout);
436 else
437 segout = drms_segment_lookupnum(outrec, 0);
438 tstartuse=MAXIMUM(tstartout, tstartin);
439 tstopuse= MINIMUM(tstopout, tstopin);
440 lminuse=MAXIMUM(lminout, lminin);
441 lmaxuse=MINIMUM(lmaxout, lmaxin);
442 nmodes=MODES(lmaxuse+1)-MODES(lminuse);
443 npts=(tstopuse - tstartuse)/cadence;
444
445 out_time_offset = (tstartuse - tstartout)/cadence;
446 out_modes_offset = MODES(lminuse) - MODES(lminout);
447 // out_offset = 2 * (out_modes_offset * ndt + out_time_offset);
448 out_offset = 0; // 2 * (out_modes_offset * npts + out_time_offset);
449 in_time_offset = (tstartuse - tstartin)/cadence;
450 in_modes_offset = MODES(lminuse) - MODES(lminin);
451 in_offset = 2 * (in_modes_offset * tstepin / cadence + in_time_offset);
452
453 startind[0]=2*out_time_offset;
454 startind[1]=out_modes_offset;
455 tplarson 1.1 endind[0]=2*(out_time_offset + npts) - 1;
456 endind[1]=out_modes_offset + nmodes - 1;
457 totallength[0]=2*ndt;
458 totallength[1]=lmaxout*(lmaxout+1)/2+lmaxout - lminout*(lminout+1)/2 + 1;
459
460 length[0]=2*npts;
461 length[1]=nmodes;
462 arrptr=(float *)(calloc(length[0]*length[1],sizeof(float)));
463 outarr = drms_array_create(usetype, 2, length, arrptr, &status);
464 if (status != DRMS_SUCCESS || outarr == NULL || arrptr == NULL)
465 {
|
466 tplarson 1.2 fprintf(stderr,"ERROR: problem creating output array: T_START = %s, LMIN = %d, LMAX = %d, length = [%d, %d], status = %d, histrecnum = %lld\n",
|
467 tplarson 1.1 tstartstr, lminout, lmaxout, length[0], length[1], status, histrecnum);
468 drms_close_records(inrecset, DRMS_FREE_RECORD);
469 drms_close_records(outrecset, DRMS_FREE_RECORD);
470 return 0;
471 }
472 outptr = (float *)(outarr->data);
473
474 for (imode=0; imode<nmodes; imode++)
475 {
476 for (itime=0; itime<npts; itime++)
477 {
478 in_index=in_offset + 2*itime;
479 out_index=out_offset + 2*itime;
480 outptr[out_index] = inptr[in_index];
481 outptr[out_index+1] = inptr[in_index+1];
482 }
483 out_offset+=2*npts; // 2*ndt;
484 in_offset+=2*tstepin/cadence;
485 }
486
|
487 tplarson 1.3 outarr->bzero=segout->bzero;
488 outarr->bscale=segout->bscale;
|
489 tplarson 1.1 status=drms_segment_writeslice_ext(segout, outarr, startind, endind, totallength, 0);
490 if (status != DRMS_SUCCESS)
491 {
492 fprintf(stderr, "ERROR: problem writing output segment: status = %d, T_START = %s, LMIN = %d, LMAX = %d, histrecnum = %lld\n",
493 status, tstartstr, lminout, lmaxout, histrecnum);
494 drms_close_records(inrecset, DRMS_FREE_RECORD);
495 drms_close_records(outrecset, DRMS_FREE_RECORD);
496 return 0;
497 }
498
499 drms_free_array(outarr);
500
501 irecout++;
502 } // end loop on lchunk
503 } // end loop on iset
504
|
505 tplarson 1.7 firsttimethrough=0;
506 drms_free_array(inarr);
507 continue_outer_loop:
508 inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);
|
509 tplarson 1.1 } // end loop on irecin
510
511 drms_close_records(inrecset, DRMS_FREE_RECORD);
512
513 int nsegments=0;
514 for (irecout=0; irecout < nrecsout; irecout++)
515 {
516 outrec=outrecset->records[irecout];
517 if (noinput || nskiparr[irecout] == nrecsin)
518 {
519 drms_setkey_int(outrec, "QUALITY", QUAL_NODATA);
520 }
|
521 tplarson 1.5 else if (mixflagarr[irecout])
522 {
523 drms_setkey_int(outrec, "QUALITY", QUAL_MIXEDCALVER);
524 nsegments++;
525 }
|
526 tplarson 1.1 else
527 {
528 drms_setkey_int(outrec, "QUALITY", 0);
529 nsegments++;
530 }
531
|
532 tplarson 1.5 for (i=0;i<16;i++)
533 calversout=setbits(calversout,4*i+3,4,nybblearrout[16*irecout + i]);
534 drms_setkey_longlong(outrec, "CALVER64", calversout);
535
|
536 tplarson 1.1 tnow = (double)time(NULL);
537 tnow += UNIX_epoch;
538 drms_setkey_time(outrec, "DATE", tnow);
539 }
540
541 free(nskiparr);
542 drms_close_records(outrecset, DRMS_INSERT_RECORD);
543
544 wt=getwalltime();
545 ct=getcputime(&ut, &st);
546 if (verbflag)
547 {
548 printf("number of records created = %d\n", nrecsout);
549 printf("number of segments created = %d\n", nsegments);
550 fprintf(stdout, "total time spent: %.2f ms wall time, %.2f ms cpu time\n",
551 wt-wt0, ct-ct0);
552 }
553
554 printf("module %s successful completion\n", cmdparams.argv[0]);
555
556 return 0;
557 tplarson 1.1
558 }
|