Index: /trunk/stac/src/Makefile
===================================================================
--- /trunk/stac/src/Makefile	(revision 3682)
+++ /trunk/stac/src/Makefile	(revision 3683)
@@ -15,5 +15,7 @@
 SHIFTSIZE = shiftSize.o stacWrite.o stacConfig.o stacRead.o stacCheckMemory.o stacSize.o
 
-TARGETS = stac shift combine shiftSize
+FIXIMAGE = fixImage.o
+
+TARGETS = stac shift combine shiftSize fixImage
 
 .PHONY: tags clean empty test profile optimise all
@@ -33,4 +35,7 @@
 shiftSize:	$(SHIFTSIZE)
 		$(CC) $(CFLAGS) -o $@ $(SHIFTSIZE) $(LDFLAGS) $(OPTFLAGS)
+
+fixImage:	$(FIXIMAGE)
+		$(CC) $(CFLAGS) -o $@ $(FIXIMAGE) $(LDFLAGS) $(OPTFLAGS)
 
 all:		$(TARGETS)
Index: /trunk/stac/src/fixImage.c
===================================================================
--- /trunk/stac/src/fixImage.c	(revision 3683)
+++ /trunk/stac/src/fixImage.c	(revision 3683)
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include "pslib.h"
+
+void help(const char *programName
+    )
+{
+    fprintf (stderr, "fixImage: Fix an image (floating point with no NaNs)\n"
+	     "Usage: %s IN OUT\n"
+	     "where\n"
+	     "\tIN           Input image\n"
+	     "\tOUT          Output image\n",
+	     programName
+	);
+}
+
+
+int main(int argc, char **argv)
+{
+    if (argc != 3) {
+	help(argv[0]);
+	exit(EXIT_FAILURE);
+    }
+    const char *inName = argv[1];	// Input filename
+    const char *outName = argv[2];	// Output filename
+
+    psFits *imageFile = psFitsAlloc(inName);
+    psRegion *imageRegion = psRegionAlloc(0, 0, 0, 0); // Region of image to read
+    psImage *image = psFitsReadImage(NULL, imageFile, *imageRegion, 0);
+    if (image == NULL) {
+	psErrorStackPrint(stderr, "Fatal error: Unable to read %s\n", inName);
+	exit(EXIT_FAILURE);
+    }
+    psTrace("shift", 4, "Image %s is %dx%d\n", inName, image->numCols, image->numRows);
+    // Convert to 32-bit floating point, in necessary
+    if (image->type.type != PS_TYPE_F32) {
+	psTrace("shift", 5, "Converting %s to floating point in memory....", inName);
+	psImage *temp = psImageCopy(NULL, image, PS_TYPE_F32);
+	psFree(image);
+	image = temp;
+    }
+    psFree(imageFile);
+    psFree(imageRegion);
+
+    int numPix = psImageClipNaN(image, 0.0);
+    printf("%d NaN pixels clipped.\n", numPix);
+
+    // Write out transformed image
+    psFits *outFile = psFitsAlloc(outName);
+    if (!psFitsWriteImage(outFile, NULL, image, 0, NULL)) {
+	psErrorStackPrint(stderr, "Unable to write image: %s\n", outName);
+    }
+    psTrace("shift", 1, "Fixed image written to %s\n", outName);
+    psFree(outFile);
+    psFree(image);
+
+}
Index: /trunk/stac/src/stacSize.c
===================================================================
--- /trunk/stac/src/stacSize.c	(revision 3682)
+++ /trunk/stac/src/stacSize.c	(revision 3683)
@@ -94,17 +94,17 @@
     // Tweak the maps to account for the offset
     if (xMapDiff != NULL) {
-	*xMapDiff = floor(xMin);
+	*xMapDiff = floorf(xMin);
     }
     if (yMapDiff != NULL) {
-	*yMapDiff = floor(yMin);
+	*yMapDiff = floorf(yMin);
     }
     for (int i = 0; i < nImages; i++) {
 	psPlaneTransform *map = maps->data[i]; // The map of interest
-	map->x->coeff[0][0] -= floor(xMin);
-	map->y->coeff[0][0] -= floor(yMin);
+	map->x->coeff[0][0] -= floorf(xMin);
+	map->y->coeff[0][0] -= floorf(yMin);
     }
 
-    *outnx = (int)(xMax + 0.5) - (int)xMin;
-    *outny = (int)(yMax + 0.5) - (int)yMin;
+    *outnx = (int)ceilf(xMax - xMin);
+    *outny = (int)ceilf(yMax - yMin);
 
     psTrace("stac.size", 1, "Output size is to be %dx%d\n", *outnx, *outny);
