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

    r4470 r4585  
    11# include "dvo1.h"
    2 double *ExtractByDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param);
    32
    43int dmagmeas (int argc, char **argv) {
    54 
     5  char filename[256], catdir[256], *RegionName, *RegionList;
     6  double Radius, *M1, *M3;
     7  int i, j, k, m, i1, i3, N1, N3, N;
     8  int Npts, NPTS, param, mode[3];
     9  int Ngraph, Nsec, Nregions;
     10
    611  Catalog catalog;
    7   Graphdata graphsky;
    812  RegionFile *regions;
    913  PhotCode *code[3];
    1014  Vector *xvec, *yvec;
    11 
    12   char filename[256], catdir[256], *CPTfile;
    13   double Radius, *M1, *M3;
    14   int i, j, k, m, N1, N3, N;
    15   int Npts, NPTS, param, mode[3];
    16   int Ngraph, Nsec, Nregions;
    1715
    1816  /* defaults */
     
    2119  catalog.secfilt = NULL;
    2220  catalog.measure = NULL;
     21  RegionName = NULL;
     22  RegionList = NULL;
    2323
    2424  /* load photcode information */
     
    2626  Nsec = GetPhotcodeNsecfilt ();
    2727
    28   /* load data about plot windows */
    29   Ngraph = 0;
    30   if (!GetGraphData (&graphsky, NULL, &Ngraph)) return (FALSE);
    31  
    3228  /* find CATDIR in config system */
    33   VarConfig ("CATDIR", "%s", catdir);
    34 
    35   /* check for CPT selection */
    36   CPTfile = NULL;
    37   if (N = get_argument (argc, argv, "-cpt")) {
    38     remove_argument (N, &argc, argv);
    39     CPTfile = strcreate (argv[N]);
    40     remove_argument (N, &argc, argv);
    41   }   
     29  if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    4230
    4331  /* interpret command-line options */
    44   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 arguments: dmagmeas F1 - F2 : (value) */
    4536  if (argc != 6) { goto usage; }
    4637  if (strcmp (argv[2], "-")) goto usage;
    4738  if (strcmp (argv[4], ":")) goto usage;
    48 
    49   /* interpret command-line options */
    5039  if (!GetPhotcodeInfo (argv[1], &code[0], &mode[0])) goto usage;
    5140  if (!GetPhotcodeInfo (argv[3], &code[1], &mode[1])) goto usage;
    5241  if ((param = GetMeasureParam (argv[5])) == MEAS_ZERO) goto usage;
     42  if (!TestPhotSelections (&code[2], MEAS_ZERO)) goto escape;
    5343
    54   /* test PhotSelections: is photcode specified if needed? */
    55   for (i = 0; i < 2; i++) {
    56     if (!TestPhotSelections (&code[i])) {
    57       fprintf (stderr, "photcode selection rules violated\n");
    58       fprintf (stderr, "average and ensemble restrictions require a corresponding photcode\n");
    59       goto escape;
    60     }
    61   }
    62 
    63   /* determine region-file names */
    64   if (CPTfile == NULL) {
    65     float Radius;
    66     Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    67     regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
    68   } else {
    69     Nregions = 1;
    70     ALLOCATE (regions, RegionFile, 1);
    71     strcpy (regions[0].name, CPTfile);
    72   }
    73   if (!SetImageSelection (param, &graphsky, TRUE)) return (FALSE);
     44  /* load region corresponding to selection above */
     45  if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     46  if (!SetImageSelection (param)) goto escape;
    7447
    7548  /* init vectors to save data */
     
    10174      m = catalog.average[i].offset;
    10275
     76      SetSelectionParam (0);
    10377      M1 = ExtractDMag (code, mode, &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N1);
    10478      if (N1 == 0) goto skip;
    10579
    106       M3 = ExtractByDMag (code, mode, &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N3, param);
    107       if (N3 != N1) { fprintf (stderr, "mismatch: programming error\n"); goto escape; }
     80      SetSelectionParam (2);
     81      M3 = ExtractMeasures (code[2], mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N3, param);
     82      if (N3 == 0) goto skip;
    10883
    109       for (k = 0; k < N1; k++) {
    110         xvec[0].elements[Npts] = M1[k];
    111         yvec[0].elements[Npts] = M3[k];
    112         Npts++;
    113         if (Npts == NPTS) {
    114           NPTS += 2000;
    115           REALLOCATE (xvec[0].elements, float, NPTS);
    116           REALLOCATE (yvec[0].elements, float, NPTS);
     84      for (i1 = 0; i1 < N1; i1++) {
     85        for (i3 = 0; i3 < N3; i3++) {
     86          xvec[0].elements[Npts] = M1[i1];
     87          yvec[0].elements[Npts] = M3[i3];
     88          Npts++;
     89          if (Npts >= NPTS) {
     90            NPTS += 2000;
     91            REALLOCATE (xvec[0].elements, float, NPTS);
     92            REALLOCATE (yvec[0].elements, float, NPTS);
     93          }
    11794        }
    11895      }
     
    143120  if (catalog.secfilt != NULL) free (catalog.secfilt);
    144121  if (catalog.measure != NULL) free (catalog.measure);
     122  if (RegionName != NULL) free (RegionName);
     123  if (RegionList != NULL) free (RegionList);
    145124  return (FALSE);
    146125}
Note: See TracChangeset for help on using the changeset viewer.