00001 char *cvsinfo_jretile_manytofew = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile_manytofew.c,v 1.10 2017/03/31 20:02:28 tplarson Exp $";
00002
00003 int jretile_manytofew(void)
00004 {
00005 int newstat = 0;
00006 int status = DRMS_SUCCESS;
00007 int fetchstat = DRMS_SUCCESS;
00008 DRMS_RecChunking_t chunkstat = kRecChunking_None;
00009
00010 char *inrecquery = NULL;
00011 char *outseries = NULL;
00012 char *segnamein = NULL;
00013 char *segnameout = NULL;
00014 DRMS_RecordSet_t *inrecset = NULL;
00015 DRMS_RecordSet_t *outrecset = NULL;
00016 int irecin, irecout, nrecsin=0, nrecsout=0, nlchunks;
00017 DRMS_Record_t *inrec = NULL;
00018 DRMS_Record_t *outrec = NULL;
00019 DRMS_Segment_t *segin = NULL;
00020 DRMS_Segment_t *segout = NULL;
00021 DRMS_Array_t *inarr = NULL;
00022 DRMS_Array_t *outarr = NULL;
00023 DRMS_RecLifetime_t lifetime;
00024 DRMS_Type_t usetype = DRMS_TYPE_FLOAT;
00025 int length[2], startind[2], endind[2], totallength[2];
00026 float *inptr, *outptr;
00027 long long histrecnum=-1;
00028 int quality;
00029 int mapmmax=-1;
00030 int sinbdivs=-1;
00031 double cadence=0;
00032 int i;
00033
00034 TIME tnow, UNIX_epoch = -220924792.000;
00035 char tstartstr[100], tscrstr[100];
00036
00037 double tstart, tepoch, tstep, tround, tstop, tstartin, tstopin, tstepin, tstartuse, tstopuse, nseconds, chunksecs;
00038 char *ttotal, *tchunk;
00039 int ndt;
00040 int lmin, lmax, lminin, lmaxin, lminuse, lmaxuse, lchunk, lchunksize, lchunkfirst, lchunklast;
00041 int ntimechunks, nmodes, npts, imode, itime;
00042 int out_time_offset, out_modes_offset, out_offset, in_time_offset, in_modes_offset, in_offset, out_index, in_index;
00043 int iset, lminout, lmaxout;
00044 double tstartout, tstopout;
00045 float *arrptr;
00046
00047 int errbufstat=setvbuf(stderr, NULL, _IONBF, BUFSIZ);
00048 int outbufstat=setvbuf(stdout, NULL, _IONBF, BUFSIZ);
00049
00050 double wt0, wt1, wt2, wt3, wt;
00051 double ut0, ut1, ut2, ut3, ut;
00052 double st0, st1, st2, st3, st;
00053 double ct0, ct1, ct2, ct3, ct;
00054
00055 wt0=getwalltime();
00056 ct0=getcputime(&ut0, &st0);
00057
00058 inrecquery = (char *)cmdparams_save_str(&cmdparams, "in", &newstat);
00059 outseries = (char *)cmdparams_save_str(&cmdparams, "out", &newstat);
00060 segnamein = (char *)cmdparams_save_str(&cmdparams, "segin", &newstat);
00061 segnameout = (char *)cmdparams_save_str(&cmdparams, "segout", &newstat);
00062 int seginflag = strcmp(kNOTSPECIFIED, segnamein);
00063 int segoutflag = strcmp(kNOTSPECIFIED, segnameout);
00064 int verbflag = cmdparams_save_int(&cmdparams, "VERB", &newstat);
00065 int permflag = cmdparams_save_int(&cmdparams, "PERM", &newstat);
00066 if (permflag)
00067 lifetime = DRMS_PERMANENT;
00068 else
00069 lifetime = DRMS_TRANSIENT;
00070 unsigned short calverkey = (unsigned short)cmdparams_save_int(&cmdparams, "CALVERKEY", &newstat);
00071
00072 char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat);
00073
00074 tstart=cmdparams_save_time(&cmdparams, "TSTART", &newstat);
00075 sprint_time(tstartstr, tstart, "TAI", 0);
00076 ttotal=(char *)cmdparams_save_str(&cmdparams, "TTOTAL", &newstat);
00077 status=drms_names_parseduration(&ttotal, &nseconds, 1);
00078 if (status != DRMS_SUCCESS)
00079 {
00080
00081 fprintf(stderr, "ERROR: problem parsing TTOTAL, = %s\n", ttotal);
00082 return 1;
00083 }
00084 tchunk=(char *)cmdparams_save_str(&cmdparams, "TCHUNK", &newstat);
00085 if (strcmp(kNOTSPECIFIED, tchunk))
00086 {
00087 status=drms_names_parseduration(&tchunk, &chunksecs, 1);
00088 if (status != DRMS_SUCCESS)
00089 newstat = newstat | CPSAVE_UNKNOWN_ERROR;
00090 }
00091 else
00092 chunksecs=0;
00093
00094 lmin=cmdparams_save_int(&cmdparams, "LMIN", &newstat);
00095 lmax=cmdparams_save_int(&cmdparams, "LMAX", &newstat);
00096 lchunksize=cmdparams_save_int(&cmdparams, "LCHUNK", &newstat);
00097 if (lchunksize == 0)
00098 lchunksize=lmax+1;
00099
00100 if (newstat)
00101 {
00102 fprintf(stderr, "ERROR: problem with input arguments, status = %d, diagnosis follows\n", newstat);
00103 cpsave_decode_error(newstat);
00104 return 1;
00105 }
00106 else if (savestrlen != strlen(savestr))
00107 {
00108 fprintf(stderr, "ERROR: problem with savestr, savestrlen = %d, strlen(savestr) = %d\n", savestrlen, (int)strlen(savestr));
00109 return 1;
00110 }
00111
00112 DRMS_Record_t *tempoutrec = drms_create_record(drms_env,
00113 outseries,
00114 DRMS_TRANSIENT,
00115 &status);
00116
00117 if (status != DRMS_SUCCESS)
00118 {
00119 fprintf(stderr,"ERROR: couldn't open a record in output dataseries %s, status = %d\n", outseries, status);
00120 return 1;
00121 }
00122
00123
00124
00125 DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname);
00126 if (histlink != NULL)
00127 {
00128 histrecnum=set_history(histlink);
00129 if (histrecnum < 0)
00130 {
00131 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00132 return 1;
00133 }
00134 }
00135 else
00136 {
00137 fprintf(stderr,"WARNING: could not find history link in output dataseries\n");
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 tepoch=drms_getkey_time(tempoutrec, "T_START_epoch", &status);
00159 tstep=drms_getkey_float(tempoutrec, "T_START_step", &status);
00160 tround=drms_getkey_float(tempoutrec, "T_START_round", &status);
00161 cadence=drms_getkey_float(tempoutrec, "T_STEP", &status);
00162 if (fmod(tstart-tepoch,tstep) > tround/2)
00163 {
00164 sprint_time(tscrstr, tepoch, "TAI", 0);
00165 fprintf(stderr, "ERROR: output dataseries seems incompatible with input parameters (tstep must divide tstart-tepoch): TSTART = %s, T_START_epoch = %s, tstep = %f\n",
00166 tstartstr, tscrstr, tstep);
00167 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00168 return 1;
00169 }
00170 if (chunksecs == 0.0)
00171 chunksecs = tstep;
00172 else if (fmod(chunksecs,tstep))
00173 {
00174 fprintf(stderr, "ERROR: output dataseries seems incompatible with input parameters (tstep must divide chunksecs): chunksecs = %f, tstep = %f\n", chunksecs, tstep);
00175 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00176 return 1;
00177 }
00178 if (fmod(nseconds,chunksecs) != 0.0)
00179 {
00180 fprintf(stderr, "ERROR: input parameters seem incompatible (chunksecs must divide totalsecs): totalsecs = %f, chunksecs = %f\n", nseconds, chunksecs);
00181 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00182 return 1;
00183 }
00184 ntimechunks=nseconds/chunksecs;
00185 ndt=chunksecs/cadence;
00186 if (verbflag)
00187 {
00188 printf("%d timechunks, %.1f seconds per chunk\n", ntimechunks, chunksecs);
00189 }
00190
00191 int mapmmaxout=-1;
00192 int sinbdivsout=-1;
00193 DRMS_Keyword_t *outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "MAPMMAX");
00194 if (outkeytest != NULL && outkeytest->info->recscope == 1)
00195 mapmmaxout=drms_getkey_int(tempoutrec, "MAPMMAX", &status);
00196 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "SINBDIVS");
00197 if (outkeytest != NULL && outkeytest->info->recscope == 1)
00198 sinbdivsout=drms_getkey_int(tempoutrec, "SINBDIVS", &status);
00199
00200 float apinnerout=0.0;
00201 float apwidthout=0.0;
00202 float apinner=0.0;
00203 float apwidth=0.0;
00204 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "APINNER");
00205 if (outkeytest != NULL && outkeytest->info->recscope == 1)
00206 apinnerout=drms_getkey_float(tempoutrec, "APINNER", &status);
00207 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "APWIDTH");
00208 if (outkeytest != NULL && outkeytest->info->recscope == 1)
00209 apwidthout=drms_getkey_float(tempoutrec, "APWIDTH", &status);
00210
00211 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00212
00213 char *inchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "T_STEP"};
00214 DRMS_Keyword_t *inkeytest;
00215 int itest;
00216 inrecset = drms_open_recordset(drms_env, inrecquery, &status);
00217
00218
00219 if (status != DRMS_SUCCESS || inrecset == NULL)
00220 {
00221 fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);
00222 return 1;
00223 }
00224
00225 nrecsin = drms_count_records(drms_env, inrecquery, &status);
00226 if (status != DRMS_SUCCESS)
00227 {
00228 fprintf(stderr, "ERROR: problem counting input records: status = %d, nrecs = %d\n", status, nrecsin);
00229 return 1;
00230 }
00231
00232 if (verbflag)
00233 printf("input recordset opened, nrecs = %d\n", nrecsin);
00234
00235 int noinput=0;
00236 if (nrecsin == 0)
00237 {
00238 printf("WARNING: input recordset contains no records\n");
00239 noinput=1;
00240 goto skip1;
00241
00242 }
00243
00244 inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);
00245
00246
00247 for (itest=0; itest < ARRLENGTH(inchecklist); itest++)
00248 {
00249 inkeytest = hcon_lookup_lower(&inrec->keywords, inchecklist[itest]);
00250 if (inkeytest == NULL)
00251 {
00252 fprintf(stderr, "ERROR: required input keyword %s is missing\n", inchecklist[itest]);
00253 drms_close_records(inrecset, DRMS_FREE_RECORD);
00254 return 1;
00255 }
00256 }
00257
00258 if (cadence != drms_getkey_float(inrec, "T_STEP", &status))
00259 {
00260 fprintf(stderr, "ERROR: input T_STEP does not equal output T_STEP\n");
00261 drms_close_records(inrecset, DRMS_FREE_RECORD);
00262 return 1;
00263 }
00264
00265 inkeytest = hcon_lookup_lower(&inrec->keywords, "MAPMMAX");
00266 if (inkeytest != NULL)
00267 mapmmax=drms_getkey_int(inrec, "MAPMMAX", &status);
00268 if (mapmmaxout != -1 && mapmmaxout != mapmmax)
00269 {
00270 fprintf(stderr, "ERROR: input MAPMMAX does not equal output MAPMMAX, in=%d, out=%d\n", mapmmax, mapmmaxout);
00271 drms_close_records(inrecset, DRMS_FREE_RECORD);
00272 return 1;
00273 }
00274
00275 inkeytest = hcon_lookup_lower(&inrec->keywords, "SINBDIVS");
00276 if (inkeytest != NULL)
00277 sinbdivs=drms_getkey_int(inrec, "SINBDIVS", &status);
00278 if (sinbdivsout != -1 && sinbdivsout != sinbdivs)
00279 {
00280 fprintf(stderr, "ERROR: input SINBDIVS does not equal output SINBDIVS, in=%d, out=%d\n", sinbdivs, sinbdivsout);
00281 drms_close_records(inrecset, DRMS_FREE_RECORD);
00282 return 1;
00283 }
00284
00285 inkeytest = hcon_lookup_lower(&inrec->keywords, "APINNER");
00286 if (inkeytest != NULL)
00287 apinner=drms_getkey_float(inrec, "APINNER", &status);
00288 if (apinnerout != 0.0 && (int)(10000*apinnerout) != (int)(10000*apinner))
00289 {
00290 fprintf(stderr, "ERROR: input APINNER does not equal output APINNER, in=%f, out=%f\n",apinner, apinnerout);
00291 drms_close_records(inrecset, DRMS_FREE_RECORD);
00292 return 1;
00293 }
00294
00295 inkeytest = hcon_lookup_lower(&inrec->keywords, "APWIDTH");
00296 if (inkeytest != NULL)
00297 apwidth=drms_getkey_float(inrec, "APWIDTH", &status);
00298 if (apinnerout != 0.0 && (int)(10000*apwidthout) != (int)(10000*apwidth))
00299 {
00300 fprintf(stderr, "ERROR: input APWIDTH does not equal output APWIDTH, in=%f, out=%f\n", apwidth, apwidth);
00301 drms_close_records(inrecset, DRMS_FREE_RECORD);
00302 return 1;
00303 }
00304
00305 status=drms_stage_records(inrecset, 1, 0);
00306 if (status != DRMS_SUCCESS)
00307 {
00308 fprintf(stderr, "ERROR: drms_stage_records returned status = %d\n", status);
00309 return 1;
00310 }
00311
00312 skip1:
00313
00314 lchunkfirst = lmin/lchunksize;
00315 lchunklast = lmax/lchunksize;
00316
00317 nlchunks = (lchunklast - lchunkfirst) + 1;
00318 nrecsout = nlchunks*ntimechunks;
00319 outrecset = drms_create_records(drms_env, nrecsout, outseries, lifetime, &status);
00320 if (status != DRMS_SUCCESS || outrecset == NULL)
00321 {
00322 fprintf(stderr,"ERROR: unable to create records record in output dataseries %s, status = %d\n", outseries, status);
00323 drms_close_records(inrecset, DRMS_FREE_RECORD);
00324 return 1;
00325 }
00326
00327 unsigned long long calversout, calvers;
00328 int fixflagarr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
00329 for (i=0;i<16;i++)
00330 {
00331 if (getbits(calverkey,i,1))
00332 fixflagarr[i]=1;
00333 }
00334
00335 unsigned int *nybblearrout = (unsigned int *)malloc(16*nrecsout*sizeof(unsigned int));
00336 int *mixflagarr = (int *)calloc(16*nrecsout,sizeof(int));
00337 int *calverssetarr = (int *)calloc(16*nrecsout,sizeof(int));
00338 unsigned long long *calversoutarr = (unsigned long long *)malloc(nrecsout*sizeof(unsigned long long));
00339
00340 int firsttimethrough=1;
00341 int *nskiparr=(int *)calloc(nrecsout,sizeof(int));
00342 for (irecin=0; irecin < nrecsin; irecin++)
00343 {
00344
00345
00346 tstartin=drms_getkey_time(inrec, "T_START", &status);
00347 tstopin=drms_getkey_time(inrec, "T_STOP", &status);
00348 lminin=drms_getkey_int(inrec, "LMIN", &status);
00349 lmaxin=drms_getkey_int(inrec, "LMAX", &status);
00350 tstepin=tstopin-tstartin;
00351
00352 if (verbflag > 1)
00353 {
00354 sprint_time(tscrstr, tstartin, "TAI", 0);
00355 printf("processing input %d, tstart = %s, lmin = %d, lmax = %d\n", irecin, tscrstr, lminin, lmaxin);
00356 }
00357
00358 quality=drms_getkey_int(inrec, "QUALITY", &status);
00359 if (status != DRMS_SUCCESS || (quality & QUAL_NODATA))
00360 {
00361 if (verbflag > 2)
00362 {
00363
00364 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",
00365 tscrstr, lminin, lmaxin, inrec->recnum, irecin, status, quality);
00366 }
00367 for (irecout=0; irecout < nrecsout; irecout++)
00368 nskiparr[irecout]++;
00369 goto continue_outer_loop;
00370
00371 }
00372
00373 if (seginflag)
00374 segin = drms_segment_lookup(inrec, segnamein);
00375 else
00376 segin = drms_segment_lookupnum(inrec, 0);
00377 if (segin != NULL)
00378 inarr = drms_segment_read(segin, usetype, &status);
00379
00380 if (status != DRMS_SUCCESS || inarr == NULL || segin == NULL)
00381 {
00382 sprint_time(tscrstr, tstartin, "TAI", 0);
00383 fprintf(stderr, "ERROR: problem reading input segment, T_START = %s, LMIN = %d, LMAX = %d, recnum = %lld, irec = %d, status = %d\n",
00384 tscrstr, lminin, lmaxin, inrec->recnum, irecin, status);
00385 drms_close_records(inrecset, DRMS_FREE_RECORD);
00386 drms_close_records(outrecset, DRMS_FREE_RECORD);
00387 return 0;
00388 }
00389 else
00390 {
00391 inptr=(float *)(inarr->data);
00392 }
00393
00394
00395 calvers=drms_getkey_longlong(inrec, "CALVER64", &status);
00396 if (status != DRMS_SUCCESS)
00397 calvers = 0;
00398
00399 irecout=0;
00400 for (iset=0; iset < ntimechunks; iset++)
00401 {
00402 tstartout=tstart + iset * chunksecs;
00403 tstopout=tstartout+chunksecs;
00404 sprint_time(tstartstr, tstartout, "TAI", 0);
00405
00406 for (lchunk = lchunkfirst; lchunk <= lchunklast; lchunk++)
00407 {
00408 lminout = lchunk * lchunksize;
00409 lmaxout = lminout + lchunksize - 1;
00410 lminout = MAXIMUM(lminout,lmin);
00411 lmaxout = MINIMUM(lmaxout,lmax);
00412 outrec = outrecset->records[irecout];
00413
00414 if (firsttimethrough)
00415 {
00416 if (histlink != NULL)
00417 drms_setlink_static(outrec, histlinkname, histrecnum);
00418 drms_copykeys(outrec, inrec, 0, kDRMS_KeyClass_Explicit);
00419
00420 drms_setkey_int(outrec, "LMIN", lminout);
00421 drms_setkey_int(outrec, "LMAX", lmaxout);
00422 drms_setkey_time(outrec, "T_START", tstartout);
00423 drms_setkey_time(outrec, "T_STOP", tstopout);
00424 drms_setkey_time(outrec, "T_OBS", tstartout+chunksecs/2);
00425 drms_setkey_int(outrec, "NDT", ndt);
00426 }
00427
00428 if (tstartin >= tstopout || tstopin <= tstartout || lminin > lmaxout || lmaxin < lminout)
00429 {
00430 nskiparr[irecout++]++;
00431 continue;
00432 }
00433
00434 int index0 = 16*irecout;
00435
00436 if (!calverssetarr[irecout])
00437 {
00438 calversoutarr[irecout]=calvers;
00439 calverssetarr[irecout]=1;
00440 for (i=0;i<16;i++)
00441 nybblearrout[index0 + i]=getbits(calvers,4*i+3,4);
00442 }
00443
00444 for (i=0;i<16;i++)
00445 {
00446 int nybble=getbits(calvers,4*i+3,4);
00447 if (fixflagarr[i])
00448 {
00449 if (nybble != nybblearrout[index0 + i])
00450 {
00451 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);
00452 return 0;
00453 }
00454 }
00455 else
00456 {
00457 if (nybble < nybblearrout[index0 + i])
00458 nybblearrout[index0 + i]=nybble;
00459 }
00460 }
00461
00462 if (!mixflagarr[irecout] && (quality & QUAL_MIXEDCALVER || calvers != calversoutarr[irecout]))
00463 mixflagarr[irecout]=1;
00464
00465 if (segoutflag)
00466 segout = drms_segment_lookup(outrec, segnameout);
00467 else
00468 segout = drms_segment_lookupnum(outrec, 0);
00469 tstartuse=MAXIMUM(tstartout, tstartin);
00470 tstopuse= MINIMUM(tstopout, tstopin);
00471 lminuse=MAXIMUM(lminout, lminin);
00472 lmaxuse=MINIMUM(lmaxout, lmaxin);
00473 nmodes=MODES(lmaxuse+1)-MODES(lminuse);
00474 npts=(tstopuse - tstartuse)/cadence;
00475
00476 out_time_offset = (tstartuse - tstartout)/cadence;
00477 out_modes_offset = MODES(lminuse) - MODES(lminout);
00478
00479 out_offset = 0;
00480 in_time_offset = (tstartuse - tstartin)/cadence;
00481 in_modes_offset = MODES(lminuse) - MODES(lminin);
00482 in_offset = 2 * (in_modes_offset * tstepin / cadence + in_time_offset);
00483
00484 startind[0]=2*out_time_offset;
00485 startind[1]=out_modes_offset;
00486 endind[0]=2*(out_time_offset + npts) - 1;
00487 endind[1]=out_modes_offset + nmodes - 1;
00488 totallength[0]=2*ndt;
00489 totallength[1]=lmaxout*(lmaxout+1)/2+lmaxout - lminout*(lminout+1)/2 + 1;
00490
00491 length[0]=2*npts;
00492 length[1]=nmodes;
00493 arrptr=(float *)(calloc(length[0]*length[1],sizeof(float)));
00494 outarr = drms_array_create(usetype, 2, length, arrptr, &status);
00495 if (status != DRMS_SUCCESS || outarr == NULL || arrptr == NULL)
00496 {
00497 fprintf(stderr,"ERROR: problem creating output array: T_START = %s, LMIN = %d, LMAX = %d, length = [%d, %d], status = %d, histrecnum = %lld\n",
00498 tstartstr, lminout, lmaxout, length[0], length[1], status, histrecnum);
00499 drms_close_records(inrecset, DRMS_FREE_RECORD);
00500 drms_close_records(outrecset, DRMS_FREE_RECORD);
00501 return 0;
00502 }
00503 outptr = (float *)(outarr->data);
00504
00505 for (imode=0; imode<nmodes; imode++)
00506 {
00507 for (itime=0; itime<npts; itime++)
00508 {
00509 in_index=in_offset + 2*itime;
00510 out_index=out_offset + 2*itime;
00511 outptr[out_index] = inptr[in_index];
00512 outptr[out_index+1] = inptr[in_index+1];
00513 }
00514 out_offset+=2*npts;
00515 in_offset+=2*tstepin/cadence;
00516 }
00517
00518 outarr->bzero=segout->bzero;
00519 outarr->bscale=segout->bscale;
00520 status=drms_segment_writeslice_ext(segout, outarr, startind, endind, totallength, 0);
00521 if (status != DRMS_SUCCESS)
00522 {
00523 fprintf(stderr, "ERROR: problem writing output segment: status = %d, T_START = %s, LMIN = %d, LMAX = %d, histrecnum = %lld\n",
00524 status, tstartstr, lminout, lmaxout, histrecnum);
00525 drms_close_records(inrecset, DRMS_FREE_RECORD);
00526 drms_close_records(outrecset, DRMS_FREE_RECORD);
00527 return 0;
00528 }
00529
00530 drms_free_array(outarr);
00531
00532 irecout++;
00533 }
00534 }
00535
00536 firsttimethrough=0;
00537 drms_free_array(inarr);
00538 continue_outer_loop:
00539 inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);
00540 }
00541
00542 drms_close_records(inrecset, DRMS_FREE_RECORD);
00543
00544 int nsegments=0;
00545 for (irecout=0; irecout < nrecsout; irecout++)
00546 {
00547 outrec=outrecset->records[irecout];
00548 if (noinput || nskiparr[irecout] == nrecsin)
00549 {
00550 drms_setkey_int(outrec, "QUALITY", QUAL_NODATA);
00551 }
00552 else if (mixflagarr[irecout])
00553 {
00554 drms_setkey_int(outrec, "QUALITY", QUAL_MIXEDCALVER);
00555 nsegments++;
00556 }
00557 else
00558 {
00559 drms_setkey_int(outrec, "QUALITY", 0);
00560 nsegments++;
00561 }
00562
00563 for (i=0;i<16;i++)
00564 calversout=setbits(calversout,4*i+3,4,nybblearrout[16*irecout + i]);
00565 drms_setkey_longlong(outrec, "CALVER64", calversout);
00566
00567 tnow = (double)time(NULL);
00568 tnow += UNIX_epoch;
00569 drms_setkey_time(outrec, "DATE", tnow);
00570 }
00571
00572 free(nskiparr);
00573 drms_close_records(outrecset, DRMS_INSERT_RECORD);
00574
00575 wt=getwalltime();
00576 ct=getcputime(&ut, &st);
00577 if (verbflag)
00578 {
00579 printf("number of records created = %d\n", nrecsout);
00580 printf("number of segments created = %d\n", nsegments);
00581 fprintf(stdout, "total time spent: %.2f ms wall time, %.2f ms cpu time\n",
00582 wt-wt0, ct-ct0);
00583 }
00584
00585 printf("module %s successful completion\n", cmdparams.argv[0]);
00586
00587 return 0;
00588
00589 }