Commit c8c6644b authored by Reza  ANSARI's avatar Reza ANSARI
Browse files

Ajout nouvelles fonctions lecture entete FITS avec newline et scan des HDU de...

Ajout nouvelles fonctions lecture entete FITS avec newline et scan des HDU de fits, pour la lecture/scan interactive de fichier fits ds piapp, Reza 23/05/2022
parent fc41e13f
......@@ -35,8 +35,9 @@ int FitsIOServerInitiator::FgInit = 0;
// Module version number - 2.4 , Dec 2014
// Module version number - 2.5 , Juin 2015 (Adaptation refonte SkyMap - SphericalMaps)
// Module version number - 2.55 , Jan 2018 pour SOPHYVA V=2.5
// Module version number - 2.57 , Mai 2022
#define FitsIOServer_MOD_VERS 2.55
#define FitsIOServer_MOD_VERS 2.57
FitsIOServerInitiator::FitsIOServerInitiator()
: SophyaInitiator()
......
......@@ -624,6 +624,33 @@ string FitsInOutFile::GetHeader(int & nkeyrec, bool fgnoch) const
return rs;
}
/*-- Methode --*/
string FitsInOutFile::GetHeaderWithNewLine(int & nkeyrec, bool fgnoch) const
/*!
the 80 character long header records are concatenated into a character array, separated each with
a newline character and returned as a multi-line std::string.
This method calls the cfitsio routine fits_hdr2str() .
if fgnoch==true (default), COMMENT, HISTORY, records or with blank keywords in the header are not copied.
*/
{
int status=0;
char * header=NULL;
nkeyrec=0;;
fits_hdr2str(FitsPtr(), (fgnoch?1:0), NULL, 0, &header, &nkeyrec, &status);
FitsCheckStatus(status, "FitsInOutFile::GetHeaderWithNewLine() fits_hdr2str() Error: ");
size_t len=strlen(header);
size_t jl=0, jinc=80; // 80 header record length
string rs;
while (jl+jinc<=len) {
char cz=header[jl+jinc]; header[jl+jinc]='\0';
rs+=header+jl; rs+='\n';
header[jl+jinc]=cz; jl+=jinc;
}
fits_free_memory(header, &status);
FitsCheckStatus(status, "FitsInOutFile::GetHeaderWithNewLine() fits_free_memory() Error: ");
return rs;
}
/*-- Methode --*/
/*!
Return the value associated to the keyword \b key in the header as a string.
......
......@@ -194,9 +194,16 @@ public :
// Manipulation des informations de l'entete
//! return the complete header as string (character array) and number of header records
string GetHeader(int & nkeyrec, bool fgnoch=true) const;
//! return the complete header as string (character array)
/*! \brief return the complete header as string (character array)
see the method with an additional argument for details */
inline string GetHeader(bool fgnoch=true) const
{ int nkeyrec; return GetHeader(nkeyrec, fgnoch); }
//! return the complete header as a multi-line string (character array) and number of header records
string GetHeaderWithNewLine(int & nkeyrec, bool fgnoch=true) const;
//! return the complete header as a multi-line string
inline string GetHeaderWithNewLine(bool fgnoch=true) const
{ int nkeyrec; return GetHeaderWithNewLine(nkeyrec, fgnoch); }
//! Retrieve a keyword value from the header
inline string KeyValue(string const & key)
{ bool nosk; return KeyValue(key, nosk); }
......
......@@ -261,3 +261,49 @@ int FitsManager::ScanFile(string filename, ostream& os, bool fgph, bool fgrd)
os << "===================================================" << endl;
return rc;
}
/*!
\param filename : FITS file name to be scanned
\param hdudesc : a textual description of each HDU
return value : vector of HDU-types (IMAGE_HDU, BINARY_TBL, ASCII_TBL)
*/
std::vector<int> FitsManager::ScanFile(std::string filename, std::vector<std::string>& hdudesc)
{
FitsInOutFile is(filename, FitsInOutFile::Fits_RO);
hdudesc.clear();
std::vector<int> rtyp;
for(int k=0; k<is.NbHDUs(); k++) {
int hdutyp = is.CurrentHDUType();
std::stringstream os;
if (hdutyp == IMAGE_HDU) {
LONGLONG naxes[5] = {0,0,0,0,0};
int naxis=5;
int imgtyp = is.GetImageHDUInfo(naxis, naxes);
os << ">> IMAGE_HDU (type="<<imgtyp<<") naxis= " << naxis << " : ";
for(int i=0; i<naxis; i++) {
if (i>0) os << " x " ;
os << naxes[i];
}
}
else {
vector<string> colnames;
vector<int> coltypes;
vector<LONGLONG> repcnt, width;
int ncols = is.GetColInfo(colnames, coltypes, repcnt, width);
if (hdutyp == BINARY_TBL) os << ">> BINARY_TBL : NRows= " << is.GetNbRows();
else os << ">> ASCII_TBL : NRows= " << is.GetNbRows();
os << " x NCols= " << ncols << endl;
for(size_t kk=0; kk<colnames.size(); kk++) {
os << "Col[" << kk+1 << "] Name= " << colnames[kk]
<< " Type= " << FitsTypes::DataTypeToTypeString(coltypes[kk])
<< " Repeat= " << repcnt[kk]
<< " W= " << width[kk] << endl;
}
}
rtyp.push_back(hdutyp);
hdudesc.push_back(os.str());
}
return rtyp;
}
......@@ -36,7 +36,9 @@ class FitsManager {
//! Scans the fits file and prints information about each HDU on \b cout
static inline int ScanFile(string filename, bool fgph=false, bool fgrd=false)
{ return ScanFile(filename, cout, fgph, fgrd); }
//! Scans the fits file and return the list of HDU types , and a textual description of each HDU
static inline std::vector<int> ScanFile(std::string filename, std::vector<std::string>& hdudesc);
protected:
//! Finds the appropriate handler for the object \b o in the list of registered handlers.
static FitsHandlerInterface* FindHandler(AnyDataObj & o);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment