Index: trunk/Ohana/src/opihi/dvo/calextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/calextract.c	(revision 3689)
+++ trunk/Ohana/src/opihi/dvo/calextract.c	(revision 4585)
@@ -5,14 +5,13 @@
 int calextract (int argc, char **argv) {
   
+  int i, j, m, N, Nr, Nregions, mode[2];
+  int Nsec, NSTAR;
+  char filename[256], catdir[256], *RegionName, *RegionList;
+  double Radius, M1, M2, dM2, color;
+
   Catalog catalog;
-  Graphdata graphsky;
   RegionFile *regions;
   PhotCode *code[2];
   Vector **vec;
-
-  int i, j, m, N, Nr, Nregions, mode[2];
-  int RegionList, Ngraph, Nsec, NSTAR;
-  char filename[256], catdir[256], RegionListFile[256];
-  double Radius, M1, M2, dM2, color;
 
   /* these need to be freed in the end */
@@ -21,4 +20,6 @@
   catalog.secfilt = NULL;
   catalog.measure = NULL;
+  RegionName = NULL;
+  RegionList = NULL;
 
   /* load photcode information */
@@ -26,22 +27,12 @@
   Nsec = GetPhotcodeNsecfilt ();
 
-  /* load data about plot windows */
-  Ngraph = 0;
-  if (!GetGraphData (&graphsky, NULL, &Ngraph)) goto escape;
-
   /* find CATDIR in config system */
-  VarConfig ("CATDIR", "%s", catdir);
-
-  /* specify catalog files */
-  RegionList = FALSE;
-  if (N = get_argument (argc, argv, "-list")) {
-    RegionList = TRUE;
-    remove_argument (N, &argc, argv);
-    strcpy (RegionListFile, argv[N]);
-    remove_argument (N, &argc, argv);
-  }
+  if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
 
   /* command line arguments */
-  if (!SetPhotSelections (&argc, argv)) goto usage;
+  SetSelectionParam (0);
+  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
+  if (!SetPhotSelections (&argc, argv, 2)) goto usage;
+
   if (argc != 4) goto usage;
   if (strcmp (argv[2], "-")) goto usage;
@@ -66,11 +57,6 @@
   if ((vec[Nd2] = SelectVector ("cal:dm2",      ANYVECTOR, TRUE)) == NULL) goto escape;
 
-  /* select region files */
-  if (RegionList) {
-    regions = region_list (RegionListFile, &Nregions);
-  } else {
-    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
-    regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions);
-  }
+  /* load region corresponding to selection above */
+  if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
 
   for (Nr = 0; Nr < Nregions; Nr++) {
@@ -150,4 +136,6 @@
  escape:
   
+  if (RegionName != NULL) free (RegionName);
+  if (RegionList != NULL) free (RegionList);
   if (regions != NULL) free (regions);  
   for (i = 0; i < NVEC; i++) {
