96 dst = filepath_with_filter;
235 char errdescr[FLEN_STATUS+1];
238 fits_open_file(&fp, filepath_filter.
Data(), READONLY, &status);
239 if (status)
goto ERR;
243 fits_get_hdu_num(fp, &hdunum);
248 fits_get_hdu_type(fp, &hdutype, &status);
249 if (status)
goto ERR;
254 char keyname[FLEN_KEYWORD+1];
255 char keyvalue[FLEN_VALUE+1];
256 char comment[FLEN_COMMENT+1];
258 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
259 if (status)
goto ERR;
263 for (
int i = 1; i <= nkeys; i++) {
264 fits_read_keyn(fp, i, keyname, keyvalue, comment, &status);
265 if (status)
goto ERR;
275 for (
int i = 0; i < nkeys; i++) {
276 if (
fRecords[i].fKeyword ==
"EXTNAME") {
286 long *param_dimsizes;
289 fits_get_img_dim(fp, ¶m_ndims, &status);
290 if (status)
goto ERR;
291 if (param_ndims > 0) {
293 param_dimsizes =
new long[param_ndims];
294 fits_get_img_size(fp, param_ndims, param_dimsizes, &status);
296 delete [] param_dimsizes;
302 for (
int i = 0; i < param_ndims; i++) {
306 delete [] param_dimsizes;
310 long *firstpixel =
new long[param_ndims];
314 for (
int i = 0; i < param_ndims; i++) {
319 double *pixels =
new double[npixels];
321 fits_read_pix(fp, TDOUBLE, firstpixel, npixels,
322 (
void *) &nulval, (
void *) pixels, &anynul, &status);
325 delete [] firstpixel;
332 delete [] firstpixel;
347 fits_get_num_rows(fp, &table_rows, &status);
348 if (status)
goto ERR;
352 fits_get_num_cols(fp, &table_cols, &status);
353 if (status)
goto ERR;
364 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
365 while (status == COL_NOT_UNIQUE)
368 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
370 if (status != COL_NOT_FOUND)
goto ERR;
374 fCells =
new union Cell [table_rows * table_cols];
382 for (colnum = 0, cellindex = 0; colnum <
fNColumns; colnum++) {
383 fits_get_coltype(fp, colnum+1, &typecode, &repeat, &width, &status);
385 if (status)
goto ERR;
387 if ((typecode == TDOUBLE) || (typecode == TSHORT) || (typecode == TLONG)
388 || (typecode == TFLOAT) || (typecode == TLOGICAL) || (typecode == TBIT)
389 || (typecode == TBYTE) || (typecode == TSTRING)) {
393 if (typecode == TSTRING) {
396 fits_get_col_display_width(fp, colnum+1, &dispwidth, &status);
397 if (status)
goto ERR;
400 char *nulval = (
char*)
"";
404 if (dispwidth <= 0) {
408 array =
new char* [table_rows];
409 for (
long row = 0; row < table_rows; row++) {
410 array[row] =
new char[dispwidth+1];
414 fits_read_col(fp, TSTRING, colnum+1, 1, 1, table_rows, nulval, array, &anynul, &status);
416 for (
long row = 0; row < table_rows; row++) {
417 delete [] array[row];
425 for (
long row = 0; row < table_rows; row++) {
426 strlcpy(array[row],
"-",dispwidth+1);
432 for (
long row = 0; row < table_rows; row++) {
451 if (typecode == TLOGICAL) {
452 arrayl =
new char[table_rows * repeat];
453 fits_read_col(fp, TLOGICAL, colnum + 1, 1, 1, table_rows * repeat, &nulval, arrayl, &anynul,
460 array =
new double[table_rows * repeat];
461 fits_read_col(fp, TDOUBLE, colnum + 1, 1, 1, table_rows * repeat, &nulval, array, &anynul,
471 array =
new double[table_rows];
472 for (
long row = 0; row < table_rows; row++) {
480 if (typecode == TLOGICAL) {
481 for (
long row = 0; row < table_rows; row++) {
482 int temp = (
signed char)arrayl[row];
487 for (
long row = 0; row < table_rows; row++) {
492 }
else if (repeat > 1) {
494 if (typecode == TLOGICAL) {
495 for (
long row = 0; row < table_rows; row++) {
496 double *vec =
new double[repeat];
497 long offset = row * repeat;
498 for (
long component = 0; component < repeat; component++) {
499 int temp = (
signed char)arrayl[offset++];
500 vec[component] = (double)temp;
506 for (
long row = 0; row < table_rows; row++) {
507 double *vec =
new double[repeat];
508 long offset = row * repeat;
509 for (
long component = 0; component < repeat; component++) {
510 vec[component] = array[offset++];
519 Warning(
"LoadHDU",
"error opening FITS file. Column type %d is currently not supported", typecode);
523 if (hdutype == ASCII_TBL) {
532 fits_close_file(fp, &status);
536 fits_get_errstatus(status, errdescr);
537 Warning(
"LoadHDU",
"error opening FITS file. Details: %s", errdescr);
539 if (fp) fits_close_file(fp, &status);
590 char errdescr[FLEN_STATUS+1];
591 int hducount, extnum;
592 int hdutype = IMAGE_HDU;
594 char extname[FLEN_CARD]=
"PRIMARY";
595 int verbose = (opt[0] ? 1 : 0);
599 if (status)
goto ERR;
602 fits_get_num_hdus(fp, &hducount, &status);
603 if (status)
goto ERR;
604 printf(
"Total: %d HDUs\n", hducount);
609 fits_get_hdu_type(fp, &hdutype, &status);
610 if (status)
goto ERR;
612 if (hdutype == IMAGE_HDU) {
614 }
else if (hdutype == ASCII_TBL) {
615 exttype=
"ASCII TABLE";
617 exttype=
"BINARY TABLE";
622 char keyname[FLEN_KEYWORD+1];
623 char keyvalue[FLEN_VALUE+1];
624 char comment[FLEN_COMMENT+1];
626 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
627 if (status)
goto ERR;
631 for (
int i = 1; i <= nkeys; i++) {
632 fits_read_keyn(fp, i, keyname, keyvalue, comment, &status);
639 records[i-1].
fValue = keyvalue;
642 if (strcmp(keyname,
"EXTNAME") == 0) {
644 strlcpy(extname, keyvalue,FLEN_CARD);
649 printf(
" [%d] %s (%s)\n", extnum, exttype, extname);
653 for (
int i = 0; i < nkeys; i++) {
655 printf(
" %-10s = %s / %s\n", records[i].fKeyword.Data(), records[i].
fValue.
Data(), records[i].
fComment.
Data());
657 printf(
" %-10s = %s\n", records[i].fKeyword.Data(), records[i].
fValue.
Data());
668 fits_movrel_hdu(fp, 1, &hdutype, &status);
669 if (status)
goto ERR;
674 fits_close_file(fp, &status);
678 fits_get_errstatus(status, errdescr);
679 Warning(
"PrintFileMetadata",
"error opening FITS file. Details: %s", errdescr);
681 if (fp) fits_close_file(fp, &status);
690 Warning(
"PrintColumnInfo",
"this is not a table HDU.");
707 Warning(
"PrintColumnInfo",
"this is not a table HDU.");
718 while(printed_chars--) {
727 printf(
"%-10s",
fCells[col * fNRows + row].fString);
729 printed_chars = printf(
"%.2lg",
fCells[col * fNRows + row].fRealNumber);
731 while (printed_chars < 0) {
737 if (col <= fNColumns - 1) printf(
"| ");
755 if ((opt[0] ==
'F') || (opt[0] ==
'f')) {
757 }
else if ((opt[0] ==
'T') || (opt[0] ==
't')) {
778 Warning(
"ReadAsImage",
"this is not an image HDU.");
784 Warning(
"ReadAsImage",
"could not convert image HDU to image because it has %d dimensions.",
fSizes->
GetSize());
799 Warning(
"ReadAsImage",
"layer out of bounds.");
807 Int_t offset = layer * pixels_per_layer;
809 for (i = 0; i < pixels_per_layer; i++) {
812 if (pixvalue > maxval) {
816 if ((i == 0) || (pixvalue < minval)) {
828 if (maxval == minval) {
830 for (i = 0; i < pixels_per_layer; i++) {
831 layer_pixels->
SetAt(255.0, i);
834 Double_t factor = 255.0 / (maxval-minval);
835 for (i = 0; i < pixels_per_layer; i++) {
837 layer_pixels->
SetAt(factor * (pixvalue-minval), i) ;
844 for (i = 0; i < 256; i++) {
872 Warning(
"Draw",
"cannot draw. This is not an image HDU.");
882 ctitle.Form(
"%d x %d", width, height);
883 new TCanvas(cname, ctitle, width, height);
899 Warning(
"ReadAsMatrix",
"this is not an image HDU.");
904 Warning(
"ReadAsMatrix",
"could not convert image HDU to image because it has %d dimensions.",
fSizes->
GetSize());
911 Warning(
"ReadAsMatrix",
"layer out of bounds.");
925 offset = layer * pixels_per_layer;
927 double *layer_pixels =
new double[pixels_per_layer];
929 if ((opt[0] ==
'S') || (opt[0] ==
's')) {
932 Double_t factor, maxval=0, minval=0;
934 for (i = 0; i < pixels_per_layer; i++) {
937 if (pixvalue > maxval) {
941 if ((i == 0) || (pixvalue < minval)) {
946 if (maxval == minval) {
948 for (i = 0; i < pixels_per_layer; i++) {
949 layer_pixels[i] = 1.0;
952 factor = 1.0 / (maxval-minval);
955 for (i = 0; i < pixels_per_layer; i++) {
956 layer_pixels[i] = factor * (
fPixels->
GetAt(offset + i) - minval);
964 for (i = 0; i < pixels_per_layer; i++) {
971 memcpy(mat->
GetMatrixArray(), layer_pixels, pixels_per_layer*
sizeof(double));
974 delete [] layer_pixels;
992 Warning(
"ReadAsHistogram",
"this is not an image HDU.");
999 Warning(
"ReadAsHistogram",
"could not convert image HDU to histogram because it has %d dimensions.",
fSizes->
GetSize());
1010 for (x = 0; x < Nx; x++) {
1012 if (nentries < 0) nentries = 0;
1013 h->
Fill(x, nentries);
1026 for (y = 0; y < Ny; y++) {
1028 for (x = 0; x < Nx; x++) {
1030 if (nentries < 0) nentries = 0;
1031 h->
Fill(x,y, nentries);
1044 TH3D *
h =
new TH3D(
"",
"",
Int_t(Nx), 0, Nx-1,
Int_t(Ny), 0, Ny-1,
Int_t(Nz), 0, Nz-1);
1047 for (z = 0; z < Nz; z++) {
1048 UInt_t offset1 = z * Nx * Ny;
1049 for (y = 0; y < Ny; y++) {
1051 for (x = 0; x < Nx; x++) {
1053 if (nentries < 0) nentries = 0;
1054 h->
Fill(x, y, z, nentries);
1071 Warning(
"GetArrayRow",
"this is not an image HDU.");
1076 Warning(
"GetArrayRow",
"could not get row from HDU because it has %d dimensions.",
fSizes->
GetSize());
1087 Warning(
"GetArrayRow",
"index out of bounds.");
1092 double *
v =
new double[W];
1094 for (i = 0; i < W; i++) {
1111 Warning(
"GetArrayColumn",
"this is not an image HDU.");
1116 Warning(
"GetArrayColumn",
"could not get row from HDU because it has %d dimensions.",
fSizes->
GetSize());
1127 Warning(
"GetArrayColumn",
"index out of bounds.");
1131 double *
v =
new double[
H];
1133 for (i = 0; i <
H; i++) {
1151 for (colnum = 0; colnum <
fNColumns; colnum++) {
1165 Warning(
"GetTabStringColumn",
"this is not a table HDU.");
1169 if ((colnum < 0) || (colnum >=
fNColumns)) {
1170 Warning(
"GetTabStringColumn",
"column index out of bounds.");
1175 Warning(
"GetTabStringColumn",
"attempting to read a column that is not of type 'kString'.");
1195 Warning(
"GetTabStringColumn",
"this is not a table HDU.");
1203 Warning(
"GetTabStringColumn",
"column not found.");
1208 Warning(
"GetTabStringColumn",
"attempting to read a column that is not of type 'kString'.");
1228 Warning(
"GetTabRealVectorColumn",
"this is not a table HDU.");
1232 if ((colnum < 0) || (colnum >=
fNColumns)) {
1233 Warning(
"GetTabRealVectorColumn",
"column index out of bounds.");
1238 Warning(
"GetTabRealVectorColumn",
"attempting to read a column that is not of type 'kRealNumber'.");
1241 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded vectors, not real scalars. Use GetTabRealVectorCells() instead.");
1254 res->
Use(fNRows, arr);
1265 Warning(
"GetTabRealVectorColumn",
"this is not a table HDU.");
1272 Warning(
"GetTabRealVectorColumn",
"column not found.");
1277 Warning(
"GetTabRealVectorColumn",
"attempting to read a column that is not of type 'kRealNumber'.");
1280 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded vectors, not real scalars. Use GetTabRealVectorCells() instead.");
1293 res->
Use(fNRows, arr);
1316 Warning(
"Change",
"error changing HDU. Restoring the previous one...");
1322 Warning(
"Change",
"could not restore previous HDU. This object is no longer reliable!!");
1338 tmppath.
Form(
"[%d]", extension_number);
1349 Warning(
"GetTabRealVectorCells",
"this is not a table HDU.");
1353 if ((colnum < 0) || (colnum >=
fNColumns)) {
1354 Warning(
"GetTabRealVectorCells",
"column index out of bounds.");
1359 Warning(
"GetTabRealVectorCells",
"attempting to read a column that is not of type 'kRealNumber'.");
1370 v->
Use(dim,
fCells[offset + row].fRealVector);
1387 Warning(
"GetTabRealVectorCells",
"this is not a table HDU.");
1394 Warning(
"GetTabRealVectorCells",
"column not found.");
1407 Warning(
"GetTabRealVectorCell",
"this is not a table HDU.");
1411 if ((colnum < 0) || (colnum >=
fNColumns)) {
1412 Warning(
"GetTabRealVectorCell",
"column index out of bounds.");
1416 if ((rownum < 0) || (rownum >=
fNRows)) {
1417 Warning(
"GetTabRealVectorCell",
"row index out of bounds.");
1422 Warning(
"GetTabRealVectorCell",
"attempting to read a column that is not of type 'kRealNumber'.");
1438 Warning(
"GetTabRealVectorCell",
"this is not a table HDU.");
1445 Warning(
"GetTabRealVectorCell",
"column not found.");
1461 Error(
"GetColumnName",
"this is not a table HDU.");
1465 if ((colnum < 0) || (colnum >=
fNColumns)) {
1466 Error(
"GetColumnName",
"column index out of bounds.");
virtual const char * GetName() const
Returns name of object.
Double_t * fPoints
[fNumPoints] value of each anchor point [0..1]
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void SetAt(Double_t v, Int_t i)
Int_t fNRows
Number of rows (when fType == kTableHDU)
TString fExtensionName
Extension Name.
Collectable string class.
TFITSHDU(const char *filepath_with_filter)
TFITSHDU constructor from file path with HDU selection filter.
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...
Int_t fNRecords
Number of records.
virtual const Element * GetMatrixArray() const
TArrayI * fSizes
Image sizes in each dimension (when fType == kImageHDU)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TMatrixD * ReadAsMatrix(Int_t layer=0, Option_t *opt="")
Read image HDU as a matrix.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
An abstract interface to image processing library.
void _release_resources()
Release internal resources.
Bool_t LoadHDU(TString &filepath_filter)
Load HDU from fits file satisfying the specified filter.
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Array of integers (32 bits per element).
UShort_t * fColorRed
[fNumPoints] red color at each anchor point
void Print(const Option_t *opt="") const
Print metadata.
~TFITSHDU()
TFITSHDU destructor.
struct HDURecord * GetRecord(const char *keyword)
Get record by keyword.
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
FITS file interface class.
void _initialize_me()
Do some initializations.
void PrintFileMetadata(const Option_t *opt="") const
Print HDU's parent file's metadata.
TVectorD * GetArrayRow(UInt_t row)
Get a row from the image HDU when it's a 2D array.
enum EHDUTypes fType
HDU type.
Double_t GetAt(Int_t i) const
TVectorT< Double_t > TVectorD
TObjArray * GetTabStringColumn(Int_t colnum)
Get a string-typed column from a table HDU given its column index (>=0).
TH1 * ReadAsHistogram()
Read image HDU as a histogram.
TMatrixT< Double_t > TMatrixD
THist< 3, double, THistStatContent, THistStatUncertainty > TH3D
Bool_t Change(const char *filter)
Change to another HDU given by "filter".
void PrintColumnInfo(const Option_t *) const
Print column information.
3-D histogram with a double per channel (see TH1 documentation)}
UShort_t * fColorAlpha
[fNumPoints] alpha at each anchor point
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Int_t Fill(Double_t)
Invalid Fill method.
void PrintHDUMetadata(const Option_t *opt="") const
Print records.
UShort_t * fColorBlue
[fNumPoints] blue color at each anchor point
1-D histogram with a double per channel (see TH1 documentation)}
TArrayD * fPixels
Image pixels (when fType == kImageHDU)
void SetAt(Double_t v, Int_t i)
TVectorD * GetTabRealVectorColumn(Int_t colnum)
Get a real number-typed column from a table HDU given its column index (>=0).
Int_t fNumber
HDU number (1=PRIMARY)
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
A class to define a conversion from pixel values to pixel color.
Array of doubles (64 bits per element).
TString fBaseFilePath
Path to HDU's file excluding filter.
TVectorD * GetTabRealVectorCell(Int_t rownum, Int_t colnum)
Get a real vector embedded in a cell given by (row>=0, column>=0)
TString fFilePath
Path to HDU's file including filter.
you should not use this method at all Int_t Int_t z
UShort_t * fColorGreen
[fNumPoints] green color at each anchor point
TVectorD * GetArrayColumn(UInt_t col)
Get a column from the image HDU when it's a 2D array.
union Cell * fCells
Table cells (when fType == kTableHDU).
TString & GetKeywordValue(const char *keyword)
Get the value of a given keyword. Return "" if not found.
static void CleanFilePath(const char *filepath_with_filter, TString &dst)
Clean path from possible filter and put the result in 'dst'.
struct HDURecord * fRecords
HDU metadata records.
Double_t GetAt(Int_t i) const
void PrintFullTable(const Option_t *) const
Print full table contents.
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
const TString & GetColumnName(Int_t colnum)
Get the name of a column given its index (column>=0).
static TImage * Create()
Create an image.
Int_t Fill(Double_t)
Invalid Fill method.
struct Column * fColumnsInfo
Information about columns (when fType == kTableHDU)
Int_t fNColumns
Number of columns (when fType == kTableHDU)
TObjArray * GetTabRealVectorCells(Int_t colnum)
Get a collection of real vectors embedded in cells along a given column from a table HDU...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
TImage * ReadAsImage(Int_t layer=0, TImagePalette *pal=0)
Read image HDU as a displayable image.
Int_t GetColumnNumber(const char *colname)
Get column number given its name.
2-D histogram with a double per channel (see TH1 documentation)}
const char * Data() const