(file) Return to jretile_manytofew.c CVS log (file) (dir) Up to [Development] / JSOC / proj / globalhs / apps

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

Karen Tian
Powered by
ViewCVS 0.9.4