source: Sophya/trunk/SophyaExt/FitsIOServer/fitsblkrw.h@ 2824

Last change on this file since 2824 was 2820, checked in by ansari, 20 years ago

1/ Ajout classes FitsInOutFile / FitsTypes / FitsIOException d'enrobage lib cfitsio
2/ Ajout classes FitsBlockRW<T> pour lecture/ecriture sur IMGHDU et Tables
3/ Ajout classes gestionnaire FITS FitsHandler<T> et FitsManager
4/ Ajout classe gestionnaires pour TArray<T> FitsArrayHandler<T>
5/ Ajout classe gestionnaire pour DataTable FitsHandler<BaseDataTable>

Reza 12 octobre 2006

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#ifndef FITSBLKRW_H
2#define FITSBLKRW_H
3
4#include "fitsinoutfile.h"
5
6namespace SOPHYA {
7
8/*!
9 \ingroup FitsIOServer
10 \brief Template class with static methods for handling bloc data
11 read from / write to fits files
12*/
13
14template <class T>
15class FitsBlockRW {
16public:
17//! Write image HDU data to a fits file
18static void WriteImageData(FitsInOutFile& fios, const T * d, size_t sz,
19 long * fpixel=NULL)
20{
21 int status = 0;
22 long fpix[5] = {1,1,1,1,1};
23 if (fpixel == NULL) fpixel = fpix;
24 T * ncd = const_cast<T *>(d);
25 fits_write_pix(fios.FitsPtr(), FitsTypes::DataType(d[0]), fpixel,
26 sz, ncd, &status);
27 if ( status ) {
28 fits_report_error(stderr, status);
29 char buff[32];
30 fits_get_errstatus(status, buff);
31 string msg = "FitsBlockRW<T>::WriteImageData() Error: " ;
32 msg += buff;
33 throw FitsIOException(msg);
34 }
35}
36
37//! Read image HDU data from a fits file
38static void ReadImageData(FitsInOutFile& fios, T * d, size_t sz,
39 long * fpixel=NULL)
40{
41 int status = 0;
42 long fpix[5] = {1,1,1,1,1};
43 if (fpixel == NULL) fpixel = fpix;
44 int anynul = 0;
45 fits_read_pix(fios.FitsPtr(), FitsTypes::DataType(d[0]), fpixel,
46 sz, NULL, d, &anynul, &status);
47 if ( status ) {
48 fits_report_error(stderr, status);
49 char buff[32];
50 fits_get_errstatus(status, buff);
51 string msg = "FitsBlockRW<T>::ReadImageData() Error: " ;
52 msg += buff;
53 throw FitsIOException(msg);
54 }
55
56}
57
58
59/*!
60 Write binary/ascii HDU data to a fits file.
61 See cfitsio function fits_write_col() for more detail.
62 \param colnum : table column number (starting from 1)
63 \param firstrow : the write operation starting row (starting from 1)
64 \param firstelem : the firstelem (for vector type columns)
65 \param d : pointer to data to be written
66 \param sz : number of data elements to be written
67*/
68static void WriteColumnData(FitsInOutFile& fios, int colnum, long firstrow,
69 long firstelem, const T * d, size_t sz)
70{
71 int status = 0;
72 T * ncd = const_cast<T *>(d);
73 fits_write_col(fios.FitsPtr(), FitsTypes::DataType(d[0]), colnum,
74 firstrow, firstelem, sz, ncd, &status);
75 if ( status ) {
76 fits_report_error(stderr, status);
77 char buff[32];
78 fits_get_errstatus(status, buff);
79 string msg = "FitsBlockRW<T>::WriteColumnData() Error: " ;
80 msg += buff;
81 throw FitsIOException(msg);
82 }
83 return;
84}
85
86/*!
87 Read binary/ascii HDU data from a fits file.
88 See cfitsio function fits_read_col() for more detail.
89 \param colnum : table column number (starting from 1)
90 \param firstrow : the read operation starting point (row) (starting from 1)
91 \param firstelem : the firstelem (for vector type columns)
92 \param d : pointer to data to be written
93 \param sz : number of data elements to be read
94*/
95static void ReadColumnData(FitsInOutFile& fios, int colnum, long firstrow,
96 long firstelem, T * d, size_t sz)
97{
98 int status = 0;
99 int anynul = 0;
100 fits_read_col(fios.FitsPtr(), FitsTypes::DataType(d[0]), colnum,
101 firstrow, firstelem, sz, NULL, d, &anynul, &status);
102 if ( status ) {
103 fits_report_error(stderr, status);
104 char buff[32];
105 fits_get_errstatus(status, buff);
106 string msg = "FitsBlockRW<T>::ReadColumnData() Error: " ;
107 msg += buff;
108 throw FitsIOException(msg);
109 }
110 return;
111}
112
113
114};
115
116} // Fin du namespace
117
118#endif
Note: See TracBrowser for help on using the repository browser.