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/mextract.c

    r12332 r13479  
    33int mextract (int argc, char **argv) {
    44 
    5   int i, j, k, m, N, N1, NPTS;
     5  int i, j, k, m, n, N, N1, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack;
    66  int param, mode, Nsecfilt;
    77  char *RegionName, *RegionList, *p;
    88  double *M1;
     9  char **cstack;
     10  float *values;
    911
    10   PhotCode *code;
    1112  Catalog catalog;
    1213  SkyList *skylist;
    13   Vector *vec;
     14  PhotCode *code;
     15  Vector **vec;
     16
     17  dbField *fields;
     18  dbStack *stack;
    1419
    1520  /* defaults */
     
    2429  if (!InitPhotcodes ()) goto escape;
    2530  Nsecfilt = GetPhotcodeNsecfilt ();
     31 
     32  // init locally static variables (time refs)
     33  dbExtractMeasuresInit();
    2634
    27   /* interpret command-line options */
    28   SetSelectionParam (0);
     35  // remove skyregion options
     36  // XXX this needs to explicitly handle -qregion and -skyregion
    2937  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
    30   if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    3138
    32   /* interpret required command-line arguments: mextract (value) */
    33   if (argc != 2) goto usage;
    34   param = GetMeasureParam (argv[1]);
    35   if (param == MEAS_ZERO) {
    36     if (!GetPhotcodeInfo (argv[1], &code, &mode)) {
    37       GetMeasureParam ("help");
    38       goto escape;
    39     }
    40     param = MEAS_MAG;
    41     for (p = argv[1]; *p != 0; p++) {
    42       if (*p == '.') *p = ':';
    43     }
    44   }
    45   if (!TestPhotSelections (&code, &mode, MEAS_ZERO)) goto escape;
     39  // command-line is of the form: avextract field,field, field [where (field op value)...]
     40
     41  // parse the fields to be extracted and returned
     42  fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields);
     43  if (fields == NULL) return (FALSE);
     44
     45  // parse the remainder of the line as a boolean math expression
     46  cstack = isolate_elements (argc-last, &argv[last], &Ncstack);
     47 
     48  // construct the db Boolean math stack (frees cstack)
     49  stack = dbRPN (Ncstack, cstack, &Nstack);
     50
     51  Nreturn = Nfields;
     52  dbCheckStack (stack, Nstack, DVO_TABLE_MEASURE, &fields, &Nfields);
     53  // XXX handle errors
    4654
    4755  /* load region corresponding to selection above */
    4856  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    49   if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
     57
     58  // XXX is this still needed?
     59  // if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
    5060
    5161  /* create storage vector */
    52   N = 0;
     62  ALLOCATE (values, float, Nfields);
     63  ALLOCATE (vec, Vector *, Nreturn);
     64  for (i = 0; i < Nreturn; i++) {
     65    if ((vec[i] = SelectVector (fields[i].name, ANYVECTOR, TRUE)) == NULL) goto escape;
     66  }
     67
     68  Npts = 0;
    5369  NPTS = 1;
    54   if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    5570
     71  // XXX need to add interrupt test to this loop
    5672  for (i = 0; i < skylist[0].Nregions; i++) {
     73    /* lock, load, unlock catalog */
    5774    catalog.filename = skylist[0].filename[i];
    5875    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     
    6986
    7087    for (j = 0; j < catalog.Naverage; j++) {
    71       M1 = NULL;
    7288      m = catalog.average[j].offset;
    73       M1 = ExtractMeasures (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &N1, param);
    74       for (k = 0; k < N1; k++) {
    75         vec[0].elements[N] = M1[k];
    76         N++;
    77         CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000);
     89      for (k = 0; k < catalog.average[j].Nm; k++, m++) {
     90
     91        // extract the relevant values for this measurement
     92        for (n = 0; n < Nfields; n++) {
     93          values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     94        }
     95       
     96        // test the conditional statement
     97        if (!dbBooleanCond (stack, Nstack, values)) continue;
     98        for (n = 0; n < Nreturn; n++) {
     99          vec[n][0].elements[Npts] = values[n];
     100        }
     101        Npts++;
     102        if (Npts >= NPTS) {
     103          NPTS += 2000;
     104          for (n = 0; n < Nreturn; n++) {
     105            REALLOCATE (vec[n][0].elements, float, NPTS);
     106          }
     107        }
    78108      }
    79       if (M1 != NULL) free (M1);
    80109    }
    81110    dvo_catalog_free (&catalog);
    82111  }
    83   vec[0].Nelements = N;
    84   REALLOCATE (vec[0].elements, float, MAX(1,N));
     112  for (n = 0; n < Nreturn; n++) {
     113    vec[n][0].Nelements = Npts;
     114    REALLOCATE (vec[n][0].elements, float, MAX(1,Npts));
     115  }
     116
     117  // XXX free fields and stack
    85118
    86119  FreeImageSelection ();
Note: See TracChangeset for help on using the changeset viewer.