IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 16, 2012, 7:51:21 AM (14 years ago)
Author:
eugene
Message:

parallelize gstar, update avmatch to work with merged vectors by index; remove elements from dvoshell.h which have moved to libdvo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/avmatch.c

    r28241 r33543  
    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;
     
    4243    VERBOSE = TRUE;
    4344  }
     45
     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 *ResultFile = NULL;
     54  if ((N = get_argument (argc, argv, "-result"))) {
     55    remove_argument (N, &argc, argv);
     56    ResultFile = strcreate(argv[N]);
     57    remove_argument (N, &argc, argv);
     58  }
     59
     60  // dump results directly to fits file (esp for parallel dvo)
     61  char *CoordsFile = NULL;
     62  if ((N = get_argument (argc, argv, "-coords"))) {
     63    remove_argument (N, &argc, argv);
     64    CoordsFile = strcreate(argv[N]);
     65    remove_argument (N, &argc, argv);
     66  }
     67
     68  if (!CoordsFile && (argc < 5)) goto help;
     69  if ( CoordsFile && (argc < 3)) goto help;
    4470
    4571  dvo_catalog_init (&catalog, TRUE);
     
    4975  Nsecfilt = GetPhotcodeNsecfilt ();
    5076
     77  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
     78  if (PARALLEL && !HOST_ID) {
     79    if (!CoordsFile) {
     80      // get vectors corresponding to coordinates of interest
     81      if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
     82      if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
     83     
     84      ALLOCATE (vec, Vector *, 2);
     85      vec[0] = RAvec;
     86      vec[1] = DECvec;
     87
     88      CoordsFile = abspath("coords.fits", 1024);
     89      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     90      if (!status) goto escape;
     91    }
     92
     93    char *targv1 = argv[1];
     94    char *targv2 = argv[2];
     95    argv[1] = strcreate ("-coords");
     96    argv[2] = strcreate (CoordsFile);
     97    free (CoordsFile);
     98
     99    // I need to pass the RA & DEC vectors to the remote clients...
     100    int status = HostTableParallelOps (argc, argv, ResultFile, RAvec->Nelements);
     101    if (ResultFile) free (ResultFile);
     102    if (vec) free (vec);
     103   
     104    free (argv[1]);
     105    free (argv[2]);
     106    argv[1] = targv1;
     107    argv[2] = targv2;
     108
     109    return status;
     110  }
     111
    51112  // 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);
     113  if (CoordsFile) {
     114    // read RAvec, DECvec from coords file (1st 2 fields?)
     115    Ninvec = 0;
     116    invec = ReadVectorTableFITS (CoordsFile, "COORDS", &Ninvec);
     117    RAvec = invec[0];
     118    DECvec = invec[1];
     119  } else {
     120    if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
     121    if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
     122    // strip off RA & DEC
     123    remove_argument (1, &argc, argv);
     124    remove_argument (1, &argc, argv);
     125  }
     126  RADIUS = atof (argv[1]);
    59127  remove_argument (1, &argc, argv);
    60128
     
    92160  }
    93161  ALLOCATE (index, off_t, NPTS);
     162  ALLOCATE (found, char, NPTS);
     163  memset (found, 0, NPTS*sizeof(char));
    94164
    95165  // grab data from all selected sky regions
     
    97167  interrupt = FALSE;
    98168  for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) {
     169
     170    // does this host ID match the desired location for the table?
     171    if (PARALLEL && !HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
     172
    99173    /* lock, load, unlock catalog */
    100     catalog.filename = skylist[0].filename[i];
     174    char hostfile[1024];
     175    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     176    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    101177    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    102178    catalog.Nsecfilt = 0;
     
    124200      if (Ncat == -2) continue;
    125201
    126       // XXX set a 'found' vector to double check we catch everything?
    127202      m = catalog.average[Ncat].measureOffset;
    128203
     
    141216        }
    142217      }
     218      found[Npts] = TRUE;
    143219    }
    144220    dvo_catalog_free (&catalog);
     
    147223  interrupt = FALSE;
    148224
     225  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
     226  // only write the fields which were in a valid catalog
     227  if (ResultFile) {
     228    // extend the array by one to hold index array
     229    REALLOCATE (vec, Vector *, Nfields + 1);
     230    vec[Nfields] = InitVector();
     231    strcpy (vec[Nfields]->name, "index");
     232    ResetVector (vec[Nfields], OPIHI_INT, NPTS);
     233    Vector *idxVec = vec[Nfields];
     234
     235    // only write out the rows which were found
     236    Npts = 0;
     237    for (i = 0; i < NPTS; i++) {
     238      if (!found[i]) continue;
     239      idxVec->elements.Int[Npts] = i;
     240      Npts ++;
     241    }
     242    int Nfound = Npts;
     243    idxVec->Nelements = Nfound;
     244
     245    fprintf (stderr, "found %d of %d pts\n", Nfound, NPTS);
     246
     247    for (i = 0; i < Nfields; i++) {
     248      if (vec[i][0].type == OPIHI_FLT) {
     249        opihi_flt *tmp = NULL;
     250        ALLOCATE (tmp, opihi_flt, Nfound);
     251        Npts = 0;
     252        for (j = 0; j < NPTS; j++) {
     253          if (!found[j]) continue;
     254          tmp[Npts] = vec[i][0].elements.Flt[j];
     255          Npts++;
     256        }
     257        free (vec[i][0].elements.Flt);
     258        vec[i][0].elements.Flt = tmp;
     259      } else {
     260        opihi_int *tmp = NULL;
     261        ALLOCATE (tmp, opihi_int, Nfound);
     262        Npts = 0;
     263        for (j = 0; j < NPTS; j++) {
     264          if (!found[j]) continue;
     265          tmp[Npts] = vec[i][0].elements.Int[j];
     266          Npts++;
     267        }
     268        free (vec[i][0].elements.Int);
     269        vec[i][0].elements.Int = tmp;
     270      }
     271      vec[i][0].Nelements = Nfound;
     272    }
     273    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nfields + 1, FALSE, NULL);
     274    free (vec[Nfields]->elements.Int);
     275    free (vec[Nfields]);
     276    if (!status) goto escape;
     277  }
     278
    149279  if (vec) free (vec);
    150280  if (values) free (values);
     281  if (invec) FreeVectorArray (invec, Ninvec);
    151282  dbFreeFields (fields, Nfields);
    152283  SkyListFree (skylist);
     
    156287  if (vec) free (vec);
    157288  if (values) free (values);
     289  if (invec) FreeVectorArray (invec, Ninvec);
    158290  dbFreeFields (fields, Nfields);
    159291  SkyListFree (skylist);
     
    162294 help:
    163295  gprint (GP_ERR, "USAGE: avmatch (RA) (DEC) (RADIUS) field[,field,field...]\n");
     296  gprint (GP_ERR, "   OR: avmatch -coords (filename.fits) (RADIUS) field[,field,field...]\n");
    164297
    165298  if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
Note: See TracChangeset for help on using the changeset viewer.