Index: /trunk/Ohana/src/libautocode/Makefile
===================================================================
--- /trunk/Ohana/src/libautocode/Makefile	(revision 3608)
+++ /trunk/Ohana/src/libautocode/Makefile	(revision 3609)
@@ -29,4 +29,5 @@
 # remember to add entries here to libohana/Makefile:AOBJ as well
 LIBOBJ = \
+$(SRC)/regimage.$(ARCH).o \
 $(SRC)/detreg.$(ARCH).o \
 $(SRC)/photreg.$(ARCH).o \
@@ -37,4 +38,5 @@
 
 LIBINC = \
+$(INC)/regimage.h \
 $(INC)/detreg.h \
 $(INC)/photreg.h \
@@ -44,11 +46,10 @@
 $(INC)/spectrum-ascii.h
 
-COMINC = \
-$(DEF)/common.h
-
 $(LIBOBJ): $(INC)/autocode.h
 
 $(INC)/autocode.h: $(LIBINC)
-	cat $(COMINC) $(LIBINC) > $(INC)/autocode.h
+	cat $(DEF)/common.h >  $(INC)/autocode.h
+	cat $(LIBINC)       >> $(INC)/autocode.h
+	@echo "# endif"     >> $(INC)/autocode.h
 	@echo done with libautocode.a:
 
Index: /trunk/Ohana/src/libautocode/def/common.h
===================================================================
--- /trunk/Ohana/src/libautocode/def/common.h	(revision 3608)
+++ /trunk/Ohana/src/libautocode/def/common.h	(revision 3609)
@@ -1,5 +1,7 @@
-# include <stdio.h>
-# include <stdarg.h>
-# include <fitsio.h>
+# include <ohana.h>
+
+# ifndef AUTOCODE_H
+# define AUTOCODE_H
+/* matched endif is added by Makefile */
 
 # ifndef TRUE
@@ -32,4 +34,9 @@
 
 # define e_time unsigned int
+# 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 
Index: /trunk/Ohana/src/libautocode/def/photreg.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/photreg.d	(revision 3608)
+++ /trunk/Ohana/src/libautocode/def/photreg.d	(revision 3609)
@@ -17,5 +17,5 @@
 FIELD photcode,   PHOTCODE,   short, 	   photcode,                  photcode
 FIELD label,      LABEL,      char[64],    data label
-FIELD refcode,    REFCODE,    short, 	   photcode,                  photcode
+FIELD refcode,    REFCODE,    rawshort,	   photcode,                  photcode
 FIELD Ntime,      N_TIME,     int, 	   number of times
 FIELD Nmeas,      N_MEAS,     int, 	   number of measurements
Index: /trunk/Ohana/src/libautocode/def/regimage.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/regimage.d	(revision 3609)
+++ /trunk/Ohana/src/libautocode/def/regimage.d	(revision 3609)
@@ -0,0 +1,37 @@
+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 seq,	        SEQ,        char,   	  sequence number
+FIELD seqtime,          SEQTIME,    float,        exposure time per slice,   seconds
+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
Index: /trunk/Ohana/src/libautocode/generate
===================================================================
--- /trunk/Ohana/src/libautocode/generate	(revision 3608)
+++ /trunk/Ohana/src/libautocode/generate	(revision 3609)
@@ -41,5 +41,6 @@
 	# not a simple key/value entry
 	if ($key eq "FIELD") {
-	    ($element, $field, $format, $comment, $unit) = split (/,\s+/, $value);
+	    ($element, $field, $format, $comment, $unit) = split (/,\s+/, $value, 5);
+#	    print "$element : $field : $format : $comment : $unit\n";
 	    push @element, $element;
 	    push @field,   $field;
@@ -106,4 +107,6 @@
 	if ($type eq "float")  { $pt1 = "E"; }
 	if ($type eq "double") { $pt1 = "D"; }
+
+	if ($type eq "rawshort") { $pt1 = "I"; }
 
 	printf FILE "  fits_define_bintable_column (header, ";
@@ -130,4 +133,6 @@
 	if ($type eq "double") { $pt1 = sprintf "F%s", $length; }
 
+	if ($type eq "rawshort")  { $pt1 = sprintf "I%s", $length; }
+
 	printf FILE "  fits_define_table_column (header, ";
 	printf FILE "\"%s\", ",   $pt1;
@@ -179,4 +184,9 @@
 	    next;
 	}
+	# this is a patch for old photreg tables: provide a fix for the tables
+	if ($type eq "rawshort")  {
+	    $N +=2;
+	    next;
+	}
 	if ($type eq "short")  {
 	    $T = "BYTE";
@@ -229,4 +239,6 @@
 	if ($type eq "float")  { $Nbytes += 4; }
 	if ($type eq "double") { $Nbytes += 8; }
+
+	if ($type eq "rawshort")  { $Nbytes += 2; }
     }
     return ($Nbytes);
Index: /trunk/Ohana/src/libfits/header/F_modify.c
===================================================================
--- /trunk/Ohana/src/libfits/header/F_modify.c	(revision 3608)
+++ /trunk/Ohana/src/libfits/header/F_modify.c	(revision 3609)
@@ -11,5 +11,5 @@
 
   char comment[82], string[82], data[82];
-  char *p, *q;
+  char *p, *qs, *qe;
   va_list argp;
   
@@ -27,5 +27,4 @@
   p = fits_header_field (header, field, N);
   if (p == NULL)  {
-
     /* new entry, find the END of the header */
     p = fits_header_field (header, "END", 1);
@@ -45,8 +44,9 @@
     memset (p, ' ', FT_LINE_LENGTH);
   } else {
-    q = fits_keyword_end (p);
-    q += 3;
-    q = MIN (p + 80, q);
-    strncpy (comment, q, p + 80 - q);
+    /* old entry, save the comment region (is this skipping a character for non-strings?) */
+    qe = fits_keyword_end (p);
+    qe += 3;
+    qe = MIN (p + 80, qe);
+    strncpy (comment, qe, p + 80 - qe);
   }
   pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
@@ -86,9 +86,16 @@
   /* just a comment associated with a value.  this is assumes a fixed format position for the comment */
   if (!strcmp (mode, "%C")) { 
-    q = fits_keyword_end (p);
-    strncpy (data, p + 9, MAX (MIN ((q - p - 9), 71), 0));
+    qe = fits_keyword_end (p);
+    qs = fits_keyword_start (p);
+
+    /* keep ' on ends, if there */
+    if (qe[0]  == 0x27) qe ++;
+    if (qs[-1] == 0x27) qs --;
+
+    strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
     strncpy (comment, va_arg (argp, char *), 80);
     pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
-    snprintf (string, 81, "%-8s=%21s / %-s", field, data, comment);
+    snprintf (string, 81, "%-8s= %s / %-s", field, data, comment);
+    /* this will keep the original line, but truncate the comment */
   }
 
Index: /trunk/Ohana/src/libohana/Makefile
===================================================================
--- /trunk/Ohana/src/libohana/Makefile	(revision 3608)
+++ /trunk/Ohana/src/libohana/Makefile	(revision 3609)
@@ -13,7 +13,5 @@
 DESTMAN	=	$(LMAN)
 
-INCS	= 	-I$(LINC)
-CFLAGS	=	-Wunused -o $*.$(ARCH).o $(INCS) 
-LFLAGS	=	-c $(INCS)
+CFLAGS	=	-I$(LINC) -D$(ARCH)
 
 default: install
@@ -21,9 +19,11 @@
 install: $(DESTLIB)/libohana.a
 
-ohana: $(LIB)/libohana.$(ARCH).a 
+libohana: $(LIB)/libohana.$(ARCH).a 
 
-HOBJ = \
+INC1 = \
 $(DESTINC)/Xohana.h  \
-$(DESTINC)/ohana.h \
+$(DESTINC)/ohana.h
+
+INC2 = \
 $(DESTINC)/loneos.h \
 $(DESTINC)/elixir.h \
@@ -31,5 +31,5 @@
 $(DESTINC)/dvo.h
 
-LOBJ = \
+OBJ1 = \
 $(SRC)/version.$(ARCH).o	 \
 $(SRC)/string.$(ARCH).o		 \
@@ -37,7 +37,9 @@
 $(SRC)/glockfile.$(ARCH).o	 \
 $(SRC)/config.$(ARCH).o		 \
+$(SRC)/Fseek.$(ARCH).o           
+
+OBJ2 = \
 $(SRC)/coordops.$(ARCH).o	 \
 $(SRC)/Fread.$(ARCH).o		 \
-$(SRC)/Fseek.$(ARCH).o           \
 $(SRC)/LoadPhotcodes.$(ARCH).o   \
 $(SRC)/photfits.$(ARCH).o	 \
@@ -48,4 +50,5 @@
 
 AOBJ = \
+$(ASRC)/regimage.$(ARCH).o \
 $(ASRC)/detreg.$(ARCH).o \
 $(ASRC)/photreg.$(ARCH).o \
@@ -55,6 +58,10 @@
 $(ASRC)/spectrum-ascii.$(ARCH).o
 
-autocode:
+autocode: $(INC1)
 	cd $(AUTO) && make install
+
+$(OBJ1): $(INC1)
+$(OBJ2): $(INC2)
+$(AOBJ): autocode
 
 $(DESTLIB)/libohana.a: $(LIB)/libohana.$(ARCH).a
@@ -63,11 +70,9 @@
 	cp $(LIB)/libohana.$(ARCH).a $(DESTLIB)/libohana.a
 
-$(LIB)/libohana.$(ARCH).a: autocode $(HOBJ) $(LOBJ)
+$(LIB)/libohana.$(ARCH).a: autocode $(OBJ1) $(AOBJ) $(OBJ2)
 	@if [ ! -d $(LIB) ]; then mkdir -p $(LIB); fi
 	rm -f $(LIB)/libohana.$(ARCH).a
-	ar rcv $(LIB)/libohana.$(ARCH).a $(LOBJ) $(AOBJ)
+	ar rcv $(LIB)/libohana.$(ARCH).a $(OBJ1) $(AOBJ) $(OBJ2)
 	$(RANLIB) $(LIB)/libohana.$(ARCH).a
-
-$(LOBJ): $(DESTINC)/ohana.h $(DESTINC)/loneos.h $(DESTINC)/elixir.h $(DESTINC)/panstarrs.h
 
 $(DESTINC)/%: $(INC)/%
@@ -88,3 +93,4 @@
 
 .c.$(ARCH).o:
-	$(CC) $(CFLAGS) -c $<
+	$(CC) $(CFLAGS) -c $*.c -o $@
+	@echo done with $*.o
Index: /trunk/Ohana/src/libohana/include/dvo.h
===================================================================
--- /trunk/Ohana/src/libohana/include/dvo.h	(revision 3608)
+++ /trunk/Ohana/src/libohana/include/dvo.h	(revision 3609)
@@ -1,9 +1,51 @@
+# include <autocode.h>
 
 # ifndef DVO_H
 # define DVO_H
 
-# define ELIXIR    1
-# define LONEOS    0
-# define PANSTARRS 0
+/*** FITS DB structure  ***/
+typedef struct {
+  FILE  *f;
+  char  *filename;
+  int    dbstate;
+  int    lockstate;
+  double timeout;
+  Header header;
+  Matrix matrix;
+  Header theader;
+  FTable ftable;
+} FITS_DB;
+
+/* the standard astrometric coordinates structure */
+typedef struct {
+  double   crval1, crval2;
+  float    crpix1, crpix2;
+  float    cdelt1, cdelt2;
+  float    pc1_1, pc1_2;
+  float    pc2_1, pc2_2;
+  float    polyterms[7][2];
+  char     ctype[15];
+  char     Npolyterms;
+} Coords;  /* 120 bytes / Coords */
+
+/* in fits_db.c */
+int   fits_db_init                PROTO((FITS_DB *db));
+int   fits_db_create              PROTO((FITS_DB *db));
+int   fits_db_lock                PROTO((FITS_DB *db, char *filename));
+int   fits_db_load                PROTO((FITS_DB *db));
+int   fits_db_close               PROTO((FITS_DB *db));
+int   fits_db_free                PROTO((FITS_DB *db));
+int   fits_db_save                PROTO((FITS_DB *db));
+int   fits_db_update              PROTO((FITS_DB *db, VTable *vtable));
+
+/* in coords.c */
+int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
+int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
+int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
+int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
+int  GetCoords (Coords *coords, Header *header);
+int  PutCoords (Coords *coords, Header *header);
+void RegisterMosaic (Coords *coords);
+void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
 
 /* image data modes in RegImage */
@@ -75,51 +117,10 @@
 */
 
-/*** FITS DB structure  ***/
-typedef struct {
-  FILE  *f;
-  char  *filename;
-  int    dbstate;
-  int    lockstate;
-  double timeout;
-  Header header;
-  Matrix matrix;
-  Header theader;
-  FTable ftable;
-} FITS_DB;
+/** we are going to replace these with autocode and appropriate conversions 
+    for now, choose the appropriate table version **/
 
-/* the standard astrometric coordinates structure */
-typedef struct {
-  double   crval1, crval2;
-  float    crpix1, crpix2;
-  float    cdelt1, cdelt2;
-  float    pc1_1, pc1_2;
-  float    pc2_1, pc2_2;
-  float    polyterms[7][2];
-  char     ctype[15];
-  char     Npolyterms;
-} Coords;  /* 120 bytes / Coords */
-
-/*** FITS_DB functions ***/
-
-/* in fits_db.c */
-int   fits_db_init                PROTO((FITS_DB *db));
-int   fits_db_lock                PROTO((FITS_DB *db, char *filename));
-int   fits_db_load                PROTO((FITS_DB *db));
-int   fits_db_close               PROTO((FITS_DB *db));
-int   fits_db_free                PROTO((FITS_DB *db));
-int   fits_db_save                PROTO((FITS_DB *db));
-int   fits_db_update              PROTO((FITS_DB *db, VTable *vtable));
-
-/* in coords.c */
-int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
-int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
-int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
-int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
-int  GetCoords (Coords *coords, Header *header);
-int  PutCoords (Coords *coords, Header *header);
-void RegisterMosaic (Coords *coords);
-void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
-
-# include <autocode.h>
+# define ELIXIR    1
+# define LONEOS    0
+# define PANSTARRS 0
 
 # if (LONEOS)
@@ -135,5 +136,8 @@
 # endif
 
-/* these functions refer to the DVO structures define in the includes above */
+/* these functions refer to the DVO structures defined in the includes above 
+ *  they are being replaced with autocode entries
+ */
+
 int   Fread (void *ptr, int size, int nitems, FILE *f, char *type);
 int   Fwrite (void *ptr, int size, int nitems, FILE *f, char *type);
Index: /trunk/Ohana/src/libohana/include/elixir.h
===================================================================
--- /trunk/Ohana/src/libohana/include/elixir.h	(revision 3608)
+++ /trunk/Ohana/src/libohana/include/elixir.h	(revision 3609)
@@ -14,4 +14,5 @@
 /************  database structures ************************************/
 
+# if (0)
 /* structure for Image Registration Database */
 typedef struct {
@@ -43,5 +44,7 @@
   e_time regtime;
 } RegImage;  /* 360 bytes / image */
-
+# endif 
+
+# if (0)
 /* Detrend Database structure */
 typedef struct {
@@ -61,4 +64,5 @@
   char filename[256];
 } DetReg;    /* 416 bytes */
+# endif
 
 /* average data as stored in the LONEOS database */
Index: /trunk/Ohana/src/libohana/include/loneos.h
===================================================================
--- /trunk/Ohana/src/libohana/include/loneos.h	(revision 3608)
+++ /trunk/Ohana/src/libohana/include/loneos.h	(revision 3609)
@@ -34,4 +34,5 @@
 } RegImage;  /* 360 bytes / image */
 
+# if (0)
 /* Detrend Database structure */
 typedef struct {
@@ -51,4 +52,5 @@
   char filename[256];
 } DetReg;    /* 416 bytes */
+# endif
 
 /* average data as stored in the LONEOS database -- must be translated on load */
Index: /trunk/Ohana/src/libohana/include/panstarrs.h
===================================================================
--- /trunk/Ohana/src/libohana/include/panstarrs.h	(revision 3608)
+++ /trunk/Ohana/src/libohana/include/panstarrs.h	(revision 3609)
@@ -34,4 +34,5 @@
 } RegImage;  /* 360 bytes / image */
 
+# if (0)
 /* Detrend Database structure */
 typedef struct {
@@ -51,4 +52,5 @@
   char filename[256];
 } DetReg;    /* 416 bytes */
+# endif
 
 /* average data as stored in the LONEOS database */
Index: /trunk/Ohana/src/libohana/src/Fread.c
===================================================================
--- /trunk/Ohana/src/libohana/src/Fread.c	(revision 3608)
+++ /trunk/Ohana/src/libohana/src/Fread.c	(revision 3609)
@@ -1,6 +1,5 @@
-# include <stdio.h>
-# include <string.h>
 # include <ohana.h>
 # include <dvo.h>
+
 int   ByteSwap (char *ptr, int size, int nitems, char *type);
 int   ConvertStruct (char *buffer, int size, int Nbytes, char *type);
Index: /trunk/Ohana/src/libohana/src/fits_db.c
===================================================================
--- /trunk/Ohana/src/libohana/src/fits_db.c	(revision 3608)
+++ /trunk/Ohana/src/libohana/src/fits_db.c	(revision 3609)
@@ -1,5 +1,6 @@
-# include "ohana.h"
-# include "dvo.h"
+# include <ohana.h>
+# include <dvo.h>
 
+/* init the db structure */
 int fits_db_init (FITS_DB *db) {
 
@@ -8,4 +9,15 @@
   db[0].matrix.buffer = NULL;
   db[0].ftable.buffer = NULL;
+  db[0].ftable.header = &db[0].theader;
+  return (TRUE);
+}
+
+/* create an empty db */
+int fits_db_create (FITS_DB *db) {
+  fits_init_header (&db[0].header);    
+  db[0].header.extend = TRUE;
+  fits_create_header (&db[0].header);
+  fits_create_matrix (&db[0].header, &db[0].matrix);
+  fits_print (&db[0].header, "NEXTEND", "%d", 1, 1);
   db[0].ftable.header = &db[0].theader;
   return (TRUE);
