IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 12, 2007, 5:17:43 PM (19 years ago)
Author:
eugene
Message:

fixed handling of the photcodes in mextract and avextract

File:
1 edited

Legend:

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

    r13479 r14191  
    11# include "dvoshell.h"
    22
    3 dbInitField (dbField *field) {
     3void dbFreeFields (dbField *fields, int Nfields) {
     4
     5  int i;
     6
     7  if (fields == NULL) return;
     8
     9  for (i = 0; i <= Nfields; i++) {
     10    if (fields[i].name != NULL) free (fields[i].name);
     11    if (fields[i].photcode != NULL) {
     12      if (fields[i].photcode[0].type == PHOT_MAG) {
     13        free (fields[i].photcode);
     14      }
     15    }
     16  }
     17  free (fields);
     18}
     19
     20void dbInitField (dbField *field) {
    421  field->name = NULL;
    522  field->extract = FALSE;
     
    2643PhotCode *ParsePhotcodeField (char *field, int *mode, int defMode) {
    2744
     45  int useDefault;
    2846  char *tmpstring, *p;
    2947  PhotCode *code;
    3048
    3149  *mode = defMode;
     50  useDefault = TRUE;
    3251
    3352  p = strchr (field, ':');
    3453  if (p != NULL) {
    3554    *mode = GetMagMode (p + 1);
     55    useDefault = FALSE;
    3656    if (*mode == MAG_NONE) return (NULL);
    3757    tmpstring = strncreate (field, p - field);
     
    3959    tmpstring = strcreate (field);
    4060  }
     61  if (!strcasecmp (tmpstring, "MAG")) {
     62    ALLOCATE (code, PhotCode, 1);
     63    code[0].code = 0;
     64    strcpy (code[0].name, "MAG");
     65    code[0].type = PHOT_MAG;
     66    free (tmpstring);
     67    return (code);
     68  }
    4169  code = GetPhotcodebyName (tmpstring);
     70
     71  // enforce compatibility
     72  // XXX this is kind of poorly done
     73  if ((code[0].type == PHOT_REF) && (*mode != MAG_ERR)) {
     74    *mode = MAG_CAT;
     75  }
     76  if (code[0].type == PHOT_DEP) {
     77    if (useDefault) {
     78      *mode = MAG_REL;
     79    } else {
     80      if ((*mode == MAG_AVE) || (*mode == MAG_REF)) {
     81        // XXX error;
     82        *mode = MAG_REL;
     83      }
     84    }
     85  }
    4286  free (tmpstring);
    43 
    4487  return (code);
    4588}
     
    112155  if (!strcasecmp (fieldName, "PAR"))   ESCAPE (AVE_PAR,       MAG_NONE);
    113156  if (!strcasecmp (fieldName, "dPAR"))  ESCAPE (AVE_PAR_ERR,   MAG_NONE);
    114   if (!strcasecmp (fieldName, "MAG"))   ESCAPE (AVE_MAG,       MAG_AVE);
    115   if (!strcasecmp (fieldName, "dMAG"))  ESCAPE (AVE_dMAG,      MAG_ERR);
     157  // if (!strcasecmp (fieldName, "MAG"))   ESCAPE (AVE_MAG,       MAG_AVE);
     158  // if (!strcasecmp (fieldName, "dMAG"))  ESCAPE (AVE_dMAG,      MAG_ERR);
    116159  if (!strcasecmp (fieldName, "NMEAS")) ESCAPE (AVE_NMEAS,     MAG_NONE);
    117160  if (!strcasecmp (fieldName, "NMISS")) ESCAPE (AVE_NMISS,     MAG_NONE);
     
    129172  code = ParsePhotcodeField (fieldName, &mode, MAG_AVE);
    130173  if (code == NULL) return (FALSE);
     174  if (code[0].type == PHOT_MAG) {
     175    gprint (GP_ERR, "'mag' is ambiguous for avextract\n");
     176    free (code);
     177    return (FALSE);
     178  }
    131179
    132180  // need to distinguish phot, sys errors and scatter
Note: See TracChangeset for help on using the changeset viewer.