Index: trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 27083)
+++ trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 27084)
@@ -91,5 +91,5 @@
     psMetadata *data = pmConfigFileRule(config, camera, name); // File rule
     if (!data) {
-        psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
+        psError(psErrorCodeLast(), false, "Can't find file rule %s!", name);
         return NULL;
     }
@@ -105,5 +105,5 @@
     file->type = pmFPAfileTypeFromString(type);
     if (file->type == PM_FPA_FILE_NONE) {
-        psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
+        psError(PM_ERR_CONFIG, true, "FILE.TYPE is not defined for %s\n", name);
         psFree(file);
         return NULL;
@@ -115,5 +115,5 @@
     file->dataLevel = pmFPALevelFromName(psMetadataLookupStr (&status, data, "DATA.LEVEL"));
     if (file->dataLevel == PM_FPA_LEVEL_NONE) {
-        psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
+        psError(PM_ERR_CONFIG, true, "DATA.LEVEL is not set for %s\n", name);
         psFree(file);
         return NULL;
@@ -137,5 +137,5 @@
     if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, name,
                           PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {
-        psError(PS_ERR_IO, false, "could not add %s to config files", name);
+        psError(PM_ERR_CONFIG, false, "could not add %s to config files", name);
         return NULL;
     }
@@ -167,11 +167,12 @@
         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // Known cameras
         if (!mdok || !cameras) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
+            psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the system configuration.\n");
             return NULL;
         }
         camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest
         if (!mdok || !camera) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
-                    "camera configuration %s in system configuration.\n", cameraName);
+            psError(PM_ERR_CONFIG, true,
+                    "Unable to find automatically generated camera configuration %s in system configuration.",
+                    cameraName);
             return NULL;
         }
@@ -184,5 +185,5 @@
     psMetadata *filerule = pmConfigFileRule(config, camera, name); // File rule
     if (!filerule) {
-        psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
+        psError(psErrorCodeLast(), false, "Can't find file rule %s!", name);
         return NULL;
     }
@@ -199,5 +200,5 @@
     file->type = pmFPAfileTypeFromString(type);
     if (file->type == PM_FPA_FILE_NONE) {
-        psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
+        psError(PM_ERR_CONFIG, true, "FILE.TYPE is not defined for %s\n", name);
         psFree(file);
         return NULL;
@@ -230,5 +231,5 @@
     psMetadata *format = psMetadataLookupMetadata(&status, formats, formatName); // Camera format to use
     if (!format) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find format %s for file %s.\n",
+        psError(PM_ERR_CONFIG, true, "Unable to find format %s for file %s.\n",
                 formatName, file->name);
         psFree(file);
@@ -287,5 +288,5 @@
                 options->stdevNum = parseOptionFloat(scheme, "STDEV.NUM", source); // Padding to edge
                 if (!isfinite(options->stdevNum)) {
-                    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.NUM for %s", source);
+                    psError(PM_ERR_CONFIG, true, "Bad value for STDEV.NUM for %s", source);
                     psFree(source);
                     psFree(file);
@@ -296,5 +297,5 @@
                 options->stdevBits = parseOptionInt(scheme, "STDEV.BITS", source, 0); // Bits for stdev
                 if (options->stdevBits <= 0) {
-                    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.BITS (%d) for %s",
+                    psError(PM_ERR_CONFIG, true, "Bad value for STDEV.BITS (%d) for %s",
                             options->stdevBits, source);
                     psFree(source);
@@ -337,5 +338,5 @@
     file->fileLevel = pmFPAPHULevel(format);
     if (file->fileLevel == PM_FPA_LEVEL_NONE) {
-        psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", name);
+        psError(PM_ERR_CONFIG, true, "Unable to determine file level for %s\n", name);
         psFree(file);
         return NULL;
@@ -344,5 +345,5 @@
     file->dataLevel = pmFPALevelFromName(psMetadataLookupStr(&status, filerule, "DATA.LEVEL"));
     if (file->dataLevel == PM_FPA_LEVEL_NONE) {
-        psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
+        psError(PM_ERR_CONFIG, true, "DATA.LEVEL is not set for %s\n", name);
         psFree(file);
         return NULL;
@@ -443,5 +444,5 @@
         psString realName = pmConfigConvertFilename(filenames->data[0], config, false, false);
         if (!realName) {
-            psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *)filenames->data[0]);
+            psError(psErrorCodeLast(), false, "Failed to convert file name %s", (char *)filenames->data[0]);
             return NULL;
         }
@@ -451,5 +452,5 @@
         psFits *fits = psFitsOpen(realName, "r"); // FITS file
         if (!fits) {
-            psError(PS_ERR_IO, false, "Failed to open file %s", realName);
+            psError(psErrorCodeLast(), false, "Failed to open file %s", realName);
             psFree(realName);
             return NULL;
@@ -457,5 +458,5 @@
         phu = psFitsReadHeader (NULL, fits); // Primary header
         if (!phu) {
-            psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
+            psError(psErrorCodeLast(), false, "Failed to read file header %s", realName);
             psFree(realName);
             return NULL;
@@ -471,5 +472,5 @@
         format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true);
         if (!format) {
-            psError(PS_ERR_IO, false, "Failed to determine camera format for %s", realName);
+            psError(psErrorCodeLast(), false, "Failed to determine camera format for %s", realName);
             psFree(camera);
             psFree(formatName);
@@ -481,5 +482,5 @@
         fileLevel = pmFPAPHULevel(format);
         if (fileLevel == PM_FPA_LEVEL_NONE) {
-            psError(PS_ERR_IO, true, "Unable to determine file level for %s", realName);
+            psError(PM_ERR_CONFIG, true, "Unable to determine file level for %s", realName);
             psFree(camera);
             psFree(formatName);
@@ -494,5 +495,5 @@
         psFree(camera);
         if (!fpa) {
-            psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
+            psError(psErrorCodeLast(), false, "Failed to construct FPA from %s", realName);
             psFree(formatName);
             psFree(realName);
@@ -508,5 +509,5 @@
     pmFPAfile *file = pmFPAfileDefineInput(config, fpa, cameraName, name); // File, to return
     if (!file) {
-        psError(PS_ERR_IO, false, "File %s not defined", name);
+        psError(psErrorCodeLast(), false, "File %s not defined", name);
         psFree(formatName);
         psFree(format);
@@ -535,10 +536,10 @@
             psString realName = pmConfigConvertFilename(filenames->data[i], config, false, false);
             if (!realName) {
-                psError(PS_ERR_IO, false, "Failed to convert file name %s", (char*)filenames->data[i]);
+                psError(psErrorCodeLast(), false, "Failed to convert file name %s", (char*)filenames->data[i]);
                 return NULL;
             }
             psFits *fits = psFitsOpen(realName, "r"); // FITS file
             if (!fits) {
-                psError(PS_ERR_IO, false, "Failed to open file %s", realName);
+                psError(psErrorCodeLast(), false, "Failed to open file %s", realName);
                 psFree(realName);
                 return NULL;
@@ -551,5 +552,5 @@
             }
             if (!phu) {
-                psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
+                psError(psErrorCodeLast(), false, "Failed to read file header %s", realName);
                 psFree(realName);
                 return NULL;
@@ -560,5 +561,5 @@
         if (i == 0 && file->type == PM_FPA_FILE_MASK) {
             if (!pmConfigMaskReadHeader(config, phu)) {
-                psError(PS_ERR_IO, false, "Error reading mask bits");
+                psError(psErrorCodeLast(), false, "Error reading mask bits");
                 psFree(phu);
                 return NULL;
@@ -570,10 +571,10 @@
                 bool valid = false;
                 if (!pmConfigValidateCameraFormat(&valid, format, phu)) {
-                    psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
+                    psError(psErrorCodeLast(), false, "Error in config scripts\n");
                     psFree(phu);
                     return NULL;
                 }
                 if (!valid) {
-                    psError(PS_ERR_IO, false, "File %s is not from the required camera",
+                    psError(psErrorCodeLast(), false, "File %s is not from the required camera",
                             (char*)filenames->data[i]);
                     psFree(phu);
@@ -583,5 +584,5 @@
                 format = pmConfigCameraFormatFromHeader(NULL, NULL, NULL, config, phu, true);
                 if (!format) {
-                    psError(PS_ERR_IO, false, "Failed to determine camera format from %s",
+                    psError(psErrorCodeLast(), false, "Failed to determine camera format from %s",
                             (char*)filenames->data[i]);
                     psFree(phu);
@@ -609,5 +610,5 @@
         phu = NULL;
         if (!view) {
-            psError(PS_ERR_IO, false, "Unable to determine source for %s", name);
+            psError(PM_ERR_CONFIG, true, "Unable to determine source for %s", name);
             return NULL;
         }
@@ -641,5 +642,5 @@
     }
     if (filenames->n == 0) {
-        psError(PS_ERR_IO, false, "No files in array in %s in arguments", argname);
+        psError(PM_ERR_CONFIG, true, "No files in array in %s in arguments", argname);
         if (success) {
             *success = false;
@@ -675,5 +676,5 @@
     }
     if (filenames->n == 0) {
-        psError(PS_ERR_IO, false, "No files in array in %s in arguments", argname);
+        psError(PM_ERR_CONFIG, true, "No files in array in %s in arguments", argname);
         if (success) {
             *success = false;
@@ -708,5 +709,5 @@
     }
     if (filenames->n <= entry) {
-        psError(PS_ERR_IO, false, "Insufficient files (%ld) in array in %s in arguments",
+        psError(PM_ERR_CONFIG, true, "Insufficient files (%ld) in array in %s in arguments",
                 filenames->n, argname);
         if (success) {
@@ -768,5 +769,5 @@
     }
     if (bind && files->n != bind->n) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+        psError(PM_ERR_CONFIG, true,
                 "Length of filenames (%ld) and bind files (%ld) does not match.",
                 files->n, bind->n);
@@ -782,5 +783,5 @@
         files->data[i] = psMemIncrRefCounter(fpaFileDefineFromArray(config, bindFile, filename, dummy));
         if (!files->data[i]) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to define file %s %d", filename, i);
+            psError(psErrorCodeLast(), false, "Unable to define file %s %d", filename, i);
             psFree(dummy);
             psFree(files);
@@ -810,5 +811,5 @@
     // a camera config is needed (as source of file rule)
     if (config->camera == NULL) {
-        psError(PS_ERR_IO, true, "camera is not defined");
+        psError(PM_ERR_PROG, true, "camera is not defined");
         return NULL;
     }
@@ -817,5 +818,5 @@
     pmFPA *fpa = pmFPAConstruct(config->camera, config->cameraName);
     if (!fpa) {
-        psError(PS_ERR_IO, false, "Failed to construct FPA for %s", filename);
+        psError(psErrorCodeLast(), false, "Failed to construct FPA for %s", filename);
         return NULL;
     }
@@ -826,5 +827,5 @@
     psFree (fpa);
     if (!file) {
-        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
+        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
         return NULL;
     }
@@ -832,5 +833,5 @@
     // image names may not come from file->names
     if (!strcasecmp(file->filerule, "@FILES")) {
-        psError(PS_ERR_IO, true, "supplied filerule uses illegal value @FILES");
+        psError(PM_ERR_CONFIG, true, "supplied filerule uses illegal value @FILES");
         // XXX remove the file from config->files
         return NULL;
@@ -889,5 +890,5 @@
     // a camera config is needed (as source of file rule)
     if (config->camera == NULL) {
-        psError(PS_ERR_IO, true, "camera is not defined");
+        psError(PS_ERR_PROG, true, "camera is not defined");
         return NULL;
     }
@@ -903,5 +904,5 @@
         fpa = pmFPAConstruct(config->camera, config->cameraName);
         if (!fpa) {
-            psError(PS_ERR_IO, false, "Failed to construct FPA for %s", filename);
+            psError(psErrorCodeLast(), false, "Failed to construct FPA for %s", filename);
             return NULL;
         }
@@ -910,5 +911,5 @@
         file = pmFPAfileDefineInput (config, fpa, NULL, filename);
         if (!file) {
-            psError(PS_ERR_IO, false, "file %s not defined\n", filename);
+            psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
             psFree(fpa);
             return NULL;
@@ -942,5 +943,5 @@
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PPIMAGE");
     if (!status) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "PPIMAGE recipe not found.");
+        psError(PM_ERR_CONFIG, true, "PPIMAGE recipe not found.");
         psFree(options);
         psFree(fpa);
@@ -1020,5 +1021,5 @@
         pmDetrendSelectResults *results = pmDetrendSelect (options, config);
         if (!results) {
-            psError (PS_ERR_IO, false, "no matching detrend data");
+            psError (psErrorCodeLast(), false, "no matching detrend data");
             return NULL;
         }
@@ -1026,5 +1027,5 @@
         file->fileLevel = pmFPALevelFromName(results->level);
         if (file->fileLevel == PM_FPA_LEVEL_NONE) {
-            psError (PS_ERR_IO, false, "invalid file level for selected detrend data");
+            psError (PM_ERR_CONFIG, false, "invalid file level for selected detrend data");
             return NULL;
         }
@@ -1051,5 +1052,5 @@
     pmFPAfile *file = pmFPAfileDefineOutput (config, fpa, filename);
     if (!file) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
+        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
         return NULL;
     }
@@ -1070,5 +1071,5 @@
     pmFPAfile *file = pmFPAfileDefineOutputForFormat(config, NULL, filename, src->cameraName, src->formatName);
     if (!file) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
+        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
         return NULL;
     }
@@ -1092,9 +1093,9 @@
     pmFPAfile *file = pmFPAfileDefineOutput (config, NULL, filename);
     if (!file) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
+        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
         return NULL;
     }
     if (!file->camera) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s does not define a new camera\n", filename);
+        psError(PM_ERR_CONFIG, false, "file %s does not define a new camera\n", filename);
         return NULL;
     }
@@ -1135,5 +1136,5 @@
     }
     if (!file) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
+        psError(PM_ERR_CONFIG, true, "file %s not defined\n", filename);
         return NULL;
     }
@@ -1178,5 +1179,5 @@
     }
     if (!file) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
+        psError(PM_ERR_CONFIG, true, "file %s not defined\n", filename);
         return NULL;
     }
@@ -1185,5 +1186,5 @@
     if (src) {
         if (!pmConceptsCopyFPA(file->fpa, src, true, false)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
+            psError(psErrorCodeLast(), false, "Unable to copy concepts from source to new FPA");
             return NULL;
         }
@@ -1229,5 +1230,5 @@
     }
     if (!file) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
+        psError(PM_ERR_CONFIG, true, "file %s not defined\n", filename);
         return NULL;
     }
@@ -1236,5 +1237,5 @@
     if (src) {
         if (!pmConceptsCopyFPA(file->fpa, src, false, false)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
+            psError(psErrorCodeLast(), false, "Unable to copy concepts from source to new FPA");
             return NULL;
         }
@@ -1282,5 +1283,5 @@
     }
     if (file == NULL) {
-        psError(PS_ERR_IO, true, "file %s is NULL", name);
+        psError(PM_ERR_CONFIG, true, "file %s is NULL", name);
         return false;
     }
