IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 25, 2004, 10:28:46 AM (22 years ago)
Author:
desonia
Message:

added the (untested) psImageReadSection function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImage.c

    r746 r777  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-05-20 01:49:47 $
     11 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-05-25 20:28:46 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818/*  INCLUDE FILES                                                             */
    1919/******************************************************************************/
     20#include <string.h>
     21#include <fitsio.h>
     22
    2023#include "psMemory.h"
    2124#include "psError.h"
    2225#include "psImage.h"
    2326
    24 #include <string.h>
    2527
    2628/*****************************************************************************/
     
    355357                            int numRows, int z, char* extname, int extnum, char* filename)
    356358{
    357 
    358     return NULL;
    359 }
     359    fitsfile    *fptr=NULL;                 /*Pointer to the FITS file*/
     360    int         status=0;                   /*CFITSIO file vars*/
     361    int         nAxis=0;
     362    int         anynull=0;
     363    int         bitPix=0;                   /*Pixel type*/
     364    long        nAxes[3];
     365    long        firstPixel[3];              /* lower-left corner of image subset */
     366    long        lastPixel[3];               /* upper-right corner of image subset */
     367    long        increment[3];               /* increment for image subset */
     368    char        fitsErr[80] = "";           /*CFITSIO error message string */
     369    int         hduType = IMAGE_HDU;
     370
     371    /* Open the FITS file */
     372    (void)fits_open_file(&fptr, filename, READONLY, &status);
     373    if (fptr == NULL || status != 0) {
     374        fits_get_errstatus(status,fitsErr);
     375        psError(__func__,"Could not open file '%s'. FITS error:%s",
     376                filename, fitsErr);
     377        psImageFree(output);
     378        return NULL;
     379    }
     380
     381    /* find the specified extension */
     382    if (extname != NULL) {
     383        if (fits_movnam_hdu(fptr, hduType, extname, 0,&status) != 0) {
     384            fits_get_errstatus(status, fitsErr);
     385            status = 0;
     386            (void)fits_close_file(fptr, &status);
     387            psError(__func__,"Could not index to '%s' HDU for file %s. FITSIO ERROR:%s",
     388                    extname, filename, fitsErr);
     389            psImageFree(output);
     390            return NULL;
     391        }
     392    } else {
     393        if (fits_movabs_hdu(fptr, extnum, &hduType, &status) != 0) {
     394            fits_get_errstatus(status, fitsErr);
     395            status = 0;
     396            (void)fits_close_file(fptr, &status);
     397            psError(__func__,"Could not index to HDU #%d for file %s. FITSIO ERROR:%s",
     398                    extnum, filename, fitsErr);
     399            psImageFree(output);
     400            return NULL;
     401        }
     402    }
     403
     404    /* Get the data type 'bitPix' from the FITS image */
     405    if (fits_get_img_type(fptr, &bitPix, &status) != 0) {
     406        fits_get_errstatus(status, fitsErr);
     407        status = 0;
     408        (void)fits_close_file(fptr, &status);
     409        psError("Could not determine image data type of '%s'. FITSIO ERROR:%s",
     410                filename, fitsErr);
     411        psImageFree(output);
     412        return NULL;
     413    }
     414
     415    /* Get the dimensions 'nAxis' from the FITS image */
     416    if (fits_get_img_dim(fptr, &nAxis, &status) != 0) {
     417        (void)fits_get_errstatus(status, fitsErr);
     418        status = 0;
     419        (void)fits_close_file(fptr, &status);
     420        psError("Could not determine dimensions of '%s'. FITSIO Error: %s",
     421                filename,fitsErr);
     422        psImageFree(output);
     423        return NULL;
     424    }
     425
     426    /* Validate the number of axis */
     427    if ( (nAxis < 2) || (nAxis > 3) ) {
     428        status=0;
     429        (void)fits_close_file(fptr, &status);
     430        psError("Dimensions of '%s' are not supported (NAXIS=%i).",
     431                filename, nAxis);
     432        psImageFree(output);
     433        return NULL;
     434    }
     435
     436    /* Get the Image size from the FITS file  */
     437    if ( fits_get_img_size(fptr, nAxis, nAxes, &status) != 0) {
     438        (void)fits_get_errstatus(status, fitsErr);
     439        status = 0;
     440        (void)fits_close_file(fptr, &status);
     441        psError("Could not determine image size of '%s'. FITSIO Error:%s",
     442                filename,fitsErr);
     443        psImageFree(output);
     444        return NULL;
     445    }
     446
     447    if (numCols < 1) {
     448        numCols += nAxes[0];
     449    }
     450    if (numRows < 1) {
     451        numRows += nAxes[1];
     452    }
     453
     454    firstPixel[0] = col+1;
     455    firstPixel[1] = row+1;
     456    firstPixel[2] = z+1;
     457
     458    lastPixel[0] = firstPixel[0] + numCols - 1;
     459    lastPixel[1] = firstPixel[1] + numRows - 1;
     460    lastPixel[2] = z+1;
     461
     462    increment[0] = 1;
     463    increment[1] = 1;
     464    increment[2] = 1;
     465
     466    // turn off the BSCALE/BZERO processing in CFITSIO
     467    (void)fits_set_bscale(fptr, 1.0,0.0,&status);
     468
     469    switch (bitPix) {
     470    case BYTE_IMG:
     471        psImageRealloc(output,numCols,numRows,PS_TYPE_U8);
     472        (void)fits_read_subset(fptr, TBYTE, firstPixel, lastPixel, increment,
     473                               NULL, output->data.v, &anynull, &status);
     474        break;
     475    case SHORT_IMG:
     476        psImageRealloc(output,numCols,numRows,PS_TYPE_S16);
     477        (void)fits_read_subset(fptr, TSHORT, firstPixel, lastPixel, increment,
     478                               NULL, output->data.v, &anynull, &status);
     479        break;
     480    case LONG_IMG:
     481        psImageRealloc(output,numCols,numRows,PS_TYPE_S32);
     482        (void)fits_read_subset(fptr, TINT, firstPixel, lastPixel, increment,
     483                               NULL, output->data.v, &anynull, &status);
     484        break;
     485    case FLOAT_IMG:
     486        psImageRealloc(output,numCols,numRows,PS_TYPE_F32);
     487        (void)fits_read_subset(fptr, TFLOAT, firstPixel, lastPixel, increment,
     488                               NULL, output->data.v, &anynull, &status);
     489        break;
     490    case DOUBLE_IMG:
     491        psImageRealloc(output,numCols,numRows,PS_TYPE_F64);
     492        (void)fits_read_subset(fptr, TDOUBLE, firstPixel, lastPixel, increment,
     493                               NULL, output->data.v, &anynull, &status);
     494        break;
     495    default:
     496        psError(__func__,"Unsupported bitpix value (%d) in FITS file %s.",
     497                bitPix,filename);
     498        psImageFree(output);
     499        return NULL;
     500    }
     501
     502    return output;
     503}
     504
     505
     506int psImageWriteSection(psImage* input, int col0,int row0,int z,
     507                        char* extname, int extnum, char* filename)
     508{
     509
     510    return 0;
     511}
Note: See TracChangeset for help on using the changeset viewer.