IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 7, 2008, 3:31:01 PM (18 years ago)
Author:
eugene
Message:

big update from eam_branch_20081124 with updates to Opihi math

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/dvo/avextract.c

    r20819 r20936  
    66  int Nsecfilt, mode, VERBOSE;
    77  char **cstack, name[1024];
    8   float *values;
    98  void *Signal;
    109
    1110  Catalog catalog;
     11
     12  Vector **vec;
     13  dbStack *stack;
     14  dbField *fields;
     15  dbValue *values;
    1216  SkyList *skylist;
    1317  SkyRegionSelection *selection;
    14   PhotCode *code;
    15   Vector **vec;
    16   dbField *fields;
    17   dbStack *stack;
    1818
    1919  /* defaults */
     20  vec = NULL;
     21  stack = NULL;
     22  fields = NULL;
     23  values = NULL;
    2024  skylist = NULL;
    2125  selection = NULL;
    22   code = NULL;
     26
    2327  mode = MAG_AVE;
    24   fields = NULL;
    25   stack = NULL;
    2628
    2729  if ((N = get_argument (argc, argv, "-h"))) goto help;
     
    4749  // parse the fields to be extracted and returned
    4850  fields = dbCmdlineFields (argc, argv, DVO_TABLE_AVERAGE, &last, &Nfields);
    49   if (fields == NULL) return (FALSE);
     51  if (fields == NULL) goto escape;
     52  if (Nfields == 0) {
     53    FreeSkyRegionSelection (selection);
     54    dbFreeFields (fields, Nfields);
     55    dvo_catalog_free (&catalog);
     56    goto help;
     57  }
    5058
    5159  // examine line for 'where' or 'match to'.  'match to' is forbidden
     
    6674  Nreturn = Nfields;
    6775  if (!dbCheckStack (stack, Nstack, DVO_TABLE_AVERAGE, &fields, &Nfields)) goto escape;
    68   // XXX handle errors
    6976
    7077  /* load region corresponding to selection above */
     
    7279
    7380  /* create output storage vectors */
    74   ALLOCATE (values, float, Nfields);
     81  ALLOCATE (values, dbValue, Nfields);
    7582  ALLOCATE (vec, Vector *, Nreturn);
    7683  for (i = 0; i < Nreturn; i++) {
     
    8188    }
    8289    if ((vec[i] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) goto escape;
     90    ResetVector (vec[i], fields[i].type, NPTS);
    8391  }
    8492
     
    109117
    110118      m = catalog.average[j].measureOffset;
    111       dbExtractAveragesInit (); // reset counters for saved fields
     119
     120      // reset counters for saved fields, extract fields
     121      dbExtractAveragesInit ();
    112122      for (n = 0; n < Nfields; n++) {
    113123        values[n] = dbExtractAverages (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
    114124      }
     125
    115126      // test the conditional statement
    116127      if (!dbBooleanCond (stack, Nstack, values)) continue;
    117128      for (n = 0; n < Nreturn; n++) {
    118         vec[n][0].elements[Npts] = values[n];
     129        if (vec[n][0].type == OPIHI_FLT) {
     130          vec[n][0].elements.Flt[Npts] = values[n].Flt;
     131        } else {
     132          vec[n][0].elements.Int[Npts] = values[n].Int;
     133        }
    119134      }
    120135      Npts++;
     
    122137        NPTS += 2000;
    123138        for (n = 0; n < Nreturn; n++) {
    124           REALLOCATE (vec[n][0].elements, float, NPTS);
     139          if (vec[n][0].type == OPIHI_FLT) {
     140            REALLOCATE (vec[n][0].elements.Flt, opihi_flt, NPTS);
     141          } else {
     142            REALLOCATE (vec[n][0].elements.Int, opihi_int, NPTS);
     143          }
    125144        }
    126145      }
     
    132151  for (n = 0; n < Nreturn; n++) {
    133152    vec[n][0].Nelements = Npts;
    134     REALLOCATE (vec[n][0].elements, float, MAX(1,Npts));
    135   }
    136 
     153    if (vec[n][0].type == OPIHI_FLT) {
     154      REALLOCATE (vec[n][0].elements.Flt, opihi_flt, MAX(1,Npts));
     155    } else {
     156      REALLOCATE (vec[n][0].elements.Int, opihi_int, MAX(1,Npts));
     157    }
     158  }
     159
     160  if (vec) free (vec);
     161  if (values) free (values);
    137162  dbFreeFields (fields, Nfields);
    138163  dbFreeStack (stack, Nstack);
    139   free (stack);
     164  if (stack) free (stack);
    140165  SkyListFree (skylist);
    141166  FreeSkyRegionSelection (selection);
     
    143168
    144169 escape:
     170  if (vec) free (vec);
     171  if (values) free (values);
    145172  dbFreeFields (fields, Nfields);
    146173  dbFreeStack (stack, Nstack);
    147   free (stack);
     174  if (stack) free (stack);
    148175  SkyListFree (skylist);
    149176  FreeSkyRegionSelection (selection);
Note: See TracChangeset for help on using the changeset viewer.