Index: /trunk/Ohana/doc/www/html/DVO/addstar.htm
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/addstar.htm	(revision 5143)
+++ /trunk/Ohana/doc/www/html/DVO/addstar.htm	(revision 5144)
@@ -0,0 +1,208 @@
+<meta name=file  content=addstar>
+<meta name=title content=addstar>
+<meta name=page  content=addstar>
+
+<p>
+This program takes a photometry file, with astrometry, provided by
+earlier routines and incorporates the stellar measurements into the
+photometry database.  This routine does NOT try to calibrate or check
+the photometry, nor does it try to improve the coordinate
+determinations or calculate chisquares for position or photometry -
+those tasks are performed by other routines.
+
+<p>
+Addstar starts by loading in the photometry file and converting the
+pixel coordinates to sky coordinates using the astrometry information
+in the header of the file.  It also gets the detection limits and
+stores the image astrometry information.
+
+<p>
+Next, addstar determines which of all the previous images overlaps
+with this image and also which of the catalog regions overlaps with
+this image.
+
+<p>
+Addstar considers each catalog region in turn, and compares the
+positions of stars in the catalog with stars in the image.  If a
+catalog star is detected, a new measurement is added to the catalog.
+If a catalog star is not detected, but is in the field of view of this
+image, the detection limit for this image is added to the list of
+measurements as an upper limit.  If the image contains a star which is
+not already included in the catalog, the star is added to the catalog,
+and all previous images are checked to see if they included this
+location.  If so, upper limits are added to the list of measurements.
+
+<p>
+To deal with blended images, we have taken the philosophy that all
+measurements compatible with the coordinates of a given star should be
+included in the list of measurements.  This assumes that programs or people
+downstream will figure out which is the "correct" measurement.  To
+this end, if a catalog star is consistent with multiple measurements,
+they are all added to the catalog measurement and the measurements are
+given a flag to say that there was blending in the catalog (ie, it is
+probably the catalog star which is a blend).  If multiple catalog
+stars are consistent with the same image star, that measurement is
+added to each catalog star, and given a flag to say that there was
+blending on the image.
+
+<p>
+After all catalogs have been checked, updated, and written to disk,
+the image is added to the database of images.
+
+<p>
+see <a href=database.html> DVO database </a> for discussion of the
+database storage format.   
+
+<hr>
+
+<h2> Usage </h2>
+
+<pre>
+ addstar (filename)
+ addstar -cat (catalog)
+ addstar -ref (filename)
+</pre>
+
+<p>
+In the first form, addstar loads the photometry information for a
+single image into the database.  The file must be in one of the Elixir
+cmp/smp/smf formats, and must have been astrometrized (eg, with
+gastro, gastro2, and/or mosastro).  The file must also be provided
+with a valid photcode in the header (keyword PHOTCODE) or the photcode
+must be supplied as an option to addstar (see below).  The photcode
+must be listed in the photcode table (see config variable
+PHOTCODE_FILE).  In the case that the image has been astrometrized
+with mosastro (two-level mosaic astrometry), the corresponding mosaic
+header unit must be supplied as an option (see below).  
+
+<p>
+In the second form, addstar will load photometry from the specified
+reference catalog, located in a known location, and will load it into
+the database.  Allowed catalog names are: <tt> USNO, GSC, 2MASS,
+2MASS-ALLSKY, 2MASS-DR </tt>.  Note that USNO corresponds to the
+USNO-A catalog, 2MASS corresponds to the 2MASS-ALLSKY catalog.  It is
+necessary to have defined an appropriate photcode for the given
+catalog.  The following photcodes are expected to exist:
+
+<table>
+<tr><th> catalog </th><th> allowed photcodes   	     </th></tr>
+<tr><td> GSC     </td><td> GSC_M               	     </th></tr>
+<tr><td> USNO    </td><td> USNO_RED, USNO_BLUE 	     </th></tr>
+<tr><td> 2MASS*  </td><td> 2MASS_J, 2MASS_H, 2MASS_K </th></tr>
+</table>
+
+When more than one photcode is allowed, one must be selected; there
+are no defaults in that case. <em>It is advised that addstar -cat be
+used with a restricted region of the sky; the default behavior will
+load the reference catalog for the entire sky into the DB!</em>
+
+<p>
+In the third form, addstar will load data from the specified ASCII
+text file with a fixed format.  The file must contain lines with one
+line per star.  The first four columns must contain the values RA,
+DEC, Magnitude, Magnitude error.  The RA and DEC must be in J2000
+decimal degrees.  Blank lines are allowed, and lines may be commented
+with the hash sign (#).  The provided photometry must all be for a
+single photcode, which must be provided as a command-line option.
+
+<h2> Additional Options </h2>
+
+<pre>
+  -region ra ra dec dec           : only add data in specified region (-ref mode only)
+  -p (photcode)                   : specify photcode (override header)
+  -time (YYYY/MM/DD,HH:MM:SS)     : specify date/time (override header)
+  -mosaic (filename)              : identify associated mosaic frame for chip image
+  -fits                           : input file is FITS table, not TEXT table
+  -existing-regions               : only add measurements to existing catalog files
+  -only-match                     : only add measurements to existing objects
+  -missed                         : skipped 'missed' entries
+  -replace                        : replace time/photcode measurements (no duplication)
+  -image                          : only insert image data
+  -cal                            : perform zero-point calibration
+  -skyprobe                       : specify skyprobe mode
+  -2massquality                   : define 2MASS quality flags to keep
+  -accept                         : accept bad astrometry from header
+  -force                          : force read of database with inconsistent info
+  -v                              : verbose mode
+  -dump (mode)                    : output test data
+  -help                           : print this list
+  -h                              : print this list
+</pre>
+
+
+<h2> Elixir Configuration Data </h2>
+
+addstar uses the following Elixir configuration variables:
+
+<ul>
+<li> EXPTIME-KEYWORD  : header keyword defining exposure time
+<li> DATE-KEYWORD  : header keyword defining the date 
+<li> DATE-MODE  : mode for header date information: use a combination
+of Ys, Ms, Ds to specify order.  If only 2 digits are specified for
+the year, numbers greater than 50 are assumed in the 1900s, less than
+in the 2000s.  eg YYYY/MM/DD
+<li> UT-KEYWORD  : header keyword defining UT
+<li> MJD-KEYWORD  : header keyword defining MJD
+<li> JD-KEYWORD  : header keyword defining JD
+<li> AIRMASS-KEYWORD
+<li> CCDNUM-KEYWORD
+<li> ST-KEYWORD
+
+<li> RADIUS : radius for matches; may have the value "header", in which
+case the astrometric error listed in the header, along with
+<tt>NSIGMA</tt> is used to define a match.  Otherwise, defines a
+radius in arcseconds.
+
+<li> NSIGMA : number of astrometric error sigma to use for match
+radius (see <tt>RADIUS</tt>).
+
+<li> XOVERSCAN : used to define valid pixels in the image. subtracted
+from image NAXIS1 value to define image box. 
+
+<li> YOVERSCAN : used to define valid pixels in the image. subtracted
+from image NAXIS2 value to define image box. 
+
+<li> ADDSTAR_XMIN : this value, and the following three, are used to
+define a region on the image where the photometry is considered
+reliable.  Stars outside this region are marked as having poor
+measurements.
+
+<li> ADDSTAR_XMAX : see <tt>ADDSTAR_XMIN</tt>
+<li> ADDSTAR_YMIN : see <tt>ADDSTAR_XMIN</tt>
+<li> ADDSTAR_YMAX : see <tt>ADDSTAR_XMIN</tt>
+
+<li> MIN_SN_FSTAT : only include objects in the DB with S/N greater
+than this value.
+
+<li> GSCDIR        : location of the HST Guide Star Catalog
+<li> USNO_CDROM    : location of the USNO-A data
+<li> 2MASS_DIR_AS  : location of the 2MASS allsky data 
+<li> 2MASS_DIR_DR2 : location of the 2MASS DR2 data 
+
+2MASS, USNO, and GSC are all loaded from their idiosyncratic formats.
+
+<li> GSCFILE  : location of the GSC layout file (for GSC and ptolemy)
+<li> CATDIR  : location of the ptolemy data
+<li> IMAGE_CATALOG : location of the image database table
+
+<li> CATMODE : storage mode for the database.  may be one of RAW,
+MEF, SPLIT, MYSQL.  SPLIT and MYSQL are currently unsupported.  This
+defines the output format for new tables; the input format is auto-detected.
+
+<li> CATFORMAT : data format for the database.  may be one of LONEOS,
+ELIXIR, PANSTARRS.
+
+<li> PHOTCODE_FILE : location of the photcode file describing the
+photometry system of interest.
+
+<li> OBSERVATORY-LATITUDE : hard-wired observatory latitude.  used for
+precision airmass for skyprobe.  <em> should be replaced with a more
+sophisticated approach</em>
+
+<li> SUBPIX_DATAFILE : table for subpixel structure corrections (skyprobe)
+
+<li> IMAGE_CATALOG_TEMPLATE : deprecated, was used to supply a FITS
+header template
+<li> CATALOG_TEMPLATE : deprecated, was used to supply a FITS
+header template
+</ul>
Index: /trunk/Ohana/doc/www/html/DVO/database.htm
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/database.htm	(revision 5144)
+++ /trunk/Ohana/doc/www/html/DVO/database.htm	(revision 5144)
@@ -0,0 +1,121 @@
+
+This discussion is somewhat short, and only valid for the original
+Elixir-RAW style format/mode.  
+
+<pre>
+The format for a catalog region file is as follows:
+
+-- 
+Header
+--
+Averages
+--
+Measurements
+--
+</pre>
+
+<p>
+The Header follows the format of a FITS header but always stored with
+3 blocks to speed up read time: 2880 x 3 bytes.  Two important
+keywords in the header: NSTARS & NMEAS
+
+<p>
+All average values are stored consecutively in a single block.  They
+are written as an array with NSTARS elements of the Average structure
+defined below.  The individual measurements follow the averages as a
+block.  To find a measurement for a given star, you need to get the
+value of the offset for the star.  this is the element number for the
+first measurement of this star, and are followed by next measurements
+for this star, until the value Nm is reached.
+
+Here are the structures being used for the average and measurement
+values:
+
+<pre>
+
+typedef struct {
+  float R;                    /* RA  in decimal degrees */
+  float D;                    /* DEC in decimal degrees */
+  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
+  unsigned short int Nm;      /* number of measurements */
+  unsigned short int Xp, Xm;  /* chisq values in tenths */
+  unsigned int offset;        /* offset to first Measure-ment */
+} Average;                    /* = 20 bytes / average */
+
+typedef struct {
+  char dR, dD;                /* tenths of arcsec (-12.7 to +12.7 valid range) */
+  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
+  unsigned char dM;           /* thousandths of mag (0.000 -- 0.255 valid range) */
+  float t;                    /* time in seconds (what is reference?) */
+  unsigned int average;       /* reference to corresponding Average entry, 
+				 upper byte of value contains flags.
+				 limit of 16,777,215 stars (Naverage) 
+				 in a file (=0xFFFFFF).
+				 flags = average & 0x1000000 */
+} Measure;                    /* = 13 bytes / measure */
+</pre>
+
+<p>
+The above two structures define the entries in the photometry
+database.  The database consists of a large number of files
+representing a small patch on the sky (roughly 1.5 degree$^2$ in most
+places).  These files are organized into directories representing
+bands of Declination.  A reference file determines the coordinate
+boundaries for each of the files so that a given point on the sky can
+unambiguously be associated with a specific file in a specific
+directory.  The sky coordinates for each file is the same as those
+used by the HST Guide Star catalog, except for the region around the
+North celestial pole, for which all stars are included in a single
+file.  
+
+<p>
+Within a given file, the data are stored in a binary format, with an
+ASCII FITS-like header.  The header is examply in the format of a
+normal FITS header, but with the exception that all files have a fixed
+number of header blocks (for now 3 blocks = 8640 bytes).  This is done
+to speed loading the header and finding the beginning of the binary
+data.  The number of 3 blocks seems quite generous, as currently only
+a few FITS keywords have been defined for each file, basically
+keywords to define the number of stars and the total number of
+measurements stored in the file, as well as values to define the RA
+and DEC range of the file.  
+
+<p>
+The first section of data following the header blocks consists of
+average measurements for each uniquely observed star.  Each star
+occupies 20 bytes, the size of the Average structure defined above.
+The Average structure contains the average Ra, Dec, and Magnitude for
+the star, as well as the number of measurements, and \chisq\ values
+for the magnitude and position.  Finally, there is a 32 bit integer
+which defines the offset to the first measurement for this star.  This
+offset is defined as the number of Measure records from the start of
+the Measure structure.
+
+<p>
+The second section of data, following the Average data contains all
+measurements for each star listed in Average.  Each measurement
+occupies 13 bytes, the size of the Measure structure.  This structure
+contains the difference of this position from the average RA and DEC,
+and the instrumental magnitude of this measurement (in the units
+defined by the fstat program, which give m = -2.5*log(cts) + Mo, where
+Mo is currently 24.5 [10/15]).  There is also the magnitude error for
+this measurement, the time of the measurement (in seconds relative to
+a to-be-determined zero point), and a reference to the entry in the
+Average structure so we can relate a given measurement with a given star.
+This last entry also includes a byte of flags, of which only 4 have
+currently been defined.  This means the Average offset can only be as
+large as  16,777,215 (0xffffff), limiting the possible number of stars
+allowed in a given file.  This does not seem like a long term problem,
+though:  aside from the fact that this number is very large and we
+only expect in the vicinity of 20,000 stars per file, the file can
+easily be divided into pieces at a later date if needed.  this last
+step is trivial, consisting of splitting the data up into smaller
+RA,DEC regions, and updating the reference catalog.  With the above
+definitions for the Average and Measure structures, we will typically
+expect 20,000 * 15 measurements per year and 20,000 average entries in
+a given file.  This implies a file size of about 4.3 MB at the end of
+a year.  It is also possible that we will choose to split the files up
+in the future if the number of measurements makes their size
+unweildy.  4.3 MB is sufficiently small that this is not a problem,
+but after only 5 years, the files will be over 21 MB each, getting to
+be fairly significant.  
Index: /trunk/Ohana/doc/www/html/DVO/extract.htm
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/extract.htm	(revision 5144)
+++ /trunk/Ohana/doc/www/html/DVO/extract.htm	(revision 5144)
@@ -0,0 +1,147 @@
+<meta name=title content=DVO extractions>
+<meta name=page  content=extractions>
+
+<p>
+DVO provides several ways to access the photometry information stored
+in the database.  Several simple commands allow the user to extract 1
+dimensional information directly from one of the primary database
+tables.  The commands are:
+<ul>
+<li> imextract
+<li> avextract
+<li> mextract
+<li> imsearch
+<li> detsearch
+</ul>
+
+<h3> imextract </h3> 
+
+This command allows the user to extract one of the columns from the
+image table, applying filtering as desired:
+
+<pre>
+  dvo: imextract
+  USAGE: imextract (value) [-region] [-time start range] [-photcode photcode]
+  dvo: imextract help
+  value may be one of the following:
+   ra dec airmass Mcal dMcal Xm photcode time fwhm exptime nstar ncal sky flag
+</pre>
+
+<p>
+The extracted data is saved in a vector with the same name used to
+select the column.  The vector name will have the same case as the
+choice given, but the column selection is case-insensitive (since
+there are no ambiguities in the database columns names by case).  
+
+<h3> avextract </h3>
+
+This command allows the user to extract data from one of the Average
+table columns:
+
+<pre>
+  dvo: avextract
+  USAGE: avextract (from) (value) [options]
+    from: cpt name or 'all'
+    value: average.parameter or photcode
+  dvo: avextract all help
+  value may be one of the following:
+   ra dec dmag Nmeas Nmiss Xm Xp Nphot Ncode flag type
+</pre>
+
+<p>
+This command takes as the first argument the name of one of the
+database regions.  Alternatively, all regions currently displayed may
+be selection with the word 'all'.  The second option specifies which
+column to select from the Average table.  In addition to the basic
+data columns (ra, dec, etc), the magnitude-related average values
+(mag, dmag, Xm, Nphot, Ncode) are coupled to a photcode, which is thus
+required for these selections.  The value 'mag' may also be subsituted
+with a primary or secondary photcode.  Eg:
+
+<pre>
+  avextract all ra : select ra for all objects in displayed region
+  avextract all g  : select g magnitudes
+  avextract all mag -photcode r : select r magnitudes 
+  avextract all Xm -photcode r  : select chisq values for r average mags
+</pre>
+
+<h3> mextract </h3>
+
+This command allows the user to extract data from one of the Measure
+table columns:
+
+<pre>
+  dvo: mextract
+  USAGE: mextract (from) (value) [options]
+    from: cpt name or 'all'
+    value: measure.parameter or photcode
+  dvo: mextract all help
+  value may be one of the following:
+   ra dR dec dD mag dmag Mrel Mcal photcode time fwhm dophot xccd yccd xmosaic ymosaic flags
+</pre>
+
+<p>
+This command takes as the first argument the name of one of the
+database regions.  Alternatively, all regions currently displayed may
+be selection with the word 'all'.  The second option specifies which
+column to select from the Measure table.  In addition to the basic
+data columns (ra, dec, etc), the magnitude-related average values
+(mag, dmag) are coupled to a photcode, which is thus required for
+these selections.  The value 'mag' may also be subsituted with a
+primary or secondary photcode.  Eg:
+
+<pre>
+  mextract all ra : select ra for all objects in displayed region
+  mextract all g  : select g magnitudes
+  mextract all mag -photcode r : select r magnitudes 
+  mextract all Xm -photcode r  : select chisq values for r average mags
+</pre>
+
+<h3> option filtering </h3>
+
+The following extraction options allow the user to restrict the
+selections:
+
+<p>
+<tt> -time (start) (range)<tt><br> 
+
+select data for images within the given time range.  The start date is
+given in the format YYYY/MM/DD,hh:mm:ss (any of these element may be
+dropped, in which case they default to 00 [for hh,mm,ss] or 01 [for
+MM,DD]).  The date may also be written as a number of days followed by
+j (JD) or J (MJD).  The two special date names "now" and "today" are
+also valid.  The range is written as a number followed by a unit, with
+valid units of s (seconds), m (minutes), h (hours), d (days).  Times
+are in UT.  For example:
+
+<pre>
+ -time 2001/1/1 30d : select the range starting at midnight on 2001/1/1
+  and ending 30 days (86400*30 seconds) later.
+
+ -time now -3h : select the time range starting three hours ago and
+  ending now.
+</pre>
+
+<tt> -region<tt><br> 
+
+restrict the selection to the currently display portion of the sky.
+This filter expects a portion of the sky to be plotted, and will only
+select data for images in the part of the sky.  The algorithm for
+selecting the displayed region may not be perfect, so images near the
+boundaries may be unexpected included or excluded (this depends on the
+exact overlap details).  Multiple queries with the same region will
+result in the same subset of images selected.
+
+<tt>-photcode (photcode) </tt><br>
+
+This restricts the selection to the given photcode.  Images may only
+have photcodes of 'Dependent' type (eg, CFH12K.R.00).  This filter
+allows the selection of images by exact match (selected photcode is
+Dependent type) or by equivalence match (selected photcode is Primary
+or Secondary type).  Thus, selecting images based on CFH12K.R.00 will
+ignore images with photcode CFH12K.R.10, while selecting images based
+on photcode 'r' will return all images with CFH12K.R.*, since all are
+equivalent to 'r'.  (NOTE: these details depend on the layout of the
+photcode table).
+
+<em> fill this out with all other restrictions provided by photometry.c</em>
Index: /trunk/Ohana/doc/www/html/DVO/navigate.htm
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/navigate.htm	(revision 5144)
+++ /trunk/Ohana/doc/www/html/DVO/navigate.htm	(revision 5144)
@@ -0,0 +1,44 @@
+
+<p>
+The <a href=navigate.pro>navigate</a> script provides a convenient
+graphical user interface to the DVO shell and database.  To use it,
+simply load it into the DVO shell with the <tt>input</tt> command.  It
+is useful to always load this script by including the input command in
+your <tt>~/.dvorc</tt> file.  Once you have loaded the script, you
+can start it by typing <tt>navigate</tt>.  You can navigate around the
+sky, then exit the script at any time by typing 'q'.  This allows you
+to issue DVO commands related to your current position.  You can then
+resume navigating by restarting the script.
+
+<p>
+The navigate script lets you move about the sky by placing your cursor
+in the display window and clicking various keys.  Below is a summary
+of the basic key stokes:
+
+<pre>
+1 - zoom in factor of 2
+2 - zoom in factor of 1.2
+3 - recenter at cursor
+4 - zoom out factor of 1.2
+5 - zoom out factor of 2
+6 - zoom out factor of 10
+z - zoom to radius (requires 2nd keystroke)
+f - show full sky
+
+q - quit
+g - toggle skygrid on/off
+r - plot detected asteroids (rocks)
+l - plot HST GSC
+L - plot Landolt stars
+m - list measurements for stars within 1 pixel of cursor
+M - list measurements for stars within 1.8 arcsec of cursor
+i - list info about images touching cursor location 
+I - list info about images, with pixel coords of cursor position
+x - plot stars scaled by magnitude Chisq
+X - plot stars by magnitude scatter
+S - toggle auto-plotting of stars
+t - plot light curve for star within 2 arcsec of cursor position
+T - plot 'galaxy' light curve for star within 2 arcsec of cursor position
+c - plot status catalog boundaries
+C - list catalog at cursor location
+</pre>
Index: /trunk/Ohana/doc/www/html/DVO/navigate.pro
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/navigate.pro	(revision 5144)
+++ /trunk/Ohana/doc/www/html/DVO/navigate.pro	(revision 5144)
@@ -0,0 +1,379 @@
+# -*- perl -*-
+
+macro navigate
+  style -n 0
+  limits
+  $DSTARS = -1
+  $ZOOM = 180 / ($YMAX - $YMIN)
+  for i 1 100
+    $REDRAW = 0
+    cursor -g 1
+    # zoom controls
+    if ("$KEY" == "1")
+      $ZOOM = $ZOOM * 2
+      $REDRAW = 1
+      $Rnum = $R$KEY		      
+      $Dnum = $D$KEY
+      $KEY = num
+    end
+    if ("$KEY" == "2")
+      $ZOOM = $ZOOM * 1.2
+      $REDRAW = 1
+      $Rnum = $R$KEY		      
+      $Dnum = $D$KEY
+      $KEY = num
+    end
+    if ("$KEY" == "3")
+      $REDRAW = 1
+      $Rnum = $R$KEY		      
+      $Dnum = $D$KEY
+      $KEY = num
+    end
+    if ("$KEY" == "4")
+      $ZOOM = $ZOOM / 1.2
+      $REDRAW = 1
+      $Rnum = $R$KEY		      
+      $Dnum = $D$KEY
+      $KEY = num
+    end
+    if ("$KEY" == "5")
+      $ZOOM = $ZOOM / 2
+      $REDRAW = 1
+      $Rnum = $R$KEY		      
+      $Dnum = $D$KEY
+      $KEY = num
+    end
+    if ("$KEY" == "6")
+      $ZOOM = $ZOOM / 20
+      $REDRAW = 1
+      $Rnum = $R$KEY		      
+      $Dnum = $D$KEY
+      $KEY = num
+    end
+
+    # help list
+    if ("$KEY" == "h")
+     echo "1 - zoom in factor of 2"
+     echo "2 - zoom in factor of 1.2"
+     echo "3 - recenter at cursor"
+     echo "4 - zoom out factor of 1.2"
+     echo "5 - zoom out factor of 2"
+     echo "6 - zoom out factor of 10"
+     echo "z - zoom to radius (requires 2nd keystroke)"
+     echo "f - show full sky"
+     echo ""
+     echo "q - quit"
+     echo "g - toggle skygrid on/off"
+     echo "r - plot detected asteroids (rocks)"
+     echo "l - plot HST GSC"
+     echo "L - plot Landolt stars"
+     echo "m - list measurements for stars within 1 pixel of cursor"
+     echo "M - list measurements for stars within 1.8 arcsec of cursor"
+     echo "i - list info about images touching cursor location" 
+     echo "I - list info about images, with pixel coords of cursor position"
+     echo "x - plot stars scaled by magnitude Chisq"
+     echo "X - plot stars by magnitude scatter"
+     echo "S - toggle auto-plotting of stars"
+     echo "t - plot light curve for star within 2 arcsec of cursor position"
+     echo "T - plot 'galaxy' light curve for star within 2 arcsec of cursor position"
+     echo "c - plot status catalog boundaries"
+     echo "C - list catalog at cursor location"
+    end
+
+    # quit from navigate
+    if ("$KEY" == "q") 
+      break
+    end
+
+    # measure distance
+    if ("$KEY" == "d")
+      $r0 = $R$KEY
+      $d0 = $D$KEY
+      $ok = $KEY
+      echo "type at radius"
+      cursor -g 1
+      $r1 = $R$KEY
+      $d1 = $D$KEY
+      $dr = 3600*((dcos($d0)*($r0-$r1))^2 + ($d0-$d1)^2)^0.5
+      echo "$dr arcsec"
+    end
+    # show ra, dec
+    if ("$KEY" == "w")
+      $tmp = $R$KEY
+      if ($tmp < 0) 
+        $tmp = $R$KEY + 360.0
+      end
+      echo "$tmp $D$KEY" 
+      exec echo $tmp $D$KEY | radec -hh
+    end
+    # zoom to radius
+    if ("$KEY" == "z")
+      $r0 = $R$KEY
+      $d0 = $D$KEY
+      $ok = $KEY
+      echo "type at radius"
+      cursor -g 1
+      $r1 = $R$KEY
+      $d1 = $D$KEY
+      $dr = (($r0-$r1)^2 + ($d0-$d1)^2)^0.5
+      $ZOOM = $RAD / $dr
+      $REDRAW = 1
+      $KEY = $ok
+      $R$KEY = $r0
+      $D$KEY = $d0
+    end
+
+    # adjust mag scaling
+    if ("$KEY" == "J")
+      $MAG = $MAG - 0.5
+      $REDRAW = 2
+    end
+    if ("$KEY" == "K")
+      $MAG = $MAG + 0.5
+      $REDRAW = 2
+    end
+    if ("$KEY" == "j")
+      $dMAG = $dMAG * 0.8
+      $REDRAW = 2
+    end
+    if ("$KEY" == "k")
+      $dMAG = $dMAG * 1.25
+      $REDRAW = 2
+    end
+    echo "mag, dmag: $MAG, $dMAG"
+
+    # redraw region 
+    if ($REDRAW == 1)
+      region $R$KEY $D$KEY {$RAD/$ZOOM} sin
+      $RMIN = $R$KEY + $XMIN
+      $RMAX = $R$KEY + $XMAX
+      $DMIN = $D$KEY + $YMIN
+      $DMAX = $D$KEY + $YMAX
+      if (($ZOOM < 20) && ($GRID == 1)) 
+        style -c red; cgrid
+      end
+      if (($ZOOM > 20) && ($DSTARS == 1))
+        style -pt 7
+	pmeasure -all -m $MAG {$MAG + $dMAG}
+      end    
+      style -c black
+       images
+#       showtile
+    end
+
+    # redraw region 
+    if ($REDRAW == 2)
+      clear
+      if (($ZOOM < 20) && ($GRID == 1)) 
+        style -c red; cgrid
+      end
+      if (($ZOOM > 20) && ($DSTARS == 1))
+        style -pt 2
+	pmeasure -all -m $MAG {$MAG + $dMAG}
+      end    
+      style -c black
+      images
+    end
+
+    # turn grid on / off
+    if ("$KEY" == "g")
+      if ($GRID == 1) 
+        $GRID = 0
+        style -c white; cgrid
+        style -c black
+      else
+        $GRID = 1 
+        style -c black; cgrid
+      end
+    end
+
+    # plot full sky
+    if ("$KEY" == "f") 
+      echo "full"
+      $ZOOM = 1
+      resize 1150 600		      
+      region 0 0 90 ait
+      $RMIN = 0
+      $RMAX = 360
+      $DMIN = -90
+      $DMAX = +90
+      style -c red; cgrid
+      style -c black
+      images
+    end
+
+    # plot rocks
+    if ("$KEY" == "r") 
+#      plot.rocks
+      style -c blue   -pt 1; procks -speed 0.0041 1
+      style -c red    -pt 1; procks -speed 0.00041 0.0041
+      style -c indigo -pt 1; procks -speed 0 0.00041
+      style -c black -lw 0;
+    end
+    # plot HST-GSC
+    if ("$KEY" == "l") 
+      style -c blue -pt 7; cat -all -g -m 9 16
+      style -c black
+    end
+    # plot Landolt
+    if ("$KEY" == "L") 
+#      style -c red  -lw 2 -pt 3; cat -a 1 2 3 /data/elixir/srcdir/refs/stetson/stetsonBn.txt -m 9 18
+#      style -c blue -lw 2 -pt 3; cat -a 25 26 8 /data/elixir/srcdir/refs/landolt/new/Landolt92.fix -m 9 18
+      style -c red -lw 2 -pt 7; cat -a 1 2 3 /data/elixir/srcdir/refs/sdss/g_SDSS.dat -m 9 14
+#      style -c red -lw 2 -pt 3; cat -a 25 26 8 /data/elixir/srcdir/refs/landolt/new/Landolt92.hq -m 9 18
+#      style -c red -lw 2 -pt 3; cat -a 22 23 8 /data/elixir/srcdir/refs/landolt/new/Landolt92.unfix -m 9 18
+#      style -c blue -lw 2 -pt 7; cat -a 1 2 4 /data/elixir/srcdir/refs/landolt/extreme/extreme.match -m 0 20
+#      style -x 2 -c red -pt 7 ; cplot RA DEC
+      style -c black -lw 0
+    end
+
+    # list star measurements
+    if ("$KEY" == "m") 
+        $dR = $RAD/$ZOOM/300
+        if ($dR < 0.0005)
+	 $dR = 0.0005
+        end
+	gstar $R$KEY $D$KEY $dR -m
+    end
+
+    # plot mag residuals
+    if ("$KEY" == "R") 
+      echo "filter: "
+      cursor 1
+      clear -n 1 -s; lim 10 22 -0.2 0.2; clear; box
+      dmags $KEY\:rel - $KEY : $KEY -type 0
+      plot -x 2 -pt 0 -sz 0.3 -c red yv xv
+      dmags $KEY\:rel - $KEY : $KEY -type 0 -flag 0 -nphot +3 -chisq 2.0
+      plot -x 2 -pt 2 -sz 0.5 -c black yv xv
+      $KEY = R
+      style -n 0
+    end
+
+    if ("$KEY" == "M") 
+	gstar $R$KEY $D$KEY 0.0005 -m
+    end
+    # list images
+    if ("$KEY" == "i") 
+	gimages $R$KEY $D$KEY
+    end
+    if ("$KEY" == "I") 
+	gimages $R$KEY $D$KEY -pix
+    end
+    # turn stars on / off
+    if ("$KEY" == "S")
+      $DSTARS = $DSTARS * -1
+      if (($ZOOM > 20) && ($DSTARS == 1))
+       style -pt 7
+       pmeasure -all -m $MAG {$MAG + $dMAG}
+      end
+    end
+    # plot light-curve interactive
+    if ("$KEY" == "t")
+      style -n 1 -pt 2 -x 2
+      clear
+      if ($R$KEY < 0) 
+       $R$KEY = $R$KEY + 360
+      end
+      lcurve -l $R$KEY $D$KEY {30/3600} -d -v time mag
+      box
+      lcv
+      style -n 0
+    end
+    # plot light-curve 
+    if ("$KEY" == "T")
+      style -n 1 -pt 1 -c red -x 2
+      lcurve $R$KEY $D$KEY {30/3600} -d
+      style -c black
+      style -n 0 
+    end
+    # plot catalogs
+    if ("$KEY" == "c")
+      style -c blue; pcat; style -c black
+    end
+    # list catalogs
+    if ("$KEY" == "C")
+      gcat $R$KEY $D$KEY
+    end
+
+    # plot image chisqs
+    if ("$KEY" == "x") 
+       gcat $R$KEY $D$KEY
+       extract $CATNAME Xm -photcode R
+       extract $CATNAME ra
+       extract $CATNAME dec
+       style -x 2 -pt 7 -c blue
+       czplot ra dec Xm 3 30
+       style -c black -pt 1
+    end
+    # plot meas errors
+    if ("$KEY" == "X") 
+       gcat $R$KEY $D$KEY
+       extract $CATNAME dM -photcode R
+       extract $CATNAME ra
+       extract $CATNAME dec
+       style -x 2 -pt 7 -c red
+       czplot ra dec dM 0 30
+       style -c black -pt 1
+    end
+    # temp plot for skyprobe
+    if ("$KEY" == "u") 
+      imextract -region time
+      imextract -region mcal
+      imextract -region airmass
+      imextract -region nstar
+      vstat time
+      clear -n 1;
+      section a 0 0.00 1 0.33
+      lim {$MEDIAN-0.3} {$MEDIAN+0.3} -0.8 -0.5; box; plot time mcal
+      section b 0 0.33 1 0.33
+      lim {$MEDIAN-0.3} {$MEDIAN+0.3}  0.95 3.0; box; plot time airmass
+      section c 0 0.66 1 0.33
+      lim {$MEDIAN-0.3} {$MEDIAN+0.3} 0 3000; box; plot time nstar
+      style -n 0
+    end
+    if ("$KEY" == "s")
+      $tmp = $R$KEY
+      if ($tmp < 0) 
+        $tmp = $R$KEY + 360.0
+      end
+      $line = `echo $tmp $D$KEY | radec -hh`
+      imextract -region photcode
+      imextract -region time
+     
+      subset t = time if (int(photcode/100) == 1)
+      uniq t T
+      $Bn = t[]
+      $BN = T[]
+      
+      subset t = time if (int(photcode/100) == 2)
+      uniq t T
+      $Vn = t[]
+      $VN = T[]
+      
+      subset t = time if (int(photcode/100) == 3)
+      uniq t T
+      $Rn = t[]
+      $RN = T[]
+      
+      subset t = time if (int(photcode/100) == 4)
+      uniq t T
+      $In = t[]
+      $IN = T[]
+     
+      echo "$line  $Bn $BN  $Vn $VN  $Rn $RN  $In $IN"
+    end
+
+    if ("$KEY" == "p") 
+      echo "P - new coords; p - old coords"
+      cursor -g 1
+      exec echo $Rp $Dp $RP $DP >> fix.coords
+    end
+
+    if ("$KEY" == "y")
+      ccd I - 2MASS_J : 2MASS_J - 2MASS_K
+      lim -n 1 -1 10 -1 3; clear; box; plot -x 2 -pt 2 -sz 0.5 xv yv
+      dev -n 0 -g
+    end
+  end
+end
+
Index: /trunk/Ohana/doc/www/html/DVO/photcodes.htm
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/photcodes.htm	(revision 5144)
+++ /trunk/Ohana/doc/www/html/DVO/photcodes.htm	(revision 5144)
@@ -0,0 +1,30 @@
+<meta name=file  content=photcodes>
+<meta name=title content=photcodes>
+<meta name=page  content=photcodes>
+
+<p>
+The DVO photcodes define a photometric system, consisting of a
+detector, a filter, and a telescope.  
+
+<p>
+Many DVO commands which accept a photcode as an argument allow for
+the photcode name to be appended with a modifier which changes
+slightly the type of magnitude returned to the user.  
+
+<p>
+The type of photcode is
+specified by adding :type to a photcode.  Valid types consist of:
+<ul>
+<li> inst : instrumental magnitude
+<li>  cat : catalog magnitude = inst + nominal ZP
+<li>  sys : system magnitude = color + airmass corrected mag
+<li>  rel : relative magnitude = applies color, airmass, and relative magnitude offset
+corrections
+<li>  cal : calibrated magnitude : applies zero-point and color
+terms from dependent to primary/secondary magnitude system)
+<li>  ref : reference system
+</ul>
+
+<p>
+<em>This page needs serious work to clarify the meaning of a photcode,
+and the selection criteria </em>
Index: /trunk/Ohana/doc/www/html/DVO/relphot.htm
===================================================================
--- /trunk/Ohana/doc/www/html/DVO/relphot.htm	(revision 5143)
+++ /trunk/Ohana/doc/www/html/DVO/relphot.htm	(revision 5144)
@@ -0,0 +1,224 @@
+
+<h2> relphot outline </h2>
+
+<ul>
+<li> load data
+     <ul>
+     <li> images: match photcode and time range, reset flags
+     <li> measure: select subset matching restritions on:
+          photcode, time, dM, Minst, Mag, dophot == 1
+     </ul>
+<li> iterate to find Mcal, image.flags:
+<li> write out modified Mcal values to image table
+<li> write out modified Mcal values to measure table
+<li> write out modified Mrel values to average table
+</ul>
+
+<h2> relphot overview </h2>
+
+<p> relphot has two primary purposes:<br>
+<ul>
+<li> calculate <b>Mcal</b> for images / measures
+<li> calculate <b>Mrel</b> for stars
+</ul>
+
+<p> relphot can also be used to determine the mosaic grid used to generate
+photometrically corrected flats (-grid option).
+
+<h2> data exclusion </h2>
+
+<p> relphot uses only a subset of the photometry data to calculate
+Mcal and Mrel.  In the first stage, calculation of the Mcal values,
+relphot loads the photometry data from each relevant catalog and
+creates an internal subset catalog with the function
+<em>bcatalog</em>, excluding some of the irrelevant data.  In
+addition, it uses flags to mark some of the data as invalid for the
+processing.
+
+<b> bcatalog exclusions </b>
+<ul>
+<li> measure.photcode not equivalent to requested photcode
+<li> measure.dophot != 1
+<li> measure.Mcat > MAG_LIM
+<li> measure.dM > SIGMA_LIM
+<li> measure.Minst out of range (ImagMin - ImagMax) [optional]
+<li> measure.t out of range (TSTART, TSTOP)
+</ul>
+
+<b> flagged data </b>
+
+<b> flagged image data </b>
+
+images can be flagged by setting bits of <b>image.code</b>
+
+stars can be flagged by setting bits of <b>average.code</b>
+
+measures can be flagged by setting bits of <b>measure.flag</b>
+
+<b>image.code</b>
+
+ID_IMAGE_NOCAL : ignore, irrelevant
+ID_IMAGE_POOR  : image measured bad
+ID_IMAGE_SKIP  : externally known bad
+
+dMcal > VALUE       FLAG_IMAGE_SCATTER <em>clean_images</em>
+fabs(Mcal) > VALUE  FLAG_IMAGE_ZEROPT  <em>clean_images</em>
+
+dMcal > VALUE       FLAG_IMAGE_SCATTER <em>clean_mosaics</em>
+fabs(Mcal) > VALUE  FLAG_IMAGE_ZEROPT  <em>clean_mosaics</em>
+
+<em> mark_images </em> does not seem to do anything useful?
+
+<b>average.code</b>
+
+Ngood < MEAS_TOOFEW                     <em>setMrel</em>
+Ngood < MEAS_TOOFEW                     <em>clean_measures</em>
+ChiSq > STAR_CHISQ                      <em>clean_stars</em>
+dM    > STAR_SCATTER                    <em>clean_stars</em>
+
+average.code (STAR_BAD) is not saved by relphot: it is set by
+clean_stars, clean_measures, and setMrel, but not setMrelOutput.
+STAR_BAD should only be internal since it depends on the photcode, but
+is not associated with a specific photcode in the data.  Just in case,
+it is reset to 0 in setMrelFinal.
+
+<b>measure.flag</b>
+
+X,Y out of range                        <em>setExclusions</em>
+3 sigma clipping                        <em>clean_measures</em>
+
+<h2> setting Mrel final value </h2>
+
+setMrelFinal is used to set the final average.Mrel values.  We do this
+in 4 stages.  In each stage, we set the Mrel values for stars which
+have not already been set, based on the current exclusion settings.
+At successive stages, we relax the exclusions, allowing the more
+spurious objects to have a valid Mrel value to be set.  In this loop,
+we actually run setMrelOutput twice: once to get the approximate Mrel
+value, then we flag the outlier measurements with clean_measure,
+then we redetermine the Mrel values on this basis, and mark the stars
+for exclusion from the next iteration.  
+
+<pre>
+exclude on
+ photcode       0 1 2 3
+ time range     0 1 2 3
+ MEAS_POOR      0 1 2 3
+ MEAS_TOOFEW    0 1 2 3
+ dophot == 10   0 1 2 
+ inst mag       0 1 2 
+ dophot != 1,2  0 1  
+ ID_IMAGE_POOR  0 1
+ ID_IMAGE_SKIP  0 1
+ dophot != 1    0
+ measure.dM     0 
+</pre>
+
+for all relphot runs, Mrel is re-calculated, and measures are marked
+at least if they are outliers in mag or ccd area.
+
+setMrel.output needs to do a few things differently from setMrel:
+<ul>
+<li> set measure.Mcal (skipped in setMrel.basic)
+<li> set average.Mrel if N < TOO_FEW (not STAR_BAD) (optional!)
+<li> use MAX (stats.error, stats.sigma) (optionally)
+<li> allow STAR_BAD?
+</ul>
+
+<h2> imphotset </h2>
+
+imphotset allows you to set certain phot.image table entries.  here
+are the options:
+
+imphotset [-photcode code] [-name foo] [-trange (start) (stop)] -flag and value
+
+
+Here is a complete list of relphot configuration variable names, a
+quick description, and reasonable values to start with:
+
+<pre>
+--- configuration variables used by relphot ---
+MAG_LIM : float
+  ignore measurements fainter than this absolute magnitude
+
+SIGMA_LIM : float
+  ignore measurements with magnitude error larger than this value
+
+STAR_SCATTER : float
+  mark stars as bad if their scatter is larger than this value
+
+IMAGE_SCATTER : float
+  mark images as bad if their scatter is larger than this value
+
+IMAGE_OFFSET : float
+  mark images as bad if the absolute value of thie zero point offset
+  is larger than this number
+
+STAR_CHISQ : float
+  mark stars as variable if their reduced chisq are larger than this value
+
+STAR_TOOFEW : int
+  mark stars as bad if the have fewer than this number of valid measurements
+
+IMAGE_TOOFEW : int
+  mark images as bad if the have fewer than this number of valid measurements
+
+IMAGE_GOOD_FRACTION : float
+  mark images as bad if the have fewer than this fraction of valid measurements  
+
+IMAGE_CATALOG : string
+  name of the image catalog file
+
+IMAGE_CATALOG_TEMPLATE : string
+  name of the template file to create the image catalog file
+
+CATALOG_TEMPLATE : string
+  name of the template file to create the catalog file
+
+GSCFILE : string
+  name of the GSC region table
+
+CATDIR : string
+  directory where the database is stored
+
+PHOTCODE_FILE : string
+  file containing photometry code information
+
+ZERO_PT : float
+  default zero point for random data
+
+RELPHOT_GRID_X : int
+  scale of mosaic correction grid 
+
+RELPHOT_GRID_Y : int
+  scale of mosaic correction grid 
+
+RELPHOT_GRID_BINNING : int
+  deprecated
+
+CAMERA_CONFIG : string
+  name of the file containing descriptive information about the camera
+
+--- sample ConfigFile entries with typical values ---
+
+MAG_LIM                	 24.0
+SIGMA_LIM              	  0.05
+STAR_SCATTER           	  0.05
+IMAGE_SCATTER          	  0.05
+IMAGE_OFFSET           	  0.2
+STAR_CHISQ             	 10.0
+STAR_TOOFEW            	  3
+IMAGE_TOOFEW           	 10
+IMAGE_GOOD_FRACTION    	 
+IMAGE_CATALOG          	 $CATDIR/Images.dat
+IMAGE_CATALOG_TEMPLATE 	 $REFSDIR/elixir/template.cat
+CATALOG_TEMPLATE       	 $REFSDIR/elixir/template.cat
+GSCFILE                	 $REFSDIR/gsc/GSCregions.tbl
+CATDIR                 	 $CATDIR
+PHOTCODE_FILE          	 $CONFDIR/camera/$CAMERA.photcode
+ZERO_PT                	 25.0
+RELPHOT_GRID_X         	 4
+RELPHOT_GRID_Y         	 8
+RELPHOT_GRID_BINNING   	 512
+CAMERA_CONFIG          	 $CONFDIR/camera/$CAMERA.config
+</pre>
Index: /trunk/Ohana/doc/www/html/Elixir-Tools/mosastro.htm
===================================================================
--- /trunk/Ohana/doc/www/html/Elixir-Tools/mosastro.htm	(revision 5143)
+++ /trunk/Ohana/doc/www/html/Elixir-Tools/mosastro.htm	(revision 5144)
@@ -157,13 +157,14 @@
 values are <tt>GSC, USNO, 2MASS, PTOLEMY, STONE</tt>.  
 
-<li> USNO_CDROM  : directory where USNO data is stored
-<li> STONE_DIR  : location of the Stone et al reference data
-<li> 2MASS_DIR  : location of the 2MASS data 
-<li> CATDIR  : location of the ptolemy data
-<li> GSCDIR  : location of the HST Guide Star Catalog
-<li> GSCFILE  : location of the GSC layout file (for GSC and ptolemy)
+<li> GSCDIR      : location of the HST Guide Star Catalog
+<li> USNO_CDROM  : location of the USNO-A data
+<li> STONE_DIR   : location of the Stone et al reference data
+<li> 2MASS_DIR   : location of the 2MASS data 
+<li> CATDIR      : location of the ptolemy data
+<li> GSCFILE     : location of the GSC layout file (for GSC and ptolemy)
 
 note that 'ptolemy' refers to data using the DVO format.  2MASS data
-must be in a DVO format database.
+must be in a DVO format database.  USNO and GSC are both loaded from
+their idiosyncratic formats.  
 
 <li> RADIUS  : matching radius in arcsec to select reference stars
@@ -178,11 +179,2 @@
 systematic error limit.
 </ul>
- 
-</pre>
-
-
-
-
-
-
-
Index: /trunk/Ohana/doc/www/html/download.htm
===================================================================
--- /trunk/Ohana/doc/www/html/download.htm	(revision 5143)
+++ /trunk/Ohana/doc/www/html/download.htm	(revision 5144)
@@ -40,4 +40,5 @@
 
 <ul>
+<li><a href=download/tarballs/elixir-ohana-head.tgz>elixir-ohana-head.tgz </a>
 <li><a href=download/tarballs/elixir-ohana-1.3.tgz>elixir-ohana-1.3.tgz </a>
 <li><a href=download/tarballs/elixir-ohana-1.2.tgz>elixir-ohana-1.2.tgz </a>
Index: /trunk/Ohana/etc/distributions/elixir-ohana-head.dst
===================================================================
--- /trunk/Ohana/etc/distributions/elixir-ohana-head.dst	(revision 5143)
+++ /trunk/Ohana/etc/distributions/elixir-ohana-head.dst	(revision 5144)
@@ -10,4 +10,5 @@
  USE elixir
  USE gastro
+ USE gastro2
  USE gcompare
  USE gophot
Index: unk/Ohana/src/addstar/doc/database.txt
===================================================================
--- /trunk/Ohana/src/addstar/doc/database.txt	(revision 5143)
+++ 	(revision )
@@ -1,91 +1,0 @@
-
-\begin{verbatim}
-
-typedef struct {
-  float R;                    /* RA  in decimal degrees */
-  float D;                    /* DEC in decimal degrees */
-  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
-  unsigned short int Nm;      /* number of measurements */
-  unsigned short int Xp, Xm;  /* chisq values in tenths */
-  unsigned int offset;        /* offset to first Measure-ment */
-} Average;                    /* = 20 bytes / average */
-
-typedef struct {
-  char dR, dD;                /* tenths of arcsec (-12.7 to +12.7 valid range) */
-  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
-  unsigned char dM;           /* thousandths of mag (0.000 -- 0.255 valid range) */
-  float t;                    /* time in seconds (what is reference?) */
-  unsigned int average;       /* reference to corresponding Average entry, 
-				 upper byte of value contains flags.
-				 limit of 16,777,215 stars (Naverage) 
-				 in a file (=0xFFFFFF).
-				 flags = average & 0x1000000 */
-} Measure;                    /* = 13 bytes / measure */
-
-# define BLEND_IMAGE   0X01000000
-# define BLEND_CATALOG 0X02000000
-# define UPPER_LIMIT   0X04000000
-# define CALIBRATED    0X08000000
-
-\end{verbatim}
-
-The above two structures define the entries in the photometry
-database.  The database consists of a large number of files
-representing a small patch on the sky (roughly 1.5 degree$^2$ in most
-places).  These files are organized into directories representing
-bands of Declination.  A reference file determines the coordinate
-boundaries for each of the files so that a given point on the sky can
-unambiguously be associated with a specific file in a specific
-directory.  The sky coordinates for each file is the same as those
-used by the HST Guide Star catalog, except for the region around the
-North celestial pole, for which all stars are included in a single
-file.  
-
-Within a given file, the data are stored in a binary format, with an
-ASCII FITS-like header.  The header is examply in the format of a
-normal FITS header, but with the exception that all files have a fixed
-number of header blocks (for now 3 blocks = 8640 bytes).  This is done
-to speed loading the header and finding the beginning of the binary
-data.  The number of 3 blocks seems quite generous, as currently only
-a few FITS keywords have been defined for each file, basically
-keywords to define the number of stars and the total number of
-measurements stored in the file, as well as values to define the RA
-and DEC range of the file.  
-
-The first section of data following the header blocks consists of
-average measurements for each uniquely observed star.  Each star
-occupies 20 bytes, the size of the Average structure defined above.
-The Average structure contains the average Ra, Dec, and Magnitude for
-the star, as well as the number of measurements, and \chisq\ values
-for the magnitude and position.  Finally, there is a 32 bit integer
-which defines the offset to the first measurement for this star.  This
-offset is defined as the number of Measure records from the start of
-the Measure structure.
-
-The second section of data, following the Average data contains all
-measurements for each star listed in Average.  Each measurement
-occupies 13 bytes, the size of the Measure structure.  This structure
-contains the difference of this position from the average RA and DEC,
-and the instrumental magnitude of this measurement (in the units
-defined by the fstat program, which give m = -2.5*log(cts) + Mo, where
-Mo is currently 24.5 [10/15]).  There is also the magnitude error for
-this measurement, the time of the measurement (in seconds relative to
-a to-be-determined zero point), and a reference to the entry in the
-Average structure so we can relate a given measurement with a given star.
-This last entry also includes a byte of flags, of which only 4 have
-currently been defined.  This means the Average offset can only be as
-large as  16,777,215 (0xffffff), limiting the possible number of stars
-allowed in a given file.  This does not seem like a long term problem,
-though:  aside from the fact that this number is very large and we
-only expect in the vicinity of 20,000 stars per file, the file can
-easily be divided into pieces at a later date if needed.  this last
-step is trivial, consisting of splitting the data up into smaller
-RA,DEC regions, and updating the reference catalog.  With the above
-definitions for the Average and Measure structures, we will typically
-expect 20,000 * 15 measurements per year and 20,000 average entries in
-a given file.  This implies a file size of about 4.3 MB at the end of
-a year.  It is also possible that we will choose to split the files up
-in the future if the number of measurements makes their size
-unweildy.  4.3 MB is sufficiently small that this is not a problem,
-but after only 5 years, the files will be over 21 MB each, getting to
-be fairly significant.  
Index: unk/Ohana/src/addstar/doc/description.txt
===================================================================
--- /trunk/Ohana/src/addstar/doc/description.txt	(revision 5143)
+++ 	(revision )
@@ -1,94 +1,0 @@
-
-ADDSTAR:
-
-This program takes a photometry file, with astrometry, provided by
-earlier routines and incorporates the stellar measurements into the
-photometry database.  This routine does NOT try to calibrate or check
-the photometry, nor does it try to improve the coordinate
-determinations or calculate chisquares for position or photometry -
-those tasks are performed by other routines.
-
-Addstar starts by loading in the photometry file and converting the
-pixel coordinates to sky coordinates using the astrometry information
-in the header of the file.  It also gets the detection limits and
-stores the image astrometry information.
-
-Next, addstar determines which of all the previous images overlaps
-with this image and also which of the catalog regions overlaps with
-this image.
-
-Addstar considers each catalog region in turn, and compares the
-positions of stars in the catalog with stars in the image.  If a
-catalog star is detected, a new measurement is added to the catalog.
-If a catalog star is not detected, but is in the field of view of this
-image, the detection limit for this image is added to the list of
-measurements as an upper limit.  If the image contains a star which is
-not already included in the catalog, the star is added to the catalog,
-and all previous images are checked to see if they included this
-location.  If so, upper limits are added to the list of measurements.
-
-To deal with blended images, we have taken the philosophy that all
-measurements compatible with the coordinates of a given star should be
-included in the list of measurements.  This assumes that programs or people
-downstream will figure out which is the "correct" measurement.  To
-this end, if a catalog star is consistent with multiple measurements,
-they are all added to the catalog measurement and the measurements are
-given a flag to say that there was blending in the catalog (ie, it is
-probably the catalog star which is a blend).  If multiple catalog
-stars are consistent with the same image star, that measurement is
-added to each catalog star, and given a flag to say that there was
-blending on the image.
-
-After all catalogs have been checked, updated, and written to disk,
-the image is added to the database of images.
-
-The format for a catalog region file is as follows:
-
--- 
-Header
---
-Averages
---
-Measurements
---
-
-The Header follows the format of a FITS header but always stored with
-3 blocks to speed up read time: 2880 x 3 bytes.  Two important
-keywords in the header: NSTARS & NMEAS
-
-All average values are stored consecutively in a single block.  They
-are written as an array with NSTARS elements of the Average structure
-defined below.  The individual measurements follow the averages as a
-block.  To find a measurement for a given star, you need to get the
-value of the offset for the star.  this is the element number for the
-first measurement of this star, and are followed by next measurements
-for this star, until the value Nm is reached.
-
-Here are the structures being used for the average and measurement
-values:
-
-typedef struct {
-  float R;                    /* RA  in decimal degrees */
-  float D;                    /* DEC in decimal degrees */
-  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
-  unsigned short int Nm;      /* number of measurements */
-  unsigned short int Xp, Xm;  /* chisq values in tenths */
-  unsigned int offset;        /* offset to first measurement */
-} Average;                    /* = 20 bytes / average */
-
-typedef struct {
-  char dR, dD;                /* tenths of arcsec (-12.7 to +12.7 valid range) */
-  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
-  unsigned char dM;           /* thousandths of mag (0.000 -- 0.255 valid range) */
-  float t;                    /* time in seconds (what is reference?) */
-  unsigned int average;       
-  /* reference to corresponding average entry, upper byte stores flags:
-   limit of 16,777,215 stars (Naverage) in a file (=0xFFFFFF) 
-   flags: average & 0x1000000 */
-} Measure;                    /* = 13 bytes / measure */
-
-/* flags for measurements: */
-# define BLEND_IMAGE   0X01000000
-# define BLEND_CATALOG 0X02000000
-# define UPPER_LIMIT   0X04000000
-# define CALIBRATED    0X08000000
Index: unk/Ohana/src/addstar/doc/merge.txt
===================================================================
--- /trunk/Ohana/src/addstar/doc/merge.txt	(revision 5143)
+++ 	(revision )
@@ -1,30 +1,0 @@
-
-the goal of this project is to merge the functionality of the four
-addstar-like programs in DVO: addstar, addrefs, addspphot, addusno.  
-
-files which are identical or could be in all four:
-
-addstar/src/aregion.c
-addstar/src/addstar.c
-addstar/src/args.c
-addstar/src/calibrate.c
-addstar/src/check_permissions.c
-addstar/src/ConfigInit.c
-addstar/src/find_matches.c
-addstar/src/gcatalog.c
-addstar/src/gimages.c
-addstar/src/gregions.c
-addstar/src/gstars.c
-addstar/src/mkcatalog.c
-addstar/src/parse_time.c
-addstar/src/sort_lists.c
-addstar/src/wcatalog.c
-addstar/src/wimage.c
-
-files to watch:
-[eugene@kawelu src]$ ll addstar/src/
--rw-rw-r--    1 eugene   eugene       3658 Nov 24 14:13 calibrate.c
-
-[eugene@kawelu src]$ ll addspphot/src/
-total 116
--rw-rw-r--    1 eugene   eugene       4480 Nov 24 15:18 calibrate.c
Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 5143)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 5144)
@@ -74,4 +74,5 @@
 int    XMIN, XMAX, YMIN, YMAX;
 int    ACCEPT_ASTROM;
+int    TEXTMODE;
 
 PhotCode *thiscode;
Index: /trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 5143)
+++ /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 5144)
@@ -35,6 +35,4 @@
 
   ScanConfig (config, "IMAGE_CATALOG",          "%s",  0, ImageCat);
-  ScanConfig (config, "IMAGE_CATALOG_TEMPLATE", "%s",  0, ImageTemplate);
-  ScanConfig (config, "CATALOG_TEMPLATE",       "%s",  0, CatTemplate);
   ScanConfig (config, "GSCFILE",                "%s",  0, GSCFILE);
   ScanConfig (config, "CATDIR",                 "%s",  0, CATDIR);
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 5143)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 5144)
@@ -183,4 +183,10 @@
     remove_argument (N, &argc, argv);
   }
+  /* force read of image database with mismatched NSTARS & size */ 
+  TEXTMODE = FALSE;
+  if ((N = get_argument (argc, argv, "-textmode"))) {
+    TEXTMODE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
   /* extra error messages */
   VERBOSE = FALSE;
Index: /trunk/Ohana/src/addstar/src/gstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gstars.c	(revision 5143)
+++ /trunk/Ohana/src/addstar/src/gstars.c	(revision 5144)
@@ -166,8 +166,12 @@
   extend = FALSE;
   fits_scan (&header, "EXTEND",  "%t", 1, &extend);
-  if (extend) {
+  if (extend && !TEXTMODE) {
     Nbytes = fits_matrix_size (&header);
     fseek (f, Nbytes, SEEK_CUR); 
     rdstars = rfits (f, &image[0].nstar);
+    if (rdstars == NULL) {
+      fprintf (stderr, "ERROR: failed to read fits table\n");
+      exit (1);
+    }
   } else {
     /* allocate space for stars */
Index: /trunk/Ohana/src/imregister/src/photcode.c
===================================================================
--- /trunk/Ohana/src/imregister/src/photcode.c	(revision 5143)
+++ /trunk/Ohana/src/imregister/src/photcode.c	(revision 5144)
@@ -1,4 +1,4 @@
 # include "imregister.h"
-static char *version = "photcode $Revision: 3.1 $";
+static char *version = "photcode $Revision: 3.2 $";
 
 int main (int argc, char **argv) {
@@ -61,5 +61,5 @@
   }
   if (ccd == -1) {
-    fprintf (stderr, "warning: ccd %s not found in camera config file\n", ID);
+    fprintf (stderr, "warning: ccd %s not found in camera config file\n", ccd);
     ccd = 0;
   }
Index: /trunk/Ohana/src/libohana/src/LoadPhotcodes.c
===================================================================
--- /trunk/Ohana/src/libohana/src/LoadPhotcodes.c	(revision 5143)
+++ /trunk/Ohana/src/libohana/src/LoadPhotcodes.c	(revision 5144)
@@ -485,5 +485,5 @@
 
   int Np;
-  short M;
+  float M;
 
   Np = photcodes[0].hashcode[measure[0].source];
@@ -672,5 +672,5 @@
 
   int i, Ns;
-  short Mave, Mref, Mcol, mc;
+  float Mave, Mref, Mcol, mc;
   double Mc;
 
@@ -697,5 +697,5 @@
 
   int Ns;
-  short Mave;
+  float Mave;
 
   Ns = photcodes[0].hashNsec[code[0].code];
@@ -708,5 +708,5 @@
 
   int Ns;
-  short dM;
+  float dM;
 
   Ns = photcodes[0].hashNsec[code[0].code];
Index: /trunk/Ohana/src/opihi/dvo/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/dvo/Makefile	(revision 5143)
+++ /trunk/Ohana/src/opihi/dvo/Makefile	(revision 5144)
@@ -28,4 +28,5 @@
 $(SDIR)/ImageSelection.$(ARCH).o	\
 $(SDIR)/LoadImages.$(ARCH).o		\
+$(SDIR)/cmpRead.$(ARCH).o		\
 $(SDIR)/aregion.$(ARCH).o               \
 $(SDIR)/compare.$(ARCH).o               \
Index: /trunk/Ohana/src/opihi/dvo/cmpread.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/cmpread.c	(revision 5143)
+++ /trunk/Ohana/src/opihi/dvo/cmpread.c	(revision 5144)
@@ -1,67 +1,61 @@
 # include "dvo1.h"
-# define D_NSTARS 1000
-# define BYTES_STAR 66
-# define BLOCK 1000
+
+/* add others as needed */
+enum {F_NONE, F_RA, F_DEC, F_X, F_Y, F_MAG, F_DMAG, F_TYPE, F_SKY, F_FX, F_FY, F_APMAG, F_GALMAG};
 
 int cmpread (int argc, char **argv) {
   
-  int i, nstar, Nin, Nextra;
-  int doneread, done, Nskip, Nbytes, nbytes, Ninstar, RAnDEC;
-  char *c, *c2, *name, *file;
-  float *R, *D, *V;
-  double tR, tD, tmp, X, Y;
+  int i, field, extend, Nbytes, Nstars;
+  double tR, tD;
+  float value;
   FILE *f;
-  char *buffer;
-  int Nfield, Nra, Ndec;
-  Vector *rvec, *dvec, *vec;
+  Vector *vec;
   Header header;
   Coords coords;
+  CMPstars *stars;
 
-  if ((argc != 4) && (argc != 6)) {
-    fprintf (stderr, "USAGE: cmpread name Nfield <filename>\n");
-    fprintf (stderr, "USAGE: cmpread ra N dec N <filename>\n");
+  if (argc != 3) {
+    fprintf (stderr, "USAGE: cmpread field <filename>\n");
     return (FALSE);
   }
 
-  R = D = V = NULL;
-  file = NULL;
-  name = NULL;
-  Nfield = Nra = Ndec = 0;
-  RAnDEC = FALSE;
-
-  if (argc == 4) {
-    name = strcreate (argv[1]);
-    Nfield = atof (argv[2]);
-    file = strcreate (argv[3]);
-    RAnDEC = FALSE;
-  } else {
-    Nra  = atof (argv[2]);
-    Ndec = atof (argv[4]);
-    file = strcreate (argv[5]);
-    RAnDEC = TRUE;
-  }    
-
-  if (!fits_read_header (file, &header)) {
-    fprintf (stderr, "ERROR: can't read header for %s\n", file);
-    free (file);
-    if (!RAnDEC) free (name);
+  field = F_NONE;
+  if (!strcasecmp (argv[1], "ra"))   field = F_RA;
+  if (!strcasecmp (argv[1], "dec"))  field = F_DEC;
+  if (!strcasecmp (argv[1], "mag"))  field = F_MAG;
+  if (!strcasecmp (argv[1], "dmag")) field = F_DMAG;
+  if (!strcasecmp (argv[1], "x"))    field = F_X;
+  if (!strcasecmp (argv[1], "y"))    field = F_Y;
+  if (!strcasecmp (argv[1], "type")) field = F_TYPE;
+  if (!strcasecmp (argv[1], "sky"))  field = F_SKY;
+  if (!strcasecmp (argv[1], "fx"))   field = F_FX;
+  if (!strcasecmp (argv[1], "fy"))   field = F_FY;
+  if (!strcasecmp (argv[1], "apmag"))  field = F_APMAG;
+  if (!strcasecmp (argv[1], "galmag"))  field = F_GALMAG;
+  if (field == F_NONE) {
+    fprintf (stderr, "invalid cmp field: %s\n", argv[1]);
     return (FALSE);
   }
 
-  /* find expected number of stars */
-  fits_scan (&header, "NSTARS", "%d", 1, &nstar);
-  if (nstar == 0) {
-    fprintf (stderr, "ERROR: can't get NSTARS from header\n");
-    free (file);
-    if (!RAnDEC) free (name);
-    fits_free_header (&header);
+  if ((vec = SelectVector (argv[1],  ANYVECTOR, TRUE)) == NULL) return (FALSE);
+
+  /* load FITS header */
+  if (!fits_read_header (argv[2], &header)) {
+    fprintf (stderr, "ERROR: can't read header for %s\n", argv[2]);
     return (FALSE);
   }
 
-  f = fopen (file, "r");
+  if ((field == F_RA) || (field == F_DEC)) {
+    if (!GetCoords (&coords, &header)) {
+      fprintf (stderr, "can't get WCS info from header\n");
+      fits_free_header (&header);
+      return (FALSE);
+    }
+  }
+
+  /* re-open file to load data */
+  f = fopen (argv[2], "r");
   if (f == NULL) {
-    fprintf (stderr, "ERROR: can't read data from %s\n", file);
-    free (file);
-    if (!RAnDEC) free (name);
+    fprintf (stderr, "ERROR: can't read data from %s\n", argv[2]);
     fits_free_header (&header);
     return (FALSE);
@@ -69,86 +63,80 @@
   fseek (f, header.size, SEEK_SET); 
 
-  if (RAnDEC) {
-    if ((rvec = SelectVector ("ra",  ANYVECTOR, TRUE)) == NULL) return (FALSE);
-    if ((dvec = SelectVector ("dec",  ANYVECTOR, TRUE)) == NULL) return (FALSE);
-    REALLOCATE (rvec[0].elements, float, nstar);
-    REALLOCATE (dvec[0].elements, float, nstar);
-    R = rvec[0].elements;
-    D = dvec[0].elements;
-    rvec[0].Nelements = dvec[0].Nelements = nstar;
-    if (!GetCoords (&coords, &header)) {
-      fprintf (stderr, "can't get WCS info from header\n");
-      return (FALSE);
-    }
-  } else {
-    if ((vec = SelectVector (name, ANYVECTOR, TRUE)) == NULL) return (FALSE);
-    REALLOCATE (vec[0].elements, float, nstar);
-    V = vec[0].elements;
-    vec[0].Nelements = nstar;
+  /* find expected number of stars */
+  if (!fits_scan (&header, "NSTARS", "%d", 1, &Nstars)) {
+    fprintf (stderr, "ERROR: can't get NSTARS from header\n");
+    fits_free_header (&header);
+    return (FALSE);
   }
 
-  /* load in stars by blocks of 1000 */
-  Nin = 0;
-  ALLOCATE (buffer, char, (BLOCK*BYTES_STAR) + 1);
-  buffer[BLOCK*BYTES_STAR] = 0;
-  Nextra = 0;
-  doneread = FALSE;
-  while (!doneread) {
-    Nbytes = BYTES_STAR * BLOCK - Nextra;
-    nbytes = fread (&buffer[Nextra], 1, Nbytes, f);
-    if (nbytes == 0) {
-      doneread = TRUE;
-      continue;
+  /* read from FITS table or from text table */
+  extend = FALSE;
+  fits_scan (&header, "EXTEND",  "%t", 1, &extend);
+  if (extend) {
+    fprintf (stderr, "reading from FITS cmp file %s\n", argv[2]);
+    Nbytes = fits_matrix_size (&header);
+    fseek (f, Nbytes, SEEK_CUR); 
+    stars = cmpReadFits (f, &Nstars);
+  } else {
+    /* allocate space for stars */
+    fprintf (stderr, "reading from TEXT cmp file %s\n", argv[2]);
+    if (!fits_scan (&header, "NSTARS", "%d", 1, &Nstars)) {
+      fprintf (stderr, "ERROR: failed to find NSTARS\n");
+      exit (1);
     }
-    nbytes += Nextra;
-    /* check line-by-line integrity */
-    c = buffer;
-    done = FALSE;
-    while ((c < buffer + nbytes) && (!done)) { 
-      for (c2 = c; *c2 == '\n'; c2++);
-      if (c2 > c) { /* extra return chars */
-	memmove (c, c2, (int)(buffer + nbytes - c2));
-	Nskip = c2 - c;
-	nbytes -= Nskip;
-	bzero (buffer + nbytes, Nskip);
-      }
-      c2 = strchr (c, '\n');
-      if (c2 == (char *) NULL) {
-	done = TRUE;	
-	continue;
-      }
-      c2++;
-      if ((c2 - c) != BYTES_STAR) { /* bad line, delete it */
-	memmove (c, c2, (int)(buffer + nbytes - c2));
-	Nskip = c2 - c;
-	nbytes -= Nskip;
-	bzero (buffer + nbytes, Nskip);
-      } else {
-	c = c2;
-      }
-    }
-    Ninstar = nbytes / BYTES_STAR;
-    Nextra = nbytes % BYTES_STAR;
-    for (i = 0; i < Ninstar; i++, Nin++) {
-      if (RAnDEC) {
-	dparse (&X, Nra,  &buffer[i*BYTES_STAR]);
-	dparse (&Y, Ndec, &buffer[i*BYTES_STAR]);
-	XY_to_RD (&tR, &tD, X, Y, &coords);
-	R[Nin] = tR; D[Nin] = tD;
-      } else {
-	dparse (&tmp, Nfield, &buffer[i*BYTES_STAR]);
-	V[Nin] = tmp;
-      }
-    }
+    stars = cmpReadText (f, &Nstars);
   }
   fclose (f);
 
+  REALLOCATE (vec[0].elements, float, Nstars);
+  vec[0].Nelements = Nstars;
+  bzero (vec[0].elements, Nstars*sizeof(float));
+
+  for (i = 0; i < Nstars; i++) {
+    switch (field) {
+      case F_RA:
+	XY_to_RD (&tR, &tD, stars[i].X, stars[i].Y, &coords);
+	value = tR;
+	break;
+      case F_DEC:
+	XY_to_RD (&tR, &tD, stars[i].X, stars[i].Y, &coords);
+	value = tD;
+	break;
+      case F_X:
+	value = stars[i].X;
+	break;
+      case F_Y:
+	value = stars[i].Y;
+	break;
+      case F_MAG:
+	value = stars[i].M;
+	break;
+      case F_APMAG:
+	value = stars[i].Map;
+	break;
+      case F_GALMAG:
+	value = stars[i].Mgal;
+	break;
+      case F_DMAG:
+	value = stars[i].dM;
+	break;
+      case F_TYPE:
+	value = stars[i].dophot;
+	break;
+      case F_SKY:
+	value = stars[i].sky;
+	break;
+      case F_FX:
+	value = stars[i].fx;
+	break;
+      case F_FY:
+	value = stars[i].fy;
+	break;
+    }
+    vec[0].elements[i] = value;
+  }      
+  free (stars);
   fits_free_header (&header);
-  free (buffer);
-  free (file);
-  if (!RAnDEC) free (name);
-
-  fprintf (stderr, "loaded %d objects\n", Nin);
+  fprintf (stderr, "loaded %d objects\n", Nstars);
   return (TRUE);
 }
-
Index: /trunk/Ohana/src/opihi/include/dvo1.h
===================================================================
--- /trunk/Ohana/src/opihi/include/dvo1.h	(revision 5143)
+++ /trunk/Ohana/src/opihi/include/dvo1.h	(revision 5144)
@@ -22,4 +22,19 @@
   double RA0, RA1, DEC0, DEC1;
 } RegionFile;
+
+typedef struct {
+  double X;
+  double Y;
+  double R;
+  double D;
+  double M, dM;
+  char   dophot;
+  double sky;
+  double fx, fy, df;
+  double Mgal, Map;
+  int found;
+  short int code;
+  e_time t;
+} CMPstars;
 
 /*** dvo prototypes ***/
@@ -73,4 +88,6 @@
 void          sort_images           PROTO((Image *image, int N));
 void          sortave               PROTO((Average *ave, int N));
+CMPstars *cmpReadFits (FILE *f, int *nstars);
+CMPstars *cmpReadText (FILE *f, int *nstars);
 
 # endif
