IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6855


Ignore:
Timestamp:
Apr 13, 2006, 5:10:49 PM (20 years ago)
Author:
Paul Price
Message:

Adding pmHDUReadHeader

Location:
branches/rel10_ifa/psModules/src/astrom
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmHDU.c

    r6834 r6855  
    66#include "psAdditionals.h"
    77
     8//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     9// File-static (private) functions
     10//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     11
     12// Move to the appropriate extension in FITS file for HDU
     13static bool hduMove(pmHDU *hdu,         // HDU with extname
     14                    psFits *fits        // FITS file in which to move
     15                   )
     16{
     17    // Deal with the PHU case
     18    if (strcasecmp(hdu->extname, "PHU") == 0 || hdu->phu) {
     19        if (! psFitsMoveExtNum(fits, 0, false)) {
     20            psError(PS_ERR_IO, false, "Unable to move to primary header!\n");
     21            return false;
     22        }
     23        hdu->phu = true;
     24        return true;
     25    }
     26
     27    if (! psFitsMoveExtName(fits, hdu->extname)) {
     28        psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname);
     29        return false;
     30    }
     31    // Now, just in case for some reason the PHU has an extension name that we've moved to....
     32    if (psFitsGetExtNum(fits) == 0) {
     33        hdu->phu = true;
     34    } else {
     35        hdu->phu = false;
     36    }
     37
     38    return true;
     39}
    840
    941static void hduFree(pmHDU *hdu)
     
    1850}
    1951
     52
     53//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     54// Public functions
     55//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2056
    2157pmHDU *pmHDUAlloc(const char *extname   // Extension name
     
    4682}
    4783
     84bool pmHDUReadHeader(pmHDU *hdu,        // HDU for which to read header
     85                     psFits *fits       // FITS file from which to read
     86                    )
     87{
     88    assert(hdu);
     89    assert(fits);
     90
     91    // Move to the appropriate extension
     92    psTrace(__func__, 5, "Moving to extension %s...\n", hdu->extname);
     93    if (!hduMove(hdu, fits)) {
     94        return false;
     95    }
     96
     97    if (!hdu->header) {
     98        psTrace(__func__, 5, "Reading the header...\n");
     99        hdu->header = psFitsReadHeader(NULL, fits);
     100        if (! hdu->header) {
     101            psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", hdu->extname);
     102            return false;
     103        }
     104    }
     105
     106    return true;
     107}
    48108
    49109// Read the HDU
     
    56116    assert(fits);
    57117
    58     // Move to the appropriate extension
    59     psTrace(__func__, 5, "Moving to extension %s...\n", hdu->extname);
    60     if (strcasecmp(hdu->extname, "PHU") == 0) {
    61         if (! psFitsMoveExtNum(fits, 0, false)) {
    62             psError(PS_ERR_IO, false, "Unable to move to primary header!\n");
    63             return false;
    64         }
    65         hdu->phu = true;
    66     } else {
    67         if (! psFitsMoveExtName(fits, hdu->extname)) {
    68             psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname);
    69         }
    70         // Now, just in case for some reason the PHU has an extension name that we've moved to....
    71         if (psFitsGetExtNum(fits) == 0) {
    72             hdu->phu = true;
    73         } else {
    74             hdu->phu = false;
    75         }
    76     }
    77 
    78     // Read the header
    79     if (! hdu->header) {
    80         psTrace(__func__, 5, "Reading the header...\n");
    81         hdu->header = psFitsReadHeader(NULL, fits);
    82         if (! hdu->header) {
    83             psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", hdu->extname);
    84             return false;
    85         }
     118    // Read the header; includes the move
     119    if (!pmHDUReadHeader(hdu, fits)) {
     120        return false;
    86121    }
    87122
  • branches/rel10_ifa/psModules/src/astrom/pmHDU.h

    r6713 r6855  
    2020pmHDU *pmHDUAlloc(const char *extname);
    2121
     22// Read the header
     23bool pmHDUReadHeader(pmHDU *hdu,        // HDU for which to read header
     24                     psFits *fits       // FITS file from which to read
     25                    );
     26
    2227// Read the HDU
    2328bool pmHDURead(pmHDU *hdu,              // HDU to read
Note: See TracChangeset for help on using the changeset viewer.