IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 22, 2007, 12:23:09 PM (19 years ago)
Author:
eugene
Message:

upgrading to kapa 2.0 API, upgrades to dvo user interface

File:
1 edited

Legend:

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

    r12332 r13479  
    33int avextract (int argc, char **argv) {
    44 
    5   int i, j, m, N, NPTS, param;
     5  int i, j, n, m, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack;
    66  int Nsecfilt, mode;
    77  char *RegionName, *RegionList, *p;
     8  char **cstack;
     9  float *values;
    810
    911  Catalog catalog;
    1012  SkyList *skylist;
    1113  PhotCode *code;
    12   Vector *vec;
     14  Vector **vec;
     15
     16  dbField *fields;
     17  dbStack *stack;
    1318
    1419  /* defaults */
     
    2429  Nsecfilt = GetPhotcodeNsecfilt ();
    2530
    26   /* interpret command-line options */
    27   SetSelectionParam (0);
     31  // remove skyregion options
     32  // XXX this needs to explicitly handle -qregion and -skyregion
    2833  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
    29   if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    3034
    31   /* interpret required command-line arguments: mextract (value) */
    32   if (argc != 2) { goto usage; }
    33   param = GetAverageParam (argv[1]);
    34   if (param == AVE_ZERO) {
    35     if (!GetPhotcodeInfo (argv[1], &code, &mode)) {
    36       GetAverageParamHelp ();
    37       goto escape;
    38     }
    39     param = AVE_MAG;
    40     for (p = argv[1]; *p != 0; p++) {
    41       if (*p == '.') *p = ':';
    42     }
    43   }
    44   if (!TestPhotSelections (&code, &mode, param)) goto escape;
     35  // command-line is of the form: avextract field,field, field [where (field op value)...]
     36
     37  // parse the fields to be extracted and returned
     38  fields = dbCmdlineFields (argc, argv, DVO_TABLE_AVERAGE, &last, &Nfields);
     39  if (fields == NULL) return (FALSE);
     40
     41  // parse the remainder of the line as a boolean math expression
     42  cstack = isolate_elements (argc-last, &argv[last], &Ncstack);
     43 
     44  // construct the db Boolean math stack (frees cstack)
     45  stack = dbRPN (Ncstack, cstack, &Nstack);
     46
     47  Nreturn = Nfields;
     48  dbCheckStack (stack, Nstack, DVO_TABLE_AVERAGE, &fields, &Nfields);
     49  // XXX handle errors
    4550
    4651  /* load region corresponding to selection above */
    4752  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    4853
    49   /* create storage vector */
    50   N = 0;
     54  /* create output storage vectors */
     55  ALLOCATE (values, float, Nfields);
     56  ALLOCATE (vec, Vector *, Nreturn);
     57  for (i = 0; i < Nreturn; i++) {
     58    if ((vec[i] = SelectVector (fields[i].name, ANYVECTOR, TRUE)) == NULL) goto escape;
     59  }
     60
     61  Npts = 0;
    5162  NPTS = 1;
    52   if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    5363
    5464  // XXX need to add interrupt test to this loop
     
    6878    for (j = 0; j < catalog.Naverage; j++) {
    6979      m = catalog.average[j].offset;
    70       vec[0].elements[N] = ExtractAverages (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], param);
    71       N++;
    72       CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000);
     80      // extract the relevant values
     81      // XXX for measure values, this could be optimized for one loop over measures...
     82      for (n = 0; n < Nfields; n++) {
     83        values[n] = dbExtractAverages (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     84      }
     85      // test the conditional statement
     86      if (!dbBooleanCond (stack, Nstack, values)) continue;
     87      for (n = 0; n < Nreturn; n++) {
     88        vec[n][0].elements[Npts] = values[n];
     89      }
     90      Npts++;
     91      if (Npts >= NPTS) {
     92        NPTS += 2000;
     93        for (n = 0; n < Nreturn; n++) {
     94          REALLOCATE (vec[n][0].elements, float, NPTS);
     95        }
     96      }
    7397    }
    7498    dvo_catalog_free (&catalog);
    7599  }
    76   vec[0].Nelements = N;
    77   REALLOCATE (vec[0].elements, float, MAX(1,N));
     100  for (n = 0; n < Nreturn; n++) {
     101    vec[n][0].Nelements = Npts;
     102    REALLOCATE (vec[n][0].elements, float, MAX(1,Npts));
     103  }
     104
     105  // XXX free fields and stack
    78106
    79107  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
Note: See TracChangeset for help on using the changeset viewer.