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

Diff for /JSOC/proj/globalhs/apps/jretile_manytofew.c between version 1.1 and 1.6

version 1.1, 2012/05/09 03:53:22 version 1.6, 2013/04/28 08:05:21
Line 1 
Line 1 
 #define MODES(L)        ((((L)+1)*(L))/2)  char *cvsinfo_jretile_manytofew = "cvsinfo: $Header$";
 #define MINIMUM(X,Y)    (((X)<(Y))?(X):(Y))  
 #define MAXIMUM(X,Y)    (((X)>(Y))?(X):(Y))  
  
 int jretile_manytofew(void) int jretile_manytofew(void)
 { {
Line 31  int jretile_manytofew(void)
Line 29  int jretile_manytofew(void)
   int mapmmax=-1;   int mapmmax=-1;
   int sinbdivs=-1;   int sinbdivs=-1;
   double cadence=0;   double cadence=0;
     int i;
  
   TIME tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */   TIME tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */
   char tstartstr[100], tscrstr[100];   char tstartstr[100], tscrstr[100];
Line 68  int jretile_manytofew(void)
Line 67  int jretile_manytofew(void)
     lifetime = DRMS_PERMANENT;     lifetime = DRMS_PERMANENT;
   else   else
     lifetime = DRMS_TRANSIENT;     lifetime = DRMS_TRANSIENT;
     unsigned short calverkey = (unsigned short)cmdparams_save_int(&cmdparams, "CALVERKEY", &newstat);
  
   char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat);   char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat);
  
Line 75  int jretile_manytofew(void)
Line 75  int jretile_manytofew(void)
   sprint_time(tstartstr, tstart, "TAI", 0);   sprint_time(tstartstr, tstart, "TAI", 0);
   ttotal=(char *)cmdparams_save_str(&cmdparams, "TTOTAL", &newstat);   ttotal=(char *)cmdparams_save_str(&cmdparams, "TTOTAL", &newstat);
   status=drms_names_parseduration(&ttotal, &nseconds, 1);   status=drms_names_parseduration(&ttotal, &nseconds, 1);
   if (status)    if (status != DRMS_SUCCESS)
   {   {
 //    newstat = newstat | CPSAVE_UNKNOWN_ERROR; //    newstat = newstat | CPSAVE_UNKNOWN_ERROR;
     fprintf(stderr, "ERROR: problem parsing TTOTAL, = %s\n", ttotal);     fprintf(stderr, "ERROR: problem parsing TTOTAL, = %s\n", ttotal);
Line 85  int jretile_manytofew(void)
Line 85  int jretile_manytofew(void)
   if (strcmp(kNOTSPECIFIED, tchunk))   if (strcmp(kNOTSPECIFIED, tchunk))
   {   {
     status=drms_names_parseduration(&tchunk, &chunksecs, 1);     status=drms_names_parseduration(&tchunk, &chunksecs, 1);
     if (status)      if (status != DRMS_SUCCESS)
       newstat = newstat | CPSAVE_UNKNOWN_ERROR;       newstat = newstat | CPSAVE_UNKNOWN_ERROR;
   }   }
   else   else
Line 121  int jretile_manytofew(void)
Line 121  int jretile_manytofew(void)
   }   }
  
 // set up ancillary dataseries for processing metadata // set up ancillary dataseries for processing metadata
   char *cvsinfo = strdup("$Header$");  //  char *cvsinfo = strdup("$Header$");
   DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname);   DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname);
   if (histlink != NULL)   if (histlink != NULL)
   {   {
     histrecnum=set_history(histlink, cvsinfo);      histrecnum=set_history(histlink);
     if (histrecnum < 0)     if (histrecnum < 0)
     {     {
       drms_close_record(tempoutrec, DRMS_FREE_RECORD);       drms_close_record(tempoutrec, DRMS_FREE_RECORD);
Line 210  int jretile_manytofew(void)
Line 210  int jretile_manytofew(void)
     fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);     fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);
     return 1;     return 1;
   }   }
   nrecsin = inrecset->n;  //  nrecsin = inrecset->n;
     nrecsin = drms_count_records(drms_env, inrecquery, &status);
     if (status != DRMS_SUCCESS)
     {
       fprintf(stderr, "ERROR: problem counting input records: status = %d, nrecs = %d\n", status, nrecsin);
       return 1;
     }
  
   if (verbflag)   if (verbflag)
     printf("input recordset opened, nrecs = %d\n", nrecsin);     printf("input recordset opened, nrecs = %d\n", nrecsin);
Line 287  int jretile_manytofew(void)
Line 293  int jretile_manytofew(void)
     return 1;     return 1;
   }   }
  
   irecout=0;    unsigned long long calversout, calvers;
   for (iset=0; iset < ntimechunks; iset++)    int fixflagarr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
     for (i=0;i<16;i++)
   {   {
     tstartout=tstart + iset * chunksecs;      if (getbits(calverkey,i,1))
     tstopout=tstartout+chunksecs;        fixflagarr[i]=1;
   
     for (lchunk = lchunkfirst; lchunk <= lchunklast; lchunk++)  
     {  
       lminout = lchunk * lchunksize;  
       lmaxout = lminout + lchunksize - 1;  
       lminout = MAXIMUM(lminout,lmin);  
       lmaxout = MINIMUM(lmaxout,lmax);  
   
       outrec = outrecset->records[irecout];  
       if (histlink)  
         drms_setlink_static(outrec, histlinkname,  histrecnum);  
       drms_setkey_int(outrec, "LMIN", lminout);  
       drms_setkey_int(outrec, "LMAX", lmaxout);  
       drms_setkey_time(outrec, "T_START", tstartout);  
       drms_setkey_time(outrec, "T_STOP", tstopout);  
       drms_setkey_time(outrec, "T_OBS", tstartout+chunksecs/2);  
       drms_setkey_int(outrec, "NDT", ndt);  
 /*  
       if (segoutflag)  
         segout = drms_segment_lookup(outrec, segnameout);  
       else  
         segout = drms_segment_lookupnum(outrec, 0);  
       segout->axis[0]=2*ndt;  
       segout->axis[1]=lmaxout*(lmaxout+1)/2+lmaxout - lminout*(lminout+1)/2 + 1;  
 */  
       irecout++;  
     }  
   }   }
  
     unsigned int *nybblearrout = (unsigned int *)malloc(16*nrecsout*sizeof(unsigned int));
     int *mixflagarr    = (int *)calloc(16*nrecsout,sizeof(int));
     int *calverssetarr = (int *)calloc(16*nrecsout,sizeof(int));
     unsigned long long *calversoutarr = (unsigned long long *)malloc(nrecsout*sizeof(unsigned long long));
  
     int firsttimethrough=1;
   int *nskiparr=(int *)calloc(nrecsout,sizeof(int));   int *nskiparr=(int *)calloc(nrecsout,sizeof(int));
   for (irecin=0; irecin < nrecsin; irecin++)   for (irecin=0; irecin < nrecsin; irecin++)
   {   {
Line 333  int jretile_manytofew(void)
Line 318  int jretile_manytofew(void)
     lmaxin=drms_getkey_int(inrec, "LMAX", &status);     lmaxin=drms_getkey_int(inrec, "LMAX", &status);
     tstepin=tstopin-tstartin;     tstepin=tstopin-tstartin;
  
       if (verbflag > 1)
       {
         sprint_time(tscrstr, tstartin, "TAI", 0);
         printf("processing input %d, tstart = %s, lmin = %d, lmax = %d\n", irecin, tscrstr, lminin, lmaxin);
       }
   
     quality=drms_getkey_int(inrec, "QUALITY", &status);     quality=drms_getkey_int(inrec, "QUALITY", &status);
     if (status != DRMS_SUCCESS || (quality & QUAL_NODATA)) //may want stricter test on quality here     if (status != DRMS_SUCCESS || (quality & QUAL_NODATA)) //may want stricter test on quality here
     {     {
       if (verbflag > 2)       if (verbflag > 2)
       {       {
         sprint_time(tscrstr, tstartin, "TAI", 0);  //        sprint_time(tscrstr, tstartin, "TAI", 0);
         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",         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",
                                                                       tscrstr, lminin, lmaxin, inrec->recnum, irecin, status, quality);                                                                       tscrstr, lminin, lmaxin, inrec->recnum, irecin, status, quality);
       }       }
Line 352  int jretile_manytofew(void)
Line 343  int jretile_manytofew(void)
       segin = drms_segment_lookup(inrec, segnamein);       segin = drms_segment_lookup(inrec, segnamein);
     else     else
       segin = drms_segment_lookupnum(inrec, 0);       segin = drms_segment_lookupnum(inrec, 0);
     if (segin)      if (segin != NULL)
       inarr = drms_segment_read(segin, usetype, &status);       inarr = drms_segment_read(segin, usetype, &status);
 //      inarr = drms_segment_readslice(segin, usetype, startind, endind, &status); //      inarr = drms_segment_readslice(segin, usetype, startind, endind, &status);
     if (status != DRMS_SUCCESS || inarr == NULL || segin == NULL)     if (status != DRMS_SUCCESS || inarr == NULL || segin == NULL)
Line 369  int jretile_manytofew(void)
Line 360  int jretile_manytofew(void)
       inptr=(float *)(inarr->data);       inptr=(float *)(inarr->data);
     }     }
  
   
       calvers=drms_getkey_longlong(inrec, "CALVER64", &status);
       if (status != DRMS_SUCCESS)
         calvers = 0;
   
     irecout=0;     irecout=0;
     for (iset=0; iset < ntimechunks; iset++)     for (iset=0; iset < ntimechunks; iset++)
     {     {
Line 382  int jretile_manytofew(void)
Line 378  int jretile_manytofew(void)
         lmaxout = lminout + lchunksize - 1;         lmaxout = lminout + lchunksize - 1;
         lminout = MAXIMUM(lminout,lmin);         lminout = MAXIMUM(lminout,lmin);
         lmaxout = MINIMUM(lmaxout,lmax);         lmaxout = MINIMUM(lmaxout,lmax);
           outrec = outrecset->records[irecout];
   
           if (firsttimethrough)
           {
             if (histlink != NULL)
               drms_setlink_static(outrec, histlinkname,  histrecnum);
             drms_copykeys(outrec, inrec, 0, kDRMS_KeyClass_Explicit);
   // copykeys takes care of MAPMMAX, SINBDIVS, etc. that should be constant across the input
             drms_setkey_int(outrec, "LMIN", lminout);
             drms_setkey_int(outrec, "LMAX", lmaxout);
             drms_setkey_time(outrec, "T_START", tstartout);
             drms_setkey_time(outrec, "T_STOP", tstopout);
             drms_setkey_time(outrec, "T_OBS", tstartout+chunksecs/2);
             drms_setkey_int(outrec, "NDT", ndt);
           }
  
         if (tstartin >= tstopout || tstopin <= tstartout || lminin > lmaxout || lmaxin < lminout)         if (tstartin >= tstopout || tstopin <= tstartout || lminin > lmaxout || lmaxin < lminout)
         {         {
Line 389  int jretile_manytofew(void)
Line 400  int jretile_manytofew(void)
           continue;           continue;
         }         }
  
         outrec = outrecset->records[irecout];          int index0 = 16*irecout;
   
           if (!calverssetarr[irecout])
           {
             calversoutarr[irecout]=calvers;
             calverssetarr[irecout]=1;
             for (i=0;i<16;i++)
               nybblearrout[index0 + i]=getbits(calvers,4*i+3,4);
           }
   
           for (i=0;i<16;i++)
           {
             int nybble=getbits(calvers,4*i+3,4);
             if (fixflagarr[i])
             {
               if (nybble != nybblearrout[index0 + i])
               {
                 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);
                 return 0;
               }
             }
             else
             {
               if (nybble < nybblearrout[index0 + i])
                 nybblearrout[index0 + i]=nybble;
             }
           }
   
           if (!mixflagarr[irecout] && (quality & QUAL_MIXEDCALVER || calvers != calversoutarr[irecout]))
             mixflagarr[irecout]=1;
   
         if (segoutflag)         if (segoutflag)
           segout = drms_segment_lookup(outrec, segnameout);           segout = drms_segment_lookup(outrec, segnameout);
         else         else
Line 422  int jretile_manytofew(void)
Line 463  int jretile_manytofew(void)
         outarr = drms_array_create(usetype, 2, length, arrptr, &status);         outarr = drms_array_create(usetype, 2, length, arrptr, &status);
         if (status != DRMS_SUCCESS || outarr == NULL || arrptr == NULL)         if (status != DRMS_SUCCESS || outarr == NULL || arrptr == NULL)
         {         {
           fprintf(stderr,"ERROR: problem creating output array: T_START = %s, LMIN = %d, LMAX = %d, length = [%d, %d], status = %d, histrecnum = %lld",            fprintf(stderr,"ERROR: problem creating output array: T_START = %s, LMIN = %d, LMAX = %d, length = [%d, %d], status = %d, histrecnum = %lld\n",
                                                                 tstartstr, lminout, lmaxout, length[0], length[1], status, histrecnum);                                                                 tstartstr, lminout, lmaxout, length[0], length[1], status, histrecnum);
           drms_close_records(inrecset, DRMS_FREE_RECORD);           drms_close_records(inrecset, DRMS_FREE_RECORD);
           drms_close_records(outrecset, DRMS_FREE_RECORD);           drms_close_records(outrecset, DRMS_FREE_RECORD);
Line 443  int jretile_manytofew(void)
Line 484  int jretile_manytofew(void)
           in_offset+=2*tstepin/cadence;           in_offset+=2*tstepin/cadence;
         }         }
  
           outarr->bzero=segout->bzero;
           outarr->bscale=segout->bscale;
         status=drms_segment_writeslice_ext(segout, outarr, startind, endind, totallength, 0);         status=drms_segment_writeslice_ext(segout, outarr, startind, endind, totallength, 0);
         if (status != DRMS_SUCCESS)         if (status != DRMS_SUCCESS)
         {         {
Line 459  int jretile_manytofew(void)
Line 502  int jretile_manytofew(void)
       }  // end loop on lchunk       }  // end loop on lchunk
     }  // end loop on iset     }  // end loop on iset
  
     firsttimethrough=0;
     drms_free_array(inarr);
   continue_outer_loop:   continue_outer_loop:
   inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);   inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat, &chunkstat, NULL);
   }  // end loop on irecin   }  // end loop on irecin
Line 473  int jretile_manytofew(void)
Line 518  int jretile_manytofew(void)
     {     {
       drms_setkey_int(outrec, "QUALITY", QUAL_NODATA);       drms_setkey_int(outrec, "QUALITY", QUAL_NODATA);
     }     }
       else if (mixflagarr[irecout])
       {
         drms_setkey_int(outrec, "QUALITY", QUAL_MIXEDCALVER);
         nsegments++;
       }
     else     else
     {     {
       drms_setkey_int(outrec, "QUALITY", 0);       drms_setkey_int(outrec, "QUALITY", 0);
       nsegments++;       nsegments++;
     }     }
  
       for (i=0;i<16;i++)
         calversout=setbits(calversout,4*i+3,4,nybblearrout[16*irecout + i]);
       drms_setkey_longlong(outrec, "CALVER64", calversout);
   
     tnow = (double)time(NULL);     tnow = (double)time(NULL);
     tnow += UNIX_epoch;     tnow += UNIX_epoch;
     drms_setkey_time(outrec, "DATE", tnow);     drms_setkey_time(outrec, "DATE", tnow);


Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

Karen Tian
Powered by
ViewCVS 0.9.4