Changeset 32263
- Timestamp:
- Aug 31, 2011, 4:28:27 PM (15 years ago)
- Location:
- trunk/psLib/src/fits
- Files:
-
- 2 edited
-
psFitsTableNew.c (modified) (4 diffs)
-
psFitsTableNew.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsTableNew.c
r32251 r32263 95 95 96 96 void 97 freeTable(psFitsTable *table) { 97 freeTable(psFitsTable *table) 98 { 98 99 for (int col = 0; col < table->numCols; col++) { 99 100 psFitsTableColumn *column = &table->columns[col]; … … 287 288 } 288 289 289 // return the index for a given column290 int psFitsTableGetColumn Index(psFitsTable *table, psStringname)290 // return the column number with a given name 291 int psFitsTableGetColumnNumber(psFitsTable *table, const char *name) 291 292 { 292 293 bool mdok; … … 294 295 295 296 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); 297 298 return -1; 298 299 } … … 301 302 } 302 303 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) \ 305 ps##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 381 psFitsTableGetNumTYPE(S8, S8); 382 psFitsTableGetNumTYPE(U8, U8); 383 psFitsTableGetNumTYPE(S16, S16); 384 psFitsTableGetNumTYPE(U16, U16); 385 psFitsTableGetNumTYPE(S32, S32); 386 psFitsTableGetNumTYPE(U32, U32); 387 psFitsTableGetNumTYPE(S64, S64); 388 psFitsTableGetNumTYPE(U64, U64); 389 psFitsTableGetNumTYPE(F32, F32); 390 psFitsTableGetNumTYPE(F64, F64); 391 psFitsTableGetNumTYPE(Bool, BOOL); 319 392 320 393 // remove rows from table that are marked in the mask array as censored. -
trunk/psLib/src/fits/psFitsTableNew.h
r32228 r32263 44 44 } psFitsTable; 45 45 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) 47 int psFitsTableGetColumnNumber(psFitsTable *table, const char *name); 52 48 53 49 psFitsTable *psFitsReadTableNew(const psFits *fits); 54 50 bool 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 55 53 bool psFitsTableCensor(psFitsTable *table, bool *rowMask); 56 54 57 psF32 psFitsTableGetCellF32(psFitsTable *table, int row, int col); 55 // Get value for given row and column name 56 psBool psFitsTableGetBool(bool *status, psFitsTable *table, int row, const char* name); 57 psS8 psFitsTableGetS8(bool *status, psFitsTable *table, int row, const char* name); 58 psU8 psFitsTableGetU8(bool *status, psFitsTable *table, int row, const char* name); 59 psS16 psFitsTableGetS16(bool *status, psFitsTable *table, int row, const char* name); 60 psU16 psFitsTableGetU16(bool *status, psFitsTable *table, int row, const char* name); 61 psS32 psFitsTableGetS32(bool *status, psFitsTable *table, int row, const char* name); 62 psU32 psFitsTableGetU32(bool *status, psFitsTable *table, int row, const char* name); 63 psS64 psFitsTableGetS64(bool *status, psFitsTable *table, int row, const char* name); 64 psU64 psFitsTableGetU64(bool *status, psFitsTable *table, int row, const char* name); 58 65 59 psF32 psFitsTableGetF32(bool *status, psFitsTable *table, psString name, int row); 66 psF32 psFitsTableGetF32(bool *status, psFitsTable *table, int row, const char* name); 67 psF64 psFitsTableGetF64(bool *status, psFitsTable *table, int row, const char* name); 60 68 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.
