Index: /branches/eam_branches/ipp-20100823/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/addstar/include/addstar.h	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/addstar/include/addstar.h	(revision 29412)
@@ -253,4 +253,5 @@
 Stars     *Convert_PS1_V1_Alt	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_V2	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_V3	  PROTO((FTable *table, unsigned int *nstars));
 
 int        InitStar               PROTO((Stars *star));
Index: /branches/eam_branches/ipp-20100823/Ohana/src/addstar/src/MatchHeaders.c
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/addstar/src/MatchHeaders.c	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/addstar/src/MatchHeaders.c	(revision 29412)
@@ -57,4 +57,5 @@
     if (!strcmp (exttype, "PS1_V1")) goto keep;
     if (!strcmp (exttype, "PS1_V2")) goto keep;
+    if (!strcmp (exttype, "PS1_V3")) goto keep;
     continue;
 
Index: /branches/eam_branches/ipp-20100823/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 29412)
@@ -47,4 +47,7 @@
     stars = Convert_PS1_V2 (&table, &Nstars);
   }
+  if (!strcmp (type, "PS1_V3")) {
+    stars = Convert_PS1_V3 (&table, &Nstars);
+  }
   if (stars == NULL) {
     fprintf (stderr, "ERROR: invalid table type %s\n", type);
@@ -426,2 +429,70 @@
   return (stars);
 }
+
+Stars *Convert_PS1_V3 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
+  double ZeroPt;
+  Stars *stars;
+  CMF_PS1_V3 *ps1data;
+
+  ps1data = gfits_table_get_CMF_PS1_V3 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
+  ZeroPt = GetZeroPoint();
+
+  ALLOCATE (stars, Stars, Nstars);
+  for (i = 0; i < Nstars; i++) {
+    InitStar (&stars[i]);
+    stars[i].measure.Xccd       = ps1data[i].X;
+    stars[i].measure.Yccd       = ps1data[i].Y;
+    stars[i].measure.dXccd      = ShortPixels(ps1data[i].dX);
+    stars[i].measure.dYccd      = ShortPixels(ps1data[i].dY);
+
+    stars[i].measure.posangle   = ShortDegree(ps1data[i].posangle);
+    stars[i].measure.pltscale   = ps1data[i].pltscale;
+
+    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
+	stars[i].measure.M      = NAN;
+    } else {
+	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+    }
+    stars[i].measure.dM         = ps1data[i].dM;
+    stars[i].measure.dMcal      = ps1data[i].dMcal;
+    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
+		        
+    stars[i].measure.Sky        = ps1data[i].sky;
+    stars[i].measure.dSky       = ps1data[i].dSky;
+		        
+    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
+    stars[i].measure.psfQual    = ps1data[i].psfQual;
+    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
+    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
+    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
+    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
+
+    stars[i].measure.FWx        = ShortPixels(ps1data[i].fx);
+    stars[i].measure.FWy        = ShortPixels(ps1data[i].fy);
+    stars[i].measure.theta      = ShortDegree(ps1data[i].df);
+
+    stars[i].measure.Mxx        = ShortPixels(ps1data[i].Mxx);
+    stars[i].measure.Mxy        = ShortPixels(ps1data[i].Mxy);
+    stars[i].measure.Myy        = ShortPixels(ps1data[i].Myy);
+		        
+    stars[i].measure.photFlags  = ps1data[i].flags;
+
+    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
+    stars[i].measure.detID      = ps1data[i].detID; 
+
+    // the Average fields and the following Measure fields are set in FilterStars after
+    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID, 
+    // averef is set in find_matches, dbFlags is zero on ingest.
+
+    // the following fields are currently not being set anywhere: t_msec
+  }    
+  *nstars = Nstars;
+  return (stars);
+}
Index: /branches/eam_branches/ipp-20100823/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libautocode/Makefile.Targets	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libautocode/Makefile.Targets	(revision 29412)
@@ -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: /branches/eam_branches/ipp-20100823/Ohana/src/libautocode/def/autocode.c
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libautocode/def/autocode.c	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libautocode/def/autocode.c	(revision 29412)
@@ -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: /branches/eam_branches/ipp-20100823/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 29412)
@@ -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: /branches/eam_branches/ipp-20100823/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libfits/include/gfitsio.h	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libfits/include/gfitsio.h	(revision 29412)
@@ -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: /branches/eam_branches/ipp-20100823/Ohana/src/libkapa/include/kapa.h
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libkapa/include/kapa.h	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libkapa/include/kapa.h	(revision 29412)
@@ -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: /branches/eam_branches/ipp-20100823/Ohana/src/libohana/include/ohana.h
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libohana/include/ohana.h	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libohana/include/ohana.h	(revision 29412)
@@ -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: /branches/eam_branches/ipp-20100823/Ohana/src/libohana/src/Fread.c
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/libohana/src/Fread.c	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/libohana/src/Fread.c	(revision 29412)
@@ -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 */ 
Index: /branches/eam_branches/ipp-20100823/Ohana/src/mosastro/src/ConvertMatch.c
===================================================================
--- /branches/eam_branches/ipp-20100823/Ohana/src/mosastro/src/ConvertMatch.c	(revision 29411)
+++ /branches/eam_branches/ipp-20100823/Ohana/src/mosastro/src/ConvertMatch.c	(revision 29412)
@@ -11,16 +11,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;
-
-# ifdef linux
-# define BYTE_SWAP
-# endif
-
-# ifdef sid
-# define BYTE_SWAP
-# endif
-
-# ifdef dec
-# define BYTE_SWAP
-# endif
 
 # define MATCH_SIZE 104
