IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6514


Ignore:
Timestamp:
Mar 3, 2006, 4:39:39 PM (20 years ago)
Author:
Paul Price
Message:

Compiles now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psLib/src/fits/psFitsImage.c

    r6513 r6514  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.1.10.2 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-03-04 01:54:42 $
     9 *  @version $Revision: 1.1.10.3 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-03-04 02:39:39 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2525#include "psTrace.h"
    2626#include "psVector.h"
    27 
     27#include "psFitsImage.h"
    2828#include "psFitsHeader.h"
    2929
     
    257257    }
    258258
    259     output = psImageAlloc(lastPixel[0]-firstPixel[0]+1, lastPixel[1]-firstPixel[1]+1, datatype);
     259    psImage *output = psImageAlloc(lastPixel[0]-firstPixel[0]+1, lastPixel[1]-firstPixel[1]+1, datatype);
    260260
    261261    // n.b., this assumes contiguous image buffer
     
    278278    int nAxis = 0;                      // Number of axes
    279279    long nAxes[3];                      // Number of pixels on each axis
     280    int status = 0;                     // cfitsio status value
     281    char fitsErr[80] = "";              // CFITSIO error message string
    280282
    281283    if (fits == NULL) {
     
    327329                      psMetadata* header,
    328330                      const psImage* input,
    329                       int numZPlanes)
     331                      int numZPlanes,
     332                      const char *extname)
    330333{
    331334
     
    373376        psMetadataAddF64(header, PS_LIST_TAIL, "BSCALE", PS_META_REPLACE, "Pixel value scale", 1.0);
    374377        psMetadataAddF64(header, PS_LIST_TAIL, "BZERO",  PS_META_REPLACE, "Pixel value offset", bZero);
     378        psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "Extension name", extname);
    375379    }
    376380
     
    381385        psFitsWriteHeader(header, (psPtr)fits);
    382386    } else {
     387        // Write the necessary headers manually
    383388        fits_write_key_dbl(fits->fd, "BZERO", bZero, 12, "Pixel Value Offset", &status);
    384389        fits_write_key_dbl(fits->fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status);
     390        // Regrettably have to cast away "const" on extname
     391        fits_write_key_str(fits->fd, "EXTNAME", (char *)extname, "Extension name", &status);
     392
    385393    }
    386394
     
    438446    if (input->n == 0) {
    439447        psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_EMPTY);
    440         return falase;
     448        return false;
    441449    }
    442450
    443451    if (input->n == 1) {
    444452        // The problem reduces to one already solved
    445         return psFitsWriteImage(fits, header, input->data[0], extname);
     453        return psFitsWriteImage(fits, header, input->data[0], 1, extname);
    446454    }
    447455
    448456    // Check that all images are of the same size
    449     {
    450         psImage *image = input->data[0];// First image off the array
    451         int numCols = image->numCols;   // Number of columns
    452         int numRows = image->numRows;   // Number of rows
    453         for (int i = 1; i < input->n; i++)
    454         {
    455             image = input->data[i];
    456             if (image->numCols != numCols || image->numRows != numRows) {
    457                 psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_SIZE_DIFFER);
    458                 return false;
    459             }
     457    psImage *testImage = input->data[0];// First image off the array
     458    int numCols = testImage->numCols;   // Number of columns
     459    int numRows = testImage->numRows;   // Number of rows
     460    for (int i = 1; i < input->n; i++) {
     461        testImage = input->data[i];
     462        if (testImage->numCols != numCols || testImage->numRows != numRows) {
     463            psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_SIZE_DIFFER);
     464            return false;
    460465        }
    461466    }
     
    472477                  psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS2", PS_META_REPLACE, "Number of rows", numRows) &&
    473478                  psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS3", PS_META_REPLACE, "Number of image planes",
    474                                    images->n);
     479                                   input->n);
    475480    if (! update) {
    476         psError(PS_ERR_UNKNOWN, false, psFits_METADATA_ADD_FAILED, "NAXIS, NAXIS1, NAXIS2, NAXIS3");
     481        psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_METADATA_ADD_FAILED,
     482                "NAXIS, NAXIS1, NAXIS2, NAXIS3");
    477483        psFree(headerCopy);
    478484        return false;
    479485    }
    480486
    481     // Now we can safely write the images out
    482     for (int i = 0; i < images->n; i++) {
    483         if (! psFitsWriteImage(fits, headerCopy, images->data[i], i, extname)) {
     487    // Now we can safely write the images out.
     488    // The first is an psFitsImageWrite to create the extension.
     489    // The next are psFitsImageUpdate to write into the extension.
     490    if (! psFitsWriteImage(fits, headerCopy, input->data[0], input->n, extname)) {
     491        psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_WRITE_PLANE_FAILED, 0);
     492        psFree(headerCopy);
     493        return false;
     494    }
     495    psFree(headerCopy);                 // Free, or drop reference
     496
     497    for (int i = 1; i < input->n; i++) {
     498        if (! psFitsUpdateImage(fits, input->data[i], 0, 0, i)) {
    484499            psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_WRITE_PLANE_FAILED, i);
    485             psFree(headerCopy);
    486500            return false;
    487501        }
    488502    }
    489503
    490     psFree(headerCopy);                 // Free, or drop reference
    491 
    492504    return true;
    493505}
    494506
    495 
    496 
    497507bool psFitsUpdateImage(psFits* fits,
    498508                       const psImage* input,
    499                        psRegion region,
     509                       int x0, int y0,
    500510                       int z)
    501511{
     
    572582    long lastPixel[3];
    573583
    574     firstPixel[0] = region.x0 + 1;
    575     firstPixel[1] = region.y0 + 1;
     584    firstPixel[0] = x0 + 1;
     585    firstPixel[1] = y0 + 1;
    576586    firstPixel[2] = z + 1;
    577587
    578     if (region.x1 > 0) {
    579         lastPixel[0] = region.x1;
    580     } else {
    581         lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0
    582     }
    583     if (region.y1 > 0) {
    584         lastPixel[1] = region.y1;
    585     } else {
    586         lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0
    587     }
     588    lastPixel[0] = firstPixel[0] + input->numCols;
     589    lastPixel[1] = firstPixel[1] + input->numRows;
    588590    lastPixel[2] = z + 1;
    589591
     
    594596        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    595597                "Specified region [%d:%d,%d:%d], is not valid given the %dx%d FITS image.",
    596                 region.y0,region.y1-1,region.x0,region.x1-1);
     598                x0, x0 + input->numCols, y0, y0 + input->numRows, nAxes[0], nAxes[1]);
    597599        return false;
    598600
     
    633635}
    634636
     637bool psFitsUpdateImageCube(psFits *fits, const psArray *input, int x0, int y0)
     638{
     639    if (fits == NULL) {
     640        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     641                PS_ERRORTEXT_psFits_NULL);
     642        return false;
     643    }
     644
     645    if (input == NULL) {
     646        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     647                PS_ERRORTEXT_psFits_IMAGE_NULL);
     648        return false;
     649    }
     650
     651    if (input->n == 0) {
     652        psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_EMPTY);
     653        return false;
     654    }
     655
     656    for (int i = 0; i < input->n; i++) {
     657        if (! psFitsUpdateImage(fits, input->data[i], x0, y0, i)) {
     658            psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_UPDATE_PLANE_FAILED, i);
     659            return false;
     660        }
     661    }
     662
     663    return true;
     664}
Note: See TracChangeset for help on using the changeset viewer.