IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 11, 2004, 8:50:49 AM (22 years ago)
Author:
desonia
Message:

added test for psImageWriteSection(...).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageIO.c

    r998 r999  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-11 03:46:38 $
     8 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-11 18:50:49 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020#include "pslib.h"
    2121
    22 #define GENIMAGE(img,c,r,TYP) \
     22#define GENIMAGE(img,c,r,TYP, valueFcn) \
    2323img = psImageAlloc(c,r,PS_TYPE_##TYP); \
    2424for (unsigned int row=0;row<r;row++) { \
    2525    ps##TYP* imgRow = img->data.TYP[row]; \
    2626    for (unsigned int col=0;col<c;col++) { \
    27         imgRow[col] = (ps##TYP)(row+2*col); \
     27        imgRow[col] = (ps##TYP)(valueFcn); \
    2828    } \
    2929}
     
    8383        psImage* img_ref = NULL; \
    8484        \
    85         GENIMAGE(img,m,n,TYP); \
     85        GENIMAGE(img,m,n,TYP,row+2*col); \
    8686        img2 = psImageCopy(img2,img,PS_TYPE_##TYP); \
    87         GENIMAGE(img3,m,n,TYP); \
     87        GENIMAGE(img3,m,n,TYP,row+2*col); \
    8888        psImageClip(img3,100,100,400,400); \
    8989        img4 = psImageCopy(img4,img3,PS_TYPE_##TYP); \
     
    251251int testImageWrite(void)
    252252{
     253    psImage* img = NULL;
     254    psImage* img2 = NULL;
     255    int m = 64;
     256    int n = 96;
     257
     258    /*
     259    This function shall write the specified section within a psImage structure
     260    to a FITS file. If the specifiedfile exists, then data should overwrite the
     261    section to write. If the specified file doesn't exist, it shall be created.
     262    If an extenstion is specified, then a basic primary header data unit shall
     263    be created.
     264    */
     265
     266    /*
     267    Verify a FITS file named filename is generated and contains expected
     268    values, if the input parameter input contains known data values, input
     269    parameters col, row, ncol, nrow specify a valid data region within psImage
     270    structure.
     271
     272    Verify a FITS file named filename is generated and contains a primary
     273    header data unit with extension with expected values, if the input
     274    parameter input contains known data values, input parameters col, row,
     275    ncol, nrow specify a valid data region within psImage structure and
     276    extname and/or extnum specify an extenstion to write.
     277
     278    N.B. : these are done in testImageRead tests, see above.
     279    */
     280
     281    /*
     282    Verify a FITS file named filename is overwritten and contains
     283    expected values, if the input parameter input contains known data values,
     284    input parameters col, row, ncol, nrow specify a valid data region within
     285    psImage structure.
     286    */
     287
     288    GENIMAGE(img,m,n,F32,0);
     289    GENIMAGE(img2,m,n,F32,row+2*col);
     290    remove
     291        ("writeTest.fits");
     292    if (psImageWriteSection(img,0,0,0,NULL,0,"writeTest.fits") != 0) {
     293        psError(__func__,"Couldn't write writeTest.fits.");
     294        return 14;
     295    }
     296    if (psImageWriteSection(img2,0,0,0,NULL,0,"writeTest.fits") != 0) {
     297        psError(__func__,"Couldn't overwrite writeTest.fits.");
     298        return 15;
     299    }
     300    psImageFree(img);
     301    psImageFree(img2);
     302
     303    // Did it really overwrite the pixel values?  Let's read it in and see.
     304    img = psImageReadSection(NULL,0,0,m,n,0,NULL,0,"writeTest.fits");
     305    if (img == NULL) {
     306        psError(__func__,"Could not read in writeTest.fits.");
     307        return 16;
     308    }
     309    for (unsigned int row=0;row<n;row++) {
     310        psF32* imgRow = img->data.F32[row];
     311        for (unsigned int col=0;col<m;col++) {
     312            if (fabsf(imgRow[col] - (row+2*col)) > FLT_EPSILON) {
     313                psError(__func__,"The image values were not overwritten at %d,%d (%.2f vs %.2f)",
     314                        col,row,imgRow[col],(row+2*col));
     315                return 17;
     316            }
     317        }
     318    }
     319
     320    psImageFree(img);
    253321
    254322    return 0;
Note: See TracChangeset for help on using the changeset viewer.