IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19579


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

Location:
trunk/Ohana/src/opihi
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/dvo/Makefile

    r14401 r19579  
    7878$(SRC)/lightcurve.$(ARCH).o             \
    7979$(SRC)/mextract.$(ARCH).o               \
     80$(SRC)/mmextract.$(ARCH).o              \
    8081$(SRC)/photcodes.$(ARCH).o              \
    8182$(SRC)/pmeasure.$(ARCH).o               \
  • trunk/Ohana/src/opihi/dvo/avextract.c

    r16936 r19579  
    33int avextract (int argc, char **argv) {
    44 
    5   int i, j, n, m, N, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack;
     5  int i, j, n, m, N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
    66  int Nsecfilt, mode, VERBOSE;
    77  char **cstack, name[1024];
     
    4848  fields = dbCmdlineFields (argc, argv, DVO_TABLE_AVERAGE, &last, &Nfields);
    4949  if (fields == NULL) return (FALSE);
     50
     51  // examine line for 'where' or 'match to'.  'match to' is forbidden
     52  state = dbCmdlineConditions (argc, argv, last, &next);
     53  if (state == DVO_DB_CMDLINE_ERROR) goto escape;
     54  if (state == DVO_DB_CMDLINE_IS_MATCH) goto escape; // not allowed for mextract
    5055
    5156  // parse the remainder of the line as a boolean math expression
  • trunk/Ohana/src/opihi/dvo/dbCmdlineFields.c

    r19571 r19579  
    11# include "dvoshell.h"
    22
    3 // identify the fields to be extracted (test for where, check syntax)
     3// check for 'where' or 'matched to'; return first field after the word, and the value
     4int dbCmdlineConditions (int argc, char **argv, int first, int *nextField) {
     5
     6  int isWhere, isMatch;
     7
     8  *nextField = argc;
     9
     10  // require 'where' or 'matched to' before boolean math
     11  if (first == argc) return DVO_DB_CMDLINE_IS_END;
     12
     13  isWhere = !strcasecmp(argv[first], "where");
     14  isMatch = !strcasecmp(argv[first], "match");
     15   
     16  if (!isMatch && !isWhere) {
     17    gprint (GP_ERR, "WHERE or MATCH TO\n");
     18    return DVO_DB_CMDLINE_ERROR;
     19  }
     20  if (isMatch && ((first + 1 >= argc - 1) || strcasecmp(argv[first+1], "to"))) {
     21    gprint (GP_ERR, "missing boolean expression\n");
     22    return DVO_DB_CMDLINE_ERROR;
     23  }
     24  if (isWhere && (first >= argc - 1)) {
     25    gprint (GP_ERR, "missing boolean expression\n");
     26    return DVO_DB_CMDLINE_ERROR;
     27  }
     28
     29  if (isWhere) {
     30    *nextField = first + 1;
     31    return DVO_DB_CMDLINE_IS_WHERE;
     32  }
     33
     34  if (isMatch) {
     35    *nextField = first + 2;
     36    return DVO_DB_CMDLINE_IS_MATCH;
     37  }
     38
     39  gprint (GP_ERR, "programming error?\n");
     40  return DVO_DB_CMDLINE_ERROR;
     41}
     42
     43// identify the fields to be extracted (check syntax)
     44// the 'last' pointer ends on the first word after the fields (where, match or EOL)
    445dbField *dbCmdlineFields (int argc, char **argv, int table, int *last, int *nfields) {
    546
     
    1556
    1657  // examine each argv[i] entry until we reach a 'where' or a 'matched'
    17   for (i = 1; (i < argc) && strcasecmp (argv[i], "where") && strcasecmp (argv[i], "matched"); i++) {
     58  for (i = 1; (i < argc) && strcasecmp (argv[i], "where") && strcasecmp (argv[i], "match"); i++) {
    1859    // split the word by ","
    1960    p = argv[i];
     
    5091  }
    5192
    52   // require 'where' or 'matched to' before boolean math
    53   // XXX push this to a test up one level
    54   if (i != argc) {
    55     if (strcasecmp(argv[i], "where")) {
    56       gprint (GP_ERR, "syntax error\n");
    57       free (fields);
    58       return (NULL);
    59     }
    60     if (i > argc - 2) {
    61       gprint (GP_ERR, "missing boolean expression\n");
    62       free (fields);
    63       return (NULL);
    64     }
    65     i++; // skip over the 'where'
    66   }
    67 
    6893  *last = i;
    6994  *nfields = Nfields;
  • trunk/Ohana/src/opihi/dvo/init.c

    r16433 r19579  
    4040int lightcurve      PROTO((int, char **));
    4141int mextract        PROTO((int, char **));
     42int mmextract        PROTO((int, char **));
    4243int pcat            PROTO((int, char **));
    4344int photcodes       PROTO((int, char **));
     
    9091  {1, "lightcurve",  lightcurve,   "extract lightcurve for a star"},
    9192  {1, "mextract",    mextract,     "extract measure data values"},
     93  {1, "mmextract",   mmextract,    "extract joined measurements"},
    9294  {1, "pcat",        skycat,       "plot catalog boundaries"},
    9395  {1, "photcodes",   photcodes,    "list photometry codes"},
  • trunk/Ohana/src/opihi/dvo/mextract.c

    r16936 r19579  
    33int mextract (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, Nfields, Nreturn, Ncstack, Nstack;
    66  int Nsecfilt, VERBOSE, loadImages, mosaicMode;
    77  char **cstack, name[1024];
     
    5050  if (fields == NULL) return (FALSE);
    5151
    52   // XXX add the skyregion limits as if it were a where statement
     52  // examine line for 'where' or 'match to'.  'match to' is forbidden
     53  state = dbCmdlineConditions (argc, argv, last, &next);
     54  if (state == DVO_DB_CMDLINE_ERROR) goto escape;
     55  if (state == DVO_DB_CMDLINE_IS_MATCH) goto escape; // not allowed for mextract
    5356
    5457  // parse the remainder of the line as a boolean math expression
    55   cstack = isolate_elements (argc-last, &argv[last], &Ncstack);
     58  cstack = isolate_elements (argc-next, &argv[next], &Ncstack);
    5659 
    5760  // construct the db Boolean math stack (frees cstack)
  • 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);
  • trunk/Ohana/src/opihi/include/dvoshell.h

    r17419 r19579  
    119119
    120120enum {DVO_TABLE_AVERAGE, DVO_TABLE_MEASURE};
     121enum {DVO_DB_CMDLINE_ERROR, DVO_DB_CMDLINE_IS_END, DVO_DB_CMDLINE_IS_WHERE, DVO_DB_CMDLINE_IS_MATCH};
    121122
    122123// options for selecting the ra,dec limits of the db selections
Note: See TracChangeset for help on using the changeset viewer.