IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13440


Ignore:
Timestamp:
May 21, 2007, 7:48:06 AM (19 years ago)
Author:
eugene
Message:

working towards full boolean db expressions

Location:
branches/kapa-mods-2007-05/Ohana/src/opihi/dvo
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/avextract.c

    r13439 r13440  
    2424  Nsecfilt = GetPhotcodeNsecfilt ();
    2525
     26  // command-line is of the form: avextract field,field, field [where (field op value)...]
     27
     28  // parse the fields to be extracted and returned
     29  narg = argc;
     30  fields = ParseCmdlineFields (argc, argv, DVO_TABLE_AVERAGE, &last, &Nfields);
     31  if (fields == NULL) return (FALSE);
     32
     33  // require 'where' before boolean math
     34  if ((last != argc) && (strcasecmp(argv[last], "where") || (last >= argc - 2))) {
     35    gprint (GP_ERR, "syntax error\n");
     36    free (fields);
     37    return (FALSE);
     38  }
     39
     40  // parse the remainder of the line as a boolean math expression
     41  cstack = isolate_elements (argv-last, &argv[last+1], &Ncstack);
     42 
     43  // construct the db Boolean math stack
     44  dbStack = db_convert_to_RPN (Ncstack, cstack, &NdbStack);
     45
     46  Nreturn = Nfields;
     47  db_check_stack (dbStack, NdbStack, DVO_TABLE_AVERAGE, fields, &Nfields);
     48
    2649  /* interpret command-line options */
    2750  SetSelectionParam (0);
    2851  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
    29   if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    30 
    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;
    4552
    4653  /* load region corresponding to selection above */
    4754  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    4855
    49   /* create storage vector */
    50   N = 0;
     56  /* create output storage vectors */
     57  ALLOCATE (return, float, Nreturn);
     58  ALLOCATE (vec, Vector, Nreturn);
     59  for (i = 0; i < Nreturn; i++) {
     60    if ((vec[i] = SelectVector (fields[i].name, ANYVECTOR, TRUE)) == NULL) goto escape;
     61  }
     62
     63  Npts = 0;
    5164  NPTS = 1;
    52   if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    5365
    5466  // XXX need to add interrupt test to this loop
     
    7082      // extract the relevant values
    7183      for (n = 0; n < Nfields; n++) {
    72         value[n] = ExtractAveragesNew (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], field[n]);
     84        values[n] = ExtractAveragesNew (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], fields[n]);
    7385      }
    7486      // test the conditional statement
    75       if (!CheckBooleanCond (stack, Nstack, value, field, Nfield)) continue;
    76       for (n = 0; n < Nfields; n++) {
    77         vec[n].elements[N] = value[n];
     87      if (!CheckBooleanCond (dbStack, NdbStack, values, fields, Nfields)) continue;
     88      for (n = 0; n < Nreturn; n++) {
     89        vec[n].elements[N] = values[n];
    7890      }
    7991      N++;
  • branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dvodb.c

    r13439 r13440  
    88*/
    99
     10enum {DVO_TABLE_AVERAGE, DVO_TABLE_MEASURE};
     11
    1012// a single db field
    1113typedef struct {
    12   int fieldNumber;
     14  char *name;
     15  int extract;
     16  int table;
     17  int ID;
    1318  int magMode;
    1419  PhotCode *photcode;
    1520} dvoField;
    1621
    17 ParseFields (int argc, char **argv) {
     22// db boolean operations
     23typedef struct {
     24  char   *name;
     25  char    type;
     26  int     field;
     27  float   Float;
     28} dvoStack;
     29
     30dvoField *ParseCmdlineFields (int argc, char **argv, int table, int *last, int *nfields) {
     31
     32  int i, Nfields, NFIELDS,
     33
     34  *nfields = 0;
     35  Nfields = 0;
     36  NFIELDS = 10;
     37  ALLOCATE (fields, dvoField, NFIELDS);
    1838
    1939  // examine each argv[i] entry until we reach a where
    20   for (i = 0; (i < argc) && strcasecmp (argv[i], "where"); i++) {
     40  for (i = 1; (i < argc) && strcasecmp (argv[i], "where"); i++) {
    2141    // split the word by ","
    2242    p = argv[i];
     
    3252      // identify field for word
    3353      // need to know which type of fields to look for...
    34       ParseAverageField ();
     54      // xxx extend this more generally later
     55      if (table == DVO_TABLE_MEASURE) {
     56        status = ParseMeasureField (&fields[Nfields], field);
     57      }
     58      if (table == DVO_TABLE_AVERAGE) {
     59        status = ParseAverageField (&fields[Nfields], field);
     60      }
     61      if (!status) {
     62        gprint (GP_ERR, "unknown database field %s\n", field);
     63        free (field);
     64        free (fields);
     65        return (NULL);
     66      }
    3567      free (field);
     68
     69      Nfields ++;
     70      CHECK_REALLOCATE (fields, dvoField, NFIELDS, Nfields, 10);
    3671    }
    3772  }
    3873
     74  *last = i;
     75  *nfields = Nfields;
     76  return (fields);
     77}
  • branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dvofields.c

    r13439 r13440  
    1 
    2 # define ESCAPE(F,M) { \
    3   field->fieldNumber = (F); \
    4   field->magMode = (M); \
    5   field->photcode = NULL; \
    6   return (TRUE);
    71
    82int GetMagMode (char *string) {
     
    2014}
    2115
     16PhotCode *ParsePhotcodeField (char *field, int *mode, int default) {
     17
     18  char *tmpstring, *p;
     19  PhotCode *code;
     20
     21  *mode = default;
     22
     23  p = strchr (field, ':');
     24  if (p != NULL) {
     25    *mode = GetMagMode (p + 1);
     26    if (*mode == MAG_NONE) return (NULL);
     27    tmpstring = strncreate (field, p - field);
     28  } else {
     29    tmpstring = strcreate (field);
     30  }
     31  code = GetPhotcodebyName (tmpstring);
     32  free (tmpstring);
     33
     34  return (code);
     35}
     36
     37# define ESCAPE(F,M) { \
     38  field->ID = (F); \
     39  field->magMode = (M); \
     40  field->photcode = NULL; \
     41  return (TRUE);
     42
    2243int ParseMeasureField (dvoField *field, char *fieldName) {
    2344
    2445  PhotCode *code;
     46
     47  field->table = DVO_TABLE_MEASURE;
     48  field->name  = strcreate (fieldName);
    2549
    2650  if (!strcasecmp (fieldName, "RA"))       ESCAPE (MEAS_RA,       MAG_NONE);
     
    4569
    4670  // check for code:mode in photcode name
    47   mode = MAG_REL;
    48   p = strchr (fieldName, ':');
    49   if (p != NULL) {
    50     mode = GetMagMode (p + 1);
    51     if (mode == MAG_NONE) return (FALSE);
    52     tmpstring = strncreate (fieldName, p - fieldName);
    53   } else {
    54     tmpstring = strcreate (fieldName);
    55   }
    56   code = GetPhotcodebyName (tmpstring);
    57   free (tmpstring);
    58 
     71  code = ParsePhotcodeField (&mode, MAG_REL);
    5972  if (code == NULL) return (FALSE);
    6073
    6174  if (mode == MAG_ERR) {
    62     field->fieldNumber = MEAS_dMAG;
     75    field->ID = MEAS_dMAG;
    6376  } else {
    64     field->fieldNumber = MEAS_MAG;
     77    field->ID = MEAS_MAG;
    6578  }   
    6679 
     80  field->magMode = mode;
    6781  field->photcode = code;
    6882  return (TRUE);
     
    7286
    7387  PhotCode *code;
     88
     89  field->table = DVO_TABLE_AVERAGE;
    7490
    7591  if (!strcasecmp (fieldName, "RA"))    ESCAPE (AVE_RA,        MAG_NONE);
     
    98114
    99115  // check for code:mode in photcode name
    100   mode = MAG_AVE;
    101   p = strchr (fieldName, ':');
    102   if (p != NULL) {
    103     mode = GetMagMode (p + 1);
    104     if (mode == MAG_NONE) return (FALSE);
    105     tmpstring = strncreate (fieldName, p - fieldName);
    106   } else {
    107     tmpstring = strcreate (fieldName);
    108   }
    109   code = GetPhotcodebyName (tmpstring);
    110   free (tmpstring);
    111 
     116  code = ParsePhotcodeField (&mode, MAG_AVE);
    112117  if (code == NULL) return (FALSE);
    113118
    114119  // need to distinguish phot, sys errors and scatter
    115120  if (mode == MAG_ERR) {
    116     field->fieldNumber = MEAS_dMAG;
     121    field->ID = MEAS_dMAG;
    117122  } else {
    118     field->fieldNumber = MEAS_MAG;
     123    field->ID = MEAS_MAG;
    119124  }   
    120125 
     126  field->magMode = mode;
    121127  field->photcode = code;
    122128  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.