IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #900: dvo.2.h

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

replacement for previous dvo.h (good for ipp-2.2.0)

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 char **filename;
156 SkyRegion **regions;
157} SkyList;
158
159# if (0)
160/* structure for data on a catalog region */
161typedef struct {
162 char filename[256];
163 double DEC[2], RA[2];
164} GSCRegion;
165# endif
166
167typedef struct {
168 int Ncode; // number of photcodes
169 int Nsecfilt; // number of average magnitudes
170 int hashcode[0x10000]; // index from photcode value to sequence
171 int hashNsec[0x10000]; // index from photcode value to Nsec seq
172 int codeNsec[0x10000]; // index from Nsec seq to photcode value
173 PhotCode *code;
174} PhotCodeData;
175
176/* a catalog contains this data */
177typedef struct Catalog {
178 char *filename; /* catalog file */
179 FILE *f; /* file descriptor */
180 Header header;
181
182 /* data in the catalog file */
183 Average *average;
184 Measure *measure;
185 Missing *missing;
186 SecFilt *secfilt;
187 int Naverage, Nmeasure, Nmissing, Nsecfilt; /* current number of each component */
188 int Nave_disk, Nmeas_disk, Nmiss_disk; /* number of component on disk */
189 int Nmeas_off; /* dist seq of first loaded data value */
190 /* note the different counting for Nsecfilt */
191
192 /* pointers to split data files */
193 struct Catalog *measure_catalog; /* measure catalog data (split) */
194 struct Catalog *missing_catalog; /* missing catalog data (split) */
195 struct Catalog *secfilt_catalog; /* secfilt catalog data (split) */
196
197 /* extra catalog information */
198 int lockmode;
199 int catmode; /* storage mode (raw, mef, split, mysql) */
200 int catformat; /* storage format (elixir, panstarrs, etc) */
201 int catflags; /* choices to be loaded */
202 int sorted; /* is measure table average-sorted? */
203
204 /* pointers for data manipulation */
205 int *found;
206 int *image;
207 int *mosaic;
208 float *X;
209 float *Y;
210
211} Catalog;
212
213/*** prototypes ***/
214
215/* in gfits_db.c */
216int gfits_db_init PROTO((FITS_DB *db));
217int gfits_db_create PROTO((FITS_DB *db));
218int gfits_db_lock PROTO((FITS_DB *db, char *filename));
219int gfits_db_load PROTO((FITS_DB *db));
220int gfits_db_load_segment PROTO((FITS_DB *db, int start, int Nrows));
221int gfits_db_save PROTO((FITS_DB *db));
222int gfits_db_update PROTO((FITS_DB *db));
223int gfits_db_close PROTO((FITS_DB *db));
224int gfits_db_free PROTO((FITS_DB *db));
225
226/* in coords.c, using libautocode/def/coords.d */
227int XY_to_LM (double *L, double *M, double x, double y, Coords *coords);
228int LM_to_XY (double *x, double *y, double L, double M, Coords *coords);
229int RD_to_LM (double *L, double *M, double ra, double dec, Coords *coords);
230int LM_to_RD (double *ra, double *dec, double L, double M, Coords *coords);
231int XY_to_RD (double *ra, double *dec, double x, double y, Coords *coords);
232int RD_to_XY (double *x, double *y, double ra, double dec, Coords *coords);
233int fXY_to_RD (float *ra, float *dec, double x, double y, Coords *coords);
234int fRD_to_XY (float *x, float *y, double ra, double dec, Coords *coords);
235int GetCoords (Coords *coords, Header *header);
236int PutCoords (Coords *coords, Header *header);
237void RegisterMosaic (Coords *coords);
238void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
239OhanaProjection GetProjection (char *ctype);
240int SetProjection (char *ctype, OhanaProjection proj);
241OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
242
243char *libdvo_version ();
244
245int GetRegisteredMosaic ();
246int FindMosaicForImage (Image *images, int Nimages, int entry);
247int FindMosaicForImage_TableSearch (Image *images, int Nimages, int entry);
248int FindMosaicForImage_MatchSearch (Image *images, int Nimages, int entry);
249int BuildChipMatch (Image *images, int Nimages);
250void SetImageCorners (double *X, double *Y, Image *image);
251
252short int putMi (double value);
253double getMi (short int value);
254void returnMcal (Image *image, double *c);
255void assignMcal (Image *image, double *c, int order);
256double applyMcal (Image *image, double x, double y);
257double findscatter (double *X, double *Y, double *M, double *dM, int N, double *c, int order);
258
259PhotCode *GetPhotcodebyName (char *name);
260PhotCode *GetPhotcodeEquivbyName (char *name);
261PhotCode *GetPhotcodebyCode (int code);
262PhotCode *GetPhotcodebyNsec (int Nsec);
263PhotCode *GetPhotcodeEquivbyCode (int code);
264char *GetPhotcodeNamebyCode (int code);
265
266float PhotInst (Measure *measure);
267float PhotCat (Measure *measure);
268float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
269float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
270float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
271float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
272float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
273float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
274float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
275
276float PhotColorForCode (Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
277int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
278
279PhotCodeData *GetPhotcodeTable ();
280
281int LoadPhotcodes (char *catdir_file, char *master_file);
282int LoadPhotcodesText (char *filename);
283int LoadPhotcodesFITS (char *filename);
284int SavePhotcodesText (char *filename);
285int SavePhotcodesFITS (char *filename);
286
287void PrintPhotcodeNamebyCode (FILE *f, char *format, int code);
288
289int GetPhotcodeCodebyName (char *name);
290int GetPhotcodeEquivCodebyName (char *name);
291int GetPhotcodeEquivCodebyCode (int code);
292int GetPhotcodeNsec (int code);
293int GetPhotcodeNsecfilt ();
294void SetZeroPoint (double ZP);
295int *GetPhotcodeEquivList (int code, int *nlist);
296void ParseColorTerms (char *terms, float *X, int *N);
297
298int get_image_type (char *name);
299char *get_type_name (int type);
300int get_image_mode (char *name);
301char *get_mode_name (int mode);
302
303/* these functions refer to the DVO structures defined in the includes above
304 * they are being replaced with autocode entries (drop when totally autocoded)
305 */
306
307int Fread (void *ptr, int size, int nitems, FILE *f, char *type);
308int Fwrite (void *ptr, int size, int nitems, FILE *f, char *type);
309int ByteSwap (char *ptr, int size, int nitems, char *type);
310int ConvertStruct (char *buffer, int size, int Nbytes, char *type);
311
312/** dvo_catalog APIs */
313void dvo_catalog_init (Catalog *catalog, int complete);
314void dvo_catalog_create (SkyRegion *region, Catalog *catalog);
315void dvo_catalog_free (Catalog *catalog);
316int dvo_catalog_check (Catalog *catalog, int Nsecfilt, int extend);
317int dvo_catalog_lock (Catalog *catalog, int lockmode);
318int dvo_catalog_unlock (Catalog *catalog);
319int dvo_catalog_load (Catalog *catalog, int VERBOSE);
320int dvo_catalog_open (Catalog *catalog, SkyRegion *region, int VERBOSE, char *iomode);
321int dvo_catalog_save (Catalog *catalog, char VERBOSE);
322int dvo_catalog_update (Catalog *catalog, char VERBOSE);
323int dvo_catalog_catformat (char *catformat);
324int dvo_catalog_catmode (char *catmode);
325void dvo_catalog_test (Catalog *catalog, int halt);
326
327/* catmode-specific APIs */
328int dvo_catalog_load_raw (Catalog *catalog, int VERBOSE);
329int dvo_catalog_save_raw (Catalog *catalog, char VERBOSE);
330int dvo_catalog_load_mef (Catalog *catalog, int VERBOSE);
331int dvo_catalog_save_mef (Catalog *catalog, char VERBOSE);
332int dvo_catalog_load_split (Catalog *catalog, int VERBOSE);
333int dvo_catalog_save_split (Catalog *catalog, char VERBOSE);
334int dvo_catalog_update_split (Catalog *catalog, char VERBOSE);
335
336/*** conversion functions / I/O conversions ***/
337Average *ReadRawAverage (FILE *f, int Naverage, int format, SecFilt **primary);
338Measure *ReadRawMeasure (FILE *f, int Nmeasure, int format);
339SecFilt *ReadRawSecFilt (FILE *f, int Nsecfilt, int format);
340int WriteRawAverage (FILE *f, Average *average, int Naverage, int format, SecFilt *primary);
341int WriteRawMeasure (FILE *f, Measure *measure, int Nmeasure, int format);
342int WriteRawSecFilt (FILE *f, SecFilt *secfilt, int Nsecfilt, int format);
343
344Average *FtableToAverage (FTable *ftable, int *Naverage, int *format, SecFilt **primary);
345Measure *FtableToMeasure (FTable *ftable, int *Nmeasure, int *format);
346SecFilt *FtableToSecFilt (FTable *ftable, int *Nsecfilt, int *format);
347int FtableToImage (FTable *ftable, Header *theader, int *format);
348
349int AverageToFtable (FTable *ftable, Average *average, int Naverage, int format, SecFilt *primary);
350int MeasureToFtable (FTable *ftable, Measure *measure, int Nmeasure, int format);
351int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, int Nsecfilt, int format);
352int ImageToFtable (FTable *ftable, Header *theader, int format);
353int ImageToVtable (VTable *vtable, Header *theader, int format);
354
355Image *ImageElixirToInternal (ImageElixir *in, int Nvalues);
356Image *ImageLoneosToInternal (ImageLoneos *in, int Nvalues);
357Image *ImagePanstarrsToInternal (ImagePanstarrs *in, int Nvalues);
358Image *ImagePanstarrs_DEV_0_ToInternal (ImagePanstarrs_DEV_0 *in, int Nvalues);
359Image *ImagePanstarrs_DEV_1_ToInternal (ImagePanstarrs_DEV_1 *in, int Nvalues);
360
361ImageElixir *ImageInternalToElixir (Image *in, int Nvalues);
362ImageLoneos *ImageInternalToLoneos (Image *in, int Nvalues);
363ImagePanstarrs *ImageInternalToPanstarrs (Image *in, int Nvalues);
364ImagePanstarrs_DEV_0 *ImageInternalToPanstarrs_DEV_0 (Image *in, int Nvalues);
365ImagePanstarrs_DEV_1 *ImageInternalToPanstarrs_DEV_1 (Image *in, int Nvalues);
366
367Average *AverageLoneosToInternal (AverageLoneos *in, int Nvalues, SecFilt **primary);
368Average *AverageElixirToInternal (AverageElixir *in, int Nvalues, SecFilt **primary);
369Average *AveragePanstarrsToInternal (AveragePanstarrs *in, int Nvalues);
370Average *AveragePanstarrs_DEV_0_ToInternal (AveragePanstarrs_DEV_0 *in, int Nvalues);
371Average *AveragePanstarrs_DEV_1_ToInternal (AveragePanstarrs_DEV_1 *in, int Nvalues);
372
373AverageLoneos *AverageInternalToLoneos (Average *in, int Nvalues, SecFilt *primary);
374AverageElixir *AverageInternalToElixir (Average *in, int Nvalues, SecFilt *primary);
375AveragePanstarrs *AverageInternalToPanstarrs (Average *in, int Nvalues);
376AveragePanstarrs_DEV_0 *AverageInternalToPanstarrs_DEV_0 (Average *in, int Nvalues);
377AveragePanstarrs_DEV_1 *AverageInternalToPanstarrs_DEV_1 (Average *in, int Nvalues);
378
379Measure *MeasureLoneosToInternal (MeasureLoneos *in, int Nvalues);
380Measure *MeasureElixirToInternal (MeasureElixir *in, int Nvalues);
381Measure *MeasurePanstarrsToInternal (MeasurePanstarrs *in, int Nvalues);
382Measure *MeasurePanstarrs_DEV_0_ToInternal (MeasurePanstarrs_DEV_0 *in, int Nvalues);
383Measure *MeasurePanstarrs_DEV_1_ToInternal (MeasurePanstarrs_DEV_1 *in, int Nvalues);
384
385MeasureLoneos *MeasureInternalToLoneos (Measure *in, int Nvalues);
386MeasureElixir *MeasureInternalToElixir (Measure *in, int Nvalues);
387MeasurePanstarrs *MeasureInternalToPanstarrs (Measure *in, int Nvalues);
388MeasurePanstarrs_DEV_0 *MeasureInternalToPanstarrs_DEV_0 (Measure *in, int Nvalues);
389MeasurePanstarrs_DEV_1 *MeasureInternalToPanstarrs_DEV_1 (Measure *in, int Nvalues);
390
391SecFilt *SecFiltLoneosToInternal (SecFiltLoneos *in, int Nvalues);
392SecFilt *SecFiltElixirToInternal (SecFiltElixir *in, int Nvalues);
393SecFilt *SecFiltPanstarrsToInternal (SecFiltPanstarrs *in, int Nvalues);
394SecFilt *SecFiltPanstarrs_DEV_0_ToInternal (SecFiltPanstarrs_DEV_0 *in, int Nvalues);
395SecFilt *SecFiltPanstarrs_DEV_1_ToInternal (SecFiltPanstarrs_DEV_1 *in, int Nvalues);
396
397SecFiltLoneos *SecFiltInternalToLoneos (SecFilt *in, int Nvalues);
398SecFiltElixir *SecFiltInternalToElixir (SecFilt *in, int Nvalues);
399SecFiltPanstarrs *SecFiltInternalToPanstarrs (SecFilt *in, int Nvalues);
400SecFiltPanstarrs_DEV_0 *SecFiltInternalToPanstarrs_DEV_0 (SecFilt *in, int Nvalues);
401SecFiltPanstarrs_DEV_1 *SecFiltInternalToPanstarrs_DEV_1 (SecFilt *in, int Nvalues);
402
403/*** DVO image db I/O Functions ***/
404int dvo_image_lock (FITS_DB *db, char *filename, double timeout, int lockstate);
405int dvo_image_unlock (FITS_DB *db);
406int dvo_image_load (FITS_DB *db, int VERBOSE, int FORCE_READ);
407int dvo_image_save (FITS_DB *db, int VERBOSE);
408int dvo_image_update (FITS_DB *db, int VERBOSE);
409int dvo_image_load_raw (FITS_DB *db, int VERBOSE, int FORCE_READ);
410int dvo_image_update_raw (FITS_DB *db, int VERBOSE);
411int dvo_image_save_raw (FITS_DB *db, int VERBOSE);
412int dvo_image_addrows (FITS_DB *db, Image *new, int Nnew);
413void dvo_image_create (FITS_DB *db, double ZeroPoint);
414
415/* skyregion APIs */
416int SkyTableSave PROTO((SkyTable *table, char *filename));
417SkyTable *SkyTableLoad PROTO((char *filename, int VERBOSE));
418SkyTable *SkyTableFromGSC PROTO((char *filename, int depth, int VERBOSE));
419SkyTable *SkyTableLoadOptimal PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int depth, int VERBOSE));
420int SkyTableSetDepth PROTO((SkyTable *sky, int depth));
421SkyList *SkyRegionByPoint PROTO((SkyTable *table, int depth, double ra, double dec));
422SkyList *SkyListByPoint PROTO((SkyTable *table, double ra, double dec));
423SkyList *SkyListByRadius PROTO((SkyTable *table, int depth, double RA, double DEC, double radius));
424SkyList *SkyListByPatch PROTO((SkyTable *table, int depth, SkyRegion *patch));
425SkyList *SkyListByName PROTO((SkyTable *table, char *name));
426SkyList *SkyListByImage PROTO((SkyTable *table, int depth, Image *image));
427SkyList *SkyListByBounds PROTO((SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
428SkyList *SkyListChildrenByBounds PROTO((SkyTable *table, int No, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
429int SkyListMerge PROTO((SkyList **outlist, SkyList *newlist));
430int SkyListFree PROTO((SkyList *list, int ELEMENTS));
431int SkyTableFree PROTO((SkyTable *table));
432int SkyListSetFilenames PROTO((SkyList *list, char *path, char *ext));
433int SkyTableSetFilenames PROTO((SkyTable *sky, char *path, char *ext));
434
435# endif