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

    r4470 r4585  
    33int dmagaves (int argc, char **argv) {
    44 
    5   Catalog catalog;
    6   Graphdata graphsky;
    7   RegionFile *regions;
    8   PhotCode *code[3];
    9   Vector *xvec, *yvec;
    10 
    11   char filename[256], catdir[256], *CPTfile;
     5  char filename[256], catdir[256], *RegionName, *RegionList;
    126  double Radius, *M1, M2;
    137  int i, j, k, m, N1, N;
    148  int Npts, NPTS, param, mode[3];
    159  int Ngraph, Nsec, Nregions;
     10
     11  Catalog catalog;
     12  RegionFile *regions;
     13  PhotCode *code[3];
     14  Vector *xvec, *yvec;
    1615
    1716  /* defaults */
     
    2019  catalog.secfilt = NULL;
    2120  catalog.measure = NULL;
     21  RegionName = NULL;
     22  RegionList = NULL;
    2223
    2324  /* load photcode information */
     
    2526  Nsec = GetPhotcodeNsecfilt ();
    2627
    27   /* load data about plot windows */
    28   Ngraph = 0;
    29   if (!GetGraphData (&graphsky, NULL, &Ngraph)) return (FALSE);
    30  
    3128  /* find CATDIR in config system */
    32   VarConfig ("CATDIR", "%s", catdir);
    33 
    34   /* check for CPT selection */
    35   CPTfile = NULL;
    36   if (N = get_argument (argc, argv, "-cpt")) {
    37     remove_argument (N, &argc, argv);
    38     CPTfile = strcreate (argv[N]);
    39     remove_argument (N, &argc, argv);
    40   }   
     29  if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    4130
    4231  /* interpret command-line options */
    43   if (!SetPhotSelections (&argc, argv)) goto usage;
     32  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
     33  if (!SetPhotSelections (&argc, argv, 3)) goto usage;
     34
     35  /* interpret command-line options: dmagaves F1 - F2 : (value) */
    4436  if (argc != 6) { goto usage; }
    4537  if (strcmp (argv[2], "-")) goto usage;
    4638  if (strcmp (argv[4], ":")) goto usage;
     39  if (!GetPhotcodeInfo (argv[1], &code[0], &mode[0])) goto usage;
     40  if (!GetPhotcodeInfo (argv[3], &code[1], &mode[1])) goto usage;
     41  if ((param = GetAverageParam (argv[5])) == AVE_ZERO) goto usage;
     42  if (!TestPhotSelections (&code[2], param)) goto escape;
    4743
    48   /* interpret command-line options */
    49   if (!GetPhotcodeInfo (argv[1], &code[0], &mode[0])) return (FALSE);
    50   if (!GetPhotcodeInfo (argv[3], &code[1], &mode[1])) return (FALSE);
    51   if ((param = GetAverageParam (argv[5])) == AVE_ZERO) {
    52     GetAverageParamHelp ();
    53     return (FALSE);
    54   }
    55   code[2] = GetPhotcodeEquivbyCode (code[0][0].code);
    56   mode[2] = mode[0];
    57 
    58   /* test PhotSelections: is photcode specified if needed? */
    59   for (i = 0; i < 3; i++) {
    60     if (!TestPhotSelections (&code[i])) {
    61       fprintf (stderr, "photcode selection rules violated\n");
    62       fprintf (stderr, "average and ensemble restrictions require a corresponding photcode\n");
    63       goto escape;
    64     }
    65   }
    66 
    67   /* determine region-file names */
    68   if (CPTfile == NULL) {
    69     float Radius;
    70     Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    71     regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
    72   } else {
    73     Nregions = 1;
    74     ALLOCATE (regions, RegionFile, 1);
    75     strcpy (regions[0].name, CPTfile);
    76   }
     44  /* load region corresponding to selection above */
     45  if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
    7746
    7847  /* init vectors to save data */
     
    10372      m = catalog.average[i].offset;
    10473
     74      SetSelectionParam (0);
    10575      M1 = ExtractDMag (code, mode, &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N1);
    10676      if (N1 == 0) goto skip;
    10777
     78      SetSelectionParam (2);
    10879      M2 = ExtractAverages (code[2], mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], param);
    10980
     
    11283        yvec[0].elements[Npts] = M2;
    11384        Npts++;
    114         if (Npts == NPTS) {
     85        if (Npts >= NPTS) {
    11586          NPTS += 2000;
    11687          REALLOCATE (xvec[0].elements, float, NPTS);
     
    12899    catalog.measure = (Measure *) NULL;
    129100  }
    130   FreeImageSelection ();
    131101  if (regions != NULL) free (regions);
    132102  xvec[0].Nelements = yvec[0].Nelements = Npts;
     
    138108
    139109escape:
    140   FreeImageSelection ();
    141110  if (regions != NULL) free (regions);
    142111  if (catalog.average != NULL) free (catalog.average);
    143112  if (catalog.secfilt != NULL) free (catalog.secfilt);
    144113  if (catalog.measure != NULL) free (catalog.measure);
     114  if (RegionName != NULL) free (RegionName);
     115  if (RegionList != NULL) free (RegionList);
    145116  return (FALSE);
    146117}
Note: See TracChangeset for help on using the changeset viewer.