IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2006, 3:50:33 PM (20 years ago)
Author:
Paul Price
Message:

Moving psFitsWriteTable functionality into psFitsInsertTable (the two were virtually identical; this now mirrors psFitsWriteImage and psFitsInsertImage). psFitsInsertImage now writes out the supplied header.

File:
1 edited

Legend:

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

    r6767 r7230  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-04-04 19:52:42 $
     9 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-05-27 01:50:33 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 */
    1414
     15#include "config.h"
    1516#include "psFits.h"
    1617#include "string.h"
     
    2324#include "psTrace.h"
    2425#include "psVector.h"
    25 #include "config.h"
     26#include "psFitsTable.h"
     27#include "psFitsHeader.h"
    2628
    2729#define MAX_STRING_LENGTH 256  // maximum length string for FITS routines
     
    603605
    604606bool psFitsWriteTable(psFits* fits,
    605                       const psMetadata* header,
    606                       const psArray* table)
     607                      psMetadata* header,
     608                      const psArray* table,
     609                      const char *extname)
    607610{
     611    psFitsMoveLast(fits);
     612    return psFitsInsertTable(fits, header, table, extname, true);
     613
     614    #if 0
     615
    608616    int status = 0;
    609617
     
    710718    }
    711719
    712     psString extname = NULL;
    713     if (header != NULL) {
    714         extname = psMetadataLookupStr(NULL, header, "EXTNAME");
    715         if ( extname == NULL) {
    716             extname = psMetadataLookupStr(NULL, header, "HDUNAME");
    717         }
    718     }
    719 
     720    // Create the table
    720721    fits_create_tbl(fits->fd,
    721722                    BINARY_TBL,
     
    727728                    extname, // extension name
    728729                    &status);
    729 
    730730    psFree(columnNames);
    731731    psFree(columnTypes);
     732
     733    // Write header
     734    if (header && !psFitsWriteHeader(header, fits)) {
     735        psError(PS_ERR_IO, false, "Unable to write FITS header.\n");
     736        return false;
     737    }
    732738
    733739    // fill in the table elements with data
     
    810816
    811817    return true;
     818    #endif
    812819}
    813820
    814821bool psFitsInsertTable(psFits* fits,
    815                        const psMetadata* header,
     822                       psMetadata* header,
    816823                       const psArray* table,
     824                       const char *extname,
    817825                       bool after)
    818826{
     
    921929    }
    922930
    923     psString extname = NULL;
    924     if (header != NULL) {
    925         extname = psMetadataLookupStr(NULL, header, "EXTNAME");
    926         if ( extname == NULL) {
    927             extname = psMetadataLookupStr(NULL, header, "HDUNAME");
    928         }
    929     }
    930 
    931     if (! after) {
    932         if (psFitsGetExtNum(fits) == 0) {
    933             // set status to signal fits_insert_img to insert a new primary HDU
    934             status = PREPEND_PRIMARY;
    935         } else {
    936             // move back one to perform an insert after the previous HDU
    937             psFitsMoveExtNum(fits, -1, true);
    938         }
    939     }
    940 
    941     fits_insert_btbl(fits->fd,
    942                      table->n, // number of rows in table
    943                      columns->n, // number of columns in table
    944                      (char**)columnNames->data, // names of the columns
    945                      (char**)columnTypes->data, // format of the columns
    946                      NULL, // physical unit of columns
    947                      extname, // extension name
    948                      0,
    949                      &status);
    950 
     931    // Create the table HDU
     932    int hdus = psFitsGetSize(fits);     // Number of HDUs in file
     933    if (hdus == 0) {
     934        // We're creating the first extension
     935        fits_create_tbl(fits->fd,
     936                        BINARY_TBL,
     937                        table->n, // number of rows in table
     938                        columns->n, // number of columns in table
     939                        (char**)columnNames->data, // names of the columns
     940                        (char**)columnTypes->data, // format of the columns
     941                        NULL, // physical unit of columns
     942                        (char*)extname, // extension name; casting away const because cfitsio is horrible
     943                        &status);
     944    } else {
     945        if (!after) {
     946            if (psFitsGetExtNum(fits) == 0) {
     947                // We're creating a replacement primary HDU.
     948                // Set status to signal fits_insert_img to insert a new primary HDU
     949                status = PREPEND_PRIMARY;
     950            } else {
     951                // Move back one to perform an insert after the previous HDU
     952                psFitsMoveExtNum(fits, -1, true);
     953            }
     954        }
     955        // Insert the table
     956        fits_insert_btbl(fits->fd,
     957                         table->n, // number of rows in table
     958                         columns->n, // number of columns in table
     959                         (char**)columnNames->data, // names of the columns
     960                         (char**)columnTypes->data, // format of the columns
     961                         NULL, // physical unit of columns
     962                         (char*)extname, // extension name; casting away const because cfitsio is horrible
     963                         0,
     964                         &status);
     965    }
    951966    psFree(columnNames);
    952967    psFree(columnTypes);
    953968
     969    // Write header
     970    if (header && !psFitsWriteHeader(header, fits)) {
     971        psError(PS_ERR_IO, false, "Unable to write FITS header.\n");
     972        return false;
     973    }
    954974
    955975    // fill in the table elements with data
Note: See TracChangeset for help on using the changeset viewer.