IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 16, 2008, 9:16:26 AM (18 years ago)
Author:
eugene
Message:

adding mmextract and supporting api changes to dbCmdlineField.c functions

File:
1 edited

Legend:

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

    r19570 r19579  
    33int mmextract (int argc, char **argv) {
    44 
    5   int i, j, k, m, n, N, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack;
     5  int i, j, k, m, n, N, Npts, NPTS, last, next, state;
     6  int Nfields, Nreturn, Nreturn_base, Ncstack1, Ncstack2, Nstack1, Nstack2;
     7  int Nwhere, Iwhere, Nmatch, Imatch, NTABLE, Nt1, Nt2, n1, n2;
    68  int Nsecfilt, VERBOSE, loadImages, mosaicMode;
    7   char **cstack, name1[1024], name2[1024];
    8   float *values;
     9  char **cstack1, **cstack2, name1[1024], name2[1024];
     10  float *values, **table1, **table2;
    911  void *Signal;
    1012
     
    1416  Vector **vec;
    1517  dbField *fields;
    16   dbStack *stack;
     18  dbStack *stack1;
     19  dbStack *stack2;
    1720  SkyRegionSelection *selection;
    1821
     
    2124  code = NULL;
    2225  fields = NULL;
    23   stack = NULL;
     26  stack1 = NULL;
     27  stack2 = NULL;
    2428
    2529  if ((N = get_argument (argc, argv, "-h"))) goto help;
     
    5155  // -noauto means imageID is not matched
    5256
    53   // parse the fields to be extracted and returned
     57  // parse the fields to be extracted and returned : last points to end, or first 'where' or 'matched'
    5458  fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields);
    5559  if (fields == NULL) return (FALSE);
    5660
    57   // XXX require a 'where' and a 'matched to'? if not, all are cross-matched (that's ok)
    58   // XXX add the skyregion limits as if it were a where statement
    59 
    60   // need to find the location of 'where' and 'matched to' expressions
    61   for (i = last; i < argc; i++) {
    62     if (!strcasecmp (argv[i], "matched")) {
    63     }
    64   }
    65 
    66   whereS = N; whereE = N;
    67   matchS = N; matchE = N;
     61  // examine line for 'where' and 'match to'.  neither is required, but order is fixed
     62  state = dbCmdlineConditions (argc, argv, last, &next);
     63  if (state == DVO_DB_CMDLINE_ERROR) goto escape;
     64
     65  if (state == DVO_DB_CMDLINE_IS_END) {
     66      Nwhere = Nmatch = 0;
     67      Iwhere = Imatch = 0;
     68  }
     69
     70  if (state == DVO_DB_CMDLINE_IS_MATCH) {
     71      Nwhere = 0;
     72      Iwhere = 0;
     73      Imatch = next;
     74      Nmatch = argc - next;
     75  }
     76
     77  if (state == DVO_DB_CMDLINE_IS_WHERE) {
     78      Iwhere = next;
     79      // find the end or the 'match to'
     80      for (last = next; (last < argc) && strcasecmp (argv[last], "match"); last++);
     81      state = dbCmdlineConditions (argc, argv, last, &next);
     82      if (state == DVO_DB_CMDLINE_ERROR) goto escape;
     83      if (state == DVO_DB_CMDLINE_IS_WHERE) goto escape;
     84      if (state == DVO_DB_CMDLINE_IS_END) {
     85          Nwhere = argc - Iwhere;
     86          Imatch = Nmatch = 0;
     87      } else {
     88          Nwhere = last - Iwhere;
     89          Imatch = next;
     90          Nmatch = argc - Imatch;
     91      }
     92  }
    6893
    6994  // parse the 'where' and 'matched to' segments of the line as boolean math expressions
    70   cstack1 = isolate_elements (Nwhere, &argv[whereS], &Ncstack1);
    71   cstack2 = isolate_elements (Nmatch, &argv[matchS], &Ncstack2);
     95  cstack1 = isolate_elements (Nwhere, &argv[Iwhere], &Ncstack1);
     96  cstack2 = isolate_elements (Nmatch, &argv[Imatch], &Ncstack2);
    7297 
    7398  // construct the db Boolean math stack (frees cstack)
     
    88113
    89114  // add the skyregion limits to the where statement (or create)
    90   dbAstroRegionLimits (&stack, &Nstack, selection, DVO_TABLE_MEASURE);
     115  dbAstroRegionLimits (&stack1, &Nstack1, selection, DVO_TABLE_MEASURE);
     116  dbAstroRegionLimits (&stack2, &Nstack2, selection, DVO_TABLE_MEASURE);
    91117
    92118  // parse stack elements into fields and scalars as needed
     
    133159  // we save the selected measures for each average to temporary tables 1 and 2
    134160  NTABLE = 100;
    135   ALLOCATE (table1, double *, Nreturn_base);
    136   ALLOCATE (table2, double *, Nreturn_base);
     161  ALLOCATE (table1, float *, Nreturn_base);
     162  ALLOCATE (table2, float *, Nreturn_base);
    137163  for (i = 0; i < Nreturn_base; i++) {
    138     ALLOCATE (table1[i], double, NTABLE);
    139     ALLOCATE (table2[i], double, NTABLE);
     164    ALLOCATE (table1[i], float, NTABLE);
     165    ALLOCATE (table2[i], float, NTABLE);
    140166  }
    141167
     
    188214          for (n = 0; n < Nreturn_base; n++) {
    189215            table1[n][Nt1] = values[n];
    190             Nt1 ++;
    191216            // fprintf (stderr, "keep : field: %s, value: %f\n", fields[n].name, values[n]);
    192217          }
     218          Nt1 ++;
    193219        }
    194220        // test the second conditional statement
     
    196222          for (n = 0; n < Nreturn_base; n++) {
    197223            table2[n][Nt2] = values[n];
    198             Nt2 ++;
    199224            // fprintf (stderr, "keep : field: %s, value: %f\n", fields[n].name, values[n]);
    200225          }
    201         }
    202 
    203         // XXX now do the join :: need to filter against automatch if -noauto is selected (record the index value k to test)
    204         for (n1 = 0; n1 < Nt1; n1++) {
    205           for (n2 = 0; n2 < Nt2; n2++) {
    206             for (n = 0; n < Nreturn_base; n++) {
    207               vec[n][0].elements[Npts] = table1[n][n1];
    208             }
    209             for (n = 0; n < Nreturn_base; n++) {
    210               vec[n+Nreturn_base][0].elements[Npts] = table2[n][n2];
    211             }
    212             Npts++;
    213             if (Npts >= NPTS) {
    214               NPTS += 2000;
    215               for (n = 0; n < Nreturn; n++) {
    216                 REALLOCATE (vec[n][0].elements, float, NPTS);
    217               }
     226          Nt2 ++;
     227        }
     228      }
     229
     230      // XXX now do the join :: need to filter against automatch if -noauto is selected (record the index value k to test)
     231      for (n1 = 0; n1 < Nt1; n1++) {
     232        for (n2 = 0; n2 < Nt2; n2++) {
     233          for (n = 0; n < Nreturn_base; n++) {
     234            vec[2*n+0][0].elements[Npts] = table1[n][n1];
     235            vec[2*n+1][0].elements[Npts] = table2[n][n2];
     236          }
     237          Npts++;
     238          if (Npts >= NPTS) {
     239            NPTS += 2000;
     240            for (n = 0; n < Nreturn; n++) {
     241              REALLOCATE (vec[n][0].elements, float, NPTS);
    218242            }
    219243          }
     
    221245      }
    222246    }
     247
    223248    dvo_catalog_free (&catalog);
    224249    // dbStackAllocPrint ();
     
    235260  }
    236261
     262  for (n = 0; n < Nreturn_base; n++) {
     263    free (table1[n]);
     264    free (table2[n]);
     265  }
     266  free (table1);
     267  free (table2);
     268
     269  free (values);
     270
    237271  dbFreeFields (fields, Nfields);
    238   dbFreeStack (stack, Nstack);
    239   free (stack);
     272  dbFreeStack (stack1, Nstack1);
     273  dbFreeStack (stack2, Nstack2);
     274  free (stack1);
     275  free (stack2);
    240276  FreeImageSelection ();
    241277  SkyListFree (skylist);
     
    245281escape:
    246282  dbFreeFields (fields, Nfields);
    247   dbFreeStack (stack, Nstack);
    248   free (stack);
     283  dbFreeStack (stack1, Nstack1);
     284  dbFreeStack (stack2, Nstack2);
     285  free (stack1);
     286  free (stack2);
    249287  FreeImageSelection ();
    250288  SkyListFree (skylist);
Note: See TracChangeset for help on using the changeset viewer.