IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2006, 9:52:55 AM (20 years ago)
Author:
desonia
Message:

modified API to match current SDRS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFitsImage.c

    r5511 r6767  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-11-14 22:18:30 $
     9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-04-04 19:52:42 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1616
    1717#include "psFits.h"
     18#include "psFitsImage.h"
    1819#include "string.h"
    1920#include "psError.h"
     
    292293                      psMetadata* header,
    293294                      const psImage* input,
    294                       int numZPlanes)
     295                      int numZPlanes,
     296                      const char* extname)
     297{
     298    // this is equivalent to insert after the last HDU
     299
     300    psFitsMoveLast(fits);
     301    return psFitsInsertImage(fits,header,input,numZPlanes,extname,true);
     302}
     303
     304bool psFitsInsertImage(psFits* fits,
     305                       psMetadata* header,
     306                       const psImage* input,
     307                       int numZPlanes,
     308                       const char* extname,
     309                       bool after)
    295310{
    296311
     
    330345    }
    331346
    332     fits_create_img(fits->fd, bitPix, naxis, naxes, &status);
     347    int chdu = psFitsGetExtNum(fits);
     348    int hdus = psFitsGetSize(fits);
     349    if (! after) {
     350        if (chdu == 0) {
     351            // set status to signal fits_insert_img to insert a new primary HDU
     352            status = PREPEND_PRIMARY;
     353        } else if (hdus > 0) {
     354            // move back one to perform an insert after the previous HDU
     355            psFitsMoveExtNum(fits, -1, true);
     356        }
     357    }
     358
     359    if (hdus == 0) {
     360        status = 0;
     361        fits_create_img(fits->fd, bitPix, naxis, naxes, &status);
     362
     363    } else {
     364        fits_insert_img(fits->fd, bitPix, naxis, naxes, &status);
     365    }
    333366
    334367    if (bZero != 0) {        // set the bscale/bzero
     
    339372
    340373    // write the header, if any.
     374    if (extname != NULL) {
     375        psFitsSetExtName(fits,extname);
     376    }
     377
    341378    if (header != NULL) {
    342         psFitsWriteHeader(header, (psPtr)fits);
     379        if (extname != NULL) {
     380            psMetadataAddStr(header,PS_LIST_TAIL,"EXTNAME",
     381                             PS_META_REPLACE,
     382                             "Extenion Name",
     383                             extname);
     384        }
     385
     386        psFitsWriteHeader(header, fits);
    343387    }
    344388
     
    378422bool psFitsUpdateImage(psFits* fits,
    379423                       const psImage* input,
    380                        psRegion region,
     424                       int x0,
     425                       int y0,
    381426                       int z)
    382427{
     
    453498    long lastPixel[3];
    454499
    455     firstPixel[0] = region.x0 + 1;
    456     firstPixel[1] = region.y0 + 1;
     500    firstPixel[0] = x0 + 1;
     501    firstPixel[1] = y0 + 1;
    457502    firstPixel[2] = z + 1;
    458503
    459     if (region.x1 > 0) {
    460         lastPixel[0] = region.x1;
    461     } else {
    462         lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0
    463     }
    464     if (region.y1 > 0) {
    465         lastPixel[1] = region.y1;
    466     } else {
    467         lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0
    468     }
     504    lastPixel[0] = x0 + numCols;
     505    lastPixel[1] = y0 + numRows;
    469506    lastPixel[2] = z + 1;
    470507
     
    474511            lastPixel[1] < 1 || lastPixel[1] > nAxes[1]) {
    475512        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    476                 "Specified region [%d:%d,%d:%d], is not valid given the %dx%d FITS image.",
    477                 region.y0,region.y1-1,region.x0,region.x1-1);
    478         return false;
    479 
    480     }
    481 
    482     int dx = lastPixel[0] - firstPixel[0];
    483     int dy = lastPixel[1] - firstPixel[1];
    484     if (dx > numCols ||
    485             dy > numRows) {
    486         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    487                 "The region [%d:%d,%d:%d], is not valid given the input %dx%d image.",
    488                 firstPixel[1]-1,lastPixel[1]-1,
    489                 firstPixel[0]-1,lastPixel[0]-1,
    490                 numCols, numRows);
    491         return false;
    492     }
    493 
    494     psImage* subset;
    495     if (dx != numCols || dy != numRows) {
    496         // the input image needs to be subsetted
    497         subset = psImageSubset((psImage*)input, psRegionSet(0,dx+1,0,dy+1));
    498     } else {
    499         subset = psMemIncrRefCounter((psImage*)input);
    500     }
    501 
    502     fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status);
     513                "Input image [size of %ix%i] at position (%i,%i) does not all lay in the %ix%i FITS image.",
     514                numCols, numRows,
     515                x0, y0,
     516                nAxes[0], nAxes[1]);
     517        return false;
     518    }
     519
     520    fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, input->data.V[0], &status);
    503521
    504522    if ( status != 0) {
Note: See TracChangeset for help on using the changeset viewer.