IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36490 for trunk/Ohana


Ignore:
Timestamp:
Feb 6, 2014, 12:45:37 PM (12 years ago)
Author:
eugene
Message:

add support for alt PS1_V4 dvo format; add TessellationTable stuff; consistency for ctype and RA vs DEC as source

Location:
trunk/Ohana/src/libdvo
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libdvo/Makefile

    r35416 r36490  
    107107$(SRC)/convert.$(ARCH).o                \
    108108$(SRC)/HostTable.$(ARCH).o              \
    109 $(SRC)/BoundaryTree.$(ARCH).o
    110 
     109$(SRC)/BoundaryTree.$(ARCH).o           \
     110$(SRC)/TessellationTable.$(ARCH).o
    111111
    112112# $(SRC)/dvo_convert_panstarrs.$(ARCH).o
  • trunk/Ohana/src/libdvo/include/dvo.h

    r36084 r36490  
    308308# define BOUNDARY_TREE_NAME_LENGTH 128
    309309
     310// BoundaryTree is a structure to describe the 3pi RINGS skycell boundaries in terms of lines of constant (RA,DEC)
     311// the structure is flexible for a variety of RINGS-like tessellations, but is not appropriate for the LOCAL style tess
    310312typedef struct {
    311313  int FixedGridDEC;           // is the DEC sequence linear?
     
    342344} BoundaryTree;
    343345
    344 // XXX DROP? // a reduced-subset structure for relastro
    345 // XXX DROP? typedef struct {
    346 // XXX DROP?   double         R;
    347 // XXX DROP?   double         D;
    348 // XXX DROP?   unsigned short Nmeasure;
    349 // XXX DROP?   int            measureOffset;
    350 // XXX DROP?   uint32_t       flags;
    351 // XXX DROP?   int            catID;
    352 // XXX DROP? } AverageTinyAstro;
     346typedef enum { TESS_NONE, TESS_LOCAL, TESS_RINGS } TessType;
     347
     348// TessellationTable is a structure to describe the parameters of a set of "tessellations"
     349// (these are not strictly tessellations but projection sets as only the non-local
     350// versions can cover the full sky).  For LOCAL projection cells, the structure describes
     351// the boundaries of a SINGLE projection cell with Nx * Ny skycells and includes some
     352// basic parameters (not used by the fullsky, eg RINGS, tessellations)
     353typedef struct {
     354  double Rmin; // this tessellation is valid only for RA >= Rmin
     355  double Rmax; // this tessellation is valid only for RA <  Rmax
     356  double Dmin; // this tessellation is valid only for DEC >= Dmin
     357  double Dmax; // this tessellation is valid only for DEC <  Dmax
     358
     359  double Xo;
     360  double Yo;
     361  double Ro;
     362  double Do;
     363  double dPix;
     364  int dX;
     365  int dY;
     366
     367  int NX_SUB;
     368  int NY_SUB;
     369
     370  char *basename;
     371  int Nbasename;
     372  int projectIDoff;
     373  int skycellIDoff;
     374
     375  TessType type; //
     376  BoundaryTree *tree;
     377} TessellationTable;
    353378
    354379// a reduced-subset structure for relphot
     
    387412} MeasureTiny;
    388413
     414
     415/** STRUCT DEFINITION **/
     416typedef struct {
     417  float            dR;                   // RA offset (arcsec)
     418  float            dD;                   // DEC offset (arcsec)
     419  float            M;                    // catalog mag (mag)
     420  float            Mcal;                 // image cal mag (mag)
     421  float            Map;                  // aperture mag (mag)
     422  float            Mkron;                // kron magnitude (mag)
     423  float            dMkron;               // kron magnitude error (mag)
     424  float            dM;                   // mag error (mag)
     425  float            dMcal;                // systematic calibration error (mag)
     426  float            dt;                   // exposure time (2.5*log(exptime))
     427  float            FluxPSF;              // flux from psf fit (counts/sec?)
     428  float            dFluxPSF;             // error on psf flux (counts/sec?)
     429  float            FluxKron;             // flux from kron ap (counts/sec?)
     430  float            dFluxKron;            // error on kron flux (counts/sec?)
     431  float            airmass;              // (airmass - 1) (airmass)
     432  float            az;                   // telescope azimuth
     433  float            Xccd;                 // X coord on chip (raw value) (pixels)
     434  float            Yccd;                 // Y coord on chip (raw value) (pixels)
     435  float            Sky;                  // local estimate of sky flux (counts/sec)
     436  float            dSky;                 // local estimate of sky flux (counts/sec)
     437  int              t;                    // time in seconds (UNIX)
     438  unsigned int     averef;               // reference to average entry     
     439  unsigned int     detID;                // detection ID
     440  unsigned int     imageID;              // reference to DVO image ID
     441  unsigned int     objID;                // unique ID for object in table
     442  unsigned int     catID;                // unique ID for table in which object was first realized
     443  uint64_t         extID;                // external ID (eg PSPS detID)
     444  float            psfQF;                // psf coverage/quality factor
     445  float            psfQFperf;            // psf coverage / quality factor (all mask bits)
     446  float            psfChisq;             // psf fit chisq
     447  int              psfNdof;              // psf degrees of freedom
     448  int              psfNpix;              // psf number of pixels
     449  float            crNsigma;             // Nsigma deviation towards CR
     450  float            extNsigma;            // Nsigma deviation towards EXT
     451  short            FWx;                  // object fwhm major axis (1/100 of pixels)
     452  short            FWy;                  // object fwhm minor axis (1/100 of pixels )
     453  short            theta;                // angle wrt ccd X dir ((0xffff/360) deg)
     454  short            Mxx;                  // second moments in pixel coords (1/100 of pixels)
     455  short            Mxy;                  // second moments in pixel coords (1/100 of pixels)
     456  short            Myy;                  // second moments in pixel coords (1/100 of pixels)
     457  unsigned short   t_msec;               // time fraction of second (milliseconds)
     458  unsigned short   photcode;             // photcode
     459  short            dXccd;                // X coord error on chip (1/100 of pixels)
     460  short            dYccd;                // Y coord error on chip (1/100 of pixels)
     461  short            dRsys;                // systematic error from astrom (1/100 of pixels)
     462  short            posangle;             // position angle sky to chip ((0xffff/360) deg)
     463  float            pltscale;             // plate scale (arcsec/pixel)
     464  unsigned int     dbFlags;              // flags supplied by analysis in database
     465  unsigned int     photFlags;            // flags supplied by photometry program
     466} Measure_PS1_V4alt;
     467
     468Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
     469Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues);
     470
    389471/* a catalog contains this data */
    390472typedef struct Catalog {
     
    717799int free_tiny_values (Catalog *catalog);
    718800
     801BoundaryTree *BoundaryTreeLoad(char *filename);
     802BoundaryTree *BoundaryTreeRead(Header *headerPHU, Header *headerZone, FILE *f);
     803
     804int BoundaryTreeSave(char *filename, BoundaryTree *tree);
     805int BoundaryTreeWrite(FILE *f, BoundaryTree *tree);
     806
    719807int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec);
    720 int BoundaryTreeSave(char *filename, BoundaryTree *tree);
    721 BoundaryTree *BoundaryTreeLoad(char *filename);
    722808int BoundaryTreeProjection (double *x, double *y, double r, double d, BoundaryTree *tree, int zone, int band);
     809
     810TessellationTable *TessellationTableLoad(char *filename, int *Ntess);
     811int TessellationTableSave(char *filename, TessellationTable *tess, int Ntess);
     812int TessellationPrimaryCellIDs (TessellationTable *tess, int Ntess, int *tessID, int *projID, int *skycellID, double ra, double dec);
     813void TessellationTableInit (TessellationTable *tess, int Ntess);
    723814
    724815void dvo_average_init (Average *average);
  • trunk/Ohana/src/libdvo/include/dvodb.h

    r36084 r36490  
    375375
    376376// Some values used by code moved to libdvo from opihi.
    377 enum {OPIHI_FLT, OPIHI_INT};
     377enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT};
    378378#define opihi_flt double
    379379#define opihi_int int
  • trunk/Ohana/src/libdvo/src/BoundaryTree.c

    r35755 r36490  
    11# include "dvo.h"
    22
    3 # define GET_COLUMN_NEW(OUT,NAME,TYPE)                                  \
    4   TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     3# define GET_COLUMN_NEW(HEADER,FTABLE,OUT,NAME,TYPE)                            \
     4  TYPE *OUT = gfits_get_bintable_column_data (HEADER, FTABLE, NAME, type, &Nrow, &Ncol); \
    55  myAssert (!strcmp(type, #TYPE), "wrong column type");
    66
    7 # define GET_COLUMN_RAW(OUT,NAME,TYPE)                                  \
    8   OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     7# define GET_COLUMN_RAW(HEADER,FTABLE,OUT,NAME,TYPE)                    \
     8  OUT = gfits_get_bintable_column_data (HEADER, FTABLE, NAME, type, &Nrow, &Ncol); \
    99  myAssert (!strcmp(type, #TYPE), "wrong column type");
    1010
     
    1212
    1313BoundaryTree *BoundaryTreeLoad(char *filename) {
     14
     15  Header header;
     16  Header theader;
     17  Matrix matrix;
     18
     19  header.buffer = NULL;
     20  matrix.buffer = NULL;
     21  theader.buffer = NULL;
     22  BoundaryTree *tree = NULL;
     23
     24  FILE *f = fopen (filename, "r");
     25  if (!f) {
     26    fprintf (stderr, "ERROR: cannot open boundary tree file %s\n", filename);
     27    return NULL;
     28  }
     29
     30  /* load in PHU segment (ignore) */
     31  if (!gfits_fread_header (f, &header)) {
     32    if (DEBUG) fprintf (stderr, "can't read boundary tree header\n");
     33    goto escape;
     34  }
     35  if (!gfits_fread_matrix (f, &matrix, &header)) {
     36    if (DEBUG) fprintf (stderr, "can't read boundary tree matrix\n");
     37    goto escape;
     38  }
     39
     40  // load data for this header
     41  if (!gfits_load_header (f, &theader)) {
     42    if (DEBUG) fprintf (stderr, "can't read boundary tree zone table header\n");
     43    goto escape;
     44  }
     45
     46  tree = BoundaryTreeRead (&header, &theader, f);
     47
     48escape:
     49
     50  gfits_free_header (&theader);
     51  gfits_free_header (&header);
     52  gfits_free_matrix (&matrix);
     53  fclose (f);
     54
     55  return tree;
     56}
     57
     58// assume we are pointing at the relevant table portion
     59BoundaryTree *BoundaryTreeRead(Header *headerPHU, Header *headerZone, FILE *f) {
    1460
    1561  int i, j, nz, nb, Ncol;
    1662  off_t Nrow;
    1763  char type[16];
    18   Header header;
    19   Header theader;
    20   Matrix matrix;
    21   FTable ftable;
    22 
    23   header.buffer = NULL;
    24   matrix.buffer = NULL;
    25   ftable.buffer = NULL;
    26   theader.buffer = NULL;
     64
     65  FTable ftableZone;
     66
     67  Header headerCell;
     68  FTable ftableCell;
     69
     70  ftableZone.buffer = NULL;
     71  ftableCell.buffer = NULL;
     72  headerCell.buffer = NULL;
     73
     74  // we must have already read in the Zone table header section
     75  ftableZone.header =  headerZone;
     76  ftableCell.header = &headerCell;
     77
    2778  BoundaryTree *tree = NULL;
    2879
    29   FILE *f = fopen (filename, "r");
    30   if (!f) {
    31     fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename);
    32     return NULL;
    33   }
    34 
    35   /* load in PHU segment (ignore) */
    36   if (!gfits_fread_header (f, &header)) {
    37     if (DEBUG) fprintf (stderr, "can't read image subset header\n");
    38     goto escape;
    39   }
    40   if (!gfits_fread_matrix (f, &matrix, &header)) {
    41     if (DEBUG) fprintf (stderr, "can't read image subset matrix\n");
    42     goto escape;
    43   }
    44 
    4580  ALLOCATE (tree, BoundaryTree, 1);
    4681
    47   gfits_scan (&header, "DEC_ORI", "%lf", 1, &tree->DEC_origin);
    48   gfits_scan (&header, "DEC_OFF", "%lf", 1, &tree->DEC_offset);
    49 
    50   gfits_scan (&header, "NX_SUB", "%d", 1, &tree->NX_SUB);
    51   gfits_scan (&header, "NY_SUB", "%d", 1, &tree->NY_SUB);
    52   gfits_scan (&header, "PIXSCALE", "%lf", 1, &tree->dPix);
    53 
    54   ftable.header = &theader;
     82  // we need to read the boundary tree parameters from the correct header
     83  // put them in the PHU header in any case?
     84  gfits_scan (headerPHU, "DEC_ORI",  "%lf", 1, &tree->DEC_origin);
     85  gfits_scan (headerPHU, "DEC_OFF",  "%lf", 1, &tree->DEC_offset);
     86  gfits_scan (headerPHU, "NX_SUB",   "%d",  1, &tree->NX_SUB);
     87  gfits_scan (headerPHU, "NY_SUB",   "%d",  1, &tree->NY_SUB);
     88  gfits_scan (headerPHU, "PIXSCALE", "%lf", 1, &tree->dPix);
    5589
    5690  /*** zone information table ***/
    57   {
    58     // load data for this header
    59     if (!gfits_load_header (f, &theader)) goto escape;
    60 
    61     // read the fits table bytes
    62     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
     91
     92  // read the fits table bytes
     93  if (!gfits_fread_ftable_data (f, &ftableZone, FALSE)) goto escape;
    6394 
    64     // need to create and assign to flat-field correction
    65     GET_COLUMN_RAW(tree->Nband,       "NBAND",           int);
    66     GET_COLUMN_RAW(tree->RA_origin,   "RA_ORIGIN",   double);
    67     GET_COLUMN_RAW(tree->RA_offset,   "RA_OFFSET",   double);
    68     GET_COLUMN_RAW(tree->DEC_min  ,   "DEC_MIN",     double);
    69     GET_COLUMN_RAW(tree->DEC_max  ,   "DEC_MAX",     double);
    70     GET_COLUMN_RAW(tree->DEC_min_raw, "DEC_MIN_RAW", double);
    71     GET_COLUMN_RAW(tree->DEC_max_raw, "DEC_MAX_RAW", double);
    72     gfits_free_header (&theader);
    73     gfits_free_table  (&ftable);
    74 
    75     fprintf (stderr, "loaded data for %lld zones\n", (long long) Nrow);
    76     tree->Nzone = Nrow;
    77 
    78     // allocate the storage arrays
    79     ALLOCATE (tree->ra,   double *, tree->Nzone);
    80     ALLOCATE (tree->dec,  double *, tree->Nzone);
    81     ALLOCATE (tree->Xo,   double *, tree->Nzone);
    82     ALLOCATE (tree->Yo,   double *, tree->Nzone);
    83     ALLOCATE (tree->dX,      int *, tree->Nzone);
    84     ALLOCATE (tree->dY,      int *, tree->Nzone);
    85     ALLOCATE (tree->cell,    int *, tree->Nzone);
    86     ALLOCATE (tree->projID,  int *, tree->Nzone);
    87     ALLOCATE (tree->name,  char **, tree->Nzone);
    88     for (i = 0; i < tree->Nzone; i++) {
    89       ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
    90       ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
    91       ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
    92       ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
    93       ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
    94       ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
    95       ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
    96       ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
    97       ALLOCATE (tree->name[i], char *, tree->Nband[i]);
    98       for (j = 0; j < tree->Nband[i]; j++) {
    99         ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH);
    100       }
     95  // need to create and assign to flat-field correction
     96  GET_COLUMN_RAW(headerZone, &ftableZone, tree->Nband,       "NBAND",       int);
     97  GET_COLUMN_RAW(headerZone, &ftableZone, tree->RA_origin,   "RA_ORIGIN",   double);
     98  GET_COLUMN_RAW(headerZone, &ftableZone, tree->RA_offset,   "RA_OFFSET",   double);
     99  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_min  ,   "DEC_MIN",     double);
     100  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_max  ,   "DEC_MAX",     double);
     101  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_min_raw, "DEC_MIN_RAW", double);
     102  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_max_raw, "DEC_MAX_RAW", double);
     103  gfits_free_table  (&ftableZone);
     104
     105  fprintf (stderr, "loaded data for %lld zones\n", (long long) Nrow);
     106  tree->Nzone = Nrow;
     107
     108  // allocate the storage arrays
     109  ALLOCATE (tree->ra,   double *, tree->Nzone);
     110  ALLOCATE (tree->dec,  double *, tree->Nzone);
     111  ALLOCATE (tree->Xo,   double *, tree->Nzone);
     112  ALLOCATE (tree->Yo,   double *, tree->Nzone);
     113  ALLOCATE (tree->dX,      int *, tree->Nzone);
     114  ALLOCATE (tree->dY,      int *, tree->Nzone);
     115  ALLOCATE (tree->cell,    int *, tree->Nzone);
     116  ALLOCATE (tree->projID,  int *, tree->Nzone);
     117  ALLOCATE (tree->name,  char **, tree->Nzone);
     118  for (i = 0; i < tree->Nzone; i++) {
     119    ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
     120    ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
     121    ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
     122    ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
     123    ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
     124    ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
     125    ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
     126    ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
     127    ALLOCATE (tree->name[i], char *, tree->Nband[i]);
     128    for (j = 0; j < tree->Nband[i]; j++) {
     129      ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH);
    101130    }
    102131  }
    103132
    104133  /*** cell information table ***/
    105   {
    106     // load data for this header
    107     if (!gfits_load_header (f, &theader)) goto escape;
    108 
    109     // read the fits table bytes
    110     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
     134
     135  // load data for this header
     136  if (!gfits_load_header (f, &headerCell)) goto escape;
     137
     138  // read the fits table bytes
     139  if (!gfits_fread_ftable_data (f, &ftableCell, FALSE)) goto escape;
    111140 
    112     // need to create and assign to flat-field correction
    113     GET_COLUMN_NEW(R,     "RA",          double);
    114     GET_COLUMN_NEW(D,     "DEC",         double);
    115     GET_COLUMN_NEW(zone,  "ZONE",        int);
    116     GET_COLUMN_NEW(band,  "BAND",        int);
    117     GET_COLUMN_NEW(index, "INDEX",       int);
    118     GET_COLUMN_NEW(Xo,    "X_CENT",      double);
    119     GET_COLUMN_NEW(Yo,    "Y_CENT",      double);
    120     GET_COLUMN_NEW(dX,    "X_GRID",      int);
    121     GET_COLUMN_NEW(dY,    "Y_GRID",      int);
    122     GET_COLUMN_NEW(name,  "NAME",        char); // XXX how is this done?
    123     gfits_free_header (&theader);
    124     gfits_free_table  (&ftable);
    125     fprintf (stderr, "loaded data for %lld cells\n", (long long) Nrow);
    126 
    127     // assign the storage arrays
    128     for (i = 0; i < Nrow; i++) {
    129       nz = zone[i];
    130       nb = band[i];
    131       tree->ra[nz][nb] = R[i];
    132       tree->dec[nz][nb] = D[i];
    133       tree->Xo[nz][nb] = Xo[i];
    134       tree->Yo[nz][nb] = Yo[i];
    135       tree->dX[nz][nb] = dX[i];
    136       tree->dY[nz][nb] = dY[i];
    137       tree->cell[nz][nb] = i; // XXX ?
    138       memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
    139       // XXX parse out the ID from the name (skycell.NNNN)
    140       tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
    141     }
    142 
    143     free (R     );
    144     free (D     );
    145     free (zone  );
    146     free (band  );
    147     free (Xo    );
    148     free (Yo    );
    149     free (dX    );
    150     free (dY    );
    151     free (index );
    152     free (name  );
    153   }
    154 
    155   gfits_free_header (&header);
    156   gfits_free_matrix (&matrix);
    157   fclose (f);
     141  // need to create and assign to flat-field correction
     142  GET_COLUMN_NEW(&headerCell, &ftableCell, R,     "RA",          double);
     143  GET_COLUMN_NEW(&headerCell, &ftableCell, D,     "DEC",         double);
     144  GET_COLUMN_NEW(&headerCell, &ftableCell, zone,  "ZONE",        int);
     145  GET_COLUMN_NEW(&headerCell, &ftableCell, band,  "BAND",        int);
     146  GET_COLUMN_NEW(&headerCell, &ftableCell, index, "INDEX",       int);
     147  GET_COLUMN_NEW(&headerCell, &ftableCell, Xo,    "X_CENT",      double);
     148  GET_COLUMN_NEW(&headerCell, &ftableCell, Yo,    "Y_CENT",      double);
     149  GET_COLUMN_NEW(&headerCell, &ftableCell, dX,    "X_GRID",      int);
     150  GET_COLUMN_NEW(&headerCell, &ftableCell, dY,    "Y_GRID",      int);
     151  GET_COLUMN_NEW(&headerCell, &ftableCell, name,  "NAME",        char); // XXX how is this done?
     152  gfits_free_header (&headerCell);
     153  gfits_free_table  (&ftableCell);
     154
     155  fprintf (stderr, "loaded data for %lld cells\n", (long long) Nrow);
     156
     157  // assign the storage arrays
     158  for (i = 0; i < Nrow; i++) {
     159    nz = zone[i];
     160    nb = band[i];
     161    tree->ra[nz][nb] = R[i];
     162    tree->dec[nz][nb] = D[i];
     163    tree->Xo[nz][nb] = Xo[i];
     164    tree->Yo[nz][nb] = Yo[i];
     165    tree->dX[nz][nb] = dX[i];
     166    tree->dY[nz][nb] = dY[i];
     167    tree->cell[nz][nb] = i; // XXX ?
     168    memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
     169    // XXX parse out the ID from the name (skycell.NNNN)
     170    tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
     171  }
     172
     173  free (R     );
     174  free (D     );
     175  free (zone  );
     176  free (band  );
     177  free (Xo    );
     178  free (Yo    );
     179  free (dX    );
     180  free (dY    );
     181  free (index );
     182  free (name  );
    158183
    159184  return tree;
    160185
    161186escape:
    162   gfits_free_header (&header);
    163   gfits_free_matrix (&matrix);
    164   gfits_free_header (&theader);
    165   gfits_free_table  (&ftable);
     187  gfits_free_header (&headerCell);
     188  gfits_free_table  (&ftableCell);
     189  gfits_free_table  (&ftableZone);
    166190  if (tree) free (tree);
    167191
    168   fclose (f);
    169192  return NULL;
    170193}
     
    173196int BoundaryTreeSave(char *filename, BoundaryTree *tree) {
    174197
    175   int i, nz, nb;
    176198  Header header;
    177   Header theader;
    178199  Matrix matrix;
    179   FTable ftable;
    180200
    181201  gfits_init_header (&header);
     
    202222  gfits_free_header (&header);
    203223  gfits_free_matrix (&matrix);
     224
     225  BoundaryTreeWrite (f, tree);
     226  fclose (f);
     227
     228  return TRUE;
     229}
     230
     231int BoundaryTreeWrite(FILE *f, BoundaryTree *tree) {
     232
     233  int i, nz, nb;
     234  Header theader;
     235  FTable ftable;
    204236
    205237  /*** zone information table ***/
  • trunk/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r35416 r36490  
    1818  field.pc1_2  = field.pc2_1  = 0.0;
    1919  field.Npolyterms = 0;
    20   strcpy (field.ctype, "RA---SIN");
     20  strcpy (field.ctype, "DEC--SIN");
    2121
    2222  /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
     
    2626  mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    2727  mosaic.Npolyterms = 0;
    28   strcpy (mosaic.ctype, "RA---SIN");
     28  strcpy (mosaic.ctype, "DEC--SIN");
    2929
    3030  if ((image = ImageMetadataLoad (filename, &Nimage)) == NULL) return (FALSE);
  • trunk/Ohana/src/libdvo/src/ImageSelection.c

    r35416 r36490  
    2828      mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    2929      mosaic.Npolyterms = 0;
    30       strcpy (mosaic.ctype, "RA---SIN");
     30      strcpy (mosaic.ctype, "DEC--SIN");
    3131  }
    3232
  • trunk/Ohana/src/libdvo/src/coordops.c

    r34088 r36490  
    11# include <dvo.h>
     2
     3/* note that Coords.ctype carries the DEC (ctype2) value */
    24
    35static Coords mosaic;
     
    621623
    622624  /* modifications to the ctype? */
     625  /* note that Coords.ctype carries the DEC (ctype2) value */
    623626  OldAIPS = FALSE;
    624627  gfits_modify (header, "CTYPE2",   "%s",  1, coords[0].ctype);
  • trunk/Ohana/src/libdvo/src/dbCheckStack.c

    r35755 r36490  
    77// these would be better done using bit values to test for field? temp? float?
    88//
    9 
    10 #define OPIHI_INT 1
    119
    1210int dbCheckStack (dbStack *stack, int Nstack, int table, dbField **inFields, int *inNfields) {
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r35172 r36490  
    154154    fprintf (stderr, "EXTNAME missing for measure table\n");
    155155    return (FALSE);
     156  }
     157
     158  // block to convert broken tables (PS1_V4 made before the Xfix addition)
     159  if (!strcmp (extname, "DVO_MEASURE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 176)) {
     160    fprintf (stderr, "reading alt PS1_V4 format\n");
     161    Measure_PS1_V4alt *tmpMeasure;
     162    tmpMeasure = gfits_table_get_Measure_PS1_V4alt (ftable, Nmeasure, NULL);
     163    if (!tmpMeasure) {
     164      fprintf (stderr, "ERROR: failed to read measures\n");
     165      exit (2);
     166    }
     167    measure = Measure_PS1_V4alt_ToInternal (tmpMeasure, *Nmeasure);
     168    free (tmpMeasure);
     169    *format = DVO_FORMAT_PS1_V4;
     170    return (measure);
    156171  }
    157172
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r35162 r36490  
    481481  return (out);
    482482}
     483
     484/*** there are some mini dvodbs with the wrong PS1_V4 format (missing Xoff,Yoff / Xfix,Yfix) ************/
     485
     486Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues) {
     487
     488  off_t i;
     489  Measure *out;
     490
     491  ALLOCATE_ZERO (out, Measure, Nvalues);
     492
     493  for (i = 0; i < Nvalues; i++) {
     494    dvo_measure_init (&out[i]);
     495
     496    out[i].dR         = in[i].dR;
     497    out[i].dD         = in[i].dD;
     498    out[i].M          = in[i].M;
     499    out[i].Mcal       = in[i].Mcal;
     500    out[i].Map        = in[i].Map;
     501    out[i].Mkron      = in[i].Mkron;
     502    out[i].dMkron     = in[i].dMkron;
     503    out[i].dM         = in[i].dM;
     504    out[i].dMcal      = in[i].dMcal;
     505    out[i].dt         = in[i].dt;
     506    out[i].FluxPSF    = in[i].FluxPSF;
     507    out[i].dFluxPSF   = in[i].dFluxPSF;
     508    out[i].FluxKron   = in[i].FluxKron;
     509    out[i].dFluxKron  = in[i].dFluxKron;
     510    out[i].airmass    = in[i].airmass;
     511    out[i].az         = in[i].az;
     512    out[i].Xccd       = in[i].Xccd;
     513    out[i].Yccd       = in[i].Yccd;
     514    out[i].Xfix       = in[i].Xccd;
     515    out[i].Yfix       = in[i].Yccd;
     516    out[i].Sky        = in[i].Sky;
     517    out[i].dSky       = in[i].dSky;
     518    out[i].t          = in[i].t;
     519    out[i].t_msec     = in[i].t_msec;
     520    out[i].averef     = in[i].averef;
     521    out[i].detID      = in[i].detID;
     522    out[i].imageID    = in[i].imageID;
     523    out[i].objID      = in[i].objID;
     524    out[i].catID      = in[i].catID;
     525    out[i].extID      = in[i].extID;
     526    out[i].psfQF      = in[i].psfQF;
     527    out[i].psfQFperf  = in[i].psfQFperf;
     528    out[i].psfChisq   = in[i].psfChisq;
     529    out[i].psfNdof    = in[i].psfNdof;
     530    out[i].psfNpix    = in[i].psfNpix;
     531    out[i].crNsigma   = in[i].crNsigma;
     532    out[i].extNsigma  = in[i].extNsigma;
     533    out[i].FWx        = in[i].FWx;
     534    out[i].FWy        = in[i].FWy;
     535    out[i].theta      = in[i].theta;
     536    out[i].Mxx        = in[i].Mxx;
     537    out[i].Mxy        = in[i].Mxy;
     538    out[i].Myy        = in[i].Myy;
     539    out[i].dXccd      = in[i].dXccd;
     540    out[i].dYccd      = in[i].dYccd;
     541    out[i].dRsys      = in[i].dRsys;
     542    out[i].posangle   = in[i].posangle;
     543    out[i].pltscale   = in[i].pltscale;
     544    out[i].photcode   = in[i].photcode;
     545    out[i].dbFlags    = in[i].dbFlags;
     546    out[i].photFlags  = in[i].photFlags;
     547  }
     548  return (out);
     549}
     550
     551int gfits_convert_Measure_PS1_V4alt (Measure_PS1_V4alt *data, off_t size, off_t nitems) {
     552
     553  off_t i;
     554  unsigned char *byte, tmp;
     555
     556  if (size != 176) {
     557    fprintf (stderr, "WARNING: mismatch in data types Measure_PS1_V4alt: "OFF_T_FMT" vs %d\n",  size,  176);
     558    return (FALSE);
     559  }
     560
     561  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     562  i = tmp = 0;
     563  byte = NULL;
     564
     565# ifdef BYTE_SWAP
     566  byte = (unsigned char *) data;
     567  for (i = 0; i < nitems; i++, byte += 176) {
     568    /** BYTE SWAP **/
     569    SWAP_WORD (0); // D_RA
     570    SWAP_WORD (4); // D_DEC
     571    SWAP_WORD (8); // MAG
     572    SWAP_WORD (12); // M_CAL
     573    SWAP_WORD (16); // M_APER
     574    SWAP_WORD (20); // M_KRON
     575    SWAP_WORD (24); // M_KRON_ERR
     576    SWAP_WORD (28); // MAG_ERR
     577    SWAP_WORD (32); // MAG_CAL_ERR
     578    SWAP_WORD (36); // M_TIME
     579    SWAP_WORD (40); // FLUX_PSF
     580    SWAP_WORD (44); // FLUX_PSF_ERR
     581    SWAP_WORD (48); // FLUX_KRON
     582    SWAP_WORD (52); // FLUX_KRON_ERR
     583    SWAP_WORD (56); // AIRMASS
     584    SWAP_WORD (60); // AZ
     585    SWAP_WORD (64); // X_CCD
     586    SWAP_WORD (68); // Y_CCD
     587    SWAP_WORD (72); // SKY_FLUX   
     588    SWAP_WORD (76); // SKY_FLUX_ERR
     589    SWAP_WORD (80); // TIME
     590    SWAP_WORD (84); // AVE_REF
     591    SWAP_WORD (88); // DET_ID
     592    SWAP_WORD (92); // IMAGE_ID
     593    SWAP_WORD (96); // OBJ_ID
     594    SWAP_WORD (100); // CAT_ID
     595    SWAP_DBLE (104); // EXT_ID
     596    SWAP_WORD (112); // PSF_QF       
     597    SWAP_WORD (116); // PSF_QF_PERFECT
     598    SWAP_WORD (120); // PSF_CHISQ     
     599    SWAP_WORD (124); // PSF_NDOF     
     600    SWAP_WORD (128); // PSF_NPIX     
     601    SWAP_WORD (132); // CR_NSIGMA     
     602    SWAP_WORD (136); // EXT_NSIGMA   
     603    SWAP_BYTE (140); // FWHM_MAJOR
     604    SWAP_BYTE (142); // FWHM_MINOR
     605    SWAP_BYTE (144); // PSF_THETA 
     606    SWAP_BYTE (146); // MXX       
     607    SWAP_BYTE (148); // MXY       
     608    SWAP_BYTE (150); // MYY       
     609    SWAP_BYTE (152); // TIME_MSEC 
     610    SWAP_BYTE (154); // PHOTCODE   
     611    SWAP_BYTE (156); // X_CCD_ERR 
     612    SWAP_BYTE (158); // Y_CCD_ERR 
     613    SWAP_BYTE (160); // POS_SYS_ERR
     614    SWAP_BYTE (162); // POSANGLE   
     615    SWAP_WORD (164); // PLTSCALE 
     616    SWAP_WORD (168); // DB_FLAGS 
     617    SWAP_WORD (172); // PHOT_FLAGS
     618  }
     619# endif 
     620
     621  return (TRUE);
     622}
     623
     624/*** add test of EXTNAME and header-defined columns? ***/
     625/* return internal structure representation */
     626Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *ftable, off_t *Ndata, char *swapped) {
     627
     628  int Ncols;
     629  Measure_PS1_V4alt *data;
     630
     631  Ncols = ftable[0].header[0].Naxis[0];
     632  if (Ncols != 176) {
     633    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 176);
     634    return NULL;
     635  }
     636
     637  *Ndata = ftable[0].header[0].Naxis[1];
     638  data = (Measure_PS1_V4alt *) ftable[0].buffer;
     639  if ((swapped == NULL) || (*swapped == FALSE)) {
     640    if (!gfits_convert_Measure_PS1_V4alt (data, sizeof (Measure_PS1_V4alt), *Ndata)) {
     641      return NULL;
     642    }
     643    gfits_table_scale_data (ftable);
     644    if (swapped != NULL) *swapped = TRUE;
     645  }
     646  return (data);
     647}
     648
Note: See TracChangeset for help on using the changeset viewer.