IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 7, 2008, 3:31:01 PM (18 years ago)
Author:
eugene
Message:

big update from eam_branch_20081124 with updates to Opihi math

File:
1 edited

Legend:

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

    r20819 r20936  
    88  int Nsecfilt, VERBOSE, loadImages, mosaicMode;
    99  char **cstack1, **cstack2, name1[1024], name2[1024];
    10   float *values, **table1, **table2;
     10  dbValue *values, **table1, **table2;
    1111  void *Signal;
    1212
    1313  Catalog catalog;
    1414  SkyList *skylist;
    15   PhotCode *code;
    1615  Vector **vec;
    1716  dbField *fields;
     
    2120
    2221  /* defaults */
    23   skylist = NULL;
    24   code = NULL;
    25   fields = NULL;
     22  vec = NULL;
    2623  stack1 = NULL;
    2724  stack2 = NULL;
     25  fields = NULL;
     26  values = NULL;
     27  skylist = NULL;
     28  selection = NULL;
    2829
    2930  if ((N = get_argument (argc, argv, "-h"))) goto help;
     
    5758  // parse the fields to be extracted and returned : last points to end, or first 'where' or 'matched'
    5859  fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields);
    59   if (fields == NULL) return (FALSE);
     60  if (fields == NULL) goto escape;
     61  if (Nfields == 0) {
     62    FreeSkyRegionSelection (selection);
     63    dbFreeFields (fields, Nfields);
     64    dvo_catalog_free (&catalog);
     65    goto help;
     66  }
    6067
    6168  // examine line for 'where' and 'match to'.  neither is required, but order is fixed
     
    139146
    140147  /* create storage vector */
    141   ALLOCATE (values, float, Nfields);
     148  ALLOCATE (values, dbValue, Nfields);
    142149  ALLOCATE (vec, Vector *, Nreturn);
    143150
     
    152159    if ((vec[2*i+0] = SelectVector (name1, ANYVECTOR, TRUE)) == NULL) goto escape;
    153160    if ((vec[2*i+1] = SelectVector (name2, ANYVECTOR, TRUE)) == NULL) goto escape;
     161    ResetVector (vec[2*i+0], fields[i].type, fields[i].type);
     162    ResetVector (vec[2*i+1], fields[i].type, fields[i].type);
    154163  }
    155164
     
    158167
    159168  // we save the selected measures for each average to temporary tables 1 and 2
     169  // XXX need to deal with the INT / DBL difference here...
    160170  NTABLE = 100;
    161   ALLOCATE (table1, float *, Nreturn_base);
    162   ALLOCATE (table2, float *, Nreturn_base);
     171  ALLOCATE (table1, dbValue *, Nreturn_base);
     172  ALLOCATE (table2, dbValue *, Nreturn_base);
    163173  for (i = 0; i < Nreturn_base; i++) {
    164     ALLOCATE (table1[i], float, NTABLE);
    165     ALLOCATE (table2[i], float, NTABLE);
     174    ALLOCATE (table1[i], dbValue, NTABLE);
     175    ALLOCATE (table2[i], dbValue, NTABLE);
    166176  }
    167177
     
    194204        NTABLE = catalog.average[j].Nmeasure;
    195205        for (n = 0; n < Nreturn_base; n++) {
    196           REALLOCATE (table1[n], float, NTABLE);
    197           REALLOCATE (table2[n], float, NTABLE);
     206          REALLOCATE (table1[n], dbValue, NTABLE);
     207          REALLOCATE (table2[n], dbValue, NTABLE);
    198208        }
    199209      }
     
    206216        dbExtractMeasuresInitMeas (); // reset counters for saved fields
    207217        for (n = 0; n < Nfields; n++) {
     218          // values needs to be a pointer to a type with FLT and INT (with a union, we would save a bit of memory...)
    208219          values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
    209220        }
     
    232243        for (n2 = 0; n2 < Nt2; n2++) {
    233244          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];
     245            if (vec[2*n+0][0].type == OPIHI_FLT) {
     246              vec[2*n+0][0].elements.Flt[Npts] = table1[n][n1].Flt;
     247              vec[2*n+1][0].elements.Flt[Npts] = table2[n][n2].Flt;
     248            } else {
     249              vec[2*n+0][0].elements.Int[Npts] = table1[n][n1].Int;
     250              vec[2*n+1][0].elements.Int[Npts] = table2[n][n2].Int;
     251            }
    236252          }
    237253          Npts++;
     
    239255            NPTS += 2000;
    240256            for (n = 0; n < Nreturn; n++) {
    241               REALLOCATE (vec[n][0].elements, float, NPTS);
     257              if (vec[n][0].type == OPIHI_FLT) {
     258                REALLOCATE (vec[n][0].elements.Flt, opihi_flt, NPTS);
     259              } else {
     260                REALLOCATE (vec[n][0].elements.Int, opihi_int, NPTS);
     261              }
    242262            }
    243263          }
     
    255275  interrupt = FALSE;
    256276
     277  // free excess memory
    257278  for (n = 0; n < Nreturn; n++) {
    258279    vec[n][0].Nelements = Npts;
    259     REALLOCATE (vec[n][0].elements, float, MAX(1,Npts));
     280    if (vec[n][0].type == OPIHI_FLT) {
     281      REALLOCATE (vec[n][0].elements.Flt, opihi_flt, MAX(1,Npts));
     282    } else {
     283      REALLOCATE (vec[n][0].elements.Int, opihi_int, MAX(1,Npts));
     284    }
    260285  }
    261286
     
    280305
    281306escape:
     307  if (vec) free (vec);
     308  if (values) free (values);
    282309  dbFreeFields (fields, Nfields);
    283310  dbFreeStack (stack1, Nstack1);
     
    292319
    293320 help:
    294   gprint (GP_ERR, "USAGE: mextract field[,field,field...] where (expression)\n");
     321  gprint (GP_ERR, "USAGE: mmextract field[,field,field...] where (expression) match to (expression)\n");
     322  gprint (GP_ERR, "  pairs of fields are returned: the first set are restricted by the 'where' expression, the second by the 'match to' expression\n");
    295323
    296324  if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
     
    344372    return (FALSE);
    345373  }
    346   gprint (GP_ERR, " mextract --help fields : for a complete listing of allowed fields\n");
     374  gprint (GP_ERR, " mmextract --help fields : for a complete listing of allowed fields\n");
    347375  return (FALSE);
    348376}
Note: See TracChangeset for help on using the changeset viewer.