Index: /trunk/Ohana/src/addstar/doc/wise.catalog.txt
===================================================================
--- /trunk/Ohana/src/addstar/doc/wise.catalog.txt	(revision 32346)
+++ /trunk/Ohana/src/addstar/doc/wise.catalog.txt	(revision 32346)
@@ -0,0 +1,276 @@
+designation     %20s     ----   no       Sexagesimal, equatorial position-based source name in the form: hhmmss.ss+ddmmss.s. The full naming convention for WISE Preliminary Release Catalog sources has the form "WISEP  Jhhmmss.ss+ddmmss.s," where "WISEP" indicates the source is from the Preliminary Release Source Catalog, and "J" indicates the position is J2000. The "WISEP" acronym is not listed explicitly in the designation column.
+ra              %10.6f  deg     no       J2000 right ascension with respect to the 2MASS PSC reference frame     
+dec             %10.6f  deg     no       J2000 declination with respect to the 2MASS PSC reference frame.
+sigra           %4.2f   arcsec  no      One-sigma uncertainty in right ascension coordinate.     
+sigdec          %4.2f   arcsec  no      One-sigma uncertainty in declination coordinate.
+sigradec        %3d     deg     no      The co-sigma of the equatorial position uncertainties, sig_ra, sig_dec (ÏÎ±, ÏÎŽ). The co-sigma is related to the covariance between the position errors VÎ±ÎŽ   by the formula VÎ±ÎŽ = ÏÎ±ÎŽ|ÏÎ±ÎŽ|. This maintains the sign information for the correlation, since ÏÎ±ÎŽ may be negative. It is more natural to carry the co-sigma along with the other uncertainties instead of the covariance because the former is in the same units as the other uncertainties.         
+glon            %7.3f   deg     no      Galactic longitude. CAUTION: This coordinate should not be used as an astrometric reference.
+glat            %7.3f   deg     no      Galactic latitude. CAUTION: This coordinate should not be used as an astrometric reference.
+elon            %7.3f   deg     no      Ecliptic longitude. CAUTION: This coordinate should not be used as an astrometric reference.
+elat            %7.3f   deg     no      Ecliptic latitude. CAUTION: This coordinate should not be used as an astrometric reference.
+wx              %7.3f   pix     no      The x-pixel coordinate of this source on the Atlas Image.
+wy              %7.3f   pix     no      The y-pixel coordinate of this source on the Atlas Image.
+cntr            %19d    ----    no      Unique identification number for the Catalog source. This number is formed entirely from the source_id, which is in turn formed from the coadd_id and source number src. On average, sources with cntr values close to each other are also close to each other on the sky, except at Tile boundaries. Cntr ordering thus provides a useful mapping of the WISE Catalog on storage media.
+source_id       %28s    ----    no      Unique source ID, formed from a combination of the Atlas Tile ID, coadd_id, and sequential extracted source number, src, within the Tile. The source_id string has the form RRRRsDDD_[trev]-IIIIII where:
+coadd_id        %20s    ----    no      Atlas Tile identifier from which source was extracted. The identifier has the general form: RRRRsDDD_[trev], where
+src             %6d     ----    no      Sequential number of this source extraction in the Atlas Tile from which this source was extracted, in approximate descending order of W1 source brightness.     
+w1mpro          %7.3f   mag     yes     W1 magnitude measured with profile-fitting photometry, or the magnitude of the 95% confidence brightness upper limit if the W1 flux measurement has SNR<2. This column is null if the source is nominally detected in W1, but no useful brightness estimate could be made.       
+w1sigmpro       %5.3f   mag     yes     W1 profile-fit photometric measurement uncertainty in mag units. This column is null if the W1 profile-fit magnitude is a 95% confidence upper limit or if the source is not measurable.         
+w1snr           %7.1f   ----    yes     W1 profile-fit measurement signal-to-noise ratio. This value is the ratio of the flux (w1flux) to flux uncertainty (w1sigflux)in the W1 profile-fit photometry measurement. This column is null if w1flux is negative, or if w1flux or w1sigflux are null.       
+w1rchi2         %9.3e   ----    yes     Reduced Ï2 of the W1 profile-fit photometry measurement. This column is null if the W1 magnitude is a 95% confidence upper limit (i.e. the source is not detected).      
+w2mpro          %7.3f   mag     yes     W2 magnitude measured with profile-fitting photometry, or the magnitude of the 95% confidence brightness upper limit if the W2 flux measurement has SNR<2. This column is null if the source is nominally detected in W1, but no useful brightness estimate could be made.       
+w2sigmpro       %5.3f   mag     yes     W2 profile-fit photometric measurement uncertainty in mag units. This column is null if the W2 profile-fit magnitude is a 95% confidence upper limit or if the source is not measurable.         
+w2snr           %7.1f   ----    yes     W2 profile-fit measurement signal-to-noise ratio. This value is the ratio of the flux (w2flux to flux uncertainty (w2sigflux)in the W2 profile-fit photometry measurement. This column is null if w2flux is negative, or if w2flux or w2sigflux are null.        
+w2rchi2         %9.3e   ----    yes     Reduced Ï2 of the W2 profile-fit photometry measurement. This column is null if the W2 magnitude is a 95% confidence upper limit (i.e. the source is not detected).      
+w3mpro          %7.3f   mag     yes     W3 magnitude measured with profile-fitting photometry, or the magnitude of the 95% confidence brightness upper limit if the W3 flux measurement has SNR<2. This column is null if the source is nominally detected in W3, but no useful brightness estimate could be made.       
+w3sigmpro       %5.3f   mag     yes     W3 profile-fit photometric measurement uncertainty in mag units. This column is null if the W3 profile-fit magnitude is a 95% confidence upper limit or if the source is not measurable.         
+w3snr           %7.1f   ----    yes     W3 profile-fit measurement signal-to-noise ratio. This value is the ratio of the flux (w3flux to flux uncertainty (w3sigflux)in the W3 profile-fit photometry measurement. This column is null if w3flux is negative, or if w3flux or w3sigflux are null.        
+w3rchi2         %9.3e   ----    yes     Reduced Ï2 of the W3 profile-fit photometry measurement. This column is null if the W3 magnitude is a 95% confidence upper limit (i.e. the source is not detected).      
+w4mpro          %7.3f   mag     yes     W4 magnitude measured with profile-fitting photometry, or the magnitude of the 95% confidence brightness upper limit if the W4 flux measurement has SNR<2. This column is null if the source is nominally detected in W4, but no useful brightness estimate could be made.       
+w4sigmpro       %5.3f   mag     yes     W4 profile-fit photometric measurement uncertainty in mag units. This column is null if the W4 profile-fit magnitude is a 95% confidence upper limit or if the source is not measurable.         
+w4snr           %7.1f   ----    yes     W4 profile-fit measurement signal-to-noise ratio. This value is the ratio of the flux (w4flux to flux uncertainty (w4sigflux)in the W4 photometry measurement. This column is null if w4flux is negative, or if w4flux or w4sigflux are null.    
+w4rchi2         %9.3e   ----    yes     Reduced Ï2 of the W4 profile-fit photometry measurement. This column is null if the W4 magnitude is a 95% confidence upper limit (i.e. the source is not detected).      
+rchi2           %9.3f   ----    yes     Combine reduced Ï2 of the profile-fit photometry measurement in all bands.       
+nb              %1d     ----    yes     Number of PSF components used simultaneously in the profile-fitting for this source. This number includes the source itself, so the minimum value of nb is "1". Nb is greater than "1" when the source is fit concurrently with other nearby detections (passive deblending), or when a single source is split into two components during the fitting process (active deblending).       
+na              %1d     ----    yes     Active deblending flag. Indicates if a single detection was split into multiple sources in the process of profile-fitting. 
+w1sat           %5.3f   ----    yes     Saturated pixel fraction, W1. The fraction of all pixels within the profile-fitting area in the stack of single-exposure images used to characterize this source that are flagged as saturated. A value larger than 0.0 indicates one or more pixels of saturation. Saturation begins to occur for point sources brighter than [W1]~8 mag. Saturation may occur in fainter sources because of a charged particle strike.         
+w2sat           %5.3f   ----    yes     Saturated pixel fraction, W2. The fraction of all pixels within the profile-fitting area in the stack of single-exposure images used to characterize this source that are flagged as saturated. A value larger than 0.0 indicates one or more pixels of saturation. Saturation begins to occur for point sources brighter than [W2]~7 mag. Saturation may occur in fainter sources because of a charged particle strike.         
+w3sat           %5.3f   ----    yes     Saturated pixel fraction, W3. The fraction of all pixels within the profile-fitting area source in the stack of single-exposure images used to characterize this source that are flagged as saturated. A value larger than 0.0 indicates one or more pixels of saturation. Saturation begins to occur for point sources brighter than [W3]~4 mag. Saturation may occur in fainter sources because of a charged particle strike.  
+w4sat           %5.3f   ----    yes     Saturated pixel fraction, W4. The fraction of all pixels within the profile-fitting area in the stack of single-exposure images used to characterize this source that are flagged as saturated. A value larger than 0.0 indicates one or more pixels of saturation. Saturation begins to occur for point sources brighter than [W4]~0 mag. Saturation may occur in fainter sources because of a charged particle strike.         
+satnum          %4s     ----    no      Minimum sample at which saturation occurs in each band. Four character string, one character per band, that indicates the minimum SUTR sample in which any pixel in the profile-fitting area in all of the single-exposure images used to characterize this source was flagged as having reached the saturation level in the on-board WISE payload processing. If no pixels in a given band are flagged as saturated, the value for that band is "0".    
+cc_flags        %4s     ----    no      Contamination and confusion flag. Four character strong, one character per band [W1/W2/W3/W4], that indicates that the photometry and/or position measurements of a source may be contaminated or biased due to proximity to an image artifact.
+ext_flg         %1d     ----    no      Extended source flag. This flag indicates whether or not the morphology of a source is consistent with the WISE point spread function in any band.
+var_flg         %4s     ----    yes     Variability flag. The variability flag is a four-character string, one character per band, in which the value for each band is related to the probability that the source flux measured on the individual WISE exposures was not constant with time.
+ph_qual         %4s     ----    no      
+
+det_bit         %3d     ----    no      Bit-encoded integer indicating bands in which a source has a w?snr>2 detection. For example, a source detected in W1 only has det_bit=1 (binary 0001). A source detected in W4 only has det_bit=8 (binary 1000). A source detected in all four bands has det_bit=15 (binary 1111).       
+w1nm            %6d     ----    yes     Integer frame detection count. This column gives the number of individual 7.7s exposures on which this source was detected with SNR>3 in the W1 profile-fit measurement. This number can be zero for sources that are well-detected on the coadded Atlas Image, but too faint for detection on the single exposures.     
+w1m             %6d     ----    yes     Integer frame coverage. This column gives the number of individual 7.7s W1 exposures on which a profile-fit measurement of this source was possible.
+w2nm            %6d     ----    yes     Integer frame detection count. This column gives the number of individual 7.7s exposures on which this source was detected with SNR>3 in the W2 profile-fit measurement. This number can be zero for sources that are well-detected on the coadded Atlas Image, but too faint for detection on the single exposures.     
+w2m             %6d     ----    yes     Integer frame coverage. This column gives the number of individual 8.8s W2 exposures on which a profile-fit measurement of this source was possible.
+
+w3nm            %6d     ----    yes     Integer frame detection count. This column gives the number of individual 8.8s exposures on which this source was detected with SNR>3 in the W3 profile-fit measurement. This number can be zero for sources that are well-detected on the coadded Atlas Image, but too faint for detection on the single exposures.     
+w3m             %6d     ----    yes     Integer frame coverage. This column gives the number of individual 7.7s W3 exposures on which a profile-fit measurement of this source was possible.
+w4nm            %6d     ----    yes     Integer frame detection count. This column gives the number of individual 8.8s exposures on which this source was detected with SNR>3 in the W4 profile-fit measurement. This number can be zero for sources that are well-detected on the coadded Atlas Image, but too faint for detection on the single exposures.     
+w4m             %6d     ----    yes     Integer frame coverage. This column gives the number of individual 8.8s W4 exposures on which a profile-fit measurement of this source was possible.
+w1cov           %7.3f   ----    yes     Mean pixel coverage in W1. This column gives the mean pixel value from the W1 Atlas Tile Coverage Map within the "standard" aperture, a circular area with a radius of 8.25" centered on the position of this source.
+
+w2cov           %7.3f   ----    yes     Mean pixel coverage in W2. This column gives the mean pixel value from the W2 Atlas Tile Coverage Map within the "standard" aperture, a circular area with a radius of 8.25" centered on the position of this source.
+w3cov           %7.3f   ----    yes     Mean pixel coverage in W3. This column gives the mean pixel value from the W3 Atlas Tile Coverage Map within the "standard" aperture, a circular area with a radius of 8.25" centered on the position of this source.
+w4cov           %7.3f   ----    yes     Mean pixel coverage in W4. This column gives the mean pixel value from the W4 Atlas Tile Coverage Map within the "standard" aperture, a circular area with a radius of 17.0" centered on the position of this source.
+w1frl           %5.3f   ----    yes     Fraction of pixels affected by latents. This column gives the fraction of all W1 pixels in the stack of individual W1 exposures used to characterize this source that may be affected by the presence of a latent image produced by a bright source. This number is computed by counting the number of pixels in the single exposure Bit Mask images with value "25" that are present within the profile-fitting area, a circular region with radius of 7.25", centered on the position of this source, and dividing by the total number of pixels in the same area that are available for measurement.  
+w2frl           %5.3f   ----    yes     Fraction of pixels affected by latents. This column gives the fraction of all W2 pixels in the stack of individual W2 exposures used to characterize this source that may be affected by the presence of a latent image produced by a bright source. This number is computed by counting the number of pixels in the single exposure Bit Mask images with value "25" that are present within the profile-fitting area, a circular region with radius of 7.25", centered on the position of this source, and dividing by the total number of pixels in the same area that are available for measurement.  
+
+w3frl           %5.3f   ----    yes     Fraction of pixels affected by latents. This column gives the fraction of all W3 pixels in the stack of individual W3 exposures used to characterize this source that may be affected by the presence of a latent image produced by a bright source. This number is computed by counting the number of pixels in the single exposure Bit Mask images with value "25" that are present within the profile-fitting area, a circular region with radius of 7.25", centered on the position of this source, and dividing by the total number of pixels in the same area that are available for measurement.  
+w4frl           %5.3f   ----    yes     Fraction of pixels affected by latents. This column gives the fraction of all W4 pixels in the stack of individual W4 exposures used to characterize this source that may be affected by the presence of a latent image produced by a bright source. This number is computed by counting the number of pixels in the single exposure Bit Mask images with value '25' that are present within the profile-fitting area, a circular region with radius of 15.0", centered on the position of this source, and dividing by the total number of pixels in the same area that are available for measurement.  
+w1cc_map        %3d     ----    no      Contamination and confusion map for this source in W1. This column contains the integer equivalent of the 9-bit binary number that specifies if the W1 measurement is believed to be contaminated by or a spurious detection of an image artifact. The elements of the binary array are:
+w1cc_map_str    %12s    ----    yes     Contamination and confusion string. This column is a character string that denotes all artifacts that may contaminate the W1 measurement of this source, in the priority order D,P,H,O. Lower-case letters denote cases where the source detection in this band is believed to be real but the measurement may be contaminated by the artifact. upper-case letters denote cases where the source detection in this band may be a spurious detection of an artifact.
+w2cc_map        %3d     ----    no      Contamination and confusion map for this source in W2. This column contains the integer equivalent of the 9-bit binary number that specifies if the W2 measurement is believed to be contaminated by or a spurious detection of an image artifact. The elements of the binary array are:
+
+w2cc_map_str    %12s    ----    yes     
+w3cc_map        %3d     ----    no      Contamination and confusion map for this source in W3. This column contains the integer equivalent of the 9-bit binary number that specifies if the W3 measurement is believed to be contaminated by or a spurious detection of an image artifact. The elements of the binary array are:
+w3cc_map_str    %12s    ----    yes     Contamination and confusion string. This column is a character string that denotes all artifacts that may contaminate the W3 measurement of this source, in the priority order D,P,H,O. Lower-case letters denote cases where the source detection in this band is believed to be real but the measurement may be contaminated by the artifact. Upper-case letters denote cases where the source detection in this band may be a spurious detection of an artifact.
+w4cc_map        %3d     ----    no      Contamination and confusion map for this source in W4. This column contains the integer equivalent of the 9-bit binary number that specifies if the W4 measurement is believed to be contaminated by or a spurious detection of an image artifact. The elements of the binary array are:
+w4cc_map_str    %12s    ----    yes     Contamination and confusion string. This column is a character string that denotes all artifacts that may contaminate the W4 measurement of this source, in the priority order D,P,H,O. Lower-case letters denote cases where the source detection in this band is believed to be real but the measurement may be contaminated by the artifact. Upper-case letters denote cases where the source detection in this band may be a spurious detection of an artifact.
+- skip 25 felds
+
+w1flux          %9.3f   dn      yes     The "raw" W1 source flux measured in profile-fit photometry in units of digital numbers. This value may be negative. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.  
+w1sigflux       %9.3f   dn      yes     Uncertainty in the "raw" W1 source flux measurement in profile-fit photometry in units of digital numbers. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.    
+w1sky           %9.3f   dn      yes      The trimmed average of the W1 sky background value in digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70". Both profile-fit and aperture photometry source brightness measurements are made relative to this sky background value.
+w1sigsk         %7.3f   dn      yes     The uncertainty in the W1 sky background value in units of digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70".   
+w1conf          %9.3f   dn      yes     Estimated confusion noise in the W1 sky background annulus, in digital numbers. This number is the difference between the measured noise in the sky background w1sigsk and the noise measured in the same region on the Atlas Uncertainty Maps.  
+w2flux          %9.3f   dn      yes     The "raw" W2 source flux measured in profile-fit photometry in units of digital numbers. This value may be negative. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.  
+w2sigflux       %9.3f   dn      yes     Uncertainty in the "raw" W2 source flux measurement in profile-fit photometry in units of digital numbers. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.    
+w2sky           %9.3f   dn      yes      The trimmed average of the W2 sky background value in digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70". Both profile-fit and aperture photometry source brightness measurements are made relative to this sky background value.
+w2sigsk         %7.3f   dn      yes     The uncertainty in the W2 sky background value in units of digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70".   
+w2conf          %9.3f   dn      yes     Estimated confusion noise in the W2 sky background annulus, in digital numbers. This number is the difference between the measured noise in the sky background w2sigsk and the noise measured in the same region on the Atlas Uncertainty Maps.  
+w3flux          %9.3f   dn      yes     The "raw" W3 source flux measured in profile-fit photometry in units of digital numbers. This value may be negative. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.  
+w3sigflux       %9.3f   dn      yes     Uncertainty in the "raw" W3 source flux measurement in profile-fit photometry in units of digital numbers. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.    
+w3sky           %9.3f   dn      yes      The trimmed average of the W3 sky background value in digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70". Both profile-fit and aperture photometry source brightness measurements are made relative to this sky background value.
+w3sigsk         %7.3f   dn      yes     The uncertainty in the W3 sky background value in units of digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70".   
+w3conf          %9.3f   dn      yes     Estimated confusion noise in the W3 sky background annulus, in digital numbers. This number is the difference between the measured noise in the sky background w3sigsk and the noise measured in the same region on the Atlas Uncertainty Maps.  
+w4flux          %9.3f   dn      yes     The "raw" W1 source flux measured in profile-fit photometry in units of digital numbers. This value may be negative. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.  
+w4sigflux       %9.3f   dn      yes     Uncertainty in the "raw" W1 source flux measurement in profile-fit photometry in units of digital numbers. This column is null if no useful profile-fit measurement of the source is possible because of masked or otherwise unusable pixels.    
+w4sky           %9.3f   dn      yes      The trimmed average of the W1 sky background value in digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70". Both profile-fit and aperture photometry source brightness measurements are made relative to this sky background value.
+w4sigsk         %7.3f   dn      yes     The uncertainty in the W1 sky background value in units of digital numbers measured in an annulus with an inner radius of 50" and outer radius of 70".   
+w4conf          %9.3f   dn      yes     Estimated confusion noise in the W1 sky background annulus, in digital numbers. This number is the difference between the measured noise in the sky background w4sigsk and the noise measured in the same region on the Atlas Uncertainty Maps.  
+- skip 20 fields
+
+w1mag           %7.3f   mag     yes     W1 "standard" aperture magnitude. This is the curve-of-growth corrected source brightness measured in an 8.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". The curve-of-growth correction is given in w1mcor.
+w1sigm          %5.3f   mag     yes     Uncertainty in the W1 "standard" aperture magnitude.
+w1flg           %3d     ----    yes      W1 "standard" aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag value is an integer that is the combination of one or more of the following values that signify different conditions: 
+w1mcor          %6.3f   mag     yes      W1 aperture curve-of-growth correction, in magnitudes. This correction is subtracted from the nominal 8.25" aperture photometry brightness, w1mag_2, to give the "standard-aperture" magnitude.         
+
+w2mag           %7.3f   mag     yes     W2 "standard" aperture magnitude. This is the curve-of-growth corrected source brightness measured in an 8.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". The curve-of-growth correction is given in w2mcor.
+w2sigm          %5.3f   mag     yes     Uncertainty in the W2 "standard" aperture magnitude.
+w2flg           %3d     ----    yes      W2 "standard" aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag value is an integer that is the combination of one or more of the following values that signify different conditions: 
+w2mcor          %6.3f   mag     yes      W2 aperture curve-of-growth correction, in magnitudes. This correction is subtracted from the nominal 8.25" aperture photometry brightness, w2mag_2, to give the "standard-aperture" magnitude.         
+
+w3mag           %7.3f   mag     yes     W3 "standard" aperture magnitude. This is the curve-of-growth corrected source brightness measured in an 8.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". The curve-of-growth correction is given in w3mcor.
+w3sigm          %5.3f   mag     yes     Uncertainty in the W3 "standard" aperture magnitude.
+w3flg           %3d     ----    yes      W3 "standard" aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag value is an integer that is the combination of one or more of the following values that signify different conditions: 
+w3mcor          %6.3f   mag     yes      W3 aperture curve-of-growth correction, in magnitudes. This correction is subtracted from the nominal 8.25" aperture photometry brightness, w3mag_2, to give the "standard-aperture" magnitude.         
+
+w4mag           %7.3f   mag     yes     W4 "standard" aperture magnitude. This is the curve-of-growth corrected source brightness measured in a 16.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". The curve-of-growth correction is given in w4mcor.
+w4sigm          %5.3f   mag     yes     Uncertainty in the W4 "standard" aperture magnitude.
+w4flg           %3d     ----    yes      W4 "standard" aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag value is an integer that is the combination of one or more of the following values that signify different conditions: 
+w4mcor          %6.3f   mag     yes      W4 aperture curve-of-growth correction, in magnitudes. This correction is subtracted from the nominal 16.5" aperture photometry brightness, w4mag_2, to give the "standard-aperture" magnitude.         
+- 16 fields
+
+w1mag_1         %7.3f   mag     yes     W1 5.5" radius aperture magnitude. This is the calibrated source brightness measured in a 5.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_1        %5.3f   mag     yes     Uncertainty in the W1 5.5" radius aperture magnitude.
+w1flg_1         %3d     ----    yes      W1 5.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.         
+w2mag_1         %7.3f   mag     yes     W2 5.5" radius aperture magnitude. This is the calibrated source brightness measured in a 5.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_1        %5.3f   mag     yes     Uncertainty in the W2 5.5" radius aperture magnitude.
+w2flg_1         %3d     ----    yes      W2 5.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.         
+w3mag_1         %7.3f   mag     yes     W3 5.5" radius aperture magnitude. This is the calibrated source brightness measured in a 5.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_1        %5.3f   mag     yes     Uncertainty in the W3 5.5" radius aperture magnitude.
+w3flg_1         %3d     ----    yes      W3 5.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.         
+w4mag_1         %7.3f   mag     yes     W4 11.0" radius aperture magnitude. This is the calibrated source brightness measured in a 11.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_1        %5.3f   mag     yes     Uncertainty in the W4 11.0" radius aperture magnitude.
+w4flg_1         %3d     ----    yes      W4 11.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_2         %7.3f   mag     yes     W1 8.25" radius aperture magnitude. This is the calibrated source brightness measured in a 8.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_2        %5.3f   mag     yes     Uncertainty in the W1 8.25" radius aperture magnitude.
+w1flg_2         %3d     ----    yes      W1 8.25" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.        
+w2mag_2         %7.3f   mag     yes     W2 8.25" radius aperture magnitude. This is the calibrated source brightness measured in a 8.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_2        %5.3f   mag     yes     Uncertainty in the W2 8.25" radius aperture magnitude.
+w2flg_2         %3d     ----    yes      W2 8.25" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.        
+w3mag_2         %7.3f   mag     yes     W3 8.25" radius aperture magnitude. This is the calibrated source brightness measured in a 8.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_2        %5.3f   mag     yes     Uncertainty in the W3 8.25" radius aperture magnitude.
+w3flg_2         %3d     ----    yes      W3 8.25" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.        
+w4mag_2         %7.3f   mag     yes     W4 16.5" radius aperture magnitude. This is the calibrated source brightness measured in a 16.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_2        %5.3f   mag     yes     Uncertainty in the W4 16.5" radius aperture magnitude.
+w4flg_2         %3d     ----    yes      W4 16.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_3         %7.3f   mag     yes     W1 11.0" radius aperture magnitude. This is the calibrated source brightness measured in a 11.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_3        %5.3f   mag     yes     Uncertainty in the W1 11.0" radius aperture magnitude.
+w1flg_3         %3d     ----    yes      W1 11.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.        
+w2mag_3         %7.3f   mag     yes     W2 11.0" radius aperture magnitude. This is the calibrated source brightness measured in a 11.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_3        %5.3f   mag     yes     Uncertainty in the W2 11.0" radius aperture magnitude.
+w2flg_3         %3d     ----    yes      W2 11.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.        
+w3mag_3         %7.3f   mag     yes     W3 11.0" radius aperture magnitude. This is the calibrated source brightness measured in a 11.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_3        %5.3f   mag     yes     Uncertainty in the W3 11.0" radius aperture magnitude.
+w3flg_3         %3d     ----    yes      W3 11.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.        
+w4mag_3         %7.3f   mag     yes     W4 22.0" radius aperture magnitude. This is the calibrated source brightness measured in a 22.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_3        %5.3f   mag     yes     Uncertainty in the W4 22.0" radius aperture magnitude.
+w4flg_3         %3d     ----    yes      W4 22.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_4         %7.3f   mag     yes     W1 13.75" radius aperture magnitude. This is the calibrated source brightness measured in a 13.75" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_4        %5.3f   mag     yes     Uncertainty in the W1 13.75" radius aperture magnitude.
+w1flg_4         %3d     ----    yes      W1 13.75" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.       
+w2mag_4         %7.3f   mag     yes     W2 13.75" radius aperture magnitude. This is the calibrated source brightness measured in a 13.75" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_4        %5.3f   mag     yes     Uncertainty in the W2 13.75" radius aperture magnitude.
+w2flg_4         %3d     ----    yes      W2 13.75" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.       
+w3mag_4         %7.3f   mag     yes     W3 13.75" radius aperture magnitude. This is the calibrated source brightness measured in a 13.75" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_4        %5.3f   mag     yes     Uncertainty in the W3 13.75" radius aperture magnitude.
+w3flg_4         %3d     ----    yes      W3 13.75" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.       
+w4mag_4         %7.3f   mag     yes     W4 27.5" radius aperture magnitude. This is the calibrated source brightness measured in a 27.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_4        %5.3f   mag     yes     Uncertainty in the W4 27.5" radius aperture magnitude.
+w4flg_4         %3d     ----    yes      W4 27.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_5         %7.3f   mag     yes     W1 16.5" radius aperture magnitude. This is the calibrated source brightness measured in a 16.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_5        %5.3f   mag     yes     Uncertainty in the W1 16.5" radius aperture magnitude.
+w1flg_5         %3d     ----    yes      W1 16.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.        
+w2mag_5         %7.3f   mag     yes     W2 16.5" radius aperture magnitude. This is the calibrated source brightness measured in a 16.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_5        %5.3f   mag     yes     Uncertainty in the W2 16.5" radius aperture magnitude.
+w2flg_5         %3d     ----    yes      W2 16.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.        
+w3mag_5         %7.3f   mag     yes     W3 16.5" radius aperture magnitude. This is the calibrated source brightness measured in a 16.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_5        %5.3f   mag     yes     Uncertainty in the W3 16.5" radius aperture magnitude.
+w3flg_5         %3d     ----    yes      W3 16.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.        
+w4mag_5         %7.3f   mag     yes     W4 33.0" radius aperture magnitude. This is the calibrated source brightness measured in a 33.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_5        %5.3f   mag     yes     Uncertainty in the W4 33.0" radius aperture magnitude.
+w4flg_5         %3d     ----    yes      W4 33.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_6         %7.3f   mag     yes     W1 19.25" radius aperture magnitude. This is the calibrated source brightness measured in a 19.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_6        %5.3f   mag     yes     Uncertainty in the W1 19.25" radius aperture magnitude.
+w1flg_6         %3d     ----    yes      W1 19.25" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.       
+w2mag_6         %7.3f   mag     yes     W2 19.25" radius aperture magnitude. This is the calibrated source brightness measured in a 19.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_6        %5.3f   mag     yes     Uncertainty in the W2 19.25" radius aperture magnitude.
+w2flg_6         %3d     ----    yes      W2 19.25" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.       
+w3mag_6         %7.3f   mag     yes     W3 19.25" radius aperture magnitude. This is the calibrated source brightness measured in a 19.25" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_6        %5.3f   mag     yes     Uncertainty in the W3 19.25" radius aperture magnitude.
+w3flg_6         %3d     ----    yes      W3 19.25" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.       
+w4mag_6         %7.3f   mag     yes     W4 38.5" radius aperture magnitude. This is the calibrated source brightness measured in a 38.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_6        %5.3f   mag     yes     Uncertainty in the W4 38.5" radius aperture magnitude.
+w4flg_6         %3d     ----    yes      W4 38.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_7         %7.3f   mag     yes     W1 22.0" radius aperture magnitude. This is the calibrated source brightness measured in a 22.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_7        %5.3f   mag     yes     Uncertainty in the W1 22.0" radius aperture magnitude.
+w1flg_7         %3d     ----    yes      W1 22.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.        
+w2mag_7         %7.3f   mag     yes     W2 22.0" radius aperture magnitude. This is the calibrated source brightness measured in a 22.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_7        %5.3f   mag     yes     Uncertainty in the W2 22.0" radius aperture magnitude.
+w2flg_7         %3d     ----    yes      W2 22.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.        
+w3mag_7         %7.3f   mag     yes     W3 22.0" radius aperture magnitude. This is the calibrated source brightness measured in a 22.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_7        %5.3f   mag     yes     Uncertainty in the W3 22.0" radius aperture magnitude.
+w3flg_7         %3d     ----    yes      W3 22.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.        
+w4mag_7         %7.3f   mag     yes     W4 44.0" radius aperture magnitude. This is the calibrated source brightness measured in a 44.0" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_7        %5.3f   mag     yes     Uncertainty in the W4 44.0" radius aperture magnitude.
+w4flg_7         %3d     ----    yes      W4 44.0" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1mag_8         %7.3f   mag     yes     W1 24.75" radius aperture magnitude. This is the calibrated source brightness measured in a 24.75" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w1sigm_8        %5.3f   mag     yes     Uncertainty in the W1 24.75" radius aperture magnitude.
+w1flg_8         %3d     ----    yes      W1 24.75" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w1mflg.       
+w2mag_8         %7.3f   mag     yes     W2 24.75" radius aperture magnitude. This is the calibrated source brightness measured in a 24.75" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w2sigm_8        %5.3f   mag     yes     Uncertainty in the W2 24.75" radius aperture magnitude.
+w2flg_8         %3d     ----    yes      W2 24.75" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w2mflg.       
+w3mag_8         %7.3f   mag     yes     W3 24.75" radius aperture magnitude. This is the calibrated source brightness measured in a 24.75" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w3sigm_8        %5.3f   mag     yes     Uncertainty in the W3 24.75" radius aperture magnitude.
+w3flg_8         %3d     ----    yes      W3 24.75" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w3mflg.       
+w4mag_8         %7.3f   mag     yes     W4 49.5" radius aperture magnitude. This is the calibrated source brightness measured in a 49.5" radius circular aperture centered on the source position on the Atlas Image. If the source is not detected in the aperture measurement, this is the 95% confidence upper limit to the brightness. The background sky reference level is measured in an annular region with inner radius of 50" and outer radius of 70". No curve-of-growth correction has been applied.
+w4sigm_8        %5.3f   mag     yes     Uncertainty in the W4 49.5" radius aperture magnitude.
+w4flg_8         %3d     ----    yes      W4 49.5" radius aperture magnitude quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the standard aperture photometry quality flag, w4mflg.        
+- 12 fields
+w1magp          %6.3f   mag     yes     Inverse-variance-weighted mean W1 magnitude computed from profile-fit measurements on the w1m individual frames covering this source. This differs from w1mpro in that it is computed by combining the profile-fit measurements from individual frames, whereas w1mpro is computed by fitting all W1 frames simultaneously and incorporating a robust error model.
+w1sigp1         %6.3f   mag     yes     Standard deviation of the population of W1 fluxes measured on the w1m individual frames covering this source, in magnitudes. This provides a measure of the characteristic uncertainty of the measurement of this source on individual frames.
+w1sigp2         %6.3f   mag     yes     Standard deviation of the mean of the distribution of W1 fluxes (w1magp) computed from profile-fit measurements on the w1m individual frames covering this source, in magnitudes. This is equivalent to w1sigp1/sqrt(w1m).
+w2magp          %6.3f   mag     yes     Inverse-variance-weighted mean W2 magnitude computed from profile-fit measurements on the w2m individual frames covering this source. This differs from w2mpro in that it is computed by combining the profile-fit measurements from individual frames, whereas w2mpro is computed by fitting all W2 frames simultaneously and incorporating a robust error model.
+w2sigp1         %6.3f   mag     yes     Standard deviation of the population of W2 fluxes measured on the w2m individual frames covering this source, in magnitudes. This provides a measure of the characteristic uncertainty of the measurement of this source on individual frames.
+w2sigp2         %6.3f   mag     yes     Standard deviation of the mean of the distribution of W2 fluxes (w2magp) computed from profile-fit measurements on the w2m individual frames covering this source, in magnitudes. This is equivalent to w2sigp1/sqrt(w2m).
+w3magp          %6.3f   mag     yes     Inverse-variance-weighted mean W3 magnitude computed from profile-fit measurements on the w3m individual frames covering this source. This differs from w3mpro in that it is computed by combining the profile-fit measurements from individual frames, whereas w3mpro is computed by fitting all W3 frames simultaneously and incorporating a robust error model.
+w3sigp1         %6.3f   mag     yes     Standard deviation of the population of W3 fluxes measured on the w3m individual frames covering this source, in magnitudes. This provides a measure of the characteristic uncertainty of the measurement of this source on individual frames.
+w3sigp2         %6.3f   mag     yes     Standard deviation of the mean of the distribution of W3 fluxes (w3magp) computed from profile-fit measurements on the w3m individual frames covering this source, in magnitudes. This is equivalent to w3sigp1/sqrt(w3m).
+w4magp          %6.3f   mag     yes     Inverse-variance-weighted mean W4 magnitude computed from profile-fit measurements on the w4m individual frames covering this source. This differs from w4mpro in that it is computed by combining the profile-fit measurements from individual frames, whereas w4mpro is computed by fitting all W4 frames simultaneously and incorporating a robust error model.
+w4sigp1         %6.3f   mag     yes     Standard deviation of the population of W4 fluxes measured on the w4m individual frames covering this source, in magnitudes. This provides a measure of the characteristic uncertainty of the measurement of this source on individual frames.
+w4sigp2         %6.3f   mag     yes     Standard deviation of the mean of the distribution of W4 fluxes (w4magp) computed from profile-fit measurements on the w4m individual frames covering this source, in magnitudes. This is equivalent to w4sigp1/sqrt(w4m).
+- 12 fields
+xscprox         %8.2f   arcsec  yes     2MASS Extended Source Catalog (XSC) proximity. This column gives the distance between the WISE source position and the position of a nearby 2MASS XSC source, if the separation is less than 1.1 times the Ks isophotal radius size of the XSC source. This identifies WISE sources that are identically the 2MASS XSC source as well as WISE sources that are fragments of large galaxies. This column is "null" if there is no 2MASS XSC source in proximity to the WISE source.
+w1rsemi         %8.2f   arcsec  yes     Semi-major axis of the elliptical aperture used to measure source in W1.         
+w1ba            %4.2f   arcsec  yes     Axis ratio (b/a) of the elliptical aperture used to measure source in W1.        
+w1pa            %7.2f   deg     yes     Position angle (degrees E of N) of the elliptical aperture major axis used to measure source in W1.      
+w1gmag          %7.3f   mag     yes     W1 magnitude of source measured in the elliptical aperture described by w1rsemi, w1ba, and w1pa.         
+w1gerr          %5.3f   mag     yes     Uncertainty in the W1 magnitude of source measured in elliptical aperture.       
+w1gflg          %1d     ----    yes     W1 elliptical aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the "standard" aperture photometry quality flag, w1mflg.       
+w2rsemi         %8.2f   arcsec  yes     Semi-major axis of the elliptical aperture used to measure source in W2.         
+w2ba            %4.2f   arcsec  yes     Axis ratio (b/a) of the elliptical aperture used to measure source in W2.        
+w2pa            %7.2f   deg     yes     Position angle (degrees E of N) of the elliptical aperture major axis used to measure source in W2.      
+w2gmag          %7.3f   mag     yes     W2 magnitude of source measured in the elliptical aperture described by w2rsemi, w2ba, and w2pa.         
+w2gerr          %5.3f   mag     yes     Uncertainty in the W2 magnitude of source measured in elliptical aperture.       
+w2gflg          %1d     ----    yes     W2 elliptical aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the "standard" aperture photometry quality flag, w2mflg.       
+w3rsemi         %8.2f   arcsec  yes     Semi-major axis of the elliptical aperture used to measure source in W3.         
+w3ba            %4.2f   arcsec  yes     Axis ratio (b/a) of the elliptical aperture used to measure source in W3.        
+w3pa            %7.2f   deg     yes     Position angle (degrees E of N) of the elliptical aperture major axis used to measure source in W3.      
+w3gmag          %7.3f   mag     yes     W3 magnitude of source measured in the elliptical aperture described by w3rsemi, w3ba, and w3pa.         
+w3gerr          %5.3f   mag     yes     Uncertainty in the W3 magnitude of source measured in elliptical aperture.       
+w3gflg          %1d     ----    yes     W3 elliptical aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the "standard" aperture photometry quality flag, w3mflg.       
+w4rsemi         %8.2f   arcsec  yes     Semi-major axis of the elliptical aperture used to measure source in W4.         
+w4ba            %4.2f   arcsec  yes     Axis ratio (b/a) of the elliptical aperture used to measure source in W4.        
+w4pa            %7.2f   deg     yes     Position angle (degrees E of N) of the elliptical aperture major axis used to measure source in W4.      
+w4gmag          %7.3f   mag     yes     W4 magnitude of source measured in the elliptical aperture described by w4rsemi, w4ba, and w4pa.         
+w4gerr          %5.3f   mag     yes     Uncertainty in the W4 magnitude of source measured in elliptical aperture.       
+w4gflg          %1d     ----    yes     W4 elliptical aperture measurement quality flag. This flag indicates if one or more image pixels in the measurement aperture for this band is confused with nearby objects, is contaminated by saturated or otherwise unusable pixels, or is an upper limit. The flag values are as described for the "standard" aperture photometry quality flag, w4mflg.       
+- 25 fields
+tmass_key       %10d    ----    yes     2MASS PSC association. Unique identifier of the closest source in the 2MASS Point Source Catalog (PSC) that falls within 3" of the position of this WISE source. This is equivalent to the pts_key in the 2MASS PSC entry. This column is "null" if there is no 2MASS PSC source within 3" of the WISE source position. The number of 2MASS PSC sources within 3" of the WISE position is given in n_2mass
+r_2mass         %7.3f   arcsec  yes     Distance separating the positions of the WISE source and associated 2MASS PSC source within 3". This column is "null" if there is no associated 2MASS PSC source.        
+pa_2mass        %6.1f   deg     yes     Position angle (degrees E of N) of the vector from the WISE source to the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source.         
+n_2mass         %3d     ----    yes     The number of 2MASS PSC entries found within a 3" radius of the WISE source position. If more than one 2MASS PSC falls within 3" of the WISE position, the closest 2MASS PSC entry is listed. This column is "null" if there is no associated 2MASS PSC source.  
+j_m_2mass       %7.3f   mag     yes     2MASS J-band magnitude or magnitude upper limit of the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source or if the 2MASS PSC J-band magnitude entry is "null".       
+j_msig_2mass    %5.3f   mag     yes     2MASS J-band corrected photometric uncertainty of the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source or if the 2MASS PSC J-band uncertainty entry is "null".      
+h_m_2mass       %7.3f   mag     yes     2MASS H-band magnitude or magnitude upper limit of the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source or if the 2MASS PSC H-band magnitude entry is "null".       
+h_msig_2mass    %5.3f   mag     yes     2MASS H-band corrected photometric uncertainty of the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source or if the 2MASS PSC H-band uncertainty entry is "null".      
+k_m_2mass       %7.3f   mag     yes     2MASS Ks-band magnitude of the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source or if the 2MASS PSC Ks-band magnitude entry is "null".      
+k_msig_2mass    %5.3f   mag     yes     2MASS Ks-band corrected photometric uncertainty of the associated 2MASS PSC source. This column is "null" if there is no associated 2MASS PSC source or if the 2MASS PSC Ks-band uncertainty entry is "null".    
+x               %19.16f ----    no      Unit sphere position x value     
+y               %19.16f ----    no      Unit sphere position y value     
+z               %19.16f ----    no      Unit sphere position z value     
+spt_ind         %9d     ----    no      HTM spatial index key    
Index: /trunk/Ohana/src/addstar/doc/wise.sample.dat
===================================================================
--- /trunk/Ohana/src/addstar/doc/wise.sample.dat	(revision 32346)
+++ /trunk/Ohana/src/addstar/doc/wise.sample.dat	(revision 32346)
@@ -0,0 +1,3 @@
+J070019.93+432212.0|105.0830765|43.3700066|0.0714|0.5048|-0.0096|173.4548334|19.7690989|101.6541116|20.53902|73.341|623.355|1040143901111000001|1040p439_aa11-000001|1040p439_aa11|1|7.149|0.028|38.9|0.869199991|7.294|0.023|48.1|0.935500026|7.13|0.02|54.8|0.841700017|7.115|0.099|11.0|1.074|0.926599979|1|0|0.142|0.0|0.0|0.0|5000|0000|0|1110|AAAA|15|12|12|12|12|12|12|7|12|10.898|12.111|11.879|12.129|0.0|0.0|0.0|0.0|0||0||0||0||219050.0|5638.0|17.205|3.254|0.0|76247.0|1585.40002|45.53|4.079|0.0|14058.0|256.390015|1881.719|22.688|0.0|225.919998|20.566|736.969|10.674|2.705|7.67|0.005|16|0.222|7.313|0.005|0|0.28|7.118|0.008|0|0.665|7.106|0.162|0|0.616|8.338|0.006|16|8.026|0.006|0|8.369|0.009|0|8.211|0.17|0|7.892|0.005|16|7.593|0.005|0|7.783|0.008|0|7.722|0.162|0|7.725|0.005|16|7.428|0.005|0|7.466|0.007|0|7.414|0.167|1|7.654|0.005|16|7.364|0.005|0|7.3|0.008|0|7.228|0.184|1|7.618|0.005|16|7.332|0.005|0|7.212|0.008|0|7.106|0.21|1|7.596|0.005|16|7.314|0.005|0|7.165|0.009|0|7.052|0.247|1|7.58|0.005|16|7.301|0.005|0|7.139|0.009|0|7.075|0.308|1|7.569|0.005|16|7.291|0.005|0|7.124|0.01|0|7.089|0.375|1|7.147|0.037|0.011|7.295|0.03|0.009|7.13|0.027|0.008|7.129|0.34|0.098||||||||||||||||||||||||||389882849|0.009|81.1|1|8.222|0.034|7.451|0.046|7.231|0.021|-0.18916233986809|0.70189102689035|0.686707066766055|223003002|
+J065913.94+431543.9|104.8081131|43.2621994|0.0973|0.5092|-0.012|173.493124|19.5447216|101.4544493|20.4099538|594.029|335.42|1040143901111000051|1040p439_aa11-000051|1040p439_aa11|51|12.893|0.025|42.9|0.7676|12.864|0.03|36.5|0.90079999|12.057||1.7|0.876299977|9.18|||0.902999997|0.857800007|2|0|0.0|0.0|0.0|0.0|0000|0000|0|1100|AAUU|3|13|13|13|13|0|13|0|13|12.628|12.656|12.771|12.717|0.0|0.0|0.0|0.0|0||0||0||0||1103.90002|25.7310009|16.008|3.288|0.0|451.25|12.3649998|44.678|4.026|0.0|69.2180023|40.5629997|1882.381|21.958|0.0|-4.68730021|16.8579998|737.179|10.956|4.392|12.905|0.015|0|0.222|12.907|0.03|0|0.28|11.954||32|0.665|9.494||32|0.616|13.497|0.015|0|13.611|0.031|0|13.002||32|9.6||32|13.127|0.015|0|13.187|0.03|0|12.619||32|10.11||32|12.997|0.016|1|13.048|0.033|1|12.304||32|8.742||32|12.944|0.019|1|13.016|0.04|1|12.015||32|8.286||32|12.914|0.021|1|13.013|0.047|1|11.719||32|7.817||32|12.889|0.024|1|13.007|0.055|1|11.464||32|7.427||32|12.868|0.027|1|12.996|0.063|1|11.264||32|7.166||32|12.853|0.031|1|12.99|0.072|1|11.11||32|7.018||32|12.893|0.023|0.006|12.865|0.068|0.019|12.952|2.605|0.723|||||||||||||||||||||||||||||389862912|0.091|-72.5|1|13.336|0.022|13.016|0.021|13.003|0.028|-0.186121697487002|0.704038676616684|0.685338059319913|223003031|
+J065944.84+432452.7|104.9368439|43.4146538|0.1091|0.5117|-0.0212|173.3730353|19.6833296|101.5360666|20.5717047|352.875|736.982|1040143901111000076|1040p439_aa11-000076|1040p439_aa11|76|13.239|0.025|42.8|1.56500006|13.299|0.037|29.1|1.04999995|11.895||1.8|1.01699996|8.748||0.8|0.957199991|1.13900006|1|0|0.0|0.0|0.0|0.0|0000|h000|0|0100|AAUU|3|11|11|11|11|0|11|0|11|11.257|11.534|10.912|11.402|0.0|0.0|0.0|0.0|8|h|0||0||0||802.429993|18.7660007|16.709|3.838|0.0|302.220001|10.3889999|45.571|5.071|0.0|81.6419983|46.5060005|1883.447|23.228|0.0|14.4219999|17.8859997|736.917|10.331|1.413|13.119|0.023|1|0.222|13.132|0.052|1|0.28|12.004|0.508|1|0.665|8.292||32|0.616|13.802|0.025|0|13.954|0.061|0|12.532||32|9.343||32|13.341|0.023|1|13.412|0.052|1|12.669|0.508|1|8.908||32|13.048|0.022|1|13.081|0.049|1|12.099|0.386|1|8.562||32|12.775|0.022|1|12.793|0.047|1|11.694|0.328|1|8.27||32|12.506|0.021|1|12.523|0.044|1|11.434|0.311|1|8.008||32|12.298|0.02|1|12.317|0.043|1|11.252|0.311|1|7.772||32|12.171|0.021|1|12.183|0.044|1|11.152|0.329|1|7.556||32|12.088|0.022|1|12.09|0.047|1|11.163|0.382|1|7.357||32|13.239|0.03|0.009|13.299|0.078|0.023|12.364|0.996|0.3|9.792|2.153|0.649||||||||||||||||||||||||||389863247|0.051|123.7|1|13.972|0.03|13.451|0.031|13.378|0.03|-0.187232347403342|0.701854285923945|0.687273314930839|223003031|
Index: /trunk/Ohana/src/addstar/include/WISE.h
===================================================================
--- /trunk/Ohana/src/addstar/include/WISE.h	(revision 32346)
+++ /trunk/Ohana/src/addstar/include/WISE.h	(revision 32346)
@@ -0,0 +1,55 @@
+
+/* structure for data on a catalog region */
+typedef struct {
+  char filename[256];
+  double RA[2];
+  int Nrec;
+} WISE_Region;
+
+typedef struct {
+  double Rmin, Rmax, Dmin, Dmax;
+  int index[20];
+  int Nindex;
+} WISE_Bands;
+
+typedef struct {
+  double R, D;
+  int offset;
+  int flag;
+} WISE_Stars;
+
+short WISE_W1, WISE_W2, WISE_W3, WISE_W4;
+
+SkyTable *get2mass_acc (SkyRegion *patch, char *path, char *accel);
+Stars    *get2mass_2DR_data (SkyRegion *region, char *filename, SkyRegion *patch, int photcode, int *nstars);
+Stars    *get2mass_AS_data (SkyRegion *region, char *filename, SkyRegion *patch, int phocode, int *nstars);
+Stars    *get2mass_AS_rawdata (SkyRegion *region, char *filename, SkyRegion *patch, int phocode, int *nstars);
+
+SkyTable *scan2mass_acc (char *path, char *accel);
+int       scan2mass_as_data (char *filename);
+
+char     *skipNbounds (char *line, char bound, int Nbound, int Nbyte);
+e_time    get2mass_time (char *ptr, int Nbound, int Nbyte);
+e_time    get2mass_date (char *ptr, int Nbound, int Nmax);
+
+int       load2mass_as_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options);
+SkyTable *load2mass_acc (char *path, char *accel);
+int       get2mass_3star (Stars *star, char *line, int Nmax);
+int       load2mass_catalog (Catalog *catalog, Stars *stars, int Nstars);
+
+int       get2mass_setup (int photcode);
+int       get2mass_coords (char *line, double *R, double *D, int Nmax);
+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);
+int get2mass_sortStars (WISE_Stars *tstars, int Ntstars);
Index: /trunk/Ohana/src/addstar/src/loadwise.c
===================================================================
--- /trunk/Ohana/src/addstar/src/loadwise.c	(revision 32346)
+++ /trunk/Ohana/src/addstar/src/loadwise.c	(revision 32346)
@@ -0,0 +1,52 @@
+# include "addstar.h"
+# include "WISE.h"
+
+int main (int argc, char **argv) {
+
+  char *path;
+  int i;
+  SkyTable *sky, *skyWISE;
+  SkyList *skylist = NULL;
+  SkyList *overlap = NULL;
+  AddstarClientOptions options;
+
+  // need to construct these options with args_loadWISE...
+  options = ConfigInit (&argc, argv);
+  options = args_loadWISE (argc, argv, options);
+
+  // load the full sky description table:
+  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+  
+  // generate the subset matching the user-selected region
+  skylist = SkyListByPatch (sky, -1, &UserPatch);
+
+  // if we only match to existing (already populated) regions, limit the select to those regions:
+  if (options.existing_regions) {
+    SkyList *tmp;
+    tmp = SkyListExistingSubset (skylist, CATDIR);
+    SkyListFree (skylist);
+    skylist = tmp;
+  }
+
+  path = WISE_DIR_PRELIM;
+
+  // the accel.dat file has the raw filenames
+  // test if the file exists, or else try the .gz version
+  // XXX can we build an accelerator?
+  skyWISE = loadWISE_acc (path, "accel.dat");
+  
+  for (i = 0; i < skyWISE[0].Nregions; i++) {
+    // check if any of the skylist entries overlap this WISE catalog:
+    overlap = SkyListByBounds_List (skylist, -1, skyWISE[0].regions[i].Rmin, skyWISE[0].regions[i].Rmax, skyWISE[0].regions[i].Dmin, skyWISE[0].regions[i].Dmax);
+    if (overlap[0].Nregions == 0) {
+      SkyListFree (overlap);
+      continue;
+    }
+    
+    fprintf (stderr, "loading %s\n", skyWISE[0].filename[i]);
+    loadWISE_as_rawdata (overlap, skyWISE[0].filename[i], options);
+    SkyListFree (overlap);
+  }
+  exit (0);
+}  
Index: /trunk/Ohana/src/addstar/src/loadwise_ops.c
===================================================================
--- /trunk/Ohana/src/addstar/src/loadwise_ops.c	(revision 32346)
+++ /trunk/Ohana/src/addstar/src/loadwise_ops.c	(revision 32346)
@@ -0,0 +1,155 @@
+# include "addstar.h"
+# include "WISE.h"
+
+static int FilterSkip;
+static int TimeSkip;
+static int Qentry;
+static int Photcode;
+
+int getWISE_setup () {
+
+  NAMED_PHOTCODE (WISE_W1, "WISE_W1");
+  NAMED_PHOTCODE (WISE_W2, "WISE_W2");
+  NAMED_PHOTCODE (WISE_W3, "WISE_W3");
+  NAMED_PHOTCODE (WISE_W4, "WISE_W4");
+
+  return TRUE;
+}
+
+// fill in the coords for a single star.  takes a pointer to the start of the line
+int getWISE_coords (char *line, double *R, double *D, int Nmax) {
+
+  char *ptr = line;
+
+  ptr = skipNbounds (ptr, '|', 1, Nmax);
+  *R = strtod (ptr, NULL);
+  ptr = skipNbounds (ptr, '|', 1, Nmax);
+  *D = strtod (ptr, NULL);
+  if (*D > 90) Shutdown ("weird DEC value: something is wrong");
+
+  return TRUE;
+}
+
+int getWISE_sortStars (WISE_Stars *tstars, int Ntstars) {
+
+# define SWAPFUNC(A,B){ WISE_Stars temp = tstars[A]; tstars[A] = tstars[B]; tstars[B] = temp; }
+# define COMPARE(A,B)(tstars[A].R < tstars[B].R)
+
+  OHANA_SORT (Ntstars, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+  
+  return TRUE;
+}
+
+// this function retrieves the time from the DATE field
+e_time getWISE_date (char *ptr, int Nbound, int Nmax) {
+
+  e_time time;
+  char *p, *end;
+
+  p = skipNbounds (ptr, '|', Nbound, Nmax);
+  if (p == NULL) Shutdown ("format error in WISE");
+  end = memchr (p, '|', Nmax - (p - ptr));
+  if (end == NULL) Shutdown ("format error in WISE");
+  *end = 0;
+  time = ohana_date_to_sec (ptr);
+  *end = '|';
+
+  return (time);
+}
+
+// this function retrieves the time from the JDATE field (%12.4f)
+e_time getWISE_time (char *ptr, int Nbound, int Nmax) {
+
+  e_time time;
+  double jd;
+  char *p, *end;
+
+  p = skipNbounds (ptr, '|', Nbound, Nmax);
+  if (p == NULL) Shutdown ("format error in WISE");
+  end = memchr (p, '|', Nmax - (p - ptr));
+  if (end == NULL) Shutdown ("format error in WISE");
+  *end = 0;
+  jd = strtod (p, NULL);
+  time = ohana_jd_to_sec (jd);
+  *end = '|';
+
+  return (time);
+}
+
+/* return a pointer to the first char after Nbound of value bound */
+char *skipNbounds (char *line, char bound, int Nbound, int Nbyte) {
+
+  int i;
+  char *p, *q;
+
+  p = line;
+  for (i = 0; i < Nbound; i++) {
+    q = memchr (p, bound, Nbyte - (p - line));
+    if (q == NULL) return (NULL);
+    p = q + 1;
+    if (p - line == Nbyte) return (NULL);
+  }
+  return (p);
+}
+  
+/* watch for patches which cross 0,360 boundary */
+SkyTable *loadWISE_acc (char *path, char *accel) {
+
+  int Nregions, NREGIONS, Nrec;
+  char accelfile[1024], line[256], filename[128], datafile[256], **filenames;
+  FILE *f;
+  double Rs, Re, Ds, De;
+
+  SkyTable *sky;
+  SkyRegion *regions;
+
+  sprintf (accelfile, "%s/%s", path, accel);
+  f = fopen (accelfile, "r");
+  if (f == NULL) Shutdown ("can't read data from accelerator %s", accelfile);
+
+  Nregions = 0;
+  NREGIONS = 200;
+  ALLOCATE (regions, SkyRegion, NREGIONS);
+  ALLOCATE (filenames, char *, NREGIONS);
+
+  /* read in stars line-by-line */
+  while (scan_line (f, line) != EOF) {
+    stripwhite (line);
+    if (line[0] == 0) continue;
+    if (line[0] == '#') continue;
+    sscanf (line, "%s %lf %lf %lf %lf %d", filename, &Rs, &Re, &Ds, &De, &Nrec);
+    Rs *= 15.0;
+    Re *= 15.0;
+
+    // don't restrict by RA, but limit by DEC
+    if (De < UserPatch.Dmin) continue;
+    if (Ds > UserPatch.Dmax) continue;
+
+    regions[Nregions].Rmin = Rs;
+    regions[Nregions].Rmax = Re;
+    regions[Nregions].Dmin = Ds;
+    regions[Nregions].Dmax = De;
+    regions[Nregions].childE = Nrec; // a cheat since WISE only has one depth
+
+    sprintf (datafile, "%s/%s", path, filename);
+    filenames[Nregions] = strcreate (datafile);
+
+    Nregions ++;
+    if (Nregions >= NREGIONS) {
+	NREGIONS += 20;
+	REALLOCATE (regions, SkyRegion, NREGIONS);
+	REALLOCATE (filenames, char *, NREGIONS);
+    }
+  }    
+  fclose (f);
+
+  ALLOCATE (sky, SkyTable, 1);
+  sky[0].regions = regions;
+  sky[0].filename = filenames;
+  sky[0].Nregions = Nregions;
+  return (sky);
+}
+
Index: /trunk/Ohana/src/addstar/src/loadwise_prelim_rawdata.c
===================================================================
--- /trunk/Ohana/src/addstar/src/loadwise_prelim_rawdata.c	(revision 32346)
+++ /trunk/Ohana/src/addstar/src/loadwise_prelim_rawdata.c	(revision 32346)
@@ -0,0 +1,241 @@
+# include "addstar.h"
+# include "WISE.h"
+
+/* unlike the DR2 data, the AS data is NOT fixed bytes/row 
+ * we need to handle fractional lines at the end of each read block
+ */
+
+/* read in chunks of ~64MB */
+# define NBYTE 0x4000000
+# define DEBUG 0
+
+int loadWISE_as_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options) {
+  
+  int i, j, verbose;
+  int Nstars, NSTARS, Ntstars, NTSTARS;
+  int Nbyte, Nextra, Ntotal, offset;
+
+  double Rmin, Rmax, Dmin, Dmax;
+
+  FILE *f;
+  char *buffer, *p, *q;
+
+  Stars **stars; // this is an array of pointers to be consistent with input to find_match_refstars
+  WISE_Stars *tstars;
+  SkyList *skylist;
+  SkyRegion *region;
+  Catalog catalog;
+
+  getWISE_setup ();
+
+  ALLOCATE (buffer, char, NBYTE);
+
+  // scan through the entire WISE file
+  f = fopen (filename, "r");
+  if (f == NULL) Shutdown ("can't read WISE data file: %s", filename);
+  // test if this is a raw datafile or gzipped...
+
+  Nextra = 0;  // number excess bytes from lsat partial row
+  Ntotal = 0;  // track the total number of bytes read 
+  while ((Nbyte = fread (&buffer[Nextra], 1, NBYTE-Nextra, f)) != 0) {
+    if (Nbyte == -1) Shutdown ("error reading from raw file %s", filename);
+    if (DEBUG) fprintf (stderr, "read %d bytes", Nbyte);
+
+    Nbyte += Nextra;
+
+    if (VERBOSE) fprintf (stderr, "read .. ");
+
+    /* find bounds on first complete line */
+    p = buffer;
+    q = memchr (p, '\n', Nbyte);
+    if (q == NULL) Shutdown ("incomplete line at end of file\n");
+    offset = p - buffer; // offset within this scan
+
+    Ntstars = 0;
+    NTSTARS = 10000;
+    ALLOCATE (tstars, WISE_Stars, NTSTARS);
+
+    Rmin = 360.0;
+    Rmax =   0.0;
+    Dmin = +90.0;
+    Dmax = -90.0;
+
+    // scan through entire buffer for star coords
+    while (1) {
+      getWISE_coords (p, &tstars[Ntstars].R, &tstars[Ntstars].D, Nbyte - offset);
+      tstars[Ntstars].offset = offset; // offset within scan
+      tstars[Ntstars].flag = FALSE;
+
+      if (VERBOSE) {
+	Rmin = MIN (Rmin, tstars[Ntstars].R);
+	Rmax = MAX (Rmax, tstars[Ntstars].R);
+	Dmin = MIN (Dmin, tstars[Ntstars].D);
+	Dmax = MAX (Dmax, tstars[Ntstars].D);
+      }
+
+      Ntstars ++;
+      CHECK_REALLOCATE (tstars, WISE_Stars, NTSTARS, Ntstars, 10000);
+
+      /* start of the next line */
+      p = q + 1;
+      offset = p - buffer; // offset within this scan
+      if (offset == Nbyte) {
+	// last line in buffer is a complete line
+	Nextra = 0;
+	break;
+      }
+      /* end of the next line */
+      q = memchr (p, '\n', Nbyte - offset);
+      if (q == NULL) {
+	// last, incomplete line in buffer
+	Nextra = Nbyte - offset;
+	break;
+      } 
+    }
+    if (VERBOSE) fprintf (stderr, "scan %d stars (%10.6f - %10.6f, %10.6f - %10.6f) .. ", Ntstars, Rmin, Rmax, Dmin, Dmax);
+
+    // sort the tstars by RA
+    getWISE_sortStars (tstars, Ntstars);
+
+    // scan through the stars, loading the containing catalogs
+    // skip through table for unsaved stars
+    for (i = 0; i < Ntstars; i++) {
+      if (tstars[i].flag) continue;
+
+      // scan forward until we read the UserPatch
+      if (tstars[i].R < UserPatch.Rmin) continue;
+      if (tstars[i].R > UserPatch.Rmax) break;
+      if (tstars[i].D < UserPatch.Dmin) continue;
+      if (tstars[i].D > UserPatch.Dmax) continue;
+
+      // identify the relevant catalog
+      skylist = SkyRegionByPoint_List (skytable, -1, tstars[i].R, tstars[i].D);
+      if (skylist[0].Nregions == 0) {
+	  SkyListFree (skylist);
+	  continue;
+      }
+      region = skylist[0].regions[0];
+      if (DEBUG) fprintf (stderr, "writing to %s\n", skylist[0].filename[0]);
+
+      // collect array of (Stars *) stars in a new output catalog
+      Nstars = 0;
+      NSTARS = 3000;
+      ALLOCATE (stars, Stars *, NSTARS);
+
+      // loop over stars in this WISE region that are also in this output region
+      for (j = i; j < Ntstars; j++) {
+	if (tstars[j].flag) continue;
+
+	// check if in skyregion
+	if (tstars[j].R < region[0].Rmin) continue;
+	if (tstars[j].R > region[0].Rmax) break;
+	if (tstars[j].D < region[0].Dmin) continue;
+	if (tstars[j].D > region[0].Dmax) continue;
+	  
+	// check if in UserPatch
+	if (tstars[j].R < UserPatch.Rmin) continue;
+	if (tstars[j].R > UserPatch.Rmax) break;
+	if (tstars[j].D < UserPatch.Dmin) continue;
+	if (tstars[j].D > UserPatch.Dmax) continue;
+	  
+	offset = tstars[j].offset;
+
+	ALLOCATE (stars[Nstars+0], Stars, 1);
+	ALLOCATE (stars[Nstars+1], Stars, 1);
+	ALLOCATE (stars[Nstars+2], Stars, 1);
+	ALLOCATE (stars[Nstars+3], Stars, 1);
+
+	InitStar (stars[Nstars+0]);
+	InitStar (stars[Nstars+1]);
+	InitStar (stars[Nstars+2]);
+	InitStar (stars[Nstars+3]);
+
+	stars[Nstars+0][0].average.R = tstars[j].R;
+	stars[Nstars+0][0].average.D = tstars[j].D;
+	stars[Nstars+1][0].average.R = tstars[j].R;
+	stars[Nstars+1][0].average.D = tstars[j].D;
+	stars[Nstars+2][0].average.R = tstars[j].R;
+	stars[Nstars+2][0].average.D = tstars[j].D;
+	stars[Nstars+3][0].average.R = tstars[j].R;
+	stars[Nstars+3][0].average.D = tstars[j].D;
+	getWISE_star_full (&stars[Nstars], &buffer[offset], Nbyte - offset);
+
+	tstars[j].flag = TRUE;
+
+	Nstars += 4;
+	if (Nstars >= NSTARS - 4) {
+	  NSTARS += 4000;
+	  REALLOCATE (stars, Stars *, NSTARS);
+	}
+      }
+
+      if (!Nstars) {
+	free (stars);
+	continue;
+      }
+
+      if (DEBUG) fprintf (stderr, "selected %d stars (%10.6f - %10.6f, %10.6f - %10.6f)\n", Nstars, 
+			  region[0].Rmin, region[0].Rmax, region[0].Dmin, region[0].Dmax);
+
+      if (1) {
+	verbose = VERBOSE;
+	VERBOSE = FALSE;
+
+	// now we have all of the loaded stars in this catalog
+	catalog.filename = skylist[0].filename[0];
+	catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
+	catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
+	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+
+	// an error exit status here is a significant error
+	if (!dvo_catalog_open (&catalog, skylist[0].regions[0], VERBOSE, "w")) {
+	  fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+	  exit (2);
+	}
+
+	// assume no input star matches an existing star 
+	// simply add to the existing table
+	// loadWISE_catalog (&catalog, stars, Nstars);
+	find_matches_refstars (skylist[0].regions[0], stars, Nstars, &catalog, options);
+	// loadWISE_catalog (&catalog, stars, Nstars);
+
+	dvo_catalog_save (&catalog, VERBOSE);
+	dvo_catalog_unlock (&catalog);
+	dvo_catalog_free (&catalog);
+	// free (catalog.filename);
+	// XXX don't free this! it points to an element of the skytable
+      }
+
+      SkyListFree (skylist);
+      for (j = 0; j < Nstars; j++) free (stars[j]);
+      free (stars);
+      VERBOSE = verbose;
+    }
+    free (tstars);
+    if (VERBOSE) fprintf (stderr, "done\n");
+
+    // at end, p points at the start of last, partial line
+    if (Nextra) memmove (buffer, p, Nextra);
+  }
+
+  if (VERBOSE) fprintf (stderr, "\n");
+  
+  fclose (f);
+  free (buffer);
+  return (TRUE);
+}
+
+/*
+  for each WISE file:
+  for each data block
+  generate a table of: R, D, byte, flag
+  for each unsaved star
+  find containing catalog
+  load catalog
+  find all contained stars
+  add to catalog
+  save catalog 
+  mark all contained stars
+*/
+
Index: /trunk/Ohana/src/addstar/src/loadwise_star_full.c
===================================================================
--- /trunk/Ohana/src/addstar/src/loadwise_star_full.c	(revision 32346)
+++ /trunk/Ohana/src/addstar/src/loadwise_star_full.c	(revision 32346)
@@ -0,0 +1,264 @@
+# include "addstar.h"
+# include "WISE.h"
+
+// XXX check to see if desired output format is PS1_V1 or later?  (use 16bit version if not?)
+
+// fill in the data for a WISE quad star.  takes a pointer to the start of the line the
+// RA and DEC have already been set
+int getWISE_star_full (Stars **star, char *line, int Nmax) {
+
+  char *ptr;
+  double dMfull;
+  double jd;
+
+  if (line == NULL) Shutdown ("format error in WISE");
+
+  ptr = skipNbounds (ptr, '|', 3, Nmax); // skip: desig, ra, dec,
+  star[0][0].measure.FWx = ToShortPixels(strtod (ptr, NULL));
+  ptr = nextWISEfield (ptr); // sig_dec
+  star[0][0].measure.FWy = ToShortPixels(strtod (ptr, NULL));
+  ptr = nextWISEfield (ptr); // sig_radec
+  star[0][0].measure.theta = ToShortPixels(strtod (ptr, NULL));
+
+  star[1][0].measure.FWx   = star[0][0].measure.FWx;
+  star[1][0].measure.FWy   = star[0][0].measure.FWy;
+  star[1][0].measure.theta = star[0][0].measure.theta;
+  star[2][0].measure.FWx   = star[0][0].measure.FWx;
+  star[2][0].measure.FWy   = star[0][0].measure.FWy;
+  star[2][0].measure.theta = star[0][0].measure.theta;
+  star[3][0].measure.FWx   = star[0][0].measure.FWx;
+  star[3][0].measure.FWy   = star[0][0].measure.FWy;
+  star[3][0].measure.theta = star[0][0].measure.theta;
+
+  ptr = skipNbounds (ptr, '|', 10, Nmax); // skip: glon, glat, elon, elat, wx, wy, cntr, source_id, coadd_id, src
+
+  // W1
+  star[0][0].measure.M  = strtod (ptr, NULL);
+  ptr = nextWISEfield (ptr); // j_cmsig
+  star[0][0].measure.dM = strtod (ptr, NULL);
+  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: w1snr, w1rchi2
+
+  // W2
+  star[1][0].measure.M  = strtod (ptr, NULL);
+  ptr = nextWISEfield (ptr); // j_cmsig
+  star[1][0].measure.dM = strtod (ptr, NULL);
+  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: w2snr, w2rchi2
+
+  // W3
+  star[2][0].measure.M  = strtod (ptr, NULL);
+  ptr = nextWISEfield (ptr); // j_cmsig
+  star[2][0].measure.dM = strtod (ptr, NULL);
+  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: w3snr, w3rchi2
+
+  // W4
+  star[3][0].measure.M  = strtod (ptr, NULL);
+  ptr = nextWISEfield (ptr); // j_cmsig
+  star[3][0].measure.dM = strtod (ptr, NULL);
+  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: w4snr, w4rchi2
+
+  star[0][0].measure.photFlags = 0;
+  star[1][0].measure.photFlags = 0;
+  star[2][0].measure.photFlags = 0;
+  star[3][0].measure.photFlags = 0;
+  ptr = skipNbounds (ptr, '|', 8, Nmax); // skip fields
+
+  setWISE_cc_flag (star[0], ptr[0]); // cc_flg
+  setWISE_cc_flag (star[1], ptr[1]); // cc_flg
+  setWISE_cc_flag (star[2], ptr[2]); // cc_flg
+  setWISE_cc_flag (star[3], ptr[2]); // cc_flg
+  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: ext_flg, var_flg
+
+  setWISE_ph_qual (star[0], ptr[0]); // ph_qual
+  setWISE_ph_qual (star[1], ptr[1]); // ph_qual
+  setWISE_ph_qual (star[2], ptr[2]); // ph_qual
+  setWISE_ph_qual (star[3], ptr[3]); // ph_qual
+  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: ext_flg, var_flg
+
+  // setWISE_rd_flag (star[0], ptr[0]);
+  // setWISE_bl_flag (star[0], ptr[0]);
+  // setWISE_gal_flag (star[0], ptr[0]);
+  // setWISE_mp_flag (star[0], ptr[0]);
+
+  // ptr = nextWISEfield (ptr); // x_scan
+  // star[0][0].measure.Xccd = strtod (ptr, NULL);
+  // star[2][0].measure.Xccd = star[1][0].measure.Xccd = star[0][0].measure.Xccd;
+  // ptr = nextWISEfield (ptr); // jdate (julian date)
+
+  jd = 2455263.0; // NOTE : WISE prelim release does not contain per-detection time info. 
+  // the release is based on data taken in the period 14 January 2010 to 29 April 2010
+  star[0][0].measure.t = ohana_jd_to_sec (jd);
+  star[1][0].measure.t = star[0][0].measure.t;
+  star[2][0].measure.t = star[0][0].measure.t;
+  star[3][0].measure.t = star[0][0].measure.t;
+
+  // ptr = nextWISEfield (ptr); // j_psfchi
+  // star[0][0].measure.psfChisq = strtod (ptr, NULL);
+  // ptr = nextWISEfield (ptr); // h_psfchi
+  // star[1][0].measure.psfChisq = strtod (ptr, NULL);
+  // ptr = nextWISEfield (ptr); // k_psfchi
+  // star[2][0].measure.psfChisq = strtod (ptr, NULL);
+  // 
+  // ptr = nextWISEfield (ptr); // j_m_stdap
+  // star[0][0].measure.Map = strtod (ptr, NULL);
+  // ptr = nextWISEfield (ptr); // j_msig_stdap (skip?)
+  // 
+  // ptr = nextWISEfield (ptr); // h_m_stdap
+  // star[1][0].measure.Map = strtod (ptr, NULL);
+  // ptr = nextWISEfield (ptr); // h_msig_stdap (skip?)
+  // 
+  // ptr = nextWISEfield (ptr); // k_m_stdap
+  // star[2][0].measure.Map = strtod (ptr, NULL);
+  // ptr = nextWISEfield (ptr); // k_msig_stdap (skip?)
+  // 
+  // ptr = nextWISEfield (ptr); // dist_edge_ns (skip)
+  // ptr = nextWISEfield (ptr); // dist_edge_ew (skip)
+  // ptr = nextWISEfield (ptr); // dist_edge_flg (skip)
+  // 
+  // ptr = nextWISEfield (ptr); // dup_src (one flag for all filters)
+  // setWISE_dup_flag (star[0], ptr[0]);
+  // setWISE_dup_flag (star[1], ptr[0]);
+  // setWISE_dup_flag (star[2], ptr[0]);
+  // 
+  // ptr = nextWISEfield (ptr); // use_src (one flag for all filters)
+  // setWISE_use_flag (star[0], ptr[0]);
+  // setWISE_use_flag (star[1], ptr[0]);
+  // setWISE_use_flag (star[2], ptr[0]);
+
+  star[0][0].measure.photcode  = TM_J;
+  star[0][0].measure.detID   = 0;
+  star[0][0].measure.imageID = 0;
+
+  star[1][0].measure.photcode  = TM_H;
+  star[1][0].measure.detID   = 0;
+  star[1][0].measure.imageID = 0;
+
+  star[2][0].measure.photcode  = TM_K;
+  star[2][0].measure.detID   = 0;
+  star[2][0].measure.imageID = 0;
+
+  return TRUE;
+}
+
+/* return a pointer to the first char after the next field separator (|) */
+char *nextWISEfield (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 setWISE_cc_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case 'p': star[0].measure.photFlags |= 0x00010000; break;
+    case 'P': star[0].measure.photFlags |= 0x00010000; break;
+    case 'h': star[0].measure.photFlags |= 0x00020000; break;
+    case 'H': star[0].measure.photFlags |= 0x00020000; break;
+    case 'd': star[0].measure.photFlags |= 0x00040000; break;
+    case 'D': star[0].measure.photFlags |= 0x00040000; break;
+    case 'o': star[0].measure.photFlags |= 0x00020000; break;
+    case 'O': star[0].measure.photFlags |= 0x00020000; break;
+    case '0': break;
+    default: 
+      fprintf (stderr, "error!\n");
+      exit (2);
+  }      
+  return (TRUE);
+}
+
+int setWISE_ph_qual (Stars *star, char qual) {
+
+  switch (qual) {
+    case 'A': star[0].measure.photFlags |= 0x00000001; break; // was: 0x0004
+    case 'B': star[0].measure.photFlags |= 0x00000002; break; // was: 0x0005
+    case 'C': star[0].measure.photFlags |= 0x00000004; break; // was: 0x0006
+    case 'U': star[0].measure.photFlags |= 0x00000040; break; // was: 0x0001
+    case 'X': star[0].measure.photFlags |= 0x00000080; break; // was: 0x0000
+    default: 
+      fprintf (stderr, "error!\n");
+      exit (2);
+  }      
+  return (TRUE);
+}
+
+int setWISE_rd_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].measure.photFlags |= 0x00000100; break; // was: 0x0000 
+    case '1': star[0].measure.photFlags |= 0x00000200; break; // was: 0x0010 
+    case '2': star[0].measure.photFlags |= 0x00000400; break; // was: 0x0020 
+    case '3': star[0].measure.photFlags |= 0x00000800; break; // was: 0x0030 
+    case '4': star[0].measure.photFlags |= 0x00001000; break; // was: 0x0040 
+    case '6': star[0].measure.photFlags |= 0x00002000; break; // was: 0x0050 
+    case '9': star[0].measure.photFlags |= 0x00004000; break; // was: 0x0060 
+    default: 
+      fprintf (stderr, "error!\n");
+      exit (2);
+  }      
+  return (TRUE);
+}
+
+int setWISE_bl_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].measure.photFlags &= ~0x00300000; break; // was: ~0x0008
+    case '1': star[0].measure.photFlags |=  0x00100000; break; // was: ~0x0008
+    default:  star[0].measure.photFlags |=  0x00200000; break; // was:  0x0008
+  }      
+  return (TRUE);
+}
+
+int setWISE_gal_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].measure.photFlags &= ~0x00c00000; break; // was: ~0x0080 
+    case '1': star[0].measure.photFlags |=  0x00400000; break; // was: ~0x0080 
+    default:  star[0].measure.photFlags |=  0x00800000;	       // was:  0x0080
+      star[0].measure.extNsigma = 100.0;
+      break;
+  }      
+  return (TRUE);
+}
+
+int setWISE_mp_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].measure.photFlags &= ~0x03000000; break; // was: ~0x0800
+    case '1': star[0].measure.photFlags |=  0x01000000; break; // was: ~0x0800
+    default:  star[0].measure.photFlags |=  0x02000000; break; // was:  0x0800
+  }      
+  return (TRUE);
+}
+
+int setWISE_dup_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].measure.photFlags &= ~0x0c000000; break; // was: ~0x1000
+    case '1': star[0].measure.photFlags |=  0x04000000; break; // was: ~0x1000
+    default:  star[0].measure.photFlags |=  0x08000000; break; // was:  0x1000
+  }      
+  return (TRUE);
+}
+
+int setWISE_use_flag (Stars *star, char qual) {
+
+  switch (qual) {
+    case '0': star[0].measure.photFlags &= ~0x10000000; break; // was: ~0x2000
+    case '1': star[0].measure.photFlags |=  0x10000000; break; // was:  0x2000
+    default:  abort();
+  }      
+  return (TRUE);
+}
+
+// unused photFlags:
+// 0x0000.8000
+// 0x0004.0000
+// 0x0008.0000
+// 0x2000.0000
+// 0x4000.0000
+// 0x8000.0000
Index: /trunk/Ohana/src/kapa2/src/DrawObjects.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/DrawObjects.c	(revision 32345)
+++ /trunk/Ohana/src/kapa2/src/DrawObjects.c	(revision 32346)
@@ -408,4 +408,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -424,4 +425,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -440,4 +442,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -457,4 +460,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -475,4 +479,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -495,4 +500,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -513,4 +519,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -531,4 +538,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -547,4 +555,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -567,4 +576,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
@@ -589,4 +599,5 @@
 	  (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
Index: /trunk/Ohana/src/kapa2/src/PSObjects.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/PSObjects.c	(revision 32345)
+++ /trunk/Ohana/src/kapa2/src/PSObjects.c	(revision 32346)
@@ -323,4 +323,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -340,4 +341,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -357,4 +359,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -375,4 +378,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -393,4 +397,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -415,4 +420,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -434,4 +440,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -453,4 +460,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -470,4 +478,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -491,4 +500,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
@@ -514,4 +524,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
Index: /trunk/Ohana/src/kapa2/src/bDrawObjects.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/bDrawObjects.c	(revision 32345)
+++ /trunk/Ohana/src/kapa2/src/bDrawObjects.c	(revision 32346)
@@ -307,4 +307,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -326,4 +327,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -345,4 +347,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -365,4 +368,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -385,4 +389,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -405,4 +410,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -424,4 +430,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -445,4 +452,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -464,4 +472,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -487,4 +496,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
@@ -511,4 +521,5 @@
       {
 	if (scaleColor) {
+	  if (!finite(z[i])) continue;
 	  int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
 	  buffer->bColor_R = pixel1[pixel];
Index: /trunk/Ohana/src/opihi/cmd.basic/echo.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.basic/echo.c	(revision 32345)
+++ /trunk/Ohana/src/opihi/cmd.basic/echo.c	(revision 32346)
@@ -3,5 +3,11 @@
 int echo (int argc, char **argv) {
   
-  int i;
+  int i, N, RETURN_CHAR;
+
+  RETURN_CHAR = TRUE;
+  if ((N = get_argument (argc, argv, "-no-return"))) {
+    remove_argument (N, &argc, argv);
+    RETURN_CHAR = FALSE;
+  }
 
   for (i = 1; i < argc - 1; i++) {
@@ -9,5 +15,9 @@
   }
   if (argc >= 2) {
+    if (RETURN_CHAR) {
       gprint (GP_LOG, "%s\n", argv[argc - 1]);
+    } else {
+      gprint (GP_LOG, "%s", argv[argc - 1]);
+    }
   }
   return (TRUE);
Index: /trunk/Ohana/src/opihi/cmd.data/plot.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/plot.c	(revision 32345)
+++ /trunk/Ohana/src/opihi/cmd.data/plot.c	(revision 32346)
@@ -53,4 +53,9 @@
     return (FALSE);
   }
+  if (dypvec && (dypvec->Nelements != xvec->Nelements)) goto mismatch;
+  if (dymvec && (dymvec->Nelements != xvec->Nelements)) goto mismatch;
+  if (dxpvec && (dxpvec->Nelements != xvec->Nelements)) goto mismatch;
+  if (dxmvec && (dxmvec->Nelements != xvec->Nelements)) goto mismatch;
+
   Npts = xvec[0].Nelements;
   if (Npts == 0) return (TRUE);
@@ -69,3 +74,7 @@
   }
   return (TRUE);
+
+mismatch:
+  gprint (GP_ERR, "error and data vector lengths are mismatched\n");
+  return (FALSE);
 }
Index: /trunk/Ohana/src/relastro/Makefile
===================================================================
--- /trunk/Ohana/src/relastro/Makefile	(revision 32345)
+++ /trunk/Ohana/src/relastro/Makefile	(revision 32346)
@@ -62,4 +62,6 @@
 $(SRC)/high_speed_objects.$(ARCH).o  \
 $(SRC)/high_speed_utils.$(ARCH).o  \
+$(SRC)/relastro_merge_source.$(ARCH).o  \
+$(SRC)/resort_catalog.$(ARCH).o  \
 $(SRC)/relastroVisual.$(ARCH).o
 
Index: /trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- /trunk/Ohana/src/relastro/include/relastro.h	(revision 32345)
+++ /trunk/Ohana/src/relastro/include/relastro.h	(revision 32346)
@@ -15,5 +15,5 @@
 typedef enum {FIT_NONE, FIT_AVERAGE, FIT_PM_ONLY, FIT_PAR_ONLY, FIT_PM_AND_PAR} FitMode;
 
-typedef enum {TARGET_NONE, TARGET_OBJECTS, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED} FitTarget;
+typedef enum {TARGET_NONE, TARGET_OBJECTS, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE} FitTarget;
 
 typedef struct {
@@ -94,4 +94,9 @@
 char   SKY_TABLE[256];
 int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
+
+unsigned int OBJ_ID_SRC;
+unsigned int CAT_ID_SRC;
+unsigned int OBJ_ID_DST;
+unsigned int CAT_ID_DST;
 
 double SIGMA_LIM;
@@ -210,10 +215,10 @@
 void          getfullregion       PROTO((Image *image, off_t Nimage, GSCRegion *fullregion));
 Image        *getimage            PROTO((off_t N));
-Image        *getimages           PROTO((off_t *N));
+Image        *getimages           PROTO((off_t *N, off_t **line_number));
 void          global_stats        PROTO((Catalog *catalog, int Ncatalog));
 void          initGrid            PROTO((int dX, int dY));
 void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
 void          initImageBins       PROTO((Catalog *catalog, int Ncatalog, int FULLINIT));
-void          initImages          PROTO((Image *input, off_t N));
+void          initImages          PROTO((Image *input, off_t *line_number, off_t N));
 void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
 void          initMosaicGrid      PROTO((Image *image, off_t Nimage));
@@ -372,2 +377,5 @@
 int applyConstraintsB(Catalog *catalog, off_t i);
 void setupAreaSelection(SkyRegion *region);
+
+int relastro_merge_source ();
+void resort_catalog (Catalog *catalog);
Index: /trunk/Ohana/src/relastro/src/CoordOps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/CoordOps.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/CoordOps.c	(revision 32346)
@@ -13,5 +13,5 @@
   Image *images;
 
-  images = getimages (&N);
+  images = getimages (&N, NULL);
 
   NoldCoords = N;
Index: /trunk/Ohana/src/relastro/src/FitPM.c
===================================================================
--- /trunk/Ohana/src/relastro/src/FitPM.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/FitPM.c	(revision 32346)
@@ -73,8 +73,8 @@
   chisq = 0.0;
   for (i = 0; i < Npts; i++) {
-      Xf = fit[0].Ro + fit[0].uR*T[i];
-      Yf = fit[0].Do + fit[0].uD*T[i];
-      chisq += SQ(X[i] - Xf) / SQ(dX[i]);
-      chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
+    Xf = fit[0].Ro + fit[0].uR*T[i];
+    Yf = fit[0].Do + fit[0].uD*T[i];
+    chisq += SQ(X[i] - Xf) / SQ(dX[i]);
+    chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
   }
   fit[0].Nfit = Npts;
Index: /trunk/Ohana/src/relastro/src/FitPMandPar.c
===================================================================
--- /trunk/Ohana/src/relastro/src/FitPMandPar.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/FitPMandPar.c	(revision 32346)
@@ -9,4 +9,5 @@
   double wx, wy, Wx, Wy, Tx, Ty, Tx2, Ty2, Xs, Ys, XT, YT;
   double PR, PD, PRT, PDT, PRX, PDY, PR2, PD2;
+  double chisq, Xf, Yf;
 
   A = array_init (5, 5);
@@ -95,4 +96,16 @@
   /* get the chisq from the matrix values */
 
+  // add up the chi square for the fit
+  chisq = 0.0;
+  for (i = 0; i < Npts; i++) {
+    Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].dp*pR[i];
+    Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].dp*pD[i];
+    chisq += SQ(X[i] - Xf) / SQ(dX[i]);
+    chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
+  }
+  fit[0].Nfit = Npts;
+
+  // the reduced chisq is divided by (Ndof = 2*Npts - 5)
+  fit[0].chisq = chisq / (2.0*Npts - 5.0);
   return (TRUE);
 }
Index: /trunk/Ohana/src/relastro/src/FixProblemImages.c
===================================================================
--- /trunk/Ohana/src/relastro/src/FixProblemImages.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/FixProblemImages.c	(revision 32346)
@@ -15,5 +15,5 @@
   ALLOCATE (sublist.filename, char *, 1);
 
-  image = getimages (&Nimage);
+  image = getimages (&Nimage, NULL);
 
   Nbad = 0;
Index: /trunk/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 32346)
@@ -11,4 +11,5 @@
 static Image        *image;   // list of available images
 static off_t        Nimage;   // number of available images
+static off_t       *LineNumber; // match of subset to full image table
 
 static int         *Ncatlist;  // catalogs associated with each image
@@ -27,6 +28,8 @@
 # endif
 
-Image *getimages (off_t *N) {
+Image *getimages (off_t *N, off_t **line_number) {
+
   *N = Nimage;
+  if (line_number) *line_number = LineNumber;
   return (image);
 }
@@ -42,9 +45,10 @@
 }
 
-void initImages (Image *input, off_t N) {
+void initImages (Image *input, off_t *line_number, off_t N) {
 
   off_t i;
 
   image = input;
+  LineNumber = line_number;
   Nimage = N;
 
Index: /trunk/Ohana/src/relastro/src/StarMaps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/StarMaps.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/StarMaps.c	(revision 32346)
@@ -40,5 +40,5 @@
   off_t i, Nimages;
 
-  images = getimages(&Nimages);
+  images = getimages(&Nimages, NULL);
 
   ALLOCATE (starmap, StarMap, Nimages);
@@ -64,5 +64,5 @@
   gettimeofday (&start, (void *) NULL);
 
-  images = getimages(&Nimages);
+  images = getimages(&Nimages, NULL);
 
   for (i = 0; i < catalog[0].Nmeasure; i++) {
@@ -90,5 +90,5 @@
   int ix, iy;
 
-  images = getimages(&Nimages);
+  images = getimages(&Nimages, NULL);
 
   for (i = 0; i < Nimages; i++) {
@@ -129,5 +129,5 @@
   double L, M, dLmax, dMmax;
 
-  images = getimages(&Nimages);
+  images = getimages(&Nimages, NULL);
 
   dLmax = dMmax = 0.0;
Index: /trunk/Ohana/src/relastro/src/UpdateChips.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateChips.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/UpdateChips.c	(revision 32346)
@@ -18,5 +18,5 @@
   Nskip = Nmosaic = NnewFit = NoldFit = 0;
 
-  image = getimages (&Nimage);
+  image = getimages (&Nimage, NULL);
 
   // save fit results for summary plot
Index: /trunk/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 32346)
@@ -13,5 +13,5 @@
     ID_IMAGE_ASTROM_FEW;
 
-  image = getimages (&Nimage);
+  image = getimages (&Nimage, NULL);
 
   for (i = 0; i < Nimage; i++) {
Index: /trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 32346)
@@ -196,5 +196,5 @@
       }
       
-      XVERB = FALSE && (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);
+      XVERB = (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);
 
       // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
@@ -225,6 +225,5 @@
 
       if (mode == FIT_PM_AND_PAR) {
-	fprintf (stderr, "parallax fitting is still untested (%s, %d)", __FILE__, __LINE__);
-	exit (2);
+	// fprintf (stderr, "parallax fitting is still untested (%s, %d)\n", __FILE__, __LINE__);
 
 	for (k = 0; k < N; k++) {
Index: /trunk/Ohana/src/relastro/src/UpdateSimple.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateSimple.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/UpdateSimple.c	(revision 32346)
@@ -8,5 +8,5 @@
   StarData *raw, *ref;
 
-  image = getimages (&Nimage);
+  image = getimages (&Nimage, NULL);
 
   for (i = 0; i < Nimage; i++) {
Index: /trunk/Ohana/src/relastro/src/args.c
===================================================================
--- /trunk/Ohana/src/relastro/src/args.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/args.c	(revision 32346)
@@ -1,4 +1,6 @@
 # include "relastro.h"
 void usage (void);
+void usage_merge_source (void);
+void usage_merge_source_id (char *name);
 
 int args (int argc, char **argv) {
@@ -6,8 +8,33 @@
   int N;
   double trange;
+  char *endptr;
 
   /* possible operations */
   FIT_TARGET = TARGET_NONE;
   FIT_MODE = FIT_AVERAGE;
+
+  if ((N = get_argument (argc, argv, "-merge-source"))) {
+    if (N > argc - 6) usage_merge_source();
+    if (strcmp(argv[N+3], "into")) usage_merge_source();
+    FIT_TARGET = TARGET_MERGE_SOURCE;
+    remove_argument (N, &argc, argv);
+    OBJ_ID_SRC = strtol(argv[N], &endptr, 0);
+    if (*endptr) usage_merge_source_id (argv[N]); 
+    remove_argument (N, &argc, argv);
+    CAT_ID_SRC = strtol(argv[N], &endptr, 0);
+    if (*endptr) usage_merge_source_id (argv[N]); 
+    remove_argument (N, &argc, argv);
+    remove_argument (N, &argc, argv); // remove the 'into'
+    OBJ_ID_DST = strtol(argv[N], &endptr, 0);
+    if (*endptr) usage_merge_source_id (argv[N]); 
+    remove_argument (N, &argc, argv);
+    CAT_ID_DST = strtol(argv[N], &endptr, 0);
+    if (*endptr) usage_merge_source_id (argv[N]); 
+    remove_argument (N, &argc, argv);
+
+    if (argc != 1) usage ();
+    return TRUE;
+  }
+
   if ((N = get_argument (argc, argv, "-update-objects"))) {
     remove_argument (N, &argc, argv);
@@ -307,4 +334,6 @@
   fprintf (stderr, "ERROR: USAGE: relastro -region RA RA DEC DEC\n");
   fprintf (stderr, "       OR:    relastro -catalog (ra) (dec)\n\n");
+  fprintf (stderr, "       OR:    relastro -high-speed [options]\n\n");
+  fprintf (stderr, "       OR:    relastro -merge-source [options]\n\n");
   fprintf (stderr, "  specify one of the following modes: \n");
   fprintf (stderr, "  -update-objects\n");
@@ -340,2 +369,12 @@
 } 
 
+void usage_merge_source_id (char *name) {
+
+  fprintf (stderr, "ERROR: invalid ID %s (remember to prefix 0x to hex IDs)\n", name);
+  exit (2);
+}
+
+void usage_merge_source () {
+  fprintf (stderr, "ERROR: USAGE: relastro -merge-source (objID) (catID) into (objID) (catID)\n");
+  exit (2);
+}
Index: /trunk/Ohana/src/relastro/src/initialize.c
===================================================================
--- /trunk/Ohana/src/relastro/src/initialize.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/initialize.c	(revision 32346)
@@ -10,4 +10,6 @@
   ConfigInit (&argc, argv);
   args (argc, argv);
+
+  if (FIT_TARGET == TARGET_MERGE_SOURCE) return;
 
   /* build a list of accepted photcodes. these will be used by bcatalog to accept or
Index: /trunk/Ohana/src/relastro/src/load_images.c
===================================================================
--- /trunk/Ohana/src/relastro/src/load_images.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/load_images.c	(revision 32346)
@@ -44,14 +44,5 @@
   MARKTIME("  select images: %f sec\n", dtime);
 
-  // generate db->vtable from db->ftable based on the selection
-  // XXX does this simply duplicate the memory needlessly?  we recreate these lines
-  // in reload_images.  If we had saved the line numbers, we could avoid this
-  // vtable points *another* copy of the subset rows
-  // (the later call to 'reload_images' copies the subset elements back on top of 
-  // the rows of the vtable)
-  // gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
-  // MARKTIME("converted ftable to vtable: %f sec\n", dtime);
-
-  initImages (subset, Nsubset);
+  initImages (subset, LineNumber, Nsubset);
   MARKTIME("  init images: %f sec\n", dtime);
 
@@ -68,9 +59,10 @@
 
   Image     *image;
-  off_t     Nimage, Nx, i;
+  off_t     Nimage, Nx, i, *LineNumber;
   VTable    *vtable;
 
-  image = getimages (&Nimage);
+  image = getimages (&Nimage, &LineNumber);
 
+  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nimage);
   vtable = &db[0].vtable;
 
Index: /trunk/Ohana/src/relastro/src/relastro.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro.c	(revision 32345)
+++ /trunk/Ohana/src/relastro/src/relastro.c	(revision 32346)
@@ -23,4 +23,10 @@
   if (FIT_TARGET == TARGET_HIGH_SPEED) {
     high_speed_catalogs ();
+    exit (0);
+  }
+
+  /* the object analysis is a separate process iterating over catalogs */
+  if (FIT_TARGET == TARGET_MERGE_SOURCE) {
+    relastro_merge_source ();
     exit (0);
   }
Index: /trunk/Ohana/src/relastro/src/relastro_merge_source.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro_merge_source.c	(revision 32346)
+++ /trunk/Ohana/src/relastro/src/relastro_merge_source.c	(revision 32346)
@@ -0,0 +1,138 @@
+# include "relastro.h"
+
+int relastro_merge_source () {
+
+  int i, m;
+  SkyTable *sky = NULL;
+  Catalog catalog_src, catalog_dst;
+
+  // relastro -merge-source (objID) (catID) into (objID) (catID) 
+  // merge the detections of the first source with those of the second source
+  
+  // tell libdvo the CATDIR
+  dvo_set_catdir(CATDIR);
+
+  // load the current sky table (layout of all SkyRegions) 
+  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, FALSE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+  
+  // we are merging the detections of the src into the dst : OBJ_ID_SRC,CAT_ID_SRC -> OBJ_ID_DST,CAT_ID_DST
+
+  // find the catalog containing the src object:
+  dvo_catalog_init (&catalog_src, TRUE);
+  dvo_catalog_init (&catalog_dst, TRUE);
+  SkyRegion *region_src = NULL;
+  SkyRegion *region_dst = NULL;
+
+  // load data from each region file, only use bright stars
+  for (i = 0; i < sky[0].Nregions; i++) {
+    if (sky[0].regions[i].index == CAT_ID_SRC) {
+      catalog_src.filename = sky[0].filename[i];
+      region_src = &sky[0].regions[i];
+    }
+    if (sky[0].regions[i].index == CAT_ID_DST) {
+      catalog_dst.filename = sky[0].filename[i];
+      region_dst = &sky[0].regions[i];
+    }
+  }    
+
+  if (!catalog_src.filename) {
+    fprintf (stderr, "ERROR: cannot find catalog file matching source catID %x\n", CAT_ID_SRC);
+    exit (2);
+  }
+  if (!catalog_dst.filename) {
+    fprintf (stderr, "ERROR: cannot find catalog file matching destination catID %x\n", CAT_ID_DST);
+    exit (2);
+  }
+
+  // load the source object catalog:
+  catalog_src.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
+  catalog_src.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
+  catalog_src.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+  catalog_src.Nsecfilt  = GetPhotcodeNsecfilt ();
+
+  if (!dvo_catalog_open (&catalog_src, region_src, VERBOSE, "w")) {
+    fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog_src.filename);
+    exit (1);
+  }
+  if (!catalog_src.Naves_disk) {
+    fprintf (stderr, "no data in %s, error in cat ID?\n", catalog_src.filename);
+    exit (1);
+  }
+
+  // find the source object (by objID)
+  int index_src = -1;
+  for (i = 0; i < catalog_src.Naverage; i++) {
+    if (OBJ_ID_SRC != catalog_src.average[i].objID) continue;
+    index_src = i;
+    break;
+  }
+  if (index_src < 0) {
+    fprintf (stderr, "cannot find source object ID %x\n", OBJ_ID_SRC);
+    exit (1);
+  }
+
+  // save the measures from this object 
+  // Measure *measures_src;
+  // ALLOCATE (measures_src, Measure, catalog_src.average[index_src].Nmeasure);
+  // m = catalog_src.average[index_src].measureOffset;
+  // for (i = 0; i < catalog_src.average[index_src].Nmeasure; i++, m++) {
+  //   memcpy (&measures_src[i], &catalog_src.measure[m], sizeof(Measure));
+  // }
+    
+  if (CAT_ID_SRC == CAT_ID_DST) {
+
+    // find the target objects 
+    int index_dst = -1;
+    for (i = 0; i < catalog_src.Naverage; i++) {
+      if (OBJ_ID_DST != catalog_src.average[i].objID) continue;
+      index_dst = i;
+      break;
+    }
+    if (index_dst < 0) {
+      fprintf (stderr, "cannot find source object ID %x\n", OBJ_ID_DST);
+      exit (1);
+    }
+
+    // repoint the src measures at this object
+    Measure *measures_src;
+    ALLOCATE (measures_src, Measure, catalog_src.average[index_src].Nmeasure);
+    m = catalog_src.average[index_src].measureOffset;
+    for (i = 0; i < catalog_src.average[index_src].Nmeasure; i++, m++) {
+
+      // update objID & catID to match the new source
+      catalog_src.measure[m].objID  = catalog_src.average[index_dst].objID;
+      catalog_src.measure[m].catID  = catalog_src.average[index_dst].catID;
+      catalog_src.measure[m].averef = index_dst;
+
+      // get the instantaneous positions:
+      double R = catalog_src.average[index_src].R - catalog_src.measure[m].dR / 3600.0;
+      double D = catalog_src.average[index_src].D - catalog_src.measure[m].dD / 3600.0;
+
+      // update the offset coordinates to match the new source
+      catalog_src.measure[m].dR = 3600.0*(catalog_src.average[index_dst].R - R);
+      catalog_src.measure[m].dD = 3600.0*(catalog_src.average[index_dst].D - D);
+    }
+
+    // update the count? (updated by resort?)
+    catalog_src.average[index_dst].Nmeasure += catalog_src.average[index_src].Nmeasure;
+
+    // for the moment, don't delete this object...
+    catalog_src.average[index_src].Nmeasure = 0;
+    catalog_src.average[index_src].measureOffset = 0;
+
+    catalog_src.sorted = FALSE;
+
+    // resort the measure table and save
+    resort_catalog (&catalog_src);
+
+    dvo_catalog_save (&catalog_src, VERBOSE);
+    dvo_catalog_unlock (&catalog_src);
+    dvo_catalog_free (&catalog_src);
+
+    exit (0);
+  }
+
+  return TRUE;
+}
+
Index: /trunk/Ohana/src/relastro/src/resort_catalog.c
===================================================================
--- /trunk/Ohana/src/relastro/src/resort_catalog.c	(revision 32346)
+++ /trunk/Ohana/src/relastro/src/resort_catalog.c	(revision 32346)
@@ -0,0 +1,149 @@
+# include "relastro.h"
+
+# define myAbort(MSG) { fprintf (stderr, "%s\n", MSG); abort(); }
+# define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } }
+
+// sort the measure Sequence based on the average Sequence entries
+void SortAveMeasMatch (off_t *MEAS, off_t *AVE, off_t N) {
+
+# define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;	\
+    tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;		\
+    tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;		\
+  }
+# define COMPARE(A,B)(AVE[A] < AVE[B])
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+# undef SWAPFUNC
+# undef COMPARE
+}
+
+// XXX : where is the time going?  perhaps the ALLOCATE?
+// XXX : I don't thnk his is getting the right answer yet.
+
+void resort_catalog (Catalog *catalog) {
+
+  off_t Naverage, Nmeasure;
+  Measure *measure;
+  Average *average;
+  off_t i, j, N, currentAve;
+
+  off_t *measureSeq = NULL;
+  off_t *averageSeq = NULL;
+  Measure *measureTMP = NULL;
+
+  if (catalog[0].sorted == TRUE) return;
+
+  // struct timeval start, stop;
+  // gettimeofday (&start, NULL);
+
+  /* internal counters */
+  Nmeasure = catalog[0].Nmeasure;
+  Naverage = catalog[0].Naverage;
+
+  measure = catalog[0].measure;
+  average = catalog[0].average;
+  
+  // we have a table of average objects and an unsorted table of measurements.  each measurement
+  // has a reference to the average object sequence (as well as an ID)
+  // measure[i].averef -> average[averef]
+  // measure[i].objID = average[averef].objID
+  // measure[i].catID = average[averef].catID
+
+  // we want a sorted measure array with all averef entries in sequence
+
+  ALLOCATE (measureSeq, off_t,   Nmeasure);
+  ALLOCATE (averageSeq, off_t,   Nmeasure);
+
+  for (i = 0; i < Nmeasure; i++) {
+    measureSeq[i] = i;
+    averageSeq[i] = measure[i].averef;
+    
+    if (catalog[0].catformat >= DVO_FORMAT_PS1_V1) {
+      // earlier formats did not carry the objID or catID, so they are not available (we could assign on load, but we don't)
+      myAssert(average[averageSeq[i]].objID == measure[measureSeq[i]].objID, "object / detection mismatch");
+      myAssert(average[averageSeq[i]].catID == measure[measureSeq[i]].catID, "object / detection mismatch");
+    }
+  }
+  
+  // check that averageSeq is now in order
+  // for (i = 1; i < Nmeasure; i++) {
+  //   if (averageSeq[i] < averageSeq[i-1]) {
+  //     fprintf (stderr, "%d ", (int) i);
+  //   }
+  // }
+  // fprintf (stderr, "\n");
+
+  SortAveMeasMatch(measureSeq, averageSeq, Nmeasure);
+  // MARKTIME("sort : %f sec\n", dtime);
+
+  // check that averageSeq is now in order
+  // for (i = 1; i < Nmeasure; i++) {
+  //   if (averageSeq[i] < averageSeq[i-1]) {
+  //     fprintf (stderr, "%d ", (int) i);
+  //   }
+  // }
+  // fprintf (stderr, "\n");
+
+  // copy the measurements in the sorted order
+  ALLOCATE (measureTMP, Measure, Nmeasure);
+  for (i = 0; i < Nmeasure; i++) {
+    j = measureSeq[i];
+    measureTMP[i] = measure[j];
+  }
+  // MARKTIME("assign measure : %f sec\n", dtime);
+
+  // update the values of average.measureOffset and average.Nmeasure
+  FREE(measure);
+  catalog[0].measure = measureTMP;
+
+  N = 0;
+  currentAve = averageSeq[0];
+  average[currentAve].measureOffset = 0;
+  for (i = 0; i < Nmeasure; i++) {
+    if (averageSeq[i] != currentAve) {
+      // we have hit the next entry in the list
+      average[currentAve].Nmeasure = N;
+      N = 0;
+      currentAve = averageSeq[i];
+      average[currentAve].measureOffset = i;
+    }
+    N++;
+  }
+  // N++;
+  average[currentAve].Nmeasure = N;
+  // MARKTIME("update Nmeasure : %f sec\n", dtime);
+
+  int NmeasureTotal = 0;
+  int measureOffsetOK = TRUE;
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    NmeasureTotal += catalog[0].average[i].Nmeasure;
+    if (VERBOSE && !(NmeasureTotal <= catalog[0].Nmeasure)) {
+      fprintf (stderr, "too few measurements: %d %d %d\n", (int) i, NmeasureTotal, (int) catalog[0].Nmeasure);
+    }
+    measureOffsetOK &= (catalog[0].average[i].measureOffset < catalog[0].Nmeasure);
+    if (VERBOSE && !(catalog[0].average[i].measureOffset < catalog[0].Nmeasure)) {
+      fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nmeasure, (int) catalog[0].Nmeasure);
+    }
+    measureOffsetOK &= (catalog[0].average[i].measureOffset + catalog[0].average[i].Nmeasure <= catalog[0].Nmeasure);
+    if (VERBOSE && !(catalog[0].average[i].measureOffset + catalog[0].average[i].Nmeasure <= catalog[0].Nmeasure)) {
+      fprintf (stderr, "orrset + Nmeasure too large: %d + %d > %d %d\n", (int) i, catalog[0].average[i].measureOffset, catalog[0].average[i].Nmeasure, (int) catalog[0].Nmeasure);
+    }
+  }
+
+  if (!measureOffsetOK) {
+    fprintf (stderr, "ERROR: catalog %s has an invalid measureOffset\n", catalog[0].filename);
+  }
+
+  if (NmeasureTotal != catalog[0].Nmeasure) {
+    fprintf (stderr, "ERROR: catalog %s has an invalid Nmeasure\n", catalog[0].filename);
+  }
+
+  // MARKTIME("  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeasure, (long long) Naverage);
+
+  catalog[0].sorted = TRUE;
+
+  FREE (measureSeq);
+  FREE (averageSeq);
+
+  return;
+}
+
Index: /trunk/Ohana/src/relphot/src/load_images.c
===================================================================
--- /trunk/Ohana/src/relphot/src/load_images.c	(revision 32345)
+++ /trunk/Ohana/src/relphot/src/load_images.c	(revision 32346)
@@ -85,14 +85,4 @@
   }
 
-
-  // generate db->vtable from db->ftable based on the selection
-  // XXX does this simply duplicate the memory needlessly?  we recreate these lines
-  // in reload_images.  If we had saved the line numbers, we could avoid this
-  // vtable points *another* copy of the subset rows
-  // (the later call to 'reload_images' copies the subset elements back on top of 
-  // the rows of the vtable)
-  // gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
-  // MARKTIME("converted ftable to vtable: %f sec\n", dtime);
-
   // save the subset of images in the static reference in ImageOps, set up indexes
   initImages (subset, LineNumber, Nsubset);
