Changeset 31010 for trunk/ippToPsps/src
- Timestamp:
- Mar 22, 2011, 4:10:43 PM (15 years ago)
- Location:
- trunk/ippToPsps/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/src/Fits.c
r30861 r31010 19 19 if (fits_close_file(this->file, &status)) { 20 20 21 psError(PS_ERR_IO, false, " Unable to close FITS file");21 psError(PS_ERR_IO, false, "* Fits: Unable to close FITS file"); 22 22 fits_report_error(stderr, status); 23 23 } 24 25 printf("destroyed...\n"); 26 27 return; 24 else 25 psLogMsg("ippToPsps", PS_LOG_INFO, "* Fits: Closed '%s'", this->path); 26 } 27 28 /** 29 Gets a header key value 30 */ 31 static bool getHeaderKeyValue(Fits* this, int type, char* name, void* value) { 32 33 int status = 0; 34 fits_read_key(this->file, type, name, value, NULL, &status); 35 36 if (status) { 37 38 psError(PS_ERR_IO, false, "* Fits: Could not get value for header key '%s'\n", name); 39 return false; 40 } 41 42 return true; 43 } 44 45 /* 46 Gets the contents of a column vector 47 */ 48 static bool getColumnVector( 49 Fits* this, 50 int col, 51 long row, 52 int type, 53 int repeat, 54 float* vector) { 55 56 int status = 0; 57 int anynull = 0; 58 59 // remember to add 1 to row number since cfitsio is the stupidest libary ever written 60 fits_read_col(this->file, type, col, row+1, 1, repeat, NULL, vector, &anynull, &status); 61 62 if (status) { 63 64 psError(PS_ERR_IO, false, "* Fits: Failed to read vector column %d row %ld", col, row); 65 return false; 66 } 67 68 return true; 28 69 } 29 70 … … 37 78 if (status) { 38 79 39 psError(PS_ERR_IO, false, "Could not get column number for '%s'\n", name); 40 return false; 41 } 42 43 return true; 44 } 80 psError(PS_ERR_IO, false, "* Fits: Could not get column number for '%s'\n", name); 81 return false; 82 } 83 84 return true; 85 } 86 87 /* 88 Gets metadata about a column 89 */ 90 bool getColumnMeta( 91 Fits* this, 92 char* name, 93 int* colNum, 94 int* type, 95 long* repeat) { 96 97 int status = 0; 98 fits_get_colnum(this->file, CASESEN, name, colNum, &status); 99 if (status) { 100 101 psError(PS_ERR_IO, false, "* Fits: Unable to read col '%s'", name); 102 return false; 103 } 104 105 status = 0; 106 fits_get_eqcoltype(this->file, *colNum, type, repeat, NULL, &status); 107 if (status) { 108 109 psError(PS_ERR_IO, false, "* Fits: Unable to read type info for '%s'", name); 110 return false; 111 } 112 113 return true; 114 } 115 45 116 46 117 /** … … 52 123 if (fits_movnam_hdu(this->file, type, name, 0, &status)) { 53 124 54 psError(PS_ERR_IO, false, " Can't move to table extension named '%s'\n", name);125 psError(PS_ERR_IO, false, "* Fits: Can't move to table extension named '%s'\n", name); 55 126 } 56 127 … … 61 132 Moves to a certain header extension 62 133 */ 63 bool moveToHeader(Fits* this, char* name) {134 static bool moveToHeader(Fits* this, char* name) { 64 135 65 136 return moveToExtension(this, name, IMAGE_HDU); … … 69 140 Moves to a certain binary table extension 70 141 */ 71 bool moveToBinaryTable(Fits* this, char* name) {142 static bool moveToBinaryTable(Fits* this, char* name) { 72 143 73 144 return moveToExtension(this, name, BINARY_TBL); … … 75 146 76 147 /** 148 Counts the rows in the current table extension 149 */ 150 static bool countRows(Fits* this, long* count) { 151 152 int status = 0; 153 if (fits_get_num_rows(this->file, count, &status)) { 154 155 psError(PS_ERR_IO, false, "* Fits: Count not count rows in this table\n"); 156 return false; 157 } 158 159 return true; 160 } 161 162 /** 163 Moves to a certain binary table extension and counts rows within 164 */ 165 static bool moveToBinaryTableAndCountRows(Fits* this, char* name, long* count) { 166 167 if (!moveToExtension(this, name, BINARY_TBL)) return false; 168 return countRows(this, count); 169 } 170 171 /** 172 Deletes this file. 173 */ 174 static bool delete(Fits* this) { 175 176 if (remove(this->path) == -1) { 177 178 psError(PS_ERR_UNKNOWN, false, "* Fits: Unable to delete '%s'", this->path); 179 return false; 180 } 181 182 return true; 183 } 184 185 /** 186 Returns the file path. 187 */ 188 static char* getPath(Fits* this) { 189 190 return this->path; 191 } 192 193 /** 77 194 Returns the file pointer. 78 195 */ … … 83 200 84 201 /** 85 Constructor. Returns a new Fits object. 86 */ 87 Fits* new_Fits(char* path) { 88 89 Fits* this = (Fits*)calloc(1, sizeof(Fits)); 90 91 int status = 0; 92 if (fits_open_file(&this->file, path, READONLY, &status)) { 93 94 psError(PS_ERR_IO, false, "Unable to open FITS file here %s\n", path); 95 } 202 Deletes a bunch of rows from the current binary table 203 */ 204 static bool deleteRows(Fits* this, long *rowlist, long nrows) { 205 206 int status = 0; 207 fits_delete_rowlist(this->file, rowlist, nrows, &status); 208 if (status) { 209 210 psError(PS_ERR_IO, false, "* Fits: Unable to delet rows using rowlist \n"); 211 return false; 212 } 213 214 return true; 215 } 216 217 /** 218 Reads a column from the current binary table 219 */ 220 static bool readColumn( 221 Fits* this, 222 int datatype, 223 int colnum, 224 LONGLONG firstrow, 225 LONGLONG firstelem, 226 LONGLONG nelements, 227 void* coldata) { 228 229 int anynull = 0; 230 int status = 0; 231 232 if (datatype == TBYTE) { 233 234 int8_t nullval = -99; 235 fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status); 236 } 237 else if (datatype == TSHORT) { 238 239 int16_t nullval = -999; 240 fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status); 241 } 242 else if (datatype == TLONG || datatype == TLONGLONG) { 243 244 long nullval = -999; 245 fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status); 246 } 247 else if (datatype == TFLOAT) { 248 249 float nullval = -999.0; 250 fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status); 251 } 252 else if (datatype == TDOUBLE) { 253 254 double nullval = -999.0; 255 fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status); 256 } 257 else if (datatype == TSTRING) { 258 259 char nullval[20]; 260 strcpy(nullval, "null"); 261 fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status); 262 } 263 else { 264 265 psError(PS_ERR_IO, false, "* Fits: Don't support datatype '%d' yet\n", datatype); 266 return false; 267 } 268 269 if (status) { 270 271 psError(PS_ERR_IO, false, "* Fits: Unable to read column data from column %d\n", colnum); 272 return false; 273 274 } 275 276 return true; 277 } 278 279 /** 280 Reads a column from the current binary table providing column name 281 */ 282 static bool readColumnUsingName( 283 Fits* this, 284 int datatype, 285 char* colname, 286 LONGLONG firstrow, 287 LONGLONG firstelem, 288 LONGLONG nelements, 289 void* coldata) { 290 291 int colnum; 292 if (!getColumnNumber(this, colname, &colnum)) return false; 293 294 return readColumn(this, datatype, colnum, firstrow, firstelem, nelements, coldata); 295 } 296 297 /** 298 Writes a column to the current binary table 299 */ 300 static bool writeColumn( 301 Fits* this, 302 int datatype, 303 int colnum, 304 LONGLONG firstrow, 305 LONGLONG firstelem, 306 LONGLONG nelements, 307 void* coldata) { 308 309 int status = 0; 310 fits_write_col(this->file, datatype, colnum, firstrow, firstelem, nelements, coldata, &status); 311 if (status) { 312 313 psError(PS_ERR_IO, false, "* Fits: Unable to write column data for column %d\n", colnum); 314 return false; 315 316 } 317 318 return true; 319 } 320 321 /** 322 Creates a new binary table 323 */ 324 static bool createBinaryTable( 325 Fits* this, 326 LONGLONG nRows, 327 int nCols, 328 char *names[], 329 char *types[], 330 char *name) { 331 332 int status = 0; 333 fits_create_tbl(this->file, BINARY_TBL, nRows, nCols, names, types, NULL, name, &status); 334 335 if (status) { 336 337 psError(PS_ERR_IO,"* Fits: Unable to create table: '%s'", name); 338 return false; 339 } 340 341 342 return true; 343 } 344 345 /** 346 Initilization common to all constructors 347 */ 348 static void init(Fits* this) { 96 349 97 350 // method pointers 98 351 this->getFilePtr = getFilePtr; 352 this->getPath = getPath; 353 this->countRows = countRows; 354 this->getColumnMeta = getColumnMeta; 99 355 this->getColumnNumber = getColumnNumber; 356 this->getColumnVector = getColumnVector; 357 this->readColumn = readColumn; 358 this->readColumnUsingName = readColumnUsingName; 359 this->getHeaderKeyValue = getHeaderKeyValue; 100 360 this->moveToExtension = moveToExtension; 101 361 this->moveToHeader = moveToHeader; 102 362 this->moveToBinaryTable = moveToBinaryTable; 363 this->moveToBinaryTableAndCountRows = moveToBinaryTableAndCountRows; 364 this->deleteRows = deleteRows; 365 this->createBinaryTable = createBinaryTable; 366 this->writeColumn = writeColumn; 367 this->delete = delete; 103 368 this->destroy = destroy; 104 369 105 370 assert(this); 106 371 372 } 373 374 /** 375 Constructor. 376 377 Returns a new Fits object representing an existing FITS file. 378 379 */ 380 Fits* existing_Fits(char* path) { 381 382 Fits* this = (Fits*)calloc(1, sizeof(Fits)); 383 384 int status = 0; 385 strcpy(this->path, path); 386 387 if (fits_open_file(&this->file, this->path, READONLY, &status)) { 388 389 psError(PS_ERR_IO, false, "* Fits: Unable to open FITS file here %s\n", path); 390 this->file = NULL; 391 } 392 393 init(this); 394 107 395 return this; 108 396 } 109 397 110 398 /** 399 Constructor. 400 401 Returns a new Fits object representing a new FITS file. 402 */ 403 Fits* new_Fits(char* path) { 404 405 Fits* this = (Fits*)calloc(1, sizeof(Fits)); 406 407 int status = 0; 408 strcpy(this->path, path); 409 410 if (fits_create_file(&this->file, this->path, &status)) { 411 412 psError(PS_ERR_IO, false, "* Fits: Unable to create file here '%s'", path); 413 this->file = NULL; 414 } 415 416 init(this); 417 418 return this; 419 } 420 421 -
trunk/ippToPsps/src/Fits.h
r30861 r31010 15 15 16 16 /** 17 17 18 Class that encapsulates a FITS file, making an OO interface to the dreaded cfitsio 18 19 … … 21 22 22 23 // fields 23 fitsfile* file; 24 fitsfile* file; // cfitsio file pointer 25 char path[1000]; // FITS path 24 26 25 // methods27 // accessor methods 26 28 fitsfile* (*getFilePtr)(); 29 char* (*getPath)(); 30 bool (*countRows)(); 31 bool (*getColumnMeta)(); 27 32 bool (*getColumnNumber)(); 33 bool (*getColumnVector)(); 34 bool (*readColumn)(); 35 bool (*readColumnUsingName)(); 36 bool (*getHeaderKeyValue)(); 37 38 // mutators 28 39 bool (*moveToExtension)(); 29 40 bool (*moveToHeader)(); 30 41 bool (*moveToBinaryTable)(); 42 bool (*moveToBinaryTableAndCountRows)(); 43 bool (*createBinaryTable)(); 44 bool (*writeColumn)(); 45 bool (*deleteRows)(); 46 bool (*delete)(); 47 48 // destructor 31 49 void (*destroy)(); 32 50 33 51 } Fits; 34 52 53 // constructors 54 Fits* existing_Fits(char* path); 35 55 Fits* new_Fits(char* path); 36 56 -
trunk/ippToPsps/src/Makefile.am
r30147 r31010 31 31 Batch.c \ 32 32 Version.c \ 33 Fits.c \ 33 34 Config.c 34 35 … … 40 41 Batch.c \ 41 42 Version.c \ 43 Fits.c \ 42 44 Config.c 43 45 … … 49 51 Batch.c \ 50 52 Version.c \ 53 Fits.c \ 51 54 Config.c 52 55
Note:
See TracChangeset
for help on using the changeset viewer.
