IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 19, 2012, 5:24:19 PM (14 years ago)
Author:
mhuber
Message:

merging latest r34040 trunk changes to branch

Location:
branches/meh_branches/ppstack_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/Ohana/src/opihi/dvo/avmatch.c

    r28241 r34041  
    1414 
    1515  off_t i, j, n, m, *index;
    16   int N, Ncat, Npts, NPTS, last, Nfields, Nsecfilt;
     16  int N, Ncat, Npts, NPTS, last, Nfields, Nsecfilt, Ninvec;
    1717  int VERBOSE;
    18   char name[1024];
     18  char name[1024], *found;
    1919  void *Signal;
    2020  float RADIUS;
     
    2222  Catalog catalog;
    2323
    24   Vector **vec, *RAvec, *DECvec;
     24  Vector **vec, **invec, *RAvec, *DECvec;
    2525  dbField *fields;
    2626  dbValue *values;
     
    2929  /* defaults */
    3030  vec = NULL;
     31  invec = NULL;
    3132  fields = NULL;
    3233  values = NULL;
    3334  skylist = NULL;
     35  Ninvec = 0;
    3436
    3537  if ((N = get_argument (argc, argv, "-h"))) goto help;
    3638  if ((N = get_argument (argc, argv, "--help"))) goto help;
    37   if (argc < 5) goto help;
    3839
    3940  VERBOSE = FALSE;
     
    4344  }
    4445
     46  int PARALLEL = FALSE;
     47  if ((N = get_argument (argc, argv, "-parallel"))) {
     48    remove_argument (N, &argc, argv);
     49    PARALLEL = TRUE;
     50  }
     51
     52  // dump results directly to fits file (esp for parallel dvo)
     53  char *CoordsFile = NULL;
     54  if ((N = get_argument (argc, argv, "-coords"))) {
     55    remove_argument (N, &argc, argv);
     56    CoordsFile = strcreate(argv[N]);
     57    remove_argument (N, &argc, argv);
     58  }
     59
     60  if (!CoordsFile && (argc < 5)) goto help;
     61  if ( CoordsFile && (argc < 3)) goto help;
     62
    4563  dvo_catalog_init (&catalog, TRUE);
    4664
     
    4967  Nsecfilt = GetPhotcodeNsecfilt ();
    5068
     69  // init locally static variables (time refs)
     70  dbExtractAveragesInit ();
     71
     72  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
     73  RAvec  = NULL;
     74  DECvec = NULL;
     75  if (PARALLEL && !HOST_ID) {
     76    if (!CoordsFile) {
     77      // get vectors corresponding to coordinates of interest
     78      if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
     79      if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
     80     
     81      ALLOCATE (vec, Vector *, 2);
     82      vec[0] = RAvec;
     83      vec[1] = DECvec;
     84
     85      CoordsFile = abspath("coords.fits", 1024);
     86      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     87      if (!status) goto escape;
     88    }
     89
     90    char *targv1 = argv[1];
     91    char *targv2 = argv[2];
     92    argv[1] = strcreate ("-coords");
     93    argv[2] = strcreate (CoordsFile);
     94    free (CoordsFile);
     95
     96    // I need to pass the RA & DEC vectors to the remote clients...
     97    int status = HostTableParallelOps (argc, argv, RESULT_FILE, RAvec->Nelements, VERBOSE);
     98    if (vec) free (vec);
     99   
     100    free (argv[1]);
     101    free (argv[2]);
     102    argv[1] = targv1;
     103    argv[2] = targv2;
     104
     105    return status;
     106  }
     107
    51108  // get vectors corresponding to coordinates of interest
    52   if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
    53   if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
    54   RADIUS = atof (argv[3]);
    55 
    56   // strip off RA, DEC, RADIUS arguments
    57   remove_argument (1, &argc, argv);
    58   remove_argument (1, &argc, argv);
     109  if (CoordsFile) {
     110    // read RAvec, DECvec from coords file (1st 2 fields?)
     111    Ninvec = 0;
     112    invec = ReadVectorTableFITS (CoordsFile, "COORDS", &Ninvec);
     113    RAvec = invec[0];
     114    DECvec = invec[1];
     115  } else {
     116    if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
     117    if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
     118    // strip off RA & DEC
     119    remove_argument (1, &argc, argv);
     120    remove_argument (1, &argc, argv);
     121  }
     122  RADIUS = atof (argv[1]);
    59123  remove_argument (1, &argc, argv);
    60124
     
    66130    dvo_catalog_free (&catalog);
    67131    goto help;
     132  }
     133
     134  // check the requested fields : are all average/secfilt entries, or do we need measures?
     135  int needMeasures = FALSE;
     136  for (i = 0; !needMeasures && (i < Nfields); i++) {
     137    if (fields[i].magMode == MAG_NONE) continue;
     138    if (fields[i].photcode == NULL) continue; // assert this?
     139    if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
     140    if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    68141  }
    69142
     
    92165  }
    93166  ALLOCATE (index, off_t, NPTS);
     167  ALLOCATE (found, char, NPTS);
     168  memset (found, 0, NPTS*sizeof(char));
    94169
    95170  // grab data from all selected sky regions
     
    97172  interrupt = FALSE;
    98173  for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) {
     174
     175    // does this host ID match the desired location for the table?
     176    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
     177
    99178    /* lock, load, unlock catalog */
    100     catalog.filename = skylist[0].filename[i];
    101     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     179    char hostfile[1024];
     180    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     181    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
     182    catalog.catflags = LOAD_AVES | LOAD_SECF;
     183    catalog.catflags |= needMeasures ? LOAD_MEAS : SKIP_MEAS;
    102184    catalog.Nsecfilt = 0;
    103185
     
    124206      if (Ncat == -2) continue;
    125207
    126       // XXX set a 'found' vector to double check we catch everything?
    127208      m = catalog.average[Ncat].measureOffset;
    128209
    129210      // reset counters for saved fields, extract fields
    130       dbExtractAveragesInit ();
     211      dbExtractAveragesInitAve ();
    131212      for (n = 0; n < Nfields; n++) {
    132213        values[n] = dbExtractAverages (&catalog.average[Ncat], &catalog.secfilt[Ncat*Nsecfilt], &catalog.measure[m], &fields[n]);
     
    141222        }
    142223      }
     224      found[Npts] = TRUE;
    143225    }
    144226    dvo_catalog_free (&catalog);
     
    147229  interrupt = FALSE;
    148230
     231  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
     232  // only write the fields which were in a valid catalog
     233  if (RESULT_FILE) {
     234    // extend the array by one to hold index array
     235    REALLOCATE (vec, Vector *, Nfields + 1);
     236    vec[Nfields] = InitVector();
     237    strcpy (vec[Nfields]->name, "index");
     238    ResetVector (vec[Nfields], OPIHI_INT, NPTS);
     239    Vector *idxVec = vec[Nfields];
     240
     241    // only write out the rows which were found
     242    Npts = 0;
     243    for (i = 0; i < NPTS; i++) {
     244      if (!found[i]) continue;
     245      idxVec->elements.Int[Npts] = i;
     246      Npts ++;
     247    }
     248    int Nfound = Npts;
     249    idxVec->Nelements = Nfound;
     250
     251    fprintf (stderr, "found %d of %d pts\n", Nfound, NPTS);
     252
     253    for (i = 0; i < Nfields; i++) {
     254      if (vec[i][0].type == OPIHI_FLT) {
     255        opihi_flt *tmp = NULL;
     256        ALLOCATE (tmp, opihi_flt, Nfound);
     257        Npts = 0;
     258        for (j = 0; j < NPTS; j++) {
     259          if (!found[j]) continue;
     260          tmp[Npts] = vec[i][0].elements.Flt[j];
     261          Npts++;
     262        }
     263        free (vec[i][0].elements.Flt);
     264        vec[i][0].elements.Flt = tmp;
     265      } else {
     266        opihi_int *tmp = NULL;
     267        ALLOCATE (tmp, opihi_int, Nfound);
     268        Npts = 0;
     269        for (j = 0; j < NPTS; j++) {
     270          if (!found[j]) continue;
     271          tmp[Npts] = vec[i][0].elements.Int[j];
     272          Npts++;
     273        }
     274        free (vec[i][0].elements.Int);
     275        vec[i][0].elements.Int = tmp;
     276      }
     277      vec[i][0].Nelements = Nfound;
     278    }
     279    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL);
     280    free (vec[Nfields]->elements.Int);
     281    free (vec[Nfields]);
     282    if (!status) goto escape;
     283  }
     284
    149285  if (vec) free (vec);
    150286  if (values) free (values);
     287  if (invec) FreeVectorArray (invec, Ninvec);
    151288  dbFreeFields (fields, Nfields);
    152289  SkyListFree (skylist);
     
    156293  if (vec) free (vec);
    157294  if (values) free (values);
     295  if (invec) FreeVectorArray (invec, Ninvec);
    158296  dbFreeFields (fields, Nfields);
    159297  SkyListFree (skylist);
     
    162300 help:
    163301  gprint (GP_ERR, "USAGE: avmatch (RA) (DEC) (RADIUS) field[,field,field...]\n");
     302  gprint (GP_ERR, "   OR: avmatch -coords (filename.fits) (RADIUS) field[,field,field...]\n");
    164303
    165304  if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
Note: See TracChangeset for help on using the changeset viewer.