IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 14, 2006, 1:14:22 PM (20 years ago)
Author:
eugene
Message:

modifying dvo_catalog APIs

Location:
trunk/Ohana/src/addstar/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/src/addstar.c

    r7974 r8328  
    9595
    9696    catalog.filename = skylist[0].filename[i];
    97     load_pt_catalog (&catalog, skylist[0].regions[i]);
     97    catalog.catformat = dvo_catalog_format (CATFORMAT);  // set the default catformat from config data
     98    catalog.catmode   = dvo_catalog_mode (CATMODE);      // set the default catmode from config data
     99    catalog.lockmode  = LCK_XCLD;
     100    dvo_catalog_open (&catalog, skylist[0].regions[i], Nsecfilt, "w");
    98101
    99102    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
    100103    if ((catalog.Nave_disk == 0) && options.only_match) {
    101       unlock_catalog (&catalog);
    102       free (catalog.filename);
    103       free_catalog (&catalog);
     104      dvo_catalog_unlock (&catalog);
     105      free (catalog.filename);  // can this be done within the dvo_catalog_free function??
     106      dvo_catalog_free (&catalog);
    104107      continue;
    105108    }
     
    136139
    137140    if (Nsubset == 0) {
     141      // XXX remove empty catalogs
    138142      unlock_catalog (&catalog);
    139143    } else {
    140144      SetProtect (TRUE);
    141       if (!options.only_images) wcatalog (&catalog);
     145      if (!options.only_images) dvo_catalog_save (&catalog);
    142146      SetProtect (FALSE);
    143       unlock_catalog (&catalog);
     147      dvo_catalog_unlock (&catalog);
    144148    }
    145     free_catalog (&catalog);
    146     free (catalog.filename);
     149    dvo_catalog_free (&catalog);
     150    free (catalog.filename); // XXX ????
    147151
    148152    if (options.mode == M_REFCAT) free (stars);
  • trunk/Ohana/src/addstar/src/find_matches.c

    r8243 r8328  
    11# include "addstar.h"
    22
    3 void find_matches (SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
    4 
    5   int i, j, n, N, J;
     3void find_matches (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
     4
     5  int i, j, n, N, J, status, Nstars;
    66  double X, Y, RADIUS, RADIUS2, secz;
    77  float *X1, *Y1, *X2, *Y2;
     
    2323
    2424  /** allocate local arrays (stars) **/
    25   ALLOCATE (X1, float, Nstars);
    26   ALLOCATE (Y1, float, Nstars);
    27   ALLOCATE (N1, int,   Nstars);
     25  ALLOCATE (X1, float, NstarsIn);
     26  ALLOCATE (Y1, float, NstarsIn);
     27  ALLOCATE (N1, int,   NstarsIn);
    2828
    2929  /** allocate local arrays (catalog) **/
     
    5555    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    5656    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
     57    tcoords.Npolyterms = 1;
    5758    strcpy (tcoords.ctype, "RA---TAN");
    5859  }
    5960
    6061  /* build spatial index (RA sort) */
    61   for (i = 0; i < Nstars; i++) {
    62     fRD_to_XY (&X1[i], &Y1[i], stars[i].R, stars[i].D, &tcoords);
    63     N1[i] = i;
     62  Nstars = 0;
     63  for (i = 0; i < NstarsIn; i++) {
     64    status = fRD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
     65    if (!status) continue;
     66    N1[Nstars] = i;
     67    Nstars ++;
     68  }
     69  if (Nstars < 1) {
     70    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
     71    free (catalog[0].found);
     72    free (X1);
     73    free (Y1);
     74    free (N1);
     75    free (X2);
     76    free (Y2);
     77    free (N2);
     78    return;
    6479  }
    6580  if (Nstars > 1) sort_lists (X1, Y1, N1, Nstars);
     
    333348
    334349  /* note stars which have been found in this catalog */
    335   for (i = 0; i < Nstars; i++) {
     350  for (i = 0; i < NstarsIn; i++) {
    336351    if (stars[i].found > -1) {
    337352      stars[i].found = -2;
     
    346361  catalog[0].Nmissing = Nmiss;
    347362  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmiss, Nmatch);
     363
     364  free (catalog[0].found);
     365  free (X1);
     366  free (Y1);
     367  free (N1);
     368  free (X2);
     369  free (Y2);
     370  free (N2);
    348371  return;
    349372}
  • trunk/Ohana/src/addstar/src/find_matches_closest.c

    r8304 r8328  
    11# include "addstar.h"
    2 # define DEBUG 1
    3 
    4 void find_matches_closest (SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
    5 
    6   int i, j, n, N, J, Jmin;
     2
     3void find_matches_closest (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
     4
     5  int i, j, n, N, J, Jmin, status, Nstars;
    76  double X, Y, RADIUS, RADIUS2, Rmin, secz;
    87  float *X1, *Y1, *X2, *Y2;
     
    2423
    2524  /** allocate local arrays (stars) **/
    26   ALLOCATE (X1, float, Nstars);
    27   ALLOCATE (Y1, float, Nstars);
    28   ALLOCATE (N1, int,   Nstars);
     25  ALLOCATE (X1, float, NstarsIn);
     26  ALLOCATE (Y1, float, NstarsIn);
     27  ALLOCATE (N1, int,   NstarsIn);
    2928
    3029  /** allocate local arrays (catalog) **/
     
    4039  NMEAS = Nmeas = catalog[0].Nmeasure;
    4140  NMISS = Nmiss = catalog[0].Nmissing;
    42  
     41
    4342  /* project onto rectilinear grid with 1 arcsec pixels */
    4443  /* we keep the original crpix1,2 and crref1,2 */
     
    5655    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    5756    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
     57    tcoords.Npolyterms = 1;
    5858    strcpy (tcoords.ctype, "RA---TAN");
    5959  }
    6060
    61   /* build spatial index (RA sort) */
    62   for (i = 0; i < Nstars; i++) {
    63     fRD_to_XY (&X1[i], &Y1[i], stars[i].R, stars[i].D, &tcoords);
    64     N1[i] = i;
     61  /* build spatial index (RA sort) referencing input array sequence */
     62  Nstars = 0;
     63  for (i = 0; i < NstarsIn; i++) {
     64    status = fRD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
     65    if (!status) continue;
     66    N1[Nstars] = i;
     67    Nstars ++;
     68  }
     69  if (Nstars < 1) {
     70    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
     71    free (catalog[0].found);
     72    free (X1);
     73    free (Y1);
     74    free (N1);
     75    free (X2);
     76    free (Y2);
     77    free (N2);
     78    return;
    6579  }
    6680  if (Nstars > 1) sort_lists (X1, Y1, N1, Nstars);
    67  
     81
    6882  /* build spatial index (RA sort) */
    6983  for (i = 0; i < Nave; i++) {
     
    149163    n = N2[Jmin];
    150164    N = N1[i];
    151 
    152     if (DEBUG) fprintf (stderr, "matched %f,%f and %f,%f\n",
    153                         catalog[0].average[n].R, catalog[0].average[n].D,
    154                         stars[N].R, stars[N].D);
    155165
    156166    /* add to end of measurement list */
     
    329339  }
    330340     
    331   free (catalog[0].found);
    332341  REALLOCATE (catalog[0].average, Average, Nave);
    333342  REALLOCATE (catalog[0].measure, Measure, Nmeas);
     
    344353
    345354  /* note stars which have been found in this catalog */
    346   for (i = 0; i < Nstars; i++) {
     355  for (i = 0; i < NstarsIn; i++) {
    347356    if (stars[i].found > -1) {
    348357      stars[i].found = -2;
     
    356365  catalog[0].Nmeasure = Nmeas;
    357366  catalog[0].Nmissing = Nmiss;
    358   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmiss, Nmatch);
     367  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", NstarsIn, Nave, Nmeas, Nmiss, Nmatch);
     368
     369  free (catalog[0].found);
     370  free (X1);
     371  free (Y1);
     372  free (N1);
     373  free (X2);
     374  free (Y2);
     375  free (N2);
    359376  return;
    360377}
  • trunk/Ohana/src/addstar/src/gcatalog.c

    r7080 r8328  
    88
    99  /* read catalog header */
    10   if (!load_catalog (catalog, VERBOSE)) {
     10  if (!dvo_catalog_load (catalog, VERBOSE)) {
    1111    fprintf (stderr, "ERROR: failure loading catalog\n");
    1212    exit (1);
    1313  }
    1414
    15   /* should this be moved into save_catalog?? */
    16   status = gfits_scan (&catalog[0].header, "SORTED", "%t", 1, &catalog[0].sorted);
    17   if (!status) catalog[0].sorted = TRUE;
    18   /* XXX EAM - is this a good choice?  should the default be 'FALSE'? */
    19 
    2015  /* check Nsecfile value, update if needed */
    2116  Nsecfilt = GetPhotcodeNsecfilt ();
    22   if (catalog[0].Nsecfilt < Nsecfilt) {
    23 
    24     int i, j, Nextra, in, out;
    25     SecFilt *insec, *outsec;
    26 
    27     Nextra = Nsecfilt - catalog[0].Nsecfilt;
    28     insec = catalog[0].secfilt;
    29     ALLOCATE (outsec, SecFilt, catalog[0].Naverage * Nsecfilt);
    30     for (in = out = i = 0; i < catalog[0].Naverage; i++) {
    31       for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
    32         outsec[out].M_PS  = insec[in].M_PS;
    33         outsec[out].dM_PS = insec[in].dM_PS;
    34         outsec[out].Xm = insec[in].Xm;
    35       }
    36       for (j = 0; j < Nextra; j++, out++) {
    37         outsec[out].M_PS  = NO_MAG;
    38         outsec[out].dM_PS = NO_MAG;
    39         outsec[out].Xm    = NO_MAG;
    40       }
    41     }
    42     free (catalog[0].secfilt);
    43     catalog[0].secfilt = outsec;
    44     catalog[0].Nsecfilt = Nsecfilt;
    45   }
    46 
    47   if (catalog[0].Nsecfilt > Nsecfilt) {
     17  if (!dvo_catalog_check (catalog, Nsecfilt, TRUE)) {
    4818    fprintf (stderr, "ERROR: can't reduce number of secondary filters\n");
    49     exit (1);
     19    exit (2);
    5020  }
    5121  return (TRUE);
  • trunk/Ohana/src/addstar/src/load_pt_catalog.c

    r7691 r8328  
    11# include "addstar.h"
    22
     3// XXX can I replace this with dvo_catalog_open ()
     4// XXX set the catalog properties before the function call (not as args)
    35int load_pt_catalog (Catalog *catalog, SkyRegion *region) {
    46 
    5   if (!check_file_access (catalog[0].filename, TRUE, TRUE)) {
    6     exit (1);
    7   }
     7  if (!check_file_access (catalog[0].filename, TRUE, TRUE)) exit (1);
    88
    99  if (VERBOSE) fprintf (stderr, "adding to %s\n", catalog[0].filename);
    1010   
     11  /* check Nsecfile value, update if needed */
     12  Nsecfilt = GetPhotcodeNsecfilt ();
     13
    1114  switch (lock_catalog (catalog, LCK_XCLD)) {
    1215  case 0:
     
    1417    exit (1);
    1518  case 1:
    16     gcatalog (catalog); /* load from disk */
    17     if (VERBOSE) fprintf (stderr, "loading existing file %s\n", catalog[0].filename);
     19    if (!dvo_catalog_load (catalog, VERBOSE)) {
     20      fprintf (stderr, "ERROR: failure loading catalog\n");
     21      exit (1);
     22    }
     23    if (!dvo_catalog_check (catalog, Nsecfilt, TRUE)) {
     24      fprintf (stderr, "ERROR: can't reduce number of secondary filters\n");
     25      exit (2);
     26    }
     27    if (VERBOSE) fprintf (stderr, "loaded existing file %s\n", catalog[0].filename);
    1828    break;
    1929  case 2:
    20     mkcatalog (region, catalog); /* fills in new header info */
     30    dvo_catalog_create (region, catalog, Nsecfilt, CATFORMAT, CATMODE); /* fills in new header info */
    2131    if (VERBOSE) fprintf (stderr, "creating new file %s\n", catalog[0].filename);
    2232    break;
Note: See TracChangeset for help on using the changeset viewer.