Home
Install
Use
Develop
Support
News
Credits
hosted by
|
14 #include "FITSError.h"
22 extern bool psrfits_verbose;
30 static inline int datatype() { return TDOUBLE; }
31 static inline double null () { return 0; }
37 static inline int datatype() { return TFLOAT; }
38 static inline float null () { return fits_nullfloat; }
44 static inline int datatype() { return TSHORT; }
45 static inline short null () { return -1; }
51 static inline int datatype() { return TINT; }
52 static inline int null () { return -1; }
57 static inline int datatype() { return TLONG; }
58 static inline long null () { return -1; }
63 static inline int datatype() { return TLONGLONG; }
64 static inline long null () { return -1; }
69 static inline int datatype() { return TUINT; }
70 static inline long null () { return 0; }
76 static inline int datatype() { return TSTRING; }
77 static inline std::string null () { return ""; }
81 void* FITS_void_ptr ( const T& ptr)
83 return const_cast<T* > (&ptr);
86 void* FITS_void_ptr ( const std::string&);
90 void psrfits_update_key (fitsfile* fptr, const char* name, T data,
91 const char* comment = 0)
97 const_cast<char* >(name), &data,
98 const_cast<char* >(comment), &status);
101 throw FITSError (status, "psrfits_update_key", name);
105 void psrfits_update_key (fitsfile* fptr, const char* name,
107 const char* comment = 0);
110 void psrfits_update_key (fitsfile* fptr, const char* name,
111 const std::string& data,
112 const char* comment = 0);
115 void psrfits_update_key (fitsfile* fptr,
118 const std::string& value,
119 const char* comment = 0);
122 void psrfits_read_key (fitsfile* fptr,
126 std::string& comment);
130 void psrfits_read_key_work (fitsfile* fptr, const char* name, T* data,
137 const_cast<char* >(name), data,
142 void psrfits_read_key_work (fitsfile* fptr, const char* name, std::string*,
147 void psrfits_read_key (fitsfile* fptr, const char* name, T* data)
151 psrfits_read_key_work (fptr, name, data, &status);
153 throw FITSError (status, "psrfits_read_key", name);
158 void psrfits_read_key (fitsfile* fptr, const char* name, T* data,
159 T dfault, bool verbose = false)
163 psrfits_read_key_work (fptr, name, data, &status);
168 FITSError error (status, "psrfits_read_key", name);
169 std::cerr << error.get_message() << std::endl;
170 std::cerr << "psrfits_read_key: using default=" << dfault << std::endl;
175 std::cerr << "psrfits_read_key: " << name << "=" << *data << std::endl;
179 void psrfits_update_tdim (fitsfile* ffptr, int column, unsigned dim);
182 void psrfits_update_tdim (fitsfile* ffptr, int column,
183 unsigned dim1, unsigned dim2);
186 void psrfits_update_tdim (fitsfile* ffptr, int column,
187 unsigned dim1, unsigned dim2, unsigned dim3);
190 void psrfits_update_tdim (fitsfile* ffptr, int column,
191 unsigned dim1, unsigned dim2,
192 unsigned dim3, unsigned dim4);
195 void psrfits_update_tdim (fitsfile* ffptr, int column,
196 const std::vector<unsigned>& dims);
199 void psrfits_write_col (fitsfile* fptr, const char* name, int row,
200 const std::vector<T>& data,
201 const std::vector<unsigned>& dims)
210 std::cerr << "psrfits_write_col calling fits_get_colnum"
211 " name='" << name << "'" << std::endl;
213 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
216 throw FITSError (status, "psrfits_write_col(vector<T>)",
217 "fits_get_colnum (name=%s)", name);
219 psrfits_write_col (fptr, colnum, row, data, dims);
223 template< typename Stream>
224 void psrfits_write_col (fitsfile* fptr, const char* name, int row,
225 const Stream* stream)
234 std::cerr << "psrfits_write_col calling fits_get_colnum"
235 " name='" << name << "'" << std::endl;
237 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
240 throw FITSError (status, "psrfits_write_col(vector<T>)",
241 "fits_get_colnum (name=%s)", name);
245 psrfits_write_col (fptr, colnum, row, stream);
249 throw error += "psrfits_write_col(vector<T>," + std::string(name) + ")";
254 void psrfits_write_col (fitsfile* fptr, int colnum, int row,
255 const std::vector<T>& data,
256 const std::vector<unsigned>& dims)
261 std::cerr << "psrfits_write_col calling fits_modify_vector_len"
262 " colnum=" << colnum << " size=" << data.size() << std::endl;
264 fits_modify_vector_len (fptr, colnum, data.size(), &status);
267 throw FITSError (status, "psrfits_write_col(vector<T>)",
268 "fits_modify_vector_len (col=%d size=%u)",
269 colnum, data.size());
274 std::cerr << "psrfits_write_col calling psrfits_update_tdim" << std::endl;
276 psrfits_update_tdim (fptr, colnum, dims);
280 std::cerr << "psrfits_write_col calling fits_write_col" << std::endl;
285 const_cast<T* >(&(data[0])), &status);
288 throw FITSError (status, "psrfits_write_col(vector<T>)",
289 "fits_write_col (type=%s col=%d row=%d size=%u)",
291 colnum, row, data.size());
294 template< typename Stream>
295 void psrfits_write_col (fitsfile* fptr, int colnum, int row,
296 const Stream* stream)
300 unsigned ndat = stream->get_ndat();
303 std::cerr << "psrfits_write_col (Stream) calling fits_modify_vector_len"
304 " colnum=" << colnum << " size=" << ndat << std::endl;
306 fits_modify_vector_len (fptr, colnum, ndat, &status);
309 throw FITSError (status, "psrfits_write_col(vector<T>)",
310 "fits_modify_vector_len (col=%d size=%u)",
313 unsigned nwritten = 0;
315 unsigned buffer_size = 1024 * 1024;
317 std::vector< typename Stream::Type > tmp ( buffer_size );
318 while (nwritten < ndat)
320 if (nwritten + buffer_size > ndat)
321 buffer_size = ndat - nwritten;
323 stream->get_data (nwritten, buffer_size, &tmp[0] );
327 nwritten + 1, buffer_size,
331 throw FITSError (status, "psrfits_write_col(Stream)",
332 "fits_write_col (type=%s col=%d row=%d size=%u)",
334 colnum, row, buffer_size);
336 nwritten += buffer_size;
341 void psrfits_write_col( fitsfile *fptr, const char *name, int row,
347 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
350 throw FITSError (status, "psrfits_write_col(T)",
351 "fits_get_colnum (name=%s)", name);
354 psrfits_write_col (fptr, colnum, row, data);
358 throw error += "psrfits_write_col(T," + std::string(name) + ")";
363 void psrfits_write_col( fitsfile *fptr, int colnum, int row, const T& data )
370 FITS_void_ptr(data), &status);
373 throw FITSError (status, "psrfits_write_col(T)",
374 "col=%d row=%d", colnum, row);
378 void psrfits_read_col (fitsfile* fptr, const char* name,
379 std::vector< std::vector<T> >& data,
388 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
393 for ( unsigned i = 0; i < data.size(); i++)
397 counter, data[i].size(),
398 & null, &(data[i][0]),
402 throw FITSError( status, "psrfits_read_col",
403 "%s colnum=%d firstrow=%d firstelem=%d nelements=%d",
404 name, colnum, row, counter, data[i].size() );
406 counter += data[i].size();
412 void psrfits_read_col (fitsfile* fptr, const char* name, std::vector<T>& data,
421 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, &status);
426 if (data.size() == 0)
432 fits_get_coltype (fptr, colnum, &typecode, &repeat, &width, &status);
434 throw FITSError (status, "psrfits_read_col",
435 "fits_get_coltype (%s)", name);
437 data.resize( repeat );
448 throw FITSError (status, "psrfits_read_col", name);
452 template< typename T >
453 void psrfits_read_col_work( fitsfile *fptr, const char *name, T *data,
454 int row, T null, int* status)
457 fits_get_colnum (fptr, CASEINSEN, const_cast<char* >(name), &colnum, status);
467 void psrfits_read_col_work( fitsfile *fptr, const char *name,
469 int row, std::string& null, int* status);
472 template< typename T >
473 void psrfits_read_col( fitsfile *fptr, const char *name, T *data,
477 psrfits_read_col_work (fptr, name, data, row, null, &status);
479 throw FITSError (status, "psrfits_read_call", name);
483 template< typename T >
484 void psrfits_read_col( fitsfile *fptr, const char *name, T *data,
485 int row, T null, T dfault, bool verbose)
489 psrfits_read_col_work (fptr, name, data, row, null, &status);
494 FITSError error (status, "psrfits_read_col", name);
495 std::cerr << error.get_message() << std::endl;
496 std::cerr << "psrfits_read_col: using default=" << dfault << std::endl;
501 std::cerr << "psrfits_read_col: " << name << "=" << *data << std::endl;
506 void psrfits_init_hdu (fitsfile *fptr, const char *name, unsigned nrows=1);
509 bool psrfits_move_hdu (fitsfile *fptr, const char *name,
510 bool optional = false,
511 int table_type = BINARY_TBL, int version = 0);
514 void psrfits_clean_rows (fitsfile*);
517 void psrfits_set_rows (fitsfile*, unsigned nrow);
520 void psrfits_insert_row (fitsfile* fptr);
523 void psrfits_delete_col (fitsfile* fptr, const char* name);
A convenient exception handling class. Definition: Error.h:54
Empty template class requires specialization. Definition: psrfitsio.h:25
Generated using doxygen 1.8.17
|