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

Ajout methode FitsInOutFile::GetKeyValue()

Modification de FitsManager::ScanFile() pour renvoyer aussi les noms des HDU (HDUNAME ou EXTNAME)
parent 74a0b208
/*
--- SOPHYA software - FitsIOServer module ---
R. Ansari , 2005-2014
R. Ansari , 2005-2022
(C) UPS+LAL IN2P3/CNRS (C) IRFU-SPP/CEA
*/
#include "sopnamsp.h"
......@@ -12,6 +12,8 @@
#include <string.h>
#include <iostream>
namespace SOPHYA {
string FitsTypes::ImageTypeToTypeString(int ityp)
{
switch (ityp) {
......@@ -651,13 +653,34 @@ string FitsInOutFile::GetHeaderWithNewLine(int & nkeyrec, bool fgnoch) const
FitsCheckStatus(status, "FitsInOutFile::GetHeaderWithNewLine() fits_free_memory() Error: ");
return rs;
}
/*-- Methode --*/
/*!
fills the argument \b kval with the value associated to the keyword \b key in the header converted to a string,
as well as the corresponding comment.
Return true if the keyword is found, false otherwise.
*/
bool FitsInOutFile::GetKeyValue(const char* key, string & kval, string& comment) const
{
int status = 0;
char value[FLEN_VALUE], comm[FLEN_COMMENT];
fits_read_key(FitsPtr(), TSTRING, const_cast<char *>(key), value, comm, &status);
if (status == KEY_NO_EXIST) {
kval=comment="";
return false;
}
FitsCheckStatus(status, "FitsInOutFile::GetKeyValue() Error: ");
kval=value; comment=comm;
return true;
}
/*-- Methode --*/
/*!
Return the value associated to the keyword \b key in the header as a string.
If the keyword is not found in the fits header, an empty string is returned
and the \b nosk flag is set to true.
*/
string FitsInOutFile::KeyValue(string const & key, bool& nosk)
string FitsInOutFile::KeyValue(string const & key, bool& nosk) const
{
nosk = false;
int status = 0;
......@@ -850,3 +873,5 @@ void FitsInOutFile::PrintHeader(ostream& os, bool fgnoch) const
FitsCheckStatus(status, "FitsInOutFile::PrintHeader() fits_free_memory() Error: ");
return;
}
} // Fin du namespace
/*
--- SOPHYA software - FitsIOServer module ---
R. Ansari , 2005-2014
R. Ansari , 2005-2022
(C) UPS+LAL IN2P3/CNRS (C) IRFU-SPP/CEA
*/
#ifndef FITSINOUTFILE_H
......@@ -203,12 +203,18 @@ public :
//! return the complete header as a multi-line string
inline string GetHeaderWithNewLine(bool fgnoch=true) const
{ int nkeyrec; return GetHeaderWithNewLine(nkeyrec, fgnoch); }
//! return the value (converted to string) and comment associated with the specified keyword from the header. return false if keyword not found
bool GetKeyValue(const char* key, string & kval, string& comment) const ;
//! return the value (converted to string) and comment associated with the specified keyword from the header. return false if keyword not foun
inline bool GetKeyValue(string const & key, string & kval, string& comment) const {
return GetKeyValue(key.c_str(), kval, comment);
}
//! Retrieve a keyword value from the header
inline string KeyValue(string const & key)
inline string KeyValue(string const & key) const
{ bool nosk; return KeyValue(key, nosk); }
//! Retrieve a keyword value from the header
string KeyValue(string const & key, bool& nosk);
string KeyValue(string const & key, bool& nosk) const ;
//! Read header records and appends the information to dvl
int GetHeaderRecords(DVList& dvl,
bool stripkw= true, bool keepstkey=false);
......
/*
--- SOPHYA software - FitsIOServer module ---
R. Ansari , 2005-2022
(C) UPS+LAL IN2P3/CNRS (C) DAPNIA-SPP/CEA
*/
#include "machdefs.h"
#include "sopnamsp.h"
......@@ -9,16 +14,20 @@
#include "fitsmanager.h"
#include "fitshandler.h"
namespace SOPHYA {
//--- structures et typedef pour gerer la liste des FitsHandler enregistres
struct hand_list_el {
FitsHandlerInterface * fhi;
int glev;
string desc;
};
typedef list<hand_list_el> HandlerList;
typedef std::list<hand_list_el> HandlerList;
static HandlerList * hlistp = NULL;
// verifie et si besoin alloue la liste des handlers
static inline void ChkHLP()
{
if (hlistp == NULL) hlistp = new HandlerList;
......@@ -265,15 +274,17 @@ int FitsManager::ScanFile(string filename, ostream& os, bool fgph, bool fgrd)
/*!
\param filename : FITS file name to be scanned
\param hdudesc : a textual description of each HDU
\param extnames : HDU names corresponding to HDUNAME or EXTNAME keywords
return value : vector of HDU-types (0:Unknown/Probleme; 1:IMAGE_HDU, 2:BINARY_TBL, 3:ASCII_TBL)
*/
std::vector<int> FitsManager::ScanFile(std::string filename, std::vector<std::string>& hdudesc)
std::vector<int> FitsManager::ScanFile(std::string filename, std::vector<std::string>& hdudesc, std::vector<std::string>& extnames)
{
FitsInOutFile is(filename, FitsInOutFile::Fits_RO);
hdudesc.clear();
std::vector<int> vrtyp;
int rtyp=0;
int rtyp=0;
string extname, comment;
for(int k=0; k<is.NbHDUs(); k++) {
rtyp=0;
int hdutyp = is.CurrentHDUType();
......@@ -310,7 +321,13 @@ std::vector<int> FitsManager::ScanFile(std::string filename, std::vector<std::st
}
vrtyp.push_back(rtyp);
hdudesc.push_back(os.str());
extname="";
bool fgokextn=is.GetKeyValue("HDUNAME",extname,comment);
if (!fgokextn) fgokextn=is.GetKeyValue("EXTNAME",extname,comment);
extnames.push_back(extname);
is.MoveToNextHDU();
}
return vrtyp;
}
} // Fin du namespace
......@@ -123,7 +123,7 @@ typedef struct {
typedef unsigned char ObjType_t;
typedef unsigned char ObjAge_t;
typedef unsigned char byte;
typedef unsigned char A_byte; // Reza, Mai 2022 : byte remplace par A_byte - confusion entre byte et std::byte si compile avec c++
/* Obj is a massive union.
* many fields are in common so we use macros to make things a little easier.
......@@ -132,7 +132,7 @@ typedef unsigned char byte;
/* fields common to *all* structs in the Obj union */
#define OBJ_COMMON_FLDS \
ObjType_t co_type; /* current object type; see flags, below */ \
byte co_flags; /* FUSER*... used by others */ \
A_byte co_flags; /* FUSER*... used by others */ \
ObjAge_t co_age; /* update aging code; see db.c */ \
char co_name[MAXNM];/* name, including \0 */ \
float co_ra; /* geo/topo app/mean ra, rads */ \
......@@ -181,8 +181,8 @@ typedef struct {
OBJ_FIXED_FLDS;
/* following are for galaxies */
byte fo_ratio; /* minor/major diameter ratio. use s/get_ratio() */
byte fo_pa; /* position angle, E of N, rads. use s/get_pa() */
A_byte fo_ratio; /* minor/major diameter ratio. use s/get_ratio() */
A_byte fo_pa; /* position angle, E of N, rads. use s/get_pa() */
} ObjF;
/* true-orbit parameters of binary-star object type */
......@@ -215,8 +215,8 @@ typedef struct {
OBJ_COMMON_FLDS;
OBJ_FIXED_FLDS;
byte b_2compute; /* whether to compute secondary positions */
byte b_nbp; /* number of b_bp[] or 0 to use b_bo */
A_byte b_2compute; /* whether to compute secondary positions */
A_byte b_nbp; /* number of b_bp[] or 0 to use b_bo */
short b_2mag; /* secondary's magnitude * MAGSCALE */
char b_2spect[2]; /* secondary's spectrum */
......@@ -234,11 +234,11 @@ typedef struct {
#define SRSCALE 255.0 /* galaxy size ratio scale */
#define PASCALE (255.0/(2*PI)) /* pos angle scale factor */
#define get_ratio(op) (((int)(op)->f_ratio)/SRSCALE)
#define set_ratio(op,maj,min) ((op)->f_ratio = (byte)(((maj) > 0) \
#define set_ratio(op,maj,min) ((op)->f_ratio = (A_byte)(((maj) > 0) \
? ((min)*SRSCALE/(double)(maj)+0.5) \
: 0))
#define get_pa(op) ((double)(op)->f_pa/PASCALE)
#define set_pa(op,s) ((op)->f_pa = (byte)((s)*PASCALE + 0.5))
#define set_pa(op,s) ((op)->f_pa = (A_byte)((s)*PASCALE + 0.5))
#define NCLASSES 128 /* n potential fo_classes -- allow for all ASCII */
......
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