Index: /branches/libautocode-1-7/Ohana/src/libautocode/.cvsignore
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/.cvsignore	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/.cvsignore	(revision 11885)
@@ -0,0 +1,4 @@
+include
+lib
+src
+tex
Index: /branches/libautocode-1-7/Ohana/src/libautocode/Makefile
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/Makefile	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/Makefile	(revision 11885)
@@ -0,0 +1,75 @@
+default: autocode
+help:
+	@echo "make options: install autocode latex objects"
+
+include ../../Configure
+HOME	=	$(ROOT)/src/libautocode
+BIN	=	$(HOME)/bin
+LIB	=	$(HOME)/lib
+SRC	=	$(HOME)/src
+MAN	= 	$(HOME)/doc
+DEF	=	$(HOME)/def
+TEX	=	$(HOME)/tex
+INC	=	$(HOME)/include
+ASRC    =       $(SRC)
+AINC    =       $(INC)
+include ../../Makefile.Common
+
+# programs may add their own internal requirements here
+FULL_CFLAGS   = $(BASE_CFLAGS) -fPIC
+FULL_CPPFLAGS = $(BASE_CPPFLAGS)
+FULL_LDFLAGS  = $(BASE_LDFLAGS)
+
+latex:    $(LIBTEX)
+objects:  $(AOBJS)
+install:  $(DESTINC)/autocode.h $(DESTLIB)/libautocode.a $(DESTLIB)/libautocode.so
+autocode: $(INC)/autocode.h $(LIB)/libautocode.$(ARCH).a $(LIB)/libautocode.$(ARCH).so
+
+# this library is not normally installed: the objects in the
+# file included below are rolled into libdvo 
+include Makefile.Targets
+
+LIBTEX = \
+$(TEX)/coords.tex \
+$(TEX)/average.tex \
+$(TEX)/secfilt.tex \
+$(TEX)/measure.tex \
+$(TEX)/missing.tex \
+$(TEX)/photcode.tex \
+$(TEX)/image.tex 
+
+$(LIB)/libautocode.$(ARCH).a: $(AOBJS)
+$(LIB)/libautocode.$(ARCH).so: $(AOBJS)
+
+$(DESTLIB)/libautocode.a:  $(LIB)/libautocode.$(ARCH).a
+$(DESTLIB)/libautocode.so: $(LIB)/libautocode.$(ARCH).so
+
+$(AOBJS): $(INC)/autocode.h
+
+$(INC)/autocode.h: $(AINCS) $(DEF)/common.h
+	cat $(DEF)/common.h >  $(INC)/autocode.h
+	cat $(AINCS)        >> $(INC)/autocode.h
+	@echo "# endif"     >> $(INC)/autocode.h
+	@echo done with autocode.h
+
+$(TEX)/%.tex: $(DEF)/%.d $(DEF)/autocode.tex
+	@if [ ! -d $(TEX) ]; then mkdir -p $(TEX); fi
+	./generate $< $(DEF)/autocode.tex $@
+
+$(INC)/%.h: $(DEF)/%.d $(DEF)/autocode.h
+	@if [ ! -d $(INC) ]; then mkdir -p $(INC); fi
+	./generate $< $(DEF)/autocode.h $@
+
+$(SRC)/%.c: $(DEF)/%.d $(DEF)/autocode.c
+	@if [ ! -d $(SRC) ]; then mkdir -p $(SRC); fi
+	./generate $< $(DEF)/autocode.c $@
+
+clean:	cleandef
+cleandef:
+	rm -f `find src -name "*.c"`
+	rm -f `find include -name "*.h"`
+# 	this is an unusual target!  it deletes .c and .h files!
+
+.PRECIOUS: $(SRC)/%.c
+.PRECIOUS: $(LIB)/%.$(ARCH).a
+.PRECIOUS: $(LIB)/%.$(ARCH).so
Index: /branches/libautocode-1-7/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/Makefile.Targets	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/Makefile.Targets	(revision 11885)
@@ -0,0 +1,66 @@
+
+AOBJS = \
+$(ASRC)/coords.$(ARCH).o \
+$(ASRC)/average.$(ARCH).o \
+$(ASRC)/average-loneos.$(ARCH).o \
+$(ASRC)/average-elixir.$(ARCH).o \
+$(ASRC)/average-panstarrs.$(ARCH).o \
+$(ASRC)/average-pmtest.$(ARCH).o \
+$(ASRC)/secfilt.$(ARCH).o \
+$(ASRC)/secfilt-loneos.$(ARCH).o \
+$(ASRC)/secfilt-elixir.$(ARCH).o \
+$(ASRC)/secfilt-panstarrs.$(ARCH).o \
+$(ASRC)/measure.$(ARCH).o \
+$(ASRC)/measure-loneos.$(ARCH).o \
+$(ASRC)/measure-elixir.$(ARCH).o \
+$(ASRC)/measure-panstarrs.$(ARCH).o \
+$(ASRC)/missing.$(ARCH).o \
+$(ASRC)/photcode.$(ARCH).o \
+$(ASRC)/image.$(ARCH).o \
+$(ASRC)/image-loneos.$(ARCH).o \
+$(ASRC)/image-elixir.$(ARCH).o \
+$(ASRC)/image-panstarrs.$(ARCH).o \
+$(ASRC)/regimage.$(ARCH).o \
+$(ASRC)/detreg.$(ARCH).o \
+$(ASRC)/photreg.$(ARCH).o \
+$(ASRC)/photreg-old.$(ARCH).o \
+$(ASRC)/smpdata.$(ARCH).o \
+$(ASRC)/spectrum.$(ARCH).o \
+$(ASRC)/spectrum-ascii.$(ARCH).o \
+$(ASRC)/Stars.$(ARCH).o \
+$(ASRC)/GSCRegion.$(ARCH).o \
+$(ASRC)/AddstarClientOptions.$(ARCH).o \
+$(ASRC)/SkyRegion.$(ARCH).o
+
+AINCS = \
+$(AINC)/coords.h \
+$(AINC)/average.h \
+$(AINC)/average-loneos.h \
+$(AINC)/average-elixir.h \
+$(AINC)/average-panstarrs.h \
+$(AINC)/average-pmtest.h \
+$(AINC)/secfilt.h \
+$(AINC)/secfilt-loneos.h \
+$(AINC)/secfilt-elixir.h \
+$(AINC)/secfilt-panstarrs.h \
+$(AINC)/measure.h \
+$(AINC)/measure-loneos.h \
+$(AINC)/measure-elixir.h \
+$(AINC)/measure-panstarrs.h \
+$(AINC)/missing.h \
+$(AINC)/photcode.h \
+$(AINC)/image.h \
+$(AINC)/image-loneos.h \
+$(AINC)/image-elixir.h \
+$(AINC)/image-panstarrs.h \
+$(AINC)/regimage.h \
+$(AINC)/detreg.h \
+$(AINC)/photreg.h \
+$(AINC)/photreg-old.h \
+$(AINC)/smpdata.h \
+$(AINC)/spectrum.h \
+$(AINC)/spectrum-ascii.h \
+$(AINC)/Stars.h \
+$(AINC)/GSCRegion.h \
+$(AINC)/AddstarClientOptions.h \
+$(AINC)/SkyRegion.h
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/AddstarClientOptions.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/AddstarClientOptions.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/AddstarClientOptions.d	(revision 11885)
@@ -0,0 +1,21 @@
+STRUCT  AddstarClientOptions
+EXTNAME OPTIONS
+TYPE    BINTABLE
+SIZE    72
+
+FIELD     Nsigma,           NSIGMA,               double,         match radius in terms of astrometric error 
+FIELD     radius,           RADIUS,		  double,         match radius in arcsec (default)
+FIELD  	  mode,             MODE,                 int,            data source mode
+FIELD  	  existing_regions, EXISTING_REGIONS,     int,            use only existing regions
+FIELD  	  only_match,       ONLY_MATCH,           int,            only update matched stars
+FIELD  	  skip_missed,      SKIP_MISSED,          int,            .
+FIELD  	  replace,          REPLACE,              int,            .
+FIELD  	  closest,          CLOSEST,              int,            .
+FIELD  	  nosort,           NOSORT,               int,            .
+FIELD  	  update,           UPDATE,               int,            .
+FIELD  	  only_images,      ONLY_IMAGES,          int,            .
+FIELD  	  calibrate,        CALIBRATE,            int,            .
+FIELD  	  quality_airmass,  HQ_AIRMASS,           int,            use high-quality airmass?
+FIELD  	  mosaic,           MOSAIC,               int,            does this image require a mosaic coordinate system?
+FIELD  	  photcode,         PHOTCODE,             int,     	  photocode of input data
+FIELD  	  timeref,          TIMEREF,              e_time,  	  time/date of input data (REFLIST only?)
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/GSCRegion.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/GSCRegion.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/GSCRegion.d	(revision 11885)
@@ -0,0 +1,8 @@
+STRUCT  GSCRegion
+EXTNAME OPTIONS
+TYPE    BINTABLE
+SIZE    288
+
+FIELD   filename,   FILENAME,   char[256],   catalog filename
+FIELD   DEC,        DEC,        double[2],   Dec boundaries
+FIELD   RA,         DEC,        double[2],   RA boundaries
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/SkyRegion.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/SkyRegion.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/SkyRegion.d	(revision 11885)
@@ -0,0 +1,17 @@
+STRUCT  SkyRegion
+EXTNAME SKY_REGION
+TYPE    BINTABLE
+SIZE    56
+
+FIELD   Rmin,	   R_MIN,	   float, 
+FIELD   Rmax,	   R_MAX,	   float, 
+FIELD   Dmin,	   D_MIN,	   float, 
+FIELD   Dmax,	   D_MAX,	   float, 
+FIELD   childS,	   CHILD_S,	   int,           sequence number in full table of first child
+FIELD   childE,	   CHILD_E,	   int,           sequence number in full table of last child + 1
+FIELD   parent,	   PARENT,	   int,           sequence number in full table of parent
+FIELD   index,     INDEX,          int,           sequence number in full table of this entry
+FIELD   depth,	   DEPTH,	   char,          depth of this entry
+FIELD   child,	   CHILD,	   char,          does this entry have children?
+FIELD   table,	   TABLE,	   char,          does this entry have a table?
+FIELD   name,      NAME,           char[21],      name / filename
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/Stars.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/Stars.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/Stars.d	(revision 11885)
@@ -0,0 +1,38 @@
+STRUCT  Stars
+EXTNAME STARS
+TYPE    BINTABLE
+SIZE    188
+
+FIELD     X,                X,          double,    x coordinate on image,	     pixels
+FIELD     Y,                Y,          double,    y coordinate on image,	     pixels
+FIELD     R,                R,          double,    ra coordinate on sky,	     decimal degrees
+FIELD     D,                D,          double,    dec coordinate on sky,	     decimal degrees
+FIELD     dR,               dR,         double,    ra error,			     arcsec
+FIELD     dD,               dD,         double,    dec error,			     arcsec
+FIELD     uR,               U_RA,       double,    proper motion in RA,		     milliarcsec/year
+FIELD     uD,               U_DEC,      double,    proper motion in DEC,	     milliarcsec/year
+FIELD     duR,              U_RA_ERR,   double,    p-m error in RA,		     milliarcsec/year
+FIELD     duD,              U_DEC_ERR,  double,    p-m error in DEC,		     milliarcsec/year
+FIELD     P,                PAR,        double,    parallax,			     milliarcsec
+FIELD     dP,               PAR_ERR,    double,    parallax error,		     milliarcsec
+FIELD     M,                M,          double,    instrumental mag
+FIELD     dM,               DM,         double,    error on mag
+FIELD     sky,              SKY,        double,    local sky counts
+FIELD     fx,               FX,         double,    object FWHM x-dir,		     pixels?
+FIELD     fy,               FY,         double,    object FWHM y-dir,		     pixels?
+FIELD     df,               DF,         double,    object position angle,	     degrees
+FIELD     Mgal,             MGAL,       double,    alternative (galaxy) magnitude
+FIELD     Map,              MAP,        double,    alternative (aperture) magnitude
+FIELD     found,            FOUND,      int,       found in database catalog?
+FIELD     t,                T,          e_time,    date/time of exposure (UNIX)
+FIELD     dt,               EXPTIME,    float,     exposure time,                    2.5*log(exptime)
+FIELD     code,             CODE,       short,     .
+FIELD     dophot,           DOPHOT,     char,      dophot type code
+FIELD     dummy,            DUMMY,      char[5],   .
+FIELD     Mcal,             MCAL,       float,     image cal mag,	             mag
+FIELD     airmass,          AIRMASS,    float,     (airmass - 1),		     airmass
+
+# this structure is only used internally and for interprocess communication (addstar)
+# dR, uR, etc should be better defined at the pole...
+# define down the types to floats where reasonable (all but R,D)?
+# R,D should be in ICRS, J2000, epoch 2000 : precess as needed, apply p-m as needed
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.c
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.c	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.c	(revision 11885)
@@ -0,0 +1,124 @@
+# include "autocode.h"
+
+int gfits_convert_$STRUCT ($STRUCT *data, int size, int nitems) {
+
+  int i;
+  unsigned char *byte, tmp;
+
+  if (size != $SIZE) { 
+    fprintf (stderr, "ERROR: mismatch in data types $STRUCT: %d vs %d\n",
+	     size, $SIZE);
+    exit (1);
+  }
+
+  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
+  i = tmp = 0;
+  byte = NULL;
+
+# ifdef BYTE_SWAP
+  byte = (unsigned char *) data;
+  for (i = 0; i < nitems; i++, byte += $SIZE) {
+    /** BYTE SWAP **/
+  }
+# endif  
+
+  return (TRUE);
+} 
+
+/*** add test of EXTNAME and header-defined columns? ***/
+/* return internal structure representation */
+$STRUCT *gfits_table_get_$STRUCT (FTable *ftable, int *Ndata, int *swapped) {
+
+  $STRUCT *data;
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  data = ($STRUCT *) ftable[0].buffer;
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+    gfits_convert_$STRUCT (data, sizeof ($STRUCT), *Ndata);
+    if (swapped != NULL) *swapped = TRUE;
+  }
+  return (data);
+}
+
+int gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, int Ndata) {
+
+  Header *header;
+
+  header = ftable[0].header;
+
+  /* create table header */
+  gfits_create_table_header (header, "$TYPE", "$EXTNAME");
+
+  /* define table layout */
+  /** TABLE DEFINITION **/
+
+  /* create table */
+  gfits_create_table (header, ftable);
+
+  /* add data values */
+  gfits_convert_$STRUCT (data, sizeof ($STRUCT), Ndata);
+  gfits_add_rows (ftable, (char *) data, Ndata, sizeof ($STRUCT));
+
+  return (TRUE);
+}
+
+int gfits_table_mkheader_$STRUCT (Header *header) {
+
+  /* create table header */
+  gfits_create_table_header (header, "$TYPE", "$EXTNAME");
+
+  /* define table layout */
+  /** TABLE DEFINITION **/
+
+  return (TRUE);
+}
+
+int Send_$STRUCT (int device, $STRUCT *data, int Ndata, int copy) {
+
+  int Nbytes;
+  $STRUCT *tmpdata;
+
+  Nbytes = Ndata * sizeof ($STRUCT);
+
+  if (copy) {
+    ALLOCATE (tmpdata, $STRUCT, Ndata);
+    memcpy (tmpdata, data, Nbytes);
+  } else {
+    tmpdata = data;
+  }
+
+  gfits_convert_$STRUCT (tmpdata, sizeof ($STRUCT), Ndata);
+
+  SendCommand (device, 16, "NVALUE: %6d", Ndata);
+  SendCommand (device, 16, "NBYTES: %6d", Nbytes);
+  write (device, tmpdata, Nbytes);
+  
+  /* perform handshaking? */
+
+  return (TRUE);
+}
+
+int Recv_$STRUCT (int device, $STRUCT **data, int *Ndata) {
+
+  int ndata;
+  IOBuffer message;
+  $STRUCT *tmpdata;
+
+  ExpectCommand (device, 16, 1.0, &message);
+  sscanf (message.buffer, "%*s %d", &ndata);
+  FreeIOBuffer (&message);
+  
+  /* what is reasonable for timeout? */
+  ExpectMessage (device, 1.0, &message);
+  
+  tmpdata = ($STRUCT *) message.buffer;
+  gfits_convert_$STRUCT (tmpdata, sizeof ($STRUCT), ndata);
+
+  /* double-check data length? */
+  /* perform handshaking? */
+
+  *Ndata = ndata;
+  *data = tmpdata;
+
+  return (TRUE);
+}
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.h
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.h	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.h	(revision 11885)
@@ -0,0 +1,9 @@
+
+/** STRUCT DEFINITION **/
+
+$STRUCT *gfits_table_get_$STRUCT (FTable *table, int *Ndata, int *swapped);
+int      gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, int Ndata);
+int      gfits_table_mkheader_$STRUCT (Header *header);
+int      gfits_convert_$STRUCT ($STRUCT *data, int size, int nitems);
+int Send_$STRUCT (int device, $STRUCT *data, int Ndata, int copy);
+int Recv_$STRUCT (int device, $STRUCT **data, int *Ndata);
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.tex
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.tex	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/autocode.tex	(revision 11885)
@@ -0,0 +1,13 @@
+
+\begin{table}[h]
+\begin{center}
+\caption{\label{$STRUCT} $DESCRIPTION (EXTNAME: {\tt $STRUCT})}
+\begin{tabular}{|l|l|l|l|}
+\hline
+name        & type           & description                 & units \\
+\hline
+%%% LATEX TABLE DEFINITION 
+\hline
+\end{tabular}
+\end{center}
+\end{table}
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/average-elixir.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/average-elixir.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/average-elixir.d	(revision 11885)
@@ -0,0 +1,19 @@
+STRUCT  AverageElixir
+EXTNAME DVO_AVERAGE_ELIXIR
+TYPE    BINTABLE
+SIZE    32
+
+# elements of data structure / FITS table
+
+FIELD R,              RA,         float,            RA,                	       	  decimal degrees 
+FIELD D,              DEC,        float,            DEC,               	       	  decimal degrees 
+FIELD M,              MAG,        short,            primary mag,       	       	  millimag
+FIELD Nm,             NMEAS,      unsigned short,   number of measures
+FIELD Nn,             NMISS,      unsigned short,   number of missings
+FIELD Xp,             SIGMA_POS,  short, 	    position scatter,   	  1/100 arcsec
+FIELD Xm,             CHISQ_MAG,  short, 	    chisq for primary mag,        [100*log(value)]  ?
+FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
+FIELD offset,         offset,     int,     	    offset to first measurement
+FIELD missing,        missing,    int,     	    offset to first missing obs
+FIELD dM,             MAG_ERR,    short,            error on primary mag,         millimag
+FIELD Xg,             Xg,         short,            best chisq value
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/average-loneos.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/average-loneos.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/average-loneos.d	(revision 11885)
@@ -0,0 +1,17 @@
+STRUCT  AverageLoneos
+EXTNAME DVO_AVERAGE_LONEOS
+TYPE    BINTABLE
+SIZE    28
+
+# elements of data structure / FITS table
+
+FIELD R,              RA,         float,            RA,                	       	  decimal degrees 
+FIELD D,              DEC,        float,            DEC,               	       	  decimal degrees 
+FIELD M,              MAG,        short,            primary mag,       	       	  millimag
+FIELD Nm,             NMEAS,      unsigned short,   number of measures
+FIELD Nn,             NMISS,      unsigned short,   number of missings
+FIELD Xp,             SIGMA_POS,  short, 	    position scatter,   	  1/100 arcsec
+FIELD Xm,             CHISQ_MAG,  short, 	    chisq for primary mag,        [1000*value]  ?
+FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
+FIELD offset,         offset,     int,     	    offset to first measurement
+FIELD missing,        missing,    int,     	    offset to first missing obs
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/average-panstarrs.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/average-panstarrs.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/average-panstarrs.d	(revision 11885)
@@ -0,0 +1,22 @@
+STRUCT  AveragePanstarrs
+EXTNAME DVO_AVERAGE_PANSTARRS
+TYPE    BINTABLE
+SIZE    48
+
+# elements of data structure / FITS table
+
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD M,              MAG,        float,            primary mag,       	       	  mag
+FIELD dM,             MAG_ERR,    float,            error on primary mag,         mag
+FIELD Xp,             SIGMA_POS,  short, 	    position scatter,   	  1/100 arcsec
+FIELD Xm,             CHISQ_MAG,  short, 	    chisq for primary mag,        [100*log(value)]
+FIELD Xg,             CHISQ_GAL,  short,            chisq for galaxy mag          [100*log(value)]
+FIELD Nm,             NMEAS,      unsigned short,   number of measures
+FIELD Nn,             NMISS,      unsigned short,   number of missings
+FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
+FIELD offset,         offset,     int,     	    offset to first measurement
+FIELD missing,        missing,    int,     	    offset to first missing obs
+FIELD dummy,          dummy,      int,              extra space
+
+# change this table eventually to a temp name and provide a script to fix existing DBs
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/average-pmtest.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/average-pmtest.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/average-pmtest.d	(revision 11885)
@@ -0,0 +1,32 @@
+STRUCT       AveragePMtest
+EXTNAME      DVO_AVERAGE_PMTEST
+TYPE         BINTABLE
+SIZE         80
+DESCRIPTION  DVO Average Object Table
+
+# elements of data structure / FITS table
+
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD dR,             RA_ERR,     float,            RA error                      arcsec
+FIELD dD,             DEC_ERR,    float,            DEC error                     arcsec
+
+FIELD uR,             U_RA,       float,            RA*cos(D) proper-motion,      arcsec/year
+FIELD uD,             U_DEC,      float,            DEC proper-motion,            arcsec/year
+FIELD duR,            V_RA_ERR,   float,            RA*cos(D) p-m error,          arcsec/year
+FIELD duD,            V_DEC_ERR,  float,            DEC p-m error,                arcsec/year
+FIELD P,              PAR,        float,            parallax,			  arcsec
+FIELD dP,             PAR_ERR,    float,            parallax error,               arcsec
+
+FIELD M,              MAG,        float,            primary mag,       	       	  mag
+FIELD dM,             MAG_ERR,    float,            error on primary mag,         mag
+FIELD Xp,             SIGMA_POS,  short, 	    position scatter,   	  1/100 arcsec
+FIELD Xm,             CHISQ_MAG,  short, 	    chisq for primary mag,        [100*log(value)]
+FIELD Xg,             CHISQ_GAL,  short,            chisq for galaxy mags,        [100*log(value)]
+FIELD Nm,             NMEAS,      unsigned short,   number of measures
+FIELD Nn,             NMISS,      unsigned short,   number of missings
+FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
+FIELD offset,         offset,     int,     	    offset to first measurement
+FIELD missing,        missing,    int,     	    offset to first missing obs
+FIELD dummy,          dummy,      int,              extra space
+
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/average.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/average.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/average.d	(revision 11885)
@@ -0,0 +1,35 @@
+STRUCT       Average
+EXTNAME      DVO_AVERAGE
+TYPE         BINTABLE
+SIZE         76
+DESCRIPTION  DVO Average Object Table
+
+# elements of data structure / FITS table
+
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD dR,             RA_ERR,     float,            RA error                      arcsec
+FIELD dD,             DEC_ERR,    float,            DEC error                     arcsec
+
+FIELD uR,             U_RA,       float,            RA*cos(D) proper-motion,      arcsec/year
+FIELD uD,             U_DEC,      float,            DEC proper-motion,            arcsec/year
+FIELD duR,            V_RA_ERR,   float,            RA*cos(D) p-m error,          arcsec/year
+FIELD duD,            V_DEC_ERR,  float,            DEC p-m error,                arcsec/year
+FIELD P,              PAR,        float,            parallax,			  arcsec
+FIELD dP,             PAR_ERR,    float,            parallax error,               arcsec
+
+FIELD M,              MAG,        float,            primary mag,       	       	  mag
+FIELD dM,             MAG_ERR,    float,            error on primary mag,         mag
+FIELD Xp,             SIGMA_POS,  short, 	    position scatter,   	  1/100 arcsec
+FIELD Xm,             CHISQ_MAG,  short, 	    chisq for primary mag,        [100*log(value)]
+FIELD Xg,             CHISQ_GAL,  short,            chisq for galaxy mags,        [100*log(value)]
+FIELD Nm,             NMEAS,      unsigned short,   number of measures
+FIELD Nn,             NMISS,      unsigned short,   number of missings
+FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
+FIELD offset,         offset,     int,     	    offset to first measurement
+FIELD missing,        missing,    int,     	    offset to first missing obs
+
+# this structure should only be used for internal representations
+# the average-FORMAT structures should be used for external representations
+# note that the average magnitudes are stored in the 'secfilt' table (change this name??)
+# the index for the secfilt table is just Nsecfilt times the index for the average table.
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/common.h
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/common.h	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/common.h	(revision 11885)
@@ -0,0 +1,52 @@
+# include <ohana.h>
+# include <gfitsio.h>
+
+# ifndef AUTOCODE_H
+# define AUTOCODE_H
+/* matched endif is added by Makefile */
+
+# ifndef TRUE
+# define TRUE (1)
+# define FALSE (0)
+# endif
+
+# define SWAP_BYTE(X) \
+  tmp = byte[X+0]; byte[X+0] = byte[X+1]; byte[X+1] = tmp;
+# define SWAP_WORD(X) \
+  tmp = byte[X+0]; byte[X+0] = byte[X+3]; byte[X+3] = tmp; \
+  tmp = byte[X+1]; byte[X+1] = byte[X+2]; byte[X+2] = tmp;
+# define SWAP_DBLE(X) \
+  tmp = byte[X+0]; byte[X+0] = byte[X+7]; byte[X+7] = tmp; \
+  tmp = byte[X+1]; byte[X+1] = byte[X+6]; byte[X+6] = tmp; \
+  tmp = byte[X+2]; byte[X+2] = byte[X+5]; byte[X+5] = tmp; \
+  tmp = byte[X+3]; byte[X+3] = byte[X+4]; byte[X+4] = tmp;
+
+# ifdef linux
+# define BYTE_SWAP
+# endif
+
+# ifdef sid
+# define BYTE_SWAP
+# endif
+
+# ifdef dec
+# define BYTE_SWAP
+# endif
+
+# define e_time unsigned int
+# define e_void long long
+# define rawshort short
+
+/*** rawshort is used to handle the broken pre-autocode photreg tables
+     fix the tables and remove this
+***/
+
+/*** this file uses data types which must have fixed sizes regardless 
+     of the platform.  It originally used the basic C primitives: 
+       float, double, int, short int, unsigned long int, etc.
+     this breaks under 64 bit (and probably on other systems).
+     I should define internal data types which should be set by the 
+     use of # define statements if needed.  I will cheat for now and use
+     the time_t to replace unsigned long int in this file 
+***/
+
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/coords.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/coords.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/coords.d	(revision 11885)
@@ -0,0 +1,20 @@
+STRUCT       Coords
+EXTNAME      COORDS
+TYPE         BINTABLE
+SIZE         120
+DESCRIPTION  DVO Coordinate Transformation Table
+
+# elements of the Coords structure
+FIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+FIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+FIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+FIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+FIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+FIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+FIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+FIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+FIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+FIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+FIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+FIELD  ctype,            CTYPE,                char[15],      coordinate type
+FIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/detreg.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/detreg.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/detreg.d	(revision 11885)
@@ -0,0 +1,21 @@
+STRUCT  DetReg
+EXTNAME DETREND_DATABASE
+TYPE    BINTABLE
+SIZE    416
+
+# elements of data structure / FITS table
+
+FIELD tstart,         START_TIME, e_time,    start time of measurement, seconds since 1970 Jan 01 UT
+FIELD tstop,          STOP_TIME,  e_time,    stop time of measurement,  seconds since Jan 1, 1970 UT
+FIELD treg,           REG_TIME,   e_time,    time of registration,      seconds since Jan 1, 1970 UT
+FIELD exptime,        EXPTIME,    float,     exposure time,             seconds
+FIELD type,           IMAGETYP,   int,       detrend type number
+FIELD filter,         FILTER,     int,       filter number
+FIELD ccd,            CCDNUM,     int,       ccd number
+FIELD Nentry,         VERSION,    int,       image version number
+FIELD Norder,         ORDER,      int,       selection order
+FIELD mode,           MODE,       char,      image mode
+FIELD altpath,        ALTPATH,    char,      available on alt db paths, true for data on alt db paths
+FIELD dummy,          RESERVED,   char[58],  space for additions,       for future expansion
+FIELD label,          LABEL,      char[64],  data label
+FIELD filename,       PATH,       char[256], filename in db
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/image-ascii.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/image-ascii.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/image-ascii.d	(revision 11885)
@@ -0,0 +1,16 @@
+# name of structure type
+STRUCT  ImageASCII
+EXTNAME IMAGE
+TYPE    TABLE
+SIZE    328
+
+# elements of data structure / FITS table
+FIELD obstime,    START_TIME, char[20],    start time of measurement, yyyy/mm/dd,hh:mm:ss
+FIELD filter,  	  FILTER,     char[10],    filter and camera name    
+FIELD ZP,      	  ZP_OBS,     float[8.4],  measured zero point,       mag
+FIELD dZP,     	  ZP_ERR,     float[7.4],  error on zero point,       mag
+FIELD ra,      	  RA,         float[11.6], RA (J2000),                dec. degrees
+FIELD dec,     	  DEC,        float[11.6], DEC (J2000),               dec. degrees
+FIELD airmass, 	  C_AIRMASS,  float[7.3],  airmass coeff,             mag per airmass 
+FIELD sky,     	  SKY,        float[7.1],  median sky flux,           counts
+FIELD Nstar,   	  NSTAR,      int[6],      Number of stars in image,  stars
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/image-elixir.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/image-elixir.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/image-elixir.d	(revision 11885)
@@ -0,0 +1,59 @@
+STRUCT  ImageElixir
+EXTNAME DVO_IMAGE_ELIXIR
+TYPE 	BINTABLE
+SIZE 	240
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+SUBFIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+SUBFIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+SUBFIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+SUBFIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+SUBFIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+SUBFIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+SUBFIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+SUBFIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+SUBFIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
+SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+
+FIELD 	  tzero,            TZERO,                e_time,         readout time (row 0)
+FIELD 	  nstar,            NSTAR,                unsigned int,   number of stars on image
+FIELD 	  secz,             SECZ,                 short,      	  airmass,                   milliairmass
+FIELD 	  NX,               NX,                   short,      	  image width
+FIELD 	  NY,               NY,                   short,      	  image height
+FIELD 	  apmifit,          APMIFIT,              short,      	  aperture correction,       millimag
+FIELD 	  dapmifit,         DAPMIFIT,             short,      	  apmifit error,             millimag
+FIELD 	  source,           SOURCE,               short,      	  identifier for CCD,
+FIELD 	  Mcal,             MCAL,                 short,      	  calibration mag,           millimag
+FIELD 	  dMcal,            DMCAL,                short,      	  error on Mcal,             millimag
+FIELD 	  Xm,               XM,                   short,      	  image chisq,               10*log(value)
+FIELD 	  name,             NAME,                 char[32],       name of original image 
+FIELD 	  detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
+FIELD 	  saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
+FIELD 	  cerror,           CERROR,               unsigned char,  astrometric error,         50*arcsec
+FIELD 	  fwhm_x,           FWHM_X,               unsigned char,  PSF x width,               25*arcsec
+FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
+FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
+FIELD 	  exptime,          EXPTIME,              float,          exposure time,             seconds
+FIELD 	  code,             CODE,                 char,           image quality flag
+FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
+FIELD 	  dummy,            DUMMY,                char[20],       unused
+FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
+FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
+FIELD 	  My,               MY,                   short,      	  Mrel polyterm
+FIELD 	  Mxx,              MXX,                  short,      	  Mrel polyterm
+FIELD 	  Mxy,              MXY,                  short,      	  Mrel polyterm
+FIELD 	  Myy,              MYY,                  short,      	  Mrel polyterm
+FIELD 	  Mxxx,             MXXX,                 short,      	  Mrel polyterm
+FIELD 	  Mxxy,             MXXY,                 short,      	  Mrel polyterm
+FIELD 	  Mxyy,             MXYY,                 short,      	  Mrel polyterm
+FIELD 	  Myyy,             MYYY,                 short,      	  Mrel polyterm
+FIELD 	  Mxxxx,            MXXXX,                short,      	  Mrel polyterm
+FIELD 	  Mxxxy,            MXXXY,                short,      	  Mrel polyterm
+FIELD 	  Mxxyy,            MXXYY,                short,      	  Mrel polyterm
+FIELD 	  Mxyyy,            MXYYY,                short,      	  Mrel polyterm
+FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/image-loneos.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/image-loneos.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/image-loneos.d	(revision 11885)
@@ -0,0 +1,59 @@
+STRUCT  ImageLoneos
+EXTNAME DVO_IMAGE_LONEOS
+TYPE 	BINTABLE
+SIZE 	240
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+SUBFIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+SUBFIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+SUBFIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+SUBFIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+SUBFIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+SUBFIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+SUBFIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+SUBFIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+SUBFIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
+SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+
+FIELD 	  tzero,            TZERO,                e_time,         readout time (row 0)
+FIELD 	  nstar,            NSTAR,                unsigned int,   number of stars on image
+FIELD 	  secz,             SECZ,                 short,      	  airmass,                   milliairmass
+FIELD 	  NX,               NX,                   short,      	  image width
+FIELD 	  NY,               NY,                   short,      	  image height
+FIELD 	  apmifit,          APMIFIT,              short,      	  aperture correction,       millimag
+FIELD 	  dapmifit,         DAPMIFIT,             short,      	  apmifit error,             millimag
+FIELD 	  source,           SOURCE,               short,      	  identifier for CCD,
+FIELD 	  Mcal,             MCAL,                 short,      	  calibration mag,           millimag
+FIELD 	  dMcal,            DMCAL,                short,      	  error on Mcal,             millimag
+FIELD 	  Xm,               XM,                   short,      	  image chisq,               10*log(value)
+FIELD 	  name,             NAME,                 char[32],       name of original image 
+FIELD 	  detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
+FIELD 	  saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
+FIELD 	  cerror,           CERROR,               unsigned char,  astrometric error,         50*arcsec
+FIELD 	  fwhm_x,           FWHM_X,               unsigned char,  PSF x width,               25*arcsec
+FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
+FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
+FIELD 	  exptime,          EXPTIME,              float,          exposure time,             seconds
+FIELD 	  code,             CODE,                 char,           image quality flag
+FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
+FIELD 	  dummy,            DUMMY,                char[20],       unused
+FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
+FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
+FIELD 	  My,               MY,                   short,      	  Mrel polyterm
+FIELD 	  Mxx,              MXX,                  short,      	  Mrel polyterm
+FIELD 	  Mxy,              MXY,                  short,      	  Mrel polyterm
+FIELD 	  Myy,              MYY,                  short,      	  Mrel polyterm
+FIELD 	  Mxxx,             MXXX,                 short,      	  Mrel polyterm
+FIELD 	  Mxxy,             MXXY,                 short,      	  Mrel polyterm
+FIELD 	  Mxyy,             MXYY,                 short,      	  Mrel polyterm
+FIELD 	  Myyy,             MYYY,                 short,      	  Mrel polyterm
+FIELD 	  Mxxxx,            MXXXX,                short,      	  Mrel polyterm
+FIELD 	  Mxxxy,            MXXXY,                short,      	  Mrel polyterm
+FIELD 	  Mxxyy,            MXXYY,                short,      	  Mrel polyterm
+FIELD 	  Mxyyy,            MXYYY,                short,      	  Mrel polyterm
+FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/image-panstarrs.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/image-panstarrs.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/image-panstarrs.d	(revision 11885)
@@ -0,0 +1,65 @@
+STRUCT  ImagePanstarrs
+EXTNAME DVO_IMAGE_PANSTARRS
+TYPE    BINTABLE
+SIZE    248
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+SUBFIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+SUBFIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+SUBFIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+SUBFIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+SUBFIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+SUBFIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+SUBFIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+SUBFIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+SUBFIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
+SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+# 120 bytes
+
+FIELD 	  tzero,            TZERO,                e_time,         readout time (row 0)
+FIELD 	  nstar,            NSTAR,                unsigned int,   number of stars on image
+FIELD 	  secz,             SECZ,                 float,      	  airmass,                   mag
+FIELD 	  NX,               NX,                   short,      	  image width
+FIELD 	  NY,               NY,                   short,      	  image height
+FIELD 	  apmifit,          APMIFIT,              float,      	  aperture correction,       mag
+FIELD 	  dapmifit,         DAPMIFIT,             float,      	  apmifit error,             mag
+FIELD 	  Mcal,             MCAL,                 float,      	  calibration mag,           mag
+FIELD 	  dMcal,            DMCAL,                float,      	  error on Mcal,             mag
+FIELD 	  Xm,               XM,                   short,      	  image chisq,               10*log(value)
+FIELD 	  source,           SOURCE,               short,      	  identifier for CCD,
+FIELD 	  exptime,          EXPTIME,              float,          exposure time,             seconds
+# 40 bytes
+
+FIELD 	  name,             NAME,                 char[32],       name of original image 
+FIELD 	  detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
+FIELD 	  saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
+FIELD 	  cerror,           CERROR,               unsigned char,  astrometric error,         50*arcsec
+FIELD 	  fwhm_x,           FWHM_X,               unsigned char,  PSF x width,               25*arcsec
+FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
+FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
+FIELD 	  code,             CODE,                 char,           image quality flag
+FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
+# 40 bytes 
+
+FIELD 	  dummy,            DUMMY,                char[18],       unused
+FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
+FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
+FIELD 	  My,               MY,                   short,      	  Mrel polyterm
+FIELD 	  Mxx,              MXX,                  short,      	  Mrel polyterm
+FIELD 	  Mxy,              MXY,                  short,      	  Mrel polyterm
+FIELD 	  Myy,              MYY,                  short,      	  Mrel polyterm
+FIELD 	  Mxxx,             MXXX,                 short,      	  Mrel polyterm
+FIELD 	  Mxxy,             MXXY,                 short,      	  Mrel polyterm
+FIELD 	  Mxyy,             MXYY,                 short,      	  Mrel polyterm
+FIELD 	  Myyy,             MYYY,                 short,      	  Mrel polyterm
+FIELD 	  Mxxxx,            MXXXX,                short,      	  Mrel polyterm
+FIELD 	  Mxxxy,            MXXXY,                short,      	  Mrel polyterm
+FIELD 	  Mxxyy,            MXXYY,                short,      	  Mrel polyterm
+FIELD 	  Mxyyy,            MXYYY,                short,      	  Mrel polyterm
+FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
+# 48 bytes
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/image.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/image.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/image.d	(revision 11885)
@@ -0,0 +1,68 @@
+STRUCT       Image
+EXTNAME      DVO_IMAGE
+TYPE         BINTABLE
+SIZE         256
+DESCRIPTION  DVO Image Table 
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+SUBFIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+SUBFIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+SUBFIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+SUBFIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+SUBFIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+SUBFIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+SUBFIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+SUBFIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+SUBFIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
+SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+# 120 bytes
+
+FIELD 	  tzero,            TZERO,                e_time,         readout time (row 0)
+FIELD 	  nstar,            NSTAR,                unsigned int,   number of stars on image
+FIELD 	  secz_PS,          SECZ,                 float,      	  airmass,                   mag
+FIELD 	  NX,               NX,                   short,      	  image width
+FIELD 	  NY,               NY,                   short,      	  image height
+FIELD 	  apmifit_PS,       APMIFIT,              float,      	  aperture correction,       mag
+FIELD 	  dapmifit_PS,      DAPMIFIT,             float,      	  apmifit error,             mag
+FIELD 	  Mcal_PS,          MCAL,                 float,      	  calibration mag,           mag
+FIELD 	  dMcal_PS,         DMCAL,                float,      	  error on Mcal,             mag
+FIELD 	  Xm,               XM,                   short,      	  image chisq,               10*log(value)
+FIELD 	  source,           SOURCE,               short,      	  identifier for CCD,
+FIELD 	  exptime,          EXPTIME,              float,          exposure time,             seconds
+FIELD     sidtime,          ST,			  float,          sidereal time of exposure
+FIELD     latitude,         LAT,		  float,          observatory latitude,      degrees
+# 40 bytes
+
+FIELD 	  name,             NAME,                 char[32],       name of original image 
+FIELD 	  detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
+FIELD 	  saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
+FIELD 	  cerror,           CERROR,               unsigned char,  astrometric error,         50*arcsec
+FIELD 	  fwhm_x,           FWHM_X,               unsigned char,  PSF x width,               25*arcsec
+FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
+FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
+FIELD 	  code,             CODE,                 char,           image quality flag
+FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
+# 40 bytes 
+
+FIELD 	  dummy,            DUMMY,                char[18],       unused
+FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
+FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
+FIELD 	  My,               MY,                   short,      	  Mrel polyterm
+FIELD 	  Mxx,              MXX,                  short,      	  Mrel polyterm
+FIELD 	  Mxy,              MXY,                  short,      	  Mrel polyterm
+FIELD 	  Myy,              MYY,                  short,      	  Mrel polyterm
+FIELD 	  Mxxx,             MXXX,                 short,      	  Mrel polyterm
+FIELD 	  Mxxy,             MXXY,                 short,      	  Mrel polyterm
+FIELD 	  Mxyy,             MXYY,                 short,      	  Mrel polyterm
+FIELD 	  Myyy,             MYYY,                 short,      	  Mrel polyterm
+FIELD 	  Mxxxx,            MXXXX,                short,      	  Mrel polyterm
+FIELD 	  Mxxxy,            MXXXY,                short,      	  Mrel polyterm
+FIELD 	  Mxxyy,            MXXYY,                short,      	  Mrel polyterm
+FIELD 	  Mxyyy,            MXYYY,                short,      	  Mrel polyterm
+FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
+# 48 bytes
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-elixir.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-elixir.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-elixir.d	(revision 11885)
@@ -0,0 +1,23 @@
+STRUCT  MeasureElixir
+EXTNAME DVO_MEASURE_ELIXIR
+TYPE    BINTABLE
+SIZE    32
+
+# elements of data structure / FITS table
+
+FIELD dR,             D_RA,       short,          RA offset,                	  1/100 arcsec
+FIELD dD,             D_DEC,      short,          DEC offset,               	  1/100 arcsec
+FIELD M,              MAG,        short,          catalog mag,       	       	  millimag
+FIELD Mcal,           Mcal,       short,          image cal mag,	          millimag
+FIELD Mgal,           Mgal,       short,          galaxy mag,			  millimag
+FIELD airmass,        airmass,    short,          (airmass - 1),		  milliairmass
+FIELD FWx,            FWx,        short,          object fwhm major axis,         1/100 of arcsec 
+FIELD dM,             dM,         unsigned char,  mag error,                      millimag
+FIELD fwy,            fwy,        unsigned char,  object fwhm minor/major ratio
+FIELD theta,          theta,      unsigned char,  angle wrt ccd X dir,            (0xff/360) deg
+FIELD dophot,         dophot,     char,           dophot type
+FIELD source,         source,     unsigned short, photcode
+FIELD t,              t,          unsigned int,   time in seconds (UNIX)
+FIELD averef,         averef,     unsigned int,   reference to average entry      
+FIELD dt,             dt,         short,          exposure time,                  2500*log(exptime)
+FIELD flags,          flags,      unsigned short, flags for various uses  
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-loneos.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-loneos.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-loneos.d	(revision 11885)
@@ -0,0 +1,16 @@
+STRUCT  MeasureLoneos
+EXTNAME DVO_MEASURE_LONEOS
+TYPE    BINTABLE
+SIZE    20
+
+# elements of data structure / FITS table
+
+FIELD dR,             D_RA,       short,          RA offset,                	  1/100 arcsec
+FIELD dD,             D_DEC,      short,          DEC offset,               	  1/100 arcsec
+FIELD M,              MAG,        short,          catalog mag,       	       	  millimag
+FIELD Mcal,           Mcal,       short,          image cal mag,	          millimag
+FIELD dM,             dM,         unsigned char,  mag error,                      millimag
+FIELD dophot,         dophot,     char,           dophot type
+FIELD source,         source,     unsigned short, photcode
+FIELD t,              t,          unsigned int,   time in seconds (UNIX)
+FIELD averef,         averef,     unsigned int,   reference to average entry      
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-panstarrs.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-panstarrs.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/measure-panstarrs.d	(revision 11885)
@@ -0,0 +1,24 @@
+STRUCT  MeasurePanstarrs
+EXTNAME DVO_MEASURE_PANSTARRS
+TYPE    BINTABLE
+SIZE    52
+
+# elements of data structure / FITS table
+
+FIELD dR,             D_RA,       float,          RA offset,                	  arcsec
+FIELD dD,             D_DEC,      float,          DEC offset,               	  arcsec
+FIELD M,              MAG,        float,          catalog mag,       	       	  mag
+FIELD dM,             dM,         float,          mag error,                      mag
+FIELD Mcal,           Mcal,       float,          image cal mag,	          mag
+FIELD Mgal,           Mgal,       float,          galaxy mag,			  mag
+FIELD airmass,        airmass,    float,          (airmass - 1),		  airmass
+FIELD dt,             dt,         float,          exposure time,                  2.5*log(exptime)
+FIELD FWx,            FWx,        short,          object fwhm major axis,         1/100 of arcsec 
+FIELD FWy,            FWy,        short,          object fwhm minor axis,         1/100 of arcsec 
+FIELD theta,          theta,      unsigned char,  angle wrt ccd X dir,            (0xff/360) deg
+FIELD dophot,         dophot,     char,           dophot type
+FIELD source,         source,     unsigned short, photcode
+FIELD flags,          flags,      unsigned short, flags for various uses  
+FIELD dummy,          dummy,      short,          extra space
+FIELD t,              t,          unsigned int,   time in seconds (UNIX)
+FIELD averef,         averef,     unsigned int,   reference to average entry      
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/measure.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/measure.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/measure.d	(revision 11885)
@@ -0,0 +1,22 @@
+STRUCT       Measure
+EXTNAME      DVO_MEASURE
+TYPE         BINTABLE
+SIZE         50
+DESCRIPTION  DVO Detection Measurement Table 
+
+FIELD dR_PS,          D_RA,       float,          RA offset,                	  arcsec
+FIELD dD_PS,          D_DEC,      float,          DEC offset,               	  arcsec
+FIELD M_PS,           MAG,        float,          catalog mag,       	       	  mag
+FIELD Mcal_PS,        Mcal,       float,          image cal mag,	          mag
+FIELD Mgal_PS,        Mgal,       float,          galaxy mag,			  mag
+FIELD dM_PS,          dM,         float,          mag error,                      mag
+FIELD airmass_PS,     airmass,    float,          (airmass - 1),		  airmass
+FIELD dt_PS,          dt,         float,          exposure time,                  2.5*log(exptime)
+FIELD FWx,            FWx,        short,          object fwhm major axis,         1/100 of arcsec 
+FIELD FWy,            FWy,        short,          object fwhm minor axis,         1/100 of arcsec 
+FIELD theta,          theta,      unsigned char,  angle wrt ccd X dir,            (0xff/360) deg
+FIELD dophot,         dophot,     char,           dophot type
+FIELD source,         source,     unsigned short, photcode
+FIELD flags,          flags,      unsigned short, flags for various uses  
+FIELD t,              t,          unsigned int,   time in seconds (UNIX)
+FIELD averef,         averef,     unsigned int,   reference to average entry      
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/missing.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/missing.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/missing.d	(revision 11885)
@@ -0,0 +1,8 @@
+STRUCT       Missing
+EXTNAME      DVO_MISSING
+TYPE         BINTABLE
+SIZE         4
+DESCRIPTION  DVO Non-Detection Table 
+
+# elements of data structure / FITS table
+FIELD t,               TIME,        unsigned int,    time in seconds
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/photcode.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/photcode.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/photcode.d	(revision 11885)
@@ -0,0 +1,19 @@
+STRUCT       PhotCode
+EXTNAME      DVO_PHOTCODE
+TYPE         BINTABLE
+SIZE         77
+DESCRIPTION  DVO Photcode Description Table 
+
+# elements of data structure / FITS table
+FIELD  code,        CODE,        unsigned short, code number (stored in Measure.source) 
+FIELD  name,        NAME,        char[32],	 name for filter combination 
+FIELD  type,        TYPE,        char,	      	 PRI/SEC/DEP/REF 
+FIELD  C,           C_LAM,       short,	      	 primary phot calibration terms (millimags) 
+FIELD  dC,          C_LAM_ERR,   short,	      	 primary phot calibration terms (millimags) 
+FIELD  dX,          X_ERR,       short,	      	 primary phot calibration terms (millimags) 
+FIELD  K,           K,           float,	      	 secondary phot calibration terms (millimags) 
+FIELD  c1,          C1,          int,	      	 color is average.M[c1] - average.M[c2] 
+FIELD  c2,          C2,          int,	      	 color is average.M[c1] - average.M[c2] 
+FIELD  equiv,       EQUIV,       int,	      	 this dependent filter is equivalent to equiv PRI/SEC
+FIELD  Nc,          NC,          int,	      	 number of color terms 
+FIELD  X,           X,           float[4],    	 color terms $X[0]*mc + X[1]*mc^2 + X[2]*mc^3$, etc 
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/photreg-old.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/photreg-old.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/photreg-old.d	(revision 11885)
@@ -0,0 +1,18 @@
+STRUCT PhotParsOld
+EXTNAME ZERO_POINTS
+TYPE BINTABLE
+SIZE 100
+
+# elements of data structure / FITS table
+
+FIELD ZP,    	  ZP_OBS,     float,       measured zero point,       mag
+FIELD ZPo,   	  ZP_REF,     float, 	   nominal zero point,        mag
+FIELD dZP,   	  ZP_ERR,     float, 	   error on zero point,       mag
+FIELD K,     	  C_AIRMASS,  float, 	   airmass coeff,             mag per airmass
+FIELD X,     	  C_COLOR,    float, 	   color coeff,               mag per mag
+FIELD tstart,	  START_TIME, e_time,      start time of measurement, seconds since 1 Jan 1970 UT
+FIELD tstop, 	  STOP_TIME,  e_time,      stop time of measurement,  seconds since 1 Jan 1970 UT
+FIELD c1,    	  C1_CODE,    short, 	   code 1 for color,          photcode
+FIELD c2,    	  C2_CODE,    short, 	   code 2 for color,          photcode
+FIELD photcode,   PHOTCODE,   short, 	   photcode,                  photcode
+FIELD label,      LABEL,      char[66],    data label
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/photreg.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/photreg.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/photreg.d	(revision 11885)
@@ -0,0 +1,21 @@
+STRUCT PhotPars
+EXTNAME ZERO_POINTS_3.0
+TYPE BINTABLE
+SIZE 108
+
+# elements of data structure / FITS table
+
+FIELD ZP,    	  ZP_OBS,     float,       measured zero point,       mag
+FIELD ZPo,   	  ZP_REF,     float, 	   nominal zero point,        mag
+FIELD dZP,   	  ZP_ERR,     float, 	   error on zero point,       mag
+FIELD K,     	  C_AIRMASS,  float, 	   airmass coeff,             mag per airmass
+FIELD X,     	  C_COLOR,    float, 	   color coeff,               mag per mag
+FIELD tstart,	  START_TIME, e_time,      start time of measurement, seconds since 1 Jan 1970 UT
+FIELD tstop, 	  STOP_TIME,  e_time,      stop time of measurement,  seconds since 1 Jan 1970 UT
+FIELD c1,    	  C1_CODE,    short, 	   code 1 for color,          photcode
+FIELD c2,    	  C2_CODE,    short, 	   code 2 for color,          photcode
+FIELD photcode,   PHOTCODE,   short, 	   photcode,                  photcode
+FIELD label,      LABEL,      char[64],    data label
+FIELD refcode,    REFCODE,    rawshort,	   photcode,                  photcode
+FIELD Ntime,      N_TIME,     int, 	   number of times
+FIELD Nmeas,      N_MEAS,     int, 	   number of measurements
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/regimage.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/regimage.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/regimage.d	(revision 11885)
@@ -0,0 +1,40 @@
+STRUCT  RegImage
+EXTNAME IMAGE_DATABASE
+TYPE    BINTABLE
+SIZE    360
+
+# elements of data structure / FITS table
+
+FIELD filename,         FILE,       char[64],     filename in db
+FIELD pathname,     	PATH,       char[128],    fullpath in db
+FIELD filter,       	FILTER,     char[32],     filter name
+FIELD instrument,   	INSTRUMENT, char[32],     instrument
+FIELD ccd,	        CCD,        char,   	  ccd identifier
+FIELD mode,	        MODE,       char,   	  mef/split/etc
+FIELD type,	        TYPE,       char,   	  object/flat/bias/etc
+FIELD flag,	        FLAG,       char,   	  data flags
+FIELD seqtime,          SEQTIME,    float,        exposure time per slice,   seconds
+FIELD seq,	        SEQ,        char,   	  sequence number
+FIELD junk,	        JUNK,       char[19],     space for expansion
+FIELD exptime,	        EXPTIME,    float,  	  exposure time,             seconds
+FIELD airmass,	        AIRMASS,    float,  	  airmass
+FIELD sky,	        SKY,        float,  	  background level,          counts / pixel
+FIELD bias,	        BIAS,       float,  	  bias level,                counts / pixel
+FIELD fwhm,	        FWHM,       float,  	  image quality,             pixels
+FIELD telfocus,	        TELFOCUS,   float,  	  telescope focus,           microns
+FIELD xprobe,	        XPROBE,     float,  	  bonnette probe x pos,      microns
+FIELD yprobe,	        YPROBE,     float,  	  bonnette probe y pos,      microns
+FIELD zprobe,	        ZPROBE,     float,  	  bonnette focus,            microns
+FIELD dettemp,	        DETTEMP,    float,  	  detector temperature,      deg celcius
+FIELD teltemp_0,       	TELTEMP0,   float,  	  other temperature,         deg celcius
+FIELD teltemp_1,       	TELTEMP1,   float,  	  other temperature,         deg celcius
+FIELD teltemp_2,       	TELTEMP2,   float,  	  other temperature,         deg celcius
+FIELD teltemp_3,       	TELTEMP3,   float,  	  other temperature,         deg celcius
+FIELD rotangle,	        ROTANGLE,   float,  	  camera rotation angle,     degrees
+FIELD ra,	        RA,         float,  	  image ra,                  degrees
+FIELD dec,	        DEC,        float,  	  image dec,                 degrees
+FIELD obstime,	        OBS_TIME,   e_time, 	  time of measurement,       seconds since 01 Jan 1970 UT
+FIELD regtime,	        REG_TIME,   e_time, 	  time of registration,      seconds since 01 Jan 1970 UT
+
+# take care of the memory padding boundaries when using 'junk' for new elements
+# which are not of type char!
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-elixir.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-elixir.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-elixir.d	(revision 11885)
@@ -0,0 +1,9 @@
+STRUCT  SecFiltElixir
+EXTNAME DVO_SECFILT_ELIXIR
+TYPE    BINTABLE
+SIZE    6
+
+# elements of data structure / FITS table
+FIELD  M,  MAG,      short,                other mags,       millimags
+FIELD  Xm, MAG_CHI,  short,                chisq on mag
+FIELD  dM, MAG_ERR,  short,                scatter on mag
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-loneos.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-loneos.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-loneos.d	(revision 11885)
@@ -0,0 +1,8 @@
+STRUCT  SecFiltLoneos
+EXTNAME DVO_SECFILT_LONEOS
+TYPE    BINTABLE
+SIZE    4
+
+# elements of data structure / FITS table
+FIELD  M,  MAG,      short,                other mags,       millimags
+FIELD  Xm, MAG_CHI,  short,                chisq on mag
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-panstarrs.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-panstarrs.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt-panstarrs.d	(revision 11885)
@@ -0,0 +1,10 @@
+STRUCT  SecFiltPanstarrs
+EXTNAME DVO_SECFILT_PANSTARRS
+TYPE    BINTABLE
+SIZE    12
+
+# elements of data structure / FITS table
+FIELD  M,  MAG,      float,                other mags,       mags
+FIELD  dM, MAG_ERR,  float,                scatter on mag    1e4*mag
+FIELD  Xm, MAG_CHI,  short,                chisq on mag,     [100*log(value)]
+FIELD  dummy, JUNK,  short,                chisq on mag,     [100*log(value)]
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/secfilt.d	(revision 11885)
@@ -0,0 +1,11 @@
+STRUCT       SecFilt
+EXTNAME      DVO_SECFILT
+TYPE         BINTABLE
+SIZE         12
+DESCRIPTION  DVO SecFilt : Secondary Filter Data 
+
+# elements of data structure / FITS table
+FIELD  M_PS,  MAG,      float,                other mags,       mags
+FIELD  dM_PS, MAG_ERR,  float,                scatter on mag,   mags
+FIELD  Xm,    MAG_CHI,  short,                chisq on mag,     [100*log(value)]
+FIELD  dummy, JUNK,     short,                place holder
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/smpdata.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/smpdata.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/smpdata.d	(revision 11885)
@@ -0,0 +1,19 @@
+# name of structure type
+STRUCT  SMPData
+EXTNAME SMPFILE
+TYPE    BINTABLE
+SIZE    44
+
+# elements of data structure / FITS table
+FIELD X,      X_PIX,      float,    x coord,              pixels
+FIELD Y,      Y_PIX,      float,    y coord,              pixels
+FIELD M,      MAG_RAW,    float,    inst mags,            mags
+FIELD dM,     MAG_ERR,    float,    inst mag error,       mags
+FIELD Mgal,   MAG_GAL,    float,    galaxy mag,           mags
+FIELD Map,    MAG_AP,     float,    aperture mag,         mags
+FIELD sky,    LOG_SKY,    float,    log-10 of sky,        cnts/sec
+FIELD fx,     FWHM_X,     float,    semi-major,           pixels
+FIELD fy,     FWHM_Y,     float,    semi-minor,           pixels
+FIELD df,     THETA,      float,    ellipse angle,        degrees
+FIELD dophot, DOPHOT,     char,     dophot type,          none
+FIELD dummy,  DUMMY,      char[3],  padding,              none
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/spectrum-ascii.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/spectrum-ascii.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/spectrum-ascii.d	(revision 11885)
@@ -0,0 +1,29 @@
+# name of structure type
+STRUCT  SpectrumASCII
+EXTNAME SPECTRUM
+TYPE    TABLE
+SIZE    262
+
+# elements of data structure / FITS table
+FIELD filename,   FILENAME,   char[32],    filename in db,        
+FIELD pathname,   PATHNAME,   char[64],    fullpath in db,        
+FIELD instrument, INSTRUMENT, char[16],    instrument,            
+FIELD telescope,  TELESCOPE,  char[16],    telescope,             
+FIELD objname,    OBJNAME,    char[16],    object name,           
+FIELD extname,    EXTNAME,    char[16],    extname in file,       
+
+FIELD ra,         RA,         float[10.6], ra,                    degrees
+FIELD dec,        DEC,        float[10.6], dec,                   degrees
+FIELD exptime,    EXPTIME,    float[6.1],  exposure time,         seconds
+FIELD airmass,    AIRMASS,    float[5.3],  airmass,               none
+FIELD Ws,         Ws,         float[7.2],  spectral range start,  Angstrom
+FIELD We,         We,         float[7.2],  spectral range end,    Angstrom
+FIELD dW,         dW,         float[7.2],  spectral resolution,   Angstrom / pix
+	       			      
+FIELD Nspec,      NSPECTRA,   int[3],      number of spectra,     none
+FIELD obstime,    OBS_TIME,   char[20],    time of measurement,   yyyy/mm/dd
+FIELD regtime,    REG_TIME,   char[20],    time of registration,  yyyy/mm/dd
+	       			      
+FIELD mode,       MODE,       int[2],      phu/mef/ext,           
+FIELD state,      STATE,      int[2],      raw/wav/flx/etc,       
+FIELD flag,       FLAG,       int[3],      status flags,          
Index: /branches/libautocode-1-7/Ohana/src/libautocode/def/spectrum.d
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/def/spectrum.d	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/def/spectrum.d	(revision 11885)
@@ -0,0 +1,31 @@
+STRUCT  Spectrum
+EXTNAME SPECTRUM_DATABASE
+TYPE    BINTABLE
+SIZE    216
+
+# elements of data structure / FITS table
+	       			      
+FIELD ra,         RA,         float,     ra,                    degrees
+FIELD dec,        DEC,        float,     dec,                   degrees
+FIELD exptime,    EXPTIME,    float,     exposure time,         seconds
+FIELD airmass,    AIRMASS,    float,     airmass,               
+FIELD Ws,         Ws,         float,     spectral range start,  Angstrom
+FIELD We,         We,         float,     spectral range end,    Angstrom
+FIELD dW,         dW,         float,     spectral resolution,   Angstrom / pix
+	       			      
+FIELD Nspec,      NSPECTRA,   int,       number of spectra,     
+FIELD obstime,    OBS_TIME,   int,       time of measurement,   seconds since 1 Jan 1970 UT
+FIELD regtime,    REG_TIME,   int,       time of registration,  seconds since 1 Jan 1970 UT
+	       			      
+FIELD mode,       MODE,       char,      phu/mef/ext           
+FIELD state,      STATE,      char,      raw/wav/flx/etc       
+FIELD flag,       FLAG,       char,      status flags
+FIELD extra,      EXTRA,      char[13],  room for expansion
+
+FIELD pathname,   PATHNAME,   char[64],  fullpath in db
+FIELD filename,   FILENAME,   char[32],  filename in db
+FIELD extname,    EXTNAME,    char[16],  extname in file,       
+
+FIELD instrument, INSTRUMENT, char[16],  instrument,            
+FIELD telescope,  TELESCOPE,  char[16],  telescope,             
+FIELD objname,    OBJNAME,    char[16],  object name,           
Index: /branches/libautocode-1-7/Ohana/src/libautocode/doc/ChangeLog.txt
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/doc/ChangeLog.txt	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/doc/ChangeLog.txt	(revision 11885)
@@ -0,0 +1,44 @@
+
+- libautocode 1.5
+  * converted to gfits APIs (forces libfits 1.6)
+  * fixed comma errors in average tables
+
+- libautocode 1.4
+  * added average-pmtest.d
+  * added autocode.tex, tex interpretation
+  * added proper-motion, etc to Stars.d
+  * added proper-motion, etc to average.d
+  * DESCRIPTION element for tex tables
+
+- libautocode 1.3
+  * added SkyRegion.d
+  * added AddstarClientOptions
+  * fixed e_void ptr in generate
+  * cleaned up signed/unsigned inconsistencies
+
+libautocode-1-2
+  added support for Comm functions (Send/Recv structure)
+  changed internal precision to doubles (RA/DEC) and floats (MAG)
+  dropped all internal millimag representations
+  made panstarrs format higher precisions than elixir
+  added the following new structures to support multiple data formats:
+     average-elixir
+     image-ascii
+     image-elixir
+     image-loneos
+     image-panstarrs
+     measure-elixir
+     measure-panstarrs
+     secfilt-elixir
+     secfilt-loneos
+     secfilt-panstarrs
+  added these structures for addstar client/server comms
+     AddstarClientOptions
+     GSCRegion
+     Stars
+
+libautocode-1-1
+  added the measure, average entries to autocode tables
+
+libautocode-1-0
+  import to CVS
Index: /branches/libautocode-1-7/Ohana/src/libautocode/doc/autocode.txt
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/doc/autocode.txt	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/doc/autocode.txt	(revision 11885)
@@ -0,0 +1,71 @@
+
+This directory contains a collection of autocoded FITS I/O routines
+used to define FITS Table DB functions.  
+
+The autocoder program is a perl script 'generate'.  This scripts takes
+as input a schema file and a template source code file, and produces
+an output file from these two inputs.  A single schema file is meant
+to be associated with a single data concept which is being coded.  For
+example, in the case of the FITS DB tables, a single schema file
+defines a single FITS table, or equivalently, a single C structure
+representing a row in that FITS table.
+
+Schema File
+
+The schema file currently consists of two types of information.
+
+First, there are simple keyword / name pairs which the autocoder
+simply applies as a direct replacement anywhere in the template.  For
+example, the keyword NAME replaces any instance of "$NAME" in the
+template with the corresponding value.  
+
+Second, there is a special type of keyword: FIELD.  The FIELD entry
+defines an entry in the data structure.  The FIELD entry is followed
+by the following comma-separated pieces of information:
+
+- the element name
+- the element data type
+- the element description
+- the element physical unit
+
+Template File
+
+The template file is a source code in whatever language is desired.
+Within the template, the defined keywords may be used as desired,
+wherever needed.  In addition, there are special directives which
+invoke additional special behavior.  All special directives have the
+form of comments within their target language.  They are replaced with
+a block of code in that target language, normally one which iterates
+over the FIELD elements of the schema file.  As such, the directive
+appropriate for one language should not be used within code for a
+different language.  Here is a list of existing special directives:
+
+/** STRUCT DEFINITION **/
+
+This tells the autocoder to create a structure definition for the
+schema.  The structure definition creates a structure with elements
+based on the FIELD entries, with the name $NAME (NOTE: this is perhaps
+making too much of an assumption.  we could require the template to
+provide the wrapper: "typedef struct { } $NAME;" and have the
+autocoder only insert the field lines).  
+
+/** TABLE DEFINITION **/
+
+This tells the autocoder to output the lines which add a column to an
+exiting empty table.  The assumption is that the template contains
+code to initialize a table.  It then invokes the table definition
+code, which defines each of the appropriate columns.  This is perhaps
+followed by some code which finalizes the table definition.  (Note:
+the code output by the autocoder in this block is not very flexible:
+it the current example, it explicitly uses the Elixir FITS Table
+functions, and refers to some data elements in the template code.  The
+latter could possibly be more abstracted with the keyword / value
+pairs, but in any case, the autocoded lines will have to be
+constructed somewhat by hand for a specific API set.
+
+/** BYTE SWAP **/
+
+This tells the autocoder to output code defining the byte swaps
+appropriat to the data structure.  Again, the resulting code depends a
+bit on the intended use and API set.
+
Index: /branches/libautocode-1-7/Ohana/src/libautocode/doc/notes.txt
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/doc/notes.txt	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/doc/notes.txt	(revision 11885)
@@ -0,0 +1,138 @@
+
+FITS I/O APIs
+
+  - I/O to a binary FITS table
+  - one extension per file?
+  - no locking
+  - always read/write to/from matched structure
+  - user needs to supply idiosyncratic conversions
+
+  - basic APIs:
+    - fits_read_datatable_NAME
+    - fits_write_datatable_NAME
+    - fits_IO_convert_NAME
+    - fits_fread_datatable_NAME
+    - fits_fwrite_datatable_NAME
+
+FITS db APIs
+
+Basic Rules:
+
+  - All db files are Binary FITS tables
+  - There is only one extension per file
+  - The PHU contains basic information like status & date
+  - There is no data array for the PHU (NAXIS = 0)
+
+typedef struct {
+  FILE *f;
+  char *filename;
+  Header header;
+  FTable ftable;
+  int Nrows;
+  int Ncols;
+  int Nbyte;
+  int lockstate;
+  int lockreq;
+  NAME *data;
+} NAME_DB;
+
+NAME_DB *NAME_DB_Init (NAME_DB *db);
+
+  - 
+
+NAME_DB *NAME_DB_Load (char *filename, int lockreq);
+
+  - lock the database file
+  - load PHU
+  - load the header
+  - validate the EXTNAME
+  - validate the header
+  - load the data into ftable
+  - convert to memory format
+
+  * if SOFT & database file does not exist (file is empty), 
+    - return structure w/ 0 entries
+
+  * if HARD & database file does not exist (file is empty), 
+    - open, lock, return structure w/ 0 entries
+
+  * if database file cannot be locked
+    - return an error (NULL)
+
+  * if header does not validate: 
+    - unlock file
+    - return an error (NULL)
+
+NAME_DB *NAME_DB_Loadset (char *filename, int lockreq, int start, int Nrows);
+
+  - lock the database file
+  - load PHU
+  - load the header
+  - validate the EXTNAME
+  - validate the header
+  - load the data into vtable
+  - convert to memory format
+
+  * if database file does not exist (file is empty), 
+    - open, lock, return structure w/ 0 entries
+  * if requested entries don't exist
+    - unlock file
+    - return an error (NULL)
+
+NAME_DB *NAME_DB_Save ();
+
+  - if Nrows = 0, delete the file
+
+  - write PHU
+  - write header
+  - write ftable
+
+  - if vtable: 
+    - update 
+  - if ftable: 
+    - update 
+
+NAME_DB *NAME_DB_Saveset ();
+
+  - if Nrows = 0, delete the file
+
+  - write PHU
+  - write header
+  - write ftable
+
+  - if vtable: 
+    - update 
+  - if ftable: 
+    - update 
+
+NAME_DB *NAME_DB_Free ();
+
+  - unlock file
+
+
+---
+
+DVO tables
+
+I am converting all DVO tables to have an internal representation of
+the table with the necessary precision (ie, double for RA & DEC, etc),
+and a set of external representations in which the precision and
+available columns are truncated to fit a specific representation.  the
+autocode tables then include the internal name (ie, measure.d) and the
+external versions (ie, measure-elixir.d, etc).  
+
+To pursue this, I have modifed the definion of measure.d to replace,
+eg, dR with dR_PS.  I am now compiling all of ohana and looking for
+places where the new name is needed in the code, stopping the
+compilation.  (In the process, I am being forced to clean up the
+relphot - at least - coding problems: unused variables, undeclared
+functions, etc).  After I have made the changes, I will search for all
+instances of dR_PS and return them to their original.
+
+The only things to watch for in this process are units for the
+values.  In the older code, the value of measure.dR was interpreted as
+1/100th of an arcsec.  Everywhere this was the interpretation must be
+changed to make the value represent 1 arcsec.  This will also be an
+issue for the internal magnitude representations, which all use
+millimags...
+
Index: /branches/libautocode-1-7/Ohana/src/libautocode/generate
===================================================================
--- /branches/libautocode-1-7/Ohana/src/libautocode/generate	(revision 11885)
+++ /branches/libautocode-1-7/Ohana/src/libautocode/generate	(revision 11885)
@@ -0,0 +1,384 @@
+#!/usr/bin/env perl
+
+$VERBOSE = 0;
+if ($ARGV[0] eq "-v") { $VERBOSE = 1; shift @ARGV; }
+if (@ARGV != 3) { die "generate (schema) (template) (output)\n"; }
+
+$schema   = $ARGV[0];
+$template = $ARGV[1];
+$output   = $ARGV[2];
+
+&parse_schema;
+&parse_template;
+exit 0;
+
+sub parse_schema {
+    open (FILE, "$schema");
+    @list = <FILE>;
+    close (FILE);
+
+    $NAME    = "";
+    $FILE    = "";
+    $Nfield  = 0;
+    $TIMEOUT = 0;
+
+    &init_key ("DESCRIPTION");
+    &init_key ("TIMEOUT");
+    &init_key ("EXTNAME");
+    &init_key ("STRUCT");
+    &init_key ("NAME");
+    &init_key ("FILE");
+    &init_key ("SIZE");
+    &init_key ("TYPE");
+
+    foreach $line (@list) {
+	chop $line;
+	($key, $value) = split (" ", $line, 2);
+	
+	# strip white space from the following
+	if ($key eq "TYPE")    { ($value) = $value =~ m|\s*(\S+)\s*|; }
+	if ($key eq "SIZE")    { ($value) = $value =~ m|\s*(\S+)\s*|; }
+	if ($key eq "STRUCT")  { ($value) = $value =~ m|\s*(\S+)\s*|; }
+	if ($key eq "EXTNAME") { ($value) = $value =~ m|\s*(\S+)\s*|; }
+
+	&set_keypair ($key, $value);
+
+	# these are used internally (not just a replacement)
+	if ($key eq "TYPE")    { $TYPE = $value;   }
+	if ($key eq "SIZE")    { $SIZE = $value;   }
+	if ($key eq "STRUCT")  { $STRUCT = $value; }
+
+	# not a simple key/value entry
+ 	if (($key eq "FIELD") || ($key eq "SUBSTRUCT") || ($key eq "SUBFIELD")) {
+	    ($element, $field, $format, $comment, $unit) = split (/,\s+/, $value, 5);
+	    if ($VERBOSE) { printf "%-20s %-20s %-15s %-35s %-10s\n", $element, $field, $format, $comment, $unit; }
+	    push @element, $element;
+	    push @field,   $field;
+	    push @format,  $format;
+	    push @comment, $comment;
+	    push @unit,    $unit;
+	    push @mode,    $key;
+	}
+    }
+    $Nexpect = 0;
+    if ($TYPE eq "BINTABLE") { $Nexpect = &count_bintablesize; }
+    if ($TYPE eq "TABLE")    { $Nexpect = &count_tablesize;    }
+    if (! $Nexpect) { die "missing valid TYPE\n"; }
+    if ($Nexpect != $SIZE) { die "size mismatch: $Nexpect vs $SIZE\n"; }
+}
+
+sub parse_template {
+    open (FILE, $template);
+    @list = <FILE>;
+    close (FILE);
+
+    open (FILE, ">$output");
+
+    foreach $line (@list) {
+	
+	&check_keypairs;
+
+	print FILE $line;
+
+	# fill in structure
+	if ($line =~ m|/\*\* STRUCT DEFINITION \*\*/|) {
+	    &write_structure;
+	}
+
+	# fill in latex table description
+	if ($line =~ m|%%% LATEX TABLE DEFINITION|) {
+	    &write_latex;
+	}
+
+	# fill in structure
+	if ($line =~ m|/\*\* TABLE DEFINITION \*\*/|) {
+	    if ($TYPE eq "BINTABLE") { &write_bintabledefs; }
+	    if ($TYPE eq "TABLE")    { &write_tabledefs; }
+	}
+
+	# fill in swaps
+	if ($line =~ m|/\*\* BYTE SWAP \*\*/|) {
+	    &write_byteswaps;
+	}
+    }
+    close (FILE);
+}
+
+sub write_bintabledefs {
+
+    for ($i = 0; $i < @field; $i++) {
+	# skip SUBSTRUCT type of entries:
+	if ($mode[$i] eq "SUBSTRUCT") { next; }
+
+	($type, $Np) = &get_type_array ($format[$i]);
+	
+	# rawshort is a short without byteswapping
+
+	$pt1 = 0;
+	if ($type eq "char")          { $pt1 = "A"; }
+	if ($type eq "byte")   	      { $pt1 = "B"; }
+	if ($type eq "unsigned char") { $pt1 = "B"; }
+	if ($type eq "rawshort")      { $pt1 = "I"; }
+	if ($type eq "short")  	      { $pt1 = "I"; }
+	if ($type eq "unsigned short"){ $pt1 = "I"; }
+	if ($type eq "int")    	      { $pt1 = "J"; }
+	if ($type eq "unsigned int")  { $pt1 = "J"; }
+	if ($type eq "e_time") 	      { $pt1 = "J"; }
+	if ($type eq "float")  	      { $pt1 = "E"; }
+	if ($type eq "double") 	      { $pt1 = "D"; }
+
+	if ($type eq "e_void") 	      { $pt1 = "B"; $Np = 8*$Np; }
+	# e_void is a 64 bit pointer, cast to size_t.  its value is not loaded
+	# from the table.
+
+	if (!$pt1) { die "unknown type $type"; }
+
+	if ($Np == 1) {
+	    $pt2 = $pt1;
+	} else {
+	    $pt2 = sprintf "%d%s", $Np, $pt1;
+	}
+
+	printf FILE "  gfits_define_bintable_column (header, ";
+	printf FILE "%-8s",               "\"$pt2\", ";
+	printf FILE "%-20s",              "\"$field[$i]\", ";
+	printf FILE "%-35s",              "\"$comment[$i]\", ";
+	printf FILE "%-20s 1.0, 0.0);\n", "\"$unit[$i]\", ";
+    }
+
+}
+
+sub write_latex {
+
+    for ($i = 0; $i < @field; $i++) {
+	# skip SUBSTRUCT type of entries:
+	if ($mode[$i] eq "SUBSTRUCT") { next; }
+
+	($type, $Np) = &get_type_array ($format[$i]);
+
+	if ($type eq "e_time") 	      { $type = "unsigned int"; }
+
+	# print STDOUT "$field[$i] .. $type[$i] .. $comment[$i] .. $unit[$i]\n";
+
+        printf FILE "%-20s & ",       "\\code{$field[$i]} ";
+	printf FILE "%-20s & ",       "$type";
+	printf FILE "%-35s & ",       "$comment[$i]";
+	printf FILE "%-20s \\\\ \n",  "$unit[$i]";
+    }
+}
+
+sub get_type_array {
+    
+    my ($format) = $_[0];
+    my ($type);
+    my ($Np, $N1, $N2, $N3);
+
+    $type = $N1 = $N2 = $N3 = $Np = 0;
+    if (!$type) {
+	($type, $N1, $N2, $N3) = $format =~ m|^(.w+)\[(\d+)\]\[(\d+)\]\[(\d+)\]|;
+	$Np = $N1*$N2*$N3;
+    }
+    if (!$type) {
+	($type, $N1, $N2)      = $format =~ m|^(.+)\[(\d+)\]\[(\d+)\]|;
+	$Np = $N1*$N2;
+    } 
+    if (!$type) {
+	($type, $N1)           = $format =~ m|^(.+)\[(\d+)\]|;
+	$Np = $N1;
+    }
+    if (!$type) { 
+	$type                  = $format; 
+	$Np = 1;
+    }
+    # print "type: $type, Np: $Np\n";
+    if ($Np == 0) { die "syntax error in format/array\n"; }
+    return ($type, $Np);
+}
+
+sub write_tabledefs {
+
+    for ($i = 0; $i < @field; $i++) {
+	# skip SUBSTRUCT type of entries:
+	if ($mode[$i] eq "SUBSTRUCT") { next; }
+
+	($type, $N1, $N2)      = $format[$i] =~ m|^(\w+)\[(\d+)\]\[(\d+)\]|;
+	if ($N2) { die "ASCII table cannot have multi-valued column"; }
+
+	($type, $length) = $format[$i] =~ m|^(\w+)\[([\d\.]+)\]|;
+	if (!$type && !$length) { die "format must be specified for ASCII table"; }
+
+	$pt1 = 0;
+	if ($type eq "char")   	      { $pt1 = sprintf "A%s", $length; }
+	if ($type eq "byte")   	      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "unsigned char") { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "rawshort")      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "short")  	      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "unsigned short"){ $pt1 = sprintf "I%s", $length; }
+	if ($type eq "int")    	      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "unsigned int")  { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "e_time") 	      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "float")  	      { $pt1 = sprintf "F%s", $length; }
+	if ($type eq "double") 	      { $pt1 = sprintf "F%s", $length; }
+
+	if ($type eq "e_void") 	      { $pt1 = sprintf "I%s", $length; }
+
+	if (!$pt1) { die "unknown type $type"; }
+
+	printf FILE "  gfits_define_table_column (header, ";
+	printf FILE "%-8s",      "\"$pt1\", ";
+	printf FILE "%-20s",     "\"$field[$i]\", ";
+	printf FILE "%-35s",     "\"$comment[$i]\", ";
+	printf FILE "%-20s);\n", "\"$unit[$i]\"";
+    }
+
+}
+
+sub write_structure {
+    print FILE "typedef struct {\n";
+    for ($i = 0; $i < @element; $i++) {
+	# skip SUBFIELD entries
+	if ($mode[$i] eq "SUBFIELD") { next; }
+
+	# here we only want to match the pattern [1][2][3]..[N]
+	($type, $array) = $format[$i] =~ m|^(\w+)(\[.*\])|;
+	# print "type: $type, array: $array\n";
+	if (!$type && !$array) { $type = $format[$i]; }
+
+	if ($array && (($TYPE eq "BINTABLE") || ($type eq "char"))) {
+	    $pt2 = sprintf "%s%s;", $element[$i], $array;
+	} else {
+	    $pt2 = sprintf "%s;", $element[$i];
+	}
+
+	if ($unit[$i] eq "") {
+	    $pt3 = sprintf "// %s", $comment[$i];
+	} else {
+	    $pt3 = sprintf "// %s (%s)", $comment[$i], $unit[$i];
+	}
+	printf FILE "  %-16s %-21s %s\n", $type, $pt2, $pt3;
+    }    
+    print FILE "} $STRUCT;\n";
+}
+
+# this does not work with ASCII tables, 
+# but should not be needed for ASCII tables!
+sub write_byteswaps {
+    if ($TYPE eq "TABLE") {
+	printf FILE "/*** no byteswaps for ASCII tables ***/\n";
+	return;
+    }
+    $N = 0;
+    for ($i = 0; $i < @field; $i++) {
+	# skip SUBSTRUCT type of entries:
+	if ($mode[$i] eq "SUBSTRUCT") { next; }
+
+	($type, $Np) = &get_type_array ($format[$i]);
+
+	# rawshort is a patch for old photreg tables: provide a fix for the tables
+	# some photreg tables were not byteswapped for certain columns
+
+	$n = 0;
+	if ($type eq "char") 	      { $N +=   $Np; next; }
+	if ($type eq "byte") 	      { $N +=   $Np; next; }
+	if ($type eq "unsigned char") { $N +=   $Np; next; }
+	if ($type eq "rawshort")      { $N += 2*$Np; next; }
+	if ($type eq "short")  	      { $T = "BYTE"; $n = 2; }
+	if ($type eq "unsigned short"){ $T = "BYTE"; $n = 2; }
+	if ($type eq "int")    	      { $T = "WORD"; $n = 4; }
+	if ($type eq "unsigned int")  { $T = "WORD"; $n = 4; }
+	if ($type eq "e_time") 	      { $T = "WORD"; $n = 4; }
+	if ($type eq "e_void") 	      { $T = "DBLE"; $n = 8; }
+	if ($type eq "float")  	      { $T = "WORD"; $n = 4; }
+	if ($type eq "double") 	      { $T = "DBLE"; $n = 8; }
+	if (!$n) { die "unknown type $type"; }
+	for ($j = 0; $j < $Np; $j++) {
+	    printf FILE "    SWAP_%s (%d); // %s\n", $T, $N, $field[$i];
+	    $N += $n;
+	}
+    }
+}
+
+sub count_bintablesize {
+
+    $Nbytes = 0;
+    for ($i = 0; $i < @field; $i++) {
+	# skip SUBSTRUCT type of entries:
+	if ($mode[$i] eq "SUBSTRUCT") { next; }
+
+	# add [\d\.] to match ascii-type formats
+	($type, $Np) = &get_type_array ($format[$i]);
+
+	$valid = 0;
+	if ($type eq "char")   	       { $Nbytes += 1*$Np; $valid = 1; }
+	if ($type eq "byte")   	       { $Nbytes += 1*$Np; $valid = 1; }
+	if ($type eq "unsigned char")  { $Nbytes += 1*$Np; $valid = 1; }
+	if ($type eq "rawshort")       { $Nbytes += 2*$Np; $valid = 1; }
+	if ($type eq "short")  	       { $Nbytes += 2*$Np; $valid = 1; }
+	if ($type eq "unsigned short") { $Nbytes += 2*$Np; $valid = 1; }
+	if ($type eq "int")    	       { $Nbytes += 4*$Np; $valid = 1; }
+	if ($type eq "unsigned int")   { $Nbytes += 4*$Np; $valid = 1; }
+	if ($type eq "e_time") 	       { $Nbytes += 4*$Np; $valid = 1; }
+	if ($type eq "e_void") 	       { $Nbytes += 8*$Np; $valid = 1; }
+	if ($type eq "float")  	       { $Nbytes += 4*$Np; $valid = 1; }
+	if ($type eq "double") 	       { $Nbytes += 8*$Np; $valid = 1; }
+	if (!$valid) { die "unknown type $type"; }
+    }
+    return ($Nbytes);
+}
+
+sub count_tablesize {
+
+    $Nbytes = 0;
+    for ($i = 0; $i < @field; $i++) {
+	# skip SUBSTRUCT type of entries:
+	if ($mode[$i] eq "SUBSTRUCT") { next; }
+
+	($fpt) = $format[$i] =~ m|^\w+\[([\d\.]+)\]|;
+	$length = int($fpt);
+	# print "$format[$i], $length, $fpt\n";
+	if ($length == 0) { die "ASCII table format requires field size"; }
+	$Nbytes += $length;
+    }
+    return ($Nbytes);
+}
+
+sub init_key {
+    my ($key)   = $_[0];
+
+    push @key, $key;
+    push @value, "";
+}
+
+sub set_keypair {
+    my ($i);
+    my ($key)   = $_[0];
+    my ($value) = $_[1];
+
+    for ($i = 0; $i < @key; $i++) {
+	if ($key eq $key[$i]) {
+	    if ($value[$i] ne "") { die "key is multiply defined\n"; }
+	    $value[$i] = $value;
+	    return;
+	}
+    }
+}
+
+sub check_keypairs {
+    my ($i);
+    for ($i = 0; $i < @key; $i++) {
+	# if ($VERBOSE) { print "$key[$i]  -- $value[$i]\n"; }
+	if ($line =~ m|\$$key[$i]|) {
+	    if ($value[$i] eq "") { die "missing value for required key $key[$i]\n"; }
+	    $line =~ s|\$$key[$i]|$value[$i]|g;
+	}
+    }
+}
+
+# we need to find the structure size, including padding 
+# i'm not sure I know the answer to this: it is probably 
+# the total number of bytes rounded up to the largest 
+# data item in the structure (ie, 8 for a double, etc)
+# if we have the size, then we can double check the structure
+# against the expectation at runtime.  for the moment,
+# calculate by hand and add to def.d file 
+
