Index: /trunk/Ohana/src/getstar/Makefile
===================================================================
--- /trunk/Ohana/src/getstar/Makefile	(revision 6967)
+++ /trunk/Ohana/src/getstar/Makefile	(revision 6968)
@@ -19,10 +19,15 @@
 
 GETSTAR = \
-$(SRC)/getstar.$(ARCH).o 	$(SRC)/gcatalog.$(ARCH).o 	\
-$(SRC)/gregions.$(ARCH).o 	$(SRC)/gimages.$(ARCH).o        \
-$(SRC)/wstars.$(ARCH).o   	$(SRC)/find_matches.$(ARCH).o 	\
-$(SRC)/sort_lists.$(ARCH).o 	$(SRC)/ConfigInit.$(ARCH).o 	\
-$(SRC)/aregion.$(ARCH).o	$(SRC)/clean_stars.$(ARCH).o	\
-$(SRC)/args.$(ARCH).o
+$(SRC)/getstar.$(ARCH).o 	 \
+$(SRC)/args.$(ARCH).o		 \
+$(SRC)/ConfigInit.$(ARCH).o 	 \
+$(SRC)/Shutdown.$(ARCH).o	 \
+$(SRC)/SetSignals.$(ARCH).o	 \
+$(SRC)/gcatalog.$(ARCH).o 	 \
+$(SRC)/load_pt_catalog.$(ARCH).o \
+$(SRC)/select_by_region.$(ARCH).o \
+$(SRC)/wcatalog.$(ARCH).o        \
+$(SRC)/init_catalog.$(ARCH).o    \
+$(SRC)/mkcatalog.$(ARCH).o
 
 OBJ = $(GETSTAR)
Index: /trunk/Ohana/src/getstar/include/getstar.h
===================================================================
--- /trunk/Ohana/src/getstar/include/getstar.h	(revision 6967)
+++ /trunk/Ohana/src/getstar/include/getstar.h	(revision 6968)
@@ -10,57 +10,31 @@
   BY_IMAGE,
   BY_IMMATCH,
+  BY_IMLIST,
 };
 
-# if (0)
-typedef struct {
-  double X;
-  double Y;
-  double R;
-  double D;
-  double M, dM;
-  char   dophot;
-  double sky;
-  double fx, fy, df;
-  double Mgal, Map;
-  int found;
-} Stars;
-# endif
+int       VERBOSE;
+int       MODE;
+SkyRegion REGION;
+char     *IMAGENAME;
 
-/* global variables set in parameter file */
-# if (0)
-char   ImageCat[256];
-char   ImageTemplate[256];
-char   CatTemplate[256];
-char   GSCFILE[256];
-char   CATDIR[256];
-char   CATMODE[16];    /* raw, mef, split, mysql */
-char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
-double DEFAULT_RADIUS, NSIGMA, SNLIMIT;
-double ZeroPt;
-int    SKIP_MISSED;
-int    XOVERSCAN, YOVERSCAN;
-int    XMIN, XMAX, YMIN, YMAX;
-int    ACCEPT_ASTROM;
-# endif
+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    VERBOSE;
-int    MODE;
-SkyRegion REGION;
-char *IMAGENAME;
-
-PhotCode *thiscode;
-
-char DateKeyword[64];
-char DateMode[64];
-char UTKeyword[64];
-char MJDKeyword[64];
-char JDKeyword[64];
-char ExptimeKeyword[64];
-char AirmassKeyword[64];
-char CCDNumKeyword[64];
-
-int CalReference;
-int CalColor;
-int CALIBRATE;
-int DUMP_MATCHES;
-int ONLY_IMAGES;
+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: /trunk/Ohana/src/getstar/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/getstar/src/ConfigInit.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/ConfigInit.c	(revision 6968)
@@ -1,8 +1,7 @@
 # include "getstar.h"
 
-ConfigInit (int *argc, char **argv) {
+int ConfigInit (int *argc, char **argv) {
 
   char *config, *file;
-  char RadiusWord[80];
   char PhotCodeFile[256];
 
@@ -17,41 +16,15 @@
   if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
 
-  ScanConfig (config, "RADIUS",                 "%s", 0,  RadiusWord);
-  if (!strcasecmp (RadiusWord, "header")) {
-    DEFAULT_RADIUS = 0;
-  } else {
-    DEFAULT_RADIUS = atof (RadiusWord);
-  }
-
-  XMIN = XMAX = YMIN = YMAX = 0;
-  ScanConfig (config, "NSIGMA",                 "%lf", 0, &NSIGMA);
-  ScanConfig (config, "XOVERSCAN",              "%d", 0, &XOVERSCAN);
-  ScanConfig (config, "YOVERSCAN",              "%d", 0, &YOVERSCAN);
-  ScanConfig (config, "ZERO_PT",                "%lf", 0, &ZeroPt);
-
-  ScanConfig (config, "ADDSTAR_XMIN",           "%d", 0, &XMIN);
-  ScanConfig (config, "ADDSTAR_XMAX",           "%d", 0, &XMAX);
-  ScanConfig (config, "ADDSTAR_YMIN",           "%d", 0, &YMIN);
-  ScanConfig (config, "ADDSTAR_YMAX",           "%d", 0, &YMAX);
-
-  ScanConfig (config, "IMAGE_CATALOG",          "%s", 0, ImageCat);
-  ScanConfig (config, "IMAGE_CATALOG_TEMPLATE", "%s", 0, ImageTemplate);
-  ScanConfig (config, "CATALOG_TEMPLATE",       "%s", 0, CatTemplate);
   ScanConfig (config, "GSCFILE",                "%s", 0, GSCFILE);
   ScanConfig (config, "CATDIR",                 "%s", 0, CATDIR);
   ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
-  ScanConfig (config, "MIN_SN_FSTAT",           "%lf", 0, &SNLIMIT);
   ScanConfig (config, "PHOTCODE_FILE",          "%s", 0, PhotCodeFile);
-
-  ScanConfig (config, "DATE-KEYWORD",           "%s", 0, DateKeyword);
-  ScanConfig (config, "DATE-MODE",              "%s", 0, DateMode);
-  ScanConfig (config, "UT-KEYWORD",             "%s", 0, UTKeyword);
-  ScanConfig (config, "MJD-KEYWORD",            "%s", 0, MJDKeyword);
-  ScanConfig (config, "JD-KEYWORD",             "%s", 0, JDKeyword);
-
-  ScanConfig (config, "EXPTIME-KEYWORD",        "%s", 0, ExptimeKeyword);
-  ScanConfig (config, "AIRMASS-KEYWORD",        "%s", 0, AirmassKeyword);
-  ScanConfig (config, "CCDNUM-KEYWORD",         "%s", 0, CCDNumKeyword);
+  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");
@@ -66,3 +39,4 @@
   free (file);
 
+  return (TRUE);
 }
Index: /trunk/Ohana/src/getstar/src/SetSignals.c
===================================================================
--- /trunk/Ohana/src/getstar/src/SetSignals.c	(revision 6968)
+++ /trunk/Ohana/src/getstar/src/SetSignals.c	(revision 6968)
@@ -0,0 +1,118 @@
+# 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 this signals */
+    case SIGKILL:    /* kill -9: cannot be caught or ignored */
+    case SIGSTOP:    /* SIGSTOP: cannot be caught or ignored */
+      /* ignore these signals */
+    case SIGCHLD:    /* child halted: ignore */
+    case SIGPWR:     /* power failure - why ignore this? */
+    case SIGWINCH:   /* window resized */
+    case SIGCONT:    /* continue - maintain this action */
+    case SIGTSTP:    /* stop signal sent from tty - why ignore? */
+    case SIGURG:     /* socket signal, ignore this */
+      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: unk/Ohana/src/getstar/src/aregion.c
===================================================================
--- /trunk/Ohana/src/getstar/src/aregion.c	(revision 6967)
+++ 	(revision )
@@ -1,112 +1,0 @@
-# include "getstar.h"
-
-double BigDecBounds[] = {0.0, 7.5, 15.0, 22.5, 30.0, 37.5, 45.0, 
-			 52.5, 60.0, 67.5, 75.0, 82.5, 90.0,
-			 0.0, -7.5, -15.0, -22.5, -30.0, -37.5, -45.0, 
-			 -52.5, -60.0, -67.5, -75.0, -82.5, -90.0};
-char *DecSections[] = {"N0000", "N0730", "N1500", "N2230", "N3000", "N3730", "N4500", 
-		       "N5230", "N6000", "N6730", "N7500", "N8230", "weirdness", 
-		       "S0000", "S0730", "S1500", "S2230", "S3000", "S3730", "S4500", 
-		       "S5230", "S6000", "S6730", "S7500", "S8230", "weirdness"};
-
-char *Dec2Sections[] = {"n0000", "n0730", "n1500", "n2230", "n3000", "n3730", "n4500", 
-			"n5230", "n6000", "n6730", "n7500", "n8230", "weirdness", 
-			"s0000", "s0730", "s1500", "s2230", "s3000", "s3730", "s4500", 
-			"s5230", "s6000", "s6730", "s7500", "s8230", "weirdness"};
-
-char *disk[] = {"disk 1", "disk 1", "disk 1", "disk 1", "disk 1", "disk 1", "disk 1", 
-		"disk 1", "disk 1", "disk 1", "disk 1", "disk 1", "weirdness", 
-		"disk 1", "disk 2", "disk 2", "disk 2", "disk 2", "disk 2", "disk 2", 
-		"disk 2", "disk 2", "disk 2", "disk 2", "disk 2", "weirdness"};
-
-int NBigRASections [] = {48, 47, 45, 43, 40, 36, 32, 28, 21, 15, 9, 3, 3, 48, 47, 45, 43, 40, 36, 32, 28, 21, 15, 9, 3, 3};
-
-int NDecLines[] = {593, 584, 551, 530, 522, 465, 406, 362, 280, 198, 123, 24, 
-                   0, 597, 578, 574, 577, 534, 499, 442, 376, 294, 212, 144, 48};
-
-# define DEBUG 1
-
-/* find region file which contains ra, dec */
-aregion (region, f, ra, dec) 
-GSCRegion region[];
-FILE *f;
-double ra, dec;
-{
-  
-  
-  char buffer[28800], temp[50], file[256];
-  double dr, dd;
-  double RA0, RA1, DEC0, DEC1;
-  int i, NBigDec, NLINES, done, nregion;
-  
-  while (ra < 0) { ra += 360.0; }
-  while (ra >= 360.0) { ra -= 360.0; }
-
-  if (dec >= 86.25) {
-    sprintf (file, "%s/n8230/pole.cpt\0", CATDIR);
-    region[0].DEC[0] = 86.25;
-    region[0].DEC[1] = 93.75;
-    region[0].RA[0] =  0.0;
-    region[0].RA[1] =  360.0;
-    strcpy (region[0].filename, file);
-    return;
-  }
-    
-  NBigDec = -1;
-  for (i = 0; i < 12; i++) {
-    if ((dec >= BigDecBounds[i]) && (dec < BigDecBounds[i+1])) {
-      NBigDec = i;
-      break;
-    }
-  }
-  if (NBigDec < 0) {
-    for (i = 13; i < 24; i++) {
-      if ((dec < BigDecBounds[i]) && (dec >= BigDecBounds[i+1])) {
-	NBigDec = i;
-	break;
-      }
-    }
-  }
-  if (NBigDec < 0) {
-    fprintf (stderr, "dec out of range: %f\n", dec);
-  }
-    
-  NLINES = 0;
-  for (i = 0; i < NBigDec; i++) {
-    NLINES += NDecLines[i];
-  }
-  fseek (f, 5*2880 + 48*NLINES, SEEK_SET);
-      
-  done = FALSE;
-  fread (buffer, 1, 48*NDecLines[NBigDec], f);
-  for (i = 0; !done && (i < NDecLines[NBigDec]); i++) {
-    strncpy (temp, &buffer[i*48], 48);
-    temp[49] = 0;
-    hstgsc_hms_to_deg (&RA0, &RA1, &DEC0, &DEC1, &temp[7]);
-    if (RA1 < RA0) RA1 += 360.0;
-    if ((dec >= 0) && (dec >= DEC0) && (dec < DEC1) && (ra >= RA0) && (ra < RA1)) {
-      done = TRUE;
-    }
-    if ((dec < 0) && (dec < DEC0) && (dec >= DEC1) && (ra >= RA0) && (ra < RA1)) {
-      done = TRUE;
-    }
-  }
-
-  if (!done) {
-    fprintf (stderr, "error in search: %f %f\n", ra, dec);
-    exit (1);
-  }
-  temp[5] = 0;
-  sprintf (file, "%s/%s/%s.cpt\0", CATDIR, Dec2Sections[NBigDec], &temp[1]);
-  if (DEC0 < DEC1) {
-    region[0].DEC[0] = DEC0;
-    region[0].DEC[1] = DEC1;
-  } else {
-    region[0].DEC[0] = DEC1;
-    region[0].DEC[1] = DEC0;
-  }     
-  region[0].RA[0] = RA0;
-  region[0].RA[1] = RA1;
-  strcpy (region[0].filename, file);
-  return;
-}
Index: /trunk/Ohana/src/getstar/src/args.c
===================================================================
--- /trunk/Ohana/src/getstar/src/args.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/args.c	(revision 6968)
@@ -8,10 +8,9 @@
 	   "getstar -image name\n"
 	   "getstar -immatch partial-name\n\n"
-	   "other options:\n"
-	   " -smf  (file)    : return smf file (-image only)\n"
-	   " -smp (file)     : return smp file (-image only)\n"
-	   " -meas (file)    : return measurements\n"
-	   " -aves (file)    : return average / secfilt table *default*\n"
-	   " -imtable (file) : return image table\n");
+	   " option options: \n"
+	   " -o output  : defaults to stdout\n"
+	   " -v         : verbose mode\n"
+	   " -h / -help : this list\n"
+    );
   exit (2);
 }
@@ -34,4 +33,12 @@
   if ((N = get_argument (argc, argv, "-v"))) {
     VERBOSE = TRUE;
+    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);
   }
@@ -92,4 +99,5 @@
   }
   if (MODE == BY_NOTHING) help ();
+  return (TRUE);
 }
 
Index: unk/Ohana/src/getstar/src/clean_stars.c
===================================================================
--- /trunk/Ohana/src/getstar/src/clean_stars.c	(revision 6967)
+++ 	(revision )
@@ -1,63 +1,0 @@
-# include "getstar.h"
-
-int clean_stars (Stars *stars, int *nstars, Image *image) {
-
-  int i, j, Nsubset, *subset, *skip, *found, Nstars, check, Nskip;
-  double Xo, Yo, Xt, Yt, radius;
-  double Mo, Mt, dM;
-
-  Nstars = *nstars;
-  ALLOCATE (found,  int, Nstars);
-  ALLOCATE (subset, int, Nstars);
-  ALLOCATE (skip,   int, Nstars);
-  bzero (skip, Nstars*sizeof(int));
-
-  Nskip = 0;
-  Nsubset = 0;
-  for (i = 0; i < Nstars; i++) {
-    RD_to_XY (&stars[i].X, &stars[i].Y, stars[i].R, stars[i].D, &image[0].coords);
-    check = (stars[i].found & BLEND_IMAGE) || (stars[i].found & BLEND_IMAGE_NEIGHBOR) || (stars[i].found & BLEND_CATALOG);
-    if (check) {
-      subset[Nsubset] = i;
-      found[Nsubset] = FALSE;
-      Nsubset ++;
-    }
-  }
-
-  if (Nsubset > 1) {
-    for (i = 0; i < Nsubset; i++) {
-      if (found[i]) continue;
-      Xo = stars[subset[i]].X;
-      Yo = stars[subset[i]].Y;
-      Mo = stars[subset[i]].M;
-      for (j = 0; j < Nsubset; j++) {
-	if (j == i) continue;
-	if (found[j]) continue;
-	Xt = stars[subset[j]].X;
-	Yt = stars[subset[j]].Y;
-	Mt = stars[subset[j]].M;
-	radius = hypot ((Xo-Xt), (Yo-Yt));
-	dM = fabs (Mo-Mt);
-	if ((radius < 5.0) && (dM < 0.005)) {
-	  skip[subset[j]] = TRUE;
-	  found[j] = TRUE;
-	  Nskip ++;
-	}
-      }
-      found[i] = TRUE;
-    }
- 
-    for (i = j = 0; i < Nstars; i++) {
-      if (skip[i]) continue;
-      if (i == j) { 
-	j++;
-	continue;
-      }
-      stars[j] = stars[i];
-      j++;
-    }
-    *nstars = j;
-  }
-  fprintf (stderr, "%d skipped\n", Nskip);
-}
-
Index: unk/Ohana/src/getstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/getstar/src/find_matches.c	(revision 6967)
+++ 	(revision )
@@ -1,57 +1,0 @@
-# include "getstar.h"
-
-Stars *find_matches (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].source;
-  }
-  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].source)) { 
-      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: /trunk/Ohana/src/getstar/src/gcatalog.c
===================================================================
--- /trunk/Ohana/src/getstar/src/gcatalog.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/gcatalog.c	(revision 6968)
@@ -4,12 +4,9 @@
   
   int Nsecfilt;
-  char mode;
-
-  /* no autodetect for CATMODE yet */
-  strcpy (catalog[0].catmode, CATMODE);
+  int i, j, Nextra, in, out;
+  SecFilt *insec, *outsec;
 
   /* read catalog header */
-  mode = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-  if (!load_catalog (catalog, mode, VERBOSE)) {
+  if (!load_catalog (catalog, VERBOSE)) {
     fprintf (stderr, "ERROR: failure loading catalog\n");
     exit (1);
@@ -20,7 +17,4 @@
   if (catalog[0].Nsecfilt < Nsecfilt) {
 
-    int i, j, Nextra, in, out;
-    SecFilt *insec, *outsec;
-
     Nextra = Nsecfilt - catalog[0].Nsecfilt;
     insec = catalog[0].secfilt;
@@ -28,10 +22,12 @@
     for (in = out = i = 0; i < catalog[0].Naverage; i++) {
       for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
-	outsec[out].M = insec[in].M;
+	outsec[out].M_PS  = insec[in].M_PS;
+	outsec[out].dM_PS = insec[in].dM_PS;
 	outsec[out].Xm = insec[in].Xm;
       }
       for (j = 0; j < Nextra; j++, out++) {
-	outsec[out].M = NO_MAG;
-	outsec[out].Xm = NO_MAG;
+	outsec[out].M_PS  = NO_MAG;
+	outsec[out].dM_PS = NO_MAG;
+	outsec[out].Xm    = NO_MAG;
       }
     }
Index: /trunk/Ohana/src/getstar/src/getstar.c
===================================================================
--- /trunk/Ohana/src/getstar/src/getstar.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/getstar.c	(revision 6968)
@@ -1,12 +1,13 @@
 # include "getstar.h"
 
-main (int argc, char **argv) {
+int main (int argc, char **argv) {
 
-  int i, Nstars, Nregions;
-  Image *image, *gimages(), *gtimes(), *find_images();
+  int i;
+  SkyTable *sky;
+  SkyList *skylist;
   Catalog catalog;
-  GSCRegion *region, *tregion, *gregions();
-  Stars *stars;
-  
+  Catalog output;
+  FITS_DB db;
+
   args (argc, argv);
   set_db (&db);
@@ -16,8 +17,6 @@
 
   /* choose elements to load based on options */
-  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-
-  Nstars = 0;
-  stars = NULL;
+  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+  init_catalog (&output);
 
   switch (MODE) {
@@ -45,5 +44,5 @@
       # if (0)
       /* load corresponding sky regions */
-      skylist = SkyListByImage (sky, -1, &image);
+      skylist = SkyListByImage (sky, -1, &image, &Nimage);
       for (i = 0; i < skylist[0].Nregions; i++) {
 	  catalog.filename = skylist[0].filename[i];
@@ -56,16 +55,20 @@
       }
       # endif
+      fprintf (stderr, "error: BY_IMAGE not implemented\n");
+      exit (1);
       break;
 
     case BY_CATALOG:
-      /* not implemented */
+      fprintf (stderr, "error: BY_CATALOG not implemented\n");
+      exit (1);
       break;
-
-      /* not implemented */
-      break;
+      
+    default:
+      fprintf (stderr, "error: invalid options\n");
+      exit (1);
   }
 
   /* write out the selected stars */
-  wcatalog (argv[2], output);
+  wcatalog (OUTPUT, &output);
   fprintf (stderr, "SUCCESS\n");
   exit (0);
Index: unk/Ohana/src/getstar/src/gimages.c
===================================================================
--- /trunk/Ohana/src/getstar/src/gimages.c	(revision 6967)
+++ 	(revision )
@@ -1,39 +1,0 @@
-# include "getstar.h"
-
-/* return image or images which match the name */
-Image *gimages (char *filename, int *Nfound, int exact) {
-  
-  int i, size, Nimage, nimage;
-  double zeropt;
-  struct stat filestatus;
-  FILE *f;
-  Image *timage, *image;
-  Header header;
-  
-  set_db (&db);
-  dvo_image_lock (&db, ImageCat);
-  if (db[0].dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db[0].filename);
-
-  status = dvo_image_load (db, VERBOSE, FALSE);
-  if (!status) Shutdown ("can't read image catalog %s", db[0].filename);
-
-  timage = fits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
-  dvo_image_unlock (&db, ImageCat);
-
-  fits_scan (&header, "ZERO_PT", "%lf", 1, &zeropt);
-  if (fabs (ZeroPt - zeropt) > 1e-4) {
-    fprintf (stderr, "ERROR: zero point in image table (%f:%s) inconsistent with zero point in image header (%f:%s)\n",
-	     zeropt, ImageCat, ZeroPt, filename);
-    exit (1);
-  }
-
-  ALLOCATE (image, Image, 1);
-  for (i = 0; i < Nimage; i++) {
-    if (strcmp (timage[i].name, filename)) continue;
-    memcpy (image, &timage[i], sizeof(Image));
-    return (image);
-  }
-
-  fprintf (stderr, "error: failed to find desired image\n");
-  exit (1);
-}
Index: unk/Ohana/src/getstar/src/gregions.c
===================================================================
--- /trunk/Ohana/src/getstar/src/gregions.c	(revision 6967)
+++ 	(revision )
@@ -1,56 +1,0 @@
-# include "getstar.h"
-
-GSCRegion *gregions (image, Nregions)
-Image *image;
-int *Nregions;
-{
-  
-  GSCRegion *region;
-  FILE *f;
-  double x, y;
-  double dr, dd, dec, ra;
-  int i, j, done, nregion, NREGION;
-  
-  f = fopen (GSCFILE, "r");
-  if (f == NULL) {
-    fprintf (stderr, "ERROR: can't find GSC region file %s\n", GSCFILE);
-    exit (1);
-  }
-  
-  /* find regions at image corners */
-  NREGION = 10;
-  ALLOCATE (region, GSCRegion, NREGION);
-  nregion = 0;
-
-  /* look for new regions on grid across image */ 
-  for (x = 0.0; x <= 1.0; x+=0.25) {
-    for (y = 0.0; y <= 1.0; y+=0.25) {
-      XY_to_RD (&ra, &dec, image[0].NX*(1.1*x - 0.05), image[0].NY*(1.1*y - 0.05), &image[0].coords);
-      aregion (&region[nregion], f, ra, dec);
-      done = FALSE;
-      for (j = 0; (j < nregion) && !done; j++) {
-	if (!strcmp (region[nregion].filename, region[j].filename)) {
-	  nregion --;
-	  done = TRUE;
-	}
-      }
-      nregion ++;
-      if (nregion == NREGION) {
-	NREGION += 10;
-	REALLOCATE (region, GSCRegion, NREGION);
-      }
-    }
-  }
-
-  if (VERBOSE) {
-    fprintf (stderr, "found %d region files:\n", nregion);
-    for (i = 0; i < nregion; i++) {
-      fprintf (stderr, "  %d %s\n", i, region[i].filename);
-    }
-  }
-  *Nregions = nregion;
-  
-  fclose (f);
-  return (region);
-  
-}
Index: unk/Ohana/src/getstar/src/image-db.c
===================================================================
--- /trunk/Ohana/src/getstar/src/image-db.c	(revision 6967)
+++ 	(revision )
@@ -1,2 +1,0 @@
-# include "getstar.h"
-
Index: /trunk/Ohana/src/getstar/src/init_catalog.c
===================================================================
--- /trunk/Ohana/src/getstar/src/init_catalog.c	(revision 6968)
+++ /trunk/Ohana/src/getstar/src/init_catalog.c	(revision 6968)
@@ -0,0 +1,17 @@
+# include "getstar.h"
+
+void init_catalog (Catalog *catalog) {
+  
+  catalog[0].Naverage = 0;
+  ALLOCATE (catalog[0].average, Average, 1);
+
+  catalog[0].Nmeasure = 0;
+  ALLOCATE (catalog[0].measure, Measure, 1);
+
+  catalog[0].Nsecfilt = GetPhotcodeNsecfilt ();
+  ALLOCATE (catalog[0].secfilt, SecFilt, 1);
+
+  catalog[0].Nmissing = 0;
+  ALLOCATE (catalog[0].missing, Missing, 1);
+
+}
Index: /trunk/Ohana/src/getstar/src/load_pt_catalog.c
===================================================================
--- /trunk/Ohana/src/getstar/src/load_pt_catalog.c	(revision 6968)
+++ /trunk/Ohana/src/getstar/src/load_pt_catalog.c	(revision 6968)
@@ -0,0 +1,27 @@
+# include "getstar.h"
+
+int load_pt_catalog (Catalog *catalog, SkyRegion *region) {
+  
+  if (!check_file_access (catalog[0].filename, TRUE, TRUE)) {
+    exit (1);
+  }
+
+  if (VERBOSE) fprintf (stderr, "adding to %s\n", catalog[0].filename);
+    
+  switch (lock_catalog (catalog, LCK_XCLD)) {
+  case 0:
+    fprintf (stderr, "ERROR: can't lock file %s\n", catalog[0].filename);
+    exit (1);
+  case 1:
+    gcatalog (catalog); /* load from disk */
+    break;
+  case 2:
+    /* no data in file */
+    return (FALSE);
+  }
+  return (TRUE);
+}
+
+/* If the catalog file is locked, something weird is happening...  this is an unexpected error
+   because ImageCat was NOT locked so we should be the only locking entity.  However, this logic
+   breaks down for the server design: image and catalog are updated independently... */
Index: /trunk/Ohana/src/getstar/src/mkcatalog.c
===================================================================
--- /trunk/Ohana/src/getstar/src/mkcatalog.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/mkcatalog.c	(revision 6968)
@@ -1,6 +1,8 @@
-# include "addstar.h"
+# include "getstar.h"
 
-void mkcatalog (SkyRegion *region, Catalog *catalog) {
+void mkcatalog (Catalog *catalog) {
   
+  int i;
+  double Rmin, Rmax, Dmin, Dmax;
   int length, status;
   char *path, *root, *file, *line;
@@ -94,9 +96,21 @@
   }    
 
+  /* determine RA,DEC range */
+  Rmin = 360.0;
+  Rmax =   0.0;
+  Dmin = +90.0;
+  Dmax = -90.0;
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    Rmin = MIN (Rmin, catalog[0].average[i].R);
+    Rmax = MAX (Rmax, catalog[0].average[i].R);
+    Dmin = MIN (Dmin, catalog[0].average[i].D);
+    Dmax = MAX (Dmax, catalog[0].average[i].D);
+  }
+
   /* write RA,DEC range in header */
-  fits_modify (&catalog[0].header, "RA0",  "%lf", 1, region[0].Rmin);
-  fits_modify (&catalog[0].header, "DEC0", "%lf", 1, region[0].Dmin);
-  fits_modify (&catalog[0].header, "RA1",  "%lf", 1, region[0].Rmax);
-  fits_modify (&catalog[0].header, "DEC1", "%lf", 1, region[0].Dmax);
+  fits_modify (&catalog[0].header, "RA0",  "%lf", 1, Rmin);
+  fits_modify (&catalog[0].header, "DEC0", "%lf", 1, Dmin);
+  fits_modify (&catalog[0].header, "RA1",  "%lf", 1, Rmax);
+  fits_modify (&catalog[0].header, "DEC1", "%lf", 1, Dmax);
 
   /* write creation date in header */
Index: /trunk/Ohana/src/getstar/src/select_by_region.c
===================================================================
--- /trunk/Ohana/src/getstar/src/select_by_region.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/select_by_region.c	(revision 6968)
@@ -1,19 +1,23 @@
 # include "getstar.h"
 
-/* return 'stars' or return 'average' / 'measure' entries? */
-bool select_by_region (Catalog *output, Catalog *catalog, SkyRegion *region, int start, int end) {
+/* add selected catalog objects to the output catalog */
+int select_by_region (Catalog *output, Catalog *catalog, SkyRegion *region, int start, int end) {
 
-  int i, n, N, NSTARS;
-  int photcode;
+  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 range %d to %d (photcode %s)\n", start, end, photcode);
+  if (VERBOSE) fprintf (stderr, "extracting for range %d to %d\n", start, end);
 
   /* select the average objects in this region */
   Nave = output[0].Naverage;
   NAVE = output[0].Naverage + 1000;
-  REALLOCATE (output[0].average, Average, NOUT);
+  REALLOCATE (output[0].average, Average, NAVE);
+  REALLOCATE (output[0].secfilt, SecFilt, NAVE*Nsecfilt);
 
   Nmeas = output[0].Nmeasure;
@@ -28,5 +32,5 @@
     
     if (R < region[0].Rmin) continue;
-    if (R > region[0].Rman) continue;
+    if (R > region[0].Rmax) continue;
     if (D < region[0].Dmin) continue;
     if (D > region[0].Dmax) continue;
@@ -34,6 +38,6 @@
     output[0].average[Nave] = catalog[0].average[i];
     output[0].average[Nave].offset = Nmeas;
-    for (j = 0; j < PhotNsec; j++) {
-      output[0].secfilt[PhotNsec*Nave + j] = catalog[0].secfilt[PhotNsec*i + j];
+    for (j = 0; j < Nsecfilt; j++) {
+      output[0].secfilt[Nsecfilt*Nave + j] = catalog[0].secfilt[Nsecfilt*i + j];
     }
 
@@ -53,7 +57,7 @@
       NAVE += 1000;
       REALLOCATE (output[0].average, Average, NAVE);
-      REALLOCATE (output[0].secfilt, SecFilt, NAVE*PhotNsec);
+      REALLOCATE (output[0].secfilt, SecFilt, NAVE*Nsecfilt);
+    }
   }
   return (TRUE);
 }
-
Index: unk/Ohana/src/getstar/src/sort_lists.c
===================================================================
--- /trunk/Ohana/src/getstar/src/sort_lists.c	(revision 6967)
+++ 	(revision )
@@ -1,82 +1,0 @@
-
-sort_lists (X, Y, S, N) 
-float *X, *Y;
-int *S, N;
-{
-  int l,j,ir,i;
-  double tX, tY, tS;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-      tY = Y[l];
-      tS = S[l];
-    }
-    else {
-      tX = X[ir];
-      X[ir] = X[0];
-      tY = Y[ir];
-      Y[ir] = Y[0];
-      tS = S[ir];
-      S[ir] = S[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	Y[0] = tY;
-	S[0] = tS;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	Y[i] = Y[j];
-	S[i] = S[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-    Y[i] = tY;
-    S[i] = tS;
-  }
-}
-
-fsort (float *X, int N) {
-
-  int l,j,ir,i;
-  float tX;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-    }
-    else {
-      tX = X[ir];
-      X[ir] = X[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-  }
-}
Index: /trunk/Ohana/src/getstar/src/wcatalog.c
===================================================================
--- /trunk/Ohana/src/getstar/src/wcatalog.c	(revision 6967)
+++ /trunk/Ohana/src/getstar/src/wcatalog.c	(revision 6968)
@@ -1,7 +1,11 @@
-# include "uniphot.h"
+# include "getstar.h"
 
 void wcatalog (char *filename, Catalog *catalog) {
 
   /* CATMODE and CATFORMAT determined from catalog */
+  // XXX 'stdout' and SPLIT are not compatible
+  
+  catalog[0].filename = filename;
+  mkcatalog (catalog);
 
   /* open file as appropriate */
Index: unk/Ohana/src/getstar/src/wstars.c
===================================================================
--- /trunk/Ohana/src/getstar/src/wstars.c	(revision 6967)
+++ 	(revision )
@@ -1,146 +1,0 @@
-# include "getstar.h"
-# define NCHAR 66 /* 65 char EXCLUDING return */
-
-int wstars (char *filename, Stars *stars, int Nstars, Image *image) {
-
-  /* construct a header from the image structure */
-  /* write out header */
-  /* write out data lines */
-
-  int i, Nchar, Ny, mode;
-  double scale;
-  char *photcode, *c, *py, *pm, *pd, datestr[64], timestr[64];
-  struct tm *gmt;
-  Header header;
-  FILE *f;
-  char line[NCHAR];
-
-  fits_init_header (&header);
-  header.Naxis[0] = image[0].NX + XOVERSCAN;
-  header.Naxis[1] = image[0].NY + YOVERSCAN;
-  header.bitpix   = 16;
-  header.Naxes    = 2;
-  fits_create_header (&header);
-
-  /* astrometric data */
-  fits_print (&header, "CTYPE1",  "%s", 1, "RA---SIN");
-  fits_print (&header, "CTYPE2",  "%s", 1, "DEC--SIN");
-
-  fits_print (&header, "CRVAL1", "%f", 1, image[0].coords.crval1);
-  fits_print (&header, "CRVAL2", "%f", 1, image[0].coords.crval2);
-
-  fits_print (&header, "CRPIX1", "%f", 1, image[0].coords.crpix1);
-  fits_print (&header, "CRPIX2", "%f", 1, image[0].coords.crpix2);
-
-  fits_print (&header, "PC001001",  "%f", 1, image[0].coords.pc1_1);
-  fits_print (&header, "PC001002",  "%f", 1, image[0].coords.pc1_2);
-  fits_print (&header, "PC002001",  "%f", 1, image[0].coords.pc2_1);
-  fits_print (&header, "PC002002",  "%f", 1, image[0].coords.pc2_2);
-
-  fits_print (&header, "CDELT1",  "%f", 1, image[0].coords.cdelt1);
-  fits_print (&header, "CDELT2",  "%f", 1, image[0].coords.cdelt2);
-  
-  fits_print (&header, "NASTRO", "%d", 1, 1); /* TBD */
-  fits_print (&header, "EQUINOX", "%f", 1, 2000.0); /* TBD */
-  
-  fits_print (&header, "CERROR", "%f", 1, 0.02*image[0].cerror);
-
-  photcode = GetPhotcodeNamebyCode (image[0].source);
-  fits_print (&header, "PHOTCODE", "%s", 1, photcode);
-
-  fits_print (&header, ExptimeKeyword, "%f", 1, image[0].exptime);
-  
-  fits_print (&header, "FLIMIT",   "%lf", 1, 0.1*image[0].detection_limit);
-  fits_print (&header, "FSATUR",   "%lf", 1, 0.1*image[0].saturation_limit);
-
-  scale = image[0].coords.cdelt1*25.0*3600.0;
-  fits_print (&header, "FWHM_X",   "%lf", 1, image[0].fwhm_x / scale);
-  fits_print (&header, "FWHM_Y",   "%lf", 1, image[0].fwhm_y / scale);
-	      
-  fits_print (&header, "TRATE",   "%lf", 1, image[0].trate/10000.0);
-  fits_print (&header, AirmassKeyword, "%lf", 1, 0.001*image[0].secz);
-
-  if (image[0].ccdnum != 0xff) {
-    fits_print (&header, CCDNumKeyword, "%d", 1, image[0].ccdnum);
-  }
-
-  /* parse date-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);
-  }
-
-  gmt = gmtime ((unsigned long *)&image[0].tzero);
-
-  switch (mode) {
-  case 1:
-    sprintf (datestr, "%04d/%02d/%02d", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday);
-    break;
-  case 2:
-    sprintf (datestr, "%04d/%02d/%02d", 1900 + gmt[0].tm_year, gmt[0].tm_mday, gmt[0].tm_mon+1);
-    break;
-  case 3:
-    sprintf (datestr, "%02d/%02d/%04d", gmt[0].tm_mon+1, gmt[0].tm_mday, 1900 + gmt[0].tm_year);
-    break;
-  case 4:
-    sprintf (datestr, "%02d/%02d/%04d", gmt[0].tm_mday, gmt[0].tm_mon+1, 1900 + gmt[0].tm_year);
-    break;
-  }
-  sprintf (timestr, "%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-  fits_print (&header, UTKeyword, "%s", 1, timestr);
-  fits_print (&header, DateKeyword, "%s", 1, datestr);
-
-  fits_print (&header, "ZERO_PT", "%lf", 1, ZeroPt);
-  fits_print (&header, "NSTARS", "%d", 1, Nstars);
-  
-  f = fopen (filename, "w");
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "ERROR: can't create output file %s\n", filename);
-    exit (1);
-  }
-
-  fwrite (header.buffer, 1, header.size, f);
-
-  for (i = 0; i < Nstars; i++) {
-    Nchar = snprintf (line, NCHAR, "%6.1f %6.1f %6.3f %03d %2d %3.1f %6.3f %6.3f %6.2f %6.2f %5.1f", 
-		      stars[i].X, stars[i].Y, stars[i].M, 
-		      (int)(stars[i].dM), stars[i].dophot, stars[i].sky, 
-		      stars[i].Mgal, stars[i].Map, stars[i].fx, stars[i].fy, stars[i].df);
-    fprintf (f, "%s\n", line);
-  }
-  fclose (f);
-}
-
-uppercase (char *string) {
-
-  int i;
-    
-  for (i = 0; i < strlen (string); i++) string[i] = toupper (string[i]);
-
-}
