Home
Install
Use
Develop
Support
News
Credits
hosted by
|
15#include "ReferenceTo.h"
24extern bool psrfits_verbose;
32 static inline int datatype() { return TDOUBLE; }
33 static inline double null () { return 0; }
39 static inline int datatype() { return TFLOAT; }
40 static inline float null () { return fits_nullfloat; }
46 static inline int datatype() { return TSHORT; }
47 static inline short null () { return -1; }
53 static inline int datatype() { return TINT; }
54 static inline int null () { return -1; }
59 static inline int datatype() { return TLONG; }
60 static inline long null () { return -1; }
65 static inline int datatype() { return TLONGLONG; }
66 static inline long null () { return -1; }
71 static inline int datatype() { return TUINT; }
72 static inline long null () { return 0; }
78 static inline int datatype() { return TSTRING; }
79 static inline std::string null () { return ""; }
85 static inline int datatype() { return TCOMPLEX; }
86 static inline float null () { return 0; }
92 static inline int datatype() { return TDBLCOMPLEX; }
93 static inline double null () { return 0; }
97void* FITS_void_ptr ( const T& ptr)
99 return const_cast<T* > (&ptr);
102void* FITS_void_ptr ( const std::string&);
106void psrfits_update_key (fitsfile* fptr, const char* name, T data, const char* comment = 0)
112 const_cast<char* >(name), &data,
113 const_cast<char* >(comment), &status);
116 throw FITSError (status, "psrfits_update_key", name);
120void psrfits_update_key (fitsfile* fptr, const char* name,
122 const char* comment = 0);
125void psrfits_update_key (fitsfile* fptr, const char* name,
126 const std::string& data,
127 const char* comment = 0);
130void psrfits_update_key (fitsfile* fptr,
133 const std::string& value,
134 const char* comment = 0);
137void psrfits_read_key (fitsfile* fptr,
141 std::string& comment);
145void psrfits_read_key_work (fitsfile* fptr, const char* name, T* data, int* status)
151 const_cast<char* >(name), data,
156void psrfits_read_key_work (fitsfile* fptr, const char* name, std::string*,
161void psrfits_read_key (fitsfile* fptr, const char* name, T* data)
165 psrfits_read_key_work (fptr, name, data, &status);
167 throw FITSError (status, "psrfits_read_key", name);
174template< typename Class, typename T>
175void psrfits_read_key (fitsfile* fptr, const char* name, Class* instance, void(Class::*set)(T))
178 psrfits_read_key (fptr, name, &val);
179 (instance->*set)(val);
186template< typename Class, typename T>
187void psrfits_read_key (fitsfile* fptr, const char* name, Reference::To<Class>& instance, void(Class::*set)(T))
190 psrfits_read_key (fptr, name, &val);
191 (instance->*set)(val);
196void psrfits_read_key (fitsfile* fptr, const char* name, T* data, T dfault, bool verbose = false)
200 psrfits_read_key_work (fptr, name, data, &status);
205 FITSError error (status, "psrfits_read_key", name);
206 std::cerr << error.get_message() << std::endl;
207 std::cerr << "psrfits_read_key: using default=" << dfault << std::endl;
212 std::cerr << "psrfits_read_key: " << name << "=" << *data << std::endl;
216void psrfits_update_tdim (fitsfile* ffptr, int column, unsigned dim);
219void psrfits_update_tdim (fitsfile* ffptr, int column,
220 unsigned dim1, unsigned dim2);
223void psrfits_update_tdim (fitsfile* ffptr, int column,
224 unsigned dim1, unsigned dim2, unsigned dim3);
227void psrfits_update_tdim (fitsfile* ffptr, int column,
228 unsigned dim1, unsigned dim2,
229 unsigned dim3, unsigned dim4);
232void psrfits_update_tdim (fitsfile* ffptr, int column,
233 const std::vector<unsigned>& dims);
236void psrfits_write_col (fitsfile* fptr, const char* name, int row,
237 const std::vector<T>& data,
238 const std::vector<unsigned>& dims)
247 std::cerr << "psrfits_write_col calling fits_get_colnum"
248 " name='" << name << "'" << std::endl;
250 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
253 throw FITSError (status, "psrfits_write_col(vector<T>)",
254 "fits_get_colnum (name=%s)", name);
256 psrfits_write_col (fptr, colnum, row, data, dims);
260template< typename Stream>
261void psrfits_write_col (fitsfile* fptr, const char* name, int row,
262 const Stream* stream)
271 std::cerr << "psrfits_write_col calling fits_get_colnum"
272 " name='" << name << "'" << std::endl;
274 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
277 throw FITSError (status, "psrfits_write_col(vector<T>)",
278 "fits_get_colnum (name=%s)", name);
282 psrfits_write_col (fptr, colnum, row, stream);
286 throw error += "psrfits_write_col(vector<T>," + std::string(name) + ")";
291void psrfits_write_col (fitsfile* fptr, int colnum, int row,
292 const std::vector<T>& data,
293 const std::vector<unsigned>& dims)
298 std::cerr << "psrfits_write_col calling fits_modify_vector_len"
299 " colnum=" << colnum << " size=" << data.size() << std::endl;
301 fits_modify_vector_len (fptr, colnum, data.size(), &status);
304 throw FITSError (status, "psrfits_write_col(vector<T>)",
305 "fits_modify_vector_len (col=%d size=%u)",
306 colnum, data.size());
311 std::cerr << "psrfits_write_col calling psrfits_update_tdim" << std::endl;
313 psrfits_update_tdim (fptr, colnum, dims);
317 std::cerr << "psrfits_write_col calling fits_write_col" << std::endl;
322 const_cast<T* >(&(data[0])), &status);
325 throw FITSError (status, "psrfits_write_col(vector<T>)",
326 "fits_write_col (type=%s col=%d row=%d size=%u)",
328 colnum, row, data.size());
331template< typename Stream>
332void psrfits_write_col (fitsfile* fptr, int colnum, int row,
333 const Stream* stream)
337 unsigned ndat = stream->get_ndat();
340 std::cerr << "psrfits_write_col (Stream) calling fits_modify_vector_len"
341 " colnum=" << colnum << " size=" << ndat << std::endl;
343 fits_modify_vector_len (fptr, colnum, ndat, &status);
346 throw FITSError (status, "psrfits_write_col(vector<T>)",
347 "fits_modify_vector_len (col=%d size=%u)",
350 unsigned nwritten = 0;
352 unsigned buffer_size = 1024 * 1024;
354 std::vector< typename Stream::Type > tmp ( buffer_size );
355 while (nwritten < ndat)
357 if (nwritten + buffer_size > ndat)
358 buffer_size = ndat - nwritten;
360 stream->get_data (nwritten, buffer_size, &tmp[0] );
364 nwritten + 1, buffer_size,
368 throw FITSError (status, "psrfits_write_col(Stream)",
369 "fits_write_col (type=%s col=%d row=%d size=%u)",
371 colnum, row, buffer_size);
373 nwritten += buffer_size;
378void psrfits_write_col( fitsfile *fptr, const char *name, int row,
384 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
387 throw FITSError (status, "psrfits_write_col(T)",
388 "fits_get_colnum (name=%s)", name);
391 psrfits_write_col (fptr, colnum, row, data);
395 throw error += "psrfits_write_col(T," + std::string(name) + ")";
400void psrfits_write_col( fitsfile *fptr, int colnum, int row, const T& data )
407 FITS_void_ptr(data), &status);
410 throw FITSError (status, "psrfits_write_col(T)",
411 "col=%d row=%d", colnum, row);
415void psrfits_read_col (fitsfile* fptr, const char* name,
416 std::vector< std::vector<T> >& data,
425 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
430 for ( unsigned i = 0; i < data.size(); i++)
434 counter, data[i].size(),
435 &null, &(data[i][0]),
439 throw FITSError( status, "psrfits_read_col",
440 "%s colnum=%d firstrow=%d firstelem=%d nelements=%d",
441 name, colnum, row, counter, data[i].size() );
443 counter += data[i].size();
449void psrfits_read_col (fitsfile* fptr, const char* name, std::vector<T>& data,
458 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
463 if (data.size() == 0)
469 fits_get_coltype (fptr, colnum, &typecode, &repeat, &width, &status);
471 throw FITSError (status, "psrfits_read_col",
472 "fits_get_coltype (%s)", name);
474 data.resize( repeat );
485 throw FITSError (status, "psrfits_read_col", name);
489template< typename T >
490void psrfits_read_col_work( fitsfile *fptr, const char *name, T *data,
491 int row, T null, int* status)
494 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, status);
504void psrfits_read_col_work( fitsfile *fptr, const char *name,
506 int row, std::string& null, int* status);
509template< typename T >
510void psrfits_read_col( fitsfile *fptr, const char *name, T *data,
514 psrfits_read_col_work (fptr, name, data, row, null, &status);
516 throw FITSError (status, "psrfits_read_call", name);
520template< typename T >
521void psrfits_read_col( fitsfile *fptr, const char *name, T *data,
522 int row, T null, T dfault, bool verbose)
526 psrfits_read_col_work (fptr, name, data, row, null, &status);
531 FITSError error (status, "psrfits_read_col", name);
532 std::cerr << error.get_message() << std::endl;
533 std::cerr << "psrfits_read_col: using default=" << dfault << std::endl;
538 std::cerr << "psrfits_read_col: " << name << "=" << *data << std::endl;
543void psrfits_init_hdu (fitsfile *fptr, const char *name, unsigned nrows=1);
546bool psrfits_move_hdu (fitsfile *fptr, const char *name,
547 bool optional = false,
548 int table_type = BINARY_TBL, int version = 0);
551void psrfits_clean_rows (fitsfile*);
554void psrfits_set_rows (fitsfile*, unsigned nrow);
557void psrfits_insert_row (fitsfile* fptr);
560void psrfits_delete_col (fitsfile* fptr, const char* name);
A convenient exception handling class. Definition Error.h:54
Template class manages Reference::Able objects. Definition ReferenceTo.h:25
Empty template class requires specialization. Definition psrfitsio.h:27
Generated using doxygen 1.14.0
|