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/mextract.c

    r3462 r4585  
    44 
    55  int i, j, k, m, N, N1, NPTS;
    6   int param, mode, Nregions, Ngraph, Nsec;
    7   char filename[128], catdir[256], *p;
    8   double *M1;
     6  int param, mode, Nregions, Nsec;
     7  char filename[128], catdir[256], *RegionName, *RegionList, *p;
     8  double Radius, *M1;
    99
    1010  PhotCode *code;
    1111  Catalog catalog;
    1212  RegionFile *regions;
    13   Graphdata graphsky;
    1413  Vector *vec;
    1514
     15  /* defaults */
    1616  regions = NULL;
    1717  catalog.average = (Average *) NULL;
    1818  catalog.secfilt = (SecFilt *) NULL;
    1919  catalog.measure = (Measure *) NULL;
     20  RegionName = NULL;
     21  RegionList = NULL;
     22  code = NULL;
     23  mode = MAG_REL;
    2024
    2125  /* load photcode information */
     
    2327  Nsec = GetPhotcodeNsecfilt ();
    2428
    25   /* load data about plot windows */
    26   Ngraph = 0;
    27   if (!GetGraphData (&graphsky, NULL, &Ngraph)) goto escape;
    28  
    2929  /* find CATDIR in config system */
    30   VarConfig ("CATDIR", "%s", catdir);
    31 
    32   /* specify catalog files
    33   RegionList = FALSE;
    34   if (N = get_argument (argc, argv, "-list")) {
    35     RegionList = TRUE;
    36     remove_argument (N, &argc, argv);
    37     strcpy (RegionListFile, argv[N]);
    38     remove_argument (N, &argc, argv);
    39   } */
     30  if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    4031
    4132  /* interpret command-line options */
    42   if (!SetPhotSelections (&argc, argv)) goto usage;
    43   if (argc != 3) goto usage;
     33  SetSelectionParam (0);
     34  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
     35  if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    4436
    45   /* identify selection */
    46   code = NULL;
    47   mode = MAG_REL;
    48   param = GetMeasureParam (argv[2]);
     37  /* interpret required command-line arguments: mextract (value) */
     38  if (argc != 2) goto usage;
     39  param = GetMeasureParam (argv[1]);
    4940  if (param == MEAS_ZERO) {
    50     if (!GetPhotcodeInfo (argv[2], &code, &mode)) {
     41    if (!GetPhotcodeInfo (argv[1], &code, &mode)) {
    5142      GetMeasureParam ("help");
    52       fprintf (stderr, "value may also be a valid photcode\n");
    53       fprintf (stderr, "photcodes or 'mag' may have optional magnitude type: mag,[Minst, Mcat, Msys, Mrel, Mcal]\n");
    5443      goto escape;
    5544    }
    5645    param = MEAS_MAG;
    57     for (p = argv[2]; *p != 0; p++) {
     46    for (p = argv[1]; *p != 0; p++) {
    5847      if (*p == '.') *p = ':';
    5948    }
    60   }
    61   /* test PhotSelections: is photcode specified if needed? */
    62   if (!TestPhotSelections (&code)) {
    63     fprintf (stderr, "photcode selection rules violated\n");
    64     fprintf (stderr, "average and ensemble restrictions require a corresponding photcode\n");
    65     goto escape;
    6649  }
     50  if (!TestPhotSelections (&code, MEAS_ZERO)) goto escape;
    6751
    68   if ((vec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto escape;
    69 
    70   /* determine region-file names */
    71   if (!strcmp (argv[1], "all")) {
    72     float Radius;
    73     Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    74     regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
    75     /* I don't have a tool to select images by the overlapping region */
    76     if (!SetImageSelection (param, &graphsky, TRUE)) goto escape;
    77   } else {
    78     Nregions = 1;
    79     ALLOCATE (regions, RegionFile, 1);
    80     strcpy (regions[0].name, argv[1]);
    81     if (!SetImageSelection (param, NULL, FALSE)) goto escape;
    82   }
     52  /* load region corresponding to selection above */
     53  if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     54  if (!SetImageSelection (param)) goto escape;
    8355
    8456  /* create storage vector */
    85   NPTS = 1000;
    86   REALLOCATE (vec[0].elements, float, NPTS);
    87   vec[0].Nelements = N = 0;
     57  N = 0;
     58  NPTS = 1;
     59  if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    8860
    8961  for (i = 0; i < Nregions; i++) {
     
    11082        vec[0].elements[N] = M1[k];
    11183        N++;
    112         if (N == NPTS - 1) {
    113           NPTS += 2000;
    114           REALLOCATE (vec[0].elements, float, NPTS);
    115         }
     84        CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000);
    11685      }
    11786      if (M1 != NULL) free (M1);
     
    132101
    133102usage:
    134   fprintf (stderr, "USAGE: mextract (from) (value) [options]\n");
    135   fprintf (stderr, "  from: cpt name or 'all'\n");
     103  fprintf (stderr, "USAGE: mextract (value) [options]\n");
    136104  fprintf (stderr, "  value: measure.parameter or photcode\n");
    137105  return (FALSE);
    138106
    139107escape:
     108  FreeImageSelection ();
    140109  if (regions != NULL) free (regions);
    141   FreeImageSelection ();
    142110  if (catalog.average != NULL) free (catalog.average);
    143111  if (catalog.secfilt != NULL) free (catalog.secfilt);
    144112  if (catalog.measure != NULL) free (catalog.measure);
     113  if (RegionName != NULL) free (RegionName);
     114  if (RegionList != NULL) free (RegionList);
    145115  return (FALSE);
    146116}
Note: See TracChangeset for help on using the changeset viewer.