IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32263


Ignore:
Timestamp:
Aug 31, 2011, 4:28:27 PM (15 years ago)
Author:
bills
Message:

Implement the accessor functions. Remove the GetCell accessor versions.

Location:
trunk/psLib/src/fits
Files:
2 edited

Legend:

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

    r32251 r32263  
    9595
    9696void
    97 freeTable(psFitsTable *table) {
     97freeTable(psFitsTable *table)
     98{
    9899    for (int col = 0; col < table->numCols; col++) {
    99100        psFitsTableColumn *column = &table->columns[col];
     
    287288}
    288289
    289 // return the index for a given column
    290 int psFitsTableGetColumnIndex(psFitsTable *table, psString name)
     290// return the column number with a given name
     291int psFitsTableGetColumnNumber(psFitsTable *table, const char *name)
    291292{
    292293    bool mdok;
     
    294295
    295296    if (!mdok) {
    296         psFitsError(mdok, false, "Failed to lookup column index for %s", name);
     297        psFitsError(mdok, true, "Failed to lookup column index for %s", name);
    297298        return -1;
    298299    }
     
    301302}
    302303
    303 // return F32 value for given cell
    304 psF32 psFitsTableGetCellF32(psFitsTable *table, int row, int col) {
    305     return table->columns[col].data.F32[row];
    306 }
    307 
    308 // return value for a named column for a given row
    309 psF32 psFitsTableGetF32(bool *status, psFitsTable *table, psString name, int row) {
    310     bool mdok;
    311     int col = psFitsTableGetColumnIndex(table, name);
    312 
    313     if (mdok) {
    314         return table->columns[col].data.F32[row];
    315     } else {
    316         return 0;
    317     }
    318 }
     304#define psFitsTableGetNumTYPE(TYPE, NAME) \
     305ps##TYPE psFitsTableGet##NAME(bool *status, psFitsTable *table, int row, const char *name) \
     306{ \
     307    ps##TYPE value = 0; \
     308    if (status) { \
     309        *status = true; \
     310    } \
     311    \
     312    if (row >= table->numRows || row < 0) { \
     313        if (status) { \
     314            *status = false; \
     315        } \
     316        return 0; \
     317    } \
     318    bool mdok; \
     319    int col = psMetadataLookupS32(&mdok, table->index, name); \
     320    if (!mdok) { \
     321        if (status) { \
     322            *status = false; \
     323        } \
     324        return 0; \
     325    } \
     326    if (col < 0) { \
     327        if (status) { \
     328            *status = false; \
     329        } \
     330        return 0; \
     331    } \
     332    psFitsTableColumn *column = &table->columns[col]; \
     333    switch (column->type) { \
     334        case PS_DATA_S8: \
     335        value = (ps##TYPE)column->data.S8[row]; \
     336        break; \
     337    case PS_DATA_S16: \
     338        value = (ps##TYPE)column->data.S16[row]; \
     339        break; \
     340    case PS_DATA_S32: \
     341        value = (ps##TYPE)column->data.S32[row]; \
     342        break; \
     343    case PS_DATA_S64: \
     344        value = (ps##TYPE)column->data.S64[row]; \
     345        break; \
     346    case PS_DATA_U8: \
     347        value = (ps##TYPE)column->data.U8[row]; \
     348        break; \
     349    case PS_DATA_U16: \
     350        value = (ps##TYPE)column->data.U16[row]; \
     351        break; \
     352    case PS_DATA_U32: \
     353        value = (ps##TYPE)column->data.U32[row]; \
     354        break; \
     355    case PS_DATA_U64: \
     356        value = (ps##TYPE)column->data.U64[row]; \
     357        break; \
     358    case PS_DATA_F32: \
     359        value = (ps##TYPE)column->data.F32[row]; \
     360        break; \
     361    case PS_DATA_F64: \
     362        value = (ps##TYPE)column->data.F64[row]; \
     363        break; \
     364    case PS_DATA_BOOL: \
     365        if (column->data.BOOL[row]) { \
     366            value = 1; \
     367        } \
     368        break; \
     369    default: \
     370        /* if you get to this point, the value is not a number. */ \
     371        if (status) {  \
     372            *status = false; \
     373        }  \
     374        break; \
     375    } \
     376    return value; \
     377}
     378
     379// #define psFitsTableGetNumTYPE(TYPE, NAME)
     380
     381psFitsTableGetNumTYPE(S8, S8);
     382psFitsTableGetNumTYPE(U8, U8);
     383psFitsTableGetNumTYPE(S16, S16);
     384psFitsTableGetNumTYPE(U16, U16);
     385psFitsTableGetNumTYPE(S32, S32);
     386psFitsTableGetNumTYPE(U32, U32);
     387psFitsTableGetNumTYPE(S64, S64);
     388psFitsTableGetNumTYPE(U64, U64);
     389psFitsTableGetNumTYPE(F32, F32);
     390psFitsTableGetNumTYPE(F64, F64);
     391psFitsTableGetNumTYPE(Bool, BOOL);
    319392
    320393// remove rows from table that are marked in the mask array as censored.
  • trunk/psLib/src/fits/psFitsTableNew.h

    r32228 r32263  
    4444} psFitsTable;
    4545
    46 // return index of column by name
    47 int psFitsTableGetColumnIndex(psFitsTable *table, psString name);
    48 
    49 // return type for column
    50 // Most code knows it's tables so this won't be used much
    51 int psFitsTableGetColumnType(psFitsTable *table, int col);
     46// return column number of column with name (-1 if not found)
     47int psFitsTableGetColumnNumber(psFitsTable *table, const char *name);
    5248
    5349psFitsTable *psFitsReadTableNew(const psFits *fits);
    5450bool psFitsWriteTableNew(psFits *fits, const psMetadata *header, psFitsTable *table, const char *extname);
     51
     52// remove rows from table whose entry in the supplied array are true
    5553bool psFitsTableCensor(psFitsTable *table, bool *rowMask);
    5654
    57 psF32 psFitsTableGetCellF32(psFitsTable *table, int row, int col);
     55// Get value for given row and column name
     56psBool psFitsTableGetBool(bool *status, psFitsTable *table, int row, const char* name);
     57psS8 psFitsTableGetS8(bool *status, psFitsTable *table, int row, const char* name);
     58psU8 psFitsTableGetU8(bool *status, psFitsTable *table, int row, const char* name);
     59psS16 psFitsTableGetS16(bool *status, psFitsTable *table, int row, const char* name);
     60psU16 psFitsTableGetU16(bool *status, psFitsTable *table, int row, const char* name);
     61psS32 psFitsTableGetS32(bool *status, psFitsTable *table, int row, const char* name);
     62psU32 psFitsTableGetU32(bool *status, psFitsTable *table, int row, const char* name);
     63psS64 psFitsTableGetS64(bool *status, psFitsTable *table, int row, const char* name);
     64psU64 psFitsTableGetU64(bool *status, psFitsTable *table, int row, const char* name);
    5865
    59 psF32 psFitsTableGetF32(bool *status, psFitsTable *table, psString name, int row);
     66psF32 psFitsTableGetF32(bool *status, psFitsTable *table, int row, const char* name);
     67psF64 psFitsTableGetF64(bool *status, psFitsTable *table, int row, const char* name);
    6068
    61 
    62 #ifdef notdef
    63 // Accessors
    64 psF32 psFitsTableGetCellF32(psFitsTable *table, int row, int col)
    65 {
    66     assert(row >= 0 && row < table->numRows);
    67     assert(col >= 0 && col < table->numCols);
    68     assert(table->columns[col].type == PS_TYPE_F32);
    69 
    70     return table->columns[col].data.F32[row];
    71 }
    72 
    73 ---------------------------
    74 // code in streaksremove censore sources beocomes
    75 
    76     psFitsTable *table = psFitsReadTableNew(in->fits);
    77     int x_col = psFitsGetColumnIndex(table, "X_PSF");
    78     int y_col = psFitsGetColumnIndex(table, "X_PSF");
    79 
    80     // Array of booleans. If true don't write the row.
    81     bool rowMask = psAlloc(table->numRows * sizeof(bool));
    82     bzero(rowMask, table->numRows * sizeof(bool));
    83 
    84     for (int i=0; i < table->numRows; i++) {
    85         psF32 x = psFitsTableGetCellF32(table, row, x_col);
    86         psF32 y = psFitsTableGetCellF32(table, row, y_col);
    87 
    88         if ((x >= maskImage->numCols) || (y >= maskImage->numRows)
    89             || (x <  0) || (y < 0) || isnan(x) || isnan(y)) {
    90             mask = maskStreak;
    91         } else {
    92             mask = maskImage->data.PS_TYPE_IMAGE_MASK_DATA[(int)y][(int)x];
    93         }
    94 
    95         // Key the source if the center pixel is not masked with maskStreak
    96         if (mask & maskStreak) {
    97             numCensored++;
    98             rowMask[i] = true;
    99         }
    100     }
    101 
    102     if (numCensored < table->numRows) {
    103         psFitsWriteTableNew(out->fits, header, table, extname, rowMask);
    104     } else {
    105         psFitsWriteTableNewEmpty(out->fits, header, table, extname);
    106     }
    107 #endif // notdef
    108 
    109 #endif // #ifndef PS_FITSTABLENEW_H
     69#endif
Note: See TracChangeset for help on using the changeset viewer.