Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 6674)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 6675)
@@ -40,5 +40,7 @@
 $(SRC)/get2mass_dr2.$(ARCH).o \
 $(SRC)/getgsc.$(ARCH).o \
+$(SRC)/gettycho.$(ARCH).o \
 $(SRC)/getusno.$(ARCH).o \
+$(SRC)/getusnob.$(ARCH).o \
 $(SRC)/gimages.$(ARCH).o \
 $(SRC)/greference.$(ARCH).o \
@@ -58,4 +60,5 @@
 $(SRC)/wcatalog.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
 $(SRC)/SkyRegionUtils.$(ARCH).o \
 $(SRC)/SkyListForStars.$(ARCH).o \
Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 6674)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 6675)
@@ -44,5 +44,7 @@
 char   TWO_MASS_DIR_DR2[256];
 char   GSCDIR[256];
-char   CDROM[256];
+char   USNO_A_DIR[256];
+char   USNO_B_DIR[256];
+char   TYCHO_DIR[256];
 char   SubpixDatafile[256];
 char   PASSWORD[80];
@@ -110,4 +112,5 @@
 float      airmass                PROTO((float secz_image, double ra, double dec, double st, double latitude));
 void       SetAirmassQuality      PROTO((int quality));
+SkyTable  *SkyTableFromTychoIndex PROTO((char *filename, int VERBOSE));
 AddstarClientOptions args         PROTO((int argc, char **argv, AddstarClientOptions options));
 void       check_permissions      PROTO((char *basefile));
@@ -122,5 +125,7 @@
 double     get_subpix             PROTO((double x, double y));
 Stars     *getgsc                 PROTO((SkyRegion *patch, int *NSTARS));
+Stars     *gettycho               PROTO((SkyRegion *catstats, int photcode, double epoch, int *Nstars));
 Stars     *getusno                PROTO((SkyRegion *catstats, int photcode, int *Nstars));
+Stars     *getusnob               PROTO((SkyRegion *catstats, int photcode, double epoch, int *Nstars));
 Image     *gimages                PROTO((FITS_DB *db, Image *image, Coords *mosaic, int *Npimage));
 Stars     *grefcat                PROTO((char *Refcat, SkyRegion *catstats, int photcode, int *nstars));
Index: /trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 6674)
+++ /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 6675)
@@ -52,5 +52,11 @@
   ScanConfig (config, "2MASS_DIR_DR2",          "%s",  0, TWO_MASS_DIR_DR2);
   ScanConfig (config, "GSCDIR",                 "%s",  0, GSCDIR);
-  ScanConfig (config, "USNO_CDROM",             "%s",  0, CDROM);
+
+  if (!ScanConfig (config, "USNO_A_DIR",             "%s",  0, USNO_A_DIR)) {
+    ScanConfig (config, "USNO_CDROM",             "%s",  0, USNO_A_DIR);
+  }
+  ScanConfig (config, "USNO_B_DIR",             "%s",  0, USNO_B_DIR);
+
+  ScanConfig (config, "TYCHO_DIR",             "%s",  0, TYCHO_DIR);
 
   ScanConfig (config, "IMAGE_CATALOG",          "%s",  0, ImageCat);
Index: /trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c	(revision 6675)
+++ /trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c	(revision 6675)
@@ -0,0 +1,150 @@
+# include "dvo.h"
+# define NBANDS 24
+# define NDIV 4
+
+static double DecBands[] = {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};
+
+static char *DecNames[] = {"n0000", "n0730", "n1500", "n2230", "n3000", "n3730", "n4500", "n5230", "n6000", "n6730", "n7500", "n8230", "none",
+			   "s0000", "s0730", "s1500", "s2230", "s3000", "s3730", "s4500", "s5230", "s6000", "s6730", "s7500", "s8230", "none"};
+
+SkyTable *SkyTableFromTychoIndex (char *filename, int VERBOSE) {
+
+  int i, No, Nr, NR, Ntycho;
+  double Dmin, Dmax;
+  char line[256];
+  FILE *f;
+  SkyTable *skytable;
+  SkyRegion *regions;
+  SkyRegion *tycho;
+  
+  f = fopen (filename, "r");
+  if (f == NULL) {
+    if (VERBOSE) fprintf (stderr, "can't find Tycho Index file %s\n", filename);
+    return (NULL);
+  }
+
+  /* load in table data */
+  ALLOCATE (tycho, SkyRegion, 10000);
+  for (i = 0; i < 10000; i++) {
+    if (scan_line (f, line) == EOF) break;
+    tycho[i].Rmin = atof (&line[15]);
+    tycho[i].Rmax = atof (&line[22]);
+    tycho[i].Dmin = atof (&line[29]);
+    tycho[i].Dmax = atof (&line[36]);
+
+    bzero (tycho[i].name, 21);
+    strncpy (tycho[i].name, line, 7);
+    tycho[i].name[7] = 0;
+  }
+  Ntycho = i;
+  fclose (f);
+
+  /* build supporting level 0 and 1 regions */
+  Nr = 0;
+  NR = 100;
+  ALLOCATE (regions, SkyRegion, 100);
+  
+  /* level 0 : full sky */
+  regions[Nr].Rmin 	=   0;
+  regions[Nr].Rmax 	= 360;
+  regions[Nr].Dmin 	= -90;
+  regions[Nr].Dmax 	= +90;
+  regions[Nr].index  	=  0;
+  regions[Nr].depth  	=  0;
+  regions[Nr].parent 	= -1;
+  regions[Nr].child  	=  TRUE;
+  regions[Nr].table  	=  FALSE;
+  bzero (regions[Nr].name, 21);
+  strcpy (regions[Nr].name, "fullsky");
+  
+  No = Nr;
+  Nr ++;
+
+  /* level 1 : add the dec bands */
+  regions[No].childS = Nr;
+  /* first north */
+  for (i = 0; i < 12; i++, Nr++) {
+    regions[Nr].Rmin   	  =   0;
+    regions[Nr].Rmax   	  = 360;
+    regions[Nr].Dmin   	  = DecBands[i];
+    regions[Nr].Dmax   	  = DecBands[i+1];
+    regions[Nr].index  	  =  i+1;
+    regions[Nr].depth  	  =  1;
+    regions[Nr].parent 	  =  0;
+    regions[Nr].child  	  =  TRUE;
+    regions[Nr].table  	  =  FALSE;
+    bzero (regions[Nr].name, 21);
+    strcpy (regions[Nr].name, DecNames[i]);
+  }
+  /* now south */
+  for (i = 0; i < 12; i++, Nr++) {
+    regions[Nr].Rmin   	  =   0;
+    regions[Nr].Rmax   	  = 360;
+    regions[Nr].Dmin   	  = DecBands[i+14];
+    regions[Nr].Dmax   	  = DecBands[i+13];
+    regions[Nr].index  	  =  i+1;
+    regions[Nr].depth  	  =  1;
+    regions[Nr].parent 	  =  0;
+    regions[Nr].child  	  =  TRUE;
+    regions[Nr].table  	  =  FALSE;
+    bzero (regions[Nr].name, 21);
+    strcpy (regions[Nr].name, DecNames[i+13]);
+  }
+  regions[No].childE = Nr;
+
+  CHECK_REALLOCATE (regions, SkyRegion, NR, Nr, 100);
+
+  /* level 2 : copy the data from the GSC Region files */
+  No = 1;
+  Dmin = regions[No].Dmin - 0.2;
+  Dmax = regions[No].Dmax + 0.2;
+  regions[No].childS = Nr;
+
+  for (i = 0; i < Ntycho; i++) {
+    /* if we are outside of current region, go to the next one */
+    if ((tycho[i].Dmin < Dmin) || (tycho[i].Dmax > Dmax)) {
+      regions[No].childE = Nr;
+
+      No++;
+      Dmin = regions[No].Dmin - 0.2;
+      Dmax = regions[No].Dmax + 0.2;
+      regions[No].childS = Nr;
+
+      if ((tycho[i].Dmin < Dmin) || (tycho[i].Dmax > Dmax)) {
+	fprintf (stderr, "ERROR: tycho index is not in order!\n");
+	exit (1);
+      }
+    }
+
+    /* set the values for this region */
+    regions[Nr].Rmin = tycho[i].Rmin;
+    regions[Nr].Rmax = tycho[i].Rmax;
+    regions[Nr].Dmin = tycho[i].Dmin;
+    regions[Nr].Dmax = tycho[i].Dmax;
+    strcpy (regions[Nr].name, tycho[i].name);
+
+    regions[Nr].index    =  Nr;
+    regions[Nr].depth    =  2;
+    regions[Nr].parent   =  No;
+    regions[Nr].child    =  FALSE;
+    regions[Nr].table    =  FALSE;
+    regions[Nr].childS   =  0;
+    regions[Nr].childE   =  0;
+
+    Nr ++;
+    CHECK_REALLOCATE (regions, SkyRegion, NR, Nr, 100);
+  }
+
+  ALLOCATE (skytable, SkyTable, 1);
+  skytable[0].regions = regions;
+  skytable[0].Nregions = Nr;
+
+  ALLOCATE (skytable[0].filename, char *, skytable[0].Nregions);
+  for (i = 0; i < skytable[0].Nregions; i++) {
+    skytable[0].filename[i] = NULL;
+  }
+  if (VERBOSE) fprintf (stderr, "loaded %d tables from tycho index\n", skytable[0].Nregions);
+
+  return (skytable);
+}
Index: /trunk/Ohana/src/addstar/src/gettycho.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gettycho.c	(revision 6675)
+++ /trunk/Ohana/src/addstar/src/gettycho.c	(revision 6675)
@@ -0,0 +1,110 @@
+# include "addstar.h"
+# define NZONE 180
+# define NBYTE 207
+# define NITEM 100
+
+static SkyTable *tychoTable = NULL;
+
+Stars *gettycho (SkyRegion *catstats, int photcode, double epoch, int *nstars) {
+
+  int i, j, nitems;
+  char *buffer;
+  char filename[128], *line;
+  FILE *f;
+  int NTYCHO, Ntycho;
+  int firstRow, firstByte;
+  Stars *stars;
+  short int TYCHO_B, TYCHO_V;
+  SkyRegion *region;
+  SkyList  *skylist;
+
+  /* require photcode */
+  NAMED_PHOTCODE (TYCHO_B, "TYCHO_B");
+  NAMED_PHOTCODE (TYCHO_V, "TYCHO_B");
+  if (photcode == TYCHO_B) goto good_code;
+  if (photcode == TYCHO_V) goto good_code;
+  Shutdown ("TYCHO photcode not specified");
+good_code:
+
+  fprintf (stderr, "loading TYCHO catalog\n");
+
+  /* load tycho index file into sky table */
+  if (tychoTable == NULL) {
+    sprintf (filename, "%s/index.dat", TYCHO_DIR);
+    tychoTable = SkyTableFromTychoIndex (filename, VERBOSE);
+  }
+
+  /* identify tycho region files overlapping the requested region */
+  skylist = SkyListByPatch (tychoTable, 2, catstats);
+
+  /* open the Tycho catalog file */
+  sprintf (filename, "%s/tycho.dat", TYCHO_DIR);
+  f = fopen (filename, "r");
+
+  Ntycho = 0;
+  NTYCHO = 5000;
+  ALLOCATE (stars, Stars, NTYCHO);
+
+  ALLOCATE (buffer, char, NITEM*NBYTE);
+
+  for (i = 0; i < skylist[0].Nregions; i++) {
+    region = skylist[0].regions[i];
+    if (VERBOSE) fprintf (stderr, "section %d (%f - %f, %f - %f)...", i, 
+			  region[0].Rmin, region[0].Rmax, region[0].Dmin, region[0].Dmax);
+
+    firstRow  = atoi (region[0].name);
+    firstByte = firstRow * NBYTE;
+    fseek (f, firstByte, SEEK_SET);
+
+    while (1) {
+      nitems = fread (buffer, NBYTE, NITEM, f);
+      if (nitems == 0) break;
+      if (nitems != NITEM) {
+	fprintf (stderr, "ERROR: failure reading data from file %s\n", filename);
+	exit (1);
+      }
+
+      for (j = 0; j < NITEM; j++) {
+	line = &buffer[j*NBYTE];
+	stars[Ntycho].R = atof (&line[15]);
+	stars[Ntycho].D = atof (&line[28]);
+
+	if (stars[Ntycho].R < region[0].Rmin) goto next_section;
+	if (stars[Ntycho].R > region[0].Rmax) goto next_section;
+	if (stars[Ntycho].D < region[0].Dmin) goto next_section;
+	if (stars[Ntycho].D > region[0].Dmax) goto next_section;
+
+	if (stars[Ntycho].R < UserPatch.Rmin) continue;
+	if (stars[Ntycho].R > UserPatch.Rmax) continue;
+	if (stars[Ntycho].D < UserPatch.Dmin) continue;
+	if (stars[Ntycho].D > UserPatch.Dmax) continue;
+
+	stars[Ntycho].t     = 0;
+	stars[Ntycho].found = -1;
+      
+	/* one pass of addstar does either r or b */
+	if (photcode == TYCHO_B) {
+	  stars[Ntycho].M     = atof (&line[110]);
+	  stars[Ntycho].dM    = atof (&line[117]);
+	  stars[Ntycho].code  = TYCHO_B;
+	} else {
+	  stars[Ntycho].M     = atof (&line[123]);
+	  stars[Ntycho].dM    = atof (&line[130]);
+	  stars[Ntycho].code  = TYCHO_V;
+	}	
+      
+	Ntycho ++;
+	CHECK_REALLOCATE (stars, Stars, NTYCHO, Ntycho, 5000);
+      }
+    }
+  next_section:
+    if (VERBOSE) fprintf (stderr, "%d stars\n", Ntycho);
+  }
+  fclose (f);
+
+  REALLOCATE (stars, Stars, MAX (1, Ntycho));
+
+  *nstars = Ntycho;
+  if (VERBOSE) fprintf (stderr, "%d stars from Tycho\n", Ntycho);
+  return (stars);
+}
Index: /trunk/Ohana/src/addstar/src/getusno.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getusno.c	(revision 6674)
+++ /trunk/Ohana/src/addstar/src/getusno.c	(revision 6675)
@@ -1,23 +1,18 @@
 # include "addstar.h"
 # define NZONE 24
+# define NBYTE  4
+# define NELEM  3
 
-int SPDzone[] = {
-  0, 75, 450, 375, 1500, 1650, 300, 1425, 1725, 525, 1275, 225, 
-  675, 150, 600, 1575, 750, 975, 900, 1050, 1125, 1200, 825, 1350};
-
-int USNOdisk[] = {
-  1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10};
-
-Stars *getusno (SkyRegion *catstats, int photcode, int *Nstars) {
+Stars *getusno (SkyRegion *catstats, int photcode, int *nstars) {
 
   long int offset;
-  int i, bin, first, last, nitems, Nitems, Nbins;
+  int i, bin, first, last, nitems, Nitems, Nbins, Nstars;
   float hours[100];
   int start[100], number[100], *buffer, *buf;
-  char filename[128], c;
+  char filename[128];
   FILE *f;
   int iRA0, iRA1, iDEC0, iDEC1;
   double dec;
-  int spd, spd_start, spd_end, disk;
+  int spd, spd_start, spd_end;
   int NUSNO, Nusno;
   Stars *stars;
@@ -53,28 +48,12 @@
 
   for (spd = spd_start; spd < spd_end; spd += 75) {
-    disk = -1;
-    for (i = 0; i < NZONE; i++) {
-      if (spd == SPDzone[i]) 
-	disk = USNOdisk[i];
-    }
-    if (disk < 0) {
-      fprintf (stderr, "ERROR: can't find cdrom for spd %d\n",  spd);
-      exit (1);
-    }
     
     /* load accelerator file */
-    sprintf (filename, "%s/zone%04d.acc", CDROM, spd); 
+    sprintf (filename, "%s/zone%04d.acc", USNO_A_DIR, spd); 
     if (VERBOSE) fprintf (stderr, "reading from %s\n", filename);
     f = fopen (filename, "r");
     if (f == (FILE *) NULL) {
-      fprintf (stderr, "can't open file %s, is cdrom %d in drive?\n", filename, disk);
-      fprintf (stderr, "press return when ready to continue: ");
-      fscanf (stdin, "%c", &c);
-      fprintf (stderr, "trying again...\n");
-      f = fopen (filename, "r");
-      if (f == (FILE *) NULL) {
-	fprintf (stderr, "ERROR: can't open file %s, is cdrom %d in drive?\n", filename, disk);
-	exit (1);  
-      }
+      fprintf (stderr, "ERROR: can't open accelerator file %s\n", filename);
+      exit (1);  
     }
     for (i = 0; fscanf (f, "%f %d %d", &hours[i], &start[i], &number[i]) != EOF; i++);
@@ -94,5 +73,5 @@
     
     /* open data file */
-    sprintf (filename, "%s/zone%04d.cat", CDROM, spd);
+    sprintf (filename, "%s/zone%04d.cat", USNO_A_DIR, spd);
     if (VERBOSE) fprintf (stderr, "reading from %s\n", filename);
     f = fopen (filename, "r");
@@ -101,49 +80,59 @@
       exit (1);
     }
+
+    /** USNO-A consists of 3 x 4byte (int) records **/
     /* advance file pointer to first slice */
-    offset = 3*sizeof(int)*(start[first] - 1);
+    offset = NELEM*NBYTE*(start[first] - 1);
     fseek (f, offset, SEEK_SET);
-    /* on each loop, load data from an RA slice of the catalog */
+
+    /* sum the number of stars in data segment of interest */
+    Nstars = 0;
     for (bin = first; bin < last; bin++) {
-      Nitems = 3*number[bin];
-      ALLOCATE (buffer, int, Nitems);
-      nitems = Fread (buffer, sizeof(int), Nitems, f, "int");
-      if (nitems != Nitems) {
-	fprintf (stderr, "ERROR: failure reading data from file %s\n", filename);
-	exit (1);
+      Nstars += number[bin];
+    }
+    Nitems = NELEM*Nstars;  
+    /* number of blocks to read -- we need to use Fread for byte-swapping read */
+
+    /* read stars from catalog */
+    ALLOCATE (buffer, int, Nitems);
+    nitems = Fread (buffer, NBYTE, Nitems, f, "int");
+    if (nitems != Nitems) {
+      fprintf (stderr, "ERROR: failure reading data from file %s\n", filename);
+      exit (1);
+    }
+
+    /* extract the data of interest from segment (in RA and DEC range) */
+    buf = buffer;
+    for (i = 0; i < Nstars; i++, buf += NELEM) {
+      if (buf[0] < iRA0) continue;
+      if (buf[0] > iRA1) continue;
+      if (buf[1] < iDEC0) continue;
+      if (buf[1] > iDEC1) continue;
+
+      bzero (&stars[Nusno], sizeof(Stars));
+      stars[Nusno].R     = buf[0]/360000.0;
+      stars[Nusno].D     = buf[1]/360000.0 - 90.0;
+      stars[Nusno].dM    = NO_ERR;
+      stars[Nusno].t     = 0;
+      stars[Nusno].found = -1;
+
+      /* one pass of addstar does either r or b */
+      if (photcode == USNO_RED) {
+	stars[Nusno].code  = USNO_RED;
+	stars[Nusno].M     = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000))));
+      } 
+      if (photcode == USNO_BLUE) {	
+	stars[Nusno].code  = USNO_BLUE;
+	stars[Nusno].M     = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000));
       }
-      buf = buffer;
-      /* print out data from slice within RA and DEC range */
-      for (i = 0; i < number[bin]; i++, buf+=3) {
-	if (buf[0] < iRA0) continue;
-	if (buf[0] > iRA1) continue;
-	if (buf[1] < iDEC0) continue;
-	if (buf[1] > iDEC1) continue;
-
-	bzero (&stars[Nusno], sizeof(Stars));
-	stars[Nusno].R     = buf[0]/360000.0;
-	stars[Nusno].D     = buf[1]/360000.0 - 90.0;
-	stars[Nusno].dM    = NO_ERR;
-	stars[Nusno].t     = 0;
-	stars[Nusno].found = -1;
-
-	/* one pass of addstar does either r or b */
-	if (photcode == USNO_RED) {
-	  stars[Nusno].code  = USNO_RED;
-	  stars[Nusno].M     = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000))));
-	} 
-	if (photcode == USNO_BLUE) {	
-	  stars[Nusno].code  = USNO_BLUE;
-	  stars[Nusno].M     = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000));
-	}
-	Nusno ++;
-	CHECK_REALLOCATE (stars, Stars, NUSNO, Nusno, 5000);
-      }
-      free (buffer);
+      Nusno ++;
+      CHECK_REALLOCATE (stars, Stars, NUSNO, Nusno, 5000);
     }
+    free (buffer);
     fclose (f);
   }
+  REALLOCATE (stars, Stars, Nusno);
 
-  *Nstars = Nusno;
+  *nstars = Nusno;
   if (VERBOSE) fprintf (stderr, "%d stars from USNO 1.0\n", Nusno);
   return (stars);
@@ -151,2 +140,20 @@
 
 
+
+
+/* these entries are legacy code incase you want to read from one of the USNO CDRoms
+int SPDzone[]  = {0, 75, 450, 375, 1500, 1650, 300, 1425, 1725, 525, 1275, 225, 675, 150, 600, 1575, 750, 975, 900, 1050, 1125, 1200, 825, 1350};
+int USNOdisk[] = {1,  1,   1,   2,    2,    2,   3,    3,    3,   4,    4,   5,   5,   6,   6,    6,   7,   7,   8,    8,    9,    9,  10,   10};
+
+    disk = -1;
+    for (i = 0; i < NZONE; i++) {
+      if (spd == SPDzone[i]) 
+	disk = USNOdisk[i];
+    }
+    if (disk < 0) {
+      fprintf (stderr, "ERROR: can't find cdrom for spd %d\n",  spd);
+      exit (1);
+    }
+
+*/
+
Index: /trunk/Ohana/src/addstar/src/getusnob.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getusnob.c	(revision 6675)
+++ /trunk/Ohana/src/addstar/src/getusnob.c	(revision 6675)
@@ -0,0 +1,167 @@
+# include "addstar.h"
+# define NZONE 180
+# define NBYTE   4
+# define NELEM  20
+
+Stars *getusnob (SkyRegion *catstats, int photcode, double epoch, int *nstars) {
+
+  long int offset;
+  int i, bin, first, last, nitems, Nitems, Nbins;
+  float hours[100];
+  int start[100], number[100], *buffer, *buf;
+  char filename[128];
+  FILE *f;
+  double dec;
+  double uR, uD;
+  float m1, m2, mag;
+  int iDEC0, iDEC1, iRA0, iRA1;
+  int spd, spd_start, spd_end;
+  int NUSNO, Nusno, Nstars;
+  Stars *stars;
+  short int USNO_RED, USNO_BLUE;
+
+  /* require photcode */
+  NAMED_PHOTCODE (USNO_RED, "USNO_RED");
+  NAMED_PHOTCODE (USNO_BLUE, "USNO_BLUE");
+  if (photcode == USNO_RED) goto good_code;
+  if (photcode == USNO_BLUE) goto good_code;
+  Shutdown ("USNO photcode not specified");
+good_code:
+
+  fprintf (stderr, "loading USNO-B 1.0\n");
+
+  /* identify ra & dec range of interest */
+  /* note: the use of UserPatch to restrict here limits general utility of function */
+  iRA0  =  MAX (catstats[0].Rmin, UserPatch.Rmin) * 360000.0;
+  iRA1  =  MIN (catstats[0].Rmax, UserPatch.Rmax) * 360000.0;
+  iDEC0 = (MAX (catstats[0].Dmin, UserPatch.Dmin) + 90.0) * 360000.0;
+  iDEC1 = (MIN (catstats[0].Dmax, UserPatch.Dmax) + 90.0) * 360000.0;
+  /* note that iDECn is in SPD, while both have units of 0.01 degrees */
+  
+  /* data is organized in south-pole distance zones, 1 deg per direction, 0.1 deg per file */
+  spd_start = (int)(10*(catstats[0].Dmin + 90));
+  dec = 10*(catstats[0].Dmax + 90);
+  if (dec > (int)(dec)) {
+    spd_end =   (int)(1 + 10*(catstats[0].Dmax + 90));
+  } else {
+    spd_end =   (int)(0 + 10*(catstats[0].Dmax + 90));
+  }
+
+  Nusno = 0;
+  NUSNO = 5000;
+  ALLOCATE (stars, Stars, NUSNO);
+
+  for (spd = spd_start; spd < spd_end; spd ++) {
+    
+    /* load accelerator file */
+    sprintf (filename, "%s/%03d/b%04d.acc", USNO_B_DIR, (int)(spd/10), spd); 
+    if (VERBOSE) fprintf (stderr, "reading from %s\n", filename);
+    f = fopen (filename, "r");
+    if (f == (FILE *) NULL) {
+      fprintf (stderr, "ERROR: can't open accelerator file %s\n", filename);
+      exit (1);  
+    }
+    for (i = 0; fscanf (f, "%f %d %d", &hours[i], &start[i], &number[i]) != EOF; i++);
+    Nbins = i;
+    fclose (f);
+    
+    first = catstats[0].Rmin / 3.75;
+    if ((catstats[0].Rmax / 3.75) == (int) (catstats[0].Rmax / 3.75)) 
+      last  = catstats[0].Rmax / 3.75;
+    else 
+      last  = 1 + catstats[0].Rmax / 3.75;
+
+    if ((first > Nbins) || (last > Nbins)) {
+      fprintf (stderr, "ERROR: RA out of range\n");
+      exit (1);
+    }
+    
+    /* open data file */
+    /* sprintf (filename, "%s/zone%04d.cat", USNO_B_DIR, spd); */
+    sprintf (filename, "%s/%03d/b%04d.cat", USNO_B_DIR, (int)(spd/10), spd); 
+    if (VERBOSE) fprintf (stderr, "reading from %s\n", filename);
+    f = fopen (filename, "r");
+    if (f == (FILE *) NULL) {
+      fprintf (stderr, "ERROR: can't open file %s\n", filename);
+      exit (1);
+    }
+
+    /** USNO-B consists of 20 x 4byte (int) records **/
+    /* advance file pointer to first slice */
+    offset = NELEM*NBYTE*(start[first] - 1);
+    fseek (f, offset, SEEK_SET);
+
+    /* sum the number of stars in data segment of interest */
+    Nstars = 0;
+    for (bin = first; bin < last; bin++) {
+      Nstars += number[bin];
+    }
+    Nitems = NELEM*Nstars;  
+    /* number of blocks to read -- we need to use Fread for byte-swapping read */
+
+    /* allocate space for stars in segment and read */
+    ALLOCATE (buffer, int, Nitems);
+    // data has the WRONG byte order?
+    // nitems = Fread (buffer, sizeof(int), Nitems, f, "int");
+    nitems = fread (buffer, NBYTE, Nitems, f);
+    if (nitems != Nitems) {
+      fprintf (stderr, "ERROR: failure reading data from file %s\n", filename);
+      exit (1);
+    }
+
+    buf = buffer;
+    /* print out data from slice within RA and DEC range */
+    for (i = 0; i < Nstars; i++, buf += NELEM) {
+      if (buf[0] < iRA0) continue;
+      if (buf[0] > iRA1) continue;
+      if (buf[1] < iDEC0) continue;
+      if (buf[1] > iDEC1) continue;
+      
+      /* extract the basic stellar data */
+      bzero (&stars[Nusno], sizeof(Stars));
+      stars[Nusno].R = buf[0]/360000.0;
+      stars[Nusno].D = buf[1]/360000.0 - 90.0;
+      stars[Nusno].dM    = NO_ERR;
+      stars[Nusno].t     = 0;
+      stars[Nusno].found = -1;
+      
+      /* one pass of addstar does either r or b */
+      if (photcode == USNO_RED) {
+	m1 = fabs(0.01 * (buf[7] % 10000)); /* 1st red mag */
+	m2 = fabs(0.01 * (buf[8] % 10000)); /* 2nd red mag */
+	stars[Nusno].code  = USNO_RED;
+      } else {
+	m1 = fabs(0.01 * (buf[5] % 10000)); /* 1st blue mag */
+	m2 = fabs(0.01 * (buf[6] % 10000)); /* 1st blue mag */
+	stars[Nusno].code  = USNO_BLUE;
+      }	
+
+      /* if two mags are available, get an average */
+      if (m1 && m2) {
+	mag = 0.5*(m1 + m2);
+      } else {
+	mag = (m1) ? m1 : m2;
+      }
+
+      uR = (buf[2] % 10000);
+      uR = (uR - 5000.0) * 0.002 / 3600.0;
+      uD = ((buf[2] / 10000) % 10000);
+      uD = (uD - 5000.0) * 0.002 / 3600.0;
+
+      /* need to carry the proper motions */
+      stars[Nusno].M = (mag == 0.0) ? 32.0 : mag;
+      stars[Nusno].R += uR*(epoch - 2000.0);
+      stars[Nusno].D += uD*(epoch - 2000.0);
+      Nusno ++;
+      CHECK_REALLOCATE (stars, Stars, NUSNO, Nusno, 5000);
+    }
+    free (buffer);
+    fclose (f);
+  }
+
+  REALLOCATE (stars, Stars, MAX (1, Nusno));
+
+  *nstars = Nusno;
+  if (VERBOSE) fprintf (stderr, "%d stars from USNO-B 1.0\n", Nusno);
+  return (stars);
+}
Index: /trunk/Ohana/src/addstar/src/greference.c
===================================================================
--- /trunk/Ohana/src/addstar/src/greference.c	(revision 6674)
+++ /trunk/Ohana/src/addstar/src/greference.c	(revision 6675)
@@ -17,4 +17,14 @@
   if (!strcasecmp (Refcat, "USNO")) {
     stars = getusno (region, photcode, &Nstars);
+  }
+
+  /* get stars from the USNO B catalog for the given region */
+  if (!strcasecmp (Refcat, "USNOB")) {
+    stars = getusnob (region, photcode, 2000.0, &Nstars);
+  }
+
+  /* get stars from the USNO B catalog for the given region */
+  if (!strcasecmp (Refcat, "TYCHO")) {
+    stars = gettycho (region, photcode, 2000.0, &Nstars);
   }
 
