Index: /trunk/Ohana/src/opihi/dimm/Analysis.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/Analysis.c	(revision 23289)
+++ /trunk/Ohana/src/opihi/dimm/Analysis.c	(revision 23290)
@@ -86,4 +86,83 @@
 	}
 
+/* find contiguous trigger pixels in row from starting point */
+
+int fillrow (float *buffer, int Nx, int offset, int sx, int *xs, int *xe) {
+
+  trigger = FALSE;
+  for (i = sx, pix = offset + i; buffer[pix] && (i < Nx); i++, pix++) {
+    addpix (pix);
+    buffer[pix] = 0;
+    trigger = TRUE;
+    *xe = i;
+  }
+  for (i = sx - 1, pix = offset + i; (i >= 0) && buffer[pix]; i--, pix--) {
+    addpix (pix);
+    buffer[pix] = 0;
+    trigger = TRUE;
+    *xs = i;
+  }
+  return (trigger);
+}
+
+static int Npix = 0;
+static int *Pix = (int *) NULL;
+
+addpix (int pix) {
+  Npix ++;
+  if (Pix == (int *) NULL) {
+    ALLOCATE (Pix, int, MAX (1, Npix));
+  } else {
+    REALLOCATE (Pix, int, MAX (1, Npix));
+  }    
+  Pix[Npix - 1] = pix;
+}
+
+clearpix () {
+  Npix = 0;
+  REALLOCATE (Pix, int, 1);
+}
+
+statpix (double *x, double *y, float *buffer, int Nx) {
+
+  int X, Y;
+  double Sx, Sy, So;
+
+  So = Sx = Sy = 0;
+  for (i = 0; i < Npix; i++) {
+    Y = pix / Nx;
+    X = pix % Nx;
+    So += buffer[pix];
+    Sx += X * buffer[pix];
+    Sy += Y * buffer[pix];
+  }
+  *x = Sx / So;
+  *y = Sy / So;
+}
+
+/* find stars: 
+   - binarize @ threshold
+   - find all contiguous blobs
+   - find geom center of each blob
+*/
+
+
+
+/*
+
+.....................
+....x................
+...xxx...............
+..........xxx..........
+.........xx..........
+.....................
+.....................
+.....................
+.....................
+.....................
+
+
+ */
+
 # endif
 
Index: /trunk/Ohana/src/opihi/dimm/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/dimm/Makefile	(revision 23289)
+++ /trunk/Ohana/src/opihi/dimm/Makefile	(revision 23290)
@@ -26,7 +26,7 @@
 $(SRC)/init.$(ARCH).o		  	\
 $(SRC)/dimm.$(ARCH).o		  	\
-$(SRC)/camera.$(ARCH).o	  	\
+$(SRC)/camera_cmds.$(ARCH).o	  	\
 $(SRC)/findstars.$(ARCH).o	  	\
-$(SRC)/telescope.$(ARCH).o   \
+$(SRC)/telescope_cmds.$(ARCH).o   \
 $(SRC)/version.$(ARCH).o
 
@@ -64,6 +64,5 @@
 .PHONY: dimm
 
-# are these used or replaced?
-# $(SRC)/analysis.$(ARCH).o	  	\
+# these have not been finished: should be used for analysis of the extracted images
 # $(SRC)/Analysis.$(ARCH).o            \
 # $(SRC)/Image.$(ARCH).o		\
Index: unk/Ohana/src/opihi/dimm/analysis.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/analysis.c	(revision 23289)
+++ 	(revision )
@@ -1,184 +1,0 @@
-
-/* should this all be wrapped within an opihi implementation? */
-
-typedef struct {
-
-  /* image data area */
-  int Nx, Ny;
-  char *buffer;
-  int Nbytes;
-
-  /* image metadata */
-  double ccdtemp;
-  double airtemp;
-  double ra, dec, airmass;
-  double exptime;
-  int binning;
-} Image;
-
-subtractImage (Image *a, Image *b) {
-
-  if (a[0].Nx != b[0].Nx) return (FALSE);
-  if (a[0].Ny != b[0].Ny) return (FALSE);
-
-  Npix = a[0].Nx*a[0].Ny;
-  ap = (float *) a[0].buffer;
-  bp = (float *) b[0].buffer;
-  for (i = 0; i < Npix; i++, ap++, bp++) {
-    *ap -= *bp;
-  }
-  return (FALSE);
-}
-
-statsImage (Image *image, Stats *stats) {
-
-  val = (float *)image[0].buffer;
-  max = min = val[0];
-  Npix = image[0].Nx*image[0].Ny;
-  for (i = 0; i < Npix; i++, val++) {
-    N1 += *val;
-    N2 += (*val)*(*val);
-    max = MAX (max, *val);
-    min = MIN (min, *val);
-  }
-  stats[0].mean  = N1 / Npix;
-  stats[0].sigma = sqrt (N2 / Npix - SQ(stats[0].mean));
-  stats[0].min = min;
-  stats[0].max = max;
-
-  stats[0].median = stats[0].mean;
-  range = MAX (0.5, 0xffff / (max - min));
-  if (range == 0) return ();
-
-  ALLOCATE (hist, int, 0x10000);
-  bzero (hist, 0x10000*sizeof(int));
-
-  val = (float *)image[0].buffer;
-  for (i = 0; i < Npix; i++) {
-    bin = MIN (MAX (0, (*val - min) * range), 0xffff);
-    hist[bin] ++;
-  }
-
-  Nhist = 0;
-  for (i = 0; (i < 0xffff) && (Nhist < 0.5*Npix); i++) 
-    Nhist += hist[i];
-  stats[0].median = i / range + min;
-  free (hist);
-
-  return ();
-}
-
-findStars (Image *image, Stars **stars, int *Nstars, double threshold) {
-
-  /* binarize @ threshold */
-
-  binimage = createImage (image[0].Nx, image[0].Ny);
-
-  Npix = image[0].Nx*image[0].Ny;
-  ap = image[0].buffer;
-  bp = binimage[0].buffer;
-  bzero (bp, Npix*sizeof (short));
-
-  for (i = 0; i < Npix; i++, ap++, bp++) {
-    if (*ap > threshold) * bp = 1;
-  }
-
-  clearpix ();
-
-  for (j = 0; j < Ny; j++) {
-    for (i = 0; i < Nx; i++) {
-      if (binimage.buffer[j*Nx + i]) {
-	status = fillrow (binimage.buffer, Nx, j*Nx, i, &xs, &xe);
-	for (J = j + 1; (J < Ny) && status; J++) {
-	  for (I = xs; !binimage.buffer[J*Nx + I] && (I < xe); I++);
-	  if (binimage.buffer[J*Nx + I]) {
-	    status = fillrow (binimage.buffer, Nx, J*Nx, I, &xs, &xe);
-	  } 
-	}  
-	/* we now have a stack of pixels, convert to a single star */
-	statpix (&x, &y, image[0].buffer, Nx);
-	addstar (x, y);
-	clearpix ();
-      }
-    }
-  }
-}
-
-/* find contiguous trigger pixels in row from starting point */
-
-int fillrow (float *buffer, int Nx, int offset, int sx, int *xs, int *xe) {
-
-  trigger = FALSE;
-  for (i = sx, pix = offset + i; buffer[pix] && (i < Nx); i++, pix++) {
-    addpix (pix);
-    buffer[pix] = 0;
-    trigger = TRUE;
-    *xe = i;
-  }
-  for (i = sx - 1, pix = offset + i; (i >= 0) && buffer[pix]; i--, pix--) {
-    addpix (pix);
-    buffer[pix] = 0;
-    trigger = TRUE;
-    *xs = i;
-  }
-  return (trigger);
-}
-
-static int Npix = 0;
-static int *Pix = (int *) NULL;
-
-addpix (int pix) {
-  Npix ++;
-  if (Pix == (int *) NULL) {
-    ALLOCATE (Pix, int, MAX (1, Npix));
-  } else {
-    REALLOCATE (Pix, int, MAX (1, Npix));
-  }    
-  Pix[Npix - 1] = pix;
-}
-
-clearpix () {
-  Npix = 0;
-  REALLOCATE (Pix, int, 1);
-}
-
-statpix (double *x, double *y, float *buffer, int Nx) {
-
-  int X, Y;
-  double Sx, Sy, So;
-
-  So = Sx = Sy = 0;
-  for (i = 0; i < Npix; i++) {
-    Y = pix / Nx;
-    X = pix % Nx;
-    So += buffer[pix];
-    Sx += X * buffer[pix];
-    Sy += Y * buffer[pix];
-  }
-  *x = Sx / So;
-  *y = Sy / So;
-}
-
-/* find stars: 
-   - binarize @ threshold
-   - find all contiguous blobs
-   - find geom center of each blob
-*/
-
-
-
-/*
-
-.....................
-....x................
-...xxx...............
-..........xxx..........
-.........xx..........
-.....................
-.....................
-.....................
-.....................
-.....................
-
-
- */
Index: unk/Ohana/src/opihi/dimm/camera.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/camera.c	(revision 23289)
+++ 	(revision )
@@ -1,130 +1,0 @@
-# include "dimm.h"
-# define EXIT_STATUS(S) { seteuid (UID); return (S); }
-
-static uid_t UID, EUID;
-
-SetEUID () {
-
-  /* save the UID (ID of calling process) and EUID (should be root) */
-  UID = getuid ();
-  EUID = geteuid ();
-  seteuid (UID);
-}
-
-int camera (int argc, char **argv) {
-  
-  /* USAGE: 
-     camera init port
-     camera expose exptime
-     camera readout x y dx dy
-     camera temp set value
-     camera temp get var
-  */
-
-  if (argc < 2) goto usage;
-
-  seteuid (EUID);
-  
-  if (!strcasecmp (argv[1], "init")) {
-    int port, status;
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: camera init (port)\n");
-      EXIT_STATUS (FALSE);
-    }
-    sscanf (argv[2], "%x", &port);
-    status = InitCamera (port);
-    EXIT_STATUS (status);
-  }
-
-  if (!strcasecmp (argv[1], "expose")) {
-
-    int status;
-    double exptime;
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: camera expose (exptime)\n");
-      EXIT_STATUS (FALSE);
-    }
-    exptime = atof (argv[2]);
-    status = Exposure (exptime);
-    EXIT_STATUS (status);
-  }
-
-  if (!strcasecmp (argv[1], "temp")) {
-
-    int status;
-    double temp;
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: camera temp (temperature)\n");
-      EXIT_STATUS (FALSE);
-    }
-    temp = atof (argv[2]);
-    status = SetTemperature (temp);
-    EXIT_STATUS (status);
-  }
-
-  if (!strcasecmp (argv[1], "status")) {
-
-    int status;
-    double temp;
-
-    if (argc != 2) {
-      gprint (GP_ERR, "USAGE: camera status\n");
-      EXIT_STATUS (FALSE);
-    }
-    DumpCameraStatus ();
-    EXIT_STATUS (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "readout")) {
-
-    int Nbuf, status;
-    double temp;
-    int x, y, dx, dy, NX, NY;
-    Buffer *buf;
-
-    if ((argc != 7) && (argc != 3)) {
-      gprint (GP_ERR, "USAGE: camera readout (buffer) x y dx dy\n");
-      EXIT_STATUS (FALSE);
-    }
-
-    if ((buf = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) EXIT_STATUS (FALSE);
-
-    CameraFullSize (&NX, &NY);
-    x = y = 0;
-    dx = NX;
-    dy = NY;
-    if (argc == 7) {
-      x  = atof (argv[3]);
-      y  = atof (argv[4]);
-      dx = atof (argv[5]);
-      dy = atof (argv[6]);
-    } 
-
-    /* generate a buffer to store the image */
-    gfits_free_matrix (&buf[0].matrix);
-    gfits_free_header (&buf[0].header);
-    CreateBuffer (buf, dx, dy, -32, 0.0, 1.0);
-    strcpy (buf[0].file, "(empty)");
-
-    ReadOut (x, y, dx, dy, 1, buf[0].matrix.buffer);
-
-    gfits_convert_format (&buf[0].header, &buf[0].matrix, -32, 1.0, 0.0, 0xffff, gfits_get_unsign_mode());
-
-    EXIT_STATUS (TRUE);
-  }
-
-usage:
-  gprint (GP_ERR, "camera init port\n");
-  gprint (GP_ERR, "camera expose exptime\n");
-  gprint (GP_ERR, "camera readout x y dx dy\n");
-  gprint (GP_ERR, "camera temp set value\n");
-  gprint (GP_ERR, "camera temp get var\n");
-  seteuid (UID);
-  return (FALSE);
-
-}
-
-
Index: /trunk/Ohana/src/opihi/dimm/camera_cmds.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/camera_cmds.c	(revision 23290)
+++ /trunk/Ohana/src/opihi/dimm/camera_cmds.c	(revision 23290)
@@ -0,0 +1,130 @@
+# include "dimm.h"
+# define EXIT_STATUS(S) { seteuid (UID); return (S); }
+
+static uid_t UID, EUID;
+
+SetEUID () {
+
+  /* save the UID (ID of calling process) and EUID (should be root) */
+  UID = getuid ();
+  EUID = geteuid ();
+  seteuid (UID);
+}
+
+int camera (int argc, char **argv) {
+  
+  /* USAGE: 
+     camera init port
+     camera expose exptime
+     camera readout x y dx dy
+     camera temp set value
+     camera temp get var
+  */
+
+  if (argc < 2) goto usage;
+
+  seteuid (EUID);
+  
+  if (!strcasecmp (argv[1], "init")) {
+    int port, status;
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: camera init (port)\n");
+      EXIT_STATUS (FALSE);
+    }
+    sscanf (argv[2], "%x", &port);
+    status = InitCamera (port);
+    EXIT_STATUS (status);
+  }
+
+  if (!strcasecmp (argv[1], "expose")) {
+
+    int status;
+    double exptime;
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: camera expose (exptime)\n");
+      EXIT_STATUS (FALSE);
+    }
+    exptime = atof (argv[2]);
+    status = Exposure (exptime);
+    EXIT_STATUS (status);
+  }
+
+  if (!strcasecmp (argv[1], "temp")) {
+
+    int status;
+    double temp;
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: camera temp (temperature)\n");
+      EXIT_STATUS (FALSE);
+    }
+    temp = atof (argv[2]);
+    status = SetTemperature (temp);
+    EXIT_STATUS (status);
+  }
+
+  if (!strcasecmp (argv[1], "status")) {
+
+    int status;
+    double temp;
+
+    if (argc != 2) {
+      gprint (GP_ERR, "USAGE: camera status\n");
+      EXIT_STATUS (FALSE);
+    }
+    DumpCameraStatus ();
+    EXIT_STATUS (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "readout")) {
+
+    int Nbuf, status;
+    double temp;
+    int x, y, dx, dy, NX, NY;
+    Buffer *buf;
+
+    if ((argc != 7) && (argc != 3)) {
+      gprint (GP_ERR, "USAGE: camera readout (buffer) x y dx dy\n");
+      EXIT_STATUS (FALSE);
+    }
+
+    if ((buf = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) EXIT_STATUS (FALSE);
+
+    CameraFullSize (&NX, &NY);
+    x = y = 0;
+    dx = NX;
+    dy = NY;
+    if (argc == 7) {
+      x  = atof (argv[3]);
+      y  = atof (argv[4]);
+      dx = atof (argv[5]);
+      dy = atof (argv[6]);
+    } 
+
+    /* generate a buffer to store the image */
+    gfits_free_matrix (&buf[0].matrix);
+    gfits_free_header (&buf[0].header);
+    CreateBuffer (buf, dx, dy, -32, 0.0, 1.0);
+    strcpy (buf[0].file, "(empty)");
+
+    ReadOut (x, y, dx, dy, 1, buf[0].matrix.buffer);
+
+    gfits_convert_format (&buf[0].header, &buf[0].matrix, -32, 1.0, 0.0, 0xffff, gfits_get_unsign_mode());
+
+    EXIT_STATUS (TRUE);
+  }
+
+usage:
+  gprint (GP_ERR, "camera init port\n");
+  gprint (GP_ERR, "camera expose exptime\n");
+  gprint (GP_ERR, "camera readout x y dx dy\n");
+  gprint (GP_ERR, "camera temp set value\n");
+  gprint (GP_ERR, "camera temp get var\n");
+  seteuid (UID);
+  return (FALSE);
+
+}
+
+
Index: unk/Ohana/src/opihi/dimm/telescope.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/telescope.c	(revision 23289)
+++ 	(revision )
@@ -1,234 +1,0 @@
-# include "dimm.h"
-
-double distSky (double r1, double r2, double d1, double d2);
-
-int telescope (int argc, char **argv) {
-  
-  if (argc < 2) goto usage;
-
-  if (!strcasecmp (argv[1], "init")) {
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: telescope init (port)\n");
-      return (FALSE);
-    }
-    if (!SerialInit (argv[2])) return (FALSE);
-    gprint (GP_ERR, "telescope on port %s\n", argv[2]);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "cmd")) {
-
-    int status;
-    char *answer = (char *) NULL;
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: telescope cmd (string)\n");
-      return (FALSE);
-    }
-    status = SerialCommand (argv[2], &answer, 10);
-    gprint (GP_ERR, "status: %d\n", status);
-    if (answer != (char *) NULL) {
-      gprint (GP_ERR, "answer: ..%s..\n", answer);
-    }
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "ack")) {
-
-    int status;
-    char line[32], *answer;
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: telescope cmd (string)\n");
-      return (FALSE);
-    }
-    line[0] = 0x06;
-    line[1] = 0;
-    status = SerialCommand (line, &answer, 10);
-    gprint (GP_ERR, "status: %d\n", status);
-    if (answer != (char *) NULL) {
-      gprint (GP_ERR, "answer: ..%s..\n", answer);
-    }
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "slew")) {
-
-    double ra, dec;
-    int status;
-
-    if (argc != 4) {
-      gprint (GP_ERR, "USAGE: telescope slew (ra) (dec)\n");
-      return (FALSE);
-    }
-
-    ra  = ohana_normalize_angle(atof (argv[2]));
-    dec = atof (argv[3]);
-
-    status = gotoRD (ra, dec);
-
-    if (!status) return (FALSE);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "coords")) {
-
-    int status;
-    double ra, dec;
-    char line[64];
-
-    if (argc != 2) {
-      gprint (GP_ERR, "USAGE: telescope coords\n");
-      return (FALSE);
-    }
-
-    if (!getRD (&ra, &dec)) return (FALSE);
-    gprint (GP_ERR, "%f %f\n", ra, dec);
-    set_variable ("RA", ra);
-    set_variable ("DEC", dec);
-    dms_format (line, (ra/15.0));
-    set_str_variable ("Rs", line);
-    dms_format (line, dec);
-    set_str_variable ("Ds", line);
-
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "altaz")) {
-
-    int status;
-    double x, y;
-
-    if (argc != 2) {
-      gprint (GP_ERR, "USAGE: telescope altaz\n");
-      return (FALSE);
-    }
-
-    if (!getXY (&x, &y)) return (FALSE);
-    gprint (GP_ERR, "%f %f\n", x, y);
-    set_variable ("ALT", x);
-    set_variable ("AZ", y);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "site")) {
-
-    int status;
-    double lon, lat, LST;
-
-    if (argc != 2) {
-      gprint (GP_ERR, "USAGE: telescope site\n");
-      return (FALSE);
-    }
-
-    if (!getSite (&lon, &lat, &LST)) return (FALSE);
-    gprint (GP_ERR, "%f %f  %f\n", lon, lat, LST);
-    set_variable ("LON", lon);
-    set_variable ("LAT", lat);
-    set_variable ("LST", LST);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "setsite")) {
-
-    double lon, lat;
-
-    if (argc != 5) {
-      gprint (GP_ERR, "USAGE: telescope setsite (name) (longitude) (latitude)\n");
-      return (FALSE);
-    }
-
-    lon = atof (argv[3]);
-    lat = atof (argv[4]);
-    if (!setSite (argv[2], lon, lat)) return (FALSE);
-    set_variable ("LON", lon);
-    set_variable ("LAT", lat);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "settime")) {
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: telescope settime (lst)\n");
-      return (FALSE);
-    }
-
-    if (!setTime (argv[2])) return (FALSE);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "verbose")) {
-
-    int mode;
-
-    if (argc != 3) {
-      gprint (GP_ERR, "USAGE: telescope verbose (mode)\n");
-      return (FALSE);
-    }
-
-    mode = atoi (argv[2]);
-    SerialVerbose (mode);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "setcoords")) {
-
-    int status;
-    double ra, dec;
-
-    if (argc != 4) {
-      gprint (GP_ERR, "USAGE: telescope setcoords (ra) (dec)\n");
-      return (FALSE);
-    }
-
-    ra  = atof (argv[2]);
-    dec = atof (argv[3]);
-
-    if (!setRD (ra, dec)) return (FALSE);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "offset")) {
-
-    int status;
-
-    if (argc != 4) {
-      gprint (GP_ERR, "USAGE: telescope offset (direction) (distance)\n");
-      gprint (GP_ERR, "  direction : x or y\n");
-      gprint (GP_ERR, "  distance  : +arcmin or -arcmin\n");
-      return (FALSE);
-    }
-    status = offset (argv[2], atof (argv[3]));
-
-    if (!status) return (FALSE);
-    return (TRUE);
-  }
-
-  if (!strcasecmp (argv[1], "toffset")) {
-
-    int status;
-
-    if (argc != 5) {
-      gprint (GP_ERR, "USAGE: telescope toffset (direction) (rate) (duration)\n");
-      gprint (GP_ERR, "example: telescope toffset x RC 1.5\n");
-      return (FALSE);
-    }
-    status = toffset (argv[2], argv[3], atof(argv[4]));
-
-    if (!status) return (FALSE);
-    return (TRUE);
-  }
-
- usage:
-  gprint (GP_ERR, "telescope init port - set serial port (eg, /dev/ttyS0)\n");
-  gprint (GP_ERR, "telescope site - get site information\n");
-  gprint (GP_ERR, "telescope altaz - g\n");
-  gprint (GP_ERR, "telescope setcoords (ra) (dec)\n");
-  gprint (GP_ERR, "telescope setsite (name) (longitute) (latitude)\n");
-  gprint (GP_ERR, "telescope coords\n");
-  gprint (GP_ERR, "telescope slew (ra) (dec)\n");
-  gprint (GP_ERR, "telescope offset (direction) (duration)\n");
-  gprint (GP_ERR, "telescope toffset (direction) (rate) (duration)\n");
-  return (FALSE);
-}
-
Index: /trunk/Ohana/src/opihi/dimm/telescope_cmds.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/telescope_cmds.c	(revision 23290)
+++ /trunk/Ohana/src/opihi/dimm/telescope_cmds.c	(revision 23290)
@@ -0,0 +1,234 @@
+# include "dimm.h"
+
+double distSky (double r1, double r2, double d1, double d2);
+
+int telescope (int argc, char **argv) {
+  
+  if (argc < 2) goto usage;
+
+  if (!strcasecmp (argv[1], "init")) {
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: telescope init (port)\n");
+      return (FALSE);
+    }
+    if (!SerialInit (argv[2])) return (FALSE);
+    gprint (GP_ERR, "telescope on port %s\n", argv[2]);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "cmd")) {
+
+    int status;
+    char *answer = (char *) NULL;
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: telescope cmd (string)\n");
+      return (FALSE);
+    }
+    status = SerialCommand (argv[2], &answer, 10);
+    gprint (GP_ERR, "status: %d\n", status);
+    if (answer != (char *) NULL) {
+      gprint (GP_ERR, "answer: ..%s..\n", answer);
+    }
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "ack")) {
+
+    int status;
+    char line[32], *answer;
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: telescope cmd (string)\n");
+      return (FALSE);
+    }
+    line[0] = 0x06;
+    line[1] = 0;
+    status = SerialCommand (line, &answer, 10);
+    gprint (GP_ERR, "status: %d\n", status);
+    if (answer != (char *) NULL) {
+      gprint (GP_ERR, "answer: ..%s..\n", answer);
+    }
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "slew")) {
+
+    double ra, dec;
+    int status;
+
+    if (argc != 4) {
+      gprint (GP_ERR, "USAGE: telescope slew (ra) (dec)\n");
+      return (FALSE);
+    }
+
+    ra  = ohana_normalize_angle(atof (argv[2]));
+    dec = atof (argv[3]);
+
+    status = gotoRD (ra, dec);
+
+    if (!status) return (FALSE);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "coords")) {
+
+    int status;
+    double ra, dec;
+    char line[64];
+
+    if (argc != 2) {
+      gprint (GP_ERR, "USAGE: telescope coords\n");
+      return (FALSE);
+    }
+
+    if (!getRD (&ra, &dec)) return (FALSE);
+    gprint (GP_ERR, "%f %f\n", ra, dec);
+    set_variable ("RA", ra);
+    set_variable ("DEC", dec);
+    dms_format (line, (ra/15.0));
+    set_str_variable ("Rs", line);
+    dms_format (line, dec);
+    set_str_variable ("Ds", line);
+
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "altaz")) {
+
+    int status;
+    double x, y;
+
+    if (argc != 2) {
+      gprint (GP_ERR, "USAGE: telescope altaz\n");
+      return (FALSE);
+    }
+
+    if (!getXY (&x, &y)) return (FALSE);
+    gprint (GP_ERR, "%f %f\n", x, y);
+    set_variable ("ALT", x);
+    set_variable ("AZ", y);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "site")) {
+
+    int status;
+    double lon, lat, LST;
+
+    if (argc != 2) {
+      gprint (GP_ERR, "USAGE: telescope site\n");
+      return (FALSE);
+    }
+
+    if (!getSite (&lon, &lat, &LST)) return (FALSE);
+    gprint (GP_ERR, "%f %f  %f\n", lon, lat, LST);
+    set_variable ("LON", lon);
+    set_variable ("LAT", lat);
+    set_variable ("LST", LST);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "setsite")) {
+
+    double lon, lat;
+
+    if (argc != 5) {
+      gprint (GP_ERR, "USAGE: telescope setsite (name) (longitude) (latitude)\n");
+      return (FALSE);
+    }
+
+    lon = atof (argv[3]);
+    lat = atof (argv[4]);
+    if (!setSite (argv[2], lon, lat)) return (FALSE);
+    set_variable ("LON", lon);
+    set_variable ("LAT", lat);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "settime")) {
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: telescope settime (lst)\n");
+      return (FALSE);
+    }
+
+    if (!setTime (argv[2])) return (FALSE);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "verbose")) {
+
+    int mode;
+
+    if (argc != 3) {
+      gprint (GP_ERR, "USAGE: telescope verbose (mode)\n");
+      return (FALSE);
+    }
+
+    mode = atoi (argv[2]);
+    SerialVerbose (mode);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "setcoords")) {
+
+    int status;
+    double ra, dec;
+
+    if (argc != 4) {
+      gprint (GP_ERR, "USAGE: telescope setcoords (ra) (dec)\n");
+      return (FALSE);
+    }
+
+    ra  = atof (argv[2]);
+    dec = atof (argv[3]);
+
+    if (!setRD (ra, dec)) return (FALSE);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "offset")) {
+
+    int status;
+
+    if (argc != 4) {
+      gprint (GP_ERR, "USAGE: telescope offset (direction) (distance)\n");
+      gprint (GP_ERR, "  direction : x or y\n");
+      gprint (GP_ERR, "  distance  : +arcmin or -arcmin\n");
+      return (FALSE);
+    }
+    status = offset (argv[2], atof (argv[3]));
+
+    if (!status) return (FALSE);
+    return (TRUE);
+  }
+
+  if (!strcasecmp (argv[1], "toffset")) {
+
+    int status;
+
+    if (argc != 5) {
+      gprint (GP_ERR, "USAGE: telescope toffset (direction) (rate) (duration)\n");
+      gprint (GP_ERR, "example: telescope toffset x RC 1.5\n");
+      return (FALSE);
+    }
+    status = toffset (argv[2], argv[3], atof(argv[4]));
+
+    if (!status) return (FALSE);
+    return (TRUE);
+  }
+
+ usage:
+  gprint (GP_ERR, "telescope init port - set serial port (eg, /dev/ttyS0)\n");
+  gprint (GP_ERR, "telescope site - get site information\n");
+  gprint (GP_ERR, "telescope altaz - g\n");
+  gprint (GP_ERR, "telescope setcoords (ra) (dec)\n");
+  gprint (GP_ERR, "telescope setsite (name) (longitute) (latitude)\n");
+  gprint (GP_ERR, "telescope coords\n");
+  gprint (GP_ERR, "telescope slew (ra) (dec)\n");
+  gprint (GP_ERR, "telescope offset (direction) (duration)\n");
+  gprint (GP_ERR, "telescope toffset (direction) (rate) (duration)\n");
+  return (FALSE);
+}
+
