Index: trunk/Ohana/src/libohana/include/dvo.h
===================================================================
--- trunk/Ohana/src/libohana/include/dvo.h	(revision 4026)
+++ trunk/Ohana/src/libohana/include/dvo.h	(revision 4500)
@@ -4,50 +4,5 @@
 # define DVO_H
 
-/*** FITS DB structure  ***/
-typedef struct {
-  FILE  *f;
-  char  *filename;
-  int    dbstate;
-  int    lockstate;
-  double timeout;
-  Header header;
-  Matrix matrix;
-  Header theader;
-  FTable ftable;
-} FITS_DB;
-
-# if (0)
-/* the standard astrometric coordinates structure */
-typedef struct {
-  double   crval1, crval2;
-  float    crpix1, crpix2;
-  float    cdelt1, cdelt2;
-  float    pc1_1, pc1_2;
-  float    pc2_1, pc2_2;
-  float    polyterms[7][2];
-  char     ctype[15];
-  char     Npolyterms;
-} Coords;  /* 120 bytes / Coords */
-# endif
-
-/* in fits_db.c */
-int   fits_db_init                PROTO((FITS_DB *db));
-int   fits_db_create              PROTO((FITS_DB *db));
-int   fits_db_lock                PROTO((FITS_DB *db, char *filename));
-int   fits_db_load                PROTO((FITS_DB *db));
-int   fits_db_close               PROTO((FITS_DB *db));
-int   fits_db_free                PROTO((FITS_DB *db));
-int   fits_db_save                PROTO((FITS_DB *db));
-int   fits_db_update              PROTO((FITS_DB *db, VTable *vtable));
-
-/* in coords.c, using libautocode/def/coords.d */
-int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
-int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
-int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
-int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
-int  GetCoords (Coords *coords, Header *header);
-int  PutCoords (Coords *coords, Header *header);
-void RegisterMosaic (Coords *coords);
-void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
+/*** named data values (convert all to enums?) ***/
 
 /* image data modes in RegImage */
@@ -55,5 +10,4 @@
 enum {M_UNDEF = -1, M_NONE, M_MEF, M_SPLIT, M_SINGLE, M_CUBE, M_SLICE, M_MODES, N_MODE};
 
-/* convert these to enums? */
 /* RegImage.flag values */
 # define IMREG_DIST  0x01 /* image distributed, only imregister-3.0 */
@@ -93,4 +47,14 @@
 # define ID_MEAS_TRAIL        0x2000
 # define ID_MEAS_GHOST        0x4000
+
+/* some subtle distinctions between the blend flags:
+   BLEND_IMAGE: the star on an image is matched with more 
+      than one star in the catalog (image has worse seeing than catalog)
+   BLEND_CATALOG: the star in the catalog is matched with more 
+      than one star on the image (image has better seeing than catalog)
+   CALIBRATED: relative photometry has been performed on this measurement
+   BLEND_IMAGE_NEIGHBOR: the star on an image is matched with more 
+      than one star in the catalog, but not in the same catalog file.
+*/
 
 /* Average.code values */
@@ -109,35 +73,141 @@
 # define ID_COSMIC     0xc004 /* 0x8000 + 0x4000 + 0x0004 */ 
 
-/* 
-   BLEND_IMAGE: the star on an image is matched with more 
-      than one star in the catalog (image has worse seeing than catalog)
-   BLEND_CATALOG: the star in the catalog is matched with more 
-      than one star on the image (image has better seeing than catalog)
-   CALIBRATED: relative photometry has been performed on this measurement
-   BLEND_IMAGE_NEIGHBOR: the star on an image is matched with more 
-      than one star in the catalog, but not in the same catalog file.
-*/
-
-/** we are going to replace these with autocode and appropriate conversions 
-    for now, choose the appropriate table version **/
-
-# define ELIXIR    1
-# define LONEOS    0
-# define PANSTARRS 0
-
-# if (LONEOS)
-# include <loneos.h>
-# endif
-
-# if (ELIXIR)
-# include <elixir.h>
-# endif
-
-# if (PANSTARRS)
-# include <panstarrs.h>
-# endif
-
-/* these functions refer to the DVO structures defined in the includes above 
- *  they are being replaced with autocode entries
+/*** general dvo structures (internal use only / not IO) ***/
+
+/* FITS DB structure */
+typedef struct {
+  FILE  *f;
+  char  *filename;
+  int    dbstate;
+  int    lockstate;
+  double timeout;
+  Header header;
+  Matrix matrix;
+  Header theader;
+  FTable ftable;
+} FITS_DB;
+
+/* structure for data on a catalog region */
+typedef struct {
+  char filename[256];
+  double DEC[2], RA[2];
+} GSCRegion;
+
+typedef struct {
+  int Ncode;
+  int Nsecfilt;
+  int hashcode[0x10000];
+  int hashNsec[0x10000];
+  PhotCode *code;
+} PhotCodeData;
+
+/* a catalog contains this data */
+typedef struct {
+  /* data in the file: */
+  Average *average;
+  Measure *measure; 
+  Missing *missing; 
+  SecFilt *secfilt;
+  Header  header;
+  int Naverage, Nmeasure, Nmissing, Nsecfilt;
+  /* description of the catalog file: */
+  char *filename;
+  int lockmode;
+  FILE *f;
+  /* pointers for data manipulation */
+  int *found;
+  int *image;
+  int *mosaic;
+  float *X;
+  float *Y;
+} Catalog;
+
+/*** prototypes ***/
+
+/* in fits_db.c */
+int   fits_db_init                PROTO((FITS_DB *db));
+int   fits_db_create              PROTO((FITS_DB *db));
+int   fits_db_lock                PROTO((FITS_DB *db, char *filename));
+int   fits_db_load                PROTO((FITS_DB *db));
+int   fits_db_close               PROTO((FITS_DB *db));
+int   fits_db_free                PROTO((FITS_DB *db));
+int   fits_db_save                PROTO((FITS_DB *db));
+int   fits_db_update              PROTO((FITS_DB *db, VTable *vtable));
+
+/* in coords.c, using libautocode/def/coords.d */
+int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
+int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
+int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
+int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
+int  GetCoords (Coords *coords, Header *header);
+int  PutCoords (Coords *coords, Header *header);
+void RegisterMosaic (Coords *coords);
+void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
+
+int lock_catalog (Catalog *catalog, int lockmode);
+int unlock_catalog (Catalog *catalog);
+int load_catalog (Catalog *catalog, char mode, int VERBOSE);
+int save_catalog (Catalog *catalog, char VERBOSE);
+
+int FindMosaicForImage (Image *images, int Nimages, int entry);
+int FindMosaicForImage_TableSearch (Image *images, int Nimages, int entry);
+int FindMosaicForImage_MatchSearch (Image *images, int Nimages, int entry);
+int BuildChipMatch (Image *images, int Nimages);
+
+short int putMi (double value);
+double getMi (short int value);
+void returnMcal (Image *image, double *c);
+void assignMcal (Image *image, double *c, int order);
+double applyMcal (Image *image, double x, double y);
+double findscatter (double *X, double *Y, double *M, double *dM, int N, double *c, int order);
+
+PhotCode *GetPhotcodebyName (char *name);
+PhotCode *GetPhotcodeEquivbyName (char *name);
+PhotCode *GetPhotcodebyCode (int code);
+PhotCode *GetPhotcodeEquivbyCode (int code);
+char *GetPhotcodeNamebyCode (int code);
+
+double PhotInst (Measure *measure);
+double PhotAbs (Measure *measure);
+double PhotCat (Measure *measure);
+double PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
+double PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
+double PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
+double PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
+double PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
+double PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
+double PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
+
+short iPhotInst (Measure *measure);
+short iPhotAbs (Measure *measure);
+short iPhotCat (Measure *measure);
+short iPhotSys (Measure *measure, Average *average, SecFilt *secfilt);
+short iPhotRel (Measure *measure, Average *average, SecFilt *secfilt);
+short iPhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
+short iPhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
+short iPhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
+short iPhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
+short iPhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
+
+short iPhotColor (Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
+int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
+
+int LoadPhotcodes (char *filename);
+int GetPhotcodeCodebyName (char *name);
+int GetPhotcodeEquivCodebyName (char *name);
+int GetPhotcodeEquivCodebyCode (int code);
+int GetPhotcodeNsec (int code);
+int GetPhotcodeNsecfilt ();
+void SetZeroPoint (double ZP);
+int *GetPhotcodeEquivList (int code, int *nlist);
+void ParseColorTerms (char *terms, float *X, int *N);
+
+int get_image_type (char *name);
+char *get_type_name (int type);
+int get_image_mode (char *name);
+char *get_mode_name (int mode);
+
+/* these functions refer to the DVO structures defined in the includes above
+ *  they are being replaced with autocode entries (drop when totally autocoded)
  */
 
