IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #900: dvo.h

File dvo.h, 18.9 KB (added by eugene, 19 years ago)

update to dvo.h which fixes the enum conflicts on macs

Line 
1# include <ohana.h>
2# include <gfitsio.h>
3# include <autocode.h>
4
5# ifndef DVO_H
6# define DVO_H
7
8/*
9 # define ELIXIR 1
10 # define PANSTARRS 0
11 # define LONEOS 0
12*/
13
14/*** named data values (convert all to enums?) ***/
15
16/* DVO table modes */
17typedef enum {DVO_MODE_UNDEF, DVO_MODE_RAW, DVO_MODE_MEF, DVO_MODE_SPLIT, DVO_MODE_MYSQL} DVOTableMode;
18
19/* DVO table formats */
20typedef enum {DVO_FORMAT_UNDEF,
21 DVO_FORMAT_INTERNAL,
22 DVO_FORMAT_ELIXIR,
23 DVO_FORMAT_LONEOS,
24 DVO_FORMAT_PANSTARRS,
25 DVO_FORMAT_PMTEST,
26 DVO_FORMAT_PANSTARRS_DEV_0,
27 DVO_FORMAT_PANSTARRS_DEV_1
28} DVOTableFormat;
29
30/* image data modes in RegImage */
31typedef enum {T_UNDEF = -1, T_NONE, T_OBJECT, T_DARK, T_BIAS, T_FLAT, T_MASK, T_FRINGE, T_SCATTER, T_MODES, T_FRINGEPTS, T_ANY, N_TYPE} ElixirDetrendTypes;
32typedef enum {M_UNDEF = -1, M_NONE, M_MEF, M_SPLIT, M_SINGLE, M_CUBE, M_SLICE, M_MODES, N_MODE} ElixirDetrendModes;
33
34typedef enum {
35 PROJ_NONE, // undefined
36 PROJ_ZEA, // zenithal
37 PROJ_ZPL, // zenithal
38 PROJ_ARC, // zenithal
39 PROJ_STG, // zenithal
40 PROJ_SIN, // zenithal
41 PROJ_TAN, // zenithal
42 PROJ_DIS, // zenithal (TAN + polyterms)
43 PROJ_LIN, // cartesian
44 PROJ_PLY, // cartesian
45 PROJ_WRP, // cartesian
46 PROJ_AIT, // pseudocyl
47 PROJ_GLS, // pseudocyl
48 PROJ_PAR, // pseudocyl
49} OhanaProjection;
50
51typedef enum {
52 PROJ_MODE_NONE,
53 PROJ_MODE_CARTESIAN,
54 PROJ_MODE_ZENITHAL,
55 PROJ_MODE_PSEUDOCYL,
56} OhanaProjectionMode;
57
58/* RegImage.flag values */
59# define IMREG_DIST 0x01 /* image distributed, only imregister-3.0 */
60
61/* catalog values to be loaded */
62# define LOAD_AVES 0x01
63# define LOAD_MEAS 0x02
64# define LOAD_MISS 0x04
65# define LOAD_SECF 0x08
66# define LOAD_MEAS_META 0x10
67
68/* invalid mag value */
69# define NO_MAG 0x7fff
70# define NO_ERR 0xff
71
72/* photometry code types */
73// # define PHOT_PRI 0x01
74# define PHOT_SEC 0x02
75# define PHOT_DEP 0x03
76# define PHOT_REF 0x04
77# define PHOT_ALT 0x05 /* never stored, only for look-ups */
78# define PHOT_MAG 0x06 /* generic magnitude; never stored */
79
80/* Image.code values. these are codes to note bad images */
81# define ID_IMAGE_NEW 0x0000 /* no nrphot attempted */
82# define ID_IMAGE_NOCAL 0x0001 /* used within nrphot to mean "don't apply fit" */
83# define ID_IMAGE_POOR 0x0002 /* relphot says image is bad */
84# define ID_IMAGE_SKIP 0x0004 /* external information image is bad */
85# define ID_IMAGE_FEW 0x0008 /* currently too few measurements for good value */
86
87/* Measure.flags values */
88# define ID_MEAS_NOCAL 0x0001
89# define ID_MEAS_POOR 0x0002
90# define ID_MEAS_SKIP 0x0004
91# define ID_MEAS_AREA 0x0008
92# define BLEND_IMAGE 0x0100
93# define BLEND_CATALOG 0x0200
94# define BLEND_IMAGE_NEIGHBOR 0x1000
95# define ID_MEAS_TRAIL 0x2000
96# define ID_MEAS_GHOST 0x4000
97
98/* some subtle distinctions between the blend flags:
99 BLEND_IMAGE: the star on an image is matched with more
100 than one star in the catalog (image has worse seeing than catalog)
101 BLEND_CATALOG: the star in the catalog is matched with more
102 than one star on the image (image has better seeing than catalog)
103 CALIBRATED: relative photometry has been performed on this measurement
104 BLEND_IMAGE_NEIGHBOR: the star on an image is matched with more
105 than one star in the catalog, but not in the same catalog file.
106*/
107
108/* Average.code values */
109# define ID_STAR_FEW 0x0001 /* used within relphot: skip star */
110# define ID_STAR_POOR 0x0002 /* used within relphot: skip star */
111# define ID_PROPER 0x0400 /* star with large proper motion */
112# define ID_TRANSIENT 0x1000 /* is this mutually exclusive with USNO? */
113# define ID_VARIABLE 0x2000 /* not currently set? */
114# define ID_ASTEROID 0x2000 /* identified with an asteroid */
115# define ID_BAD_OBJECT 0x4000 /* if all measurements are bad, set this bit */
116# define ID_MOVING 0x8000
117# define ID_ROCK 0xa000 /* 0x8000 + 0x2000 */
118# define ID_GHOST 0xc001 /* 0x8000 + 0x4000 + 0x0001 */
119# define ID_TRAIL 0xc002 /* 0x8000 + 0x4000 + 0x0002 */
120# define ID_BLEED 0xc003 /* 0x8000 + 0x4000 + 0x0003 */
121# define ID_COSMIC 0xc004 /* 0x8000 + 0x4000 + 0x0004 */
122
123/*** general dvo structures (internal use only / not IO) ***/
124
125/* FITS DB structure */
126typedef struct {
127 FILE *f;
128 char *filename;
129 int dbstate;
130 int lockstate;
131 double timeout;
132 Header header;
133 Matrix matrix;
134 Header theader;
135 FTable ftable;
136 VTable vtable;
137 int mode; /* what data storage mode is used for disk file? */
138 int format; /* what data format is used for disk file? */
139 int virtual; /* is table in ftable or vtable? */
140 int swapped; /* is table in internal byte-order? */
141} FITS_DB;
142
143/* the basic HST GSC layout corresponds to a depth of 3 */
144# define SKY_DEPTH_HST 3
145
146/* SkyRegion : better implementation than GSCRegion */
147typedef struct {
148 int Nregions;
149 char **filename;
150 SkyRegion *regions;
151} SkyTable;
152
153typedef struct {
154 int Nregions;
155 int ownElements; /* does this list own filename, regions? */
156 char **filename;
157 SkyRegion **regions;
158} SkyList;
159
160# if (0)
161/* structure for data on a catalog region */
162typedef struct {
163 char filename[256];
164 double DEC[2], RA[2];
165} GSCRegion;
166# endif
167
168typedef struct {
169 int Ncode; // number of photcodes
170 int Nsecfilt; // number of average magnitudes
171 int hashcode[0x10000]; // index from photcode value to sequence
172 int hashNsec[0x10000]; // index from photcode value to Nsec seq
173 int codeNsec[0x10000]; // index from Nsec seq to photcode value
174 PhotCode *code;
175} PhotCodeData;
176
177/* a catalog contains this data */
178typedef struct Catalog {
179 char *filename; /* catalog file */
180 FILE *f; /* file descriptor */
181 Header header;
182
183 /* data in the catalog file */
184 Average *average;
185 Measure *measure;
186 Missing *missing;
187 SecFilt *secfilt;
188 int Naverage, Nmeasure, Nmissing, Nsecfilt; /* current number of each component */
189 int Nave_disk, Nmeas_disk, Nmiss_disk; /* number of component on disk */
190 int Nmeas_off; /* dist seq of first loaded data value */
191 /* note the different counting for Nsecfilt */
192
193 /* pointers to split data files */
194 struct Catalog *measure_catalog; /* measure catalog data (split) */
195 struct Catalog *missing_catalog; /* missing catalog data (split) */
196 struct Catalog *secfilt_catalog; /* secfilt catalog data (split) */
197
198 /* extra catalog information */
199 int lockmode;
200 int catmode; /* storage mode (raw, mef, split, mysql) */
201 int catformat; /* storage format (elixir, panstarrs, etc) */
202 int catflags; /* choices to be loaded */
203 int sorted; /* is measure table average-sorted? */
204
205 /* pointers for data manipulation */
206 int *found;
207 int *image;
208 int *mosaic;
209 float *X;
210 float *Y;
211
212} Catalog;
213
214/*** prototypes ***/
215
216/* in gfits_db.c */
217int gfits_db_init PROTO((FITS_DB *db));
218int gfits_db_create PROTO((FITS_DB *db));
219int gfits_db_lock PROTO((FITS_DB *db, char *filename));
220int gfits_db_load PROTO((FITS_DB *db));
221int gfits_db_load_segment PROTO((FITS_DB *db, int start, int Nrows));
222int gfits_db_save PROTO((FITS_DB *db));
223int gfits_db_update PROTO((FITS_DB *db));
224int gfits_db_close PROTO((FITS_DB *db));
225int gfits_db_free PROTO((FITS_DB *db));
226
227/* in coords.c, using libautocode/def/coords.d */
228int XY_to_LM (double *L, double *M, double x, double y, Coords *coords);
229int LM_to_XY (double *x, double *y, double L, double M, Coords *coords);
230int RD_to_LM (double *L, double *M, double ra, double dec, Coords *coords);
231int LM_to_RD (double *ra, double *dec, double L, double M, Coords *coords);
232int XY_to_RD (double *ra, double *dec, double x, double y, Coords *coords);
233int RD_to_XY (double *x, double *y, double ra, double dec, Coords *coords);
234int fXY_to_RD (float *ra, float *dec, double x, double y, Coords *coords);
235int fRD_to_XY (float *x, float *y, double ra, double dec, Coords *coords);
236int GetCoords (Coords *coords, Header *header);
237int PutCoords (Coords *coords, Header *header);
238void RegisterMosaic (Coords *coords);
239void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
240OhanaProjection GetProjection (char *ctype);
241int SetProjection (char *ctype, OhanaProjection proj);
242OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
243
244char *libdvo_version ();
245
246int GetRegisteredMosaic ();
247int FindMosaicForImage (Image *images, int Nimages, int entry);
248int FindMosaicForImage_TableSearch (Image *images, int Nimages, int entry);
249int FindMosaicForImage_MatchSearch (Image *images, int Nimages, int entry);
250int BuildChipMatch (Image *images, int Nimages);
251void SetImageCorners (double *X, double *Y, Image *image);
252
253short int putMi (double value);
254double getMi (short int value);
255void returnMcal (Image *image, double *c);
256void assignMcal (Image *image, double *c, int order);
257double applyMcal (Image *image, double x, double y);
258double findscatter (double *X, double *Y, double *M, double *dM, int N, double *c, int order);
259
260PhotCode *GetPhotcodebyName (char *name);
261PhotCode *GetPhotcodeEquivbyName (char *name);
262PhotCode *GetPhotcodebyCode (int code);
263PhotCode *GetPhotcodebyNsec (int Nsec);
264PhotCode *GetPhotcodeEquivbyCode (int code);
265char *GetPhotcodeNamebyCode (int code);
266
267float PhotInst (Measure *measure);
268float PhotCat (Measure *measure);
269float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
270float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
271float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
272float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
273float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
274float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
275float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
276
277float PhotColorForCode (Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
278int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
279
280PhotCodeData *GetPhotcodeTable ();
281
282int LoadPhotcodes (char *catdir_file, char *master_file);
283int LoadPhotcodesText (char *filename);
284int LoadPhotcodesFITS (char *filename);
285int SavePhotcodesText (char *filename);
286int SavePhotcodesFITS (char *filename);
287
288void PrintPhotcodeNamebyCode (FILE *f, char *format, int code);
289
290int GetPhotcodeCodebyName (char *name);
291int GetPhotcodeEquivCodebyName (char *name);
292int GetPhotcodeEquivCodebyCode (int code);
293int GetPhotcodeNsec (int code);
294int GetPhotcodeNsecfilt ();
295void SetZeroPoint (double ZP);
296int *GetPhotcodeEquivList (int code, int *nlist);
297void ParseColorTerms (char *terms, float *X, int *N);
298
299int get_image_type (char *name);
300char *get_type_name (int type);
301int get_image_mode (char *name);
302char *get_mode_name (int mode);
303
304/* these functions refer to the DVO structures defined in the includes above
305 * they are being replaced with autocode entries (drop when totally autocoded)
306 */
307
308int Fread (void *ptr, int size, int nitems, FILE *f, char *type);
309int Fwrite (void *ptr, int size, int nitems, FILE *f, char *type);
310int ByteSwap (char *ptr, int size, int nitems, char *type);
311int ConvertStruct (char *buffer, int size, int Nbytes, char *type);
312
313/** dvo_catalog APIs */
314void dvo_catalog_init (Catalog *catalog, int complete);
315void dvo_catalog_create (SkyRegion *region, Catalog *catalog);
316void dvo_catalog_free (Catalog *catalog);
317int dvo_catalog_check (Catalog *catalog, int Nsecfilt, int extend);
318int dvo_catalog_lock (Catalog *catalog, int lockmode);
319int dvo_catalog_unlock (Catalog *catalog);
320int dvo_catalog_load (Catalog *catalog, int VERBOSE);
321int dvo_catalog_open (Catalog *catalog, SkyRegion *region, int VERBOSE, char *iomode);
322int dvo_catalog_save (Catalog *catalog, char VERBOSE);
323int dvo_catalog_update (Catalog *catalog, char VERBOSE);
324int dvo_catalog_catformat (char *catformat);
325int dvo_catalog_catmode (char *catmode);
326void dvo_catalog_test (Catalog *catalog, int halt);
327
328/* catmode-specific APIs */
329int dvo_catalog_load_raw (Catalog *catalog, int VERBOSE);
330int dvo_catalog_save_raw (Catalog *catalog, char VERBOSE);
331int dvo_catalog_load_mef (Catalog *catalog, int VERBOSE);
332int dvo_catalog_save_mef (Catalog *catalog, char VERBOSE);
333int dvo_catalog_load_split (Catalog *catalog, int VERBOSE);
334int dvo_catalog_save_split (Catalog *catalog, char VERBOSE);
335int dvo_catalog_update_split (Catalog *catalog, char VERBOSE);
336
337/*** conversion functions / I/O conversions ***/
338Average *ReadRawAverage (FILE *f, int Naverage, int format, SecFilt **primary);
339Measure *ReadRawMeasure (FILE *f, int Nmeasure, int format);
340SecFilt *ReadRawSecFilt (FILE *f, int Nsecfilt, int format);
341int WriteRawAverage (FILE *f, Average *average, int Naverage, int format, SecFilt *primary);
342int WriteRawMeasure (FILE *f, Measure *measure, int Nmeasure, int format);
343int WriteRawSecFilt (FILE *f, SecFilt *secfilt, int Nsecfilt, int format);
344
345Average *FtableToAverage (FTable *ftable, int *Naverage, int *format, SecFilt **primary);
346Measure *FtableToMeasure (FTable *ftable, int *Nmeasure, int *format);
347SecFilt *FtableToSecFilt (FTable *ftable, int *Nsecfilt, int *format);
348int FtableToImage (FTable *ftable, Header *theader, int *format);
349
350int AverageToFtable (FTable *ftable, Average *average, int Naverage, int format, SecFilt *primary);
351int MeasureToFtable (FTable *ftable, Measure *measure, int Nmeasure, int format);
352int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, int Nsecfilt, int format);
353int ImageToFtable (FTable *ftable, Header *theader, int format);
354int ImageToVtable (VTable *vtable, Header *theader, int format);
355
356Image *ImageElixirToInternal (ImageElixir *in, int Nvalues);
357Image *ImageLoneosToInternal (ImageLoneos *in, int Nvalues);
358Image *ImagePanstarrsToInternal (ImagePanstarrs *in, int Nvalues);
359Image *ImagePanstarrs_DEV_0_ToInternal (ImagePanstarrs_DEV_0 *in, int Nvalues);
360Image *ImagePanstarrs_DEV_1_ToInternal (ImagePanstarrs_DEV_1 *in, int Nvalues);
361
362ImageElixir *ImageInternalToElixir (Image *in, int Nvalues);
363ImageLoneos *ImageInternalToLoneos (Image *in, int Nvalues);
364ImagePanstarrs *ImageInternalToPanstarrs (Image *in, int Nvalues);
365ImagePanstarrs_DEV_0 *ImageInternalToPanstarrs_DEV_0 (Image *in, int Nvalues);
366ImagePanstarrs_DEV_1 *ImageInternalToPanstarrs_DEV_1 (Image *in, int Nvalues);
367
368Average *AverageLoneosToInternal (AverageLoneos *in, int Nvalues, SecFilt **primary);
369Average *AverageElixirToInternal (AverageElixir *in, int Nvalues, SecFilt **primary);
370Average *AveragePanstarrsToInternal (AveragePanstarrs *in, int Nvalues);
371Average *AveragePanstarrs_DEV_0_ToInternal (AveragePanstarrs_DEV_0 *in, int Nvalues);
372Average *AveragePanstarrs_DEV_1_ToInternal (AveragePanstarrs_DEV_1 *in, int Nvalues);
373
374AverageLoneos *AverageInternalToLoneos (Average *in, int Nvalues, SecFilt *primary);
375AverageElixir *AverageInternalToElixir (Average *in, int Nvalues, SecFilt *primary);
376AveragePanstarrs *AverageInternalToPanstarrs (Average *in, int Nvalues);
377AveragePanstarrs_DEV_0 *AverageInternalToPanstarrs_DEV_0 (Average *in, int Nvalues);
378AveragePanstarrs_DEV_1 *AverageInternalToPanstarrs_DEV_1 (Average *in, int Nvalues);
379
380Measure *MeasureLoneosToInternal (MeasureLoneos *in, int Nvalues);
381Measure *MeasureElixirToInternal (MeasureElixir *in, int Nvalues);
382Measure *MeasurePanstarrsToInternal (MeasurePanstarrs *in, int Nvalues);
383Measure *MeasurePanstarrs_DEV_0_ToInternal (MeasurePanstarrs_DEV_0 *in, int Nvalues);
384Measure *MeasurePanstarrs_DEV_1_ToInternal (MeasurePanstarrs_DEV_1 *in, int Nvalues);
385
386MeasureLoneos *MeasureInternalToLoneos (Measure *in, int Nvalues);
387MeasureElixir *MeasureInternalToElixir (Measure *in, int Nvalues);
388MeasurePanstarrs *MeasureInternalToPanstarrs (Measure *in, int Nvalues);
389MeasurePanstarrs_DEV_0 *MeasureInternalToPanstarrs_DEV_0 (Measure *in, int Nvalues);
390MeasurePanstarrs_DEV_1 *MeasureInternalToPanstarrs_DEV_1 (Measure *in, int Nvalues);
391
392SecFilt *SecFiltLoneosToInternal (SecFiltLoneos *in, int Nvalues);
393SecFilt *SecFiltElixirToInternal (SecFiltElixir *in, int Nvalues);
394SecFilt *SecFiltPanstarrsToInternal (SecFiltPanstarrs *in, int Nvalues);
395SecFilt *SecFiltPanstarrs_DEV_0_ToInternal (SecFiltPanstarrs_DEV_0 *in, int Nvalues);
396SecFilt *SecFiltPanstarrs_DEV_1_ToInternal (SecFiltPanstarrs_DEV_1 *in, int Nvalues);
397
398SecFiltLoneos *SecFiltInternalToLoneos (SecFilt *in, int Nvalues);
399SecFiltElixir *SecFiltInternalToElixir (SecFilt *in, int Nvalues);
400SecFiltPanstarrs *SecFiltInternalToPanstarrs (SecFilt *in, int Nvalues);
401SecFiltPanstarrs_DEV_0 *SecFiltInternalToPanstarrs_DEV_0 (SecFilt *in, int Nvalues);
402SecFiltPanstarrs_DEV_1 *SecFiltInternalToPanstarrs_DEV_1 (SecFilt *in, int Nvalues);
403
404/*** DVO image db I/O Functions ***/
405int dvo_image_lock (FITS_DB *db, char *filename, double timeout, int lockstate);
406int dvo_image_unlock (FITS_DB *db);
407int dvo_image_load (FITS_DB *db, int VERBOSE, int FORCE_READ);
408int dvo_image_save (FITS_DB *db, int VERBOSE);
409int dvo_image_update (FITS_DB *db, int VERBOSE);
410int dvo_image_load_raw (FITS_DB *db, int VERBOSE, int FORCE_READ);
411int dvo_image_update_raw (FITS_DB *db, int VERBOSE);
412int dvo_image_save_raw (FITS_DB *db, int VERBOSE);
413int dvo_image_addrows (FITS_DB *db, Image *new, int Nnew);
414void dvo_image_create (FITS_DB *db, double ZeroPoint);
415
416/* skyregion APIs */
417int SkyTableSave PROTO((SkyTable *table, char *filename));
418SkyTable *SkyTableLoad PROTO((char *filename, int VERBOSE));
419SkyTable *SkyTableFromGSC PROTO((char *filename, int depth, int VERBOSE));
420SkyTable *SkyTableLoadOptimal PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int depth, int VERBOSE));
421int SkyTableSetDepth PROTO((SkyTable *sky, int depth));
422SkyList *SkyRegionByPoint PROTO((SkyTable *table, int depth, double ra, double dec));
423SkyList *SkyListByPoint PROTO((SkyTable *table, double ra, double dec));
424SkyList *SkyListByRadius PROTO((SkyTable *table, int depth, double RA, double DEC, double radius));
425SkyList *SkyListByPatch PROTO((SkyTable *table, int depth, SkyRegion *patch));
426SkyList *SkyListByName PROTO((SkyTable *table, char *name));
427SkyList *SkyListByImage PROTO((SkyTable *table, int depth, Image *image));
428SkyList *SkyListByBounds PROTO((SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
429SkyList *SkyListChildrenByBounds PROTO((SkyTable *table, int No, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
430int SkyListMerge PROTO((SkyList **outlist, SkyList *newlist));
431int SkyListFree PROTO((SkyList *list));
432int SkyTableFree PROTO((SkyTable *table));
433int SkyListSetFilenames PROTO((SkyList *list, char *path, char *ext));
434int SkyTableSetFilenames PROTO((SkyTable *sky, char *path, char *ext));
435
436# endif