Index: trunk/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 29001)
+++ trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 29540)
@@ -102,5 +102,6 @@
 $(SRC)/read_vectors.$(ARCH).o	\
 $(SRC)/rebin.$(ARCH).o		\
-$(SRC)/resize.$(ARCH).o	\
+$(SRC)/reindex.$(ARCH).o	\
+$(SRC)/resize.$(ARCH).o		\
 $(SRC)/relocate.$(ARCH).o	\
 $(SRC)/roll.$(ARCH).o		\
Index: trunk/Ohana/src/opihi/cmd.data/center.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/center.c	(revision 29001)
+++ trunk/Ohana/src/opihi/cmd.data/center.c	(revision 29540)
@@ -16,4 +16,6 @@
   if (!GetImage (NULL, &kapa, name)) return (FALSE);
   FREE (name);
+
+  // XXX need an option to center the image based on the current plot limits
 
   if ((argc != 3) && (argc != 4)) {
Index: trunk/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/init.c	(revision 29001)
+++ trunk/Ohana/src/opihi/cmd.data/init.c	(revision 29540)
@@ -91,4 +91,5 @@
 int rebin            PROTO((int, char **));
 int resize           PROTO((int, char **));
+int reindex          PROTO((int, char **));
 int relocate         PROTO((int, char **));
 int roll             PROTO((int, char **));
@@ -232,4 +233,5 @@
   {1, "read",         read_vectors,     "read vectors from datafile"},
   {1, "rebin",        rebin,            "rebin image data by factor of N"},
+  {1, "reindex",      reindex,          "create new vector from old vector based on index vector"},
   {1, "resize",       resize,           "set graphics/image window size"},
   {1, "relocate",     relocate,         "set graphics/image window position"},
Index: trunk/Ohana/src/opihi/cmd.data/limits.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/limits.c	(revision 29001)
+++ trunk/Ohana/src/opihi/cmd.data/limits.c	(revision 29540)
@@ -24,4 +24,6 @@
   if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
   FREE (name);
+
+  // XXX need an option to set the limits based on the current image bounds
 
   if (argc == 1) {
Index: trunk/Ohana/src/opihi/cmd.data/read_vectors.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 29001)
+++ trunk/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 29540)
@@ -216,5 +216,12 @@
 
     while (1) {
-      if (!gfits_load_header (f, &header)) ESCAPE ("extension not found in file");
+      if (!gfits_load_header (f, &header)) {
+	gprint (GP_ERR, "extension %s not found in file\n", extname);
+	if (CCDKeyword != NULL) free (CCDKeyword); 
+	gfits_free_table  (&table); 
+	gfits_free_header (&header); 
+	return (TRUE);  
+      }
+
       Nbytes = gfits_data_size (&header);
 
Index: trunk/Ohana/src/opihi/cmd.data/reindex.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/reindex.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/reindex.c	(revision 29540)
@@ -0,0 +1,66 @@
+# include "data.h"
+
+# define ESCAPE(MSG,...){ gprint (GP_ERR, MSG, __VA_ARGS__); goto error; } 
+
+int reindex (int argc, char **argv) {
+  
+  int  i, Npts, Nmax, valid;
+  Vector *ivec, *ovec, *xvec;
+
+  ivec = ovec = xvec = NULL;
+  Npts = 0;
+
+  valid = TRUE;
+  valid &= (argc >= 6);
+  valid &= !strcmp(argv[2], "=");
+  valid &= !strcmp(argv[4], "using");
+  if (!valid) {
+    gprint (GP_ERR, "USAGE: reindex (out) = (in) using (index)\n");
+    gprint (GP_ERR, "  creates a new vectors (out) from (in) based on sequence in (index)\n");
+    return (FALSE);
+  }
+
+  if ((ovec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto error;
+  if ((ivec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) goto error;
+  if ((xvec = SelectVector (argv[5], OLDVECTOR, TRUE)) == NULL) goto error;
+
+  if (xvec->type != OPIHI_INT) ESCAPE("%s\n", "index is not an integer?");
+
+  // ovec matches ivec in type and xvec in size (xvec need not have all ivec elements, and may have duplicates
+  ResetVector (ovec, ivec->type, MAX (xvec[0].Nelements, 1));
+
+  Nmax = ivec[0].Nelements - 1;
+
+  // we have two cases: (ivec == flt or int)
+  if (ivec->type == OPIHI_FLT) {
+    opihi_flt *vi = ivec[0].elements.Flt;
+    opihi_int *vx = xvec[0].elements.Int;
+    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
+      if (*vx == -1) continue;
+      if (*vx < 0) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
+      if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
+      ovec[0].elements.Flt[Npts] = vi[*vx];
+      Npts++;
+    }
+  }
+  if (ivec->type == OPIHI_INT) {
+    opihi_int *vi = ivec[0].elements.Int;
+    opihi_int *vx = xvec[0].elements.Int;
+    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
+      if (*vx == -1) continue;
+      if (*vx < 0) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
+      if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
+      ovec[0].elements.Int[Npts] = vi[*vx];
+      Npts++;
+    }
+  }
+
+  // free up unused memory
+  ResetVector (ovec, ivec->type, MAX (Npts, 1));
+  return (TRUE);
+
+error:
+  DeleteVector (ovec);
+  return (FALSE);
+}
+
Index: trunk/Ohana/src/opihi/cmd.data/svd.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/svd.c	(revision 29001)
+++ trunk/Ohana/src/opihi/cmd.data/svd.c	(revision 29540)
@@ -82,6 +82,6 @@
       }
 
-# if 0     
-      status = svdcmp_bond_raw (Ny, Nx, 1, 1, FLT_EPSILON, 1e-6, a, q, u, v);
+# if 1     
+      status = svdcmp_bond_new (Ny, Nx, 1, 1, FLT_EPSILON, 1e-6, a, q, u, v);
       fprintf (stderr, "status: %d\n", status);
 # else
