96 dst = filepath_with_filter;
241 char errdescr[FLEN_STATUS+1];
244 fits_open_file(&fp, filepath_filter.
Data(), READONLY, &status);
245 if (status)
goto ERR;
249 fits_get_hdu_num(fp, &hdunum);
254 fits_get_hdu_type(fp, &hdutype, &status);
255 if (status)
goto ERR;
260 char keyname[FLEN_KEYWORD+1];
261 char keyvalue[FLEN_VALUE+1];
264 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
265 if (status)
goto ERR;
269 for (
int i = 1; i <= nkeys; i++) {
270 fits_read_keyn(fp, i, keyname, keyvalue,
comment, &status);
271 if (status)
goto ERR;
281 for (
int i = 0; i < nkeys; i++) {
282 if (
fRecords[i].fKeyword ==
"EXTNAME") {
290 Info(
"LoadHDU",
"The selected HDU contains an Image Extension");
293 long *param_dimsizes;
296 fits_get_img_dim(fp, ¶m_ndims, &status);
297 if (status)
goto ERR;
298 if (param_ndims > 0) {
300 param_dimsizes =
new long[param_ndims];
301 fits_get_img_size(fp, param_ndims, param_dimsizes, &status);
303 delete [] param_dimsizes;
309 for (
int i = 0; i < param_ndims; i++) {
313 delete [] param_dimsizes;
317 long *firstpixel =
new long[param_ndims];
321 for (
int i = 0; i < param_ndims; i++) {
326 double *pixels =
new double[npixels];
328 fits_read_pix(fp, TDOUBLE, firstpixel, npixels,
329 (
void *) &nulval, (
void *) pixels, &anynul, &status);
332 delete [] firstpixel;
339 delete [] firstpixel;
348 Info(
"LoadHDU",
"The selected HDU contains a Table Extension");
354 fits_get_num_rows(fp, &table_rows, &status);
355 if (status)
goto ERR;
359 fits_get_num_cols(fp, &table_cols, &status);
360 if (status)
goto ERR;
371 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
372 while (status == COL_NOT_UNIQUE)
375 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
377 if (status != COL_NOT_FOUND)
goto ERR;
381 fCells =
new union Cell [table_rows * table_cols];
389 for (colnum = 0, cellindex = 0; colnum <
fNColumns; colnum++) {
390 fits_get_coltype(fp, colnum+1, &typecode, &repeat, &
width, &status);
392 if (status)
goto ERR;
394 if ((typecode == TDOUBLE) || (typecode == TSHORT) || (typecode == TLONG)
395 || (typecode == TFLOAT) || (typecode == TLOGICAL) || (typecode == TBIT)
396 || (typecode == TBYTE) || (typecode == TSTRING)) {
398 if (typecode == TSTRING) {
403 fits_get_col_display_width(fp, colnum+1, &dispwidth, &status);
404 if (status)
goto ERR;
407 char *nulval = (
char*)
"";
411 if (dispwidth <= 0) {
415 array =
new char* [table_rows];
416 for (
long row = 0; row < table_rows; row++) {
417 array[row] =
new char[dispwidth+1];
421 fits_read_col(fp, TSTRING, colnum+1, 1, 1, table_rows, nulval, array, &anynul, &status);
423 for (
long row = 0; row < table_rows; row++) {
424 delete [] array[row];
432 for (
long row = 0; row < table_rows; row++) {
433 strlcpy(array[row],
"-",dispwidth+1);
438 for (
long row = 0; row < table_rows; row++) {
457 if (typecode == TLOGICAL) {
458 arrayl =
new char[table_rows * repeat];
459 fits_read_col(fp, TLOGICAL, colnum + 1, 1, 1, table_rows * repeat, &nulval, arrayl, &anynul,
466 array =
new double[table_rows * repeat];
467 fits_read_col(fp, TDOUBLE, colnum + 1, 1, 1, table_rows * repeat, &nulval, array, &anynul,
477 array =
new double[table_rows];
478 for (
long row = 0; row < table_rows; row++) {
487 if (typecode == TLOGICAL) {
488 for (
long row = 0; row < table_rows; row++) {
489 int temp = (
signed char)arrayl[row];
494 for (
long row = 0; row < table_rows; row++) {
499 }
else if (repeat > 1) {
502 if (typecode == TLOGICAL) {
503 for (
long row = 0; row < table_rows; row++) {
504 double *vec =
new double[repeat];
505 long offset = row * repeat;
506 for (
long component = 0; component < repeat; component++) {
507 int temp = (
signed char)arrayl[offset++];
508 vec[component] = (
double)temp;
514 for (
long row = 0; row < table_rows; row++) {
515 double *vec =
new double[repeat];
516 long offset = row * repeat;
517 for (
long component = 0; component < repeat; component++) {
518 vec[component] = array[offset++];
526 }
else if (typecode < 1) {
539 for (
long row = 0; row < table_rows; row++) {
543 fits_read_descript(fp, colnum+1, row+1, &repeat_row, &offset, &status);
549 for (
long row = 0; row < table_rows; row++) {
568 std::vector<short> data;
570 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval, data.data(), &anynul, &status);
571 for (
int i = 0; i < size; i++)
572 vec->
SetAt(data[i], i);
573 }
else if (abstype == 41) {
574 std::vector<int> data;
576 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval, data.data(), &anynul, &status);
577 for (
int i = 0; i < size; i++)
578 vec->
SetAt(data[i], i);
579 }
else if (abstype == 42) {
580 std::vector<float> data;
582 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval, data.data(), &anynul, &status);
583 for (
int i = 0; i < size; i++)
584 vec->
SetAt(data[i], i);
585 }
else if (abstype == 82) {
586 std::vector<double> data;
588 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval, data.data(), &anynul, &status);
589 for (
int i = 0; i < size; i++)
590 vec->
SetAt(data[i], i);
592 Error(
"LoadHDU",
"The variable-length array type in column %d is unknown", colnum + 1);
598 Warning(
"LoadHDU",
"error opening FITS file. Column type %d is currently not supported", typecode);
602 if (hdutype == ASCII_TBL) {
611 fits_close_file(fp, &status);
615 fits_get_errstatus(status, errdescr);
616 Warning(
"LoadHDU",
"error opening FITS file. Details: %s", errdescr);
618 if (fp) fits_close_file(fp, &status);
669 char errdescr[FLEN_STATUS+1];
670 int hducount, extnum;
671 int hdutype = IMAGE_HDU;
673 char extname[FLEN_CARD]=
"PRIMARY";
674 int verbose = (opt[0] ? 1 : 0);
678 if (status)
goto ERR;
681 fits_get_num_hdus(fp, &hducount, &status);
682 if (status)
goto ERR;
683 printf(
"Total: %d HDUs\n", hducount);
688 fits_get_hdu_type(fp, &hdutype, &status);
689 if (status)
goto ERR;
691 if (hdutype == IMAGE_HDU) {
693 }
else if (hdutype == ASCII_TBL) {
694 exttype=
"ASCII TABLE";
696 exttype=
"BINARY TABLE";
701 char keyname[FLEN_KEYWORD+1];
702 char keyvalue[FLEN_VALUE+1];
705 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
706 if (status)
goto ERR;
710 for (
int i = 1; i <= nkeys; i++) {
711 fits_read_keyn(fp, i, keyname, keyvalue,
comment, &status);
718 records[i-1].
fValue = keyvalue;
721 if (strcmp(keyname,
"EXTNAME") == 0) {
723 strlcpy(extname, keyvalue,FLEN_CARD);
728 printf(
" [%d] %s (%s)\n", extnum, exttype, extname);
732 for (
int i = 0; i < nkeys; i++) {
734 printf(
" %-10s = %s / %s\n", records[i].fKeyword.Data(), records[i].
fValue.
Data(), records[i].
fComment.
Data());
736 printf(
" %-10s = %s\n", records[i].fKeyword.Data(), records[i].
fValue.
Data());
747 fits_movrel_hdu(fp, 1, &hdutype, &status);
748 if (status)
goto ERR;
753 fits_close_file(fp, &status);
757 fits_get_errstatus(status, errdescr);
758 Warning(
"PrintFileMetadata",
"error opening FITS file. Details: %s", errdescr);
760 if (fp) fits_close_file(fp, &status);
769 Warning(
"PrintColumnInfo",
"this is not a table HDU.");
799 Warning(
"PrintColumnInfo",
"this is not a table HDU.");
807 Warning(
"PrintColumnInfo",
"The table contains column with fixed-length arrays and cannot be flattened for printing.");
811 Warning(
"PrintColumnInfo",
"The table contains column with variable-length arrays and cannot be flattened for printing.");
823 while(printed_chars--) {
834 printed_chars = printf(
"%.2lg",
fCells[col *
fNRows + row].fRealNumber);
836 while (printed_chars < 0) {
860 if ((opt[0] ==
'F') || (opt[0] ==
'f')) {
862 }
else if ((opt[0] ==
'T') || (opt[0] ==
't')) {
883 Warning(
"ReadAsImage",
"this is not an image HDU.");
888 Warning(
"ReadAsImage",
"could not convert image HDU to image because it has %d dimensions.",
fSizes->
GetSize());
903 Warning(
"ReadAsImage",
"layer out of bounds.");
911 Int_t offset = layer * pixels_per_layer;
913 for (i = 0; i < pixels_per_layer; i++) {
916 if (pixvalue > maxval) {
920 if ((i == 0) || (pixvalue < minval)) {
932 if (maxval == minval) {
934 for (i = 0; i < pixels_per_layer; i++) {
935 layer_pixels->
SetAt(255.0, i);
938 Double_t factor = 255.0 / (maxval-minval);
939 for (i = 0; i < pixels_per_layer; i++) {
941 layer_pixels->
SetAt(factor * (pixvalue-minval), i) ;
948 for (i = 0; i < 256; i++) {
976 Warning(
"Draw",
"cannot draw. This is not an image HDU.");
1003 Warning(
"ReadAsMatrix",
"this is not an image HDU.");
1008 Warning(
"ReadAsMatrix",
"could not convert image HDU to image because it has %d dimensions.",
fSizes->
GetSize());
1015 Warning(
"ReadAsMatrix",
"layer out of bounds.");
1029 offset = layer * pixels_per_layer;
1031 double *layer_pixels =
new double[pixels_per_layer];
1033 if ((opt[0] ==
'S') || (opt[0] ==
's')) {
1036 Double_t factor, maxval=0, minval=0;
1038 for (i = 0; i < pixels_per_layer; i++) {
1041 if (pixvalue > maxval) {
1045 if ((i == 0) || (pixvalue < minval)) {
1050 if (maxval == minval) {
1052 for (i = 0; i < pixels_per_layer; i++) {
1053 layer_pixels[i] = 1.0;
1056 factor = 1.0 / (maxval-minval);
1059 for (i = 0; i < pixels_per_layer; i++) {
1060 layer_pixels[i] = factor * (
fPixels->
GetAt(offset + i) - minval);
1068 for (i = 0; i < pixels_per_layer; i++) {
1075 memcpy(mat->
GetMatrixArray(), layer_pixels, pixels_per_layer*
sizeof(
double));
1078 delete [] layer_pixels;
1096 Warning(
"ReadAsHistogram",
"this is not an image HDU.");
1103 Warning(
"ReadAsHistogram",
"could not convert image HDU to histogram because it has %d dimensions.",
fSizes->
GetSize());
1114 for (
x = 0;
x < Nx;
x++) {
1130 for (
y = 0;
y < Ny;
y++) {
1132 for (
x = 0;
x < Nx;
x++) {
1148 TH3D *
h =
new TH3D(
"",
"",
Int_t(Nx), 0, Nx-1,
Int_t(Ny), 0, Ny-1,
Int_t(Nz), 0, Nz-1);
1151 for (z = 0; z < Nz; z++) {
1152 UInt_t offset1 = z * Nx * Ny;
1153 for (
y = 0;
y < Ny;
y++) {
1155 for (
x = 0;
x < Nx;
x++) {
1175 Warning(
"GetArrayRow",
"this is not an image HDU.");
1180 Warning(
"GetArrayRow",
"could not get row from HDU because it has %d dimensions.",
fSizes->
GetSize());
1191 Warning(
"GetArrayRow",
"index out of bounds.");
1196 double *
v =
new double[W];
1198 for (i = 0; i < W; i++) {
1215 Warning(
"GetArrayColumn",
"this is not an image HDU.");
1220 Warning(
"GetArrayColumn",
"could not get row from HDU because it has %d dimensions.",
fSizes->
GetSize());
1231 Warning(
"GetArrayColumn",
"index out of bounds.");
1235 double *
v =
new double[
H];
1237 for (i = 0; i <
H; i++) {
1255 for (colnum = 0; colnum <
fNColumns; colnum++) {
1269 Warning(
"GetTabStringColumn",
"this is not a table HDU.");
1273 if ((colnum < 0) || (colnum >=
fNColumns)) {
1274 Warning(
"GetTabStringColumn",
"column index out of bounds.");
1279 Warning(
"GetTabStringColumn",
"attempting to read a column that is not of type 'kString'.");
1299 Warning(
"GetTabStringColumn",
"this is not a table HDU.");
1307 Warning(
"GetTabStringColumn",
"column not found.");
1312 Warning(
"GetTabStringColumn",
"attempting to read a column that is not of type 'kString'.");
1332 Warning(
"GetTabRealVectorColumn",
"this is not a table HDU.");
1336 if ((colnum < 0) || (colnum >=
fNColumns)) {
1337 Warning(
"GetTabRealVectorColumn",
"column index out of bounds.");
1342 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded fixed-length arrays");
1343 Info(
"GetTabRealVectorColumn",
"Use GetTabRealVectorCells() or GetTabRealVectorCell() instead.");
1346 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded variable-length arrays");
1347 Info(
"GetTabRealVectorColumn",
"Use GetTabVarLengthCell() instead.");
1371 Warning(
"GetTabRealVectorColumn",
"this is not a table HDU.");
1378 Warning(
"GetTabRealVectorColumn",
"column not found.");
1383 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded fixed-length arrays");
1384 Info(
"GetTabRealVectorColumn",
"Use GetTabRealVectorCells() or GetTabRealVectorCell() instead.");
1387 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded variable-length arrays");
1388 Info(
"GetTabRealVectorColumn",
"Use GetTabVarLengthCell() instead.");
1424 Warning(
"Change",
"error changing HDU. Restoring the previous one...");
1430 Warning(
"Change",
"could not restore previous HDU. This object is no longer reliable!!");
1446 tmppath.
Form(
"[%d]", extension_number);
1457 Warning(
"GetTabRealVectorCells",
"this is not a table HDU.");
1461 if ((colnum < 0) || (colnum >=
fNColumns)) {
1462 Warning(
"GetTabRealVectorCells",
"column index out of bounds.");
1467 Warning(
"GetTabRealVectorCells",
"attempting to read a column whose cells have embedded variable-length arrays");
1468 Info(
"GetTabRealVectorCells",
"Use GetTabVarLengthCell() instead.");
1479 v->Use(dim,
fCells[offset + row].fRealArray);
1496 Warning(
"GetTabRealVectorCells",
"this is not a table HDU.");
1503 Warning(
"GetTabRealVectorCells",
"column not found.");
1516 Warning(
"GetTabRealVectorCell",
"this is not a table HDU.");
1520 if ((colnum < 0) || (colnum >=
fNColumns)) {
1521 Warning(
"GetTabRealVectorCell",
"column index out of bounds.");
1525 if ((rownum < 0) || (rownum >=
fNRows)) {
1526 Warning(
"GetTabRealVectorCell",
"row index out of bounds.");
1531 Warning(
"GetTabRealVectorCells",
"attempting to read a column whose cells have embedded variable-length arrays");
1532 Info(
"GetTabRealVectorCells",
"Use GetTabVarLengthCell() instead.");
1547 Warning(
"GetTabRealVectorCell",
"this is not a table HDU.");
1554 Warning(
"GetTabRealVectorCell",
"column not found.");
1569 Error(
"GetColumnName",
"this is not a table HDU.");
1573 if ((colnum < 0) || (colnum >=
fNColumns)) {
1574 Error(
"GetColumnName",
"column index out of bounds.");
1586 Warning(
"GetTabVarLengthVectorCell",
"this is not a table HDU.");
1590 if ((colnum < 0) || (colnum >=
fNColumns)) {
1591 Warning(
"GetTabVarLengthVectorCell",
"column index out of bounds.");
1595 if ((rownum < 0) || (rownum >=
fNRows)) {
1596 Warning(
"GetTabVarLengthVectorCell",
"row index out of bounds.");
1609 Warning(
"GetTabVarLengthVectorCell",
"this is not a table HDU.");
1616 Warning(
"GetTabVarLengthVectorCell",
"column not found.");
include TDocParser_001 C image html pict1_TDocParser_001 png width
TMatrixT< Double_t > TMatrixD
TVectorT< Double_t > TVectorD
Array of doubles (64 bits per element).
void SetAt(Double_t v, Int_t i)
Double_t GetAt(Int_t i) const
Array of integers (32 bits per element).
void SetAt(Double_t v, Int_t i)
Double_t GetAt(Int_t i) const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
FITS file interface class.
union Cell * fCells
Table cells (when fType == kTableHDU).
void PrintColumnInfo(const Option_t *) const
Print column information.
void _initialize_me()
Do some initializations.
void Draw(Option_t *opt="")
If the HDU is an image, draw the first layer of the primary array To set a title to the canvas,...
void PrintFullTable(const Option_t *) const
Print full table contents.
TString & GetKeywordValue(const char *keyword)
Get the value of a given keyword. Return "" if not found.
Int_t fNRows
Number of rows (when fType == kTableHDU)
const TString & GetColumnName(Int_t colnum)
Get the name of a column given its index (column>=0).
Int_t fNRecords
Number of records.
TString fFilePath
Path to HDU's file including filter.
struct Column * fColumnsInfo
Information about columns (when fType == kTableHDU)
TFITSHDU(const char *filepath_with_filter)
TFITSHDU constructor from file path with HDU selection filter.
Int_t fNColumns
Number of columns (when fType == kTableHDU)
TImage * ReadAsImage(Int_t layer=0, TImagePalette *pal=0)
Read image HDU as a displayable image.
TVectorD * GetTabRealVectorColumn(Int_t colnum)
Get a real number-typed column from a table HDU given its column index (>=0).
TArrayI * fSizes
Image sizes in each dimension (when fType == kImageHDU)
Bool_t Change(const char *filter)
Change to another HDU given by "filter".
TMatrixD * ReadAsMatrix(Int_t layer=0, Option_t *opt="")
Read image HDU as a matrix.
Int_t fNumber
HDU number (1=PRIMARY)
void PrintHDUMetadata(const Option_t *opt="") const
Print records.
~TFITSHDU()
TFITSHDU destructor.
struct HDURecord * fRecords
HDU metadata records.
TVectorD * GetArrayRow(UInt_t row)
Get a row from the image HDU when it's a 2D array.
void _release_resources()
Release internal resources.
void PrintFileMetadata(const Option_t *opt="") const
Print HDU's parent file's metadata.
static void CleanFilePath(const char *filepath_with_filter, TString &dst)
Clean path from possible filter and put the result in 'dst'.
struct HDURecord * GetRecord(const char *keyword)
Get record by keyword.
void Print(const Option_t *opt="") const
Print metadata.
TObjArray * GetTabStringColumn(Int_t colnum)
Get a string-typed column from a table HDU given its column index (>=0).
TString fBaseFilePath
Path to HDU's file excluding filter.
TH1 * ReadAsHistogram()
Read image HDU as a histogram.
TObjArray * GetTabRealVectorCells(Int_t colnum)
Get a collection of real vectors embedded in cells along a given column from a table HDU....
TArrayD * fPixels
Image pixels (when fType == kImageHDU)
TVectorD * GetArrayColumn(UInt_t col)
Get a column from the image HDU when it's a 2D array.
enum EHDUTypes fType
HDU type.
TVectorD * GetTabRealVectorCell(Int_t rownum, Int_t colnum)
Get a real array (with fixed or variable-length) embedded in a cell given by (row>=0,...
Bool_t LoadHDU(TString &filepath_filter)
Load HDU from fits file satisfying the specified filter.
TString fExtensionName
Extension Name.
TArrayD * GetTabVarLengthVectorCell(Int_t rownum, Int_t colnum)
Get the variable-length array contained in a cell given by (row>=0, column name)
Int_t GetColumnNumber(const char *colname)
Get column number given its name.
1-D histogram with a double per channel (see TH1 documentation)}
2-D histogram with a double per channel (see TH1 documentation)}
3-D histogram with a double per channel (see TH1 documentation)}
A class to define a conversion from pixel values to pixel color.
UShort_t * fColorRed
[fNumPoints] red color at each anchor point
Double_t * fPoints
[fNumPoints] value of each anchor point [0..1]
UShort_t * fColorGreen
[fNumPoints] green color at each anchor point
UShort_t * fColorBlue
[fNumPoints] blue color at each anchor point
UShort_t * fColorAlpha
[fNumPoints] alpha at each anchor point
An abstract interface to image processing library.
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
static TImage * Create()
Create an image.
virtual const Element * GetMatrixArray() const
virtual const char * GetName() const
Returns name of object.
Collectable string class.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
const char * Data() const
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
std::vector< int > fRowStart
std::vector< int > fVarLengths