RTC Toolkit  1.0.0
fitsIoFunctions.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_FITSIOFUNCTIONS_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_FITSIOFUNCTIONS_HPP
14 
15 #include <boost/filesystem.hpp>
16 #include <cassert>
17 #include <fitsio.h>
18 #include <limits>
22 #include <string>
23 #include <type_traits>
24 #include <unistd.h>
25 
26 namespace {
27 
34 template <typename T>
35 void IdentifyCfitsioTypes(int& bitpix, int& datatype) {
36  if constexpr (std::is_integral_v<T>) {
37  if constexpr (std::is_same_v<T, bool>) {
38  bitpix = BYTE_IMG;
39  datatype = TBYTE;
40  } else if constexpr (sizeof(T) == 1) {
41  if constexpr (std::is_signed_v<T>) {
42  bitpix = SBYTE_IMG;
43  datatype = TSBYTE;
44  } else {
45  bitpix = BYTE_IMG;
46  datatype = TBYTE;
47  }
48  } else if constexpr (sizeof(T) == 2) {
49  if constexpr (std::is_signed_v<T>) {
50  bitpix = SHORT_IMG;
51  datatype = TSHORT;
52  } else {
53  bitpix = USHORT_IMG;
54  datatype = TUSHORT;
55  }
56  } else if constexpr (sizeof(T) == 4) {
57  if constexpr (std::is_signed_v<T>) {
58  bitpix = LONG_IMG;
59  if constexpr (sizeof(int) == 4) {
60  datatype = TINT;
61  } else if constexpr (sizeof(long) == 4) {
62  datatype = TLONG;
63  } else {
64  static_assert(sizeof(int) == 4 or sizeof(long) == 4,
65  "Require either int or long type to be 32 bits wide.");
66  }
67  } else {
68  bitpix = ULONG_IMG;
69  if constexpr (sizeof(unsigned int) == 4) {
70  datatype = TUINT;
71  } else if constexpr (sizeof(unsigned long) == 4) {
72  datatype = TULONG;
73  } else {
74  static_assert(
75  sizeof(unsigned int) == 4 or sizeof(unsigned long) == 4,
76  "Require either unsigned int or unsigned long type to be 32 bits wide.");
77  }
78  }
79  } else if constexpr (sizeof(T) == 8) {
80  if constexpr (std::is_signed_v<T>) {
81  bitpix = LONGLONG_IMG;
82  datatype = TLONGLONG;
83  } else {
84 #ifdef ULONGLONG_IMG
85  bitpix = ULONGLONG_IMG;
86  datatype = TULONGLONG;
87 #else
88  // If we are using an older Cfitsio library that does not have ULONGLONG_IMG defined
89  // then simply alias to using the signed version for the image code and data type.
90  bitpix = LONGLONG_IMG;
91  datatype = TLONGLONG;
92 #endif
93  }
94  } else {
95  static_assert(
96  sizeof(T) == 1 or sizeof(T) == 2 or sizeof(T) == 4 or sizeof(T) == 8,
97  "The integer type used as the template parameter must be one of 8, 16, 32, or 64"
98  " bits wide.");
99  }
100  }
101  if constexpr (std::is_floating_point_v<T>) {
102  if constexpr (sizeof(T) == 4) {
103  bitpix = FLOAT_IMG;
104  datatype = TFLOAT;
105  } else if constexpr (sizeof(T) == 8) {
106  bitpix = DOUBLE_IMG;
107  datatype = TDOUBLE;
108  } else {
109  static_assert(
110  sizeof(T) == 4 or sizeof(T) == 8,
111  "The floating-point type used as the template parameter must be float or double.");
112  }
113  } else {
114  static_assert(std::is_arithmetic_v<T>,
115  "The template parameter used must be an integer or floating-point type.");
116  }
117 }
118 
119 } // namespace
120 
121 namespace rtctk::componentFramework {
122 
128 std::string GetCfitsioErrorMsg(int status);
129 
136 std::string CfitsioImageTypeToString(int bitpix);
137 
144 std::string CfitsioDataTypeToString(int datatype);
145 
151 template <typename T, typename A>
152 void WriteMatrixToFits(const std::string& filename, const MatrixBuffer<T, A>& matrix) {
153  assert(int64_t(matrix.GetNrows()) <= int64_t(std::numeric_limits<long>::max()));
154  assert(int64_t(matrix.GetNcols()) <= int64_t(std::numeric_limits<long>::max()));
155 
156  // Workout the appropriate Cfitsio image type code and data type code to use, based on the type
157  // used with MatrixBuffer, i.e. the type of T.
158  int bitpix = 0;
159  int datatype = 0;
160  IdentifyCfitsioTypes<T>(bitpix, datatype);
161 
162  std::string tmpfilename = filename + ".new-" + std::to_string(getpid());
163 
164  // Create the new FITS file and open it for modifications.
165  fitsfile* fptr = nullptr;
166  int status = 0; // It is important to initialise this to zero before each Cfitsio API call.
167  if (fits_create_file(&fptr, tmpfilename.c_str(), &status) != 0) {
168  std::string msg =
169  "Failed to create FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
170  CII_THROW(RtctkException, msg);
171  }
172 
173  try {
174  // Create the image header in the HDU.
175  long nrows = long(matrix.GetNrows());
176  long ncols = long(matrix.GetNcols());
177  long size[2] = {ncols, nrows};
178  status = 0;
179  if (fits_create_img(fptr, bitpix, 2, size, &status) != 0) {
180  std::string msg = "Failed to create the image type from FITS file '" + tmpfilename +
181  "'. " + GetCfitsioErrorMsg(status);
182  CII_THROW(RtctkException, msg);
183  }
184 
185  // Write the matrix data as pixels.
186  long fpixel[2] = {1, 1}; // Pixel start location. Cfitsio counts from 1, not 0.
187  long nelements = matrix.size();
188  // We are forced to use const_cast, since the fits_write_pix function does not accept
189  // const void*.
190  void* array = const_cast<void*>(reinterpret_cast<const void*>(matrix.data()));
191  status = 0;
192  if (fits_write_pix(fptr, datatype, fpixel, nelements, array, &status) != 0) {
193  std::string msg = "Failed to write the matrix to FITS file '" + tmpfilename + "'. " +
194  GetCfitsioErrorMsg(status);
195  CII_THROW(RtctkException, msg);
196  }
197  } catch (...) {
198  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
199  // exception if closing the file failed. Just log this error and rethrow the original
200  // exception.
201  status = 0;
202  if (fits_close_file(fptr, &status) != 0) {
203  LOG4CPLUS_ERROR(GetLogger(),
204  "Failed to close file '" + tmpfilename +
205  "' while handling an exception. " + GetCfitsioErrorMsg(status));
206  }
207  throw;
208  }
209 
210  status = 0;
211  if (fits_close_file(fptr, &status) != 0) {
212  std::string msg =
213  "Failed to close the FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
214  CII_THROW(RtctkException, msg);
215  }
216 
217  // Rename the temporary file to its final value. Updating the file in this manner will make sure
218  // that different processes or threads will see changes to the file in an atomic manner. Either
219  // the old file will be visible, or the new file, but not a partially modified file.
220  try {
221  boost::filesystem::rename(tmpfilename, filename);
222  } catch (const std::exception& error) {
223  CII_THROW_WITH_NESTED(
225  error,
226  "Failed to rename FITS file '" + tmpfilename + "' to '" + filename + "'.")
227  }
228 }
229 
235 template <typename T, typename A>
236 void ReadMatrixFromFits(const std::string& filename, MatrixBuffer<T, A>& matrix) {
237  // Identify the Cfitsio data type code to be used and the expected Cfitsio image type code,
238  // based on the type used with MatrixBuffer, i.e. type of T.
239  int expected_bitpix = 0;
240  int datatype = 0;
241  IdentifyCfitsioTypes<T>(expected_bitpix, datatype);
242 
243  fitsfile* fptr = nullptr;
244  int status = 0; // It is important to initialise this to zero before every Cfitsio API call.
245  if (fits_open_image(&fptr, filename.c_str(), READONLY, &status) != 0) {
246  std::string msg =
247  "Failed to open FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
248  CII_THROW(RtctkException, msg);
249  }
250 
251  try {
252  // Read and check that the pixel format used in the FITS file corresponds to the type used
253  // for the matrix object passed to this function.
254  int bitpix = -1;
255  status = 0;
256  if (fits_get_img_equivtype(fptr, &bitpix, &status) != 0) {
257  std::string msg = "Failed to read the image type from FITS file '" + filename + "'. " +
258  GetCfitsioErrorMsg(status);
259  CII_THROW(RtctkException, msg);
260  }
261  if (bitpix == LONGLONG_IMG) {
262  // NOTE: Correcting the bitpix for ULONGLONG_IMG. There is a bug in Cfitsio that returns
263  // LONGLONG_IMG instead of ULONGLONG_IMG.
264  char value[80]; // Use maximum possible FITS card size of 80 bytes.
265  status = 0;
266  int result = fits_read_keyword(fptr, "BZERO", value, nullptr, &status);
267  if (result != 0 and status != KEY_NO_EXIST) {
268  std::string msg = "Failed to read keyword BZERO from '" + filename + "'. " +
269  GetCfitsioErrorMsg(status);
270  CII_THROW(RtctkException, msg);
271  }
272  if (std::string(value) ==
273  std::to_string(std::numeric_limits<uint64_t>::max() / 2 + 1)) {
274 #ifdef ULONGLONG_IMG
275  bitpix = ULONGLONG_IMG;
276 #else
277  // If we are dealing with an older Cfitsio library that does not have ULONGLONG_IMG
278  // defined, then simply alias to using the signed version instead.
279  bitpix = LONGLONG_IMG;
280 #endif
281  }
282  }
283  if (bitpix != expected_bitpix) {
284  std::string msg = "The FITS file '" + filename + "' has the wrong image format of " +
285  CfitsioImageTypeToString(bitpix) +
286  ". Expected a FITS image of type " +
287  CfitsioImageTypeToString(expected_bitpix) + ".";
288  CII_THROW(RtctkException, msg);
289  }
290 
291  // Read and check that the number of image axes is 2.
292  int naxis = -1;
293  status = 0;
294  if (fits_get_img_dim(fptr, &naxis, &status) != 0) {
295  std::string msg = "Failed to read the number of image axes from FITS file '" +
296  filename + "'. " + GetCfitsioErrorMsg(status);
297  CII_THROW(RtctkException, msg);
298  }
299  if (naxis != 2) {
300  std::string msg = "The FITS file '" + filename +
301  "' has image dimensions that we cannot handle. Expect a 2D image "
302  "when loading as a matrix.";
303  CII_THROW(RtctkException, msg);
304  }
305 
306  long size[2] = {-1, -1};
307  status = 0;
308  if (fits_get_img_size(fptr, 2, size, &status) != 0) {
309  std::string msg = "Failed to read the image size from FITS file '" + filename + "'. " +
310  GetCfitsioErrorMsg(status);
311  CII_THROW(RtctkException, msg);
312  }
313 
314  using size_type = typename MatrixBuffer<T, A>::size_type;
315  auto nrows = size_type(size[1]);
316  auto ncols = size_type(size[0]);
317  long nelements = size[0] * size[1]; // Total number of pixels, i.e. rows * columns.
318 
319  long fpixel[2] = {1, 1}; // Pixel start location. Cfitsio counts from 1, not 0.
320  int anynull = 0; // Boolean flag indicating if there were any null/nil pixel values.
321  matrix.resize(nrows, ncols);
322  void* array = matrix.data();
323  status = 0;
324  int result =
325  fits_read_pix(fptr, datatype, fpixel, nelements, nullptr, array, &anynull, &status);
326  if (result != 0) {
327  std::string msg = "Failed to read the image from FITS file '" + filename + "'. " +
328  GetCfitsioErrorMsg(status);
329  CII_THROW(RtctkException, msg);
330  }
331  } catch (...) {
332  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
333  // exception if closing the file failed. Just log this error and rethrow the original
334  // exception.
335  status = 0;
336  if (fits_close_file(fptr, &status) != 0) {
337  LOG4CPLUS_ERROR(GetLogger(),
338  "Failed to close file '" + filename +
339  "' while handling an exception. " + GetCfitsioErrorMsg(status));
340  }
341  throw;
342  }
343 
344  status = 0;
345  if (fits_close_file(fptr, &status) != 0) {
346  std::string msg =
347  "Failed to close the FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
348  CII_THROW(RtctkException, msg);
349  }
350 }
351 
357 template <typename T, typename A>
358 void WriteVectorToFits(const std::string& filename, const std::vector<T, A>& vector) {
359  assert(int64_t(vector.size()) <= int64_t(std::numeric_limits<long>::max()));
360 
361  // Workout the appropriate Cfitsio image type code and data type code to use, based on the type
362  // used with std::vector, i.e. the type of T.
363  int bitpix = 0;
364  int datatype = 0;
365  IdentifyCfitsioTypes<T>(bitpix, datatype);
366 
367  std::string tmpfilename = filename + ".new-" + std::to_string(getpid());
368 
369  // Create the new FITS file and open it for modifications.
370  fitsfile* fptr = nullptr;
371  int status = 0; // It is important to initialise this to zero before each Cfitsio API call.
372  if (fits_create_file(&fptr, tmpfilename.c_str(), &status) != 0) {
373  std::string msg =
374  "Failed to create FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
375  CII_THROW(RtctkException, msg);
376  }
377 
378  try {
379  // Create the image header in the HDU.
380  long size = long(vector.size());
381  status = 0;
382  if (fits_create_img(fptr, bitpix, 1, &size, &status) != 0) {
383  std::string msg = "Failed to create the image type from FITS file '" + tmpfilename +
384  "'. " + GetCfitsioErrorMsg(status);
385  CII_THROW(RtctkException, msg);
386  }
387 
388  // Write the vector data as pixels.
389  long fpixel = 1; // Pixel start location. Cfitsio counts from 1, not 0.
390  long nelements = vector.size();
391  // We are forced to use const_cast, since the fits_write_pix function does not accept
392  // const void*.
393  void* array = const_cast<void*>(reinterpret_cast<const void*>(vector.data()));
394  status = 0;
395  if (fits_write_pix(fptr, datatype, &fpixel, nelements, array, &status) != 0) {
396  std::string msg = "Failed to write the vector to FITS file '" + tmpfilename + "'. " +
397  GetCfitsioErrorMsg(status);
398  CII_THROW(RtctkException, msg);
399  }
400  } catch (...) {
401  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
402  // exception if closing the file failed. Just log this error and rethrow the original
403  // exception.
404  status = 0;
405  if (fits_close_file(fptr, &status) != 0) {
406  LOG4CPLUS_ERROR(GetLogger(),
407  "Failed to close file '" + tmpfilename +
408  "' while handling an exception. " + GetCfitsioErrorMsg(status));
409  }
410  throw;
411  }
412 
413  status = 0;
414  if (fits_close_file(fptr, &status) != 0) {
415  std::string msg =
416  "Failed to close the FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
417  CII_THROW(RtctkException, msg);
418  }
419 
420  // Rename the temporary file to its final value. Updating the file in this manner will make sure
421  // that different processes or threads will see changes to the file in an atomic manner. Either
422  // the old file will be visible, or the new file, but not a partially modified file.
423  try {
424  boost::filesystem::rename(tmpfilename, filename);
425  } catch (const std::exception& error) {
426  CII_THROW_WITH_NESTED(
428  error,
429  "Failed to rename FITS file '" + tmpfilename + "' to '" + filename + "'.")
430  }
431 }
432 
438 template <typename T, typename A>
439 void ReadVectorFromFits(const std::string& filename, std::vector<T, A>& vector) {
440  // Identify the Cfitsio data type code to be used and the expected Cfitsio image type code,
441  // based on the type used with std::vector, i.e. type of T.
442  int expected_bitpix = 0;
443  int datatype = 0;
444  IdentifyCfitsioTypes<T>(expected_bitpix, datatype);
445 
446  fitsfile* fptr = nullptr;
447  int status = 0; // It is important to initialise this to zero before every Cfitsio API call.
448  if (fits_open_image(&fptr, filename.c_str(), READONLY, &status) != 0) {
449  std::string msg =
450  "Failed to open FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
451  CII_THROW(RtctkException, msg);
452  }
453 
454  try {
455  // Read and check that the pixel format used in the FITS file corresponds to the type used
456  // for the vector object passed to this function.
457  int bitpix = -1;
458  status = 0;
459  if (fits_get_img_equivtype(fptr, &bitpix, &status) != 0) {
460  std::string msg = "Failed to read the image type from FITS file '" + filename + "'. " +
461  GetCfitsioErrorMsg(status);
462  CII_THROW(RtctkException, msg);
463  }
464  if (bitpix == LONGLONG_IMG) {
465  // NOTE: Correcting the bitpix for ULONGLONG_IMG. There is a bug in Cfitsio that returns
466  // LONGLONG_IMG instead of ULONGLONG_IMG.
467  char value[80]; // Use maximum possible FITS card size of 80 bytes.
468  status = 0;
469  int result = fits_read_keyword(fptr, "BZERO", value, nullptr, &status);
470  if (result != 0 and status != KEY_NO_EXIST) {
471  std::string msg = "Failed to read keyword BZERO from '" + filename + "'. " +
472  GetCfitsioErrorMsg(status);
473  CII_THROW(RtctkException, msg);
474  }
475  if (std::string(value) ==
476  std::to_string(std::numeric_limits<uint64_t>::max() / 2 + 1)) {
477 #ifdef ULONGLONG_IMG
478  bitpix = ULONGLONG_IMG;
479 #else
480  // If we are dealing with an older Cfitsio library that does not have ULONGLONG_IMG
481  // defined, then simply alias to using the signed version instead.
482  bitpix = LONGLONG_IMG;
483 #endif
484  }
485  }
486  if (bitpix != expected_bitpix) {
487  std::string msg = "The FITS file '" + filename + "' has the wrong image format of " +
488  CfitsioImageTypeToString(bitpix) +
489  ". Expected a FITS image of type " +
490  CfitsioImageTypeToString(expected_bitpix) + ".";
491  CII_THROW(RtctkException, msg);
492  }
493 
494  // Read and check that the number of image axes is 2.
495  int naxis = -1;
496  status = 0;
497  if (fits_get_img_dim(fptr, &naxis, &status) != 0) {
498  std::string msg = "Failed to read the number of image axes from FITS file '" +
499  filename + "'. " + GetCfitsioErrorMsg(status);
500  CII_THROW(RtctkException, msg);
501  }
502  if (naxis != 1) {
503  std::string msg = "The FITS file '" + filename +
504  "' has image dimensions that we cannot handle. Expect a 1D image "
505  "when loading as a vector.";
506  CII_THROW(RtctkException, msg);
507  }
508 
509  long nelements = -1;
510  status = 0;
511  if (fits_get_img_size(fptr, 1, &nelements, &status) != 0) {
512  std::string msg = "Failed to read the 1D image size from FITS file '" + filename +
513  "'. " + GetCfitsioErrorMsg(status);
514  CII_THROW(RtctkException, msg);
515  }
516 
517  using size_type = typename std::vector<T, A>::size_type;
518  long fpixel = 1; // Pixel start location. Cfitsio counts from 1, not 0.
519  int anynull = 0; // Boolean flag indicating if there were any null/nil pixel values.
520  vector.resize(size_type(nelements));
521  void* array = vector.data();
522  status = 0;
523  int result =
524  fits_read_pix(fptr, datatype, &fpixel, nelements, nullptr, array, &anynull, &status);
525  if (result != 0) {
526  std::string msg = "Failed to read the image from FITS file '" + filename + "'. " +
527  GetCfitsioErrorMsg(status);
528  CII_THROW(RtctkException, msg);
529  }
530  } catch (...) {
531  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
532  // exception if closing the file failed. Just log this error and rethrow the original
533  // exception.
534  status = 0;
535  if (fits_close_file(fptr, &status) != 0) {
536  LOG4CPLUS_ERROR(GetLogger(),
537  "Failed to close file '" + filename +
538  "' while handling an exception. " + GetCfitsioErrorMsg(status));
539  }
540  throw;
541  }
542 
543  status = 0;
544  if (fits_close_file(fptr, &status) != 0) {
545  std::string msg =
546  "Failed to close the FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
547  CII_THROW(RtctkException, msg);
548  }
549 }
550 
551 // The following are template specialisations for vectors and matrices of boolean values.
552 
556 template <typename A>
557 void WriteMatrixToFits(const std::string& filename, const MatrixBuffer<bool, A>& matrix) {
558  // Concert the boolean matrix to a matrix of 8 bit integers and write that to file instead.
559  MatrixBuffer<int8_t> int_matrix;
560  int_matrix.resize(matrix.GetNrows(), matrix.GetNcols());
561  for (MatrixBuffer<int8_t>::size_type n = 0; n < int_matrix.GetNrows(); ++n) {
562  for (MatrixBuffer<int8_t>::size_type m = 0; m < int_matrix.GetNcols(); ++m) {
563  int_matrix(n, m) = matrix(n, m) ? 1 : 0;
564  }
565  }
566  WriteMatrixToFits(filename, int_matrix);
567 }
568 
572 template <typename A>
573 void ReadMatrixFromFits(const std::string& filename, MatrixBuffer<bool, A>& matrix) {
574  // Load the matrix from file as 8 bit integers and convert it to a boolean matrix.
575  MatrixBuffer<int8_t> int_matrix;
576  ReadMatrixFromFits(filename, int_matrix);
577  matrix.resize(int_matrix.GetNrows(), int_matrix.GetNcols());
578  for (MatrixBuffer<int8_t>::size_type n = 0; n < int_matrix.GetNrows(); ++n) {
579  for (MatrixBuffer<int8_t>::size_type m = 0; m < int_matrix.GetNcols(); ++m) {
580  matrix(n, m) = int_matrix(n, m) == 1 ? true : false;
581  }
582  }
583 }
584 
588 template <typename A>
589 void WriteVectorToFits(const std::string& filename, const std::vector<bool, A>& vector) {
590  // Concert the boolean vector to a vector of 8 bit integers and write that to file instead.
591  std::vector<int8_t> int_vector;
592  int_vector.resize(vector.size());
593  for (std::vector<int8_t>::size_type n = 0; n < int_vector.size(); ++n) {
594  int_vector[n] = vector[n] ? 1 : 0;
595  }
596  WriteVectorToFits(filename, int_vector);
597 }
598 
602 template <typename A>
603 void ReadVectorFromFits(const std::string& filename, std::vector<bool, A>& vector) {
604  // Load the vector from file as 8 bit integers and convert it to a boolean vector.
605  std::vector<int8_t> int_vector;
606  ReadVectorFromFits(filename, int_vector);
607  vector.resize(int_vector.size());
608  for (std::vector<int8_t>::size_type n = 0; n < int_vector.size(); ++n) {
609  vector[n] = int_vector[n] == 1 ? true : false;
610  }
611 }
612 
613 } // namespace rtctk::componentFramework
614 
615 #endif // RTCTK_COMPONENTFRAMEWORK_FITSIOFUNCTIONS_HPP
rtctk::componentFramework::CfitsioDataTypeToString
std::string CfitsioDataTypeToString(int datatype)
Returns a string representation of a Cfitsio data type code.
Definition: fitsIoFunctions.cpp:54
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::MatrixBuffer::GetNrows
size_type GetNrows() const
Definition: matrixBuffer.hpp:91
rtctk::componentFramework::ReadVectorFromFits
void ReadVectorFromFits(const std::string &filename, std::vector< T, A > &vector)
Reads a FITS file containing a 1D image into a std::vector object.
Definition: fitsIoFunctions.hpp:439
rtctk::componentFramework::MatrixBuffer::resize
constexpr void resize(size_type n, size_type m)
Definition: matrixBuffer.hpp:66
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::WriteVectorToFits
void WriteVectorToFits(const std::string &filename, const std::vector< T, A > &vector)
Writes std::vector data as a 1D image to a FITS file.
Definition: fitsIoFunctions.hpp:358
matrixBuffer.hpp
Declaration of the MatrixBuffer template class used in APIs.
rtctk::componentFramework::ReadMatrixFromFits
void ReadMatrixFromFits(const std::string &filename, MatrixBuffer< T, A > &matrix)
Reads a FITS file image into a MatrixBuffer object representing a matrix.
Definition: fitsIoFunctions.hpp:236
rtctk::componentFramework::WriteMatrixToFits
void WriteMatrixToFits(const std::string &filename, const MatrixBuffer< T, A > &matrix)
Writes MatrixBuffer data representing a matrix as an image to a FITS file.
Definition: fitsIoFunctions.hpp:152
rtctk::componentFramework::RtctkException
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
rtctk::componentFramework::GetLogger
log4cplus::Logger & GetLogger(const std::string &name="")
Get handle to a specific logger (used with logging macros)
logger.hpp
Logging Support Library based on log4cplus.
rtctk::componentFramework::CfitsioImageTypeToString
std::string CfitsioImageTypeToString(int bitpix)
Returns a string representation of a Cfitsio image type code.
Definition: fitsIoFunctions.cpp:25
rtctk::componentFramework::MatrixBuffer::GetNcols
size_type GetNcols() const
Definition: matrixBuffer.hpp:95
error
void error(const char *msg)
Definition: main.cpp:38
rtctk::componentFramework::MatrixBuffer
Definition: matrixBuffer.hpp:22
rtctkExampleDataTaskGenFitsData.filename
filename
Definition: rtctkExampleDataTaskGenFitsData.py:11
rtctk::componentFramework::GetCfitsioErrorMsg
std::string GetCfitsioErrorMsg(int status)
Helper function to convert a Cfitsio status code to a human readable message.
Definition: fitsIoFunctions.cpp:16