Index: /tags/getstar-1-5-0/Ohana/src/getstar/.cvsignore
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/.cvsignore	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/.cvsignore	(revision 13095)
@@ -0,0 +1,1 @@
+bin
Index: /tags/getstar-1-5-0/Ohana/src/getstar/Makefile
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/Makefile	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/Makefile	(revision 13095)
@@ -0,0 +1,70 @@
+default: all
+help:
+	@echo "make options: getstar (default)"
+
+include ../../Makefile.System
+HOME 	=	$(ROOT)/src/getstar
+BIN	=	$(HOME)/bin
+LIB	=	$(HOME)/lib
+SRC	=	$(HOME)/src
+MAN	=	$(HOME)/doc
+INC	= 	$(HOME)/include
+include ../../Makefile.Common
+
+# programs may add their own internal requirements here
+FULL_CFLAGS   = $(BASE_CFLAGS)
+FULL_CPPFLAGS = $(BASE_CPPFLAGS)
+FULL_LDFLAGS  = -ldvo -lFITS -lohana $(BASE_LDFLAGS)
+
+getstar: $(BIN)/getstar.$(ARCH)
+getstar.install: $(DESTBIN)/getstar
+
+dvoImageOverlaps: $(BIN)/dvoImageOverlaps.$(ARCH)
+dvoImageOverlaps.install: $(DESTBIN)/dvoImageOverlaps
+
+dvoImageExtract: $(BIN)/dvoImageExtract.$(ARCH)
+dvoImageExtract.install: $(DESTBIN)/dvoImageExtract
+
+all: getstar dvoImageOverlaps dvoImageExtract
+install: getstar.install dvoImageOverlaps.install dvoImageExtract.install
+
+GETSTAR = \
+$(SRC)/getstar.$(ARCH).o 	 \
+$(SRC)/args.$(ARCH).o		 \
+$(SRC)/ConfigInit.$(ARCH).o 	 \
+$(SRC)/Shutdown.$(ARCH).o	 \
+$(SRC)/SetSignals.$(ARCH).o	 \
+$(SRC)/select_by_region.$(ARCH).o
+
+$(GETSTAR): $(INC)/getstar.h
+$(BIN)/getstar.$(ARCH): $(GETSTAR)
+
+OVERLAPS = \
+$(SRC)/dvoImageOverlaps.$(ARCH).o 	 \
+$(SRC)/args_overlaps.$(ARCH).o		 \
+$(SRC)/ConfigInit_overlaps.$(ARCH).o 	 \
+$(SRC)/Shutdown.$(ARCH).o	         \
+$(SRC)/SetSignals.$(ARCH).o	         \
+$(SRC)/ReadImageFiles.$(ARCH).o          \
+$(SRC)/ReadImageHeader.$(ARCH).o         \
+$(SRC)/ListImageOverlaps.$(ARCH).o       \
+$(SRC)/GetFileMode.$(ARCH).o             \
+$(SRC)/edge_check.$(ARCH).o              \
+$(SRC)/opening_angle.$(ARCH).o           \
+$(SRC)/MatchImages.$(ARCH).o
+
+$(OVERLAPS): $(INC)/dvoImageOverlaps.h
+$(BIN)/dvoImageOverlaps.$(ARCH): $(OVERLAPS)
+
+EXTRACT = \
+$(SRC)/dvoImageExtract.$(ARCH).o 	 \
+$(SRC)/ConfigInit_extract.$(ARCH).o 	 \
+$(SRC)/args_extract.$(ARCH).o		 \
+$(SRC)/Shutdown.$(ARCH).o	         \
+$(SRC)/SetSignals.$(ARCH).o	         \
+$(SRC)/WriteImages.$(ARCH).o             \
+$(SRC)/WriteImageFITS.$(ARCH).o          \
+$(SRC)/SelectImages.$(ARCH).o       
+
+$(EXTRACT): $(INC)/dvoImageExtract.h
+$(BIN)/dvoImageExtract.$(ARCH): $(EXTRACT)
Index: /tags/getstar-1-5-0/Ohana/src/getstar/bin/.cvsignore
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/bin/.cvsignore	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/bin/.cvsignore	(revision 13095)
@@ -0,0 +1,2 @@
+*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
+*.linrh
Index: /tags/getstar-1-5-0/Ohana/src/getstar/doc/ChangeLog.txt
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/doc/ChangeLog.txt	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/doc/ChangeLog.txt	(revision 13095)
@@ -0,0 +1,8 @@
+ getstar-1-2
+  * added maximum magnitude selection
+
+ getstar-1-1
+  * converted to gfits APIs (forces libfits 1.6)
+
+ getstar-1-0
+    basic program, not really tested (not sure why this is tagged)
Index: /tags/getstar-1-5-0/Ohana/src/getstar/doc/database.txt
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/doc/database.txt	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/doc/database.txt	(revision 13095)
@@ -0,0 +1,91 @@
+
+\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: /tags/getstar-1-5-0/Ohana/src/getstar/doc/description.txt
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/doc/description.txt	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/doc/description.txt	(revision 13095)
@@ -0,0 +1,94 @@
+
+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: /tags/getstar-1-5-0/Ohana/src/getstar/etc/phottemp.cat
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/etc/phottemp.cat	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/etc/phottemp.cat	(revision 13095)
@@ -0,0 +1,296 @@
+SIMPLE  =                    F  / ASTROCAM PHOTOMETRY FILE                    \
+BITPIX  =                   16 /                                              \
+NAXIS   =                    2  / NUMBER OF AXES                              \
+NAXIS1  =                 1106  / NUMBER OF COLUMNS                           \
+NAXIS2  =                 1024  / NUMBER OF ROWS                              \
+BSCALE  =             1.000000 /                                              \
+BZERO   =             0.000000 /                                              \
+DATE    = '19/12/94'            / UT Date of file creation (DD/MM/YY)         \
+ORIGIN  = 'MDM Observatory'     / Michigan-Dartmouth-MIT                      \
+LATITUDE=              31.9500  / Latitude (degrees N)                        \
+LONGITUD=            -111.6150  / Longitude (degrees E)                       \
+OBSERVER= 'Metzger '            / Name of observer                            \
+TELESCOP= '1.3m McGraw-Hill'    / Telescope used for observation              \
+INSTRUME= 'Charlotte Direct'    / Instrument used for observation             \
+DETECTOR= 'Charlotte/Tek 1024^2 CCD'  / Detector used for observation         \
+FRAME   =                   32  / Frame number of observation                 \
+CCDPICNO=                   32  / Frame number of observation                 \
+OBJECT  = 'ocl0327 '            / Name of object                              \
+IMAGETYP= 'OBJECT  '            / Type of observation                         \
+EXPTIME =              250.000  / Integration time (seconds)                  \
+DARKTIME=              250.067  / Dark current time (seconds)                 \
+DATE-OBS= '19/12/94'            / UT Date of observation (DD/MM/YY)           \
+UT      = ' 05:25:44.00'        / Universal time (UTC) at exposure start      \
+JD      =       2449705.726204                                                \
+RA      =           50.700      / Right Ascension                             \
+DEC     =           89.000      / Declination                                 \
+DIRECTN =                 -1    / Moving South                                \
+EQUINOX =             1950.000  / Equinox of RA and DEC                       \
+HA      = ' 02:14:06.72'        / Hour angle at start                         \
+ST      = ' 03:49:36.85'        / Sidereal time at start                      \
+ZD      = ' 36:26:07.17'        / Zenith distance (degrees)                   \
+AIRMASS =                1.243  / Airmass at start                            \
+FILTER  = 'I KP    '            / Filter description                          \
+GAIN    =                3.350  / Nominal gain (e-/ADU)                       \
+SECPIX1 =                0.508  / Arcseconds per pixel in fast dir            \
+SECPIX2 =                0.508  / Arcseconds per pixel in slow dir            \
+CCDBIN1 =                    1  / On-chip column binning (fast dir)           \
+CCDBIN2 =                    1  / On-chip row binning (slow dir)              \
+GPROBE  = '  5000.00   7000.00'  / Guide probe X Y                            \
+DATASEC = '[51:1074,1:1024]'    / Image area of frame                         \
+CCDSEC  = '[1:1074,1:1024]'     / Image area relative to full chip            \
+BIASSEC = '[1080:1106,1:1023]'  / Overscan area of frame                      \
+UNSIGN  =                    T /                                              \
+NSTARS  =                    0  / NUMBER OF stars                             \
+CTYPE1  = 'RA---SIN          ' /                                               
+CTYPE2  = 'DEC--SIN          ' /                                               
+CDELT1  =             0.000733 /                                               
+CDELT2  =             0.000733 /                                               
+CRVAL1  =            50.191418 /                                               
+CRVAL2  =            88.998663 /                                               
+CRPIX1  =          1028.644173 /                                               
+CRPIX2  =           503.129830 /                                               
+PC001001=             0.999906 /                                               
+PC001002=             0.012081 /                                               
+PC002001=            -0.011936 /                                               
+PC002002=             0.999950 /                                               
+END                                                                           \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+ 246.5  352.1 13.000 020 1 3.2
+ 246.5  352.1 14.100 020 1 3.2
+ 279.4  328.9 13.800 020 1 3.2
+ 187.3  238.8  9.800 020 1 3.2
+ 187.3  238.8  9.800 020 1 3.2
+ 436.6  413.5 14.300 020 1 3.2
+   9.3  856.5 13.000 020 1 3.2
+   9.3  856.2 13.600 020 1 3.2
+ 319.7  697.9 12.000 020 1 3.2
+ 319.7  697.7 12.100 020 1 3.2
+ 244.3    9.5 14.100 020 1 3.2
+ 284.7  334.4 14.000 020 1 3.2
+ 127.1  122.8 14.200 020 1 3.2
+ 140.2  791.1 13.700 020 1 3.2
+ 140.2  790.8 14.400 020 1 3.2
+ 131.7  636.3 13.800 020 1 3.2
+ 423.8  700.6 13.800 020 1 3.2
+ 423.7  700.7 12.500 020 1 3.2
+ 266.2  290.7 13.800 020 1 3.2
+ 266.0  290.7 13.100 020 1 3.2
+ 570.7  721.6 13.600 020 1 3.2
+ 570.7  721.6 13.100 020 1 3.2
+ 548.7  673.0 13.700 020 1 3.2
+ 264.2  219.7 12.800 020 1 3.2
+ 264.0  219.7 12.100 020 1 3.2
+ 161.9  797.4 11.900 020 1 3.2
+ 162.0  797.2 12.200 020 1 3.2
+ 505.8  851.8 13.700 020 1 3.2
+  88.2  419.0 11.400 020 1 3.2
+  88.2  419.0 11.800 020 1 3.2
+ 426.9  613.2  9.400 020 1 3.2
+ 427.4  613.5  7.600 020 1 3.2
+ 326.1  595.2 12.100 020 1 3.2
+ 326.2  595.1 12.600 020 1 3.2
+ 444.4  845.2 14.200 020 1 3.2
+ 254.1  916.8 14.500 020 1 3.2
+ 502.6  882.4 14.200 020 1 3.2
+ 128.3  275.7 12.300 020 1 3.2
+ 128.3  275.7 12.900 020 1 3.2
+ 230.9  554.8 13.300 020 1 3.2
+ 230.9  554.7 14.200 020 1 3.2
+  47.5  685.2 13.500 020 1 3.2
+  47.5  684.9 14.200 020 1 3.2
+ 382.6  658.7 14.000 020 1 3.2
+ 182.2  330.3 14.200 020 1 3.2
+ 245.1  548.3 12.600 020 1 3.2
+ 245.3  548.0 13.200 020 1 3.2
+  50.3  849.0 13.700 020 1 3.2
+  50.5  848.8 14.300 020 1 3.2
+  17.9  772.7 14.200 020 1 3.2
+ 499.8  712.8 13.500 020 1 3.2
+ 499.8  712.6 14.400 020 1 3.2
+ 294.5  349.4 14.000 020 1 3.2
+ 497.7  747.8 11.000 020 1 3.2
+ 497.5  747.8 10.900 020 1 3.2
+ 109.7  323.5 14.000 020 1 3.2
+  59.5  917.6 14.300 020 1 3.2
+  59.4  917.8 13.700 020 1 3.2
+  82.2  880.5 13.800 020 1 3.2
+ 145.1  341.2 14.500 020 1 3.2
+ 452.7  592.4 14.400 020 1 3.2
+ 623.4  820.0 13.700 020 1 3.2
+ 609.7  829.3 13.500 020 1 3.2
+ 481.8  938.3 14.400 020 1 3.2
+ 617.0  792.7 13.500 020 1 3.2
+ 183.2  539.7 14.400 020 1 3.2
+ 133.9  679.6 14.400 020 1 3.2
+ 423.7  667.8  6.500 020 1 3.2
+ 434.7  111.9 13.200 020 1 3.2
+ 434.5  111.9 13.200 020 1 3.2
+ 434.6  111.9 14.200 020 1 3.2
+1222.3  684.2 13.900 020 1 3.2
+1077.6  282.5 14.000 020 1 3.2
+1077.8  282.5 13.400 020 1 3.2
+ 720.8  562.1 14.100 020 1 3.2
+ 721.1  561.9 14.400 020 1 3.2
+1182.1  944.4 12.100 020 1 3.2
+1181.9  944.4 11.800 020 1 3.2
+1181.9  944.4 12.300 020 1 3.2
+ 761.2  423.1 14.300 020 1 3.2
+ 761.0  423.1 14.100 020 1 3.2
+ 926.7  436.8 13.400 020 1 3.2
+ 926.6  436.8 14.200 020 1 3.2
+1209.1   45.0 13.200 020 1 3.2
+1209.2   43.6 12.800 020 1 3.2
+1135.2  653.1  8.100 020 1 3.2
+1135.6  653.4  8.200 020 1 3.2
+1123.5  735.8 12.000 020 1 3.2
+1123.6  735.8 11.800 020 1 3.2
+1123.7  735.7 11.600 020 1 3.2
+ 730.7   28.6 12.100 020 1 3.2
+ 730.7   28.6 12.200 020 1 3.2
+ 783.1  267.5 14.200 020 1 3.2
+ 783.2  267.5 13.400 020 1 3.2
+ 876.2  462.7 13.800 020 1 3.2
+ 876.4  462.7 14.200 020 1 3.2
+ 917.2  399.9 13.700 020 1 3.2
+ 917.3  399.9 13.200 020 1 3.2
+1227.5  218.4 10.400 020 1 3.2
+1227.7  218.4 10.500 020 1 3.2
+1022.7  146.0 13.300 020 1 3.2
+1022.5  146.0 14.100 020 1 3.2
+1324.7   72.3 12.900 020 1 3.2
+1324.6   72.3 13.200 020 1 3.2
+ 743.2  379.4 14.300 020 1 3.2
+ 742.9  379.4 13.900 020 1 3.2
+1255.9  544.0 12.600 020 1 3.2
+1256.0  543.9 12.300 020 1 3.2
+ 848.9  251.1 13.200 020 1 3.2
+ 849.0  251.1 12.700 020 1 3.2
+ 495.6  147.4 11.400 020 1 3.2
+ 495.6  147.4 11.300 020 1 3.2
+ 495.5  147.4 11.000 020 1 3.2
+1016.4  735.5 14.200 020 1 3.2
+1016.3  735.7 13.900 020 1 3.2
+ 795.2  675.9 14.400 020 1 3.2
+ 887.2  968.8 10.800 020 1 3.2
+ 626.8  726.9 14.400 020 1 3.2
+ 718.6  800.1  9.700 020 1 3.2
+ 675.4  301.6 14.400 020 1 3.2
+ 801.6  436.8 14.200 020 1 3.2
+1066.4  870.0 13.700 020 1 3.2
+1066.5  869.9 13.800 020 1 3.2
+ 644.5  662.9  9.900 020 1 3.2
+ 639.1  760.4 13.000 020 1 3.2
+ 822.7  663.1 12.800 020 1 3.2
+ 822.7  663.1 13.100 020 1 3.2
+ 677.2  716.2 12.900 020 1 3.2
+ 765.6  641.5 13.200 020 1 3.2
+ 765.7  641.4 13.500 020 1 3.2
+ 998.3  425.8 14.400 020 1 3.2
+ 713.7  716.2 13.800 020 1 3.2
+ 814.7  887.6  2.000 020 1 3.2
+ 808.7  884.1  8.200 020 1 3.2
+1812.3  259.3 14.500 020 1 3.2
+1655.9  655.4 12.200 020 1 3.2
+1655.9  655.4 12.100 020 1 3.2
+1577.2  839.6 11.500 020 1 3.2
+1577.2  839.6 11.400 020 1 3.2
+1643.7  597.0 14.100 020 1 3.2
+1552.8  251.1 10.100 020 1 3.2
+1552.8  251.1 10.300 020 1 3.2
+1410.0  999.9 13.900 020 1 3.2
+1335.6  687.0 13.000 020 1 3.2
+1335.8  686.8 12.700 020 1 3.2
+1471.4  262.0 14.200 020 1 3.2
+1479.6  608.3 14.200 020 1 3.2
+1478.1  211.5 12.000 020 1 3.2
+1478.3  211.5 12.000 020 1 3.2
+1552.5   46.4 14.500 020 1 3.2
+2042.4  548.3 10.800 020 1 3.2
+2042.6  548.3 11.000 020 1 3.2
+1448.0  915.7 14.100 020 1 3.2
+1462.3  989.2 13.000 020 1 3.2
+1462.3  989.0 12.700 020 1 3.2
+1316.9  787.3 14.100 020 1 3.2
+1787.6  883.5 12.200 020 1 3.2
+1787.6  883.5 12.200 020 1 3.2
+1979.1  300.3 12.900 020 1 3.2
+1979.1  300.3 12.900 020 1 3.2
+1677.2  106.4 13.100 020 1 3.2
+1677.0  106.4 13.300 020 1 3.2
+1324.2  429.9  9.200 020 1 3.2
+1324.2  429.9  9.000 020 1 3.2
+1462.8  214.3 13.700 020 1 3.2
+1462.8  214.3 14.200 020 1 3.2
+1405.4   95.5 11.700 020 1 3.2
+1405.2   95.5 11.600 020 1 3.2
+1604.8   90.0 11.200 020 1 3.2
+1604.8   90.0 11.300 020 1 3.2
+1921.5  738.1 13.500 020 1 3.2
+1921.5  738.1 13.500 020 1 3.2
+1459.8  473.6 13.400 020 1 3.2
+1459.7  473.6 13.800 020 1 3.2
+1438.7   77.8 12.200 020 1 3.2
+1438.6   77.8 12.200 020 1 3.2
+1355.0  114.6 13.000 020 1 3.2
+1354.9  114.6 13.200 020 1 3.2
+1941.4  940.7 13.000 020 1 3.2
+1941.6  940.7 12.900 020 1 3.2
+1994.0  800.8 13.900 020 1 3.2
+1993.8  800.8 14.000 020 1 3.2
+2024.4  907.0 13.700 020 1 3.2
+2024.4  907.0 13.800 020 1 3.2
+2035.7  881.6 13.900 020 1 3.2
+2035.9  881.6 13.800 020 1 3.2
+1994.0  924.2 12.100 020 1 3.2
+1994.0  924.2 12.000 020 1 3.2
Index: /tags/getstar-1-5-0/Ohana/src/getstar/etc/template.cat
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/etc/template.cat	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/etc/template.cat	(revision 13095)
@@ -0,0 +1,296 @@
+SIMPLE  =                    F  / ASTROCAM PHOTOMETRY FILE                    \
+BITPIX  =                   16 /                                              \
+NAXIS   =                    2  / NUMBER OF AXES                              \
+NAXIS1  =                 1106  / NUMBER OF COLUMNS                           \
+NAXIS2  =                 1024  / NUMBER OF ROWS                              \
+BSCALE  =             1.000000 /                                              \
+BZERO   =             0.000000 /                                              \
+DATE    = '19/12/94'            / UT Date of file creation (DD/MM/YY)         \
+ORIGIN  = 'MDM Observatory'     / Michigan-Dartmouth-MIT                      \
+LATITUDE=              31.9500  / Latitude (degrees N)                        \
+LONGITUD=            -111.6150  / Longitude (degrees E)                       \
+OBSERVER= 'Metzger '            / Name of observer                            \
+TELESCOP= '1.3m McGraw-Hill'    / Telescope used for observation              \
+INSTRUME= 'Charlotte Direct'    / Instrument used for observation             \
+DETECTOR= 'Charlotte/Tek 1024^2 CCD'  / Detector used for observation         \
+FRAME   =                   32  / Frame number of observation                 \
+CCDPICNO=                   32  / Frame number of observation                 \
+OBJECT  = 'ocl0327 '            / Name of object                              \
+IMAGETYP= 'OBJECT  '            / Type of observation                         \
+EXPTIME =              250.000  / Integration time (seconds)                  \
+DARKTIME=              250.067  / Dark current time (seconds)                 \
+DATE-OBS= '19/12/94'            / UT Date of observation (DD/MM/YY)           \
+UT      = ' 05:25:44.00'        / Universal time (UTC) at exposure start      \
+JD      =       2449705.726204                                                \
+RA      =           50.700      / Right Ascension                             \
+DEC     =           89.000      / Declination                                 \
+DIRECTN =                 -1    / Moving South                                \
+EQUINOX =             1950.000  / Equinox of RA and DEC                       \
+HA      = ' 02:14:06.72'        / Hour angle at start                         \
+ST      = ' 03:49:36.85'        / Sidereal time at start                      \
+ZD      = ' 36:26:07.17'        / Zenith distance (degrees)                   \
+AIRMASS =                1.243  / Airmass at start                            \
+FILTER  = 'I KP    '            / Filter description                          \
+GAIN    =                3.350  / Nominal gain (e-/ADU)                       \
+SECPIX1 =                0.508  / Arcseconds per pixel in fast dir            \
+SECPIX2 =                0.508  / Arcseconds per pixel in slow dir            \
+CCDBIN1 =                    1  / On-chip column binning (fast dir)           \
+CCDBIN2 =                    1  / On-chip row binning (slow dir)              \
+GPROBE  = '  5000.00   7000.00'  / Guide probe X Y                            \
+DATASEC = '[51:1074,1:1024]'    / Image area of frame                         \
+CCDSEC  = '[1:1074,1:1024]'     / Image area relative to full chip            \
+BIASSEC = '[1080:1106,1:1023]'  / Overscan area of frame                      \
+UNSIGN  =                    T /                                              \
+NSTARS  =                    0  / NUMBER OF stars                             \
+CTYPE1  = 'RA---SIN          ' /                                               
+CTYPE2  = 'DEC--SIN          ' /                                               
+CDELT1  =             0.000733 /                                               
+CDELT2  =             0.000733 /                                               
+CRVAL1  =            50.191418 /                                               
+CRVAL2  =            88.998663 /                                               
+CRPIX1  =          1028.644173 /                                               
+CRPIX2  =           503.129830 /                                               
+PC001001=             0.999906 /                                               
+PC001002=             0.012081 /                                               
+PC002001=            -0.011936 /                                               
+PC002002=             0.999950 /                                               
+END                                                                           \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+                                                                              \
+ 246.5  352.1 13.000 020 1 3.2
+ 246.5  352.1 14.100 020 1 3.2
+ 279.4  328.9 13.800 020 1 3.2
+ 187.3  238.8  9.800 020 1 3.2
+ 187.3  238.8  9.800 020 1 3.2
+ 436.6  413.5 14.300 020 1 3.2
+   9.3  856.5 13.000 020 1 3.2
+   9.3  856.2 13.600 020 1 3.2
+ 319.7  697.9 12.000 020 1 3.2
+ 319.7  697.7 12.100 020 1 3.2
+ 244.3    9.5 14.100 020 1 3.2
+ 284.7  334.4 14.000 020 1 3.2
+ 127.1  122.8 14.200 020 1 3.2
+ 140.2  791.1 13.700 020 1 3.2
+ 140.2  790.8 14.400 020 1 3.2
+ 131.7  636.3 13.800 020 1 3.2
+ 423.8  700.6 13.800 020 1 3.2
+ 423.7  700.7 12.500 020 1 3.2
+ 266.2  290.7 13.800 020 1 3.2
+ 266.0  290.7 13.100 020 1 3.2
+ 570.7  721.6 13.600 020 1 3.2
+ 570.7  721.6 13.100 020 1 3.2
+ 548.7  673.0 13.700 020 1 3.2
+ 264.2  219.7 12.800 020 1 3.2
+ 264.0  219.7 12.100 020 1 3.2
+ 161.9  797.4 11.900 020 1 3.2
+ 162.0  797.2 12.200 020 1 3.2
+ 505.8  851.8 13.700 020 1 3.2
+  88.2  419.0 11.400 020 1 3.2
+  88.2  419.0 11.800 020 1 3.2
+ 426.9  613.2  9.400 020 1 3.2
+ 427.4  613.5  7.600 020 1 3.2
+ 326.1  595.2 12.100 020 1 3.2
+ 326.2  595.1 12.600 020 1 3.2
+ 444.4  845.2 14.200 020 1 3.2
+ 254.1  916.8 14.500 020 1 3.2
+ 502.6  882.4 14.200 020 1 3.2
+ 128.3  275.7 12.300 020 1 3.2
+ 128.3  275.7 12.900 020 1 3.2
+ 230.9  554.8 13.300 020 1 3.2
+ 230.9  554.7 14.200 020 1 3.2
+  47.5  685.2 13.500 020 1 3.2
+  47.5  684.9 14.200 020 1 3.2
+ 382.6  658.7 14.000 020 1 3.2
+ 182.2  330.3 14.200 020 1 3.2
+ 245.1  548.3 12.600 020 1 3.2
+ 245.3  548.0 13.200 020 1 3.2
+  50.3  849.0 13.700 020 1 3.2
+  50.5  848.8 14.300 020 1 3.2
+  17.9  772.7 14.200 020 1 3.2
+ 499.8  712.8 13.500 020 1 3.2
+ 499.8  712.6 14.400 020 1 3.2
+ 294.5  349.4 14.000 020 1 3.2
+ 497.7  747.8 11.000 020 1 3.2
+ 497.5  747.8 10.900 020 1 3.2
+ 109.7  323.5 14.000 020 1 3.2
+  59.5  917.6 14.300 020 1 3.2
+  59.4  917.8 13.700 020 1 3.2
+  82.2  880.5 13.800 020 1 3.2
+ 145.1  341.2 14.500 020 1 3.2
+ 452.7  592.4 14.400 020 1 3.2
+ 623.4  820.0 13.700 020 1 3.2
+ 609.7  829.3 13.500 020 1 3.2
+ 481.8  938.3 14.400 020 1 3.2
+ 617.0  792.7 13.500 020 1 3.2
+ 183.2  539.7 14.400 020 1 3.2
+ 133.9  679.6 14.400 020 1 3.2
+ 423.7  667.8  6.500 020 1 3.2
+ 434.7  111.9 13.200 020 1 3.2
+ 434.5  111.9 13.200 020 1 3.2
+ 434.6  111.9 14.200 020 1 3.2
+1222.3  684.2 13.900 020 1 3.2
+1077.6  282.5 14.000 020 1 3.2
+1077.8  282.5 13.400 020 1 3.2
+ 720.8  562.1 14.100 020 1 3.2
+ 721.1  561.9 14.400 020 1 3.2
+1182.1  944.4 12.100 020 1 3.2
+1181.9  944.4 11.800 020 1 3.2
+1181.9  944.4 12.300 020 1 3.2
+ 761.2  423.1 14.300 020 1 3.2
+ 761.0  423.1 14.100 020 1 3.2
+ 926.7  436.8 13.400 020 1 3.2
+ 926.6  436.8 14.200 020 1 3.2
+1209.1   45.0 13.200 020 1 3.2
+1209.2   43.6 12.800 020 1 3.2
+1135.2  653.1  8.100 020 1 3.2
+1135.6  653.4  8.200 020 1 3.2
+1123.5  735.8 12.000 020 1 3.2
+1123.6  735.8 11.800 020 1 3.2
+1123.7  735.7 11.600 020 1 3.2
+ 730.7   28.6 12.100 020 1 3.2
+ 730.7   28.6 12.200 020 1 3.2
+ 783.1  267.5 14.200 020 1 3.2
+ 783.2  267.5 13.400 020 1 3.2
+ 876.2  462.7 13.800 020 1 3.2
+ 876.4  462.7 14.200 020 1 3.2
+ 917.2  399.9 13.700 020 1 3.2
+ 917.3  399.9 13.200 020 1 3.2
+1227.5  218.4 10.400 020 1 3.2
+1227.7  218.4 10.500 020 1 3.2
+1022.7  146.0 13.300 020 1 3.2
+1022.5  146.0 14.100 020 1 3.2
+1324.7   72.3 12.900 020 1 3.2
+1324.6   72.3 13.200 020 1 3.2
+ 743.2  379.4 14.300 020 1 3.2
+ 742.9  379.4 13.900 020 1 3.2
+1255.9  544.0 12.600 020 1 3.2
+1256.0  543.9 12.300 020 1 3.2
+ 848.9  251.1 13.200 020 1 3.2
+ 849.0  251.1 12.700 020 1 3.2
+ 495.6  147.4 11.400 020 1 3.2
+ 495.6  147.4 11.300 020 1 3.2
+ 495.5  147.4 11.000 020 1 3.2
+1016.4  735.5 14.200 020 1 3.2
+1016.3  735.7 13.900 020 1 3.2
+ 795.2  675.9 14.400 020 1 3.2
+ 887.2  968.8 10.800 020 1 3.2
+ 626.8  726.9 14.400 020 1 3.2
+ 718.6  800.1  9.700 020 1 3.2
+ 675.4  301.6 14.400 020 1 3.2
+ 801.6  436.8 14.200 020 1 3.2
+1066.4  870.0 13.700 020 1 3.2
+1066.5  869.9 13.800 020 1 3.2
+ 644.5  662.9  9.900 020 1 3.2
+ 639.1  760.4 13.000 020 1 3.2
+ 822.7  663.1 12.800 020 1 3.2
+ 822.7  663.1 13.100 020 1 3.2
+ 677.2  716.2 12.900 020 1 3.2
+ 765.6  641.5 13.200 020 1 3.2
+ 765.7  641.4 13.500 020 1 3.2
+ 998.3  425.8 14.400 020 1 3.2
+ 713.7  716.2 13.800 020 1 3.2
+ 814.7  887.6  2.000 020 1 3.2
+ 808.7  884.1  8.200 020 1 3.2
+1812.3  259.3 14.500 020 1 3.2
+1655.9  655.4 12.200 020 1 3.2
+1655.9  655.4 12.100 020 1 3.2
+1577.2  839.6 11.500 020 1 3.2
+1577.2  839.6 11.400 020 1 3.2
+1643.7  597.0 14.100 020 1 3.2
+1552.8  251.1 10.100 020 1 3.2
+1552.8  251.1 10.300 020 1 3.2
+1410.0  999.9 13.900 020 1 3.2
+1335.6  687.0 13.000 020 1 3.2
+1335.8  686.8 12.700 020 1 3.2
+1471.4  262.0 14.200 020 1 3.2
+1479.6  608.3 14.200 020 1 3.2
+1478.1  211.5 12.000 020 1 3.2
+1478.3  211.5 12.000 020 1 3.2
+1552.5   46.4 14.500 020 1 3.2
+2042.4  548.3 10.800 020 1 3.2
+2042.6  548.3 11.000 020 1 3.2
+1448.0  915.7 14.100 020 1 3.2
+1462.3  989.2 13.000 020 1 3.2
+1462.3  989.0 12.700 020 1 3.2
+1316.9  787.3 14.100 020 1 3.2
+1787.6  883.5 12.200 020 1 3.2
+1787.6  883.5 12.200 020 1 3.2
+1979.1  300.3 12.900 020 1 3.2
+1979.1  300.3 12.900 020 1 3.2
+1677.2  106.4 13.100 020 1 3.2
+1677.0  106.4 13.300 020 1 3.2
+1324.2  429.9  9.200 020 1 3.2
+1324.2  429.9  9.000 020 1 3.2
+1462.8  214.3 13.700 020 1 3.2
+1462.8  214.3 14.200 020 1 3.2
+1405.4   95.5 11.700 020 1 3.2
+1405.2   95.5 11.600 020 1 3.2
+1604.8   90.0 11.200 020 1 3.2
+1604.8   90.0 11.300 020 1 3.2
+1921.5  738.1 13.500 020 1 3.2
+1921.5  738.1 13.500 020 1 3.2
+1459.8  473.6 13.400 020 1 3.2
+1459.7  473.6 13.800 020 1 3.2
+1438.7   77.8 12.200 020 1 3.2
+1438.6   77.8 12.200 020 1 3.2
+1355.0  114.6 13.000 020 1 3.2
+1354.9  114.6 13.200 020 1 3.2
+1941.4  940.7 13.000 020 1 3.2
+1941.6  940.7 12.900 020 1 3.2
+1994.0  800.8 13.900 020 1 3.2
+1993.8  800.8 14.000 020 1 3.2
+2024.4  907.0 13.700 020 1 3.2
+2024.4  907.0 13.800 020 1 3.2
+2035.7  881.6 13.900 020 1 3.2
+2035.9  881.6 13.800 020 1 3.2
+1994.0  924.2 12.100 020 1 3.2
+1994.0  924.2 12.000 020 1 3.2
Index: /tags/getstar-1-5-0/Ohana/src/getstar/include/dvoImageExtract.h
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/include/dvoImageExtract.h	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/include/dvoImageExtract.h	(revision 13095)
@@ -0,0 +1,33 @@
+# include <ohana.h>
+# include <dvo.h>
+# include <signal.h>
+# include <glob.h>
+
+enum {NONE, SIMPLE_CMP, SIMPLE_CMF, SIMPLE_MEF, MOSAIC_CMP, MOSAIC_CMF, MOSAIC_MEF, MOSAIC_PHU};
+
+int       VERBOSE;
+
+char OUTPUT[256];
+char GSCFILE[256];
+char CATDIR[256];
+char CATMODE[16];    /* raw, mef, split, mysql */
+char CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
+char SKY_TABLE[256];
+int  SKY_DEPTH;
+char   ImageCat[256];
+char *OUTFILE;
+Coords *MOSAIC;         // carries the mosaic into ReadImageHeader
+
+int  args_extract    	 PROTO((int argc, char **argv));
+int  ConfigInit_extract  PROTO((int *argc, char **argv));
+int  Shutdown         	 PROTO((char *format, ...));
+void TrapSignal       	 PROTO((int sig));
+void SetProtect       	 PROTO((int mode));
+int  SetSignals       	 PROTO(());
+
+int GetFileMode (Header *header);
+int edge_check (double *x1, double *y1, double *x2, double *y2);
+
+int  WriteImageFITS (FILE *f, Image *image);
+int  WriteImages (char *filename, Image *images, int Nimages, int *matches, int Nmatches);
+int *SelectImages (char *filename, Image *dbImages, int NdbImages, int *Nmatch);
Index: /tags/getstar-1-5-0/Ohana/src/getstar/include/dvoImageOverlaps.h
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/include/dvoImageOverlaps.h	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/include/dvoImageOverlaps.h	(revision 13095)
@@ -0,0 +1,36 @@
+# include <ohana.h>
+# include <dvo.h>
+# include <signal.h>
+# include <glob.h>
+
+enum {NONE, SIMPLE_CMP, SIMPLE_CMF, SIMPLE_MEF, MOSAIC_CMP, MOSAIC_CMF, MOSAIC_MEF, MOSAIC_PHU};
+
+int       VERBOSE;
+
+char OUTPUT[256];
+char GSCFILE[256];
+char CATDIR[256];
+char CATMODE[16];    /* raw, mef, split, mysql */
+char CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
+char SKY_TABLE[256];
+int  SKY_DEPTH;
+char   ImageCat[256];
+Coords *MOSAIC;         // carries the mosaic into ReadImageHeader
+
+int WITH_PHU;
+int SOLO_PHU;
+
+int  args_overlaps    	 PROTO((int argc, char **argv));
+int  ConfigInit_overlaps PROTO((int *argc, char **argv));
+int  Shutdown         PROTO((char *format, ...));
+void TrapSignal       PROTO((int sig));
+void SetProtect       PROTO((int mode));
+int  SetSignals       PROTO(());
+
+Image *ReadImageFiles (char *filename, int *Nimages);
+int ReadImageHeader (Header *header, Image *image);
+int *MatchImage (Image *dbImages, int NdbImages, Image *image, int *Nmatch);
+int ListImageOverlaps (Image *dbImages, Image *image, int *matches, int Nmatches);
+
+int GetFileMode (Header *header);
+int edge_check (double *x1, double *y1, double *x2, double *y2);
Index: /tags/getstar-1-5-0/Ohana/src/getstar/include/getstar.h
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/include/getstar.h	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/include/getstar.h	(revision 13095)
@@ -0,0 +1,43 @@
+# include <ohana.h>
+# include <dvo.h>
+# include <signal.h>
+
+enum {
+  BY_NOTHING,
+  BY_REGION,
+  BY_RADIUS,
+  BY_CATALOG,
+  BY_IMAGE,
+  BY_IMMATCH,
+  BY_IMLIST,
+};
+
+int       VERBOSE;
+int       MODE;
+SkyRegion REGION;
+char     *IMAGENAME;
+
+char OUTPUT[256];
+char GSCFILE[256];
+char CATDIR[256];
+char CATMODE[16];    /* raw, mef, split, mysql */
+char CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
+char SKY_TABLE[256];
+int  SKY_DEPTH;
+
+int  MagLimitUse;
+float MagLimitValue;
+
+int  args             PROTO((int argc, char **argv));
+int  ConfigInit       PROTO((int *argc, char **argv));
+int  Shutdown         PROTO((char *format, ...));
+int  load_pt_catalog  PROTO((Catalog *catalog, SkyRegion *region));
+int  select_by_region PROTO((Catalog *output, Catalog *catalog, SkyRegion *region, int start, int end));
+void set_db           PROTO((FITS_DB *in));
+void wcatalog         PROTO((char *filename, Catalog *catalog));
+void mkcatalog        PROTO((Catalog *catalog));
+void init_catalog     PROTO((Catalog *catalog));
+void TrapSignal       PROTO((int sig));
+void SetProtect       PROTO((int mode));
+int  SetSignals       PROTO(());
+int  gcatalog         PROTO((Catalog *catalog));
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit.c	(revision 13095)
@@ -0,0 +1,45 @@
+# include "getstar.h"
+
+int ConfigInit (int *argc, char **argv) {
+
+  char *config, *file;
+  char CatdirPhotcodeFile[256];
+  char MasterPhotcodeFile[256];
+
+  /*** load configuration info ***/
+  file = SelectConfigFile (argc, argv, "ptolemy");
+  config = LoadConfigFile (file);
+  if (config == (char *) NULL) {
+    fprintf (stderr, "ERROR: can't find configuration file %s\n", file);
+    if (file != (char *) NULL) free (file);
+    exit (1);
+  }
+  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
+
+  ScanConfig (config, "GSCFILE",                "%s", 0, GSCFILE);
+  ScanConfig (config, "CATDIR",                 "%s", 0, CATDIR);
+  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
+  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
+  ScanConfig (config, "PHOTCODE_FILE",         	"%s",  0, MasterPhotcodeFile);
+  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
+    SKY_DEPTH = 2;
+  }
+  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
+    SKY_TABLE[0] = 0;
+  }
+
+  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
+  if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
+
+  /* XXX this does not yet write out the master photcode table */
+  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
+  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile)) {
+    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
+    exit (1);
+  }
+
+  free (config);
+  free (file);
+
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit_extract.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit_extract.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit_extract.c	(revision 13095)
@@ -0,0 +1,46 @@
+# include "dvoImageExtract.h"
+
+int ConfigInit_extract (int *argc, char **argv) {
+
+  char *config, *file;
+  char CatdirPhotcodeFile[256];
+  char MasterPhotcodeFile[256];
+
+  /*** load configuration info ***/
+  file = SelectConfigFile (argc, argv, "ptolemy");
+  config = LoadConfigFile (file);
+  if (config == (char *) NULL) {
+    fprintf (stderr, "ERROR: can't find configuration file %s\n", file);
+    if (file != (char *) NULL) free (file);
+    exit (1);
+  }
+  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
+
+  ScanConfig (config, "GSCFILE",                "%s", 0, GSCFILE);
+  ScanConfig (config, "CATDIR",                 "%s", 0, CATDIR);
+  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
+  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
+  ScanConfig (config, "PHOTCODE_FILE",         	"%s",  0, MasterPhotcodeFile);
+  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
+    SKY_DEPTH = 2;
+  }
+  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
+    SKY_TABLE[0] = 0;
+  }
+  sprintf (ImageCat, "%s/Images.dat", CATDIR);
+
+  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
+  if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
+
+  /* XXX this does not yet write out the master photcode table */
+  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
+  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile)) {
+    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
+    exit (1);
+  }
+
+  free (config);
+  free (file);
+
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit_overlaps.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit_overlaps.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/ConfigInit_overlaps.c	(revision 13095)
@@ -0,0 +1,46 @@
+# include "dvoImageOverlaps.h"
+
+int ConfigInit_overlaps (int *argc, char **argv) {
+
+  char *config, *file;
+  char CatdirPhotcodeFile[256];
+  char MasterPhotcodeFile[256];
+
+  /*** load configuration info ***/
+  file = SelectConfigFile (argc, argv, "ptolemy");
+  config = LoadConfigFile (file);
+  if (config == (char *) NULL) {
+    fprintf (stderr, "ERROR: can't find configuration file %s\n", file);
+    if (file != (char *) NULL) free (file);
+    exit (1);
+  }
+  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
+
+  ScanConfig (config, "GSCFILE",                "%s", 0, GSCFILE);
+  ScanConfig (config, "CATDIR",                 "%s", 0, CATDIR);
+  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
+  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
+  ScanConfig (config, "PHOTCODE_FILE",         	"%s",  0, MasterPhotcodeFile);
+  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
+    SKY_DEPTH = 2;
+  }
+  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
+    SKY_TABLE[0] = 0;
+  }
+  sprintf (ImageCat, "%s/Images.dat", CATDIR);
+
+  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
+  if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
+
+  /* XXX this does not yet write out the master photcode table */
+  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
+  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile)) {
+    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
+    exit (1);
+  }
+
+  free (config);
+  free (file);
+
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/GetFileMode.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/GetFileMode.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/GetFileMode.c	(revision 13095)
@@ -0,0 +1,45 @@
+# include "dvoImageOverlaps.h"
+
+// examine the PHU of this file and determine the file mode
+int GetFileMode (Header *header) {
+
+  char ctype[80];
+  int Naxis, Nx, Ny;
+  int simple, extend, haveNaxis, haveNx, haveNy, haveCTYPE;
+
+  gfits_scan (header, "SIMPLE", "%t", 1, &simple);
+  haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
+  haveNx    = gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
+  haveNy    = gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
+
+  gfits_scan (header, "EXTEND", "%t", 1, &extend);
+    
+  if ((Naxis == 2) || !simple) {
+    if (!strcmp (&ctype[4], "-WRP")) {
+      return MOSAIC_CMP;
+    }
+    return SIMPLE_CMP;
+  }
+
+  if (!extend && strcmp (&ctype[4], "-DIS")) {
+    if (!strcmp (&ctype[4], "-WRP")) {
+      return MOSAIC_CMF;
+    }
+    return SIMPLE_CMF;
+  }
+
+  if (!extend && !strcmp (&ctype[4], "-DIS")) {
+    return MOSAIC_PHU;
+  }
+
+  if (extend && strcmp (&ctype[4], "-DIS")) {
+    return SIMPLE_MEF;
+  }
+
+  if (extend && !strcmp (&ctype[4], "-DIS")) {
+    return MOSAIC_MEF;
+  }
+
+  return (NONE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/ListImageOverlaps.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/ListImageOverlaps.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/ListImageOverlaps.c	(revision 13095)
@@ -0,0 +1,14 @@
+# include "dvoImageOverlaps.h"
+
+/* given image, find catalog images which overlap it */
+int ListImageOverlaps (Image *dbImages, Image *image, int *matches, int Nmatches) {
+  
+  int i, N;
+
+  for (i = 0; i < Nmatches; i++) {
+    N = matches[i];
+    fprintf (stdout, "%s  :  %s\n", image[0].name, dbImages[N].name);
+  }
+  
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/MatchImages.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/MatchImages.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/MatchImages.c	(revision 13095)
@@ -0,0 +1,151 @@
+# include "dvoImageOverlaps.h"
+# ifndef FLT_MAX
+# define FLT_MAX 1e32
+# endif
+
+/* given image, find catalog images which overlap it */
+int *MatchImage (Image *dbImages, int NdbImages, Image *image, int *Nmatch) {
+  
+  int i, j, k, N, addtolist, status;
+  int NMATCH, nmatch, *match;
+  Coords tcoords;
+  double r, d, x, y;
+  double Xi[4], Yi[4], Xo[4], Yo[4];  /* image and original corners */
+  double Xmin, Xmax, Ymin, Ymax;
+  double xmin, xmax, ymin, ymax;
+
+  if (!WITH_PHU && !strcmp (&image[0].coords.ctype[4], "-DIS")) return FALSE;
+  if ( SOLO_PHU &&  strcmp (&image[0].coords.ctype[4], "-DIS")) return FALSE;
+
+  /* project onto rectilinear grid with 1 arcsec pixels */
+  /* we keep the original crpix1,2 and crref1,2 */
+  /* for mosaic astrometry, the grid should be w.r.t. the tangent-plane, not chip coords */
+  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
+    // if the input image is a mosaic, we need to register that mosaic for the calculations below
+    if (MOSAIC == NULL) {
+      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
+      return (FALSE);
+    }
+    RegisterMosaic (MOSAIC);
+
+    tcoords = MOSAIC[0];
+    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
+    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
+    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
+    tcoords.Npolyterms = 1;
+    strcpy (tcoords.ctype, "RA---TAN");
+    /* register so image->sky conversions below have correct mosaic */
+  } else {
+    tcoords = image[0].coords;
+    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
+    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
+    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
+    strcpy (tcoords.ctype, "RA---TAN");
+  }
+
+  /* define original corners */
+  SetImageCorners (Xo, Yo, &image[0]);
+  
+  Ymin = Xmin = +FLT_MAX;
+  Ymax = Xmax = -FLT_MAX;
+  for (j = 0; j < 4; j++) {
+    /* XY-to_RD is two-level if ctype == WRP */
+    XY_to_RD (&r, &d, Xo[j], Yo[j], &image[0].coords);
+    RD_to_XY (&Xo[j], &Yo[j], r, d, &tcoords);
+    Xmin = MIN (Xmin, Xo[j]);
+    Xmax = MAX (Xmax, Xo[j]);
+    Ymin = MIN (Ymin, Yo[j]);
+    Ymax = MAX (Ymax, Yo[j]);
+  }
+
+  /* match represents the subset of overlapping images */
+  nmatch = 0;
+  NMATCH = 20;
+  ALLOCATE (match, int, NMATCH);
+
+  /* setup links for mosaic WRP and DIS entries */
+  BuildChipMatch (dbImages, NdbImages);
+
+  /* run through image table and search for overlaps
+     also define the vtable entries for the images we keep  */
+
+  for (i = 0; i < NdbImages; i++) {
+
+    if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
+    if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
+
+    /* if any of these images are WRP images, need to find matching DIS */
+    if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
+
+    /* define image corners */
+    SetImageCorners (Xi, Yi, &dbImages[i]);
+    // Xi[4] = Xi[0]; Yi[4] = Yi[0];
+
+    /* transform to tcoords, skip corners off image */
+    /*** XXX this will fail for very large images which extend beyond 180deg */
+    ymin = xmin = +FLT_MAX;
+    ymax = xmax = -FLT_MAX;
+    for (j = N = 0; j < 4; j++) {
+      status = XY_to_RD (&r, &d, Xi[j], Yi[j], &dbImages[i].coords);
+      if (!status) continue;
+      status = RD_to_XY (&Xi[N], &Yi[N], r, d, &tcoords);
+      if (!status) continue;
+      xmin = MIN (xmin, Xi[N]);
+      xmax = MAX (xmax, Xi[N]);
+      ymin = MIN (ymin, Yi[N]);
+      ymax = MAX (ymax, Yi[N]);
+      N++;
+    }
+
+    /* check if one corner of dbImages[i] is inside image[0] */
+    for (j = 0; j < N; j++) {
+      addtolist = TRUE;
+      addtolist &= (Xi[j] >= Xmin);
+      addtolist &= (Xi[j] <= Xmax);
+      addtolist &= (Yi[j] >= Ymin);
+      addtolist &= (Yi[j] <= Ymax);
+      if (addtolist) goto addtolist;
+    }
+
+    /* or else, check if one corner of image[0] is inside dbImages[i] */
+    for (j = 0; j < 4; j++) {
+      addtolist = TRUE;
+      addtolist &= (Xo[j] >= xmin);
+      addtolist &= (Xo[j] <= xmax);
+      addtolist &= (Yo[j] >= ymin);
+      addtolist &= (Yo[j] <= ymax);
+      if (addtolist) goto addtolist;
+    }
+
+    // no match, skip this dbImage
+    continue;
+
+  addtolist:
+    match[nmatch] = i;
+    nmatch ++;
+    if (nmatch == NMATCH) {
+      NMATCH += 20;
+      REALLOCATE (match, int, NMATCH);
+    }
+  }
+  
+  if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", nmatch);
+
+  *Nmatch = nmatch;
+  return (match);
+}
+  
+void SetImageCorners (double *X, double *Y, Image *image) {
+
+  if (!strcmp(&image[0].coords.ctype[4], "-DIS")) {
+    X[0] = -0.5*image[0].NX; Y[0] = -0.5*image[0].NY;
+    X[1] = +0.5*image[0].NX; Y[1] = -0.5*image[0].NY;
+    X[2] = +0.5*image[0].NX; Y[2] = +0.5*image[0].NY;
+    X[3] = -0.5*image[0].NX; Y[3] = +0.5*image[0].NY;
+  } else {
+    X[0] = 0;           Y[0] = 0;
+    X[1] = image[0].NX; Y[1] = 0;
+    X[2] = image[0].NX; Y[2] = image[0].NY;
+    X[3] = 0;           Y[3] = image[0].NY;
+  }
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/ReadImageFiles.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/ReadImageFiles.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/ReadImageFiles.c	(revision 13095)
@@ -0,0 +1,225 @@
+# include "dvoImageOverlaps.h"
+
+Image *ReadImageFiles (char *filename, int *Nimages) {
+
+  int i, j, N, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
+  int Nskip, Nhead, Ndata, done, status, mode, NinStars;
+  char **file, *name;
+  FILE *f;
+  glob_t globList;
+  char **exthead, **extdata, **exttype, tmpword[80];
+  int *extnum_head, *extnum_data, *extsize;
+  Header *header, **headers;
+  Image *image;
+
+  // parse the filename as a glob
+  globList.gl_offs = 0;
+  glob (filename, 0, NULL, &globList);
+
+  // if the glob does not match, save the literal word:
+  // otherwise save all glob matches
+  if (globList.gl_pathc == 0) {
+    Nfile = 1;
+    ALLOCATE (file, char *, Nfile);
+    file[0] = strcreate (filename);
+  } else {
+    Nfile = globList.gl_pathc;
+    ALLOCATE (file, char *, Nfile);
+    for (i = 0; i < Nfile; i++) {
+      file[i] = strcreate (globList.gl_pathv[i]);
+    }
+  }
+
+  // open the first file, read the PHU header
+  f = fopen (file[0], "r");
+  if (f == NULL) {
+    fprintf (stderr, "ERROR: can't read header for %s\n", file[0]);
+    exit (1);
+  }
+  ALLOCATE (header, Header, 1);
+  gfits_fread_header (f, header);
+
+  mode = GetFileMode (header);
+
+  /*** load data from a single PHU or a collection of PHU files ***/
+  if ((mode != SIMPLE_MEF) && (mode != MOSAIC_MEF)) {
+    Nimage = Nfile;
+    ALLOCATE (image, Image, Nimage);
+    for (i = N = 0; i < Nfile; i++) {
+      if (i > 0) {
+	f = fopen (file[i], "r");
+	if (f == NULL) {
+	  fprintf (stderr, "can't read header for %s, skipping\n", file[i]);
+	  continue;
+	}
+	gfits_fread_header (f, header);
+      }
+
+      if (!ReadImageHeader (header, &image[N])) {
+	fprintf (stderr, "skipping %s\n", file[i]);
+	continue;
+      }
+      
+      /* find image rootname */
+      name = filebasename (file[i]);
+      snprintf (image[N].name, 32, name);
+      free (name);
+
+      fclose (f);
+      gfits_free_header (header);
+      N++;
+    }
+    *Nimages = N;
+    
+    if (N == 0) {
+      fprintf (stderr, "ERROR: no valid image data in %s, giving up\n", filename);
+      exit (1);
+    }
+    return image;
+  }
+    
+  /* we have a multi-chip image */
+
+  /* we need to examine the extensions to determine the headers and the data */
+  NHEADER = 10;
+  ALLOCATE (headers, Header *, NHEADER);
+
+  // the first header is already loaded
+  headers[0] = header;
+  Nskip = gfits_matrix_size (header);
+  fseek (f, Nskip, SEEK_CUR); 
+
+  // load all headers into memory
+  done = FALSE;
+  for (i = 1; !done; i++) {
+      ALLOCATE (headers[i], Header, 1);
+      status = gfits_fread_header (f, headers[i]);
+      if (!status) { 
+	  done = TRUE;
+      } else {
+	  Nskip = gfits_matrix_size (headers[i]);
+	  fseek (f, Nskip, SEEK_CUR); 
+      }
+      if (i == NHEADER - 1) {
+	  NHEADER += 10;
+	  REALLOCATE (headers, Header *, NHEADER);
+      }
+  }
+  Nheader = i - 1; /* we failed on the last loop */
+    
+  // space to store the images, indexes to the matching headers
+  Nimage = 0;
+  NIMAGE = Nheader;
+  ALLOCATE (image, Image, NIMAGE);
+  ALLOCATE (exthead, char *, NIMAGE);
+  ALLOCATE (extdata, char *, NIMAGE);
+  ALLOCATE (exttype, char *, NIMAGE);
+  ALLOCATE (extnum_head, int, NIMAGE);
+  ALLOCATE (extnum_data, int, NIMAGE);
+  ALLOCATE (extsize, int, Nheader);
+
+  if (mode == MOSAIC_MEF) {
+      exthead[Nimage] = strcreate ("PHU");
+      extdata[Nimage] = strcreate ("NONE");
+      extnum_data[Nimage] = -1;
+      extnum_head[Nimage] = 0;
+      Nimage ++;
+  }
+
+  // now examine the headers, count the table entries, find corresponding headers
+  for (i = 0; i < Nheader; i++) {
+      extsize[i] = headers[i][0].size + gfits_matrix_size (headers[i]);
+      gfits_scan (headers[i], "EXTTYPE", "%s", 1, tmpword);
+
+      if (!strcmp (tmpword, "SMPDATA") ||  
+	  !strcmp (tmpword, "PS1_DEV_0")) {
+
+	  exttype[Nimage] = strcreate (tmpword);
+	  gfits_scan (headers[i], "EXTNAME", "%s", 1, tmpword);
+	  extdata[Nimage] = strcreate (tmpword);
+	  gfits_scan (headers[i], "EXTHEAD", "%s", 1, tmpword);
+	  exthead[Nimage] = strcreate (tmpword);
+	  extnum_data[Nimage] = i;
+	  extnum_head[Nimage] = -1;
+	  // find the matching exthead entry
+	  for (j = 0; j < Nheader; j++) {
+	    if (gfits_scan (headers[j], "EXTNAME", "%s", 1, tmpword)) {
+	      if (!strcmp (tmpword, exthead[Nimage])) {
+		extnum_head[Nimage] = j;
+	      }
+	    }
+	  }
+	  // skip or crash on table with missing matching header?
+	  if (extnum_head[Nimage] == -1) {
+	      fprintf (stderr, "ERROR: can't read header for %s\n", file[0]);
+	      exit (1);
+	  }
+	  Nimage ++;
+      }
+  }
+
+  // some old format files did not write EXTTYPE.  they have a single table in the first
+  // extension matched to the header in the PHU
+  if (Nimage == 0) {
+      extsize[0] = headers[0][0].size + gfits_matrix_size (headers[0]);
+      extsize[1] = headers[1][0].size + gfits_matrix_size (headers[1]);
+      gfits_scan (headers[1], "EXTNAME", "%s", 1, tmpword);
+      if (!strcmp (tmpword, "SMPFILE")) {
+	  extdata[Nimage] = strcreate (tmpword);
+	  exttype[Nimage] = strcreate ("SMPDATA");
+	  exthead[Nimage] = strcreate ("PHU");
+	  extnum_head[Nimage] = 0;
+	  extnum_data[Nimage] = 1;
+	  Nimage = 1;
+      }
+  }
+  if (Nimage == 0) Shutdown ("no object data in file");
+    
+  if (VERBOSE) fprintf (stderr, "file %s has %d headers, including %d images\n", file[0], Nheader, Nimage);
+
+  /* find image rootname */
+  name = filebasename (file[0]);
+
+  // now run through the images, interpret the headers and read the stars
+  for (i = N = 0; i < Nimage; i++) {
+      Nhead = extnum_head[i];
+
+      // XXX do I need to advance the file pointer, or does ReadImageHeader do this?
+      if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", exthead[i], extdata[i]);
+      if (!ReadImageHeader (headers[Nhead], &image[N])) {
+	  fprintf (stderr, "skipping %s\n", exthead[i]);
+	  continue;
+      }
+
+      // XXX use something to set the chip name? EXTNAME?
+      if (!strcmp(exthead[i], "PHU") && (Nimage == 1)) {
+	snprintf (image[N].name, 32, "%s", name);
+      } else {
+	snprintf (image[N].name, 32, "%s[%s]", name, exthead[i]);
+      }
+
+      // skip the table if there is not data segment (eg, mosaic WRP image)
+      if (!strcmp(extdata[i], "NONE")) {
+	  N++;
+	  continue;
+      }
+
+      // advance the pointer to the start of the corresponding table block
+      Ndata = extnum_data[i];
+      Nskip = 0;
+      for (j = 0; j < Ndata; j++) {
+	  Nskip += extsize[j];
+      }
+      fseek (f, Nskip, SEEK_SET); 
+      N++;
+  }
+  free (name);
+  *Nimages = N;
+
+  if (N == 0) {
+    fprintf (stderr, "ERROR: no valid image data in %s, giving up\n", filename);
+    exit (1);
+  }
+
+  return image;
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/ReadImageHeader.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/ReadImageHeader.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/ReadImageHeader.c	(revision 13095)
@@ -0,0 +1,157 @@
+# include "dvoImageOverlaps.h"
+
+/* read an image header corresponding to a CMF / CMP data block */
+int ReadImageHeader (Header *header, Image *image) {
+
+  int Nastro, ccdnum, hour, min, Nx, Ny, photcode;
+  double tmp, sec, Cerror;
+  char *c, photname[64], line[80];
+
+  /* get astrometry information */
+  if (!GetCoords (&image[0].coords, header)) {
+    fprintf (stderr, "no astrometric solution in header\n");
+    return (FALSE);
+  }
+  // XXX currently, image uses an unsigned short for NX,XY. this is rather restrictive
+  // and needs to be at least checked.
+  gfits_scan (header, "NAXIS1",   "%d", 1, &Nx);
+  gfits_scan (header, "NAXIS2",   "%d", 1, &Ny);
+  if ((Nx < 0) || (Nx > 0xffff)) {
+    fprintf (stderr, "WARNING: NX, NY out of range : image boundary will be wrong\n");
+  }
+  image[0].NX = Nx;
+  image[0].NY = Ny;
+
+  // if (!gfits_scan (header, "TZERO",   "%d",  1, &image[0].tzero)) {
+  // image[0].tzero = parse_time (header);
+  // }
+
+  /* only load astrometry, NAXIS1,2, and time if this is a MOSAIC_PHU (ctype is ....-DIS) */
+  if (!strcmp (&image[0].coords.ctype[4], "-DIS")) {
+    MOSAIC = &image[0].coords;
+    return (TRUE);
+  }
+
+  /* require Nastro > 0 unless or ACCEPT_ASTROM */
+  Nastro = 0;
+  gfits_scan (header, "NASTRO", "%d", 1, &Nastro);
+  if (Nastro == 0) {
+    fprintf (stderr, "bad astrometric solution in header\n");
+    return (FALSE);
+  }
+  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
+    if (MOSAIC == NULL) {
+      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
+      return (FALSE);
+    }
+    RegisterMosaic (MOSAIC);
+  } else {
+    /* force image to lie in 0-360 range */
+    while (image[0].coords.crval1 < 0) image[0].coords.crval1 += 360.0;
+    while (image[0].coords.crval1 > 360.0) image[0].coords.crval1 -= 360.0;
+  }
+
+  { 
+    double R, D;
+    /* sanity check on the image coordinates */
+    XY_to_RD (&R, &D, 0.5*Nx, 0.5*Ny, &image[0].coords);
+    if (!finite(R) || !finite(D)) {
+      fprintf (stderr, "corrupted header coordinates, skipping\n");
+      return (FALSE);
+    }
+  }
+    
+  /* CERROR in data file is in arcsec */
+  if (!gfits_scan (header, "CERROR",   "%lf", 1, &tmp)) tmp = 1.0;
+  image[0].cerror = tmp * 50.0;
+ 
+  /* get photcode from header */
+  /*** XXX is photcode needed?? ***/
+  if (!gfits_scan (header, "PHOTCODE", "%s", 1, photname)) {
+    fprintf (stderr, "photcode not supplied in header\n");
+    return (FALSE);
+  }
+  photcode = GetPhotcodeCodebyName (photname);
+  if (photcode == 0) { 
+    fprintf (stderr, "no valid photcode is supplied\n");
+    return (FALSE);
+  }
+  image[0].photcode = photcode;
+
+  // XXX we don't really need these
+  // gfits_scan (header, ExptimeKeyword,  "%lf", 1, &tmp);
+  // image[0].exptime = tmp;
+  
+  /*** why are we no longer using APMIFIT?? ***/
+  tmp = 0;
+  /* gfits_scan (header, "APMIFIT",  "%lf", 1, &tmp); */
+  image[0].apmifit = tmp;
+
+  tmp = 0;
+  /* gfits_scan (header, "dAPMIFIT", "%lf", 1, &tmp); */
+  image[0].dapmifit = tmp;
+
+  tmp = 0;
+  gfits_scan (header, "FLIMIT",   "%lf", 1, &tmp);
+  image[0].detection_limit = tmp * 10.0;
+
+  tmp = 0;
+  gfits_scan (header, "FSATUR",   "%lf", 1, &tmp);
+  image[0].saturation_limit = tmp * 10.0;
+
+  tmp = 0;
+  gfits_scan (header, "FWHM_X",   "%lf", 1, &tmp);
+  image[0].fwhm_x = tmp * 25.0 * image[0].coords.cdelt1 * 3600.0;
+
+  tmp = 0;
+  gfits_scan (header, "FWHM_Y",   "%lf", 1, &tmp);
+  image[0].fwhm_y = tmp * 25.0 * image[0].coords.cdelt1 * 3600.0;
+
+  // XXX we don't really need the following values
+# if (0)  
+  if (STKeyword[0]) {
+    /* get ST (used for airmass calculation) */
+    gfits_scan (header, STKeyword, "%s", 1, line);
+    /* remove ':' characters */
+    for (c = strchr (line, ':'); c != (char *) NULL; c = strchr (line, ':')) { *c = ' '; }
+    sscanf (line, "%d %d %lf", &hour, &min, &sec);
+    image[0].sidtime = hour + min/60.0 + sec/3600.0;
+  } else {
+    double jd;
+    jd = sec_to_jd (image[0].tzero);
+    image[0].sidtime  = ohana_lst (jd, Longitude);
+  }
+  image[0].latitude = Latitude;
+
+  tmp = 0;
+  gfits_scan (header, "TRATE",   "%lf", 1, &tmp);
+  image[0].trate = 10000 * tmp;
+
+  tmp = 0;
+  gfits_scan (header, AirmassKeyword, "%lf", 1, &tmp);
+  image[0].secz = MIN (NO_MAG, tmp);
+
+  if (!gfits_scan (header, CCDNumKeyword, "%d", 1, &ccdnum)) {
+    image[0].ccdnum = 0xff;
+  } else {
+    image[0].ccdnum = ccdnum;
+  }
+
+  gfits_scan (header, "ZERO_PT", "%lf", 1, &ZeroPt);
+  SetZeroPoint (ZeroPt);
+# endif
+
+  /* secz is in units milli-airmass */
+  image[0].Mcal = 0.0;
+  image[0].Xm   = NO_MAG;
+  image[0].code = 0;
+  bzero (image[0].dummy, sizeof(image[0].dummy));
+
+  /* find expected number of stars */
+  if (!gfits_scan (header, "NSTARS", "%d", 1, &image[0].nstar)) {
+    fprintf (stderr, "can't get NSTARS from header\n");
+    return (FALSE);
+  }
+
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/SelectImages.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/SelectImages.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/SelectImages.c	(revision 13095)
@@ -0,0 +1,37 @@
+# include "dvoImageExtract.h"
+
+/* given image, find catalog images which overlap it */
+int *SelectImages (char *filename, Image *images, int Nimages, int *Nmatch) {
+  
+  int i, Nchar, status;
+  int NMATCH, nmatch, *match;
+
+  /* matches here are only based on string comparisons */
+
+  /* match represents the subset of matched images */
+  nmatch = 0;
+  NMATCH = 20;
+  ALLOCATE (match, int, NMATCH);
+
+  /* setup links for mosaic WRP and DIS entries */
+  BuildChipMatch (images, Nimages);
+
+  Nchar = strlen (filename);
+
+  for (i = 0; i < Nimages; i++) {
+
+    if (strncmp (images[i].name, filename, Nchar)) continue;
+
+    match[nmatch] = i;
+    nmatch ++;
+    if (nmatch == NMATCH) {
+      NMATCH += 20;
+      REALLOCATE (match, int, NMATCH);
+    }
+  }  
+
+  if (VERBOSE) fprintf (stderr, "found %d matching images\n", nmatch);
+
+  *Nmatch = nmatch;
+  return (match);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/SetSignals.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/SetSignals.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/SetSignals.c	(revision 13095)
@@ -0,0 +1,122 @@
+# include "getstar.h"
+
+static int Protect = FALSE;
+static int Trapped = FALSE;
+
+void TrapSignal (int sig) {
+    fprintf (stderr, "trapped signal %d\n", sig);
+    if (sig == 11) {
+      fprintf (stderr, "seg fault\n");
+      exit (1);
+    }
+    if (Protect) {
+      Trapped = TRUE;
+      fprintf (stderr, "blocking until protected sections are clear\n");
+      return;
+    }
+    Shutdown ("halted by signal (trapped)");
+}    
+
+void SetProtect (int mode) {
+  Protect = mode;
+  if (Trapped && !Protect) Shutdown ("halted by signal (protect)");
+}
+
+int SetSignals () {
+
+  int i;
+
+  /* disable almost all signal interrupts */
+  for (i = 0; i < 36; i++) {
+    switch (i) {
+      /* can't redirect these signals */
+    case SIGKILL:    /* kill -9: cannot be caught or ignored (POSIX.1-1990) */
+    case SIGSTOP:    /* SIGSTOP: cannot be caught or ignored (POSIX.1-1990) */
+      /* ignore these signals */
+    case SIGCHLD:    /* child halted: ignore (POSIX.1-1990) */
+    case SIGCONT:    /* continue - maintain this action (POSIX.1-1990) */
+    case SIGTSTP:    /* stop signal sent from tty - why ignore? (POSIX.1-1990) */
+    case SIGURG:     /* socket signal, ignore this (POSIX.1-2001) */
+# ifdef SIGPWR
+    case SIGPWR:     /* power failure - why ignore this? (Sys V) */
+# endif
+# ifdef SIGWINCH
+    case SIGWINCH:   /* window resized (4.3BSD) */
+# endif
+      break;
+      
+    default:
+      signal (i, TrapSignal);
+    }
+  }
+  return (TRUE);
+}
+/*
+
+       Signal     Value     Action   Comment
+       -------------------------------------------------------------------------
+       SIGHUP        1        A      Hangup detected on controlling terminal
+                                     or death of controlling process
+       SIGINT        2        A      Interrupt from keyboard
+       SIGQUIT       3        A      Quit from keyboard
+       SIGILL        4        A      Illegal Instruction
+       SIGABRT       6        C      Abort signal from abort(3)
+       SIGFPE        8        C      Floating point exception
+       SIGKILL       9       AEF     Kill signal
+       SIGSEGV      11        C      Invalid memory reference
+       SIGPIPE      13        A      Broken pipe: write to pipe with no readers
+       SIGALRM      14        A      Timer signal from alarm(2)
+       SIGTERM      15        A      Termination signal
+       SIGUSR1   30,10,16     A      User-defined signal 1
+       SIGUSR2   31,12,17     A      User-defined signal 2
+       SIGCHLD   20,17,18     B      Child stopped or terminated
+       SIGCONT   19,18,25            Continue if stopped
+       SIGSTOP   17,19,23    DEF     Stop process
+       SIGTSTP   18,20,24     D      Stop typed at tty
+       SIGTTIN   21,21,26     D      tty input for background process
+       SIGTTOU   22,22,27     D      tty output for background process
+
+       Next various other signals.
+
+       Signal       Value     Action   Comment
+       ---------------------------------------------------------------------
+       SIGTRAP        5         CG     Trace/breakpoint trap
+       SIGIOT         6         CG     IOT trap. A synonym for SIGABRT
+       SIGEMT       7,-,7       G
+       SIGBUS      10,7,10      AG     Bus error
+       SIGSYS      12,-,12      G      Bad argument to routine (SVID)
+       SIGSTKFLT    -,16,-      AG     Stack fault on coprocessor
+       SIGURG      16,23,21     BG     Urgent condition on socket (4.2 BSD)
+       SIGIO       23,29,22     AG     I/O now possible (4.2 BSD)
+       SIGPOLL                  AG     A synonym for SIGIO (System V)
+       SIGCLD       -,-,18      G      A synonym for SIGCHLD
+       SIGXCPU     24,24,30     AG     CPU time limit exceeded (4.2 BSD)
+       SIGXFSZ     25,25,31     AG     File size limit exceeded (4.2 BSD)
+       SIGVTALRM   26,26,28     AG     Virtual alarm clock (4.2 BSD)
+       SIGPROF     27,27,29     AG     Profile alarm clock
+       SIGPWR      29,30,19     AG     Power failure (System V)
+       SIGINFO      29,-,-      G      A synonym for SIGPWR
+       SIGLOST      -,-,-       AG     File lock lost
+       SIGWINCH    28,28,20     BG     Window resize signal (4.3 BSD, Sun)
+       SIGUNUSED    -,31,-      AG     Unused signal
+       (Here - denotes that a signal is absent; there where three values are given, the first one is usually  valid  for  alpha  and
+       sparc,  the  middle  one  for i386 and ppc, the last one for mips. Signal 29 is SIGINFO / SIGPWR on an alpha but SIGLOST on a
+       sparc.)
+
+       The letters in the "Action" column have the following meanings:
+
+       A      Default action is to terminate the process.
+
+       B      Default action is to ignore the signal.
+
+       C      Default action is to dump core.
+
+       D      Default action is to stop the process.
+
+       E      Signal cannot be caught.
+
+       F      Signal cannot be ignored.
+
+       G      Not a POSIX.1 conformant signal.
+
+*/
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/Shutdown.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/Shutdown.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/Shutdown.c	(revision 13095)
@@ -0,0 +1,28 @@
+# include "getstar.h"
+
+static FITS_DB *db;
+
+void set_db (FITS_DB *in) {
+  db = in;
+}
+
+/* clean up open / locked ImageCat before shutting down */
+int Shutdown (char *format, ...) {  
+  va_list argp;
+  char *formatplus;
+  
+  ALLOCATE (formatplus, char, strlen(format));
+  strcpy (formatplus, format);
+  strcat (formatplus, "\n");
+
+  va_start (argp, format);
+  vfprintf (stderr, formatplus, argp);
+  free (formatplus);
+  va_end (argp);
+
+  SetProtect (TRUE);
+  gfits_db_close (db);
+  fprintf (stderr, "ERROR: getstar halted\n");
+  exit (1);
+}
+
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/WriteImageFITS.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/WriteImageFITS.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/WriteImageFITS.c	(revision 13095)
@@ -0,0 +1,46 @@
+# include "dvoImageExtract.h"
+
+/* given image, find catalog images which overlap it.  this function actually creates an
+ * image-less file, filling in the header, but not the pixels.
+ */
+int WriteImageFITS (FILE *f, Image *image) {
+  
+  int Nstars;
+  Header header;
+  Matrix matrix;
+  Header theader;
+  FTable table;
+
+  gfits_init_header (&header);
+  header.extend = TRUE;
+  header.Naxes = 2;
+  if (image) {
+    header.Naxis[0] = image[0].NX;
+    header.Naxis[1] = image[0].NY;
+  }
+  gfits_create_header (&header);
+  gfits_modify (&header, "NAXIS", "%d", 1, 0);
+
+  if (image) {
+    PutCoords (&image[0].coords, &header);
+  }
+  /* do not create data matrix - the matrix is defined to be empty (NAXIS=0)
+     gfits_create_matrix (&header, &matrix);
+  */
+  gfits_fwrite_header  (f, &header);
+
+  // gfits_fwrite_matrix  (f, &matrix);
+  return (TRUE);
+
+  Nstars = 0;
+  if (image) Nstars = image[0].nstar;
+
+  table.header = &theader;
+  gfits_table_set_SMPData (&table, NULL, Nstars);
+  gfits_fwrite_Theader (f, &theader);
+  gfits_fwrite_table   (f, &table);
+
+  return TRUE;
+}
+
+// XXX this is a temporary hack to get skycell output working
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/WriteImages.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/WriteImages.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/WriteImages.c	(revision 13095)
@@ -0,0 +1,56 @@
+# include "dvoImageExtract.h"
+
+/* given image, find catalog images which overlap it */
+int WriteImages (char *filename, Image *images, int Nimages, int *matches, int Nmatches) {
+  
+  int i, N, status;
+  int NMATCH, nmatch, *match;
+  int nWRP, newWRP, isWRP;
+  FILE *f;
+
+  /* matches here are only based on string comparisons */
+
+  f = fopen (filename, "w");
+  if (f == NULL) {
+    fprintf (stderr, "failed to open output file %s\n", filename);
+    exit (1);
+  }
+
+  nWRP = -1;
+  isWRP = FALSE;
+  for (i = 0; i < Nmatches; i++) {
+    if (!strcmp (&images[0].coords.ctype[4], "-WRP")) {
+      if (!FindMosaicForImage (images, Nimages, i)) {
+	fprintf (stderr, "failed to find matching mosaic\n");
+	exit (1);
+      }
+      if (isWRP) {
+	newWRP = GetRegisteredMosaic();
+	if (newWRP != nWRP) {
+	  fprintf (stderr, "only one mosaic allowed in an output file\n");
+	  exit (1);
+	}
+      } else {
+	nWRP = GetRegisteredMosaic();
+	isWRP = TRUE;
+      }
+    }      
+  }
+
+  if (isWRP) {
+    WriteImageFITS (f, &images[nWRP]);
+  } else {
+    // write a blank
+    if (Nmatches > 1) {
+      WriteImageFITS (f, NULL);
+    }
+  }
+
+  for (i = 0; i < Nmatches; i++) {
+    N = matches[i];
+    WriteImageFITS (f, &images[N]);
+  }  
+
+  fclose (f);
+  return TRUE;
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/args.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/args.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/args.c	(revision 13095)
@@ -0,0 +1,136 @@
+# include "getstar.h"
+
+void help () {
+  fprintf (stderr, "USAGE: \n"
+	   "getstar -region ra dec ra dec\n"
+	   "getstar -radius ra dec radius\n"
+	   "getstar -catalog n0000/0000.cpt\n"
+	   "getstar -image name\n"
+	   "getstar -immatch partial-name\n\n"
+	   " option options: \n"
+	   " -o output  : defaults to stdout\n"
+	   " -v         : verbose mode\n"
+	   " -h / -help : this list\n"
+    );
+  exit (2);
+}
+
+int args (int argc, char **argv) {
+  
+  int N;
+
+  /* check for help request */
+  if (get_argument (argc, argv, "-help") ||
+      get_argument (argc, argv, "-h")) {
+    help ();
+  }
+
+  /* configuration info */
+  ConfigInit (&argc, argv);
+
+  /* check for command line options */
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  MagLimitUse = FALSE;
+  if ((N = get_argument (argc, argv, "-maglim"))) {
+    MagLimitUse = TRUE;
+    remove_argument (N, &argc, argv);
+    MagLimitValue = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  /* check for command line options */
+  strcpy (OUTPUT, "stdout");
+  if ((N = get_argument (argc, argv, "-o"))) {
+    remove_argument (N, &argc, argv);
+    strcpy (OUTPUT, argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  /* parse optional entries above. one of the options below is required */
+  MODE = BY_NOTHING;
+  if ((N = get_argument (argc, argv, "-region"))) {
+    double R, D;
+    MODE = BY_REGION;
+    remove_argument (N, &argc, argv);
+    if (argc != 5) help();
+    str_to_radec (&R, &D, argv[N+0], argv[N+1]);
+    REGION.Rmin = R;
+    REGION.Dmin = D;
+    remove_argument (N, &argc, argv);
+    remove_argument (N, &argc, argv);
+
+    str_to_radec (&R, &D, argv[N+0], argv[N+1]);
+    REGION.Rmax = R;
+    REGION.Dmax = D;
+    remove_argument (N, &argc, argv);
+    remove_argument (N, &argc, argv);
+
+    // XXX we will have issues at 0,360 boundary...
+    // see code in dvo/pmeasure for fixes
+    while (REGION.Rmin > 360) REGION.Rmin -= 360.0;
+    while (REGION.Rmin <   0) REGION.Rmin += 360.0;
+    while (REGION.Rmax > 360) REGION.Rmax -= 360.0;
+    while (REGION.Rmax <   0) REGION.Rmax += 360.0;
+    if (REGION.Dmax < REGION.Dmin) {
+	SWAP (REGION.Dmax, REGION.Dmin);
+    }
+  }
+  if ((N = get_argument (argc, argv, "-radius"))) {
+    double R, D, radius;
+    fprintf (stderr, "-radius is not recommended\n");
+    MODE = BY_RADIUS;
+    remove_argument (N, &argc, argv);
+    if (argc != 4) help();
+    str_to_radec (&R, &D, argv[N+0], argv[N+1]);
+    radius = atof(argv[N+2]);
+    REGION.Rmin = R - radius / cos(D*RAD_DEG);
+    REGION.Dmin = D - radius;
+    REGION.Rmax = R + radius / cos(D*RAD_DEG);
+    REGION.Dmax = D + radius;
+    remove_argument (N, &argc, argv);
+    remove_argument (N, &argc, argv);
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-catalog"))) {
+    fprintf (stderr, "-catalog is not implemented\n");
+    exit (2);
+    MODE = BY_CATALOG;
+    remove_argument (N, &argc, argv);
+    if (argc != 2) help();
+  }
+  if ((N = get_argument (argc, argv, "-image"))) {
+    MODE = BY_IMAGE;
+    remove_argument (N, &argc, argv);
+    IMAGENAME = strcreate (argv[N]);
+    if (argc != 2) help();
+  }
+  if ((N = get_argument (argc, argv, "-immatch"))) {
+    MODE = BY_IMMATCH;
+    remove_argument (N, &argc, argv);
+    IMAGENAME = strcreate (argv[N]);
+    if (argc != 2) help();
+  }
+  if (MODE == BY_NOTHING) help ();
+
+  return (TRUE);
+}
+
+
+/* USAGE
+
+getstar -region ra dec ra dec
+getstar -radius ra dec radius
+getstar -catalog n0000/0000.cpt
+getstar -image name [-smp | -smf]
+getstar -immatch partial-name [-smp | -smf]
+   
+* return measurements 
+* return average / secfilt table
+* return a single image (smf/smp format)
+
+*/
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/args_extract.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/args_extract.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/args_extract.c	(revision 13095)
@@ -0,0 +1,38 @@
+# include "dvoImageExtract.h"
+
+void help () {
+  fprintf (stderr, "USAGE: \n"
+	   "dvoExtractImages (imageID) [-o output]\n"
+    );
+  exit (2);
+}
+
+int args_extract (int argc, char **argv) {
+  
+  int N;
+
+  /* check for help request */
+  if (get_argument (argc, argv, "-help") ||
+      get_argument (argc, argv, "-h")) {
+    help ();
+  }
+
+  /* check for command line options */
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  /* check for command line options */
+  OUTFILE = NULL;
+  if ((N = get_argument (argc, argv, "-o"))) {
+    remove_argument (N, &argc, argv);
+    OUTFILE = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 2) help();
+
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/args_overlaps.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/args_overlaps.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/args_overlaps.c	(revision 13095)
@@ -0,0 +1,65 @@
+# include "dvoImageOverlaps.h"
+
+void help () {
+  fprintf (stderr, "USAGE: \n"
+	   "dvoImageOverlaps (image)\n"
+    );
+  exit (2);
+}
+
+int args_overlaps (int argc, char **argv) {
+  
+  int N;
+
+  /* check for help request */
+  if (get_argument (argc, argv, "-help") ||
+      get_argument (argc, argv, "-h")) {
+    help ();
+  }
+
+  /* check for command line options */
+  WITH_PHU = FALSE;
+  if ((N = get_argument (argc, argv, "+phu"))) {
+    WITH_PHU = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  SOLO_PHU = FALSE;
+  if ((N = get_argument (argc, argv, "-phu"))) {
+    WITH_PHU = TRUE;
+    SOLO_PHU = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  /* check for command line options */
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* provide a mosaic for distortion */
+  MOSAIC = NULL;
+  if ((N = get_argument (argc, argv, "-mosaic"))) {
+    Header header;
+    ALLOCATE (MOSAIC, Coords, 1);
+
+    remove_argument (N, &argc, argv);
+    if (!gfits_read_header (argv[N], &header)) {
+      fprintf (stderr, "ERROR: can't read header for mosaic %s\n", argv[N]);
+      exit (1);
+    }
+    if (!GetCoords (MOSAIC, &header)) {
+      fprintf (stderr, "ERROR: no astrometric solution in header\n");
+      exit (1);
+    }
+    if (strcmp(&MOSAIC[0].ctype[4], "-DIS")) {
+      fprintf (stderr, "ERROR: not a mosaic distortion header\n");
+      exit (1);
+    }
+    remove_argument (N, &argc, argv);
+    gfits_free_header (&header);
+  }
+
+  if (argc != 2) help();
+
+  return (TRUE);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/dvoImageExtract.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/dvoImageExtract.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/dvoImageExtract.c	(revision 13095)
@@ -0,0 +1,51 @@
+# include "dvoImageExtract.h"
+
+int main (int argc, char **argv) {
+
+  int i, Nimages, status;
+  int Nmatches, *matches;
+  Image *images;
+  Catalog catalog;
+  FITS_DB db;
+
+  SetSignals ();
+  ConfigInit_extract (&argc, argv);
+  args_extract (argc, argv);
+
+  /*** update the image table ***/
+  /* setup image table format and lock */
+  db.mode   = dvo_catalog_catmode (CATMODE);
+  db.format = dvo_catalog_catformat (CATFORMAT);
+  status    = dvo_image_lock (&db, ImageCat, 3600.0, LCK_SOFT);  // shorter timeout?
+  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
+
+  /* load or create the image table */
+  if (db.dbstate == LCK_EMPTY) {
+    fprintf (stderr, "no images in database (%s)\n", ImageCat);
+    exit (1);
+  } else {
+    if (!dvo_image_load (&db, VERBOSE, FALSE)) {
+      Shutdown ("can't read image catalog %s", db.filename);
+    }
+  }
+  dvo_image_unlock (&db);
+
+  // convert database table to internal structure
+  images = gfits_table_get_Image (&db.ftable, &Nimages, &db.swapped);
+  
+  matches = SelectImages (argv[1], images, Nimages, &Nmatches);
+  WriteImages (OUTFILE, images, Nimages, matches, Nmatches);
+
+  exit (0);
+}
+
+/* This program extracts images headers from a DVO database and writes them 
+   in cmf format (headers + object tables).
+
+   If multiple images are selected, they must be from the same exposures (how?).
+
+   If images are selected with WRP astrometry, the associated DIS image header is first written to
+   the output file.
+ 
+   USAGE: dvoExtractImages (imageID[s]) -o output.cmf
+*/
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/dvoImageOverlaps.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/dvoImageOverlaps.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/dvoImageOverlaps.c	(revision 13095)
@@ -0,0 +1,45 @@
+# include "dvoImageOverlaps.h"
+
+int main (int argc, char **argv) {
+
+  int i, Nimages, NdbImages, status;
+  int Nmatches, *matches;
+  Image *images, *dbImages;
+  Catalog catalog;
+  FITS_DB db;
+
+  SetSignals ();
+  ConfigInit_overlaps (&argc, argv);
+  args_overlaps (argc, argv);
+  
+  images = ReadImageFiles (argv[1], &Nimages); 
+
+  /*** update the image table ***/
+  /* setup image table format and lock */
+  db.mode   = dvo_catalog_catmode (CATMODE);
+  db.format = dvo_catalog_catformat (CATFORMAT);
+  status    = dvo_image_lock (&db, ImageCat, 3600.0, LCK_SOFT);  // shorter timeout?
+  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
+
+  /* load or create the image table */
+  if (db.dbstate == LCK_EMPTY) {
+    fprintf (stderr, "no images in database (%s)\n", ImageCat);
+    exit (1);
+  } else {
+    if (!dvo_image_load (&db, VERBOSE, FALSE)) {
+      Shutdown ("can't read image catalog %s", db.filename);
+    }
+  }
+  dvo_image_unlock (&db);
+
+  // convert database table to internal structure
+  dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.swapped);
+  
+  // for (i = 1; i < 2; i++) {
+  for (i = 0; i < Nimages; i++) {
+    matches = MatchImage (dbImages, NdbImages, &images[i], &Nmatches);
+    ListImageOverlaps (dbImages, &images[i], matches, Nmatches);
+  }
+
+  exit (0);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/edge_check.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/edge_check.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/edge_check.c	(revision 13095)
@@ -0,0 +1,36 @@
+# include "dvoImageOverlaps.h"
+
+int edge_check (double *x1, double *y1, double *x2, double *y2) {
+
+  double theta1, theta2;
+  double Theta1, Theta2;
+
+  theta1 = opening_angle (x1[0], y1[0], x2[0], y2[0], x1[1], y1[1]); 
+  theta2 = opening_angle (x1[0], y1[0], x2[0], y2[0], x2[1], y2[1]); 
+
+  if (theta1*theta2 < 0.0) {
+    return (FALSE);
+  }
+
+  if (fabs(theta1) < fabs(theta2)) {
+    return (FALSE);
+  }
+
+  Theta1 = theta1;
+  Theta2 = theta2;
+  theta1 = opening_angle (x2[0], y2[0], x1[1], y1[1], x2[1], y2[1]); 
+  theta2 = opening_angle (x2[0], y2[0], x1[1], y1[1], x1[0], y1[0]); 
+  
+ 
+  if (theta1*theta2 < 0.0) {
+    return (FALSE);
+  }
+
+  if (fabs(theta1) < fabs(theta2)) {
+    return (FALSE);
+  }
+
+  return (TRUE);
+
+}
+
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/getstar.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/getstar.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/getstar.c	(revision 13095)
@@ -0,0 +1,99 @@
+# include "getstar.h"
+
+int main (int argc, char **argv) {
+
+  int i;
+  SkyTable *sky;
+  SkyList *skylist;
+  Catalog catalog;
+  Catalog output;
+  FITS_DB db;
+
+  args (argc, argv);
+  set_db (&db);
+
+  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  // create an output catalog with the desired name and format options
+  output.filename  = OUTPUT;
+  output.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
+  output.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
+  output.Nsecfilt  = GetPhotcodeNsecfilt ();
+  dvo_catalog_open (&output, NULL, VERBOSE, "w");
+
+  switch (MODE) {
+
+    case BY_REGION:
+    case BY_RADIUS:
+
+      /* load corresponding sky regions */
+      skylist = SkyListByPatch (sky, -1, &REGION);
+      for (i = 0; i < skylist[0].Nregions; i++) {
+	// set the parameters which guide catalog open/load/create
+	catalog.filename = skylist[0].filename[i];
+	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+
+	// an error exit status here is a significant error
+	if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
+	  fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+	  exit (2);
+	}
+	if (!catalog.Nave_disk) {
+	  dvo_catalog_unlock (&catalog);
+	  dvo_catalog_free (&catalog);
+	  continue;
+	}
+	dvo_catalog_unlock (&catalog);
+
+	/* skip empty catalogs */
+	select_by_region (&output, &catalog, &REGION, 0, 0);
+      }
+      break;
+
+    case BY_IMLIST:
+      /* load image list */
+    case BY_IMAGE:
+
+      # if (0)
+      /* load corresponding sky regions */
+      skylist = SkyListByImage (sky, -1, &image, &Nimage);
+      for (i = 0; i < skylist[0].Nregions; i++) {
+	// set the parameters which guide catalog open/load/create
+	catalog.filename = skylist[0].filename[i];
+	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+
+	// an error exit status here is a significant error
+	if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
+	  fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+	  exit (2);
+	}
+	/* skip empty catalogs */
+	if (!catalog.Nave_disk) continue;
+	stars = select_by_image (&catalog, &image, 0, 0, stars, &Nstars);
+      }
+      # endif
+      fprintf (stderr, "error: BY_IMAGE not implemented\n");
+      exit (1);
+      break;
+
+    case BY_CATALOG:
+      fprintf (stderr, "error: BY_CATALOG not implemented\n");
+      exit (1);
+      break;
+      
+    default:
+      fprintf (stderr, "error: invalid options\n");
+      exit (1);
+  }
+
+  /* write out the selected stars */
+  // XXX need to set the catalog boundaries by hand? RA0-RA1, DEC0-DEC1
+  dvo_catalog_save (&output, VERBOSE);
+  dvo_catalog_unlock (&output);
+  dvo_catalog_free (&output);
+  fprintf (stderr, "SUCCESS\n");
+  exit (0);
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/opening_angle.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/opening_angle.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/opening_angle.c	(revision 13095)
@@ -0,0 +1,20 @@
+# include "dvoImageOverlaps.h"
+
+double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  double dx1, dy1, dx2, dy2, ct, st, theta;
+
+  dx1 = x1 - x2;
+  dy1 = y1 - y2;
+  
+  dx2 = x3 - x2;
+  dy2 = y3 - y2;
+  
+  ct = (dx1*dx2 + dy1*dy2);
+  st = (dx1*dy2 - dx2*dy1);
+
+  theta = atan2 (st, ct);
+
+  return (theta);
+
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/parse_time.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/parse_time.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/parse_time.c	(revision 13095)
@@ -0,0 +1,146 @@
+# include "addstar.h"
+
+int parse_time (Header *header) {
+
+  double jd;
+  int Ny, Nf, mode;
+  int Nsec, hour, min, sec, year, month, day;
+  char *py, *pm, *pd, *c;
+  char line[256];
+
+  /* we want to find JD or MJD to get Nsec (seconds since 01/01/1970) */
+
+  /* try JD first */
+  if (strcasecmp (JDKeyword, "NONE")) {
+    uppercase (JDKeyword);
+    if (!gfits_scan (header, JDKeyword, "%lf", 1, &jd)) {
+      fprintf (stderr, "ERROR: missing JD Keyword %s\n", JDKeyword);
+      exit (1);
+    }
+    Nsec = (jd - 2440587.5)*86400;
+    return (Nsec);
+  }
+
+  /* try MJD next */
+  if (strcasecmp (MJDKeyword, "NONE")) {
+    uppercase (MJDKeyword);
+    if (!gfits_scan (header, MJDKeyword, "%lf", 1, &jd)) {
+      fprintf (stderr, "ERROR: missing MJD Keyword %s\n", MJDKeyword);
+      exit (1);
+    }
+    Nsec = (jd - 40587.0)*86400;
+    return (Nsec);
+  }
+    
+  if (!strcasecmp (UTKeyword, "NONE")) {
+      fprintf (stderr, "ERROR: no valid Date/Time keywords\n");
+      exit (1);
+  }
+  if (!strcasecmp (DateKeyword, "NONE")) {
+      fprintf (stderr, "ERROR: no valid Date/Time keywords\n");
+      exit (1);
+  }
+  if (!strcasecmp (DateMode, "NONE")) {
+      fprintf (stderr, "ERROR: no valid Date/Time keywords\n");
+      exit (1);
+  }
+
+  /* get UT and DATE */
+  uppercase (UTKeyword);
+  if (!gfits_scan (header, UTKeyword, "%s", 1, line)) {
+      fprintf (stderr, "ERROR: missing UT Keyword %s\n", UTKeyword);
+      exit (1);
+    }
+  /* remove ':' characters */
+  for (c = strchr (line, 0x3a); c != (char *) NULL; c = strchr (line, 0x3a)) { *c = ' '; }
+  sscanf (line, "%d %d %d", &hour, &min, &sec);
+
+  /* parse mode line */
+  uppercase (DateMode);
+  for (Ny = 0, c = strchr (DateMode, 'Y'); c != (char ) NULL; c = strchr (c + 1, 'Y'), Ny++);
+  if ((Ny != 2) && (Ny != 4)) {
+    fprintf (stderr, "error in DATE-MODE format: %s\n", DateMode);
+    exit (1);
+  }
+  py = strchr (DateMode, 'Y');
+  pm = strchr (DateMode, 'M');
+  pd = strchr (DateMode, 'D');
+  if ((py == (char *) NULL) || (pm == (char *) NULL) || (pd == (char *) NULL)) {
+    fprintf (stderr, "error in DATE-MODE format: %s\n", DateMode);
+    exit (1);
+  }
+  if ((py > pm) && (py < pd)) {
+    fprintf (stderr, "error in DATE-MODE format: %s\n", DateMode);
+    exit (1);
+  }
+  if ((py > pd) && (py < pm)) {
+    fprintf (stderr, "error in DATE-MODE format: %s\n", DateMode);
+    exit (1);
+  }
+  mode = 0;
+  if ((py < pm) && (pm < pd)) { mode = 1; }  /* yyyy-mm-dd */
+  if ((py < pm) && (pm > pd)) { mode = 2; }  /* yyyy-dd-mm */
+  if ((py > pm) && (pm < pd)) { mode = 3; }  /* mm-dd-yyyy */
+  if ((py > pm) && (pm > pd)) { mode = 4; }  /* dd-mm-yyyy */
+  if (!mode) {
+    fprintf (stderr, "error in DATE-MODE format: %s\n", DateMode);
+    exit (1);
+  }
+
+  /* parse date entry */
+  uppercase (DateKeyword);
+  if (!gfits_scan (header, DateKeyword, "%s",  1, line)) {
+    fprintf (stderr, "ERROR: missing DATE Keyword %s\n", DateKeyword);
+    exit (1);
+  }
+  /* remove possible separators: ':', '/' '.', '-' */
+  for (c = strchr (line, 0x3a); c != (char *) NULL; c = strchr (line, 0x3a)) { *c = ' '; }
+  for (c = strchr (line, 0x2f); c != (char *) NULL; c = strchr (line, 0x2f)) { *c = ' '; }
+  for (c = strchr (line, 0x2e); c != (char *) NULL; c = strchr (line, 0x2e)) { *c = ' '; }
+  for (c = strchr (line, 0x2d); c != (char *) NULL; c = strchr (line, 0x2d)) { *c = ' '; }
+
+  Nf = 0;
+  switch (mode) {
+  case 1:
+    Nf = sscanf (line, "%d %d %d", &year, &month, &day);
+    break;
+  case 2:
+    Nf = sscanf (line, "%d %d %d", &year, &day, &month);
+    break;
+  case 3:
+    Nf = sscanf (line, "%d %d %d", &month, &day, &year);
+    break;
+  case 4:
+    Nf = sscanf (line, "%d %d %d", &day, &month, &year);
+    break;
+  }
+  if (Nf != 3) {
+    fprintf (stderr, "error in date entry (%s) or DATE-MODE format (%s)\n", line, DateMode);
+    exit (1);
+  }
+
+  if (year > 1000) {
+    if (Ny == 2) {
+      fprintf (stderr, "warning: mode line claims 2 digit year, but 4 digit year found\n");
+    }
+  } else {
+    if (Ny == 4) {
+      fprintf (stderr, "warning: mode line claims 4 digit year, but 2 digit year found\n");
+    }
+    if (year < 50) year += 100;
+    year += 1900;
+  }    
+
+  /* this should probably use localtime */
+
+  /* convert yy.mm.dd hh.mm.ss to Nsec since 1970 (jd = 2440587.5) */
+  /* note that in this section, tm_mon has range 1-12, unlike for gmtime () */
+  jd = day - 32075 + (int)(1461*(year + 4800 + (int)(((month)-14)/12))/4)
+    + (int)(367*((month) - 2 - (int)(((month) - 14)/12)*12)/12)
+    - (int)(3*(int)((year + 4900 + (int)(((month) - 14)/12))/100)/4) - 0.5;
+  /* jd is the julian day of the whole day only not the time */
+  Nsec = (jd - 2440587.5)*86400 + 3600.0*hour + min*60.0 + sec;
+  
+  return (Nsec);
+
+}
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/select_by_image.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/select_by_image.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/select_by_image.c	(revision 13095)
@@ -0,0 +1,57 @@
+# include "getstar.h"
+
+Stars *select_by_image (Catalog *catalog, Image *image, int start, int end, Stars *stars, int *Nstar) {
+
+  int i, n, N, NSTARS;
+  int photcode;
+
+  if (stars == (Stars *) NULL) {
+    N = 0;
+    NSTARS = 1000;
+    ALLOCATE (stars, Stars, NSTARS);
+  } else {
+    N = *Nstar;
+    NSTARS = N + 1000;
+    REALLOCATE (stars, Stars, NSTARS);
+  }    
+
+  /* identify selection criteria */
+  photcode = -1;
+  if ((start == 0) && (end == 0)) {
+    start = image[0].tzero;
+    end   = image[0].tzero + 1e-4*image[0].NY*image[0].trate;  /* trate is in 0.1 msec / row */
+    photcode = image[0].photcode;
+  }
+  if (VERBOSE) fprintf (stderr, "extracting for range %d to %d (photcode %s)\n", start, end, photcode);
+
+  for (i = 0; (i < catalog[0].Nmeasure); i++) {
+    if ((i % 10000) == 0) fprintf (stderr, ". ");
+    if ((catalog[0].measure[i].t >= start) && (catalog[0].measure[i].t <= end) && (photcode == catalog[0].measure[i].photcode)) { 
+      n = catalog[0].measure[i].averef;
+      stars[N].R      = catalog[0].average[n].R - catalog[0].measure[i].dR / 360000.0;
+      stars[N].D      = catalog[0].average[n].D - catalog[0].measure[i].dD / 360000.0;
+
+      stars[N].M      = 0.001*(catalog[0].measure[i].M - catalog[0].measure[i].dt);
+      stars[N].dM     = catalog[0].measure[i].dM;
+      stars[N].dophot = catalog[0].measure[i].dophot;  
+
+      stars[N].Mgal   = 0.001*(catalog[0].measure[i].Mgal - catalog[0].measure[i].dt);
+
+      stars[N].fx     = 0.01*catalog[0].measure[i].FWx;
+      stars[N].fy     = stars[N].fx * 0.01*catalog[0].measure[i].fwy;
+      stars[N].df     = (360.0/255.0)*catalog[0].measure[i].theta;
+      stars[N].found  = catalog[0].measure[i].flags;
+
+      N ++;
+      if (N == NSTARS) {
+	NSTARS += 1000;
+	REALLOCATE (stars, Stars, NSTARS);
+      }    
+
+    } 
+  }
+  fprintf (stderr, "found %d meas\n", N);
+  *Nstar = N;
+  return (stars);
+}
+
Index: /tags/getstar-1-5-0/Ohana/src/getstar/src/select_by_region.c
===================================================================
--- /tags/getstar-1-5-0/Ohana/src/getstar/src/select_by_region.c	(revision 13095)
+++ /tags/getstar-1-5-0/Ohana/src/getstar/src/select_by_region.c	(revision 13095)
@@ -0,0 +1,72 @@
+# include "getstar.h"
+
+/* add selected catalog objects to the output catalog */
+int select_by_region (Catalog *output, Catalog *catalog, SkyRegion *region, int start, int end) {
+
+  int i, j, n, Nm, offset, Nsecfilt;
+  int Nave, NAVE, Nmeas, NMEAS;
+  double R, D;
+
+  Nsecfilt = output[0].Nsecfilt;
+
+  if (output == NULL) Shutdown ("output not defined");
+
+  /* identify selection criteria */
+  if (VERBOSE) fprintf (stderr, "extracting for time range %d to %d\n", start, end);
+  if (VERBOSE) fprintf (stderr, "extracting for region %f,%f to %f,%f\n", 
+			region[0].Rmin, region[0].Dmin, region[0].Rmax, region[0].Dmax);
+
+  /* select the average objects in this region */
+  Nave = output[0].Naverage;
+  NAVE = output[0].Naverage + 1000;
+  REALLOCATE (output[0].average, Average, NAVE);
+  REALLOCATE (output[0].secfilt, SecFilt, NAVE*Nsecfilt);
+
+  Nmeas = output[0].Nmeasure;
+  NMEAS = output[0].Nmeasure + 1000;
+  REALLOCATE (output[0].measure, Measure, NMEAS);
+
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    n = catalog[0].measure[i].averef;
+
+    R = catalog[0].average[i].R;
+    D = catalog[0].average[i].D;
+    
+    if (R < region[0].Rmin) continue;
+    if (R > region[0].Rmax) continue;
+    if (D < region[0].Dmin) continue;
+    if (D > region[0].Dmax) continue;
+
+    /* XXX add photcode as argument to MagLimitUse */
+    if (MagLimitUse && (catalog[0].secfilt[Nsecfilt*i].M > MagLimitValue)) continue;
+
+    output[0].average[Nave] = catalog[0].average[i];
+    output[0].average[Nave].offset = Nmeas;
+    for (j = 0; j < Nsecfilt; j++) {
+      output[0].secfilt[Nsecfilt*Nave + j] = catalog[0].secfilt[Nsecfilt*i + j];
+    }
+
+    Nm = 0;
+    offset = catalog[0].average[i].offset;
+
+    for (j = 0; j < catalog[0].average[i].Nm; j++) {
+      output[0].measure[Nmeas] = catalog[0].measure[offset + j];
+      output[0].measure[Nmeas].averef = Nave;
+      Nmeas ++;
+      
+      CHECK_REALLOCATE (output[0].measure, Measure, NMEAS, Nmeas, 1000);
+    }      
+
+    Nave ++;
+    if (Nave == NAVE) {
+      NAVE += 1000;
+      REALLOCATE (output[0].average, Average, NAVE);
+      REALLOCATE (output[0].secfilt, SecFilt, NAVE*Nsecfilt);
+    }
+  }
+  output[0].Naverage = Nave;
+  output[0].Nmeasure = Nmeas;
+  fprintf (stderr, "output catalog has %d stars (%d measures, %d secfilt)\n",
+	   output[0].Naverage, output[0].Nmeasure, output[0].Nsecfilt);
+  return (TRUE);
+}
