Index: trunk/psLib/src/sysUtils/psTrace.c
===================================================================
--- trunk/psLib/src/sysUtils/psTrace.c	(revision 3682)
+++ trunk/psLib/src/sysUtils/psTrace.c	(revision 3781)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-07 20:27:41 $
+ *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-28 23:46:29 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -252,4 +252,8 @@
     if (cRoot == NULL) {
         initTrace();
+    }
+
+    if (traceFP == NULL) {
+        traceFP = stdout;
     }
 
@@ -425,23 +429,15 @@
     psS32 i = 0;
 
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+
     if (comp->name[0] == '\0') {
         return;
     } else {
         if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
-            if (traceFP == NULL) {
-                printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                       defLevel);
-            } else {
-                fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                        defLevel);
-            }
+            fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
         } else {
-            if (traceFP == NULL) {
-                printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                       comp->level);
-            } else {
-                fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                        comp->level);
-            }
+            fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
         }
     }
@@ -498,4 +494,8 @@
     psS32 i = 0;
 
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+
     if (NULL == comp) {
         psError(PS_ERR_BAD_PARAMETER_NULL, true,
@@ -514,26 +514,43 @@
         fmt = va_arg(ap, char *);
 
-        if (traceFP != NULL) {
-            // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
-                fprintf(traceFP, " ");
-            }
-            vfprintf(traceFP, fmt, ap);
-        } else {
-            // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
-                putchar(' ');
-            }
-            vprintf(fmt, ap);
-        }
+        // We indent each message one space for each level of the message.
+        for (i = 0; i < level; i++) {
+            fprintf(traceFP, " ");
+        }
+        vfprintf(traceFP, fmt, ap);
         va_end(ap);
     }
-    // NOTE: should we free *fmt as well? Read the man page.
-}
-
+}
+
+// XXX EAM : I've added code to close the old traceFP (safely)
 void psTraceSetDestination(FILE * fp)
 {
+
+    bool special;
+
+    // XXX EAM perhaps return an error?
+    if (fp == NULL) {
+        return;
+    }
+
+    // cannot close traceFP if one of the special FILE ptrs
+    special  = (traceFP == NULL);
+    special |= (traceFP == stdin);
+    special |= (traceFP == stdout);
+    special |= (traceFP == stderr);
+
+    if (!special) {
+        fclose (traceFP);
+    }
     traceFP = fp;
 }
 
+FILE *psTraceGetDestination()
+{
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+    return traceFP;
+}
+
 #endif
