FACT++  1.0
fitscheck.cc
Go to the documentation of this file.
1 //****************************************************************
5  //****************************************************************
6 #include "Configuration.h"
7 
8 #include "externals/fits.h"
9 
10 using namespace std;
11 
12 
13 void PrintUsage()
14 {
15  cout <<
16  "fitscheck is a tool to verify the checksums in a fits file.\n"
17  "\n"
18  "Usage: fitscheck [OPTIONS] fitsfile\n"
19  //" or: fitscheck [OPTIONS]\n"
20  "\n"
21  "Return values:\n"
22  " 0: in case of success\n"
23  " 1: if the file could not be opened\n"
24  " 2: if the header checksum could not be varified and\n"
25  " 3: if the header checksum is ok but the data checksum could not be verified.\n"
26  "\n";
27  cout << endl;
28 }
29 
30 void PrintHelp()
31 {
32 }
33 
35 {
36  po::options_description configs("Fitscheck options");
37  configs.add_options()
38  ("fitsfile,f", var<string>()
39 #if BOOST_VERSION >= 104200
40  ->required()
41 #endif
42  , "Name of FITS file")
43  ;
44 
45  po::positional_options_description p;
46  p.add("fitsfile", 1); // The first positional options
47 
48  conf.AddOptions(configs);
49  conf.SetArgumentPositions(p);
50 }
51 
52 int main(int argc, const char** argv)
53 {
54  Configuration conf(argv[0]);
56  SetupConfiguration(conf);
57 
58  if (!conf.DoParse(argc, argv, PrintHelp))
59  return -1;
60 
61  if (!conf.Has("fitsfile"))
62  {
63  cerr << "Filename required." << endl;
64  return -1;
65  }
66 
67  const string fname = conf.Get<string>("fitsfile");
68 
69  cout << "Reading '" << fname << "'.." << flush;
70 
71  fits file(fname.c_str());
72  if (!file)
73  {
74  cout << "fits::open() failed: " << strerror(errno) << " [errno=" << errno << "]";
75  return 1;
76  }
77 
78  if (!file.IsHeaderOk())
79  {
80  cout << " header checksum could not be verified." << endl;
81  return 2;
82  }
83 
84  const size_t n = file.GetNumRows()/10;
85 
86  while (file.GetNextRow())
87  if (file.GetRow()<n && file.GetRow()%n==0)
88  cout << '.' << flush;
89 
90  if (!file.IsFileOk())
91  {
92  cout << " data checksum could not be verified." << endl;
93  return 3;
94  }
95 
96  cout << " file ok." << endl;
97 
98  return 0;
99 }
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
void SetupConfiguration(Configuration &conf)
Definition: fitscheck.cc:34
STL namespace.
void SetArgumentPositions(const po::positional_options_description &desc)
virtual size_t GetNumRows() const
Definition: fits.h:1031
bool Has(const std::string &var)
Definition: fits.h:54
int main(int argc, const char **argv)
Definition: fitscheck.cc:52
void AddOptions(const po::options_description &opt, bool visible=true)
Definition: Configuration.h:92
void PrintUsage()
Definition: fitscheck.cc:13
Commandline parsing, resource file parsing and database access.
Definition: Configuration.h:9
void PrintHelp()
Definition: fitscheck.cc:30
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())