Index: /branches/eam_branches/20091113/psastro/src/psastroLoadRefstars.c
===================================================================
--- /branches/eam_branches/20091113/psastro/src/psastroLoadRefstars.c	(revision 26219)
+++ /branches/eam_branches/20091113/psastro/src/psastroLoadRefstars.c	(revision 26220)
@@ -50,5 +50,30 @@
         return false;
     }
+
+    // the name in the recipe may be one of:
+    // (A) the actual directory name
+    // (B) a reference to the name in the PSASTRO.CATDIRS folder in site.config
+    // (C) a reference to a folder in the PSASTRO.CATDIRS folder in site.config, containing multiple copy locations
     char *catdir_virtual = psMetadataLookupStr(&status, catdirs, catdir_recipe);
+
+    psMetadata *catdir_folder = psMetadataLookupMetadata(&status, catdirs, catdir_recipe);
+    if (catdir_folder) {
+	// randomly choose one of the entries
+	psLogMsg ("psastro", 3, "choosing catdir_folder\n");
+	int nEntry = catdir_folder->list->n;
+
+	psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);  
+	double frnd = psRandomUniform(rng);
+	int entry = PS_MIN(nEntry - 1, PS_MAX(0, nEntry * frnd));
+	psFree(rng);
+
+	psMetadataItem *item = psListGet(catdir_folder->list, entry);
+	if (item->type != PS_DATA_STRING) {
+	    psError(PSASTRO_ERR_CONFIG, true, "Invalid entry in PSASTRO.CATDIR folder: %s\n", item->name);
+	    return false;
+	}
+	catdir_virtual = item->data.str;
+    }
+
     char *catdir = (catdir_virtual == NULL) ? catdir_recipe : catdir_virtual;
 
@@ -56,4 +81,6 @@
     psString CATDIR = pmConfigConvertFilename(catdir, config, false, false); // Resolved filename
     PS_ASSERT (CATDIR, NULL);
+
+    psLogMsg ("psastro", 3, "looking up reference objects in %s\n", CATDIR);
 
     char *getstarCommand = psStringCopy(psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR"));
