IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 20, 2005, 4:27:25 AM (21 years ago)
Author:
eugene
Message:

substantial cleanup of photometry extraction functions

File:
1 edited

Legend:

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

    r4420 r4585  
    33int avextract (int argc, char **argv) {
    44 
     5  int i, j, m, N, NPTS, param;
     6  int Ngraph, Nsec, Nregions, mode;
     7  char filename[256], catdir[256], *RegionName, *RegionList, *p;
     8
    59  Catalog catalog;
    6   Graphdata graphsky;
    710  RegionFile *regions;
    811  PhotCode *code;
    912  Vector *vec;
    1013
    11   char filename[256], catdir[256], *p;
    12   int i, j, m, N, NPTS, param;
    13   int Ngraph, Nsec, Nregions, mode;
    14 
     14  /* defaults */
    1515  regions = NULL;
    1616  catalog.average = NULL;
    1717  catalog.secfilt = NULL;
    1818  catalog.measure = NULL;
     19  RegionName = NULL;
     20  RegionList = NULL;
     21  code = NULL;
     22  mode = MAG_AVE;
    1923
    2024  /* load photcode information */
     
    2226  Nsec = GetPhotcodeNsecfilt ();
    2327
    24   /* load data about plot windows */
    25   Ngraph = 0;
    26   if (!GetGraphData (&graphsky, NULL, &Ngraph)) goto escape;
    27  
    2828  /* find CATDIR in config system */
    29   VarConfig ("CATDIR", "%s", catdir);
    30 
    31   /* grab value of photcode, if available */
    32   code = NULL;
    33   mode = MAG_AVE;
    34   if (N = get_argument (argc, argv, "-photcode")) {
    35     remove_argument (N, &argc, argv);
    36     code = GetPhotcodebyName (argv[N]);
    37     if (code == NULL) {
    38       fprintf (stderr, "photcode not found in photcode table\n");
    39       goto usage;
    40     }
    41     remove_argument (N, &argc, argv);
    42   }
     29  if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    4330
    4431  /* interpret command-line options */
    45   if (!SetPhotSelections (&argc, argv)) goto usage;
    46   if (argc != 3) { goto usage; }
     32  SetSelectionParam (0);
     33  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
     34  if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    4735
    48   /* identify selection */
    49   param = GetAverageParam (argv[2]);
     36  /* interpret required command-line arguments: mextract (value) */
     37  if (argc != 2) { goto usage; }
     38  param = GetAverageParam (argv[1]);
    5039  if (param == AVE_ZERO) {
    51     if (!GetPhotcodeInfo (argv[2], &code, &mode)) {
     40    if (!GetPhotcodeInfo (argv[1], &code, &mode)) {
    5241      GetAverageParamHelp ();
    5342      goto escape;
    5443    }
    5544    param = AVE_MAG;
    56     for (p = argv[2]; *p != 0; p++) {
     45    for (p = argv[1]; *p != 0; p++) {
    5746      if (*p == '.') *p = ':';
    5847    }
    5948  }
    60   if ((vec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto escape;
     49  if (!TestPhotSelections (&code, param)) goto escape;
    6150
    62   /* Need valid code for some params: */
    63   switch (param) {
    64     case AVE_MAG:
    65     case AVE_dMAG:
    66     case AVE_Xm:
    67     case AVE_TYPE:
    68     case AVE_NCODE:
    69     case AVE_NPHOT:
    70       if (code == NULL) goto escape;
    71       if (code[0].type == PHOT_DEP) goto escape;
    72       if (code[0].type == PHOT_REF) goto escape;
    73       break;
    74     default:
    75       break;
    76   }
    77 
    78   /* determine region-file names */
    79   if (!strcmp (argv[1], "all")) {
    80     float Radius;
    81     Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    82     regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
    83     if (!SetImageSelection (param, &graphsky, TRUE)) goto escape;
    84     /* this is not really used by avextract -- no parameters require images */
    85   } else {
    86     Nregions = 1;
    87     ALLOCATE (regions, RegionFile, 1);
    88     strcpy (regions[0].name, argv[1]);
    89     if (!SetImageSelection (param, NULL, FALSE)) goto escape;
    90   }
     51  /* load region corresponding to selection above */
     52  if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
    9153
    9254  /* create storage vector */
    9355  N = 0;
    94   NPTS = 1000;
    95   REALLOCATE (vec[0].elements, float, NPTS);
     56  NPTS = 1;
     57  if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    9658
    9759  for (i = 0; i < Nregions; i++) {
     
    11577      vec[0].elements[N] = ExtractAverages (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsec], &catalog.measure[m], param);
    11678      N++;
    117       if (N == NPTS - 1) {
    118         NPTS += 2000;
    119         REALLOCATE (vec[0].elements, float, NPTS);
    120       }
     79      CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000);
    12180    }
    12281    if (catalog.average != NULL) free (catalog.average);
     
    13190
    13291  if (regions != NULL) free (regions);
    133   FreeImageSelection ();
    13492  return (TRUE);
    13593
    13694usage:
    137   fprintf (stderr, "USAGE: avextract (from) (value) [options]\n");
    138   fprintf (stderr, "  from: cpt name or 'all'\n");
     95  fprintf (stderr, "USAGE: avextract (value) [options]\n");
    13996  fprintf (stderr, "  value: average.parameter or photcode\n");
    140   return (FALSE);
    14197
    14298escape:
    143   fprintf (stderr, "error in avextract\n");
    14499  if (regions != NULL) free (regions);
    145   FreeImageSelection ();
    146100  if (catalog.average != NULL) free (catalog.average);
    147101  if (catalog.secfilt != NULL) free (catalog.secfilt);
    148102  if (catalog.measure != NULL) free (catalog.measure);
     103  if (RegionName != NULL) free (RegionName);
     104  if (RegionList != NULL) free (RegionList);
    149105  return (FALSE);
    150106}
Note: See TracChangeset for help on using the changeset viewer.