Index: /branches/eam_branch_20080223/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/Makefile	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/Makefile	(revision 16698)
@@ -13,5 +13,5 @@
 
 # programs may add their own internal requirements here
-FULL_CFLAGS   = $(BASE_CFLAGS)
+FULL_CFLAGS   = $(BASE_CFLAGS) -Wall -Werror
 FULL_CPPFLAGS = $(BASE_CPPFLAGS)
 FULL_LDFLAGS  = -lkapa -ldvo -lFITS -lohana $(BASE_LDFLAGS)
@@ -59,4 +59,8 @@
 $(SRC)/grefstars.$(ARCH).o \
 $(SRC)/LoadStars.$(ARCH).o \
+$(SRC)/LoadHeaders.$(ARCH).o \
+$(SRC)/MatchHeaders.$(ARCH).o \
+$(SRC)/LoadData.$(ARCH).o \
+$(SRC)/LoadDataSDSS.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
@@ -67,8 +71,10 @@
 $(SRC)/ReadStarsFITS.$(ARCH).o \
 $(SRC)/ReadStarsTEXT.$(ARCH).o \
+$(SRC)/ReadStarsSDSS.$(ARCH).o \
 $(SRC)/FilterStars.$(ARCH).o \
 $(SRC)/ImageOptions.$(ARCH).o \
 $(SRC)/GetFileMode.$(ARCH).o \
 $(SRC)/ReadImageHeader.$(ARCH).o \
+$(SRC)/UpdateImageIDs.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o
 
@@ -165,4 +171,8 @@
 $(SRC)/ConfigInit.$(ARCH).o \
 $(SRC)/LoadStars.$(ARCH).o \
+$(SRC)/LoadHeaders.$(ARCH).o \
+$(SRC)/MatchHeaders.$(ARCH).o \
+$(SRC)/LoadData.$(ARCH).o \
+$(SRC)/LoadDataSDSS.$(ARCH).o \
 $(SRC)/grefstars.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
@@ -172,4 +182,6 @@
 $(SRC)/ReadImageHeader.$(ARCH).o \
 $(SRC)/ReadStarsTEXT.$(ARCH).o \
+$(SRC)/ReadStarsSDSS.$(ARCH).o \
+$(SRC)/UpdateImageIDs.$(ARCH).o \
 $(SRC)/FilterStars.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
@@ -189,4 +201,5 @@
 $(SRC)/load2mass_catalog.$(ARCH).o \
 $(SRC)/get2mass_ops.$(ARCH).o \
+$(SRC)/get2mass_full.$(ARCH).o \
 $(SRC)/find_matches_refstars.$(ARCH).o \
 $(SRC)/args_load2mass.$(ARCH).o \
Index: /branches/eam_branch_20080223/Ohana/src/addstar/doc/2mass.txt
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/doc/2mass.txt	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/doc/2mass.txt	(revision 16698)
@@ -0,0 +1,115 @@
+
+2MASS PSC fields:
+
+ra, dec : obvious
+
+err_maj, err_min, err_ang : I only have ra_err and dec_err.  should I upgrade my tables?
+(put these in FHx, FWy, theta)
+
+designation (2mass ID) : ignore this?  potentially derivable from position
+
+j_m -> M
+j_cmsig -> dM
+j_msigcom : I don't yet have a systematic error term; add this in
+j_snr : another way of representing the error : the implied error is the MODE of dM for the scan
+
+(repeat for h, k)
+
+ph_qual[j] : using letters to represent 8 states: (3bit needed)
+
+0x0000 * "X" - There is a detection at this location, but no valid brightness estimate can be extracted using any algorithm. rd_flg="9" and default magnitude is null.
+0x0001 * "U" - Upper limit on magnitude. Source is not detected in this band (rd_flg="0"), or it is detected, but not resolved in a consistent fashion with other bands (rd_flg="6"). A value of ph_qual="U" does not necessarily mean that there is no flux detected in this band at the location. Whether or not flux has been detected can be determined from the value of rd_flg. When rd_flg="0", no flux has been detected. When rd_flg="6", flux has been detected at the location where the images were not deblended consistently in all three bands (JHKs).
+0x0002 * "F" - This category includes rd_flg="1" or rd_flg="3" sources where a reliable estimate of the photometric error, [jhk]_cmsig, could not be determined. The uncertainties reported for these sources in [jhk]_cmsig and [jhk]_msigcom are flags and have numeric values >8.0.
+0x0003 * "E" - This category includes detections where the goodness-of-fit quality of the profile-fit photometry was very poor (rd_flg=2 and [jhk]psf_chi>10.0), or detections where psf fit photometry did not converge and an aperture magnitude is reported (rd_flg=4), or detections where the number of frames was too small in relation to the number of frames in which a detection was geometrically possible (rd_flg="1" or rd_flg="2").
+0x0004 * "A" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>10 AND [jhk]_cmsig<0.10857.
+0x0005 * "B" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>7 AND [jhk]_cmsig<0.15510.
+0x0006 * "C" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>5 AND [jhk]_cmsig<0.21714.
+0x0007 * "D" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with no [jhk]_snr or [jhk]_cmsig requirement.
+
+rd_flag[j] : using numbers to represent 7 states:
+
+0x0000 * "0" - Source is not detected in this band. The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20".
+0x0010 * "1" - The default magnitude is derived from aperture photometry measurements on the 51 ms "Read_1" exposures. The aperture radius is 4", with the sky background measured in an annulus with an inner radius of 14" and an outer radius of 20". Used for sources that saturate one or more of the 1.3s "Read_2" exposures, but are not saturated on at least one of the 51 ms "Read_1" frames.
+0x0020 * "2" - The default magnitude is derived from a profile-fitting measurement made on the 1.3 sec "Read_2" exposures. The profile-fit magnitudes are normalized to curve-of-growth-corrected aperture magnitudes. This is the most common type in the PSC, and is used for sources that have no saturated pixels in any of the 1.3 sec exposures.
+0x0030 * "3" - The default magnitude is derived from a 1-d radial profile fitting measurement made on the 51 ms "Read_1" exposures. Used for very bright sources that saturate all of the 51 ms "Read 1" exposures.
+0x0040 * "4" - The default magnitude is derived from curve-of-growth-corrected 4" radius aperture photometry measurements on the 1.3 s "Read_2" exposures. This is used for sources that are not saturated in any of the Read_2 frames, but where the profile-fitting measurements fail to converge to a solution. These magnitudes are the same as the standard aperture magnitudes (j_m_stdap, h_m_stdap, k_m_stdap), but when they are the default magnitudes, it generally implies that they are low quality measurements.
+0x0050 * "6" - The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20". This is used for pairs of sources which are detected and resolved in another band, but are detected and not resolved in this band. This differs from a rd_flg="0" because in this case there is a detection of the source in this band, but it is not consistently resolved across all bands.
+0x0060 * "9" - The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20". This is used for sources that were nominally detected in this band, but which could not have a useful brightness measurement from either profile fitting or aperture photometry. This often occurs in highly confused regions, or very near Tile edges where a significant fraction of the measurement aperture of sky annulus falls off the focal plane.
+
+bl_flag[j] : 3 states:
+
+    * "0" - Source is not detected, or is inconsistently deblended in that band.
+    * "1" - One component was fit to the source in R_2 profile-fitting photometry (rd_flg="2"), or default magnitudes are from aperture photometry (rd_flg="1" or "4") or saturated star 1-d radial profile-fitting (rd_flg="3").
+    * ">1" - More than one component was fit simultaneously during R2 profile-fit photometry, where the value of the field is the number of components simultaneously fit. The maximum number of components is 7 in any band for the PSC, so this bl_flg is always a three character flag. Multi-component fitting occurs only for profile-fitting, and only when more than one detection is found within ~5". Single detections that are not well-fit by a single PSF are not split.
+
+cc_flag[j] : 6 states:
+
+    * "p" = Persistence. Source may be contaminated by a latent image left by a nearby bright star.
+    * "c" = Photometric Confusion. Source photometry is biased by a nearby star that has contaminated the background estimation. This is very common in high source density regions.
+    * "d" = Diffraction spike confusion. Source may be contaminated by a diffraction spike from a nearby star.
+    * "s" = Electronic stripe. Source measurement may be contaminated by a stripe from a nearby bright star.
+    * "b" = Bandmerge confusion. In the process of merging detections in the different bands for this source, there was more than one possible match between the different band components. This occurs in regions of very high source density, or when multiple sources were split in one band but not another.
+    * "0" = Source is unaffected by known artifacts, or is not detected in the band.
+
+ndet : number of frames detected, number of frames available (carry this somehow?)
+
+prox : distance to nearest neighbor (unneeded)
+pxpa : direction to nearest neighbor (unneeded)
+pxcntr : id of nearest neighbor
+
+gal_contam : is source close to or part of an extended source? (3 states)
+
+mp_flg : associated with know Solar System object
+
+pts_key/cntr : 2MASS internal object ID
+
+hemis : (which observatory -- replace with a photcode?)
+
+date -> ignore (not accurate)
+
+scan : scan in which it was detected (unneeded)
+
+glon, glat : derivable
+
+x_scan : pixel location in x direction -> Xccd
+
+jdate : time stamp with ~30 sec accuracy
+
+j_psfchi : fit chi sqare -> psfProb (needs to be changed in measure.d anyway)
+
+j_m_stdap : aperture magnitude -> Mgal (change to Map anyway)
+
+j_msig_stdap : aperture magnitude error (keep ??)
+
+dist_edge_ns, ew, flg : information about distance to scan edge (ns or ew)
+
+dup_src : duplicate scan 
+use_src : ??
+
+(ignore the fields for cross-correlation with other surveys)
+
+counting the flag bits (no attempt to account for any duplicate info; ignoring dist_edge info):
+
+ph_qual	   : 3 bits
+rd_flag	   : 3 bits
+bl_flag	   : 2 bits 
+cc_flag	   : 3 bits
+gal_contam : 2 bits
+mp_flag	   : 1 bit
+dup_src	   : 1 bit
+use_src	   : 1 bit
+
+total      : 17 bit (1 too many...)
+
+counting the flag bits (trying to minimize duplicate info; ignoring dist_edge info):
+
+ph_qual	   : 3 bits 0x0001 - 0x0007
+bl_flag	   : 1 bit  0x0008 (bl_flag = 0 or 1 -> 0; bl_flag > 1 -> 1)
+rd_flag	   : 3 bits 0x0010 - 0x0070
+gal_contam : 1 bit  0x0080 (gal_contam = 0 or 1 -> 0; gal_contam = 2 -> 1) (set extNsigma to a high value if gal_contam = 1) 
+cc_flag	   : 3 bits 0x0100 - 0x0700
+mp_flag	   : 1 bit  0x0800
+dup_src	   : 1 bit  0x1000 (0 or 1 -> 0; > 1 -> 1)
+use_src	   : 1 bit  0x2000 
+
+total      : 14 bits
Index: /branches/eam_branch_20080223/Ohana/src/addstar/doc/sdss-tsObj.txt
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/doc/sdss-tsObj.txt	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/doc/sdss-tsObj.txt	(revision 16698)
@@ -0,0 +1,686 @@
+.
+  Calibrated Objects
+
+*File Format:* FITS binary table
+
+*Name:* /tsObj-rrrrrr-c-v-ffff.fit/, where /rrrrrr/ is the imaging run
+number, /c/ is the camera column (1-6), and /v/ is the rerun number and
+ffff is the first field number of the segment.
+
+*Produced by:* ts
+
+*Used by:* ts, sx
+
+*Size:* 7 * 2880 + (2240 * Nstars) {rounded up to nearest multiple of
+2880) * Nfields. For a single pipeline run with 1000 fields, 400 objects
+per field, 887.06 Mb.
+
+*Archived?* Yes, by sx.
+
+
+    Description
+
+Calibrated version of the object lists put out by the /frames/ pipeline.
+
+
+    Primary Header
+
+SIMPLE  =                    T
+BITPIX  =                    8
+NAXIS   =                    0
+EXTEND  =                    T
+RUN     =                  XXX / Imaging run number.
+CAMCOL  =                  XXX / Column in the imaging camera.
+RERUN   =                  XXX / Rerun number
+FIELD0  =                  XXX / First field reduced.
+NFIELDS =                  XXX / Number of fields reduced.
+STRIPE  =                  XXX / Stripe number
+STRIP   = 'X       '           / N - north, S - south
+EQUINOX =          XXXX.XXXXXX / Equinox of great circle scanned (Julian years)
+NODE    =           XXX.XXXXXX / Ascending node of great circle scanned (deg)
+INCL    =           XXX.XXXXXX / Inclincation of great circle scanned (deg)
+C_OBS   =            XXXXX.XXX / CCD clock rate (usec/unbinned-row)
+TRACKING=            XXXXX.XXX / Tracking rate (arcsec/TAI-sec)
+PHOTO_ID= 'XXX     '           / Photometric pipeline run id.
+TASTR_ID= 'XXX     '           / Astrometric pipeline run id for target.
+EASTR_ID= 'XXX     '           / Astrometric pipeline run id for export.
+TFCAL_ID= 'XXX     '           / Photometric calibration run id for target.
+EFCAL_ID= 'XXX     '           / Photometric calibration run id for export.
+PHOT_VER= 'XXX     '           / Version of frames pipeline used.
+TAST_VER= 'XXX     '           / Version of astrometric pipeline for target.
+EAST_VER= 'XXX     '           / Version of astrometric pipeline for export.
+TFCA_VER= 'XXX     '           / Version of fcalib for target.
+EFCA_VER= 'XXX     '           / Version of fcalib for export.
+TARG_VER= 'XXX     '           / Version of target pipeline used.
+EXPO_VER= 'XXX     '           / Version of export pipeline used.
+FILTERS = 'XXX XXX ...'        / Filter order in array fields
+OBJ_SRC = 'XXX     '           / Source of objects:
+COMMENT                        /    OPDB_PRELIM = OPDB, preliminary data
+COMMENT                        /    OPDB_EXPORT = OPDB, exported to SX
+COMMENT                        /    SX          = Science Database
+COMMENT                        /    FLATFILES   = Flat files
+TARG_SRC= 'XXX     '           / Source of target info:
+COMMENT                        /    OPDB_PRELIM = OPDB, preliminary data
+COMMENT                        /    OPDB_EXPORT = OPDB, exported to SX
+COMMENT                        /    SX          = Science Database
+COMMENT                        /    FLATFILES   = Flat files
+RESOLVED=                    T / Data from a resolved segment
+EXPORTED=                  XXX / Type of objects exported in this file:
+COMMENT                        /    1 = spectroscopic targets only
+COMMENT                        /    2 = primaries only
+COMMENT                        /    3 = primaries and secondaries
+COMMENT                        /    4 = all objects
+FAMILIES=                    T / Contains family members of included objects
+REF_BAND=                    2 / band used for canonical centre
+DARK_VAR= '4 4 4 4 4'          / Per-pixel variances at zero DN (DN^2)
+GAIN    = '3.5 3.5 3.5 3.5 3.5' / Mean gains of amplifiers (e/DN)
+END                         
+
+
+    Table Header
+
+There is one HDU of this type in the file for each field, ordered by
+field number. The "QUALITY" keyword records the quality of data in the
+field, in terms of its acceptance for the survey, and can take the
+following meanings:
+
+  'BAD      '   /* Not acceptable for the survey */
+  'ACCEPTABLE'  /* Acceptable for the survey, but we'd better data */
+  'GOOD     '   /* Fully acceptable --- no desire for better data */
+  'MISSING  '   /* No objects in this field, because data is missing, but we
+                 * accept the field into the survey as a hole in the survey */
+  'HOLE     '   /* Data in this field is not acceptable, but we will accept the
+                 * field into the survey as a hole in the survey, meaning none
+                 * of the objects in the field are part of the survey */
+
+The "STATUS_X" keywords record the status of the PSF fit for that field
+in that filter, and can take the following meanings:
+
+  'UNKNOWN  '    /* ??? */
+  'OK       '    /* PSF fitted by 2nd order parabolas */
+  'PSF22    '    /* PSF fitted by linear functions */
+  'PSF11    '    /* PSF fitted by a constant */
+  'NOPSF    '    /* PSF fit from previous frame used*/
+  'ABORTED  '    /* ??? */
+  'MISSING  '    /* ??? */
+
+PSP_STAT is the maximum value of STATUS_X over all 5 filters.
+
+The /objc_type/, /objc_flags/, /objc_flags2/, /flags/, /flags2/, and
+/type/ fields are enumerated types or bit masks, with the same set of
+legal values as found for the same fields in the fpObjc <fpObjc.html> file.
+
+The /status/ field is a bit mask specifying the status of the object in
+the survey. The bits are defined as:
+
+  AR_OBJECT_STATUS_SET        = 0x1,    /* This object's status has been set */
+					/* in reference to its own run.      */
+  AR_OBJECT_STATUS_GOOD       = 0x2,    /* Good as determined by its         */
+					/* object flags.  Absence implies    */
+                                        /* bad.  This flag is set by         */
+                                        /* "setObjectStatus".                */
+  AR_OBJECT_STATUS_DUPLICATE  = 0x4,    /* This object has one or more       */
+					/* duplicate detections in an        */
+					/* adjacent field of the same Frames */
+					/* Pipeline Run.  This is set by     */
+					/* "setObjectStatus".                */
+  AR_OBJECT_STATUS_OK_RUN     = 0x10,   /* Located within the primary range  */
+					/* of rows for this field.  This is  */
+                                        /* usable object.  This flag is set  */
+                                        /* by "setObjectStatus".             */
+  AR_OBJECT_STATUS_RESOLVED   = 0x20,   /* This object has been resolved     */
+					/* against other runs.               */
+  AR_OBJECT_STATUS_PSEGMENT   = 0x40,   /* Belongs to a PRIMARY segment.     */
+					/* This does not imply that this is a*/
+					/* primary object.                   */
+  AR_OBJECT_STATUS_FIRST_FIELD= 0x100,  /* Belongs to the first field in its */
+					/* segment.  Used to distinguish     */
+					/* objects in fields shared by two   */
+					/* segments.                         */
+  AR_OBJECT_STATUS_OK_SCANLINE= 0x200,  /* Lies within valid nu range        */
+					/* for its scanline.                 */
+  AR_OBJECT_STATUS_OK_STRIPE  = 0x400,  /* Lies within valid eta range for   */
+					/* its stripe.                       */
+  AR_OBJECT_STATUS_SECONDARY  = 0x1000, /* This is a secondary survey object.*/
+  AR_OBJECT_STATUS_PRIMARY    = 0x2000, /* This is a primary survey object.  */
+  AR_OBJECT_STATUS_TARGET     = 0x4000  /* This is a spectroscopic target.   */
+
+The /primTarget/ field is a bit mask specifying which primary target
+catagories the object was selected in. The bits are defined as:
+
+  AR_TARGET_QSO_HIZ           = 0x1,
+  AR_TARGET_QSO_CAP           = 0x2,
+  AR_TARGET_QSO_SKIRT         = 0x4,
+  AR_TARGET_QSO_FIRST_CAP     = 0x8,
+  AR_TARGET_QSO_FIRST_SKIRT   = 0x10,
+  AR_TARGET_QSO_MAG_OUTLIER  = 0x2000000,
+  AR_TARGET_QSO_REJECT	      = 0x20000000,
+  AR_TARGET_GALAXY_RED        = 0x20,
+  AR_TARGET_GALAXY_RED_II     = 0x4000000,
+  AR_TARGET_GALAXY            = 0x40,
+  AR_TARGET_GALAXY_BIG        = 0x80,
+  AR_TARGET_GALAXY_BRIGHT_CORE= 0x100,
+  AR_TARGET_ROSAT_A           = 0x200,
+  AR_TARGET_ROSAT_B           = 0x400,
+  AR_TARGET_ROSAT_C           = 0x800,
+  AR_TARGET_ROSAT_D           = 0x1000,
+  AR_TARGET_ROSAT_E           = 0x8000000,
+  AR_TARGET_STAR_BHB          = 0x2000,
+  AR_TARGET_STAR_CARBON       = 0x4000,
+  AR_TARGET_STAR_BROWN_DWARF  = 0x8000,
+  AR_TARGET_STAR_SUB_DWARF    = 0x10000,
+  AR_TARGET_STAR_CATY_VAR     = 0x20000,
+  AR_TARGET_STAR_RED_DWARF    = 0x40000,
+  AR_TARGET_STAR_WHITE_DWARF  = 0x80000,
+  AR_TARGET_STAR_PN           = 0x10000000,
+  AR_TARGET_SERENDIP_BLUE     = 0x100000,
+  AR_TARGET_SERENDIP_FIRST    = 0x200000,
+  AR_TARGET_SERENDIP_RED      = 0x400000,
+  AR_TARGET_SERENDIP_DISTANT  = 0x800000,
+  AR_TARGET_SERENDIP_MANUAL   = 0x1000000
+
+The /secTarget/ field is a bit mask specifying which secondary target
+catagories the object was selected in. The bits are defined as:
+
+  TAR_TARGET_LIGHT_TRAP        = 0x1,
+  TAR_TARGET_REDDEN_STD        = 0x2,
+  TAR_TARGET_TEST_TARGET       = 0x4,
+  TAR_TARGET_QA                = 0x8,
+  TAR_TARGET_SKY               = 0x10,
+  TAR_TARGET_SPECTROPHOTO_STD  = 0x20,
+  TAR_TARGET_GUIDE_STAR        = 0x40,
+  TAR_TARGET_BUNDLE_HOLE       = 0x80,
+  TAR_TARGET_QUALITY_HOLE      = 0x100,
+  TAR_TARGET_HOT_STD           = 0x200
+
+The /CULLED/ keyword is a bit mask with the same bit values as the
+/primTarget/ field. If a bit is set, then all targets of that target
+type were culled during target selection, and thus this field is
+excluded from that science sample.
+
+XTENSION= 'BINTABLE'          
+BITPIX  =                    8
+NAXIS   =                    2
+NAXIS1  =                 2732
+NAXIS2  =                  XXX
+PCOUNT  =                    0
+GCOUNT  =                    1
+TFIELDS =                  146
+FIELD   =                  XXX / Field sequence number within the run.
+QUALITY = 'XXX     '           / Quality of field in terms of survey acceptance
+CULLED  =                  XXX / Culling bit mask
+MJD_U   =         XXXXX.XXXXXX / MJD(TAI) when row 0 of u' frame was read
+MJD_G   =         XXXXX.XXXXXX / MJD(TAI) when row 0 of g' frame was read
+MJD_R   =         XXXXX.XXXXXX / MJD(TAI) when row 0 of r' frame was read
+MJD_I   =         XXXXX.XXXXXX / MJD(TAI) when row 0 of i' frame was read
+MJD_Z   =         XXXXX.XXXXXX / MJD(TAI) when row 0 of z' frame was read
+SEEING_U=                 XX.X / Seeing on the u' frame (FWHM, arcsecs)
+SEEING_G=                 XX.X / Seeing on the g' frame (FWHM, arcsecs)
+SEEING_R=                 XX.X / Seeing on the r' frame (FWHM, arcsecs)
+SEEING_I=                 XX.X / Seeing on the i' frame (FWHM, arcsecs)
+SEEING_Z=                 XX.X / Seeing on the z' frame (FWHM, arcsecs)
+STATUS_U= 'XXX     '           / PSF fit status on u' frame
+STATUS_G= 'XXX     '           / PSF fit status on g' frame
+STATUS_R= 'XXX     '           / PSF fit status on r' frame
+STATUS_I= 'XXX     '           / PSF fit status on i' frame
+STATUS_Z= 'XXX     '           / PSF fit status on z' frame
+PSP_STAT= 'XXX     '           / Maximum of STATUS value on all 5 frames
+PSFERR_U=               XXX.XX / Photometric err due to imperfect PSF model(mag)
+PSFERR_G=               XXX.XX / Photometric err due to imperfect PSF model(mag)
+PSFERR_R=               XXX.XX / Photometric err due to imperfect PSF model(mag)
+PSFERR_I=               XXX.XX / Photometric err due to imperfect PSF model(mag)
+PSFERR_Z=               XXX.XX / Photometric err due to imperfect PSF model(mag)
+SKY_U   =               XXX.XX / Global sky value after obj sub (mag/arcsec^2)
+SKY_G   =               XXX.XX / Global sky value after obj sub (mag/arcsec^2)
+SKY_R   =               XXX.XX / Global sky value after obj sub (mag/arcsec^2)
+SKY_I   =               XXX.XX / Global sky value after obj sub (mag/arcsec^2)
+SKY_Z   =               XXX.XX / Global sky value after obj sub (mag/arcsec^2)
+TFORM1  = '1J      '          
+TTYPE1  = 'run     '           / Run ID
+TUNIT1  = 'unitless'          
+TFORM2  = '1J      '          
+TTYPE2  = 'camCol  '           / Camera column
+TUNIT2  = 'unitless'          
+TFORM3  = '1J      '          
+TTYPE3  = 'rerun   '           / Rerun number
+TUNIT3  = 'unitless'          
+TFORM4  = '1J      '          
+TTYPE4  = 'field   '           / Field ID
+TUNIT4  = 'unitless'          
+TFORM5  = '1J      '          
+TTYPE5  = 'parent  '           / Parent
+TUNIT5  = 'unitless'          
+TFORM6  = '1J      '          
+TTYPE6  = 'id      '           / Object ID, unique within its field (1 indexed)
+TUNIT6  = 'unitless'          
+TFORM7  = '1J      '          
+TTYPE7  = 'nchild  '           / Number of Children
+TUNIT7  = 'unitless'          
+TFORM8  = '1J      '          
+TTYPE8  = 'objc_type'          / Classification
+TUNIT8  = 'unitless'          
+TFORM9  = '1E      '
+TTYPE9  = 'objc_prob_psf'      / Probablity object is a star
+TUNIT9  = 'unitless'          
+TFORM10 = '1J      '          
+TTYPE10 = 'catID   '           / Catalog ID
+TUNIT10 = 'unitless'          
+TFORM11 = '1J      '          
+TTYPE11 = 'objc_flags'         / Object flags
+TUNIT11 = 'unitless'          
+TFORM12 = '1J      '          
+TTYPE12 = 'objc_flags2'        / More object flags
+TUNIT12 = 'unitless'          
+TFORM13 = '1E      '          
+TTYPE13*= 'objc_rowc'          / Nominal row position (r' coordinates)
+TUNIT13 = 'pixels  '          
+TFORM14 = '1E      '          
+TTYPE14*= 'objc_rowcErr'       / Nominal row position (r' coordinates) error
+COMMENT                        / This is the centroiding error only.  It does
+COMMENT                        / not include errors from the TRANS structures.
+TUNIT14 = 'pixels  '          
+TFORM15 = '1E      '          
+TTYPE15*= 'objc_colc'          / Nominal column position (r' coordinates)
+TUNIT15 = 'pixels  '          
+TFORM16 = '1E      '          
+TTYPE16*= 'objc_colcErr'       / Nominal column position (r' coordinates) error
+COMMENT                        / This is the centroiding error only.  It does
+COMMENT                        / not include errors from the TRANS structures.
+TUNIT16 = 'pixels  '          
+TFORM17 = '1E      '          
+TTYPE17 = 'rowv    '           / Row-component of object's velocity
+TUNIT17 = 'deg/day '          
+TFORM18 = '1E      '          
+TTYPE18 = 'rowvErr '           / Row-component of object's velocity error
+TUNIT18 = 'deg/day '          
+TFORM19 = '1E      '          
+TTYPE19 = 'colv'               / Column-component of object's velocity 
+TUNIT19 = 'deg/day'          
+TFORM20 = '1E      '          
+TTYPE20 = 'colvErr'            / Column-component of obejct's velocity error
+TUNIT20 = 'deg/day'          
+TFORM21 = '5E      '          
+TTYPE21 = 'rowc    '           / Row center
+TUNIT21 = 'pixels  '          
+TFORM22 = '5E      '          
+TTYPE22 = 'rowcErr '           / Row center error
+TUNIT22 = 'pixels  '          
+TFORM23 = '5E      '          
+TTYPE23 = 'colc    '           / Center colum 
+TUNIT23 = 'pixels  '          
+TFORM24 = '5E      '          
+TTYPE24 = 'colcErr '           / Center column error
+TUNIT24 = 'pixels  '          
+TFORM25 = '5E      '          
+TTYPE25 = 'sky     '           / Sky flux
+TUNIT25 = 'asinh mag/arcsec^2'         
+TFORM26 = '5E      '          
+TTYPE26 = 'skyErr  '           / Sky flux error
+TUNIT26 = 'asinh mag/arcsec^2'         
+TFORM27 = '5E      '          
+TTYPE27 = 'psfCounts'          / PSF flux
+TUNIT27 = 'asinh mag     '          
+TFORM28 = '5E      '          
+TTYPE28 = 'psfCountsErr'       / PSF flux error
+TUNIT28 = 'asinh mag     '          
+TFORM29 = '5E      '          
+TTYPE29 = 'fiberCounts'        / Flux in 3 arcsec diameter fiber radius
+TUNIT29 = 'asinh mag     '          
+TFORM30 = '5E      '          
+TTYPE30 = 'fiberCountsErr'     / Flux in 3 arcsec diameter fiber radius error
+TUNIT30 = 'asinh mag     '          
+TFORM31 = '5E      '          
+TTYPE31 = 'petroCounts'        / Petrosian flux
+TUNIT31 = 'asinh mag     '          
+TFORM32 = '5E      '          
+TTYPE32 = 'petroCountsErr'     / Petrosian flux error
+TUNIT32 = 'asinh mag     '          
+TFORM33 = 5E      '          
+TTYPE33 = 'petroRad'           / Petrosian radius
+TUNIT33 = 'arcsec '          
+TFORM34 = '5E      '          
+TTYPE34 = 'petroRadErr'        / Petrosian radius error
+TUNIT34 = 'arcsec '          
+TFORM35 = '5E      '          
+TTYPE35 = 'petroR50'           / Radius with 50 percent of Petrosian light
+TUNIT35 = 'arcsec '          
+TFORM36 = '5E      '          
+TTYPE36 = 'petroR50Err'        / Radius with 50 percent of Petrosian light error
+TUNIT36 = 'arcsec '          
+TFORM37 = '5E      '          
+TTYPE37 = 'petroR90'           / Radius with 90 percent of Petrosian light
+TUNIT37 = 'arcsec '          
+TFORM38 = '5E      '          
+TTYPE38 = 'petroR90Err'        / Radius with 90 percent of Petrosian light error
+TUNIT38 = 'arcsec  '          
+TFORM39 = '5E      '          
+TTYPE39 = 'Q       '           / Stokes Q parameter
+TUNIT39 = 'unitless'          
+TFORM40 = '5E      '          
+TTYPE40 = 'QErr    '           / Stokes Q parameter error
+TUNIT40 = 'unitless'          
+TFORM41 = '5E      '          
+TTYPE41 = 'U       '           / Stokes U parameter
+TUNIT41 = 'unitless'          
+TFORM42 = '5E      '          
+TTYPE42 = 'UErr    '           / Stokes U parameter error
+TUNIT42 = 'unitless'          
+TFORM43 = '5E      '
+TTYPE43 = 'M_e1    '           / Adaptive E1 shape measure
+TUNIT43 = 'unitless'          
+TFORM44 = '5E      '
+TTYPE44 = 'M_e2    '           / Adaptive E2 shape measure
+TUNIT44 = 'unitless'          
+TFORM45 = '5E      '
+TTYPE45 = 'M_e1e1Err'          / Covariance in E1-E1 shape measure
+TUNIT45 = 'unitless'          
+TFORM46 = '5E      '
+TTYPE46 = 'M_e1e2Err'          / Covariance in E1-E2 shape measure
+TUNIT46 = 'unitless'          
+TFORM47 = '5E      '
+TTYPE47 = 'M_e2e2Err'          / Covariance in E2-E2 shape measure
+TUNIT47 = 'unitless'          
+TFORM48 = '5E      '
+TTYPE48 = 'M_rr_cc '           / Adaptive ( + )
+TUNIT48 = 'unitless'          
+TFORM49 = '5E      '
+TTYPE49 = 'M_rr_ccErr'         / Error in adaptive ( + )
+TUNIT49 = 'unitless'          
+TFORM50 = '5E      '
+TTYPE50 = 'M_cr4   '           / Adaptive fourth moment
+TUNIT50 = 'unitless'          
+TFORM51 = '5E      '
+TTYPE51 = 'M_e1_psf'           / Adaptive E1 for PSF
+TUNIT51 = 'unitless'          
+TFORM52 = '5E      '
+TTYPE52 = 'M_e2_psf'           / Adaptive E2 for PSF
+TUNIT52 = 'unitless'          
+TFORM53 = '5E      '
+TTYPE53 = 'M_rr_cc_psf'        / Adaptive () for PSF
+TUNIT53 = 'unitless'          
+TFORM54 = '5E      '
+TTYPE54 = 'M_cr4_psf'          / Adaptive fourth moment for PSF
+TUNIT54 = 'unitless'          
+TFORM55 = '5E      '          
+TTYPE55 = 'iso_rowc'           / Isophotal row centroid
+TUNIT55 = 'pixels  '          
+TFORM56 = '5E      '          
+TTYPE56 = 'iso_rowcErr'        / Isophotal row centroid error
+TUNIT56 = 'pixels  '          
+TFORM57 = '5E      '          
+TTYPE57 = 'iso_rowcGrad'       / Gradient in row centroid with isophote
+TUNIT57 = 'pixels/mag/arcsec^2'
+TFORM58 = '5E      '          
+TTYPE58 = 'iso_colc'           / Isophotal column centroid
+TUNIT58 = 'pixels  '          
+TFORM59 = '5E      '          
+TTYPE59 = 'iso_colcErr'        / Isophotal column centroid error
+TUNIT59 = 'pixels  '          
+TFORM60 = '5E      '          
+TTYPE60 = 'iso_colcGrad'       / Gradient in column centroid with isophote
+TUNIT60 = 'pixels/mag/arcsec^2'
+TFORM61 = '5E      '          
+TTYPE61 = 'iso_a   '           / Isophotal major axis
+TUNIT61 = 'arcsec  '          
+TFORM62 = '5E      '          
+TTYPE62 = 'iso_aErr'           / Isophotal major axis error
+TUNIT62 = 'arcsec  '          
+TFORM63 = '5E      '          
+TTYPE63 = 'iso_aGrad'          / Gradient in major axis with isophote
+TUNIT63 = 'arcsec/mag/arcsec^2'
+TFORM64 = '5E      '          
+TTYPE64 = 'iso_b   '           / Isophotal minor axis
+TUNIT64 = 'arcsec  '          
+TFORM65 = '5E      '          
+TTYPE65 = 'iso_bErr'           / Isophotal minor axis error
+TUNIT65 = 'arcsec  '          
+TFORM66 = '5E      '          
+TTYPE66 = 'iso_bGrad'          / Gradient in minor axis with isophote
+TUNIT66 = 'arcsec/mag/arcsec^2'
+TFORM67 = '5E      '          
+TTYPE67 = 'iso_phi '           / Isophotal position angle
+TUNIT67 = 'degrees (+N thru E)'          
+TFORM68 = '5E      '          
+TTYPE68 = 'iso_phiErr'         / Isophotal position angle error
+TUNIT68 = 'degrees '          
+TFORM69 = '5E      '          
+TTYPE69 = 'iso_phiGrad'        / Gradient in positional angle with isophote
+TUNIT69 = 'degrees/mag/arcsec^2'
+TFORM70 = '5E      '          
+TTYPE70 = 'r_deV   '           / De Vaucouleurs fit scale radius
+TUNIT70 = 'arcsec  '          
+TFORM71 = '5E      '          
+TTYPE71 = 'r_deVErr'           / De Vaucouleurs fit scale radius error
+TUNIT71 = 'arcsec  '          
+TFORM72 = '5E      '          
+TTYPE72 = 'ab_deV  '           / De Vaucouleurs fit a/b
+TUNIT72 = 'unitless'          
+TFORM73 = '5E      '          
+TTYPE73 = 'ab_deVErr'          / De Vaucouleurs fit a/b error
+TUNIT73 = 'unitless'          
+TFORM74 = '5E      '          
+TTYPE74 = 'phi_deV '           / De Vaucouleurs fit position angle
+TUNIT74 = 'degrees (+N thru E)'          
+TFORM75 = '5E      '          
+TTYPE75 = 'phi_deVErr'         / De Vaucouleurs fit position angle error
+TUNIT75 = 'degrees '          
+TFORM76 = '5E      '          
+TTYPE76 = 'counts_deV'         / De Vaucouleurs magnitude fit
+TUNIT76 = 'asinh mag '          
+TFORM77 = '5E      '          
+TTYPE77 = 'counts_deVErr'      / De Vaucouleurs magnitude fit error
+TUNIT77 = 'asinh mag '          
+TFORM78 = '5E      '          
+TTYPE78 = 'r_exp   '           / Exponetial fit scale radius
+TUNIT78 = 'arcsec  '          
+TFORM79 = '5E      '          
+TTYPE79 = 'r_expErr'           / Exponetial fit scale radius error
+TUNIT79 = 'arcsec '          
+TFORM80 = '5E      '          
+TTYPE80 = 'ab_exp  '           / Exponential fit a/b
+TUNIT80 = 'unitless'          
+TFORM81 = '5E      '          
+TTYPE81 = 'ab_expErr'          / Exponential fit a/b error
+TUNIT81 = 'unitless'          
+TFORM82 = '5E      '          
+TTYPE82 = 'phi_exp '           / Exponential fit position angle
+TUNIT82 = 'degrees (+N thru E)'          
+TFORM83 = '5E      '          
+TTYPE83 = 'phi_expErr'         / Exponential fit position angle error
+TUNIT83 = 'degrees '          
+TFORM84 = '5E      '          
+TTYPE84 = 'counts_exp'         / Exponential fit
+TUNIT84 = 'asinh mag '          
+TFORM85 = '5E      '          
+TTYPE85 = 'counts_expErr'      / Exponential fit error
+TUNIT85 = 'asinh mag '          
+TFORM86 = '5E      '          
+TTYPE86 = 'counts_model'       / Better of DeV/Exp magnitude fit
+TUNIT86 = 'asinh mag '          
+TFORM87 = '5E      '          
+TTYPE87 = 'counts_modelErr'    / Better of DeV/Exp magnitude fit error
+TUNIT87 = 'asinh mag '          
+TFORM88 = '5E      '          
+TTYPE88 = 'texture '           / Texture parameter
+TUNIT88 = 'unitless'          
+TFORM89 = '5E      '          
+TTYPE89 = 'star_L  '           / Star likelihood
+TUNIT89 = 'unitless'          
+TFORM90 = '5E      '          
+TTYPE90 = 'star_lnL'           / Star ln(likelihood)
+TUNIT90 = 'unitless'          
+TFORM91 = '5E      '          
+TTYPE91 = 'exp_L   '           / Exponential disk fit likelihood
+TUNIT91 = 'unitless'          
+TFORM92 = '5E      '          
+TTYPE92 = 'exp_lnL '           / Exponential disk fit ln(likelihood)
+TUNIT92 = 'unitless'          
+TFORM93 = '5E      '          
+TTYPE93 = 'deV_L   '           / De Vaucouleurs fit likelihood
+TUNIT93 = 'unitless'          
+TFORM94 = '5E      '          
+TTYPE94 = 'deV_lnL '           / De Vaucouleurs fit ln(likelihood)
+TUNIT94 = 'unitless'          
+TFORM95 = '5E      '          
+TTYPE95 = 'fracPSF '           / Fraction of light in PSF
+TUNIT95 = 'unitless'          
+TFORM96 = '5J      '          
+TTYPE96 = 'flags   '           / Object flags
+TUNIT96 = 'unitless'          
+TFORM97 = '5J      '          
+TTYPE97 = 'flags2  '           / More object flags
+TUNIT97 = 'unitless'          
+TFORM98 = '5J      '          
+TTYPE98 = 'type    '           / Object type
+TUNIT98 = 'unitless'          
+TFORM99 = '5E      '
+TTYPE99 = 'prob_psf'           / Probablity object is a star in each filter
+TUNIT99 = 'unitless'          
+TFORM100= '5J      '          
+TTYPE100= 'nprof   '           / Number of radial bins
+TUNIT100= 'unitless'          
+TFORM101= '75E     '          
+TTYPE101= 'profMean'           / Mean pixel flux in annulus
+TUNIT101= 'maggies/arcsec^2'         
+TDIM101 = '(15,5)  '          
+TFORM102= '75E     '          
+TTYPE102= 'profErr '           / Standard deviation of profMean
+TUNIT102= 'maggies/arcsec^2'        
+TDIM102 = '(15,5)  '          
+TFORM103= '1J      '          
+TTYPE103= 'status  '           / Survey status
+TUNIT103= 'unitless'          
+TFORM104= '1D      '          
+TTYPE104= 'ra      '           / J2000 right ascension (r')
+TUNIT104= 'degrees '          
+TFORM105= '1D      '          
+TTYPE105= 'dec     '           / J2000 declination (r')
+TUNIT105= 'degrees '          
+TFORM106= '1D      '          
+TTYPE106= 'lambda  '           / Survey longitude (r')
+TUNIT106= 'degrees '          
+TFORM107= '1D      '          
+TTYPE107= 'eta     '           / Survey latitude (r')
+TUNIT107= 'degrees '          
+TFORM108= '1D      '          
+TTYPE108= 'l       '           / Galactic longitude (lII, r')
+TUNIT108= 'degrees '          
+TFORM109= '1D      '          
+TTYPE109= 'b       '           / Galactic latitude (bII, r')
+TUNIT109= 'degrees '          
+TFORM110= '5E      '          
+TTYPE110= 'offsetRa'           / Filter position ra minus final ra (* cos(dec))
+TUNIT110= 'arcsec  '          
+TFORM111= '5E      '          
+TTYPE111= 'offsetDec'          / Filter position dec minus final dec
+TUNIT111= 'arcsec  '          
+TFORM112= '1J      '
+TTYPE112= 'primTarget'         / Target selection flags
+TUNIT112= 'unitless'          
+TFORM113= '1J      '
+TTYPE113= 'secTarget'          / Additional Target selection flags
+TUNIT113= 'unitless'          
+TFORM114= '5E      '
+TTYPE114= 'reddening'          / Reddening in each filter
+TUNIT114= 'mag   '
+TFORM115= '1J      '
+TTYPE115= 'propermotionmatch'  / 1= match to USNO catatalog
+TUNIT115= 'unitless'          
+TFORM116= '1E      '
+TTYPE116= 'propermotiondelta'  / Difference in positions between USNO and
+COMMENT                        / photo object (r' band)
+TUNIT116= 'arcsec'
+TFORM117= '1E      '
+TTYPE117= 'propermotion'       / Proper motion of object
+TUNIT117= 'arcsec/century'
+TFORM118= '1E      '
+TTYPE118= 'propermotionangle'  / Direction of proper motion
+TUNIT118= 'degrees (+N thru E)'
+TFORM119= '1E      '
+TTYPE119= 'usnoBlue'           / Blue magntiude of matching USNO object
+TUNIT119= 'mag     '
+TFORM120= '1E      '
+TTYPE120= 'usnoRed '           / Red magntiude of matching USNO object
+TUNIT120= 'mag     '
+TFORM121= '1J      '
+TTYPE121= 'firstMatch'         / Number of FIRST sources matched (0=no match)
+TUNIT121= 'unitless'          
+TFORM122= '1J      '
+TTYPE122= 'firstId '           / FIRST catalog id of one matching source
+TUNIT122= 'unitless'          
+TFORM123= '1D      '
+TTYPE123= 'firstLambda'        / Composite radio source survey longitude
+TUNIT123= 'degrees '
+TFORM124= '1D      '
+TTYPE124= 'firstEta'           / Composite radio source survey latitude
+TUNIT124= 'degrees '
+TFORM125= '1E      '
+TTYPE125= 'firstDelta'         / Position difference between first and photo object (r' band)
+TUNIT125= 'arcsec'
+TFORM126= '1E      '
+TTYPE126= 'firstPeak'          / Peak first radio flux
+TUNIT126= 'mJy'
+TFORM127= '1E      '
+TTYPE127= 'firstInt'           / Integrated first radio flux
+TUNIT127= 'mJy'
+TFORM128= '1E      '
+TTYPE128= 'firstRms'           / Rms error in flux
+TUNIT128= 'mJy'
+TFORM129= '1E      '
+TTYPE129= 'firstMajor'         / Major axis (deconvolved)
+TUNIT129= 'arcsec'
+TFORM130= '1E      '
+TTYPE130= 'firstMinor'         / Minor axis (deconvolved)
+TUNIT130= 'arcsec'
+TFORM131= '1E      '
+TTYPE131= 'firstPa'            / Position angle (east of north)
+TUNIT131= 'degrees'
+TFORM132= '1J      '
+TTYPE132= 'rosatMatch'         / ID of matching ROSAT source (0 = no match)
+TUNIT132= 'unitless'          
+TFORM133= '1E      '
+TTYPE133= 'rosatDelta'         / Position difference between ROSAT and photo object (r' band)
+TUNIT133= 'arcsec'
+TFORM134= '1E      '                                                           
+TTYPE134= 'rosatPosErr'        / Error in ROSAT position
+TUNIT134= 'arcsec '
+TFORM135= '1E      '
+TTYPE135= 'rosatCps'           / Integrated ROSAT counts
+TUNIT135= 'counts/sec'
+TFORM136= '1E      '
+TTYPE136= 'rosatCpsErr'        / Error in integrated ROSAT counts
+TUNIT136= 'counts/sec'
+TFORM137= '1E      '
+TTYPE137= 'rosatHr1'           / ROSAT hardness ratio 1
+TUNIT137= 'unitless'          
+TFORM138= '1E      '
+TTYPE138= 'rosatHr1Err'        / Error in ROSAT hardness ratio 1
+TUNIT138= 'unitless'          
+TFORM139= '1E      '
+TTYPE139= 'rosatHr2'           / ROSAT hardness ratio 2
+TUNIT139= 'unitless'          
+TFORM140= '1E      '
+TTYPE140= 'rosatHr2Err'        / Error in ROSAT hardness ratio 2
+TUNIT140= 'unitless'          
+TFORM141= '1E      '
+TTYPE141= 'rosatExt'           / ROSAT extent parameter
+TUNIT141= 'arcsec'
+TFORM142= '1E      '
+TTYPE142= 'rosatExtLike'       / ROSAT extent parameter likelihood
+TUNIT142= 'unitless'          
+TFORM143= '1E      '
+TTYPE143= 'rosatDetectLike'    / ROSAT detection likelihood
+TUNIT143= 'unitless'          
+TFORM144= '1E      '
+TTYPE144= 'rosatExposure'      / ROSAT exposure time
+TUNIT144= 'seconds '
+TFORM145= '1J      '
+TTYPE145= 'priority'           / Priority bits
+TSCAL145= 1.00000000000000E+00
+TZERO145= 2.14748364800000E+09
+TUNIT145= 'unitless'          
+TFORM146= '50J     '
+TTYPE146= 'matchid '           / Link ids (run,camCol,rerun,field,id)
+TUNIT146= 'unitless'          
+TDIM146 = '(5,10)  '
+
Index: /branches/eam_branch_20080223/Ohana/src/addstar/doc/sdss.txt
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/doc/sdss.txt	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/doc/sdss.txt	(revision 16698)
@@ -9,2 +9,52 @@
 * some re-org might be needed for LoadStars
 
+
+** fields to keep:
+
+name          sdss 
+ X            'objc_colc' (or colc)
+ Y            'objc_rowc' (or rowc)
+ dX           'objc_colcErr' (or colcErr)
+ dY           'objc_rowcErr' (or rowcErr)
+ R            ra  + offset Ra (get cos des right)
+ D            dec + offset Dec
+ dR           (calculate from dX * plate scale?)
+ dD           (calculate from dX * plate scale?)
+ uR           (from 'propermotion' and 'propermotionangle')
+ uD           (from 'propermotion' and 'propermotionangle')
+ duR          ?
+ duD          ?
+ P            X
+ dP           X
+ M            psfCounts (is already a mag?)
+ dM           psfCountsErr (is already a mag?)
+ sky          sky (convert to flux?)
+ dsky         skyErr (convert to flux?)
+ fx           ?
+ fy           ?
+ df           ?
+ Mgal         X
+ Map          X
+ Mpeak        X
+ detID        X
+ found        -1
+ t            MJD_U + Y*rate
+ dt           fixed? NY*rate
+ psfChisq     
+ crNsigma     
+ extNsigma    
+ psfQual      
+ Mcal         
+ airmass      
+ az            
+ code         
+ nFrames      
+ flags        
+ dophot       
+ dummy        
+
+we can use these header fields to get the exp times, and I suppose alt, az, airmass, etc:
+NODE    =           XXX.XXXXXX / Ascending node of great circle scanned (deg)
+INCL    =           XXX.XXXXXX / Inclincation of great circle scanned (deg)
+C_OBS   =            XXXXX.XXX / CCD clock rate (usec/unbinned-row)
+TRACKING=            XXXXX.XXX / Tracking rate (arcsec/TAI-sec)
Index: /branches/eam_branch_20080223/Ohana/src/addstar/include/2mass.h
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/include/2mass.h	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/include/2mass.h	(revision 16698)
@@ -42,2 +42,13 @@
 int       get2mass_star (Stars *star, char *line, int Nmax);
 int       get2mass_3star (Stars *star, char *line, int Nmax);
+
+int get2mass_3star_full (Stars *star, char *line, int Nmax);
+char *next2MASSfield (char *line);
+int set2MASS_ph_qual (Stars *star, char qual);
+int set2MASS_rd_flag (Stars *star, char qual);
+int set2MASS_cc_flag (Stars *star, char qual);
+int set2MASS_bl_flag (Stars *star, char qual);
+int set2MASS_gal_flag (Stars *star, char qual);
+int set2MASS_mp_flag (Stars *star, char qual);
+int set2MASS_dup_flag (Stars *star, char qual);
+int set2MASS_use_flag (Stars *star, char qual);
Index: /branches/eam_branch_20080223/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/include/addstar.h	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/include/addstar.h	(revision 16698)
@@ -51,5 +51,5 @@
 
 enum {M_IMAGE, M_REFLIST, M_REFCAT, M_FAKEIMAGE, M_RESORT};
-enum {NONE, SIMPLE_CMP, SIMPLE_CMF, SIMPLE_MEF, MOSAIC_CMP, MOSAIC_CMF, MOSAIC_MEF, MOSAIC_PHU};
+enum {NONE, SIMPLE_CMP, SIMPLE_CMF, SIMPLE_MEF, MOSAIC_CMP, MOSAIC_CMF, MOSAIC_MEF, MOSAIC_PHU, SDSS_OBJ};
 /* note: MEF implies CMF */
 
@@ -163,5 +163,5 @@
 Stars     *grefstars              PROTO((char *file, int photcode, int *Nstars));
 
-Stars     *LoadStars              PROTO((char *file, int *Nstars, Image **images, int *Nimages, int photcode));
+Stars     *LoadStars              PROTO((char *file, int *Nstars, Image **images, int *Nimages, AddstarClientOptions *options));
 Header   **LoadHeaders            PROTO((FILE *f, int *mode, int *Nheader));
 HeaderSet *MatchHeaders           PROTO((int **extsize, int *nimage, int mode, Header **headers, int Nheaders));
@@ -185,6 +185,7 @@
 Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
 Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
+Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, int *nimages, unsigned int *nstars));
 int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
-Stars     *FilterStars            PROTO((Stars *instars, Image *image));
+Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID));
 Stars     *MergeStars             PROTO((Stars *stars, int *Nstars, Stars *instars, int Ninstars));
 void       save_pt_catalog        PROTO((Catalog *catalog));  /*** choose new name ***/
@@ -245,4 +246,7 @@
 int args_skycells (int argc, char **argv);
 int ConfigInit_skycells (int *argc, char **argv);
+int UpdateImageIDs (Stars *stars, int Nstars, Image *images, int Nimages);
+int LoadDataSDSS (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages);
+int altaz (double *alt, double *az, double ha, double dec, double latitude);
 
 // this is a gnu extension?? caution!
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/FilterStars.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/FilterStars.c	(revision 16698)
@@ -65,7 +65,4 @@
       stars[N].M += MTIME - dMs;
     }
-    if (!isnan(stars[N].Mgal)) {
-      stars[N].Mgal += MTIME - dMs;
-    }
     if (!isnan(stars[N].Map)) {
       stars[N].Map += MTIME - dMs;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/GetFileMode.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/GetFileMode.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/GetFileMode.c	(revision 16698)
@@ -16,4 +16,13 @@
   gfits_scan (header, "EXTEND", "%t", 1, &extend);
     
+  { 
+    int tmp, haveCAMCOL, haveSTRIPE;
+    
+    // SDSS tsObj files have CAMCOL & STRIP keywords present in the header
+    haveCAMCOL = gfits_scan (header, "CAMCOL",  "%d", 1, &tmp);
+    haveSTRIPE = gfits_scan (header, "STRIPE",  "%d", 1, &tmp);
+    if (haveCAMCOL && haveSTRIPE) return SDSS_OBJ;
+  }
+
   if ((Naxis == 2) || TEXTMODE || !simple) {
     if (!strcmp (&ctype[4], "-WRP")) {
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/ImageOptions.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/ImageOptions.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/ImageOptions.c	(revision 16698)
@@ -4,5 +4,5 @@
 int ImageOptions (AddstarClientOptions *options, Image *images, int Nimages) {
 
-  int i, equivPhotcode;
+  int i, equivPhotcode, consistent;
   float maxError;
   PhotCode *photcode;
@@ -18,5 +18,9 @@
 
   // check that all images have the same equiv photcode and save it
+  // XXX this is only used to allow use to calculate an average mag
+  // if we have mis-matched photcodes, leave this as 0;
+  options[0].photcode = 0;
   equivPhotcode = 0;
+  consistent = TRUE;
 
   for (i = 0; i < Nimages; i++) {
@@ -28,6 +32,6 @@
     if (equivPhotcode) {
       if (equivPhotcode != photcode[0].equiv) {
-	fprintf (stderr, "ERROR: mismatch in equiv photcode values\n");
-	exit (2);
+	consistent = FALSE;
+	break;
       }
     } else {
@@ -35,5 +39,7 @@
     }
   }
-  options[0].photcode = equivPhotcode;
+  if (consistent) {
+    options[0].photcode = equivPhotcode;
+  }
 
   options[0].imageID = 0;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadData.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadData.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadData.c	(revision 16698)
@@ -0,0 +1,77 @@
+# include "addstar.h"
+
+// XXX this function is somewhat specific to the elixir format output files 
+// it is capable of distinguishing several format versions defined for elixir/psphot
+
+// examine the header sets and set the Image entries for the the valid images
+int LoadData (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages) {
+
+  char *name;
+  int i, j, Nvalid, Nhead, Ndata, Nskip;
+  Stars *inStars;
+
+  if (images[0] == NULL) {
+    Nvalid = 0;
+    NVALID = 10;
+    ALLOCATE (images[0], Image, NVALID);
+  } else {
+    Nvalid = *nvalid;
+    NVALID = Nvalid + 10;
+    REALLOCATE (images[0], Image, NVALID);
+  }    
+
+  // find image rootname
+  name = filebasename (file);
+
+  // now run through the images, interpret the headers and read the stars
+  for (i = 0; i < Nimages; i++) {
+    Nhead = headerSets[i].extnum_head;
+
+    if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", headerSets[i].exthead, headerSets[i].extdata);
+    if (!ReadImageHeader (headers[Nhead], &images[0][Nvalid], 0)) {
+      fprintf (stderr, "skipping %s\n", headerSets[i].exthead);
+      continue;
+    }
+    images[0][Nvalid].imageID = Nvalid;
+    images[0][Nvalid].externID = 0;
+    images[0][Nvalid].sourceID = 0;
+
+    // XXX EAM : I seemed to have dropped the ability to support TEXT (old-style cmp format files).
+    // I need to detect them here and load them with ReadStarsTEXT instead of calling the code
+    // below.
+
+    // XXX use something to set the chip name? EXTNAME?
+    if (!strcmp(headerSets[i].exthead, "PHU") && (Nimages == 1)) {
+      snprintf (images[0][Nvalid].name, 64, "%s", name);
+    } else {
+      snprintf (images[0][Nvalid].name, 64, "%s[%s]", name, headerSets[i].exthead);
+    }
+
+    // skip the table if there is no data segment (eg, mosaic WRP image)
+    if (!strcmp(headerSets[i].extdata, "NONE")) {
+      Nvalid++;
+      if (Nvalid == NVALID) {
+	NVALID += 10;
+	REALLOCATE (images[0], Image, NVALID);
+      }
+      continue;
+    }
+
+    // advance the pointer to the start of the corresponding table block
+    Ndata = headerSets[i].extnum_data;
+    Nskip = 0;
+    for (j = 0; j < Ndata; j++) {
+      Nskip += extsize[j];
+    }
+    fseek (f, Nskip, SEEK_SET); 
+	 
+    inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
+    inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid);
+    *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
+    Nvalid++;
+  }
+  free (name);
+  *nvalid = Nvalid;
+  return (TRUE);
+}
+
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadDataSDSS.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 16698)
@@ -0,0 +1,47 @@
+# include "addstar.h"
+
+// examine the header sets and set the Image entries for the the valid images
+// there should only be a single data set (phu + table) in this file
+// each SDSS data set corresponds to 5 images (ugriz)
+int LoadDataSDSS (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages) {
+
+  char *name;
+  int j, Nvalid, Nhead, Ndata, Nskip;
+  unsigned int Ninstars;
+  Stars *inStars;
+
+  if (images[0] == NULL) {
+    Nvalid = 0;
+    NVALID = 5;
+    ALLOCATE (images[0], Image, NVALID);
+  } else {
+    Nvalid = *nvalid;
+    NVALID = Nvalid + 5;
+    REALLOCATE (images[0], Image, NVALID);
+  }    
+
+  // find image rootname
+  name = filebasename (file);
+
+  // there is only one SDSS image per file (TRUE?)
+  Nhead = headerSets[0].extnum_head;
+
+  // XXX parse the information needed from the PHU header
+  if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", headerSets[0].exthead, headerSets[0].extdata);
+
+  // advance the pointer to the start of the corresponding table block
+  Ndata = headerSets[0].extnum_data;
+  Nskip = 0;
+  for (j = 0; j < Ndata; j++) {
+    Nskip += extsize[j];
+  }
+  fseek (f, Nskip, SEEK_SET); 
+	 
+  inStars = ReadStarsSDSS (f, name, headers[Nhead], headers[Ndata], images[0], &Nvalid, &Ninstars);
+  *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
+
+  free (name);
+  *nvalid = Nvalid;
+  return (TRUE);
+}
+
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadHeaders.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadHeaders.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadHeaders.c	(revision 16698)
@@ -0,0 +1,40 @@
+# include "addstar.h"
+
+// load all of the headers, jump in file to skip data segments
+Header **LoadHeaders (FILE *f, int *mode, int *Nheaders) {
+
+  int i, status, Nskip, NHEADERS;
+  Header **headers;
+
+  /* we need to examine the extensions to determine the headers and the data */
+  NHEADERS = 10;
+  ALLOCATE (headers, Header *, NHEADERS);
+
+  // load all headers into memory
+  for (i = 0;; i++) {
+    ALLOCATE (headers[i], Header, 1);
+    status = gfits_fread_header (f, headers[i]);
+    if (!status) { 
+      *Nheaders = i;
+      return (headers);
+    }
+
+    // check the mode for this file
+    if (i == 0) {
+      *mode = GetFileMode (headers[0]);
+      if ((*mode == SIMPLE_CMP) || (*mode == MOSAIC_CMP)) {
+	*Nheaders = i;
+	return (headers);
+      }
+    }
+
+    // advance to the next header
+    Nskip = gfits_data_size (headers[i]);
+    fseek (f, Nskip, SEEK_CUR); 
+    if (i == NHEADERS - 1) {
+      NHEADERS += 10;
+      REALLOCATE (headers, Header *, NHEADERS);
+    }
+  }
+}
+
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadStars.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadStars.c	(revision 16698)
@@ -23,5 +23,10 @@
     for (i = 0; (fscanf (f, "%s", line) != EOF); i++) {
       // filename limited to 1024 chars
+      fprintf (stderr, "file: %s\n", line);
       file[i] = strcreate (line);
+      if (i == NFILE - 1) {
+	NFILE += 10;
+	REALLOCATE (file, char *, NFILE);
+      }
     }
     Nfile = i;
@@ -76,7 +81,13 @@
     }
 
+    if (!strcmp (headerSets[0].exttype, "SDSS_OBJ")) {
+      LoadDataSDSS (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
+      continue;
+    }
+
     LoadData (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
 
     // XXX add a function to (optionally) load the extended source measurements
+    # if (0)
     if (extSources) {
       // not sure how to link the measurements here to the psf measurements above (though there is an ID in the det list)
@@ -86,4 +97,5 @@
       LoadDataXFIT (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
     }
+    # endif
 
   }
@@ -100,202 +112,2 @@
 }
 
-// load all of the headers, jump in file to skip data segments
-Header **LoadHeaders (FILE *f, int *mode, int *Nheaders) {
-
-  int i, status, Nskip, NHEADERS;
-  Header **headers;
-
-  /* we need to examine the extensions to determine the headers and the data */
-  NHEADERS = 10;
-  ALLOCATE (headers, Header *, NHEADERS);
-
-  // load all headers into memory
-  for (i = 0;; i++) {
-    ALLOCATE (headers[i], Header, 1);
-    status = gfits_fread_header (f, headers[i]);
-    if (!status) { 
-      *Nheaders = i;
-      return (headers);
-    }
-
-    // check the mode for this file
-    if (i == 0) {
-      *mode = GetFileMode (headers[0]);
-      if ((*mode == SIMPLE_CMP) || (*mode == MOSAIC_CMP)) {
-	*Nheaders = i;
-	return (headers);
-      }
-    }
-
-    // advance to the next header
-    Nskip = gfits_data_size (headers[i]);
-    fseek (f, Nskip, SEEK_CUR); 
-    if (i == NHEADERS - 1) {
-      NHEADERS += 10;
-      REALLOCATE (headers, Header *, NHEADERS);
-    }
-  }
-}
-
-HeaderSet *MatchHeaders (int **extsize, int *nimage, int mode, Header **headers, int Nheaders) {
-
-  int i, j, Nimage, NIMAGE;
-  char extname[80], exttype[80], exthead[80];
-  HeaderSet *headerSets;
-
-  ALLOCATE (extsize[0], int, Nheaders);
-
-  Nimage = 0;
-  NIMAGE = 10;
-  ALLOCATE (headerSets, HeaderSet, NIMAGE);
-
-  // what is the mode of the first header (ie, do we have a PHU DIS image?)
-  mode = GetFileMode (headers[0]);
-
-  if (mode == MOSAIC_MEF) {
-    headerSets[Nimage].exthead     = strcreate ("PHU");
-    headerSets[Nimage].extdata     = strcreate ("NONE");
-    headerSets[Nimage].extnum_data = -1;
-    headerSets[Nimage].extnum_head =  0;
-    Nimage ++;
-  }
-
-  // now examine the headers, count the table entries, find corresponding headers
-  for (i = 0; i < Nheaders; i++) {
-    if (mode == SIMPLE_CMP) {
-      extsize[0][i] = headers[i][0].size;
-    } else {
-      extsize[0][i] = headers[i][0].size + gfits_data_size (headers[i]);
-    }
-    gfits_scan (headers[i], "EXTTYPE", "%s", 1, exttype);
-
-    if (!strcmp (exttype, "SMPDATA")) goto keep;
-    if (!strcmp (exttype, "PS1_DEV_0")) goto keep;
-    if (!strcmp (exttype, "PS1_DEV_1")) goto keep;
-    continue;
-
-  keep:
-    headerSets[Nimage].exttype = strcreate (exttype);
-
-    gfits_scan (headers[i], ExtnameKeyword, "%s", 1, extname);
-    gfits_scan (headers[i], "EXTHEAD", "%s", 1, exthead);
-
-    headerSets[Nimage].extdata     = strcreate (extname);
-    headerSets[Nimage].exthead     = strcreate (exthead);
-    headerSets[Nimage].extnum_data = i;
-    headerSets[Nimage].extnum_head = -1;
-
-    // find the matching exthead entry
-    for (j = 0; j < Nheaders; j++) {
-      if (!gfits_scan (headers[j], ExtnameKeyword, "%s", 1, extname)) continue;
-      if (strcmp (extname, headerSets[Nimage].exthead)) continue;
-      headerSets[Nimage].extnum_head = j;
-      break;
-    }
-
-    // skip or crash on table with missing matching header?
-    if (headerSets[Nimage].extnum_head == -1) {
-      return NULL;
-    }
-    Nimage ++;
-    if (Nimage == NIMAGE) {
-      NIMAGE += 10;
-      REALLOCATE (headerSets, HeaderSet, NIMAGE);
-    }
-  }
-
-  // some old format files did not write EXTTYPE.  they have a single table in the first
-  // extension matched to the header in the PHU
-  if (Nimage == 0) {
-    extsize[0][0] = headers[0][0].size + gfits_data_size (headers[0]);
-    extsize[0][1] = headers[1][0].size + gfits_data_size (headers[1]);
-    gfits_scan (headers[1], ExtnameKeyword, "%s", 1, extname);
-    if (!strcmp (extname, "SMPFILE")) {
-      headerSets[Nimage].extdata     = strcreate (extname);
-      headerSets[Nimage].exttype     = strcreate ("SMPDATA");
-      headerSets[Nimage].exthead     = strcreate ("PHU");
-      headerSets[Nimage].extnum_head = 0;
-      headerSets[Nimage].extnum_data = 1;
-      Nimage = 1;
-    }
-  }
-  
-  *nimage = Nimage;
-  return (headerSets);
-}
-
-// XXX this function is somewhat specific to the elixir format output files 
-// it is capable of distinguishing several format versions defined for elixir/psphot
-
-// examine the header sets and set the Image entries for the the valid images
-int LoadData (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages) {
-
-  char *name;
-  int i, j, Nvalid, Nhead, Ndata, Nskip;
-  Stars *inStars;
-
-  if (images[0] == NULL) {
-    Nvalid = 0;
-    NVALID = 10;
-    ALLOCATE (images[0], Image, NVALID);
-  } else {
-    Nvalid = *nvalid;
-    NVALID = Nvalid + 10;
-    REALLOCATE (images[0], Image, NVALID);
-  }    
-
-  // find image rootname
-  name = filebasename (file);
-
-  // now run through the images, interpret the headers and read the stars
-  for (i = 0; i < Nimages; i++) {
-    Nhead = headerSets[i].extnum_head;
-
-    if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", headerSets[i].exthead, headerSets[i].extdata);
-    if (!ReadImageHeader (headers[Nhead], &images[0][Nvalid], 0)) {
-      fprintf (stderr, "skipping %s\n", headerSets[i].exthead);
-      continue;
-    }
-    images[0][Nvalid].imageID = Nvalid;
-    images[0][Nvalid].externID = 0;
-    images[0][Nvalid].sourceID = 0;
-
-    // XXX EAM : I seemed to have dropped the ability to support TEXT (old-style cmp format files).
-    // I need to detect them here and load them with ReadStarsTEXT instead of calling the code
-    // below.
-
-    // XXX use something to set the chip name? EXTNAME?
-    if (!strcmp(headerSets[i].exthead, "PHU") && (Nimages == 1)) {
-      snprintf (images[0][Nvalid].name, 64, "%s", name);
-    } else {
-      snprintf (images[0][Nvalid].name, 64, "%s[%s]", name, headerSets[i].exthead);
-    }
-
-    // skip the table if there is no data segment (eg, mosaic WRP image)
-    if (!strcmp(headerSets[i].extdata, "NONE")) {
-      Nvalid++;
-      if (Nvalid == NVALID) {
-	NVALID += 10;
-	REALLOCATE (images[0], Image, NVALID);
-      }
-      continue;
-    }
-
-    // advance the pointer to the start of the corresponding table block
-    Ndata = headerSets[i].extnum_data;
-    Nskip = 0;
-    for (j = 0; j < Ndata; j++) {
-      Nskip += extsize[j];
-    }
-    fseek (f, Nskip, SEEK_SET); 
-	 
-    inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
-    inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid);
-    *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
-    Nvalid++;
-  }
-  free (name);
-  *nvalid = Nvalid;
-  return (TRUE);
-}
-
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/MatchHeaders.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/MatchHeaders.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/MatchHeaders.c	(revision 16698)
@@ -0,0 +1,104 @@
+# include "addstar.h"
+
+// XXX largely psphot specific
+
+HeaderSet *MatchHeaders (int **extsize, int *nimage, int mode, Header **headers, int Nheaders) {
+
+  int i, j, Nimage, NIMAGE;
+  char extname[80], exttype[80], exthead[80];
+  HeaderSet *headerSets;
+
+  ALLOCATE (extsize[0], int, Nheaders);
+
+  Nimage = 0;
+  NIMAGE = 10;
+  ALLOCATE (headerSets, HeaderSet, NIMAGE);
+
+  // what is the mode of the first header (ie, do we have a PHU DIS image?)
+  mode = GetFileMode (headers[0]);
+
+  if (mode == MOSAIC_MEF) {
+    headerSets[Nimage].exthead     = strcreate ("PHU");
+    headerSets[Nimage].extdata     = strcreate ("NONE");
+    headerSets[Nimage].extnum_data = -1;
+    headerSets[Nimage].extnum_head =  0;
+    Nimage ++;
+  }
+
+  if (mode == SDSS_OBJ) {
+    // XXX these should have two headers (phu + table)
+    assert (Nheaders == 2);
+    headerSets[0].extdata     = strcreate ("SDSS_OBJ");
+    headerSets[0].exttype     = strcreate ("SDSS_OBJ");
+    headerSets[0].exthead     = strcreate ("PHU");
+    headerSets[0].extnum_head = 0;
+    headerSets[0].extnum_data = 1;
+    extsize[0][0] = headers[0][0].size;
+    *nimage = 1;
+    return headerSets;
+  }
+
+  // now examine the headers, count the table entries, find corresponding headers
+  for (i = 0; i < Nheaders; i++) {
+    if (mode == SIMPLE_CMP) {
+      extsize[0][i] = headers[i][0].size;
+    } else {
+      extsize[0][i] = headers[i][0].size + gfits_data_size (headers[i]);
+    }
+
+    gfits_scan (headers[i], "EXTTYPE", "%s", 1, exttype);
+    if (!strcmp (exttype, "SMPDATA")) goto keep;
+    if (!strcmp (exttype, "PS1_DEV_0")) goto keep;
+    if (!strcmp (exttype, "PS1_DEV_1")) goto keep;
+    continue;
+
+  keep:
+    headerSets[Nimage].exttype = strcreate (exttype);
+
+    gfits_scan (headers[i], ExtnameKeyword, "%s", 1, extname);
+    gfits_scan (headers[i], "EXTHEAD", "%s", 1, exthead);
+
+    headerSets[Nimage].extdata     = strcreate (extname);
+    headerSets[Nimage].exthead     = strcreate (exthead);
+    headerSets[Nimage].extnum_data = i;
+    headerSets[Nimage].extnum_head = -1;
+
+    // find the matching exthead entry
+    for (j = 0; j < Nheaders; j++) {
+      if (!gfits_scan (headers[j], ExtnameKeyword, "%s", 1, extname)) continue;
+      if (strcmp (extname, headerSets[Nimage].exthead)) continue;
+      headerSets[Nimage].extnum_head = j;
+      break;
+    }
+
+    // skip or crash on table with missing matching header?
+    if (headerSets[Nimage].extnum_head == -1) {
+      return NULL;
+    }
+    Nimage ++;
+    if (Nimage == NIMAGE) {
+      NIMAGE += 10;
+      REALLOCATE (headerSets, HeaderSet, NIMAGE);
+    }
+  }
+
+  // some old format files did not write EXTTYPE.  they have a single table in the first
+  // extension matched to the header in the PHU
+  if (Nimage == 0) {
+    extsize[0][0] = headers[0][0].size + gfits_data_size (headers[0]);
+    extsize[0][1] = headers[1][0].size + gfits_data_size (headers[1]);
+    gfits_scan (headers[1], ExtnameKeyword, "%s", 1, extname);
+    if (!strcmp (extname, "SMPFILE")) {
+      headerSets[Nimage].extdata     = strcreate (extname);
+      headerSets[Nimage].exttype     = strcreate ("SMPDATA");
+      headerSets[Nimage].exthead     = strcreate ("PHU");
+      headerSets[Nimage].extnum_head = 0;
+      headerSets[Nimage].extnum_data = 1;
+      Nimage = 1;
+    }
+  }
+  
+  *nimage = Nimage;
+  return (headerSets);
+}
+
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadImageHeader.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadImageHeader.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadImageHeader.c	(revision 16698)
@@ -156,5 +156,4 @@
   image[0].Xm   = NAN_S_SHORT;
   image[0].code = 0;
-  memset (image[0].dummy, 0, sizeof(image[0].dummy));
 
   /* find expected number of stars */
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadSDSSHeader.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadSDSSHeader.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadSDSSHeader.c	(revision 16698)
@@ -0,0 +1,58 @@
+# include "addstar.h"
+
+// determine relevant image information from the PHU header
+int ReadSDSSHeader (Header *header, Image *image, int photcode) {
+
+  int Nastro, ccdnum, hour, min, Nx, Ny;
+  double tmp, sec, Cerror, ZeroPt;
+  char *c, photname[64], line[80];
+
+  // I need to convert a single obj file into a set of 5 images
+
+  // XXX how do I define the image boundaries?
+  // image[0].coords
+  // image[0].NX, NY
+
+  // image[0].tzero : MJD_U,G,R,I,Z in table header
+
+  // test astrometry quality? 
+  // image[0].cerror : ??
+ 
+  // set photcodes for the 5 images (SDSS_U,G,R,I,Z)
+  photcode = GetPhotcodeCodebyName ("SDSS_U");
+  if (photcode == 0) {
+    fprintf (stderr, "photcode %s not found in photcode table\n", photname);
+    return (FALSE);
+  }
+  image[0].photcode = photcode;
+
+  // calculate this from : C_OBS, TRACKING, and NY
+  image[0].exptime = tmp;
+  
+  // image[0].apmifit = tmp;
+  // image[0].dapmifit = tmp;
+  // image[0].detection_limit 
+  // image[0].saturation_limit
+  // image[0].fwhm_x : SEEING_U, etc in table header
+  // image[0].fwhm_y : SEEING_U, etc in table header
+
+  // XXX longitude and latitude are known for SDSS
+  // jd = ohana_sec_to_jd (image[0].tzero);
+  // image[0].sidtime  = ohana_lst (jd, Longitude);
+  // image[0].latitude = Latitude;
+
+  // image[0].trate : from C_OBS
+  // image[0].secz : ??
+  // image[0].ccdnum : COLNUM?
+
+  // secz is in units milli-airmass
+  image[0].Mcal = 0.0;
+  image[0].Xm   = NAN_S_SHORT;
+  image[0].code = 0;
+  memset (image[0].dummy, 0, sizeof(image[0].dummy));
+
+  // NAXIS2 for table:
+  // image[0].nstar
+
+  return (TRUE);
+}
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 16698)
@@ -72,9 +72,7 @@
     if ((smpdata[i].M >= ZeroPt) || isnan(smpdata[i].M)) {
       stars[i].M    = NAN;
-      stars[i].Mgal = NAN;
       stars[i].Map  = NAN;
     } else {
       stars[i].M    = smpdata[i].M;
-      stars[i].Mgal = smpdata[i].M;
       stars[i].Map  = smpdata[i].M;
     }
@@ -122,6 +120,6 @@
     stars[i].df      = ps1data[i].df;
 
-    stars[i].psfProb = ps1data[i].psfProb;
-    stars[i].psfQual = ps1data[i].psfQual;
+    stars[i].psfChisq = ps1data[i].psfChisq;
+    stars[i].psfQual  = ps1data[i].psfQual;
 
     stars[i].detID   = ps1data[i].detID;
@@ -150,5 +148,4 @@
     /* these are not used */
     stars[i].Map     = NAN;
-    stars[i].Mgal    = NAN;
     stars[i].dophot  = 0;
   }    
@@ -190,5 +187,5 @@
     stars[i].df      = ps1data[i].df;
 
-    stars[i].psfProb   = ps1data[i].psfProb;
+    stars[i].psfChisq  = ps1data[i].psfChisq;
     stars[i].psfQual   = ps1data[i].psfQual;
     stars[i].crNsigma  = ps1data[i].crNsigma;
@@ -225,5 +222,4 @@
     /* these are not used */
     stars[i].Map     = NAN;
-    stars[i].Mgal    = NAN;
     stars[i].dophot  = 0;
   }    
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 16698)
@@ -0,0 +1,285 @@
+# include "addstar.h"
+# define NFILTER 5
+# define dCOS(A)   ((double) cos ((double)RAD_DEG*A))
+# define dSIN(A)   ((double) sin ((double)RAD_DEG*A))
+
+# define GET_COLUMN_5(NAME,TYPE) \
+  TYPE *NAME; \
+  NAME = (TYPE *) gfits_get_bintable_column_data (table.header, &table, #NAME, type, &Nrow, &Ncol); \
+  assert (NAME); assert (!strcmp (type, #TYPE)); assert (Nrow == Nstars); assert (Ncol == NFILTER);
+
+# define GET_COLUMN_1(NAME,TYPE) \
+  TYPE *NAME; \
+  NAME = (TYPE *) gfits_get_bintable_column_data (table.header, &table, #NAME, type, &Nrow, &Ncol); \
+  assert (NAME); assert (!strcmp (type, #TYPE)); assert (Nrow == Nstars); assert (Ncol == 1);
+
+/* grab named photcode */
+# define NAMED_PHOTCODE_AND_ZP(CODE,ZP,NAME) { \
+  PhotCode *code; \
+  code = GetPhotcodebyName (NAME); \
+  if (code == NULL) { \
+    fprintf (stderr, "ERROR:  photcode %s not found in photcode table\n", NAME); \
+    exit (0); } \
+  CODE = code[0].code; \
+  ZP = 0.001*code[0].C; }
+
+// XXX NOTE : as of 2008.02.27, the zero point is still carried internally in millimags
+
+// given a file with the pointer at the start of the table block and the 
+// corresponding image header, load the stars from the table
+Stars *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, int *nimages, unsigned int *nstars) {
+
+  int i, j, N, Nskip, Nstars, camcol;
+  char type[80];
+  Header theader;
+  FTable table;
+  Stars *stars;
+  double clockRate, mjd[5], jd, sidtime, alt, az;
+  float seeing[5], photErr[5], zeropt[5], ZeroPt;
+  time_t tzero[5];
+  char filtname[16][5];
+  int photcode[5];
+  int Nrow, Ncol; // used in the GET_COLUMN_1,5 macros above
+  
+  if (in_theader == NULL) {
+    table.header = &theader;
+    if (!gfits_fread_header (f, table.header)) Shutdown ("ERROR: can't read table header");
+  } else {
+    table.header = in_theader;
+    Nskip = in_theader[0].size;
+    fseek (f, Nskip, SEEK_CUR); 
+  }
+
+  /* load the table data */
+  if (!gfits_fread_ftable_data (f, &table)) {
+    fprintf (stderr, "ERROR: can't read table header\n");
+    exit (1);
+  }
+
+  strcpy (filtname[0], "u");
+  strcpy (filtname[1], "g");
+  strcpy (filtname[2], "r");
+  strcpy (filtname[3], "i");
+  strcpy (filtname[4], "z");
+
+  NAMED_PHOTCODE_AND_ZP (photcode[0], zeropt[0], "U_SDSS");
+  NAMED_PHOTCODE_AND_ZP (photcode[1], zeropt[1], "G_SDSS");
+  NAMED_PHOTCODE_AND_ZP (photcode[2], zeropt[2], "R_SDSS");
+  NAMED_PHOTCODE_AND_ZP (photcode[3], zeropt[3], "I_SDSS");
+  NAMED_PHOTCODE_AND_ZP (photcode[4], zeropt[4], "Z_SDSS");
+
+  // various header values needed to calculate per-star data below
+  gfits_scan (header, "C_OBS", "%lf", 1, &clockRate); // value in header is usec / unbinned row
+  clockRate *= 1e-6; // convert to seconds / unbinned row
+
+  gfits_scan (table.header, "MJD_U", "%lf", 1, &mjd[0]);
+  gfits_scan (table.header, "MJD_G", "%lf", 1, &mjd[1]);
+  gfits_scan (table.header, "MJD_R", "%lf", 1, &mjd[2]);
+  gfits_scan (table.header, "MJD_I", "%lf", 1, &mjd[3]);
+  gfits_scan (table.header, "MJD_Z", "%lf", 1, &mjd[4]);
+  tzero[0] = ohana_mjd_to_sec (mjd[0]);
+  tzero[1] = ohana_mjd_to_sec (mjd[1]);
+  tzero[2] = ohana_mjd_to_sec (mjd[2]);
+  tzero[3] = ohana_mjd_to_sec (mjd[3]);
+  tzero[4] = ohana_mjd_to_sec (mjd[4]);
+
+  gfits_scan (table.header, "SEEING_U", "%f", 1, &seeing[0]);
+  gfits_scan (table.header, "SEEING_G", "%f", 1, &seeing[1]);
+  gfits_scan (table.header, "SEEING_R", "%f", 1, &seeing[2]);
+  gfits_scan (table.header, "SEEING_I", "%f", 1, &seeing[3]);
+  gfits_scan (table.header, "SEEING_Z", "%f", 1, &seeing[4]);
+
+  gfits_scan (table.header, "PSFERR_U", "%f", 1, &photErr[0]);
+  gfits_scan (table.header, "PSFERR_G", "%f", 1, &photErr[1]);
+  gfits_scan (table.header, "PSFERR_R", "%f", 1, &photErr[2]);
+  gfits_scan (table.header, "PSFERR_I", "%f", 1, &photErr[3]);
+  gfits_scan (table.header, "PSFERR_Z", "%f", 1, &photErr[4]);
+
+  gfits_scan (header, "CAMCOL", "%d", 1, &camcol); // value in header is usec / unbinned row
+
+  ZeroPt = GetZeroPoint();
+
+  // create a Star entry for each filter and detection
+  Nstars = table.header[0].Naxis[1];
+  ALLOCATE (stars, Stars, NFILTER*Nstars);
+
+  GET_COLUMN_5 (rowc, float);
+  GET_COLUMN_5 (colc, float);
+  GET_COLUMN_5 (sky, float);
+  GET_COLUMN_5 (psfCounts, float);
+  GET_COLUMN_5 (fiberCounts, float);
+  GET_COLUMN_5 (offsetRa, float);
+  GET_COLUMN_5 (offsetDec, float);
+  GET_COLUMN_5 (flags, int);
+  GET_COLUMN_5 (flags2, int);
+
+  GET_COLUMN_5 (prob_psf, float);
+
+  GET_COLUMN_1 (ra, double);
+  GET_COLUMN_1 (dec, double);
+
+  GET_COLUMN_5 (rowcErr, float);
+  GET_COLUMN_5 (colcErr, float);
+  GET_COLUMN_5 (skyErr, float);
+  GET_COLUMN_5 (psfCountsErr, float);
+
+  // the value of stars[].M is supposed to be the instrumental magnitude offset by the
+  // default zero point 25.0 (-2.5*log_10(counts/sec) + ZeroPt).  The magnitude reported
+  // by SDSS is the calibrated mag: -2.5*log_10(counts/sec) + C_0.  Adjust magnitudes to
+  // compensate for the difference.
+
+  for (i = 0; i < Nstars; i++) {
+    for (j = 0; j < NFILTER; j++) {
+      N = NFILTER*i + j;
+      stars[N].X         = colc[N];
+      stars[N].Y         = rowc[N];
+      stars[N].dX        = colcErr[N];
+      stars[N].dY        = rowcErr[N];
+      stars[N].M         = psfCounts[N] + ZeroPt - zeropt[j];
+      stars[N].dM        = psfCountsErr[N];
+      stars[N].Map       = fiberCounts[N] + ZeroPt - zeropt[j];
+      stars[N].Mpeak     = NAN;
+      stars[N].sky       = sky[N]; // adjust this to counts?
+      stars[N].dsky      = skyErr[N];
+      stars[N].fx        = seeing[j]; // reported in arcsec?
+      stars[N].fy        = seeing[j];
+      stars[N].df        = 0.0;
+      stars[N].psfChisq  = prob_psf[N]; // XXX not really the correct value...
+      stars[N].psfQual   = 0.0;
+      stars[N].crNsigma  = 0.0;
+      stars[N].extNsigma = 0.0;
+      stars[N].detID     = N;
+      stars[N].flags     = flags[N] & 0x0000ffff; // XXX totally arbitrary bits
+      stars[N].R         = ra[i] + dCOS(dec[i]) * offsetRa[N] / 3600.0;
+      stars[N].D         = dec[i] + offsetDec[N] / 3600.0;
+      stars[N].dR        = NAN;
+      stars[N].dD        = NAN;
+      stars[N].uR        = 0.0; // I don't trust the SDSS proper motions
+      stars[N].uD        = 0.0; // I don't trust the SDSS proper motions
+      stars[N].duR       = 0.0;
+      stars[N].duD       = 0.0;
+      stars[N].P         = 0.0;
+      stars[N].dP        = 0.0;
+      stars[N].Mcal      = 0.0;
+      stars[N].t         = tzero[j] + clockRate*rowc[N]; // time since row 0
+      stars[N].dt        = 53.907456; // is this 2048*clockRate ?
+
+      // longitude and latitude for SDSS:
+      // Latitude 32° 46' 49.30" N, Longitude 105° 49' 13.50" W
+      // longitude = 105.820419312 deg = 7.05469417
+      // latitude = 32.7803611755 deg
+
+      double Longitude = 7.05469417;   // hours (+ = W)
+      double Latitude = 32.7803611755; // degrees
+
+      jd = ohana_sec_to_jd (stars[N].t);
+      sidtime  = 15.0*ohana_lst (jd, Longitude); // sidtime in degrees
+      altaz (&alt, &az, sidtime - stars[N].R, stars[N].D, Latitude);
+
+      stars[N].airmass   = 1.0 / dCOS(90.0 - alt);
+      stars[N].az        = az;
+
+      stars[N].code      = photcode[j];
+      stars[N].found     = -1;
+      stars[N].dophot    = 0;
+    }
+  }    
+
+  for (i = 0; i < NFILTER; i++) {
+
+    N = i + *nimages;
+    
+    // XXX for now, we define a totally fake coordinate system centered on the first listed star
+    strcpy (images[N].coords.ctype, "RA---TAN");
+    
+    images[N].coords.crval1 = stars[0].R;
+    images[N].coords.crval2 = stars[0].D;
+    
+    images[N].coords.crpix1 = stars[0].X;
+    images[N].coords.crpix2 = stars[0].Y;
+    images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
+
+    images[N].coords.pc1_1 = 0.0;
+    images[N].coords.pc1_2 = 1.0;
+    images[N].coords.pc2_1 = 1.0;
+    images[N].coords.pc2_2 = 0.0;
+
+    images[N].coords.Npolyterms = 0;
+    memset (images[N].coords.polyterms, 0, 2*7*sizeof(float));
+
+    images[N].NX = 2048;
+    images[N].NY = 1490;
+
+    images[N].tzero = tzero[i];
+    images[N].cerror = 0.0;
+ 
+    // set photcodes for the 5 images (SDSS_U,G,R,I,Z)
+    images[N].photcode = photcode[i];
+
+    // calculate this from : C_OBS, TRACKING, and NY
+    images[N].exptime = 2048*clockRate;
+  
+    images[N].apmifit = 0.0;
+    images[N].dapmifit = 0.0;
+    images[N].detection_limit = 0.0; 
+    images[N].saturation_limit = 0.0;
+    images[N].fwhm_x = seeing[i];
+    images[N].fwhm_y = seeing[i];
+
+    // XXX longitude and latitude are known for SDSS
+    // SDSS is at : Latitude 32° 46' 49.30" N, Longitude 105° 49' 13.50" W
+    // longitude = 105.820419312 deg = 7.05469417
+    // latitude = 32.7803611755 deg
+
+    double Longitude = 7.05469417;   // hours (+ = W)
+    double Latitude = 32.7803611755; // degrees
+
+    jd = ohana_sec_to_jd (images[N].tzero);
+    images[N].sidtime  = ohana_lst (jd, Longitude);
+    images[N].latitude = Latitude;
+
+    altaz (&alt, &az, 15.0*images[N].sidtime - images[N].coords.crval1, images[N].coords.crval2, Latitude);
+
+    images[N].trate = clockRate * 1e-4;
+    images[N].secz = stars[0].airmass;
+    images[N].ccdnum = camcol;
+
+    // secz is in units milli-airmass
+    images[N].Mcal = 0.0;
+    images[N].Xm   = NAN_S_SHORT;
+    images[N].code = 0;
+
+    images[N].nstar = Nstars;
+  
+    images[N].imageID = N;
+    images[N].externID = 0;
+    images[N].sourceID = 0;
+
+    // save the filename
+    snprintf (images[N].name, 64, "%s[%s]", name, filtname[i]);
+  }
+
+  *nimages += NFILTER;
+  *nstars = Nstars*NFILTER;
+  return (stars);
+}
+
+// ha/dec -> alt/az
+int altaz (double *alt, double *az, double ha, double dec, double latitude) {
+
+  double sind, sinh, cosh;
+
+  sind = dSIN (dec) * dSIN (latitude) + dCOS (dec) * dCOS (ha) * dCOS (latitude);
+  *alt  = DEG_RAD * asin (sind);
+
+  sinh = - dCOS (dec) * dSIN (ha);
+  cosh =   dSIN (dec) * dCOS (latitude) - dCOS (dec) * dCOS (ha) * dSIN (latitude);
+
+  *az = DEG_RAD * atan2 (sinh, cosh);
+
+  // I may need to use the parallactic angle to get the right plate rotation...
+  // sinh = -dCOS(az) * dSIN(alt) * dSIN(ha) * dSIN(latitude) + dSIN(az) * dSIN(alt) * dCOS(ha) - dSIN(ha) * dCOS(alt) * dCOS(latitude);
+  // cosh = -dSIN(az) * dSIN(ha) * dSIN(latitude) - dCOS(az) * dCOS(ha);
+  // rot = -DEG_RAD * atan2 (sinh, cosh);
+  return TRUE;
+}
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsTEXT.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsTEXT.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/ReadStarsTEXT.c	(revision 16698)
@@ -80,5 +80,11 @@
       stars[N].dophot = tmp;
 
-      dparse (&stars[N].Mgal, 7, &buffer[j*BYTES_STAR]);
+      // XXX I've removed the Mgal field from the measure.d table, and am using Map
+      // instead.  DVO has not to date been used to track and study objects which are
+      // extended, but it is about to.  Related to this, I have created the concept of two
+      // extended source attribute tables, to carry the information being measured by the
+      // IPP.
+
+      // dparse (&stars[N].Mgal, 7, &buffer[j*BYTES_STAR]);
       dparse (&stars[N].Map,  8, &buffer[j*BYTES_STAR]);
       dparse (&stars[N].fx,   9, &buffer[j*BYTES_STAR]);
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/SEDfit.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/SEDfit.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/SEDfit.c	(revision 16698)
@@ -193,5 +193,4 @@
       outcat[0].measure[Nmeas].dt       = 0xffff;
 
-      outcat[0].measure[Nmeas].Mgal     = NAN;
       outcat[0].measure[Nmeas].airmass  = 0;
       outcat[0].measure[Nmeas].FWx      = NAN_S_SHORT;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/UpdateImageIDs.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/UpdateImageIDs.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/UpdateImageIDs.c	(revision 16698)
@@ -2,4 +2,8 @@
 
 int UpdateImageIDs (Stars *stars, int Nstars, Image *images, int Nimages) {
+
+  int i, status, isEmpty;
+  unsigned int imageID;
+  FITS_DB db;
 
   /*** update the image table ***/
@@ -14,4 +18,5 @@
     if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
     dvo_image_create (&db, GetZeroPoint());
+    isEmpty = TRUE;
   } else {
     /* position to start of file */
@@ -20,9 +25,11 @@
       Shutdown ("can't read image table phu %s", db.filename);
     }
+    isEmpty = FALSE;
   }
 
-  status = gfits_scan (&db.header, "IMAGEID", "%d", 1, &imageID);
+  // note that imageID is unsigned int
+  status = gfits_scan (&db.header, "IMAGEID", "%u", 1, &imageID);
   if (!status) {
-    status = gfits_scan (&db.header, "NIMAGES", "%d", 1, &imageID);
+    status = gfits_scan (&db.header, "NIMAGES", "%u", 1, &imageID);
   }
 
@@ -40,17 +47,25 @@
 
   imageID += Nimages;
-  status = gfits_modify (&db.header, "IMAGEID", "%d", 1, imageID);
-  
-  // write PHU
-  // position to start of file
-  Fseek (db.f, 0, SEEK_SET);
-  SetProtect (TRUE);
-  if (!gfits_fwrite_header (db.f, &db.header)) {
-    Shutdown ("can't write image table phu %s", db.filename);
+  status = gfits_modify (&db.header, "IMAGEID", "%u", 1, imageID);
+ 
+
+  if (isEmpty) {
+    dvo_image_addrows (&db, NULL, 0);
+    SetProtect (TRUE);
+    dvo_image_update (&db, VERBOSE);
+    SetProtect (FALSE);
+  } else {
+    // write just the PHU
+    // position to start of file
+    Fseek (db.f, 0, SEEK_SET);
+    SetProtect (TRUE);
+    if (!gfits_fwrite_header (db.f, &db.header)) {
+      Shutdown ("can't write image table phu %s", db.filename);
+    }
+    SetProtect (FALSE);
   }
-  SetProtect (FALSE);
 
   dvo_image_unlock (&db);
 
-  return 
+  return TRUE;
 }
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/addstarc.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/addstarc.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/addstarc.c	(revision 16698)
@@ -21,5 +21,8 @@
     case M_IMAGE:
       /* load data */
-      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, options.photcode);
+      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
+
+      // set and update the imageID sequence
+      UpdateImageIDs (stars, Nstars, images, Nimages);
 
       /* send data to server */
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/fakeimage.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/fakeimage.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/fakeimage.c	(revision 16698)
@@ -130,5 +130,4 @@
     image[i+1].Xm   = NAN_S_SHORT;
     image[i+1].code = 0;
-    memset (image[i+1].dummy, 0, sizeof(image[i+1].dummy));
 
     image[i+1].nstar = 0;
@@ -189,5 +188,4 @@
   image[0].Xm   = NAN_S_SHORT;
   image[0].code = 0;
-  memset (image[0].dummy, 0, sizeof(image[0].dummy));
   image[0].nstar = 0;
   image[0].Myyyy = 0;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches.c	(revision 16698)
@@ -10,4 +10,5 @@
   int Nave, NAVE, Nmeas, NMEAS, Nmatch;
   int Nsecfilt, Nsec;
+  unsigned int objID, catID;
   Coords tcoords;
 
@@ -183,5 +184,5 @@
       catalog[0].measure[Nmeas].photFlags = stars[N].flags;
       catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
-      catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+      catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
       catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
       catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
@@ -197,5 +198,5 @@
       catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
-      catalog[0].measure[Nmeas].Mgal     = stars[N].Mgal;
+      catalog[0].measure[Nmeas].Map      = stars[N].Map;
       catalog[0].measure[Nmeas].FWx      = 100*stars[N].fx;
       catalog[0].measure[Nmeas].FWy      = 100*stars[N].fy;
@@ -313,5 +314,5 @@
     catalog[0].measure[Nmeas].photFlags = stars[N].flags;
     catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
-    catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+    catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
     catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
     catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
@@ -327,5 +328,5 @@
     catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
-    catalog[0].measure[Nmeas].Mgal  	= stars[N].Mgal;
+    catalog[0].measure[Nmeas].Map  	= stars[N].Map;
     catalog[0].measure[Nmeas].FWx      	= 100*stars[N].fx;
     catalog[0].measure[Nmeas].FWy      	= 100*stars[N].fy;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_closest.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_closest.c	(revision 16698)
@@ -9,6 +9,7 @@
   int *N1, *N2,  *next_meas, *next_miss;
   int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
+  int Nsecfilt, Nsec;
+  unsigned int objID, catID;
   Coords tcoords;
-  int Nsecfilt, Nsec;
 
   /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
@@ -203,5 +204,5 @@
     catalog[0].measure[Nmeas].photFlags = stars[N].flags;
     catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
-    catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+    catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
     catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
     catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
@@ -217,5 +218,5 @@
     catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
-    catalog[0].measure[Nmeas].Mgal     = stars[N].Mgal;
+    catalog[0].measure[Nmeas].Map       = stars[N].Map;
 
     // XXX saturate range for FWx, FWy, theta
@@ -315,5 +316,5 @@
     catalog[0].measure[Nmeas].photFlags = stars[N].flags;
     catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
-    catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+    catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
     catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
     catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
@@ -329,5 +330,5 @@
     catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
-    catalog[0].measure[Nmeas].Mgal     = stars[N].Mgal;
+    catalog[0].measure[Nmeas].Map      = stars[N].Map;
     catalog[0].measure[Nmeas].FWx      = 100*stars[N].fx;
     catalog[0].measure[Nmeas].FWy      = 100*stars[N].fy;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_refstars.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_refstars.c	(revision 16698)
@@ -9,4 +9,5 @@
   int *N1, *N2,  *next, *next_miss, last, last_miss;
   int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
+  unsigned int objID, catID;
   Measure *tmpmeasure;
   Missing *tmpmissing;
@@ -147,5 +148,5 @@
       catalog[0].measure[Nmeas].dt       = 0xffff;
 
-      catalog[0].measure[Nmeas].Mgal     = NAN;
+      catalog[0].measure[Nmeas].Map      = NAN;
       catalog[0].measure[Nmeas].airmass  = 0;
       catalog[0].measure[Nmeas].FWx      = NAN_S_SHORT;
@@ -155,5 +156,5 @@
       catalog[0].measure[Nmeas].photFlags = 0;
       catalog[0].measure[Nmeas].qPSF      = 0;
-      catalog[0].measure[Nmeas].psfProb   = 0;
+      catalog[0].measure[Nmeas].psfChisq  = 0;
       catalog[0].measure[Nmeas].crNsigma  = 0;
       catalog[0].measure[Nmeas].extNsigma = 0;
@@ -281,5 +282,5 @@
     catalog[0].measure[Nmeas].photFlags = 0;
     catalog[0].measure[Nmeas].qPSF      = 0;
-    catalog[0].measure[Nmeas].psfProb   = 0;
+    catalog[0].measure[Nmeas].psfChisq  = 0;
     catalog[0].measure[Nmeas].crNsigma  = 0;
     catalog[0].measure[Nmeas].extNsigma = 0;
@@ -299,5 +300,5 @@
 
     catalog[0].measure[Nmeas].airmass  = 0;
-    catalog[0].measure[Nmeas].Mgal     = NAN;
+    catalog[0].measure[Nmeas].Map      = NAN;
     catalog[0].measure[Nmeas].FWx      = NAN_S_SHORT;
     catalog[0].measure[Nmeas].FWy      = NAN_S_SHORT;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_full.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_full.c	(revision 16698)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_full.c	(revision 16698)
@@ -0,0 +1,281 @@
+# include "addstar.h"
+# include "2mass.h"
+
+// fill in the data for a JHK triplet star.  takes a pointer to the start of the line the
+// RA and DEC have already been set
+int get2mass_3star_full (Stars *star, char *line, int Nmax) {
+
+  char *ptr;
+  double dMfull;
+  double jd;
+
+  if (line == NULL) Shutdown ("format error in 2mass");
+
+  ptr = line;		      // ra  (assumed to be already set)
+  ptr = next2MASSfield (ptr); // dec (assumed to be already set)
+  ptr = next2MASSfield (ptr); // err_maj
+  star[0].fx = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // err_min
+  star[0].fy = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // err_ang
+  star[0].df = strtod (ptr, NULL);
+
+  star[2].fx = star[2].fx = star[0].fx;
+  star[2].fy = star[2].fy = star[0].fy;
+  star[2].df = star[2].df = star[0].df;
+
+  ptr = next2MASSfield (ptr); // designation (skip)
+
+  ptr = next2MASSfield (ptr); // j_m
+  star[0].M  = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // j_cmsig
+  star[0].dM = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // j_msigcom
+  dMfull = strtod (ptr, NULL);
+  star[0].dMcal = sqrt (SQ(dMfull) - SQ(star[0].dM));
+  ptr = next2MASSfield (ptr); // j_snr (skip)
+
+  ptr = next2MASSfield (ptr); // h_m
+  star[1].M  = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // h_cmsig
+  star[1].dM = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // h_msigcom
+  dMfull = strtod (ptr, NULL);
+  star[1].dMcal = sqrt (SQ(dMfull) - SQ(star[1].dM));
+  ptr = next2MASSfield (ptr); // h_snr (skip)
+
+  ptr = next2MASSfield (ptr); // k_m
+  star[2].M  = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // k_cmsig
+  star[2].dM = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // k_msigcom
+  dMfull = strtod (ptr, NULL);
+  star[2].dMcal = sqrt (SQ(dMfull) - SQ(star[2].dM));
+  ptr = next2MASSfield (ptr); // k_snr (skip)
+
+  star[2].flags = star[1].flags = star[0].flags = 0;
+
+  ptr = next2MASSfield (ptr); // ph_qual
+  set2MASS_ph_qual (&star[0], ptr[0]);
+  set2MASS_ph_qual (&star[1], ptr[1]);
+  set2MASS_ph_qual (&star[2], ptr[2]);
+
+  ptr = next2MASSfield (ptr); // rd_flg
+  set2MASS_rd_flag (&star[0], ptr[0]);
+  set2MASS_rd_flag (&star[1], ptr[1]);
+  set2MASS_rd_flag (&star[2], ptr[2]);
+
+  ptr = next2MASSfield (ptr); // bl_flg
+  set2MASS_bl_flag (&star[0], ptr[0]);
+  set2MASS_bl_flag (&star[1], ptr[1]);
+  set2MASS_bl_flag (&star[2], ptr[2]);
+
+  ptr = next2MASSfield (ptr); // cc_flg
+  set2MASS_cc_flag (&star[0], ptr[0]);
+  set2MASS_cc_flag (&star[1], ptr[1]);
+  set2MASS_cc_flag (&star[2], ptr[2]);
+
+  ptr = next2MASSfield (ptr); // ndet (skip for now, XXX use somehow?)
+  ptr = next2MASSfield (ptr); // prox (skip)
+  ptr = next2MASSfield (ptr); // pxpa (skip)
+  ptr = next2MASSfield (ptr); // pxcntr (skip)
+
+  ptr = next2MASSfield (ptr); // gal_contam
+  set2MASS_gal_flag (&star[0], ptr[0]);
+  set2MASS_gal_flag (&star[1], ptr[1]);
+  set2MASS_gal_flag (&star[2], ptr[2]);
+
+  ptr = next2MASSfield (ptr); // gal_contam (one flag for all filters)
+  set2MASS_gal_flag (&star[0], ptr[0]);
+  set2MASS_gal_flag (&star[1], ptr[0]);
+  set2MASS_gal_flag (&star[2], ptr[0]);
+
+  ptr = next2MASSfield (ptr); // mp_flg (one flag for all filters)
+  set2MASS_mp_flag (&star[0], ptr[0]);
+  set2MASS_mp_flag (&star[1], ptr[0]);
+  set2MASS_mp_flag (&star[2], ptr[0]);
+
+  ptr = next2MASSfield (ptr); // pts_key (skip for now, XXX use somehow?)
+  ptr = next2MASSfield (ptr); // hemis (skip)
+  ptr = next2MASSfield (ptr); // date (skip)
+  ptr = next2MASSfield (ptr); // scan (skip)
+  ptr = next2MASSfield (ptr); // glon (skip)
+  ptr = next2MASSfield (ptr); // glat (skip)
+
+  ptr = next2MASSfield (ptr); // x_scan
+  star[0].X = strtod (ptr, NULL);
+  star[2].X = star[1].X = star[0].X;
+
+  ptr = next2MASSfield (ptr); // jdate (julian date)
+  jd = strtod (ptr, NULL);
+  star[0].t = ohana_jd_to_sec (jd);
+  star[2].t = star[1].t = star[0].t;
+
+  ptr = next2MASSfield (ptr); // j_psfchi
+  star[0].psfChisq = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // h_psfchi
+  star[1].psfChisq = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // k_psfchi
+  star[2].psfChisq = strtod (ptr, NULL);
+
+  ptr = next2MASSfield (ptr); // j_m_stdap
+  star[0].Map = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // j_msig_stdap (skip?)
+
+  ptr = next2MASSfield (ptr); // h_m_stdap
+  star[1].Map = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // h_msig_stdap (skip?)
+
+  ptr = next2MASSfield (ptr); // k_m_stdap
+  star[2].Map = strtod (ptr, NULL);
+  ptr = next2MASSfield (ptr); // k_msig_stdap (skip?)
+
+  ptr = next2MASSfield (ptr); // dist_edge_ns (skip)
+  ptr = next2MASSfield (ptr); // dist_edge_ew (skip)
+  ptr = next2MASSfield (ptr); // dist_edge_flg (skip)
+
+  ptr = next2MASSfield (ptr); // dup_src (one flag for all filters)
+  set2MASS_dup_flag (&star[0], ptr[0]);
+  set2MASS_dup_flag (&star[1], ptr[0]);
+  set2MASS_dup_flag (&star[2], ptr[0]);
+
+  ptr = next2MASSfield (ptr); // use_src (one flag for all filters)
+  set2MASS_use_flag (&star[0], ptr[0]);
+  set2MASS_use_flag (&star[1], ptr[0]);
+  set2MASS_use_flag (&star[2], ptr[0]);
+
+  star[0].code  = TM_J;
+  star[0].found = -1;
+  star[0].detID   = 0;
+  star[0].imageID = 0;
+
+  star[1].code  = TM_H;
+  star[1].found = -1;
+  star[1].detID   = 0;
+  star[1].imageID = 0;
+
+  star[2].code  = TM_K;
+  star[2].found = -1;
+  star[2].detID   = 0;
+  star[2].imageID = 0;
+
+  return TRUE;
+}
+
+/* return a pointer to the first char after the next field separator (|) */
+char *next2MASSfield (char *line) {
+
+  char *p, *q;
+
+  p = line;
+  q = strchr (p, '|');
+  if (q == NULL) return (NULL);
+  p = q + 1;
+  if (*p == 0) return (NULL);
+  return (p);
+}
+
+int set2MASS_ph_qual (Stars *star, char qual) {
+
+  switch (qual) {
+    case 'X': star[0].flags |= 0x0000; break;
+    case 'U': star[0].flags |= 0x0001; break;
+    case 'F': star[0].flags |= 0x0002; break;
+    case 'E': star[0].flags |= 0x0003; break;
+    case 'A': star[0].flags |= 0x0004; break;
+    case 'B': star[0].flags |= 0x0005; break;
+    case 'C': star[0].flags |= 0x0006; break;
+    case 'D': star[0].flags |= 0x0007; break;
+    default: 
+      fprintf (stderr, "error!\n");
+      exit (2);
+  }      
+  return (TRUE);
+}
+
+int set2MASS_rd_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].flags |= 0x0000; break;
+    case '1': star[0].flags |= 0x0010; break;
+    case '2': star[0].flags |= 0x0020; break;
+    case '3': star[0].flags |= 0x0030; break;
+    case '4': star[0].flags |= 0x0040; break;
+    case '6': star[0].flags |= 0x0050; break;
+    case '9': star[0].flags |= 0x0060; break;
+    default: 
+      fprintf (stderr, "error!\n");
+      exit (2);
+  }      
+  return (TRUE);
+}
+
+int set2MASS_cc_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case 'p': star[0].flags |= 0x0000; break;
+    case 'c': star[0].flags |= 0x0100; break;
+    case 'd': star[0].flags |= 0x0200; break;
+    case 's': star[0].flags |= 0x0300; break;
+    case 'b': star[0].flags |= 0x0400; break;
+    case '0': star[0].flags |= 0x0500; break;
+    default: 
+      fprintf (stderr, "error!\n");
+      exit (2);
+  }      
+  return (TRUE);
+}
+
+int set2MASS_bl_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].flags &= ~0x0008; break;
+    case '1': star[0].flags &= ~0x0008; break;
+    default:  star[0].flags |=  0x0008; break;
+  }      
+  return (TRUE);
+}
+
+int set2MASS_gal_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].flags &= ~0x0080; break;
+    case '1': star[0].flags &= ~0x0080; break;
+    default:  
+      star[0].flags |= 0x0080; 
+      star[0].extNsigma = 100.0;
+      break;
+  }      
+  return (TRUE);
+}
+
+int set2MASS_mp_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].flags &= ~0x0800; break;
+    case '1': star[0].flags &= ~0x0800; break;
+    default:  star[0].flags |=  0x0800; break;
+  }      
+  return (TRUE);
+}
+
+int set2MASS_dup_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].flags &= ~0x1000; break;
+    case '1': star[0].flags &= ~0x1000; break;
+    default:  star[0].flags |=  0x1000; break;
+  }      
+  return (TRUE);
+}
+
+int set2MASS_use_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].flags &= ~0x2000; break;
+    case '1': star[0].flags |=  0x2000; break;
+    default:  abort();
+  }      
+  return (TRUE);
+}
+
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/load2mass_as_rawdata.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/load2mass_as_rawdata.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/load2mass_as_rawdata.c	(revision 16698)
@@ -135,5 +135,5 @@
 	stars[Nstars+2].R = tstars[j].R;
 	stars[Nstars+2].D = tstars[j].D;
-	get2mass_3star (&stars[Nstars], &buffer[offset], Nbyte - offset);
+	get2mass_3star_full (&stars[Nstars], &buffer[offset], Nbyte - offset);
 	// get2mass_star (&stars[Nstars], &buffer[offset], Nbyte - offset);
 
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/load2mass_catalog.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/load2mass_catalog.c	(revision 16697)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/load2mass_catalog.c	(revision 16698)
@@ -47,21 +47,26 @@
     // we now have the min chisq row. use this to supply the other filter values....
     for (j = 0; j < 3; j++) {
-      catalog[0].measure[Nmeas].dR       = 0.0;
-      catalog[0].measure[Nmeas].dD       = 0.0;
-      catalog[0].measure[Nmeas].M        = stars[i+j].M;
-      catalog[0].measure[Nmeas].dM       = stars[i+j].dM;
-      catalog[0].measure[Nmeas].Mcal     = 0;
-      catalog[0].measure[Nmeas].t        = stars[i+j].t;
-      catalog[0].measure[Nmeas].averef   = Nave;
-      catalog[0].measure[Nmeas].photcode = stars[i+j].code;
-      catalog[0].measure[Nmeas].dophot   = 0;
-      catalog[0].measure[Nmeas].dbFlags  = 0;
-      catalog[0].measure[Nmeas].dt       = 0xffff;
-
-      catalog[0].measure[Nmeas].Mgal     = NAN;
-      catalog[0].measure[Nmeas].airmass  = 0;
-      catalog[0].measure[Nmeas].FWx      = NAN_S_SHORT;
-      catalog[0].measure[Nmeas].FWy      = NAN_S_SHORT;
-      catalog[0].measure[Nmeas].theta    = NAN_S_SHORT;
+      catalog[0].measure[Nmeas].dR        = 0.0;
+      catalog[0].measure[Nmeas].dD        = 0.0;
+      catalog[0].measure[Nmeas].Xccd      = stars[i+j].X;
+      catalog[0].measure[Nmeas].Yccd      = stars[i+j].Y;
+      catalog[0].measure[Nmeas].dXccd     = 0.0;
+      catalog[0].measure[Nmeas].dYccd     = 0.0;
+      catalog[0].measure[Nmeas].M         = stars[i+j].M;
+      catalog[0].measure[Nmeas].dM        = stars[i+j].dM;
+      catalog[0].measure[Nmeas].Mcal      = 0;
+      catalog[0].measure[Nmeas].dMcal     = stars[i+j].dMcal;
+      catalog[0].measure[Nmeas].t         = stars[i+j].t;
+      catalog[0].measure[Nmeas].averef    = Nave;
+      catalog[0].measure[Nmeas].photcode  = stars[i+j].code;
+      catalog[0].measure[Nmeas].dophot    = 0;
+      catalog[0].measure[Nmeas].photFlags = stars[i+j].flags;
+      catalog[0].measure[Nmeas].dbFlags   = 0;
+      catalog[0].measure[Nmeas].dt        = 0xffff;
+					  
+      catalog[0].measure[Nmeas].airmass   = 0;
+      catalog[0].measure[Nmeas].FWx       = stars[i+j].fx;
+      catalog[0].measure[Nmeas].FWy       = stars[i+j].fy;
+      catalog[0].measure[Nmeas].theta     = stars[i+j].df;
 
       catalog[0].average[Nave].Nmeasure++;
