FACT++  1.0
int main ( int  argc,
const char **  argv 
)

Definition at line 199 of file simpleFitsDumper.cc.

References CalculateBufferSize(), i, numRows, size, and writeValuesFromFits().

200 {
201  //set the names of the file and table to be loaded
202  string fileNameToLoad = "test.fits";
203  string tableNameToLoad = "FACT-TIME_ETIENNE";
204  //set the vector of columns to be dumped
205  vector<string> columnsToDump;
206  columnsToDump.push_back("Data0");
207  columnsToDump.push_back("Data1");
208  //set the name of the output text file
209  string outputFile = "output.txt";
210 
211  //load the fits file
212  CCfits::FITS* file = NULL;
213  try
214  {
215  file = new CCfits::FITS(fileNameToLoad);
216  }
217  catch (CCfits::FitsException e)
218  {
219  cout << "Could not open FITS file " << fileNameToLoad << " reason: " << e.message() << endl;
220  return -1;
221  }
222  //check if the selected table indeed exists in the loaded file. If so, load it. Otherwise display the existing tables
223  CCfits::Table* table;
224  const multimap< string, CCfits::ExtHDU * > extMap = file->extension();
225  if (extMap.find(tableNameToLoad) == extMap.end())
226  {
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 << " ";
230  cout << endl;
231  delete file;
232  return -1;
233  }
234  else
235  table = dynamic_cast<CCfits::Table*>(extMap.find(tableNameToLoad)->second);
236  int numRows = table->rows();
237  //check that the given column names are indeed part of that table
238  map<string, CCfits::Column*> colMap = table->column();
239  if (columnsToDump.size() != 0)
240  {
241  for (vector<string>::iterator it=columnsToDump.begin(); it!= columnsToDump.end(); it++)
242  {
243  if (colMap.find(*it) == colMap.end())
244  {
245  cout << "Config-given dump list contains invalid entry " << *it << endl;
246  delete file;
247  return -1;
248  }
249  }
250  }
251  //dump the requested columns
252  table->makeThisCurrent();
253  vector<int> offsets = CalculateBufferSize(colMap);
254  int size = offsets[offsets.size()-1];
255  offsets.pop_back();
256  unsigned char* fitsBuffer = new unsigned char[size];
257 
258  ofstream targetFile(outputFile.c_str());
259  int status = 0;
260 
261  for (int i=1;i<=table->rows(); i++)
262  {
263  fits_read_tblbytes(file->fitsPointer(), i, 1, size, fitsBuffer, &status);
264  if (status)
265  {
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] << " ";
269  cout << endl;
270  }
271  writeValuesFromFits(offsets, targetFile, fitsBuffer, columnsToDump, colMap);
272  }
273  delete file;
274  return 0;
275 }
int i
Definition: db_dim_client.c:21
vector< int > CalculateBufferSize(map< string, CCfits::Column * > &colMap)
int size
Definition: db_dim_server.c:17
uint32_t numRows
Definition: FITS.h:72
void writeValuesFromFits(vector< int > &offsets, ofstream &targetFile, unsigned char *fitsBuffer, vector< string > dumpList, map< string, CCfits::Column * > &colMap)

+ Here is the call graph for this function: