Index: /trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfileIO.c	(revision 11449)
+++ /trunk/psModules/src/camera/pmFPAfileIO.c	(revision 11450)
@@ -233,5 +233,5 @@
 
         psFree (file->filename);
-        file->filename = pmDetrendFile (file->filextra, extra);
+        file->filename = pmDetrendFile(file->filextra, extra, config);
         if (file->filename == NULL) {
             psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s\n", file->filextra, extra);
Index: /trunk/psModules/src/config/Makefile.am
===================================================================
--- /trunk/psModules/src/config/Makefile.am	(revision 11449)
+++ /trunk/psModules/src/config/Makefile.am	(revision 11450)
@@ -7,4 +7,5 @@
     pmConfigRecipes.c \
     pmConfigCamera.c \
+    pmConfigCommand.c \
     pmVersion.c \
     pmErrorCodes.c
@@ -14,4 +15,5 @@
     pmConfigRecipes.h \
     pmConfigCamera.h \
+    pmConfigCommand.h \
     pmVersion.h \
     pmErrorCodes.h
Index: /trunk/psModules/src/config/pmConfigCommand.c
===================================================================
--- /trunk/psModules/src/config/pmConfigCommand.c	(revision 11450)
+++ /trunk/psModules/src/config/pmConfigCommand.c	(revision 11450)
@@ -0,0 +1,58 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pslib.h>
+
+#include "pmConfigCommand.h"
+
+bool pmConfigDatabaseCommand(psString *command, const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(command, false);
+
+    bool mdok;                          // Status of MD lookup
+    const char *dbserver = psMetadataLookupStr(&mdok, config->site, "DBSERVER"); // Database server
+    if (!mdok || strlen(dbserver) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBSERVER in site configuration.\n");
+        return NULL;
+    }
+    const char *dbname = psMetadataLookupStr(&mdok, config->site, "DBNAME"); // Database name
+    if (!mdok || strlen(dbname) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBNAME in site configuration.\n");
+        return NULL;
+    }
+    const char *dbuser = psMetadataLookupStr(&mdok, config->site, "DBUSER"); // Database user
+    if (!mdok || strlen(dbuser) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBUSER in site configuration.\n");
+        return NULL;
+    }
+    const char *dbpassword = psMetadataLookupStr(&mdok, config->site, "DBPASSWORD"); // Database password
+    if (!mdok || strlen(dbpassword) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBPASSWORD in site configuration.\n");
+        return NULL;
+    }
+
+    psStringAppend(command, " -dbserver %s -dbname %s -dbuser %s -dbpassword %s",
+                   dbserver, dbname, dbuser, dbpassword);
+
+    return true;
+}
+
+
+bool pmConfigTraceCommand(psString *command)
+{
+    PS_ASSERT_PTR_NON_NULL(command, false);
+
+    psMetadata *levels = psTraceLevels(); // Metadata levels
+    psMetadataIterator *iter = psMetadataIteratorAlloc(levels, PS_LIST_HEAD, NULL); // Iterator for levels
+    psMetadataItem *item;               // Item from iteration
+    while ((item = psMetadataGetAndIncrement(iter))) {
+        assert(item->type == PS_TYPE_S32);
+        psStringAppend(command, " -trace %s %d", item->name, item->data.S32);
+    }
+    psFree(iter);
+    psFree(levels);
+
+    return true;
+}
Index: /trunk/psModules/src/config/pmConfigCommand.h
===================================================================
--- /trunk/psModules/src/config/pmConfigCommand.h	(revision 11450)
+++ /trunk/psModules/src/config/pmConfigCommand.h	(revision 11450)
@@ -0,0 +1,21 @@
+#ifndef PM_CONFIG_COMMAND_H
+#define PM_CONFIG_COMMAND_H
+
+#include <pslib.h>
+#include "pmConfig.h"
+
+/// Extend a command-line to include the necessary database flags
+///
+/// The command-line is extended with -dbserver, -dbname, -dbuser, -dbpassword
+bool pmConfigDatabaseCommand(psString *command, ///< Command to extend
+                             const pmConfig *config ///< Configuration
+                            );
+
+/// Extend a command-line to propagate the trace flags
+///
+/// The command-line is extended with -trace
+bool pmConfigTraceCommand(psString *command ///< Command to extend
+                         );
+
+
+#endif
Index: /trunk/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- /trunk/psModules/src/detrend/pmDetrendDB.c	(revision 11449)
+++ /trunk/psModules/src/detrend/pmDetrendDB.c	(revision 11450)
@@ -7,4 +7,5 @@
 #include <pslib.h>
 #include "pmConfig.h"
+#include "pmConfigCommand.h"
 #include "pmFPA.h"
 #include "pmFPALevel.h"
@@ -101,28 +102,6 @@
     PS_ASSERT_PTR_NON_NULL(config->site, NULL);
 
-    bool mdok;                          // Status of MD lookup
-    const char *dbserver = psMetadataLookupStr(&mdok, config->site, "DBSERVER"); // Database server
-    if (!mdok || strlen(dbserver) == 0) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBSERVER in site configuration.\n");
-        return NULL;
-    }
-    const char *dbname = psMetadataLookupStr(&mdok, config->site, "DBNAME"); // Database name
-    if (!mdok || strlen(dbname) == 0) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBNAME in site configuration.\n");
-        return NULL;
-    }
-    const char *dbuser = psMetadataLookupStr(&mdok, config->site, "DBUSER"); // Database user
-    if (!mdok || strlen(dbuser) == 0) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBUSER in site configuration.\n");
-        return NULL;
-    }
-    const char *dbpassword = psMetadataLookupStr(&mdok, config->site, "DBPASSWORD"); // Database password
-    if (!mdok || strlen(dbpassword) == 0) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBPASSWORD in site configuration.\n");
-        return NULL;
-    }
-
     int status, exit_status;
-    char *line = NULL;
+    psString line = NULL;
     char *time = psTimeToISO (&options->time);
     char *type = pmDetrendTypeToString (options->type);
@@ -130,18 +109,18 @@
 
     pmDetrendSelectResults *results = pmDetrendSelectResultsAlloc();
-    psStringAppend (&line, "detselect -search -inst %s -det_type %s -time %s "
-                    "-dbserver %s -dbname %s -dbuser %s -dbpassword %s",
-                    options->camera, type, time, dbserver, dbname, dbuser, dbpassword);
+    psStringAppend(&line, "detselect -search -inst %s -det_type %s -time %s", options->camera, type, time);
 
     if (options->filter) {
-        psStringAppend (&line, " -filter %s", options->filter);
+        psStringAppend(&line, " -filter %s", options->filter);
     }
     if (options->exptime > -1.0) {
-        psStringAppend (&line, " -exptime %f", options->exptime);
+        psStringAppend(&line, " -exptime %f", options->exptime);
     }
     if (options->airmass > -1.0) {
-        psStringAppend (&line, " -airmass %f", options->airmass);
-    }
-
+        psStringAppend(&line, " -airmass %f", options->airmass);
+    }
+
+    pmConfigDatabaseCommand(&line, config);
+    pmConfigTraceCommand(&line);
     psTrace("psModules.detrend", 5, "running %s", line);
 
@@ -214,5 +193,5 @@
 // detselect -select -detID (detID) -classID (classID)
 // returns: (detID) (classID) (filename) DONE
-char *pmDetrendFile (const char *detID, const char *classID)
+char *pmDetrendFile (const char *detID, const char *classID, const pmConfig *config)
 {
     unsigned int nFail;
@@ -222,9 +201,11 @@
 
     bool status;
-    char *line = NULL;
+    psString line = NULL;
     psArray *array = NULL;
 
     // generate the detselect command
     psStringAppend (&line, "detselect -select %s -class_id %s", detID, classID);
+    pmConfigDatabaseCommand(&line, config);
+    pmConfigTraceCommand(&line);
     psTrace("psModules.detrend", 5, "running %s", line);
 
Index: /trunk/psModules/src/detrend/pmDetrendDB.h
===================================================================
--- /trunk/psModules/src/detrend/pmDetrendDB.h	(revision 11449)
+++ /trunk/psModules/src/detrend/pmDetrendDB.h	(revision 11450)
@@ -9,6 +9,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-30 04:46:20 $
+ * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-01-31 00:35:24 $
  * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
  */
@@ -65,5 +65,5 @@
 pmDetrendSelectResults *pmDetrendSelectResultsAlloc();
 pmDetrendSelectResults *pmDetrendSelect (const pmDetrendSelectOptions *options, const pmConfig *config);
-char *pmDetrendFile (const char *detID, const char *classID);
+char *pmDetrendFile (const char *detID, const char *classID, const pmConfig *config);
 
 /// @}
Index: /trunk/psModules/src/psmodules.h
===================================================================
--- /trunk/psModules/src/psmodules.h	(revision 11449)
+++ /trunk/psModules/src/psmodules.h	(revision 11450)
@@ -13,4 +13,6 @@
 #include <pmConfig.h>
 #include <pmConfigRecipes.h>
+#include <pmConfigCamera.h>
+#include <pmConfigCommand.h>
 #include <pmVersion.h>
 
