Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/Makefile.Targets	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/Makefile.Targets	(revision 37376)
@@ -1,4 +1,4 @@
 AOBJS = \
-$(ASRC)/coords.$(ARCH).o \
+$(ASRC)/coords-disk.$(ARCH).o \
 $(ASRC)/average.$(ARCH).o \
 $(ASRC)/average-loneos.$(ARCH).o \
@@ -56,5 +56,4 @@
 $(ASRC)/photcode-ps1-v5.$(ARCH).o \
 $(ASRC)/photcode-ps1-ref.$(ARCH).o \
-$(ASRC)/image.$(ARCH).o \
 $(ASRC)/image-loneos.$(ARCH).o \
 $(ASRC)/image-elixir.$(ARCH).o \
@@ -98,5 +97,5 @@
 
 AINCS = \
-$(AINC)/coords.h \
+$(AINC)/coords-disk.h \
 $(AINC)/average.h \
 $(AINC)/average-loneos.h \
@@ -154,5 +153,4 @@
 $(AINC)/photcode-ps1-v5.h \
 $(AINC)/photcode-ps1-ref.h \
-$(AINC)/image.h \
 $(AINC)/image-loneos.h \
 $(AINC)/image-elixir.h \
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/common.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/common.h	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/common.h	(revision 37376)
@@ -34,4 +34,80 @@
 # define DVO_IMAGE_NAME_LEN 117
 
+typedef struct {
+  int Nx;
+  int Ny;
+  float *value;
+  float dX;
+  float dY;
+  float Xo;
+  float Yo;
+} ImageMap;
+
+/* Internal version of Coords (see CoordsDisk in libautocode/def/coords-disk.d) */
+typedef struct Coords {
+  double           crval1;               // coordinate at reference pixel
+  double           crval2;               // coordinate at reference pixel
+  float            crpix1;               // coordinate of reference pixel
+  float            crpix2;               // coordinate of reference pixel
+  float            cdelt1;               // degrees per pixel
+  float            cdelt2;               // degrees per pixel
+  float            pc1_1;                // rotation matrix
+  float            pc1_2;                // rotation matrix
+  float            pc2_1;                // rotation matrix
+  float            pc2_2;                // rotation matrix
+  float            polyterms[7][2];      // higher order warping terms
+  char             ctype[15];            // coordinate type
+  char             Npolyterms;           // order of polynomial
+  struct Coords   *mosaic;               // pointer to parent mosaic
+  ImageMap        *imageMap;		 // pointer to image map transformation
+} Coords;
+
+typedef struct Image {
+  Coords           coords;               // astrometric data
+  e_time           tzero;                // readout time (row 0)
+  unsigned int     nstar;                // number of stars on image
+  float            secz;                 // airmass (mag)
+  unsigned short   NX;                   // image width
+  unsigned short   NY;                   // image height
+  float            apmifit;              // aperture correction (mag)
+  float            dapmifit;             // apmifit error (mag)
+  float            Mcal;                 // calibration mag (mag)
+  float            dMcal;                // error on Mcal (mag)
+  short            Xm;                   // image chisq (10*log(value))
+  short            photcode;             // identifier for CCD,
+  float            exptime;              // exposure time (seconds)
+  float            sidtime;              // sidereal time of exposure
+  float            latitude;             // observatory latitude (degrees)
+  float            RAo;                  // image center (degrees)
+  float            DECo;                 // image center (degrees)
+  float            Radius;               // image radius (degrees)
+  float            refColorBlue;         // median astrometry ref color
+  float            refColorRed;          // median astrometry ref color
+  char             name[117];            // name of original image 
+  unsigned char    detection_limit;      // detection limit (10*mag)
+  unsigned char    saturation_limit;     // saturation limit (10*mag)
+  unsigned char    cerror;               // astrometric error (50*arcsec)
+  unsigned char    fwhm_x;               // PSF x width (25*arcsec)
+  unsigned char    fwhm_y;               // PSF y width (25*arcsec)
+  unsigned char    trate;                // scan rate (100 usec/pixel)
+  unsigned char    ccdnum;               // CCD ID number
+  unsigned int     flags;                // image quality flags
+  unsigned int     imageID;              // internal image ID
+  unsigned int     parentID;             // associated ref image
+  unsigned int     externID;             // external image ID
+  unsigned short   sourceID;             // analysis source ID
+  short            nLinkAstrom;          // mean number of matched measurements for astrometry
+  short            nLinkPhotom;          // mean number of matched measurements for astrometry
+  short            ubercalDist;          // distance to nearest ubercal image
+  float            dXpixSys;             // systematic astrometry error in X
+  float            dYpixSys;             // systematic astrometry error in Y
+  float            dMagSys;              // systematic photometry error
+  unsigned short   nFitAstrom;           // number of stars used for astrometry cal
+  unsigned short   nFitPhotom;           // number of stars used for photometry cal
+  unsigned int     photom_map_id;        // reference to 2D zero point map
+  unsigned int     astrom_map_id;        // reference to 2D astrometry map
+  struct Image    *parent;               // pointer to parent mosaic (not save to disk)
+} Image;
+
 /*** rawshort is used to handle the broken pre-autocode photreg tables
      fix the tables and remove this
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/coords.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/coords.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/coords.d	(revision 37376)
@@ -17,4 +17,5 @@
 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  ctype,            CTYPE,                char[15],         coordinate type
 FIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+FIELD  astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-elixir.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-elixir.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-elixir.d	(revision 37376)
@@ -6,5 +6,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-loneos.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-loneos.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-loneos.d	(revision 37376)
@@ -6,5 +6,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-panstarrs-dev-0.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-panstarrs-dev-0.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-panstarrs-dev-0.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-panstarrs-dev-1.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-panstarrs-dev-1.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-panstarrs-dev-1.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-1.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-1.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-1.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-2.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-2.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-2.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-3.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-3.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-dev-3.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-ref.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-ref.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-ref.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v1.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v1.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v1.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v2.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v2.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v2.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v3.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v3.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v4.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v4.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v4.d	(revision 37376)
@@ -7,5 +7,5 @@
 # elements of the image structure
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v5.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v5.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image-ps1-v5.d	(revision 37376)
@@ -8,5 +8,5 @@
 # careful of 8-byte boundaries
 
-SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
 SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image.d
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image.d	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/image.d	(revision 37376)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_IMAGE
 TYPE         BINTABLE
-SIZE         360
+SIZE         384
 DESCRIPTION  DVO Image Table 
 
@@ -8,4 +8,5 @@
 # careful of 8-byte boundaries
 
+# Coords is an internal structure defined in def/common.h
 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
 SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
@@ -22,5 +23,7 @@
 SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
 SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
-# 120 bytes
+SUBFIELD  mosaic,           MOSAIC,               e_void,     	 pointer to parent mosaic
+SUBFIELD  imageMap,         IMAGE_MAP,            e_void,     	 pointer to image map
+# 136 bytes
 
 # change this to a double?
@@ -76,4 +79,6 @@
 FIELD 	  photom_map_id,    PHOTOM_MAP_ID,        unsigned int,   reference to 2D zero point map
 FIELD 	  astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
+
+FIELD    *parent,           PARENT,               e_void,     	  pointer to parent mosaic (not save to disk)
 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/doc/autocode.txt
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/doc/autocode.txt	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/doc/autocode.txt	(revision 37376)
@@ -35,7 +35,20 @@
 
 - the element name
+- the element FITS field (in FITS table)
 - the element data type
 - the element description
 - the element physical unit
+
+SUBFIELD / SUBSTRUCT keywords allows the user to define elements of a
+structure which are themselves structures.  These fields are used as
+follow:
+
+Binary / ASCII FITS tables write out the SUBFIELD entries as if they
+were regular table rows (substructure distinction not visible in FITS
+table).  SUBSTRUCT rows are NOT added to the FITS table.
+
+In a C-structure, the SUBFIELD rows are skipped and only the SUBSTRUCT
+row is saved.  The definition of the substructure is assumed to be
+defined elsewhere in the C code.
 
 Template File
@@ -43,11 +56,13 @@
 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:
+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 **/
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/generate
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/generate	(revision 37375)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/generate	(revision 37376)
@@ -144,4 +144,5 @@
 	if ($type eq "e_time") 	      { $pt1 = "J"; }
 	if ($type eq "e_void") 	      { $pt1 = "B"; $Np = 8*$Np; }
+	# if ($type eq "Image") 	      { $pt1 = "B"; $Np = 8*$Np; }
 	# e_void is a 64 bit pointer, cast to size_t.  its value is not loaded
 	# from the table.
@@ -248,4 +249,5 @@
 	if ($type eq "e_time") 	      { $pt1 = sprintf "I%s", $length; }
 	if ($type eq "e_void") 	      { $pt1 = sprintf "I%s", $length; }
+	# if ($type eq "Image") 	      { $pt1 = sprintf "I%s", $length; }
 
 	if (!$pt1) { die "unknown type $type"; }
@@ -331,4 +333,5 @@
 	if ($type eq "e_time") 	      { $T = "WORD"; $n = 4; }
 	if ($type eq "e_void") 	      { $T = "DBLE"; $n = 8; }
+	# if ($type eq "Image") 	      { $T = "DBLE"; $n = 8; }
 
 	if (!$n) { die "unknown type $type"; }
@@ -375,4 +378,5 @@
 	if ($type eq "e_time") 	       { $Nbytes += 4*$Np; $valid = 1; }
 	if ($type eq "e_void") 	       { $Nbytes += 8*$Np; $valid = 1; }
+	# if ($type eq "Image") 	       { $Nbytes += 8*$Np; $valid = 1; }
 	if (!$valid) { die "unknown type $type"; }
     }
