40 for (
int i = 0; i < number; i++ ) {
48 value =
"Empty image";
53 if ( value ==
"" ) value =
"<no name>";
54 names.push_back ( value );
63 if ( type ==
Image ) {
83 for (
int i = 0; i < columns; i++ ) {
84 char colname [ FLEN_VALUE ];
86 fits_get_colname (
m_fptr, CASEINSEN, const_cast< char * > (
"*"),
88 labels.push_back (
string ( colname ) );
92 labels.push_back (
string (
"none" ) );
104 if ( dimension == 2 ) {
105 labels.push_back (
"Values" );
107 else if ( dimension == 3 ) {
108 const char type[] =
"CTYPE3";
109 bool yes =
hasKey ( type );
113 for (
int i = 0; i < number; i++ ) {
115 labels.push_back ( name +
" " + iv );
147 long nelements = vec.size();
148 vector<double>::iterator it = vec.begin();
152 fits_read_col_dbl(
m_fptr, column+1, 1, 1, nelements, nulval,
164 string tdimn (
"TDIM" );
167 fits_read_keyword (
m_fptr,
168 const_cast < char * > ( tdimn.c_str() ),
173 if ( value[0] != 0 ) {
174 const string dims = value;
175 unsigned int count = std::count ( dims.begin(), dims.end(),
',' );
178 vector < long > naxes ( count );
179 fits_read_tdim (
m_fptr, column+1, count,
181 shape.resize ( count + 1 );
183 std::copy ( naxes.begin(), naxes.end(), shape.begin() + 1 );
186 shape.resize ( 1, rows );
196 vec.resize ( naxis );
198 vector < long > ::iterator first = vec.begin();
199 long * ptr = & *first;
213 deltas.reserve ( naxis );
215 char key [ FLEN_KEYWORD];
216 char * keyroot = const_cast <
char * > (
"CDELT");
217 for (
int i = 0; i < naxis; i++ ) {
219 fits_make_keyn ( keyroot, i+1, key, &
m_status );
220 bool yes =
hasKey ( key );
224 deltas.push_back ( value );
227 deltas.push_back ( 1.0 );
238 indices.reserve ( naxis );
240 char key [ FLEN_KEYWORD];
241 char * keyroot = const_cast <
char * > (
"CRPIX" );
242 for (
int i = 0; i < naxis; i++ ) {
244 fits_make_keyn ( keyroot, i+1, key, &
m_status );
245 bool yes =
hasKey ( key );
249 indices.push_back ( value );
252 indices.push_back ( 1 );
263 values.reserve ( naxis );
265 char key [ FLEN_KEYWORD];
266 char * keyroot = const_cast <
char * > (
"CRVAL" );
267 for (
int i = 0; i < naxis; i++ ) {
269 fits_make_keyn ( keyroot, i+1, key, &
m_status );
270 bool yes =
hasKey ( key );
274 values.push_back ( value );
277 values.push_back ( 0. );
288 char key [FLEN_KEYWORD];
289 char * keyroot = const_cast <
char * > (
"CTYPE" );
290 for (
int i = 0; i < 2; i++ ) {
291 fits_make_keyn ( keyroot, i+1, key, &
m_status );
292 bool yes =
hasKey ( key );
296 if ( value.find (
"-AIT" ) == string::npos ) {
311 vector < long > naxes;
315 long nelements = naxes[0] * naxes[1];
317 vector < double >::iterator first = vec.begin();
318 double * ptr = & *first;
321 if ( naxes.size () == 2 ) {
322 long fpixel[2] = { 1, 1 };
323 fits_read_pix (
m_fptr, datatype, fpixel, nelements,
324 & nulval, ptr, & anynul, &
m_status );
326 long fpixel[] = { 1, 1, 1 };
327 fpixel[2] = zplane + 1;
328 fits_read_pix (
m_fptr, datatype, fpixel, nelements,
329 & nulval, ptr, & anynul, &
m_status );
341 long nelements = vec.size();
342 vector<int>::iterator it = vec.begin();
343 int * ptr =
new int [ nelements ];
346 fits_read_col_int(
m_fptr, column+1, 1, 1, nelements, nulval,
347 ptr, &anynul, &status);
348 copy ( ptr, ptr+nelements, it );
356 const std::vector < std::string > & names,
357 const std::vector < std::vector < int > > & shapes,
358 const std::string & extname )
360 char **
types =
new char * [ columns ];
361 char ** tform =
new char * [ columns ];
365 vector < string > forms;
366 for (
int i = 0; i < columns; i ++ ) {
367 types[i]=
const_cast<char*
> (names[i].c_str());
369 const vector < int > &
shape = shapes [ i ];
370 unsigned int rank = shape.size();
372 for (
unsigned int j = 1; j <
rank; j++ ) {
373 int dim = shape [ j ];
379 forms.push_back ( form );
381 tform[i] = strdup ( form.c_str() );
386 m_extname =
const_cast<char*
> (extname.c_str());
388 fits_create_tbl(
m_fptr, BINARY_TBL, 0, columns,
389 types, tform, tunits, m_extname, &
m_status);
391 for (
int i = 0; i < columns; i ++ ) {
392 const vector < int > &
shape = shapes [ i ];
393 unsigned int rank = shape.size();
395 vector < long > naxes;
396 for (
unsigned int j = 1; j <
rank; j++ ) {
397 naxes.push_back ( shape [ j ] );
399 fits_write_tdim (
m_fptr, i+1,
421 LONGLONG nelements = data.size ();
422 LONGLONG firstrow = 1;
423 LONGLONG firstelem = 1;
424 fits_write_col(
m_fptr, TDOUBLE, col+1, firstrow, firstelem, nelements,
425 const_cast < double * > ( &data[0] ), &
m_status);
432 long fpixel[2]={1,1};
433 long nelements = x * y;
434 fits_write_pix (
m_fptr, TDOUBLE, fpixel, nelements,
435 const_cast < double * > ( &data[0] ), &
m_status );
451 char * key = const_cast <
char * > (
"PIXCENT" );
452 bool yes =
hasKey ( key );
466 char * key1 = const_cast <
char * > (
"CRVAL1" );
467 char * key2 = const_cast <
char * > (
"CRVAL2" );
469 fits_write_key(
m_fptr, TDOUBLE, key1, &value1, NULL, &
m_status );
470 fits_write_key(
m_fptr, TDOUBLE, key2, &value2, NULL, &
m_status );
void * data(numeric::array arr)
void writeHDU(long rows, int columns, const std::vector< std::string > &names, const std::vector< std::vector< int > > &shapes, const std::string &extname)
int getNumberOfColumns() const
Returns the number of columns in a table.
double doubleValueForKey(const char *key) const
Read a specified keyword value and return it as a double.
HduType getHduType() const
Returns the type of HDU.
column
The column indices for 2 dimension data point tuple.
void fillHDUNames(std::vector< std::string > &names)
Clears and fills the vector with the HDU names.
void writeColumn(int c, const std::vector< double > &data)
Writes the vector to FITS table.
std::string stringValueForKey(const char *key) const
Read a specified keyword value and returns it as a string.
int fillIntVectorFromColumn(std::vector< int > &vec, int column)
Read elements from an ASCII or binary table column (in the CDU) and fill STL vector with its con...
int intValueForKey(const char *key) const
Read a specified keyword value and returns it as a int.
static Type types[]
An array to allow conversion of integer to enumeration.
bool isHammerAitoff() const
Returns true if coordinate system of the axis is should undergo Hammer-Aitoff transformation.
int status() const
Returns the cfitsio status code for the last operation.
A base class for the concrete classes that wrap the cfitsio library.
fitsfile * m_fptr
Pointer to the fits file data structure.
bool hasKey(const char *key) const
Returns true if the keyword key exists, otherwise returns false.
void writePix(long x, long y, const std::vector< double > &data)
int m_status
The status return code from the last cfitsio operation.
void fillShape(std::vector< intptr_t > &shape, int column)
Fills the vector with the shape of the column.
intp size(numeric::array arr)
void writeRefPixelValues(double value1, double value2)
void fillRefPixelValues(std::vector< double > &values) const
Clears and fills the vector with the reference pixel's values.
int getNumberOfHDU() const
Returns the number of HDU in the file.
int write(const std::vector< double > &a)
Given the vector it writes it to std stream.
PyArray_TYPES type(numeric::array arr)
string convert(int i)
Converts an integer to a string.
void fillImageDeltas(std::vector< double > &deltas) const
Clears and fills the vector with the delta values of an image.
int fillColumnNamesFromTable(std::vector< std::string > &labels)
Clears and fills the vector with the column labels of binary or ASCII table.
void writeImageHDU(long x, long y)
int rank(numeric::array arr)
void fillRefPixelIndices(std::vector< int > &indices) const
Clears and fills the vector with the reference pixel's indexes.
FitsFile(const std::string &filename, bool write=false)
Public construction taking a filename as argument.
int fillColumnNamesFromImage(std::vector< std::string > &labels)
Clears and fills the vector with the column labels of a image.
int moveToHDU(int hdunum)
Move to a specified absolute HDU number in the FITS file and return the cfitsio status.
std::vector< intptr_t > shape(numeric::array arr)
long getNumberOfRows() const
Returns the number of rows in the table.
hippodraw::FitsFile interface
Displays on the Z axis the values of a single column treated as a matrix of values.
int fillAxisSizes(std::vector< long > &vec) const
Clears and fills the vector vec with the size of each dimension of an image.
int getImageDimensions() const
Returns the number of dimensions (axes) of an image.
The namespace for conversion to string.
int fillFromTableColumn(std::vector< double > &v, int column)
Fills the vector v from a table column.
int fillDoubleVectorFromColumn(std::vector< double > &vec, int column)
Read elements from an ASCII or binary table column (in the CDU) and fill the vector with its contents...
int fillFromImage(std::vector< double > &vec, unsigned int axis)
Fills the vector vec from an image HDU.
int fillColumnNames(std::vector< std::string > &labels)
Clears and fills the vector with the column labels of the current HDU table.