Index: trunk/psLib/test/image/tst_psImageIO.c
===================================================================
--- trunk/psLib/test/image/tst_psImageIO.c	(revision 998)
+++ trunk/psLib/test/image/tst_psImageIO.c	(revision 999)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-11 03:46:38 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-11 18:50:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,10 +20,10 @@
 #include "pslib.h"
 
-#define GENIMAGE(img,c,r,TYP) \
+#define GENIMAGE(img,c,r,TYP, valueFcn) \
 img = psImageAlloc(c,r,PS_TYPE_##TYP); \
 for (unsigned int row=0;row<r;row++) { \
     ps##TYP* imgRow = img->data.TYP[row]; \
     for (unsigned int col=0;col<c;col++) { \
-        imgRow[col] = (ps##TYP)(row+2*col); \
+        imgRow[col] = (ps##TYP)(valueFcn); \
     } \
 }
@@ -83,7 +83,7 @@
         psImage* img_ref = NULL; \
         \
-        GENIMAGE(img,m,n,TYP); \
+        GENIMAGE(img,m,n,TYP,row+2*col); \
         img2 = psImageCopy(img2,img,PS_TYPE_##TYP); \
-        GENIMAGE(img3,m,n,TYP); \
+        GENIMAGE(img3,m,n,TYP,row+2*col); \
         psImageClip(img3,100,100,400,400); \
         img4 = psImageCopy(img4,img3,PS_TYPE_##TYP); \
@@ -251,4 +251,72 @@
 int testImageWrite(void)
 {
+    psImage* img = NULL;
+    psImage* img2 = NULL;
+    int m = 64;
+    int n = 96;
+
+    /*
+    This function shall write the specified section within a psImage structure
+    to a FITS file. If the specifiedfile exists, then data should overwrite the
+    section to write. If the specified file doesn't exist, it shall be created.
+    If an extenstion is specified, then a basic primary header data unit shall
+    be created.
+    */
+
+    /*
+    Verify a FITS file named filename is generated and contains expected
+    values, if the input parameter input contains known data values, input
+    parameters col, row, ncol, nrow specify a valid data region within psImage
+    structure.
+
+    Verify a FITS file named filename is generated and contains a primary
+    header data unit with extension with expected values, if the input
+    parameter input contains known data values, input parameters col, row,
+    ncol, nrow specify a valid data region within psImage structure and
+    extname and/or extnum specify an extenstion to write.
+
+    N.B. : these are done in testImageRead tests, see above.
+    */
+
+    /*
+    Verify a FITS file named filename is overwritten and contains
+    expected values, if the input parameter input contains known data values,
+    input parameters col, row, ncol, nrow specify a valid data region within
+    psImage structure.
+    */
+
+    GENIMAGE(img,m,n,F32,0);
+    GENIMAGE(img2,m,n,F32,row+2*col);
+    remove
+        ("writeTest.fits");
+    if (psImageWriteSection(img,0,0,0,NULL,0,"writeTest.fits") != 0) {
+        psError(__func__,"Couldn't write writeTest.fits.");
+        return 14;
+    }
+    if (psImageWriteSection(img2,0,0,0,NULL,0,"writeTest.fits") != 0) {
+        psError(__func__,"Couldn't overwrite writeTest.fits.");
+        return 15;
+    }
+    psImageFree(img);
+    psImageFree(img2);
+
+    // Did it really overwrite the pixel values?  Let's read it in and see.
+    img = psImageReadSection(NULL,0,0,m,n,0,NULL,0,"writeTest.fits");
+    if (img == NULL) {
+        psError(__func__,"Could not read in writeTest.fits.");
+        return 16;
+    }
+    for (unsigned int row=0;row<n;row++) {
+        psF32* imgRow = img->data.F32[row];
+        for (unsigned int col=0;col<m;col++) {
+            if (fabsf(imgRow[col] - (row+2*col)) > FLT_EPSILON) {
+                psError(__func__,"The image values were not overwritten at %d,%d (%.2f vs %.2f)",
+                        col,row,imgRow[col],(row+2*col));
+                return 17;
+            }
+        }
+    }
+
+    psImageFree(img);
 
     return 0;
