95 dst = filepath_with_filter;
234 char errdescr[FLEN_STATUS+1];
237 fits_open_file(&fp, filepath_filter.
Data(), READONLY, &status);
238 if (status)
goto ERR;
242 fits_get_hdu_num(fp, &hdunum);
247 fits_get_hdu_type(fp, &hdutype, &status);
248 if (status)
goto ERR;
253 char keyname[FLEN_KEYWORD+1];
254 char keyvalue[FLEN_VALUE+1];
255 char comment[FLEN_COMMENT+1];
257 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
258 if (status)
goto ERR;
262 for (
int i = 1; i <= nkeys; i++) {
263 fits_read_keyn(fp, i, keyname, keyvalue, comment, &status);
264 if (status)
goto ERR;
274 for (
int i = 0; i < nkeys; i++) {
275 if (
fRecords[i].fKeyword ==
"EXTNAME") {
285 long *param_dimsizes;
288 fits_get_img_dim(fp, ¶m_ndims, &status);
289 if (status)
goto ERR;
290 if (param_ndims > 0) {
292 param_dimsizes =
new long[param_ndims];
293 fits_get_img_size(fp, param_ndims, param_dimsizes, &status);
295 delete [] param_dimsizes;
301 for (
int i = 0; i < param_ndims; i++) {
305 delete [] param_dimsizes;
309 long *firstpixel =
new long[param_ndims];
313 for (
int i = 0; i < param_ndims; i++) {
318 double *pixels =
new double[npixels];
320 fits_read_pix(fp, TDOUBLE, firstpixel, npixels,
321 (
void *) &nulval, (
void *) pixels, &anynul, &status);
324 delete [] firstpixel;
331 delete [] firstpixel;
346 fits_get_num_rows(fp, &table_rows, &status);
347 if (status)
goto ERR;
351 fits_get_num_cols(fp, &table_cols, &status);
352 if (status)
goto ERR;
363 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
364 while (status == COL_NOT_UNIQUE)
367 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
369 if (status != COL_NOT_FOUND)
goto ERR;
373 fCells =
new union Cell [table_rows * table_cols];
381 for (colnum = 0, cellindex = 0; colnum <
fNColumns; colnum++) {
382 fits_get_coltype(fp, colnum+1, &typecode, &repeat, &width, &status);
383 if (status)
goto ERR;
385 if ((typecode == TDOUBLE) || (typecode == TSHORT) || (typecode == TLONG)
386 || (typecode == TFLOAT) || (typecode == TLOGICAL) || (typecode == TBIT)
387 || (typecode == TBYTE) || (typecode == TSTRING)) {
391 if (typecode == TSTRING) {
394 fits_get_col_display_width(fp, colnum+1, &dispwidth, &status);
395 if (status)
goto ERR;
398 char *nulval = (
char*)
"";
402 if (dispwidth <= 0) {
406 array =
new char* [table_rows];
407 for (
long row = 0; row < table_rows; row++) {
408 array[row] =
new char[dispwidth+1];
412 fits_read_col(fp, TSTRING, colnum+1, 1, 1, table_rows, nulval, array, &anynul, &status);
414 for (
long row = 0; row < table_rows; row++) {
415 delete [] array[row];
423 for (
long row = 0; row < table_rows; row++) {
424 strlcpy(array[row],
"-",dispwidth+1);
430 for (
long row = 0; row < table_rows; row++) {
447 array =
new double [table_rows * repeat];
448 fits_read_col(fp, TDOUBLE, colnum+1, 1, 1, table_rows * repeat, &nulval, array, &anynul, &status);
456 array =
new double [table_rows];
457 for (
long row = 0; row < table_rows; row++) {
465 for (
long row = 0; row < table_rows; row++) {
468 }
else if (repeat > 1) {
470 for (
long row = 0; row < table_rows; row++) {
471 double *vec =
new double [repeat];
472 long offset = row * repeat;
473 for (
long component = 0; component < repeat; component++) {
474 vec[component] = array[offset++];
485 Warning(
"LoadHDU",
"error opening FITS file. Column type %d is currently not supported", typecode);
491 if (hdutype == ASCII_TBL) {
501 fits_close_file(fp, &status);
505 fits_get_errstatus(status, errdescr);
506 Warning(
"LoadHDU",
"error opening FITS file. Details: %s", errdescr);
508 if (fp) fits_close_file(fp, &status);
559 char errdescr[FLEN_STATUS+1];
560 int hducount, extnum;
561 int hdutype = IMAGE_HDU;
563 char extname[FLEN_CARD]=
"PRIMARY";
564 int verbose = (opt[0] ? 1 : 0);
568 if (status)
goto ERR;
571 fits_get_num_hdus(fp, &hducount, &status);
572 if (status)
goto ERR;
573 printf(
"Total: %d HDUs\n", hducount);
578 fits_get_hdu_type(fp, &hdutype, &status);
579 if (status)
goto ERR;
581 if (hdutype == IMAGE_HDU) {
583 }
else if (hdutype == ASCII_TBL) {
584 exttype=
"ASCII TABLE";
586 exttype=
"BINARY TABLE";
591 char keyname[FLEN_KEYWORD+1];
592 char keyvalue[FLEN_VALUE+1];
593 char comment[FLEN_COMMENT+1];
595 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
596 if (status)
goto ERR;
600 for (
int i = 1; i <= nkeys; i++) {
601 fits_read_keyn(fp, i, keyname, keyvalue, comment, &status);
608 records[i-1].
fValue = keyvalue;
611 if (strcmp(keyname,
"EXTNAME") == 0) {
613 strlcpy(extname, keyvalue,FLEN_CARD);
618 printf(
" [%d] %s (%s)\n", extnum, exttype, extname);
622 for (
int i = 0; i < nkeys; i++) {
624 printf(
" %-10s = %s / %s\n", records[i].fKeyword.Data(), records[i].
fValue.
Data(), records[i].
fComment.
Data());
626 printf(
" %-10s = %s\n", records[i].fKeyword.Data(), records[i].
fValue.
Data());
637 fits_movrel_hdu(fp, 1, &hdutype, &status);
638 if (status)
goto ERR;
643 fits_close_file(fp, &status);
647 fits_get_errstatus(status, errdescr);
648 Warning(
"PrintFileMetadata",
"error opening FITS file. Details: %s", errdescr);
650 if (fp) fits_close_file(fp, &status);
659 Warning(
"PrintColumnInfo",
"this is not a table HDU.");
676 Warning(
"PrintColumnInfo",
"this is not a table HDU.");
687 while(printed_chars--) {
696 printf(
"%-10s",
fCells[col * fNRows + row].fString);
698 printed_chars = printf(
"%.2lg",
fCells[col * fNRows + row].fRealNumber);
700 while (printed_chars < 0) {
706 if (col <= fNColumns - 1) printf(
"| ");
724 if ((opt[0] ==
'F') || (opt[0] ==
'f')) {
726 }
else if ((opt[0] ==
'T') || (opt[0] ==
't')) {
747 Warning(
"ReadAsImage",
"this is not an image HDU.");
753 Warning(
"ReadAsImage",
"could not convert image HDU to image because it has %d dimensions.",
fSizes->
GetSize());
768 Warning(
"ReadAsImage",
"layer out of bounds.");
776 Int_t offset = layer * pixels_per_layer;
778 for (i = 0; i < pixels_per_layer; i++) {
781 if (pixvalue > maxval) {
785 if ((i == 0) || (pixvalue < minval)) {
797 if (maxval == minval) {
799 for (i = 0; i < pixels_per_layer; i++) {
800 layer_pixels->
SetAt(255.0, i);
803 Double_t factor = 255.0 / (maxval-minval);
804 for (i = 0; i < pixels_per_layer; i++) {
806 layer_pixels->
SetAt(factor * (pixvalue-minval), i) ;
813 for (i = 0; i < 256; i++) {
841 Warning(
"Draw",
"cannot draw. This is not an image HDU.");
851 ctitle.Form(
"%d x %d", width, height);
852 new TCanvas(cname, ctitle, width, height);
868 Warning(
"ReadAsMatrix",
"this is not an image HDU.");
873 Warning(
"ReadAsMatrix",
"could not convert image HDU to image because it has %d dimensions.",
fSizes->
GetSize());
880 Warning(
"ReadAsMatrix",
"layer out of bounds.");
894 offset = layer * pixels_per_layer;
896 double *layer_pixels =
new double[pixels_per_layer];
898 if ((opt[0] ==
'S') || (opt[0] ==
's')) {
901 Double_t factor, maxval=0, minval=0;
903 for (i = 0; i < pixels_per_layer; i++) {
906 if (pixvalue > maxval) {
910 if ((i == 0) || (pixvalue < minval)) {
915 if (maxval == minval) {
917 for (i = 0; i < pixels_per_layer; i++) {
918 layer_pixels[i] = 1.0;
921 factor = 1.0 / (maxval-minval);
924 for (i = 0; i < pixels_per_layer; i++) {
925 layer_pixels[i] = factor * (
fPixels->
GetAt(offset + i) - minval);
933 for (i = 0; i < pixels_per_layer; i++) {
940 memcpy(mat->
GetMatrixArray(), layer_pixels, pixels_per_layer*
sizeof(double));
943 delete [] layer_pixels;
961 Warning(
"ReadAsHistogram",
"this is not an image HDU.");
968 Warning(
"ReadAsHistogram",
"could not convert image HDU to histogram because it has %d dimensions.",
fSizes->
GetSize());
979 for (x = 0; x < Nx; x++) {
981 if (nentries < 0) nentries = 0;
982 h->
Fill(x, nentries);
995 for (y = 0; y < Ny; y++) {
997 for (x = 0; x < Nx; x++) {
999 if (nentries < 0) nentries = 0;
1000 h->
Fill(x,y, nentries);
1013 TH3D *
h =
new TH3D(
"",
"",
Int_t(Nx), 0, Nx-1,
Int_t(Ny), 0, Ny-1,
Int_t(Nz), 0, Nz-1);
1016 for (z = 0; z < Nz; z++) {
1017 UInt_t offset1 = z * Nx * Ny;
1018 for (y = 0; y < Ny; y++) {
1020 for (x = 0; x < Nx; x++) {
1022 if (nentries < 0) nentries = 0;
1023 h->
Fill(x, y, z, nentries);
1040 Warning(
"GetArrayRow",
"this is not an image HDU.");
1045 Warning(
"GetArrayRow",
"could not get row from HDU because it has %d dimensions.",
fSizes->
GetSize());
1056 Warning(
"GetArrayRow",
"index out of bounds.");
1064 for (i = 0; i < W; i++) {
1077 Warning(
"GetArrayColumn",
"this is not an image HDU.");
1082 Warning(
"GetArrayColumn",
"could not get row from HDU because it has %d dimensions.",
fSizes->
GetSize());
1093 Warning(
"GetArrayColumn",
"index out of bounds.");
1100 for (i = 0; i <
H; i++) {
1115 for (colnum = 0; colnum <
fNColumns; colnum++) {
1129 Warning(
"GetTabStringColumn",
"this is not a table HDU.");
1133 if ((colnum < 0) || (colnum >=
fNColumns)) {
1134 Warning(
"GetTabStringColumn",
"column index out of bounds.");
1139 Warning(
"GetTabStringColumn",
"attempting to read a column that is not of type 'kString'.");
1159 Warning(
"GetTabStringColumn",
"this is not a table HDU.");
1167 Warning(
"GetTabStringColumn",
"column not found.");
1172 Warning(
"GetTabStringColumn",
"attempting to read a column that is not of type 'kString'.");
1192 Warning(
"GetTabRealVectorColumn",
"this is not a table HDU.");
1196 if ((colnum < 0) || (colnum >=
fNColumns)) {
1197 Warning(
"GetTabRealVectorColumn",
"column index out of bounds.");
1202 Warning(
"GetTabRealVectorColumn",
"attempting to read a column that is not of type 'kRealNumber'.");
1205 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded vectors, not real scalars. Use GetTabRealVectorCells() instead.");
1227 Warning(
"GetTabRealVectorColumn",
"this is not a table HDU.");
1234 Warning(
"GetTabRealVectorColumn",
"column not found.");
1239 Warning(
"GetTabRealVectorColumn",
"attempting to read a column that is not of type 'kRealNumber'.");
1242 Warning(
"GetTabRealVectorColumn",
"attempting to read a column whose cells have embedded vectors, not real scalars. Use GetTabRealVectorCells() instead.");
1276 Warning(
"Change",
"error changing HDU. Restoring the previous one...");
1282 Warning(
"Change",
"could not restore previous HDU. This object is no longer reliable!!");
1298 tmppath.
Form(
"[%d]", extension_number);
1309 Warning(
"GetTabRealVectorCells",
"this is not a table HDU.");
1313 if ((colnum < 0) || (colnum >=
fNColumns)) {
1314 Warning(
"GetTabRealVectorCells",
"column index out of bounds.");
1319 Warning(
"GetTabRealVectorCells",
"attempting to read a column that is not of type 'kRealNumber'.");
1330 v->
Use(dim,
fCells[offset + row].fRealVector);
1347 Warning(
"GetTabRealVectorCells",
"this is not a table HDU.");
1354 Warning(
"GetTabRealVectorCells",
"column not found.");
1367 Warning(
"GetTabRealVectorCell",
"this is not a table HDU.");
1371 if ((colnum < 0) || (colnum >=
fNColumns)) {
1372 Warning(
"GetTabRealVectorCell",
"column index out of bounds.");
1376 if ((rownum < 0) || (rownum >=
fNRows)) {
1377 Warning(
"GetTabRealVectorCell",
"row index out of bounds.");
1382 Warning(
"GetTabRealVectorCell",
"attempting to read a column that is not of type 'kRealNumber'.");
1398 Warning(
"GetTabRealVectorCell",
"this is not a table HDU.");
1405 Warning(
"GetTabRealVectorCell",
"column not found.");
1421 Error(
"GetColumnName",
"this is not a table HDU.");
1425 if ((colnum < 0) || (colnum >=
fNColumns)) {
1426 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.
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.
Element * GetMatrixArray()
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.
tomato 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
tomato 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
typedef void((*Func_t)())
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.
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.
tomato 2-D histogram with a double per channel (see TH1 documentation)}
const char * Data() const