Index: /trunk/Ohana/src/opihi/cmd.basic/macro.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.basic/macro.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/cmd.basic/macro.c	(revision 4470)
@@ -30,12 +30,8 @@
   }
 
-  /* sub-command was not found, pass argv[1..N] to macro create,
-     make argv[0] say "create" to be consistent (probably not needed) */
-  REALLOCATE (argv[0], char, 8);
-  strcpy (argv[0], "create");
+  /* sub-command was not found, pass argv[1..N] to macro_create */
   status = macro_create (argc, argv);
   return (status);
 }
-
 
 /* macro is called with the command "macro".  
Index: /trunk/Ohana/src/opihi/dvo/ccd.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/ccd.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/dvo/ccd.c	(revision 4470)
@@ -9,8 +9,8 @@
   Vector *xvec, *yvec;
 
-  char filename[256], catdir[256];
+  char filename[256], catdir[256], *CPTfile;
   double Radius;
   double *M1, *M2;
-  int i, m, k, Npts, NPTS;
+  int i, m, k, Npts, NPTS, N;
   int N1, N2, i1, i2, mode[4];
   int Ngraph, Nsec, Nregions, UseAverages;
@@ -33,4 +33,12 @@
   VarConfig ("CATDIR", "%s", catdir);
 
+  /* check for CPT selection */
+  CPTfile = NULL;
+  if (N = get_argument (argc, argv, "-cpt")) {
+    remove_argument (N, &argc, argv);
+    CPTfile = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }    
+
   /* interpret command-line options */
   if (!SetPhotSelections (&argc, argv)) goto usage;
@@ -47,7 +55,14 @@
   if ((mode[2] == MAG_AVE) || (mode[2] == MAG_REF)) UseAverages = TRUE;
 
-  /* find catalog files which overlap this region */
-  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
-  regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  /* determine region-file names */
+  if (CPTfile == NULL) {
+    float Radius;
+    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
+    regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  } else {
+    Nregions = 1;
+    ALLOCATE (regions, RegionFile, 1);
+    strcpy (regions[0].name, CPTfile);
+  }
 
   /* init vectors to save data */
Index: /trunk/Ohana/src/opihi/dvo/cmd.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/cmd.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/dvo/cmd.c	(revision 4470)
@@ -9,7 +9,7 @@
   Vector *xvec, *yvec;
 
-  char filename[256], catdir[256];
+  char filename[256], catdir[256], *CPTfile;
   double Radius, *M1, *M3;
-  int i, j, m, i1, i3, N1, N3;
+  int i, j, m, i1, i3, N1, N3, N;
   int Npts, NPTS, mode[3];
   int Ngraph, Nsec, Nregions;
@@ -32,4 +32,12 @@
   VarConfig ("CATDIR", "%s", catdir);
 
+  /* check for CPT selection */
+  CPTfile = NULL;
+  if (N = get_argument (argc, argv, "-cpt")) {
+    remove_argument (N, &argc, argv);
+    CPTfile = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }    
+
   /* interpret command-line options */
   if (!SetPhotSelections (&argc, argv)) goto usage;
@@ -43,7 +51,14 @@
   if (!GetPhotcodeInfo (argv[5], &code[2], &mode[2])) return (FALSE);
 
-  /* find catalog files which overlap this region */
-  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
-  regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  /* determine region-file names */
+  if (CPTfile == NULL) {
+    float Radius;
+    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
+    regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  } else {
+    Nregions = 1;
+    ALLOCATE (regions, RegionFile, 1);
+    strcpy (regions[0].name, CPTfile);
+  }
 
   /* init vectors to save data */
Index: /trunk/Ohana/src/opihi/dvo/dmagaves.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dmagaves.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/dvo/dmagaves.c	(revision 4470)
@@ -9,7 +9,7 @@
   Vector *xvec, *yvec;
 
-  char filename[256], catdir[256];
+  char filename[256], catdir[256], *CPTfile;
   double Radius, *M1, M2;
-  int i, j, k, m, N1;
+  int i, j, k, m, N1, N;
   int Npts, NPTS, param, mode[3];
   int Ngraph, Nsec, Nregions;
@@ -31,4 +31,12 @@
   /* find CATDIR in config system */
   VarConfig ("CATDIR", "%s", catdir);
+
+  /* check for CPT selection */
+  CPTfile = NULL;
+  if (N = get_argument (argc, argv, "-cpt")) {
+    remove_argument (N, &argc, argv);
+    CPTfile = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }    
 
   /* interpret command-line options */
@@ -57,9 +65,15 @@
   }
 
-  /* find catalog files which overlap this region */
-  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
-  regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
-  if (!SetImageSelection (param, &graphsky, TRUE)) return (FALSE);
-  
+  /* determine region-file names */
+  if (CPTfile == NULL) {
+    float Radius;
+    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
+    regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  } else {
+    Nregions = 1;
+    ALLOCATE (regions, RegionFile, 1);
+    strcpy (regions[0].name, CPTfile);
+  }
+
   /* init vectors to save data */
   Npts = 0;
Index: /trunk/Ohana/src/opihi/dvo/dmagmeas.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dmagmeas.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/dvo/dmagmeas.c	(revision 4470)
@@ -10,7 +10,7 @@
   Vector *xvec, *yvec;
 
-  char filename[256], catdir[256];
+  char filename[256], catdir[256], *CPTfile;
   double Radius, *M1, *M3;
-  int i, j, k, m, N1, N3;
+  int i, j, k, m, N1, N3, N;
   int Npts, NPTS, param, mode[3];
   int Ngraph, Nsec, Nregions;
@@ -32,4 +32,12 @@
   /* find CATDIR in config system */
   VarConfig ("CATDIR", "%s", catdir);
+
+  /* check for CPT selection */
+  CPTfile = NULL;
+  if (N = get_argument (argc, argv, "-cpt")) {
+    remove_argument (N, &argc, argv);
+    CPTfile = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }    
 
   /* interpret command-line options */
@@ -53,7 +61,14 @@
   }
 
-  /* find catalog files which overlap this region */
-  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
-  regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  /* determine region-file names */
+  if (CPTfile == NULL) {
+    float Radius;
+    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
+    regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  } else {
+    Nregions = 1;
+    ALLOCATE (regions, RegionFile, 1);
+    strcpy (regions[0].name, CPTfile);
+  }
   if (!SetImageSelection (param, &graphsky, TRUE)) return (FALSE);
 
Index: /trunk/Ohana/src/opihi/dvo/dmags.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dmags.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/dvo/dmags.c	(revision 4470)
@@ -9,7 +9,7 @@
   Vector *xvec, *yvec;
 
-  char filename[256], catdir[256];
+  char filename[256], catdir[256], *CPTfile;
   double Radius, *M1, *M3;
-  int i, j, m, i1, i3, N1, N3;
+  int i, j, m, i1, i3, N1, N3, N;
   int Npts, NPTS, mode[3];
   int Ngraph, Nsec, Nregions;
@@ -31,4 +31,12 @@
   /* find CATDIR in config system */
   VarConfig ("CATDIR", "%s", catdir);
+
+  /* check for CPT selection */
+  CPTfile = NULL;
+  if (N = get_argument (argc, argv, "-cpt")) {
+    remove_argument (N, &argc, argv);
+    CPTfile = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }    
 
   /* interpret command-line options */
@@ -52,7 +60,14 @@
   }
 
-  /* find catalog files which overlap this region */
-  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
-  regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  /* determine region-file names */
+  if (CPTfile == NULL) {
+    float Radius;
+    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
+    regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
+  } else {
+    Nregions = 1;
+    ALLOCATE (regions, RegionFile, 1);
+    strcpy (regions[0].name, CPTfile);
+  }
 
   /* init vectors to save data */
Index: /trunk/Ohana/src/opihi/lib.shell/command.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.shell/command.c	(revision 4469)
+++ /trunk/Ohana/src/opihi/lib.shell/command.c	(revision 4470)
@@ -5,5 +5,5 @@
 
   int i, status, argc;
-  char **argv;
+  char **argv, **targv;
   Command *cmd;
 
@@ -29,4 +29,8 @@
   if (argc == 0) return (TRUE);  /* empty command or assignment */
 
+  /* save the original values of argv since command may modify the array */
+  ALLOCATE (targv, char *, argc);
+  for (i = 0; i < argc; i++) targv[i] = argv[i];
+
   cmd = MatchCommand (argv[0], TRUE, FALSE);
   if (cmd == NULL) {
@@ -35,7 +39,9 @@
     free (argv[0]);
     argv[0] = strcreate (cmd[0].name);
+    targv[0] = argv[0];
     status = (*cmd[0].func) (argc, argv);
   }
-  for (i = 0; i < argc; i++) free (argv[i]);
+  for (i = 0; i < argc; i++) free (targv[i]);
+  free (targv);
   free (argv);
 
