6 #include <CCfits/CCfits> 10 void writeValuesFromFits(vector<int>& offsets,ofstream& targetFile,
unsigned char* fitsBuffer, vector<string> dumpList, map<string, CCfits::Column*>& colMap)
12 targetFile.precision(20);
13 map<string, CCfits::Column*>::iterator it;
14 for (it=colMap.begin(); it != colMap.end(); it++)
17 for (vector<string>::iterator jt=dumpList.begin(); jt != dumpList.end(); jt++)
27 int offset = offsets[it->second->index()-1];
28 const char* charSrc =
reinterpret_cast<char*
>(&fitsBuffer[offset]);
29 unsigned char copyBuffer[30];
30 for (
int width = 0; width<it->second->width(); width++)
32 switch (it->second->type())
35 targetFile << *charSrc;
36 charSrc +=
sizeof(char);
39 reverse_copy(charSrc, charSrc+
sizeof(
unsigned short), copyBuffer);
40 targetFile << *reinterpret_cast<const unsigned short*>(copyBuffer);
41 charSrc +=
sizeof(char);
44 reverse_copy(charSrc, charSrc+
sizeof(
short), copyBuffer);
45 targetFile << *reinterpret_cast<const short*>(copyBuffer);
46 charSrc +=
sizeof(char);
49 reverse_copy(charSrc, charSrc+
sizeof(
unsigned int), copyBuffer);
51 targetFile << *reinterpret_cast<unsigned int*>(copyBuffer);
52 charSrc +=
sizeof(int);
55 reverse_copy(charSrc, charSrc+
sizeof(
int), copyBuffer);
56 targetFile << *reinterpret_cast<int*>(copyBuffer);
57 charSrc +=
sizeof(int);
60 reverse_copy(charSrc, charSrc+
sizeof(
unsigned long), copyBuffer);
61 targetFile << *reinterpret_cast<unsigned long*>(copyBuffer);
62 charSrc +=
sizeof(int);
65 reverse_copy(charSrc, charSrc+
sizeof(
long), copyBuffer);
66 targetFile << *reinterpret_cast<long*>(copyBuffer);
67 charSrc +=
sizeof(int);
69 case CCfits::Tlonglong:
70 reverse_copy(charSrc, charSrc+
sizeof(
long long), copyBuffer);
71 targetFile << *reinterpret_cast<long long*>(copyBuffer);
72 charSrc +=
sizeof(
long long);
75 reverse_copy(charSrc, charSrc+
sizeof(
float), copyBuffer);
76 targetFile << *reinterpret_cast<float*>(copyBuffer);
77 charSrc +=
sizeof(float);
80 reverse_copy(charSrc, charSrc+
sizeof(
double), copyBuffer);
81 targetFile << *reinterpret_cast<double*>(copyBuffer);
82 charSrc +=
sizeof(double);
86 case CCfits::Tlogical:
88 case CCfits::Tcomplex:
89 case CCfits::Tdblcomplex:
92 case CCfits::VTlogical:
93 case CCfits::VTushort:
99 case CCfits::VTlonglong:
100 case CCfits::VTfloat:
101 case CCfits::VTdouble:
102 case CCfits::VTcomplex:
103 case CCfits::VTdblcomplex:
104 cout <<
"Data type not implemented yet." << endl;
108 cout <<
"THIS SHOULD NEVER BE REACHED" << endl;
128 for (map<string, CCfits::Column*>::iterator it=colMap.begin(); it != colMap.end(); it++)
130 int width = it->second->width();
131 switch (it->second->type())
134 case CCfits::Tushort:
136 sizes[it->second->index()] =
sizeof(char)*width;
140 sizes[it->second->index()] =
sizeof(int)*width;
144 sizes[it->second->index()] =
sizeof(int)*width;
146 case CCfits::Tlonglong:
147 sizes[it->second->index()] =
sizeof(
long long)*width;
150 sizes[it->second->index()] =
sizeof(float)*width;
152 case CCfits::Tdouble:
153 sizes[it->second->index()] =
sizeof(double)*width;
157 case CCfits::Tlogical:
158 case CCfits::Tstring:
159 case CCfits::Tcomplex:
160 case CCfits::Tdblcomplex:
163 case CCfits::VTlogical:
164 case CCfits::VTushort:
165 case CCfits::VTshort:
168 case CCfits::VTulong:
170 case CCfits::VTlonglong:
171 case CCfits::VTfloat:
172 case CCfits::VTdouble:
173 case CCfits::VTcomplex:
174 case CCfits::VTdblcomplex:
175 cout <<
"Data type not implemented yet." << endl;
176 return vector<int>();
179 cout <<
"THIS SHOULD NEVER BE REACHED" << endl;
180 return vector<int>();
185 for (map<int,int>::iterator it=sizes.begin(); it != sizes.end(); it++)
187 result.push_back(size);
189 if (it->first != checkIndex)
191 cout <<
"Expected index " << checkIndex <<
" found " << it->first << endl;
195 result.push_back(size);
199 int main(
int argc,
const char** argv)
202 string fileNameToLoad =
"test.fits";
203 string tableNameToLoad =
"FACT-TIME_ETIENNE";
205 vector<string> columnsToDump;
206 columnsToDump.push_back(
"Data0");
207 columnsToDump.push_back(
"Data1");
209 string outputFile =
"output.txt";
212 CCfits::FITS* file = NULL;
215 file =
new CCfits::FITS(fileNameToLoad);
217 catch (CCfits::FitsException e)
219 cout <<
"Could not open FITS file " << fileNameToLoad <<
" reason: " << e.message() << endl;
223 CCfits::Table* table;
224 const multimap< string, CCfits::ExtHDU * > extMap = file->extension();
225 if (extMap.find(tableNameToLoad) == extMap.end())
227 cout <<
"Could not open table " << tableNameToLoad <<
". Tables in file are: " << endl;
228 for (std::multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it != extMap.end(); it++)
229 cout << it->first <<
" ";
235 table =
dynamic_cast<CCfits::Table*
>(extMap.find(tableNameToLoad)->second);
238 map<string, CCfits::Column*> colMap = table->column();
239 if (columnsToDump.size() != 0)
241 for (vector<string>::iterator it=columnsToDump.begin(); it!= columnsToDump.end(); it++)
243 if (colMap.find(*it) == colMap.end())
245 cout <<
"Config-given dump list contains invalid entry " << *it << endl;
252 table->makeThisCurrent();
254 int size = offsets[offsets.size()-1];
256 unsigned char* fitsBuffer =
new unsigned char[
size];
258 ofstream targetFile(outputFile.c_str());
261 for (
int i=1;
i<=table->rows();
i++)
263 fits_read_tblbytes(file->fitsPointer(),
i, 1,
size, fitsBuffer, &status);
266 cout <<
"An error occurred while reading fits row #" <<
i <<
" error code: " << status << endl;
267 for (
unsigned int j=0;j<offsets.size(); j++)
268 cout << offsets[j] <<
" ";
int main(int argc, const char **argv)
vector< int > CalculateBufferSize(map< string, CCfits::Column * > &colMap)
void writeValuesFromFits(vector< int > &offsets, ofstream &targetFile, unsigned char *fitsBuffer, vector< string > dumpList, map< string, CCfits::Column * > &colMap)