IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2005, 11:22:22 AM (21 years ago)
Author:
drobbin
Message:

Minor changes from new SDRS, prototype code for psArguments

File:
1 edited

Legend:

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

    r4898 r5057  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-08-30 01:14:13 $
     9 *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-09-15 21:22:21 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    186186    int status = 0;
    187187
    188     fits_get_hdrspace(fits->p_fd, &keysexist, &morekeys, &status);
     188    fits_get_hdrspace(fits->fd, &keysexist, &morekeys, &status);
    189189
    190190    // if no keys exist and not primary HDU, this really is an empty HDU
     
    202202
    203203    if (fits != NULL) {
    204         (void)fits_close_file(fits->p_fd, &status);
     204        (void)fits_close_file(fits->fd, &status);
    205205        psFree(fits->filename);
    206206    }
     
    247247    psFits* fits = psAlloc(sizeof(psFits));
    248248    fits->filename = psAlloc(strlen(name)+1);
    249     fits->p_fd = fptr;
     249    fits->fd = fptr;
    250250    strcpy((char*)fits->filename,name);
    251251    psMemSetDeallocator(fits,(psFreeFunc)fitsFree);
     
    279279
    280280
    281     if (fits_movnam_hdu(fits->p_fd, ANY_HDU, (char*)extname, 0, &status) != 0) {
     281    if (fits_movnam_hdu(fits->fd, ANY_HDU, (char*)extname, 0, &status) != 0) {
    282282        char fitsErr[MAX_STRING_LENGTH];
    283283        fits_get_errstatus(status, fitsErr);
     
    305305
    306306    if (relative) {
    307         fits_movrel_hdu(fits->p_fd, extnum, &hdutype, &status);
     307        fits_movrel_hdu(fits->fd, extnum, &hdutype, &status);
    308308        if (status != 0) {
    309309            char fitsErr[MAX_STRING_LENGTH];
     
    315315        }
    316316    } else {
    317         fits_movabs_hdu(fits->p_fd, extnum+1, &hdutype, &status);
     317        fits_movabs_hdu(fits->fd, extnum+1, &hdutype, &status);
    318318        if (status != 0) {
    319319            char fitsErr[MAX_STRING_LENGTH];
     
    340340
    341341
    342     return fits_get_hdu_num(fits->p_fd,&hdunum) - 1;
     342    return fits_get_hdu_num(fits->fd,&hdunum) - 1;
    343343}
    344344
     
    354354    char name[MAX_STRING_LENGTH];
    355355
    356     if (fits_read_key_str(fits->p_fd, "EXTNAME", name, NULL, &status) != 0) {
     356    if (fits_read_key_str(fits->fd, "EXTNAME", name, NULL, &status) != 0) {
    357357        status = 0;
    358         if (fits_read_key_str(fits->p_fd, "HDUNAME", name, NULL, &status) != 0) {
     358        if (fits_read_key_str(fits->fd, "HDUNAME", name, NULL, &status) != 0) {
    359359            int num = psFitsGetExtNum(fits);
    360360            snprintf(name, MAX_STRING_LENGTH, "EXT-%3d",num);
     
    380380    int status = 0;
    381381
    382     if (fits_update_key_str(fits->p_fd, "EXTNAME", (char*)name, NULL, &status) != 0) {
     382    if (fits_update_key_str(fits->fd, "EXTNAME", (char*)name, NULL, &status) != 0) {
    383383        char fitsErr[MAX_STRING_LENGTH];
    384384        (void)fits_get_errstatus(status, fitsErr);
     
    403403    int status = 0;
    404404
    405     if (fits_get_num_hdus(fits->p_fd, &num, &status) != 0) {
     405    if (fits_get_num_hdus(fits->fd, &num, &status) != 0) {
    406406        char fitsErr[MAX_STRING_LENGTH];
    407407        fits_get_errstatus(status, fitsErr);
     
    426426    int hdutype = PS_FITS_TYPE_NONE;
    427427
    428     if (fits_get_hdu_type(fits->p_fd, &hdutype, &status) != 0) {
     428    if (fits_get_hdu_type(fits->fd, &hdutype, &status) != 0) {
    429429        char fitsErr[MAX_STRING_LENGTH];
    430430        fits_get_errstatus(status, fitsErr);
     
    466466    int keyNum = 0;
    467467    int status = 0;
    468     fits_get_hdrpos(fits->p_fd, &numKeys, &keyNum, &status);
     468    fits_get_hdrpos(fits->fd, &numKeys, &keyNum, &status);
    469469
    470470    // Get each key name. Keywords start at one.
     
    478478    for (int i = 1; i <= numKeys; i++) {
    479479
    480         fits_read_keyn(fits->p_fd, i, keyName, keyValue, keyComment, &status);
     480        fits_read_keyn(fits->fd, i, keyName, keyValue, keyComment, &status);
    481481
    482482        stdKey = false;
     
    657657    // check to see if we even are positioned on an image HDU
    658658    int hdutype;
    659     if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) {
     659    if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) {
    660660        char fitsErr[MAX_STRING_LENGTH];
    661661        (void)fits_get_errstatus(status, fitsErr);
     
    672672
    673673    /* Get the data type 'bitPix' from the FITS image */
    674     if (fits_get_img_equivtype(fits->p_fd, &bitPix, &status) != 0) {
     674    if (fits_get_img_equivtype(fits->fd, &bitPix, &status) != 0) {
    675675        fits_get_errstatus(status, fitsErr);
    676676        psError(PS_ERR_IO, true,
     
    682682
    683683    /* Get the dimensions 'nAxis' from the FITS image */
    684     if (fits_get_img_dim(fits->p_fd, &nAxis, &status) != 0) {
     684    if (fits_get_img_dim(fits->fd, &nAxis, &status) != 0) {
    685685        (void)fits_get_errstatus(status, fitsErr);
    686686        psError(PS_ERR_IO, true,
     
    701701
    702702    /* Get the Image size from the FITS file */
    703     if (fits_get_img_size(fits->p_fd, nAxis, nAxes, &status) != 0) {
     703    if (fits_get_img_size(fits->fd, nAxis, nAxes, &status) != 0) {
    704704        (void)fits_get_errstatus(status, fitsErr);
    705705        psError(PS_ERR_IO, true,
     
    787787
    788788    // n.b., this assumes contiguous image buffer
    789     if (fits_read_subset(fits->p_fd, fitsDatatype, firstPixel, lastPixel, increment,
     789    if (fits_read_subset(fits->fd, fitsDatatype, firstPixel, lastPixel, increment,
    790790                         NULL, output->data.V[0], &anynull, &status) != 0) {
    791791        psFree(output);
     
    842842    }
    843843
    844     fits_create_img(fits->p_fd, bitPix, naxis, naxes, &status);
     844    fits_create_img(fits->fd, bitPix, naxis, naxes, &status);
    845845
    846846    if (bZero != 0) {        // set the bscale/bzero
    847         fits_write_key_dbl(fits->p_fd, "BZERO", bZero, 12, "Pixel Value Offset", &status);
    848         fits_write_key_dbl(fits->p_fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status);
    849         fits_set_bscale(fits->p_fd, 1.0, bZero, &status);
     847        fits_write_key_dbl(fits->fd, "BZERO", bZero, 12, "Pixel Value Offset", &status);
     848        fits_write_key_dbl(fits->fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status);
     849        fits_set_bscale(fits->fd, 1.0, bZero, &status);
    850850    }
    851851
     
    856856
    857857    if (input->parent == NULL) { // if no parent, assume that the image data is contiguous
    858         fits_write_img(fits->p_fd,
     858        fits_write_img(fits->fd,
    859859                       dataType,              // datatype
    860860                       1,                     // writing to the first z-plane
     
    865865        int firstPixel = 1;
    866866        for (int row = 0; row < numRows; row++) {
    867             fits_write_img(fits->p_fd,
     867            fits_write_img(fits->fd,
    868868                           dataType,          // datatype
    869869                           firstPixel,
     
    909909    // check to see if we are positioned on an image HDU
    910910    int hdutype;
    911     if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) {
     911    if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) {
    912912        char fitsErr[MAX_STRING_LENGTH];
    913913        (void)fits_get_errstatus(status, fitsErr);
     
    939939    long nAxes[3];
    940940    nAxes[2] = 1;
    941     fits_get_img_param(fits->p_fd, 3, &fileBitpix, &naxis, nAxes, &status);
     941    fits_get_img_param(fits->fd, 3, &fileBitpix, &naxis, nAxes, &status);
    942942
    943943    //check to see if the HDU has the same datatype
     
    10121012    }
    10131013
    1014     fits_write_subset(fits->p_fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status);
     1014    fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status);
    10151015
    10161016    if ( status != 0) {
     
    10521052        case PS_META_BOOL: {
    10531053                int value = item->data.B;
    1054                 fits_update_key(fits->p_fd,
     1054                fits_update_key(fits->fd,
    10551055                                TLOGICAL,
    10561056                                item->name,
     
    10611061            }
    10621062        case PS_META_S32:
    1063             fits_update_key(fits->p_fd,
     1063            fits_update_key(fits->fd,
    10641064                            TINT,
    10651065                            item->name,
     
    10691069            break;
    10701070        case PS_META_F32:
    1071             fits_update_key(fits->p_fd,
     1071            fits_update_key(fits->fd,
    10721072                            TFLOAT,
    10731073                            item->name,
     
    10771077            break;
    10781078        case PS_META_F64:
    1079             fits_update_key(fits->p_fd,
     1079            fits_update_key(fits->fd,
    10801080                            TDOUBLE,
    10811081                            item->name,
     
    10851085            break;
    10861086        case PS_META_STR:
    1087             fits_update_key(fits->p_fd,
     1087            fits_update_key(fits->fd,
    10881088                            TSTRING,
    10891089                            item->name,
     
    11241124    // check to see if we even are positioned on a table HDU
    11251125    int hdutype;
    1126     fits_get_hdu_type(fits->p_fd,&hdutype, &status);
     1126    fits_get_hdu_type(fits->fd,&hdutype, &status);
    11271127    if ( status != 0) {
    11281128        char fitsErr[MAX_STRING_LENGTH];
     
    11401140
    11411141    // get the size of the FITS table
    1142     fits_get_num_rows(fits->p_fd, &numRows, &status);
    1143     fits_get_num_cols(fits->p_fd, &numCols, &status);
     1142    fits_get_num_rows(fits->fd, &numRows, &status);
     1143    fits_get_num_cols(fits->fd, &numCols, &status);
    11441144    if ( status != 0) {
    11451145        char fitsErr[MAX_STRING_LENGTH];
     
    11691169        // get the column name
    11701170        if (hdutype == BINARY_TBL) {
    1171             fits_get_bcolparms(fits->p_fd, col, name,
     1171            fits_get_bcolparms(fits->fd, col, name,
    11721172                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, &status);
    11731173        } else {
    1174             fits_get_acolparms(fits->p_fd, col, name,
     1174            fits_get_acolparms(fits->fd, col, name,
    11751175                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, &status);
    11761176        }
    11771177        // get the column type
    1178         fits_get_coltype(fits->p_fd, col, &typecode, &repeat, &width, &status);
     1178        fits_get_coltype(fits->fd, col, &typecode, &repeat, &width, &status);
    11791179
    11801180        if (status == 0) {
     
    11841184                NATIVETYPE value = 0; \
    11851185                int anynul = 0; \
    1186                 fits_read_col(fits->p_fd, FITSTYPE, col,row+1, \
     1186                fits_read_col(fits->fd, FITSTYPE, col,row+1, \
    11871187                              1, 1, NULL, &value, &anynul, &status); \
    11881188                psTrace(".psFits.psFitsReadTableRow",5,"Column #%i, '%s', is type %i, repeat %i, Value = %g\n", \
     
    12051205                    char* value = psAlloc(repeat+1);
    12061206                    int anynul = 0;
    1207                     fits_read_col(fits->p_fd, TSTRING, col,row+1,
     1207                    fits_read_col(fits->fd, TSTRING, col,row+1,
    12081208                                  1, 1, NULL, &value, &anynul, &status);
    12091209                    psTrace(".psFits.psFitsReadTableRow",5,"Column #%i, '%s', is type %i, repeat %i, value = %s\n",
     
    12531253    // check to see if we even are positioned on a table HDU
    12541254    int hdutype;
    1255     if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) {
     1255    if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) {
    12561256        char fitsErr[MAX_STRING_LENGTH];
    12571257        (void)fits_get_errstatus(status, fitsErr);
     
    12681268
    12691269    // find the column by name
    1270     if ( fits_get_colnum(fits->p_fd, CASESEN, (char*)colname, &colnum, &status) != 0) {
     1270    if ( fits_get_colnum(fits->fd, CASESEN, (char*)colname, &colnum, &status) != 0) {
    12711271        char fitsErr[MAX_STRING_LENGTH];
    12721272        (void)fits_get_errstatus(status, fitsErr);
     
    12791279    // get the number of rows
    12801280    long numRows = 0;
    1281     fits_get_num_rows(fits->p_fd, &numRows, &status);
     1281    fits_get_num_rows(fits->fd, &numRows, &status);
    12821282
    12831283    // get the column length.
    12841284    int width;
    1285     if ( fits_get_col_display_width(fits->p_fd, colnum, &width, &status) != 0) {
     1285    if ( fits_get_col_display_width(fits->fd, colnum, &width, &status) != 0) {
    12861286        char fitsErr[MAX_STRING_LENGTH];
    12871287        (void)fits_get_errstatus(status, fitsErr);
     
    12991299    result->n = numRows;
    13001300
    1301     fits_read_col_str(fits->p_fd,
     1301    fits_read_col_str(fits->fd,
    13021302                      colnum,
    13031303                      1, // firstrow
     
    13351335    // check to see if we even are positioned on a table HDU
    13361336    int hdutype;
    1337     if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) {
     1337    if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) {
    13381338        char fitsErr[MAX_STRING_LENGTH];
    13391339        (void)fits_get_errstatus(status, fitsErr);
     
    13501350
    13511351    // find the column by name
    1352     if ( fits_get_colnum(fits->p_fd, CASESEN, (char*)colname, &colnum, &status) != 0) {
     1352    if ( fits_get_colnum(fits->fd, CASESEN, (char*)colname, &colnum, &status) != 0) {
    13531353        char fitsErr[MAX_STRING_LENGTH];
    13541354        (void)fits_get_errstatus(status, fitsErr);
     
    13611361    // get the number of rows
    13621362    long numRows = 0;
    1363     fits_get_num_rows(fits->p_fd,
     1363    fits_get_num_rows(fits->fd,
    13641364                      &numRows,
    13651365                      &status);
     
    13691369    long repeat;
    13701370    long width;
    1371     if ( fits_get_eqcoltype(fits->p_fd, colnum, &typecode, &repeat, &width, &status) != 0) {
     1371    if ( fits_get_eqcoltype(fits->fd, colnum, &typecode, &repeat, &width, &status) != 0) {
    13721372        char fitsErr[MAX_STRING_LENGTH];
    13731373        (void)fits_get_errstatus(status, fitsErr);
     
    13801380    psVector* result = psVectorAlloc(numRows, convertFitsToPsType(typecode));
    13811381
    1382     fits_read_col(fits->p_fd,
     1382    fits_read_col(fits->fd,
    13831383                  typecode,
    13841384                  colnum,
     
    14161416    // check to see if we even are positioned on a table HDU
    14171417    int hdutype;
    1418     if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) {
     1418    if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) {
    14191419        char fitsErr[MAX_STRING_LENGTH];
    14201420        (void)fits_get_errstatus(status, fitsErr);
     
    14321432    // get the size of the FITS table
    14331433    long numRows = 0;
    1434     fits_get_num_rows(fits->p_fd, &numRows, &status);
     1434    fits_get_num_rows(fits->fd, &numRows, &status);
    14351435    if ( status != 0) {
    14361436        char fitsErr[MAX_STRING_LENGTH];
     
    15351535    }
    15361536
    1537     fits_create_tbl(fits->p_fd,
     1537    fits_create_tbl(fits->fd,
    15381538                    BINARY_TBL,
    15391539                    table->n, // number of rows in table
     
    15621562                                         item->name);
    15631563                }
    1564                 fits_write_col_int(fits->p_fd,
     1564                fits_write_col_int(fits->fd,
    15651565                                   n+1, // column number
    15661566                                   1, // firstrow
     
    15771577                                         item->name);
    15781578                }
    1579                 fits_write_col_flt(fits->p_fd,
     1579                fits_write_col_flt(fits->fd,
    15801580                                   n+1, // column number
    15811581                                   1, // firstrow
     
    15921592                                         item->name);
    15931593                }
    1594                 fits_write_col_dbl(fits->p_fd,
     1594                fits_write_col_dbl(fits->fd,
    15951595                                   n+1, // column number
    15961596                                   1, // firstrow
     
    16071607                                        item->name);
    16081608                }
    1609                 fits_write_col_log(fits->p_fd,
     1609                fits_write_col_log(fits->fd,
    16101610                                   n+1, // column number
    16111611                                   1, // firstrow
     
    16251625                col->data[row] = item->data.V;
    16261626            }
    1627             fits_write_col_str(fits->p_fd,
     1627            fits_write_col_str(fits->fd,
    16281628                               n, // column number
    16291629                               1, // firstrow
     
    16611661    // check to see if we even are positioned on a table HDU
    16621662    int hdutype;
    1663     if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) {
     1663    if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) {
    16641664        char fitsErr[MAX_STRING_LENGTH];
    16651665        (void)fits_get_errstatus(status, fitsErr);
     
    16841684            int colnum = 0;
    16851685
    1686             if ( fits_get_colnum(fits->p_fd, CASESEN, item->name, &colnum, &status) == 0) {
     1686            if ( fits_get_colnum(fits->fd, CASESEN, item->name, &colnum, &status) == 0) {
    16871687                // cooresponding column found in table
    16881688                int dataType = 0;
    16891689                convertPsTypeToFits(item->type, NULL, NULL, &dataType);
    16901690
    1691                 if (fits_write_col(fits->p_fd, dataType, colnum, row+1, 1, 1, &item->data,&status) != 0) {
     1691                if (fits_write_col(fits->fd, dataType, colnum, row+1, 1, 1, &item->data,&status) != 0) {
    16921692                    char fitsErr[MAX_STRING_LENGTH];
    16931693                    (void)fits_get_errstatus(status, fitsErr);
Note: See TracChangeset for help on using the changeset viewer.