IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2965


Ignore:
Timestamp:
Jan 12, 2005, 3:54:26 PM (22 years ago)
Author:
desonia
Message:

Added test for psFitsMoveExtNum.

Location:
trunk/psLib
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/psLib.kdevses

    r2962 r2965  
    22<!DOCTYPE KDevPrjSession>
    33<KDevPrjSession>
    4  <DocsAndViews NumberOfDocuments="3" >
     4 <DocsAndViews NumberOfDocuments="8" >
    55  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/test/fileUtils/tst_psFits.c" >
    6    <View0 Type="Source" />
     6   <View0 line="22" Type="Source" />
    77  </Doc0>
    88  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.h" >
    9    <View0 Type="Source" />
     9   <View0 line="166" Type="Source" />
    1010  </Doc1>
    1111  <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.c" >
    12    <View0 line="318" Type="Source" />
     12   <View0 line="257" Type="Source" />
    1313  </Doc2>
     14  <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImage.h" >
     15   <View0 line="0" Type="Source" />
     16  </Doc3>
     17  <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageIO.c" >
     18   <View0 line="20" Type="Source" />
     19  </Doc4>
     20  <Doc5 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFileUtilsErrors.dat" >
     21   <View0 line="20" Type="Source" />
     22  </Doc5>
     23  <Doc6 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageErrors.dat" >
     24   <View0 line="57" Type="Source" />
     25  </Doc6>
     26  <Doc7 NumberOfViews="1" URL="file:/home/desonia/psLib/src/sysUtils/psLogMsg.h" >
     27   <View0 line="0" Type="Source" />
     28  </Doc7>
    1429 </DocsAndViews>
    1530 <pluginList>
     
    2136   </bookmarks>
    2237  </kdevbookmarks>
     38  <kdevsubversion>
     39   <subversion recurseresolve="1" recurserelocate="1" recursemerge="1" recursecommit="1" base="" recursepropget="1" recurseswitch="1" recurseupdate="1" recursepropset="1" recursediff="1" recurserevert="1" forcemove="1" recursecheckout="1" forceremove="1" recurseadd="1" recurseproplist="1" forcemerge="1" />
     40  </kdevsubversion>
    2341  <kdevvalgrind>
    2442   <executable path="" params="" />
  • trunk/psLib/src/dataIO/psFileUtilsErrors.dat

    r2962 r2965  
    2121psFits_EXTNAME_NULL                    Specified extension name can not be NULL.
    2222psFits_EXTNAME_INVALID                 Could not find HDU '%s' in file %s.\nCFITSIO Error: %s
    23 psFits_EXTNUM_INVALID                  Could not find HDU #%d in file %s.\nCFITSIO Error: %s
     23psFits_EXTNUM_ABS_MOVE_FAILED          Could not move to specified HDU #%d in file %s.\nCFITSIO Error: %s
     24psFits_EXTNUM_REL_MOVE_FAILED          Could not move %d HDUs from current position in file %s.\nCFITSIO Error: %s
    2425psFits_GET_EXTNUM_FAILED               Failed to determine the current HDU number in file %s.\nCFITSIO Error: %s
    2526psFits_GETNUMHDUS_FAILED               Failed to determine the number of HDUs in file %s.\nCFITSIO Error: %s
  • trunk/psLib/src/dataIO/psFileUtilsErrors.h

    r2962 r2965  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-01-12 22:17:01 $
     9 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-01-13 01:54:25 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4343#define PS_ERRORTEXT_psFits_EXTNAME_NULL "Specified extension name can not be NULL."
    4444#define PS_ERRORTEXT_psFits_EXTNAME_INVALID "Could not find HDU '%s' in file %s.\nCFITSIO Error: %s"
    45 #define PS_ERRORTEXT_psFits_EXTNUM_INVALID "Could not find HDU #%d in file %s.\nCFITSIO Error: %s"
     45#define PS_ERRORTEXT_psFits_EXTNUM_ABS_MOVE_FAILED "Could not move to specified HDU #%d in file %s.\nCFITSIO Error: %s"
     46#define PS_ERRORTEXT_psFits_EXTNUM_REL_MOVE_FAILED "Could not move %d HDUs from current position in file %s.\nCFITSIO Error: %s"
    4647#define PS_ERRORTEXT_psFits_GET_EXTNUM_FAILED "Failed to determine the current HDU number in file %s.\nCFITSIO Error: %s"
    4748#define PS_ERRORTEXT_psFits_GETNUMHDUS_FAILED "Failed to determine the number of HDUs in file %s.\nCFITSIO Error: %s"
  • trunk/psLib/src/dataIO/psFits.c

    r2962 r2965  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-01-12 22:17:01 $
     9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-01-13 01:54:25 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    287287
    288288    if (relative) {
    289         fits_movrel_hdu(fits->p_fd, extnum+1, &hdutype, &status);
     289        fits_movrel_hdu(fits->p_fd, extnum, &hdutype, &status);
     290        if (status != 0) {
     291            char fitsErr[MAX_STRING_LENGTH];
     292            fits_get_errstatus(status, fitsErr);
     293            psError(PS_ERR_LOCATION_INVALID, true,
     294                    PS_ERRORTEXT_psFits_EXTNUM_REL_MOVE_FAILED,
     295                    extnum, fits->filename, fitsErr);
     296            return false;
     297        }
    290298    } else {
    291299        fits_movabs_hdu(fits->p_fd, extnum+1, &hdutype, &status);
    292     }
    293 
    294     if (status != 0) {
    295         char fitsErr[MAX_STRING_LENGTH];
    296         fits_get_errstatus(status, fitsErr);
    297         psError(PS_ERR_LOCATION_INVALID, true,
    298                 PS_ERRORTEXT_psFits_EXTNUM_INVALID,
    299                 extnum, fits->filename, fitsErr);
    300         return false;
     300        if (status != 0) {
     301            char fitsErr[MAX_STRING_LENGTH];
     302            fits_get_errstatus(status, fitsErr);
     303            psError(PS_ERR_LOCATION_INVALID, true,
     304                    PS_ERRORTEXT_psFits_EXTNUM_ABS_MOVE_FAILED,
     305                    extnum, fits->filename, fitsErr);
     306            return false;
     307        }
    301308    }
    302309
  • trunk/psLib/src/fileUtils/psFileUtilsErrors.dat

    r2962 r2965  
    2121psFits_EXTNAME_NULL                    Specified extension name can not be NULL.
    2222psFits_EXTNAME_INVALID                 Could not find HDU '%s' in file %s.\nCFITSIO Error: %s
    23 psFits_EXTNUM_INVALID                  Could not find HDU #%d in file %s.\nCFITSIO Error: %s
     23psFits_EXTNUM_ABS_MOVE_FAILED          Could not move to specified HDU #%d in file %s.\nCFITSIO Error: %s
     24psFits_EXTNUM_REL_MOVE_FAILED          Could not move %d HDUs from current position in file %s.\nCFITSIO Error: %s
    2425psFits_GET_EXTNUM_FAILED               Failed to determine the current HDU number in file %s.\nCFITSIO Error: %s
    2526psFits_GETNUMHDUS_FAILED               Failed to determine the number of HDUs in file %s.\nCFITSIO Error: %s
  • trunk/psLib/src/fileUtils/psFileUtilsErrors.h

    r2962 r2965  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-01-12 22:17:01 $
     9 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-01-13 01:54:25 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4343#define PS_ERRORTEXT_psFits_EXTNAME_NULL "Specified extension name can not be NULL."
    4444#define PS_ERRORTEXT_psFits_EXTNAME_INVALID "Could not find HDU '%s' in file %s.\nCFITSIO Error: %s"
    45 #define PS_ERRORTEXT_psFits_EXTNUM_INVALID "Could not find HDU #%d in file %s.\nCFITSIO Error: %s"
     45#define PS_ERRORTEXT_psFits_EXTNUM_ABS_MOVE_FAILED "Could not move to specified HDU #%d in file %s.\nCFITSIO Error: %s"
     46#define PS_ERRORTEXT_psFits_EXTNUM_REL_MOVE_FAILED "Could not move %d HDUs from current position in file %s.\nCFITSIO Error: %s"
    4647#define PS_ERRORTEXT_psFits_GET_EXTNUM_FAILED "Failed to determine the current HDU number in file %s.\nCFITSIO Error: %s"
    4748#define PS_ERRORTEXT_psFits_GETNUMHDUS_FAILED "Failed to determine the number of HDUs in file %s.\nCFITSIO Error: %s"
  • trunk/psLib/src/fileUtils/psFits.c

    r2962 r2965  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-01-12 22:17:01 $
     9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-01-13 01:54:25 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    287287
    288288    if (relative) {
    289         fits_movrel_hdu(fits->p_fd, extnum+1, &hdutype, &status);
     289        fits_movrel_hdu(fits->p_fd, extnum, &hdutype, &status);
     290        if (status != 0) {
     291            char fitsErr[MAX_STRING_LENGTH];
     292            fits_get_errstatus(status, fitsErr);
     293            psError(PS_ERR_LOCATION_INVALID, true,
     294                    PS_ERRORTEXT_psFits_EXTNUM_REL_MOVE_FAILED,
     295                    extnum, fits->filename, fitsErr);
     296            return false;
     297        }
    290298    } else {
    291299        fits_movabs_hdu(fits->p_fd, extnum+1, &hdutype, &status);
    292     }
    293 
    294     if (status != 0) {
    295         char fitsErr[MAX_STRING_LENGTH];
    296         fits_get_errstatus(status, fitsErr);
    297         psError(PS_ERR_LOCATION_INVALID, true,
    298                 PS_ERRORTEXT_psFits_EXTNUM_INVALID,
    299                 extnum, fits->filename, fitsErr);
    300         return false;
     300        if (status != 0) {
     301            char fitsErr[MAX_STRING_LENGTH];
     302            fits_get_errstatus(status, fitsErr);
     303            psError(PS_ERR_LOCATION_INVALID, true,
     304                    PS_ERRORTEXT_psFits_EXTNUM_ABS_MOVE_FAILED,
     305                    extnum, fits->filename, fitsErr);
     306            return false;
     307        }
    301308    }
    302309
  • trunk/psLib/src/fits/psFits.c

    r2962 r2965  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-01-12 22:17:01 $
     9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-01-13 01:54:25 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    287287
    288288    if (relative) {
    289         fits_movrel_hdu(fits->p_fd, extnum+1, &hdutype, &status);
     289        fits_movrel_hdu(fits->p_fd, extnum, &hdutype, &status);
     290        if (status != 0) {
     291            char fitsErr[MAX_STRING_LENGTH];
     292            fits_get_errstatus(status, fitsErr);
     293            psError(PS_ERR_LOCATION_INVALID, true,
     294                    PS_ERRORTEXT_psFits_EXTNUM_REL_MOVE_FAILED,
     295                    extnum, fits->filename, fitsErr);
     296            return false;
     297        }
    290298    } else {
    291299        fits_movabs_hdu(fits->p_fd, extnum+1, &hdutype, &status);
    292     }
    293 
    294     if (status != 0) {
    295         char fitsErr[MAX_STRING_LENGTH];
    296         fits_get_errstatus(status, fitsErr);
    297         psError(PS_ERR_LOCATION_INVALID, true,
    298                 PS_ERRORTEXT_psFits_EXTNUM_INVALID,
    299                 extnum, fits->filename, fitsErr);
    300         return false;
     300        if (status != 0) {
     301            char fitsErr[MAX_STRING_LENGTH];
     302            fits_get_errstatus(status, fitsErr);
     303            psError(PS_ERR_LOCATION_INVALID, true,
     304                    PS_ERRORTEXT_psFits_EXTNUM_ABS_MOVE_FAILED,
     305                    extnum, fits->filename, fitsErr);
     306            return false;
     307        }
    301308    }
    302309
  • trunk/psLib/test/dataIO/tst_psFits.c

    r2963 r2965  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2005-01-12 22:18:25 $
     8*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2005-01-13 01:54:26 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222static psS32 tst_psFitsAlloc( void );
    2323static psS32 tst_psFitsMoveExtName( void );
     24static psS32 tst_psFitsMoveExtNum( void );
    2425
    2526testDescription tests[] = {
    2627                              {tst_psFitsAlloc, 801, "psFitsAlloc", 0, false},
    2728                              {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false},
     29                              {tst_psFitsMoveExtNum, 803, "psFitsMoveExtNum", 0, false},
    2830                              {NULL}
    2931                          };
     
    181183                "Operation of NULL extname didn't fail.");
    182184        return 9;
     185    }
     186
     187    psFree(fits);
     188
     189    return 0;
     190}
     191
     192psS32 tst_psFitsMoveExtNum( void )
     193{
     194
     195    if (! makeMulti() ) {
     196        return 1;
     197    }
     198
     199    psFits* fits = psFitsAlloc(multiFilename);
     200
     201    int numHDUs = psFitsGetSize(fits);
     202
     203    if (numHDUs < 2) {
     204        psError(PS_ERR_UNKNOWN,true,
     205                "The 'multi' FITS file does not have multiple HDUs.");
     206        return 2;
     207    }
     208
     209    psRegion region = {0,0,0,0};
     210
     211    // test absolute positioning
     212    for (int lcv = 0; lcv < numHDUs; lcv++) {
     213        // try to move to the extension
     214        if (! psFitsMoveExtNum(fits, lcv, false) ) {
     215            psError(PS_ERR_UNKNOWN, false,
     216                    "Failed to move to extension %d.",
     217                    lcv);
     218            return 3;
     219        }
     220
     221        // check that the image is associated to the extension moved, i.e.,
     222        // did we really move to the proper extension?
     223        psImage* image = psFitsReadImage(NULL, fits,region,0);
     224
     225        if (image == NULL || abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     226            psError(PS_ERR_UNKNOWN, true,
     227                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     228                    lcv,image->data.F32[0][0],lcv);
     229            return 4;
     230        }
     231        psFree(image);
     232    }
     233
     234    for (int lcv = numHDUs-1; lcv >= 0; lcv--) {
     235        // try to move to the extension
     236        if (! psFitsMoveExtNum(fits, lcv, false) ) {
     237            psError(PS_ERR_UNKNOWN, false,
     238                    "Failed to move to extension %d.",
     239                    lcv);
     240            return 5;
     241        }
     242
     243        // check that the image is associated to the extension moved, i.e.,
     244        // did we really move to the proper extension?
     245        psImage* image = psFitsReadImage(NULL, fits,region,0);
     246
     247        if (abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     248            psError(PS_ERR_UNKNOWN, true,
     249                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     250                    lcv,image->data.F32[0][0],lcv);
     251            return 6;
     252        }
     253        psFree(image);
     254    }
     255
     256    // test relative positioning
     257    psFitsMoveExtNum(fits,0,false);
     258    for (int lcv = 1; lcv < numHDUs; lcv++) {
     259        // try to move to the extension
     260        if (! psFitsMoveExtNum(fits, 1, true) ) {
     261            psError(PS_ERR_UNKNOWN, false,
     262                    "Failed to move to extension %d.",
     263                    lcv);
     264            return 13;
     265        }
     266
     267        // check that the image is associated to the extension moved, i.e.,
     268        // did we really move to the proper extension?
     269        psImage* image = psFitsReadImage(NULL, fits,region,0);
     270
     271        if (image == NULL || abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     272            psError(PS_ERR_UNKNOWN, true,
     273                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     274                    lcv,image->data.F32[0][0],lcv);
     275            return 14;
     276        }
     277        psFree(image);
     278    }
     279
     280    for (int lcv = numHDUs-2; lcv >= 0; lcv--) {
     281        // try to move to the extension
     282        if (! psFitsMoveExtNum(fits, -1, true) ) {
     283            psError(PS_ERR_UNKNOWN, false,
     284                    "Failed to move to extension %d.",
     285                    lcv);
     286            return 15;
     287        }
     288
     289        // check that the image is associated to the extension moved, i.e.,
     290        // did we really move to the proper extension?
     291        psImage* image = psFitsReadImage(NULL, fits,region,0);
     292
     293        if (abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     294            psError(PS_ERR_UNKNOWN, true,
     295                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     296                    lcv,image->data.F32[0][0],lcv);
     297            return 16;
     298        }
     299        psFree(image);
     300    }
     301
     302    // check to see if given a negative extension number, it errors.
     303    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     304    if (psFitsMoveExtNum(fits, -1, false) ) {
     305        psError(PS_ERR_UNKNOWN, false,
     306                "Moving to negative HDU didn't fail.");
     307        return 21;
     308    }
     309
     310    // check to see if relative positioning beyond PHU, it errors.
     311    psFitsMoveExtNum(fits,0,false);
     312    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     313    if (psFitsMoveExtNum(fits, -1, true) ) {
     314        psError(PS_ERR_UNKNOWN, false,
     315                "Moving to negative HDU didn't fail.");
     316        return 22;
     317    }
     318
     319
     320    // check to see if given a extension greater than the total #HDUs, it errors.
     321    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     322    if (psFitsMoveExtNum(fits, numHDUs, false) ) {
     323        psError(PS_ERR_UNKNOWN, false,
     324                "Moving to a HDU beyond the file's contents didn't fail.");
     325        return 31;
     326    }
     327
     328    // check to see if relative positioning beyond PHU, it errors.
     329    psFitsMoveExtNum(fits,numHDUs-1,false);
     330    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     331    if (psFitsMoveExtNum(fits, 1, true) ) {
     332        psError(PS_ERR_UNKNOWN, false,
     333                "Moving to negative HDU didn't fail.");
     334        return 32;
     335    }
     336
     337    // check to see if given a NULL psFits, it errors.
     338    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     339    if (psFitsMoveExtNum(NULL, 0, false) ) {
     340        psError(PS_ERR_UNKNOWN, false,
     341                "Operation of NULL psFits didn't fail.");
     342        return 40;
    183343    }
    184344
  • trunk/psLib/test/fileUtils/tst_psFits.c

    r2963 r2965  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2005-01-12 22:18:25 $
     8*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2005-01-13 01:54:26 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222static psS32 tst_psFitsAlloc( void );
    2323static psS32 tst_psFitsMoveExtName( void );
     24static psS32 tst_psFitsMoveExtNum( void );
    2425
    2526testDescription tests[] = {
    2627                              {tst_psFitsAlloc, 801, "psFitsAlloc", 0, false},
    2728                              {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false},
     29                              {tst_psFitsMoveExtNum, 803, "psFitsMoveExtNum", 0, false},
    2830                              {NULL}
    2931                          };
     
    181183                "Operation of NULL extname didn't fail.");
    182184        return 9;
     185    }
     186
     187    psFree(fits);
     188
     189    return 0;
     190}
     191
     192psS32 tst_psFitsMoveExtNum( void )
     193{
     194
     195    if (! makeMulti() ) {
     196        return 1;
     197    }
     198
     199    psFits* fits = psFitsAlloc(multiFilename);
     200
     201    int numHDUs = psFitsGetSize(fits);
     202
     203    if (numHDUs < 2) {
     204        psError(PS_ERR_UNKNOWN,true,
     205                "The 'multi' FITS file does not have multiple HDUs.");
     206        return 2;
     207    }
     208
     209    psRegion region = {0,0,0,0};
     210
     211    // test absolute positioning
     212    for (int lcv = 0; lcv < numHDUs; lcv++) {
     213        // try to move to the extension
     214        if (! psFitsMoveExtNum(fits, lcv, false) ) {
     215            psError(PS_ERR_UNKNOWN, false,
     216                    "Failed to move to extension %d.",
     217                    lcv);
     218            return 3;
     219        }
     220
     221        // check that the image is associated to the extension moved, i.e.,
     222        // did we really move to the proper extension?
     223        psImage* image = psFitsReadImage(NULL, fits,region,0);
     224
     225        if (image == NULL || abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     226            psError(PS_ERR_UNKNOWN, true,
     227                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     228                    lcv,image->data.F32[0][0],lcv);
     229            return 4;
     230        }
     231        psFree(image);
     232    }
     233
     234    for (int lcv = numHDUs-1; lcv >= 0; lcv--) {
     235        // try to move to the extension
     236        if (! psFitsMoveExtNum(fits, lcv, false) ) {
     237            psError(PS_ERR_UNKNOWN, false,
     238                    "Failed to move to extension %d.",
     239                    lcv);
     240            return 5;
     241        }
     242
     243        // check that the image is associated to the extension moved, i.e.,
     244        // did we really move to the proper extension?
     245        psImage* image = psFitsReadImage(NULL, fits,region,0);
     246
     247        if (abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     248            psError(PS_ERR_UNKNOWN, true,
     249                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     250                    lcv,image->data.F32[0][0],lcv);
     251            return 6;
     252        }
     253        psFree(image);
     254    }
     255
     256    // test relative positioning
     257    psFitsMoveExtNum(fits,0,false);
     258    for (int lcv = 1; lcv < numHDUs; lcv++) {
     259        // try to move to the extension
     260        if (! psFitsMoveExtNum(fits, 1, true) ) {
     261            psError(PS_ERR_UNKNOWN, false,
     262                    "Failed to move to extension %d.",
     263                    lcv);
     264            return 13;
     265        }
     266
     267        // check that the image is associated to the extension moved, i.e.,
     268        // did we really move to the proper extension?
     269        psImage* image = psFitsReadImage(NULL, fits,region,0);
     270
     271        if (image == NULL || abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     272            psError(PS_ERR_UNKNOWN, true,
     273                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     274                    lcv,image->data.F32[0][0],lcv);
     275            return 14;
     276        }
     277        psFree(image);
     278    }
     279
     280    for (int lcv = numHDUs-2; lcv >= 0; lcv--) {
     281        // try to move to the extension
     282        if (! psFitsMoveExtNum(fits, -1, true) ) {
     283            psError(PS_ERR_UNKNOWN, false,
     284                    "Failed to move to extension %d.",
     285                    lcv);
     286            return 15;
     287        }
     288
     289        // check that the image is associated to the extension moved, i.e.,
     290        // did we really move to the proper extension?
     291        psImage* image = psFitsReadImage(NULL, fits,region,0);
     292
     293        if (abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
     294            psError(PS_ERR_UNKNOWN, true,
     295                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
     296                    lcv,image->data.F32[0][0],lcv);
     297            return 16;
     298        }
     299        psFree(image);
     300    }
     301
     302    // check to see if given a negative extension number, it errors.
     303    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     304    if (psFitsMoveExtNum(fits, -1, false) ) {
     305        psError(PS_ERR_UNKNOWN, false,
     306                "Moving to negative HDU didn't fail.");
     307        return 21;
     308    }
     309
     310    // check to see if relative positioning beyond PHU, it errors.
     311    psFitsMoveExtNum(fits,0,false);
     312    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     313    if (psFitsMoveExtNum(fits, -1, true) ) {
     314        psError(PS_ERR_UNKNOWN, false,
     315                "Moving to negative HDU didn't fail.");
     316        return 22;
     317    }
     318
     319
     320    // check to see if given a extension greater than the total #HDUs, it errors.
     321    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     322    if (psFitsMoveExtNum(fits, numHDUs, false) ) {
     323        psError(PS_ERR_UNKNOWN, false,
     324                "Moving to a HDU beyond the file's contents didn't fail.");
     325        return 31;
     326    }
     327
     328    // check to see if relative positioning beyond PHU, it errors.
     329    psFitsMoveExtNum(fits,numHDUs-1,false);
     330    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     331    if (psFitsMoveExtNum(fits, 1, true) ) {
     332        psError(PS_ERR_UNKNOWN, false,
     333                "Moving to negative HDU didn't fail.");
     334        return 32;
     335    }
     336
     337    // check to see if given a NULL psFits, it errors.
     338    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
     339    if (psFitsMoveExtNum(NULL, 0, false) ) {
     340        psError(PS_ERR_UNKNOWN, false,
     341                "Operation of NULL psFits didn't fail.");
     342        return 40;
    183343    }
    184344
Note: See TracChangeset for help on using the changeset viewer.