Index: trunk/psastro/src/psastroLoadRefstars.c
===================================================================
--- trunk/psastro/src/psastroLoadRefstars.c	(revision 15538)
+++ trunk/psastro/src/psastroLoadRefstars.c	(revision 15562)
@@ -15,5 +15,4 @@
     float DECmin = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MIN");
     float DECmax = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MAX");
-    // float MAGmax = psMetadataLookupF32(NULL, recipe, "MAG_MAX");
 
     // XXX CATDIR needs to look up abstracted name from psastro.config
@@ -25,4 +24,12 @@
     char *getstarCommand = psStringCopy(psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR"));
     PS_ASSERT (getstarCommand, NULL);
+
+    char *outformat = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.OUTFORMAT");
+    PS_ASSERT (outformat, NULL);
+
+    char *photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE");
+    PS_ASSERT (photcode, NULL);
+
+    float MAGmax = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MAG.MAX");
 
     // issue the following command:
@@ -39,9 +46,9 @@
     psTimerStart ("psastro");
 
-    // use fork to add timeout capability
+    // supply a known output format (for CATALOG output) so the code below knows what to read
     if (ELIXIR_MODE) {
-        psStringAppend (&getstarCommand, " -D CATFORMAT elixir");
+        psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT elixir");
     } else {
-        psStringAppend (&getstarCommand, " -D CATFORMAT panstarrs");
+        psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT panstarrs");
     }
 
@@ -52,11 +59,13 @@
     psFree(CATDIR);
 
-    // psStringAppend (&getstarCommand, " -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile);
-    // XXX TEST : no magnitude limit
-    // XXX need to specify the desired photometry system
-    psStringAppend (&getstarCommand, " -D CATMODE mef -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
+    // supply the max magnitude, the output format, and the photcode
+    psStringAppend (&getstarCommand, " -maglim %f -format %s -photcode %s", MAGmax, outformat, photcode);
+
+    // add region and output filename
+    psStringAppend (&getstarCommand, " -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
     psTrace ("psastro", 3, "%s\n", getstarCommand);
 
     // XXX use psPipe: catch stderr, stdout, allow for Nsec timeout...
+    // use fork to add timeout capability 
     status = system (getstarCommand);
     if (status) {
@@ -71,4 +80,41 @@
     psFits *fits = psFitsOpen (tempFile, "r");
 
+    psTimerStart ("psastro");
+
+    psArray *refstars = NULL;
+    if (!strcmp (outformat, "CATALOG")) {
+      refstars = psastroReadGetstarCatalog (fits);
+    }
+    if (!strcmp (outformat, "PS1_DEV_0")) {
+      refstars = psastroReadGetstar_PS1_DEV_0 (fits);
+    }
+    if (refstars == NULL) {
+        psError(PSASTRO_ERR_REFSTARS, true, "error reading reference data\n");
+        return NULL;
+    }
+    psLogMsg ("psastro", 3, "loaded %ld reference stars : %f sec\n", refstars->n, psTimerMark ("psastro"));
+
+    psTrace ("psastro", 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n",
+             refstars->n, RAmin, DECmin, RAmax, DECmax);
+
+    psFitsClose (fits);
+    unlink (tempFile);
+
+    // dump or plot the available refstars
+    if (psTraceGetLevel("psastro.dump") > 0) {
+        psastroDumpRefstars (refstars, "refstars.dat");
+    }
+
+    if (psTraceGetLevel("psastro.plot") > 0) {
+        psastroPlotRefstars (refstars, recipe);
+    }
+
+    return refstars;
+}
+
+psArray *psastroReadGetstarCatalog (psFits *fits) {
+
+    bool status;
+
     if (ELIXIR_MODE) {
         psFitsMoveExtName (fits, "DVO_AVERAGE_ELIXIR");
@@ -77,5 +123,4 @@
     }
 
-    psTimerStart ("psastro");
     long numSources = psFitsTableSize(fits); // Number of sources in table
 
@@ -102,21 +147,30 @@
         psFree (row);
     }
-    psLogMsg ("psastro", 3, "loaded %ld reference stars : %f sec\n", refstars->n, psTimerMark ("psastro"));
-
-    psTrace ("psastro", 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n",
-             refstars->n, RAmin, DECmin, RAmax, DECmax);
-
-    psFitsClose (fits);
-    unlink (tempFile);
-
-    // dump or plot the available refstars
-    if (psTraceGetLevel("psastro.dump") > 0) {
-        psastroDumpRefstars (refstars, "refstars.dat");
-    }
-
-    if (psTraceGetLevel("psastro.plot") > 0) {
-        psastroPlotRefstars (refstars, recipe);
-    }
-
     return refstars;
 }
+
+psArray *psastroReadGetstar_PS1_DEV_0 (psFits *fits) {
+
+    bool status;
+
+    psFitsMoveExtName (fits, "GETSTAR_PS1_DEV_0");
+
+    long numSources = psFitsTableSize(fits); // Number of sources in table
+
+    // convert the Average table to the pmAstromObj entries
+    psArray *refstars = psArrayAllocEmpty (numSources);
+    for (int i = 0; i < numSources; i++) {
+        pmAstromObj *ref = pmAstromObjAlloc ();
+
+        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
+
+	ref->sky->r   = RAD_DEG*psMetadataLookupF32 (&status, row, "RA");
+	ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
+	ref->Mag      = psMetadataLookupS32 (&status, row, "MAG");
+
+        psArrayAdd (refstars, 100, ref);
+        psFree (ref);
+        psFree (row);
+    }
+    return refstars;
+}
