Index: /branches/eam_branches/ipp-20130711/Ohana/src/opihi/dvo/avmatch.c
===================================================================
--- /branches/eam_branches/ipp-20130711/Ohana/src/opihi/dvo/avmatch.c	(revision 35872)
+++ /branches/eam_branches/ipp-20130711/Ohana/src/opihi/dvo/avmatch.c	(revision 35873)
@@ -70,40 +70,6 @@
   dbExtractAveragesInit (); 
 
-  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
   RAvec  = NULL;
   DECvec = NULL;
-  if (PARALLEL && !HOST_ID) {
-    if (!CoordsFile) {
-      // get vectors corresponding to coordinates of interest
-      if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
-      if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
-      
-      ALLOCATE (vec, Vector *, 2);
-      vec[0] = RAvec;
-      vec[1] = DECvec;
-
-      CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
-      if (!status) goto escape;
-    }
-
-    char *targv1 = argv[1];
-    char *targv2 = argv[2];
-    argv[1] = strcreate ("-coords");
-    argv[2] = strcreate (CoordsFile);
-    free (CoordsFile);
-
-    // I need to pass the RA & DEC vectors to the remote clients...
-    int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, RAvec->Nelements, VERBOSE);
-    if (vec) free (vec);
-    
-    free (argv[1]);
-    free (argv[2]);
-    argv[1] = targv1;
-    argv[2] = targv2;
-
-    return status;
-  }
-
   // get vectors corresponding to coordinates of interest
   if (CoordsFile) {
@@ -120,4 +86,55 @@
     remove_argument (1, &argc, argv);
   }
+
+  /* load regions which contain all supplied RA,DEC coordinates */
+  if ((skylist = SelectRegionsByCoordVectors (RAvec, DECvec)) == NULL) goto escape;
+
+  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
+  if (PARALLEL && !HOST_ID) {
+
+    // We need to copy the args to a temp array and modify them so that we send the
+    // correct set to the remote client.  The args list looks like this:
+    // if (!CoordsFile) : avmatch (RADIUS) field, ... [we removed RA & DEC above]
+    // if ( CoordsFile) : avmatch (RADIUS) field, ... [because we stripped off the -coords filename elements]
+
+    // allocate the temp array and copy all but (RA) (DEC)
+    int targc = 0;
+    char **targv = NULL;
+    ALLOCATE (targv, char *, argc + 2);
+    for (i = 0; i < argc; i++) {
+      targv[targc] = strcreate (argv[i]);
+      targc ++;
+    }
+
+    // if not specified, create the coords.fits input file
+    // NOTE: RAvec, DECvec were set above
+    if (!CoordsFile) {
+      ALLOCATE (vec, Vector *, 2);
+      vec[0] = RAvec;
+      vec[1] = DECvec;
+
+      CoordsFile = abspath("coords.fits", 1024);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
+      if (!status) goto escape;
+    }
+
+    // add the coords file to the args list
+    targv[targc+0] = strcreate ("-coords");
+    targv[targc+1] = CoordsFile; // this gets freed with targv
+    targc += 2;
+    
+    // I need to pass the RA & DEC vectors to the remote clients...
+    int status = HostTableParallelOps (skylist, targc, targv, RESULT_FILE, TRUE, RAvec->Nelements, VERBOSE);
+    if (vec) free (vec);
+    
+    // free up targv
+    for (i = 0; i < targc; i++) {
+      free (targv[i]);
+    }
+    free (targv);
+
+    return status;
+  }
+
   RADIUS = atof (argv[1]);
   remove_argument (1, &argc, argv);
@@ -140,7 +157,4 @@
     if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
   }
-
-  /* load regions which contain all supplied RA,DEC coordinates */
-  if ((skylist = SelectRegionsByCoordVectors (RAvec, DECvec)) == NULL) goto escape;
 
   /* create output storage vectors */
