Index: /trunk/pswarp/src/Makefile.am
===================================================================
--- /trunk/pswarp/src/Makefile.am	(revision 10946)
+++ /trunk/pswarp/src/Makefile.am	(revision 10946)
@@ -0,0 +1,42 @@
+
+lib_LTLIBRARIES = libpswarp.la
+libpswarp_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSWARP_CFLAGS)
+
+bin_PROGRAMS = pswarp
+pswarp_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSWARP_CFLAGS)
+pswarp_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSWARP_LIBS)
+pswarp_LDADD = libpswarp.la
+
+pswarp_SOURCES = \
+	pswarp.c		
+
+libpswarp_la_SOURCES = \
+pswarpArguments.c	   \
+pswarpCleanup.c            \
+pswarpDataLoad.c           \
+pswarpDataSave.c           \
+pswarpDefine.c             \
+pswarpErrorCodes.c         \
+pswarpParseCamera.c   	   \
+pswarpVersion.c            
+
+include_HEADERS = \
+	pswarp.h \
+	pswarpErrorCodes.h
+
+clean-local:
+	-rm -f TAGS
+
+# Tags for emacs
+tags:
+	etags `find . -name \*.[ch] -print`
+
+### Error codes.
+BUILT_SOURCES = pswarpErrorCodes.h pswarpErrorCodes.c
+CLEANFILES = pswarpErrorCodes.h pswarpErrorCodes.c
+
+pswarpErrorCodes.h : pswarpErrorCodes.dat pswarpErrorCodes.h.in
+	$(ERRORCODES) --data=pswarpErrorCodes.dat --outdir=. pswarpErrorCodes.h
+
+pswarpErrorCodes.c : pswarpErrorCodes.dat pswarpErrorCodes.c.in pswarpErrorCodes.h
+	$(ERRORCODES) --data=pswarpErrorCodes.dat --outdir=. pswarpErrorCodes.c
Index: /trunk/pswarp/src/pswarp.c
===================================================================
--- /trunk/pswarp/src/pswarp.c	(revision 10945)
+++ /trunk/pswarp/src/pswarp.c	(revision 10946)
@@ -19,5 +19,5 @@
 
     // load identify the data sources
-    if (!psastroParseCamera (config)) {
+    if (!pswarpParseCamera (config)) {
 	psErrorStackPrint(stderr, "error setting up the camera\n");
 	exit (1);
@@ -25,14 +25,23 @@
 
     // load the skycell layout information
-    pswarpDefine ();
+    if (!pswarpDefine (config)) {
+	psErrorStackPrint(stderr, "error loading output definition\n");
+	exit (1);
+    }
 
-    // warp loop 
-    pswarpProcess ();
+    // load and warp
+    if (!pswarpDataLoad (config)) {
+	psErrorStackPrint(stderr, "error reading input data\n");
+	exit (1);
+    }
     
     // write out result image
-    pswarpDataSave ();
+    if (!pswarpDataSave (config)) {
+	psErrorStackPrint(stderr, "error writing output data\n");
+	exit (1);
+    }
 
     psLogMsg ("pswarp", 3, "complete pswarp run: %f sec\n", psTimerMark ("complete"));
-    pswarpCleanup (config, refs);
+    pswarpCleanup (config);
     exit (EXIT_SUCCESS);
 }
Index: /trunk/pswarp/src/pswarp.h
===================================================================
--- /trunk/pswarp/src/pswarp.h	(revision 10946)
+++ /trunk/pswarp/src/pswarp.h	(revision 10946)
@@ -0,0 +1,14 @@
+# ifdef HAVE_CONFIG_H
+# include <config.h>
+# endif
+
+# include <stdio.h>
+# include <string.h>
+# include <strings.h>  // for strcasecmp
+# include <unistd.h>   // for unlink
+# include <pslib.h>
+# include <psmodules.h>
+
+# include "pswarpErrorCodes.h"
+# define PSWARP_RECIPE "PSWARP" // Name of the recipe to use
+
Index: /trunk/pswarp/src/pswarpCleanup.c
===================================================================
--- /trunk/pswarp/src/pswarpCleanup.c	(revision 10946)
+++ /trunk/pswarp/src/pswarpCleanup.c	(revision 10946)
@@ -0,0 +1,18 @@
+# include "pswarp.h"
+
+void pswarpCleanup (pmConfig *config) {
+
+    psFree (refs);
+    psFree (config);
+
+    psTimerStop ();
+    psMemCheckCorruption (true);
+    // XXX not used in pswarp pmModelGroupCleanup ();
+    psTimeFinalize ();
+    pmConceptsDone ();
+    pmConfigDone ();
+    // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "pswarp");
+    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "pswarp");
+
+    return;
+}
Index: /trunk/pswarp/src/pswarpDataLoad.c
===================================================================
--- /trunk/pswarp/src/pswarpDataLoad.c	(revision 10946)
+++ /trunk/pswarp/src/pswarpDataLoad.c	(revision 10946)
@@ -0,0 +1,58 @@
+# include "pswarp.h"
+
+// this loop loads the data from the input files and selects the
+// brighter stars for astrometry
+// at the end of this function, the complete stellar data is loaded
+// into the correct fpa structure locations (readout.analysis:PSPHOT.SOURCES)
+
+// all of the different astrometry analysis modes use the same data load loop
+bool pswarpDataLoad (pmConfig *config) {
+
+    pmChip *chip;
+    pmCell *cell;
+    pmReadout *readout;
+
+    // select the input data sources
+    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT");
+    if (!input) {
+	psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
+	return false;
+    }
+
+    // de-activate PSWARP.SKYCELL and PSWARP.OUTPUT
+    // 
+    pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT");
+    pmFPAfileActivate (config->files, false, "PSWARP.SKYCELL");
+
+    pmFPAview *view = pmFPAviewAlloc (0);
+
+    // files associated with the science image
+    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+
+    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+        psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        if (!chip->process || !chip->file_exists) { continue; }
+	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+
+	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+            psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            if (!cell->process || !cell->file_exists) { continue; }
+	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+
+	    // process each of the readouts
+	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+		if (! readout->data_exists) { continue; }
+
+		pswarpConvertReadout (readout, config);
+
+		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	    }
+	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	}
+	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+    }
+    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+    psFree (view);
+    return true;
+}
Index: /trunk/pswarp/src/pswarpDataSave.c
===================================================================
--- /trunk/pswarp/src/pswarpDataSave.c	(revision 10946)
+++ /trunk/pswarp/src/pswarpDataSave.c	(revision 10946)
@@ -0,0 +1,60 @@
+# include "pswarp.h"
+
+// this loop loads the data from the input files and selects the
+// brighter stars for astrometry
+// at the end of this function, the complete stellar data is loaded
+// into the correct fpa structure locations (readout.analysis:PSPHOT.SOURCES)
+
+// all of the different astrometry analysis modes use the same data load loop
+bool pswarpDataSave (pmConfig *config) {
+
+    pmChip *chip;
+    pmCell *cell;
+    pmReadout *readout;
+
+    // select the input data sources
+    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT");
+    if (!input) {
+	psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
+	return false;
+    }
+
+    // de-activate all files except PSWARP.OUTPUT
+    pmFPAfileActivate (config->files, false, NULL);
+    pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT");
+    pmFPAview *view = pmFPAviewAlloc (0);
+
+    // files associated with the science image
+    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+
+    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+        psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        if (!chip->process || !chip->file_exists) { continue; }
+	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+
+	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+            psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            if (!cell->process || !cell->file_exists) { continue; }
+	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+
+	    // process each of the readouts
+	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+		if (! readout->data_exists) { continue; }
+
+		// pswarpConvertReadout (readout, config);
+
+		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	    }
+	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	}
+	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+    }
+    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+    psFree (view);
+
+    // re-activate all pmFPAfiles
+    pmFPAfileActivate (config->files, true, NULL);
+
+    return true;
+}
Index: /trunk/pswarp/src/pswarpDefine.c
===================================================================
--- /trunk/pswarp/src/pswarpDefine.c	(revision 10945)
+++ /trunk/pswarp/src/pswarpDefine.c	(revision 10946)
@@ -18,8 +18,4 @@
     }
 
-    // XXX drop? de-activate all files except PSWARP.INPUT
-    // pmFPAfileActivate (config->files, false, NULL);
-    // pmFPAfileActivate (config->files, true, "PSWARP.INPUT");
-
     // open the full skycell file; no need to defer different depths
     pmFPAview *view = pmFPAviewAlloc (0);
Index: /trunk/pswarp/src/pswarpErrorCodes.c.in
===================================================================
--- /trunk/pswarp/src/pswarpErrorCodes.c.in	(revision 10946)
+++ /trunk/pswarp/src/pswarpErrorCodes.c.in	(revision 10946)
@@ -0,0 +1,26 @@
+/*
+ * The line
+    { PSWARP_ERR_$X{ErrorCode}, "$X{ErrorDescription}"},
+ * (without the Xs)
+ * will be replaced by values from errorCodes.dat
+ */
+#include "pslib.h"
+#include "pswarpErrorCodes.h"
+
+void pswarpErrorRegister(void)
+{
+    static psErrorDescription errors[] = {
+       { PSWARP_ERR_BASE, "First value we use; lower values belong to psLib" },
+       { PSWARP_ERR_${ErrorCode}, "${ErrorDescription}"},
+    };
+    static int nerror = PSWARP_ERR_NERROR - PSWARP_ERR_BASE; // number of values in enum
+
+    for (int i = 0; i < nerror; i++) {
+       psErrorDescription *tmp = psAlloc(sizeof(psErrorDescription));
+       p_psMemSetPersistent(tmp, true);
+       *tmp = errors[i];
+       psErrorRegister(tmp, 1);
+       psFree(tmp);			/* it's on the internal list */
+    }
+    nerror = 0;			                // don't register more than once
+}
Index: /trunk/pswarp/src/pswarpErrorCodes.dat
===================================================================
--- /trunk/pswarp/src/pswarpErrorCodes.dat	(revision 10946)
+++ /trunk/pswarp/src/pswarpErrorCodes.dat	(revision 10946)
@@ -0,0 +1,10 @@
+#
+# This file is used to generate pmErrorClasses.h
+#
+BASE = 600		First value we use; lower values belong to psLib
+UNKNOWN			Unknown PM error code
+NOT_IMPLEMENTED		Desired feature is not yet implemented
+ARGUMENTS		Incorrect arguments
+CONFIG			Problem in configure files
+IO			Problem in FITS I/O
+DATA                    Problem in data values
Index: /trunk/pswarp/src/pswarpErrorCodes.h.in
===================================================================
--- /trunk/pswarp/src/pswarpErrorCodes.h.in	(revision 10946)
+++ /trunk/pswarp/src/pswarpErrorCodes.h.in	(revision 10946)
@@ -0,0 +1,18 @@
+#if !defined(PSWARP_ERROR_CODES_H)
+#define PSWARP_ERROR_CODES_H
+/*
+ * The line
+ *  PSWARP_ERR_$X{ErrorCode},
+ * (without the X)
+ *
+ * will be replaced by values from errorCodes.dat
+ */
+typedef enum {
+    PSWARP_ERR_BASE = 600,
+    PSWARP_ERR_${ErrorCode},
+    PSWARP_ERR_NERROR
+} pswarpErrorCode;
+
+void pswarpErrorRegister(void);
+
+#endif
Index: unk/pswarp/src/pswarpProcess.c
===================================================================
--- /trunk/pswarp/src/pswarpProcess.c	(revision 10945)
+++ 	(revision )
@@ -1,58 +1,0 @@
-# include "pswarp.h"
-// this loop loads the data from the input files and selects the
-// brighter stars for astrometry
-// at the end of this function, the complete stellar data is loaded
-// into the correct fpa structure locations (readout.analysis:PSPHOT.SOURCES)
-
-// all of the different astrometry analysis modes use the same data load loop
-bool pswarpDataLoad (pmConfig *config) {
-
-    pmChip *chip;
-    pmCell *cell;
-    pmReadout *readout;
-
-    // select the input data sources
-    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT");
-    if (!input) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
-	return false;
-    }
-
-    // de-activate PSWARP.SKYCELL and PSWARP.OUTPUT
-    // 
-    pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT");
-    pmFPAfileActivate (config->files, false, "PSWARP.SKYCELL");
-
-    pmFPAview *view = pmFPAviewAlloc (0);
-
-    // files associated with the science image
-    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-
-    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
-        psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
-        if (!chip->process || !chip->file_exists) { continue; }
-	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-
-	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
-            psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
-            if (!cell->process || !cell->file_exists) { continue; }
-	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-
-	    // process each of the readouts
-	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
-		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-		if (! readout->data_exists) { continue; }
-
-		pswarpConvertReadout (readout, config);
-
-		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-	    }
-	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-	}
-	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-    }
-    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-    psFree (view);
-    return true;
-}
-
Index: /trunk/pswarp/src/pswarpVersion.c
===================================================================
--- /trunk/pswarp/src/pswarpVersion.c	(revision 10946)
+++ /trunk/pswarp/src/pswarpVersion.c	(revision 10946)
@@ -0,0 +1,27 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pslib.h>
+#include <psmodules.h>
+#include "pswarp.h"
+
+static const char *cvsTag = "$Name: not supported by cvs2svn $";// CVS tag name
+
+psString pswarpVersion(void)
+{
+    psString version = NULL;            // Version, to return
+    psStringAppend(&version, "%s-%s",PACKAGE_NAME,PACKAGE_VERSION);
+    return version;
+}
+
+psString pswarpVersionLong(void)
+{
+    psString version = pswarpVersion(); // Version, to return
+    psString tag = psStringStripCVS(cvsTag, "Name"); // CVS tag
+    psStringAppend(&version, " (cvs tag %s) %s, %s", tag, __DATE__, __TIME__);
+    psFree(tag);
+    return version;
+}
+
