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

    r4470 r4585  
    33int dmags (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, *M3;
    137  int i, j, m, i1, i3, N1, N3, N;
    148  int Npts, NPTS, mode[3];
    15   int Ngraph, Nsec, Nregions;
     9  int Nsec, Nregions;
     10
     11  PhotCode *code[3];
     12  Catalog catalog;
     13  RegionFile *regions;
     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 required command-line arguments: dmags F1 - F2 : F3 */
    4436  if (argc != 6) { goto usage; }
    4537  if (strcmp (argv[2], "-")) goto usage;
    4638  if (strcmp (argv[4], ":")) goto usage;
    47 
    48   /* interpret command-line options */
    4939  if (!GetPhotcodeInfo (argv[1], &code[0], &mode[0])) goto usage;
    5040  if (!GetPhotcodeInfo (argv[3], &code[1], &mode[1])) goto usage;
    5141  if (!GetPhotcodeInfo (argv[5], &code[2], &mode[2])) goto usage;
     42  if (!TestPhotSelections (&code[0], MEAS_ZERO)) goto escape;
    5243
    53   /* test PhotSelections: is photcode specified if needed? */
    54   for (i = 0; i < 3; i++) {
    55     if (!TestPhotSelections (&code[i])) {
    56       fprintf (stderr, "photcode selection rules violated\n");
    57       fprintf (stderr, "average and ensemble restrictions require a corresponding photcode\n");
    58       goto escape;
    59     }
    60   }
    61 
    62   /* determine region-file names */
    63   if (CPTfile == NULL) {
    64     float Radius;
    65     Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    66     regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
    67   } else {
    68     Nregions = 1;
    69     ALLOCATE (regions, RegionFile, 1);
    70     strcpy (regions[0].name, CPTfile);
    71   }
     44  /* load region corresponding to selection above */
     45  if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
    7246
    7347  /* init vectors to save data */
     
    9973      m = catalog.average[i].offset;
    10074
     75      SetSelectionParam (0);
    10176      M1 = ExtractDMag (code, mode, &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N1);
    10277      if (N1 == 0) goto skip;
    10378
     79      SetSelectionParam (2);
    10480      M3 = ExtractMagnitudes (code[2], mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N3);
    10581      if (N3 == 0) goto skip;
     
    11086          yvec[0].elements[Npts] = M3[i3];
    11187          Npts++;
    112           if (Npts == NPTS) {
     88          if (Npts >= NPTS) {
    11389            NPTS += 2000;
    11490            REALLOCATE (xvec[0].elements, float, NPTS);
     
    134110usage:
    135111  fprintf (stderr, "USAGE: dmags F - F : F\n");
    136   fprintf (stderr, "  F : any photcodes with matched qualifiers:\n");
     112  fprintf (stderr, "    F : any photcodes with matched qualifiers:\n");
    137113  fprintf (stderr, "    pri: F:inst, F:cat, F:sys, F:rel, F:cal, F:ave, F:ref\n");
    138114  fprintf (stderr, "    sec: F:inst, F:cat, F:sys, F:rel, F:cal, F:ave, F:ref\n");
    139115  fprintf (stderr, "    dep: F:inst, F:cat, F:sys, F:rel, F:cal\n");
    140116  fprintf (stderr, "    ref: F:cat\n");
    141   return (FALSE);
    142117
    143118escape:
     
    146121  if (catalog.secfilt != NULL) free (catalog.secfilt);
    147122  if (catalog.measure != NULL) free (catalog.measure);
     123  if (RegionName != NULL) free (RegionName);
     124  if (RegionList != NULL) free (RegionList);
    148125  return (FALSE);
    149126}
Note: See TracChangeset for help on using the changeset viewer.