Index: trunk/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- trunk/Ohana/src/libautocode/Makefile.Targets	(revision 29439)
+++ trunk/Ohana/src/libautocode/Makefile.Targets	(revision 29537)
@@ -59,4 +59,5 @@
 $(ASRC)/cmf-ps1-v1.$(ARCH).o \
 $(ASRC)/cmf-ps1-v2.$(ARCH).o \
+$(ASRC)/cmf-ps1-v3.$(ARCH).o \
 $(ASRC)/cmf-smpdata.$(ARCH).o \
 $(ASRC)/getstar-ps1-dev-0.$(ARCH).o \
@@ -129,4 +130,5 @@
 $(AINC)/cmf-ps1-v1.h \
 $(AINC)/cmf-ps1-v2.h \
+$(AINC)/cmf-ps1-v3.h \
 $(AINC)/cmf-smpdata.h \
 $(AINC)/getstar-ps1-dev-0.h \
Index: trunk/Ohana/src/libautocode/def/autocode.c
===================================================================
--- trunk/Ohana/src/libautocode/def/autocode.c	(revision 29439)
+++ trunk/Ohana/src/libautocode/def/autocode.c	(revision 29537)
@@ -25,35 +25,4 @@
 } 
 
-$STRUCT *gfits_downsize_and_convert_$STRUCT ($STRUCT *data, off_t size, off_t nitems) {
-
-  off_t i;
-  unsigned char *byte, tmp;
-  $STRUCT *output;
-
-  if ($SIZE > size) { 
-    fprintf (stderr, "ERROR: uncorrectable mismatch in data types $STRUCT: "OFF_T_FMT" vs %d\n",  size,  $SIZE);
-    exit (1);
-  }
-
-  // allocate a new array 
-  ALLOCATE (output, $STRUCT, nitems);
-  for (i = 0; i < nitems; i++) {
-    memcpy (&output[i], &data[i], $SIZE);
-  }
-
-  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
-  i = tmp = 0;
-  byte = NULL;
-
-# ifdef BYTE_SWAP
-  byte = (unsigned char *) output;
-  for (i = 0; i < nitems; i++, byte += size) {
-    /** BYTE SWAP **/
-  }
-# endif  
-
-  return (output);
-} 
-
 /*** add test of EXTNAME and header-defined columns? ***/
 /* return internal structure representation */
@@ -61,5 +30,5 @@
 
   int Ncols;
-  $STRUCT *data, *output;
+  $STRUCT *data;
 
   Ncols = ftable[0].header[0].Naxis[0];
@@ -73,8 +42,5 @@
   if ((swapped == NULL) || (*swapped == FALSE)) {
     if (!gfits_convert_$STRUCT (data, sizeof ($STRUCT), *Ndata)) {
-      output = gfits_downsize_and_convert_$STRUCT (data, sizeof ($STRUCT), *Ndata);
-      free (ftable[0].buffer);
-      ftable[0].buffer = (char *) output;
-      // XXX do I need to change NX?
+      return NULL;
     }
     gfits_table_scale_data (ftable);
Index: trunk/Ohana/src/libautocode/def/cmf-ps1-v3.d
===================================================================
--- trunk/Ohana/src/libautocode/def/cmf-ps1-v3.d	(revision 29537)
+++ trunk/Ohana/src/libautocode/def/cmf-ps1-v3.d	(revision 29537)
@@ -0,0 +1,117 @@
+# name of structure type
+STRUCT  CMF_PS1_V3
+EXTNAME CMF_PS1_V3
+TYPE    BINTABLE
+SIZE    200
+
+# elements of data structure / FITS table
+FIELD detID,          IPP_IDET,          unsigned int, detection ID                     
+FIELD X,              X_PSF,             float,    x coord,               pixels
+FIELD Y,              Y_PSF,             float,    y coord,               pixels
+FIELD dX,             X_PSF_SIG,         float,    x coord error,         pixels
+FIELD dY,             Y_PSF_SIG,         float,    y coord error,         pixels
+FIELD posangle,       POSANGLE,          float,    Posangle at source,    degrees
+FIELD pltscale,       PLTSCALE,          float,    Plate Scale at source, arcsec/pixel
+FIELD M,              PSF_INST_MAG,      float,    inst mags,             mags
+FIELD dM,             PSF_INST_MAG_SIG,  float,    inst mag error,        mags
+FIELD Flux,           PSF_INST_FLUX,     float,    psf flux,	       counts
+FIELD dFlux,          PSF_INST_FLUX_SIG, float,    psf flux error,        counts      
+FIELD Map,            AP_MAG_STANDARD,   float,    standard aperture mag, mags
+FIELD MapRaw,         AP_MAG_RAW,        float,    raw aperture mag,      mags
+FIELD apRadius,       AP_MAG_RADIUS,     float,    radius used for fit,   pixels
+FIELD Mcalib,         CAL_PSF_MAG,       float,    calibrated psf mag,    mags
+FIELD dMcal,          CAL_PSF_MAG_SIG,   float,    zero point scatter,    mags
+
+# NOTE: RA & DEC (both double) need to be on an 8-byte boundary...
+FIELD RA,             RA_PSF,            double,   PSF RA coord,          degrees
+FIELD DEC,            DEC_PSF,           double,   PSF DEC coord,         degrees
+
+FIELD Mpeak,          PEAK_FLUX_AS_MAG,  float,    peak flux as a mag,    mags
+FIELD sky,            SKY,               float,    sky flux,              cnts/sec
+FIELD dSky,           SKY_SIG,           float,    sky flux error,        cnts/sec
+FIELD psfChisq,       PSF_CHISQ,         float,    psf fit chisq
+FIELD crNsigma,       CR_NSIGMA,         float,    Nsigma deviations from PSF to CF
+FIELD extNsigma,      EXT_NSIGMA,        float,    Nsigma deviations from PSF to EXT
+FIELD fx,             PSF_MAJOR,         float,    psf fit major axis,    pixels
+FIELD fy,             PSF_MINOR,         float,    psf fit minor axis,    pixels
+FIELD df,             PSF_THETA,         float,    ellipse angle,         degrees
+FIELD psfQual,        PSF_QF,            float,    quality factor
+FIELD psfQualPerfect, PSF_QF_PERFECT,    float,    quality factor perfect
+FIELD psfNdof,        PSF_NDOF,          int,      psf degrees of freedom
+FIELD psfNpix,        PSF_NPIX,          int,      psf number of pixels
+FIELD Mxx,            MOMENTS_XX,        float,    second moment X,       pixels^2
+FIELD Mxy,            MOMENTS_XY,        float,    second moment Y,       pixels^2
+FIELD Myy,            MOMENTS_YY,        float,    second moment XY,      pixels^2
+FIELD M3c,            MOMENTS_M3C,       float,    third moment cos(t),   pixels^3
+FIELD M3s,            MOMENTS_M3S,       float,    third moment sin(t),   pixels^3
+FIELD M4c,            MOMENTS_M4C,       float,    fourth moment cos(t),  pixels^4
+FIELD M4s,            MOMENTS_M4S,       float,    fourth moment sin(t),  pixels^4
+FIELD Mr1,            MOMENTS_R1,        float,    first radial moment,   pixels
+FIELD Mrh,            MOMENTS_RH,        float,    half radial moment,    pixels^1/2
+FIELD kronFlux,       KRON_FLUX,         float,    kron flux,             counts
+FIELD kronFluxErr,    KRON_FLUX_ERR,     float,    kron flux error,       counts
+FIELD kronInner,      KRON_FLUX_INNER,   float,    kron flux 1<R<2.5,     counts
+FIELD kronOuter,      KRON_FLUX_OUTER,   float,    kron flux 2.5<R<4,     counts
+FIELD flags,          FLAGS,             int,      analysis flags
+FIELD flags2,         FLAGS,             int,      analysis flags (2)
+FIELD padding2,       PADDING,           int,      padding for 8byte records
+FIELD nFrames,        N_FRAMES,          short,    images overlapping peak
+FIELD padding,        PADDING,           short,    padding for 8byte records
+
+# for an object in an image, we have three triplets that tell us about the shape:
+# second moments: Mxx, Mxy, Myy 
+# model shape parameters: F_major, F_minor, F_theta
+# centroid errors: sigma_X, sigma_Y, sigma_XY
+
+# # elements of data structure / FITS table
+# FIELD detID,          IPP_IDET,          IPP_IDET           1J      unsigned int, detection ID                     
+# FIELD X,              X_PSF,             X_PSF              1E      float,    x coord,               pixels
+# FIELD Y,              Y_PSF,             Y_PSF              1E      float,    y coord,               pixels
+# FIELD dX,             X_PSF_SIG,         X_PSF_SIG          1E      float,    x coord error,         pixels
+# FIELD dY,             Y_PSF_SIG,         Y_PSF_SIG          1E      float,    y coord error,         pixels
+# FIELD posangle,       POSANGLE,          POSANGLE           1E      float,    Posangle at source,    degrees
+# FIELD pltscale,       PLTSCALE,          PLTSCALE           1E      float,    Plate Scale at source, arcsec/pixel
+# FIELD M,              PSF_INST_MAG,      PSF_INST_MAG       1E      float,    inst mags,             mags
+# FIELD dM,             PSF_INST_MAG_SIG,  PSF_INST_MAG_SIG   1E      float,    inst mag error,        mags
+# FIELD flux,           PSF_INST_FLUX,     PSF_INST_FLUX      1E      float,    psf flux,	       counts
+# FIELD flux,           PSF_INST_FLUX_SIG, PSF_INST_FLUX_SIG  1E      float,    psf flux error,        counts      
+# FIELD Map,            AP_MAG_STANDARD,   AP_MAG             1E      float,    standard aperture mag, mags
+# FIELD Map,            AP_MAG_RAW,        AP_MAG_RAW         1E      float,    raw aperture mag,      mags
+# FIELD apRadius,       AP_MAG_RADIUS,     AP_MAG_RADIUS      1E      float,    radius used for fit,   pixels
+# FIELD Mpeak,          PEAK_FLUX_AS_MAG,  PEAK_FLUX_AS_MAG   1E      float,    peak flux as a mag,    mags
+# FIELD Mcalib,         CAL_PSF_MAG,       CAL_PSF_MAG        1E      float,    calibrated psf mag,    mags
+# FIELD dMcal,          CAL_PSF_MAG_SIG,   CAL_PSF_MAG_SIG    1E      float,    zero point scatter,    mags
+# FIELD RA,             RA_PSF,            RA_PSF             1D      double,   PSF RA coord,          degrees
+# FIELD DEC,            DEC_PSF,           DEC_PSF            1D      double,   PSF DEC coord,         degrees
+# FIELD sky,            SKY,               SKY                1E      float,    sky flux,              cnts/sec
+# FIELD dSky,           SKY_SIG,           SKY_SIGMA          1E      float,    sky flux error,        cnts/sec
+# FIELD psfChisq,       PSF_CHISQ,         PSF_CHISQ          1E      float,    psf fit chisq
+# FIELD crNsigma,       CR_NSIGMA,         CR_NSIGMA          1E      float,    Nsigma deviations from PSF to CF
+# FIELD extNsigma,      EXT_NSIGMA,        EXT_NSIGMA         1E      float,    Nsigma deviations from PSF to EXT
+# FIELD fx,             PSF_MAJOR,         PSF_MAJOR          1E      float,    psf fit major axis,    pixels
+# FIELD fy,             PSF_MINOR,         PSF_MINOR          1E      float,    psf fit minor axis,    pixels
+# FIELD df,             PSF_THETA,         PSF_THETA          1E      float,    ellipse angle,         degrees
+# FIELD psfQual,        PSF_QF,            PSF_QF             1E      float,    quality factor
+# FIELD psfQualPerfect, PSF_QF_PERFECT,    PSF_QF_PERFECT     1E      float,    quality factor perfect
+# FIELD psfNdof,        PSF_NDOF,          PSF_NDOF           1J      int,      psf degrees of freedom
+# FIELD psfNpix,        PSF_NPIX,          PSF_NPIX           1J      int,      psf number of pixels
+# FIELD Mxx,            MOMENTS_XX,        MOMENTS_XX         1E      float,    second moment X,       pixels^2
+# FIELD Mxy,            MOMENTS_XY,        MOMENTS_XY         1E      float,    second moment Y,       pixels^2
+# FIELD Myy,            MOMENTS_YY,        MOMENTS_YY         1E      float,    second moment XY,      pixels^2
+# FIELD M3c,            MOMENTS_M3C,       MOMENTS_M3C        1E      float,    third moment cos(t),   pixels^3
+# FIELD M3s,            MOMENTS_M3S,       MOMENTS_M3S        1E      float,    third moment sin(t),   pixels^3
+# FIELD M4c,            MOMENTS_M4C,       MOMENTS_M4C        1E      float,    fourth moment cos(t),  pixels^4
+# FIELD M4s,            MOMENTS_M4S,       MOMENTS_M4S        1E      float,    fourth moment sin(t),  pixels^4
+# FIELD Mr1,            MOMENTS_R1,        MOMENTS_R1         1E      float,    first radial moment,   pixels
+# FIELD Mrh,            MOMENTS_RH,        MOMENTS_RH         1E      float,    half radial moment,    pixels^1/2
+# FIELD kronFlux,       KRON_FLUX,         KRON_FLUX          1E      float,    kron flux,             counts
+# FIELD kronFluxErr,    KRON_FLUX_ERR,     KRON_FLUX_ERR      1E      float,    kron flux error,       counts
+# FIELD kronInner,      KRON_FLUX_INNER,   KRON_FLUX_INNER    1E      float,    kron flux 1<R<2.5,     counts
+# FIELD kronOuter,      KRON_FLUX_OUTER,   KRON_FLUX_OUTER    1E      float,    kron flux 2.5<R<4,     counts
+# FIELD flags,          FLAGS,             FLAGS              1J      int,      analysis flags
+# FIELD flags2,         FLAGS,             FLAGS2             1J      int,      analysis flags (2)
+# FIELD nFrames,        N_FRAMES,          N_FRAMES           1I      short,    images overlapping peak
+# FIELD padding,        PADDING,           PADDING            1I      short,    padding for 8byte records
+
+      
+
Index: trunk/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c
===================================================================
--- trunk/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 29439)
+++ trunk/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 29537)
@@ -1,3 +1,10 @@
 # include "dvo.h"
+
+/* if we are not correctly including the ohana headers, this will fail */
+# ifndef BYTE_SWAP
+# ifndef NOT_BYTE_SWAP
+# error "neither BYTE_SWAP not NOT_BYTE_SWAP is set"
+# endif
+# endif
 
 CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, off_t *Ndata, char *swapped) {
Index: trunk/Ohana/src/libfits/header/F_H_field.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_H_field.c	(revision 29439)
+++ trunk/Ohana/src/libfits/header/F_H_field.c	(revision 29537)
@@ -11,4 +11,7 @@
 
   if (header[0].buffer == NULL) return NULL;
+
+  // regular keywords cannot be larger than 8 chars (use HIERARCH instead)
+  if (strlen(field) > 8) return NULL; 
 
   /* create a blank-padded keyword with exactly 8 characters */
Index: trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- trunk/Ohana/src/libfits/include/gfitsio.h	(revision 29439)
+++ trunk/Ohana/src/libfits/include/gfitsio.h	(revision 29537)
@@ -13,4 +13,5 @@
 # endif
 
+/* if we are not correctly including the ohana headers, this will fail */
 # ifndef NEWLINE
 # define NEWLINE                 10  /* UNIX RETURN character */
Index: trunk/Ohana/src/libkapa/include/kapa.h
===================================================================
--- trunk/Ohana/src/libkapa/include/kapa.h	(revision 29439)
+++ trunk/Ohana/src/libkapa/include/kapa.h	(revision 29537)
@@ -12,4 +12,11 @@
 # include <png.h>
 # include <dvo.h>
+
+/* if we are not correctly including the ohana headers, this will fail */
+# ifndef BYTE_SWAP
+# ifndef NOT_BYTE_SWAP
+# error "neither BYTE_SWAP not NOT_BYTE_SWAP is set"
+# endif
+# endif
 
 typedef struct sockaddr_in KapaSockAddress;
Index: trunk/Ohana/src/libkapa/src/RotFont.c
===================================================================
--- trunk/Ohana/src/libkapa/src/RotFont.c	(revision 29439)
+++ trunk/Ohana/src/libkapa/src/RotFont.c	(revision 29537)
@@ -10,7 +10,12 @@
 static RotFont *currentfont;
 
+static int RotFontInited = FALSE;
+
 void InitRotFonts () {
 
   int i, Nhardwired;
+
+  if (RotFontInited) return;
+  RotFontInited = TRUE;
 
   Nhardwired = sizeof (HardwiredFonts) / sizeof (FontSet);
@@ -32,4 +37,6 @@
   
   int i, nsize, msize, bsize, bigger, dsize, match, good;
+
+  InitRotFonts();
 
   bigger = good = match = -1;
@@ -69,4 +76,6 @@
 char *GetRotFont (int *size) {
 
+  InitRotFonts();
+
   *size = currentsize;
   return (currentname);
@@ -75,4 +84,7 @@
 
 RotFont *GetRotFontData (double *scale) {
+
+  InitRotFonts();
+
   *scale = currentscale;
   return (currentfont);
@@ -84,4 +96,6 @@
   double scale; 
   
+  InitRotFonts();
+
   scale = currentscale;
 
Index: trunk/Ohana/src/libkapa/src/bDrawFuncs.c
===================================================================
--- trunk/Ohana/src/libkapa/src/bDrawFuncs.c	(revision 29439)
+++ trunk/Ohana/src/libkapa/src/bDrawFuncs.c	(revision 29537)
@@ -1,3 +1,7 @@
 # include <kapa_internal.h>
+
+// XXX we can get rid of these static vars by making them elements of the bDrawBuffer
+// 
+
 
 static int bWeight;
Index: trunk/Ohana/src/libohana/include/ohana.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana.h	(revision 29439)
+++ trunk/Ohana/src/libohana/include/ohana.h	(revision 29537)
@@ -94,7 +94,20 @@
 };
 
-/* note: in the Ohana tree, the byte order is determined by the ARCH variable
-   if you have a small endian machine that is not listed here, the test
-   program 'typestest' should fail */
+/* Some notes on the Ohana BYTE_SWAP macros:
+
+   1) BYTE_SWAP is set in this file based on the environment variable 'ARCH', which is in turn
+   set by the psconfig system (or is set manually by the builder).  
+
+   2) BYTE_SWAP is only used when building the Ohana tree: code which links against Ohana
+   (eg, libkapa or others) does not need to have this value correctly set.
+   
+   3) the libohana build tests for the validity of the BYTE_SWAP choice by running the test
+   program 'typestest' and raising an error if the tests fail.
+
+   4) if your build fails due to the typestest program, check your value of 'ARCH' and if
+   necessary add it to the list below.
+
+*/
+
 # ifndef BYTE_SWAP
 # ifdef linux
@@ -117,7 +130,10 @@
 # define BYTE_SWAP
 # endif
-# else
+# endif /* BYTE_SWAP */
+
+/* other Ohana components use these two values to check that ohana.h was correctly included */
+# ifndef BYTE_SWAP
 # define NOT_BYTE_SWAP
-# endif /* BYTE_SWAP */
+# endif
 
 # ifndef NAN
Index: trunk/Ohana/src/libohana/src/Fread.c
===================================================================
--- trunk/Ohana/src/libohana/src/Fread.c	(revision 29439)
+++ trunk/Ohana/src/libohana/src/Fread.c	(revision 29537)
@@ -14,17 +14,4 @@
   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;
-
-/** this is also used in libautocode/def/common.h -- consolidate **/
-# ifdef linux
-# define BYTE_SWAP
-# endif
-
-# ifdef sid
-# define BYTE_SWAP
-# endif
-
-# ifdef dec
-# define BYTE_SWAP
-# endif
 
 /* add other architectures here, ie dec, alpha, etc */ 
