source: trunk/FACT++/src/fitscheck.cc@ 17168

Last change on this file since 17168 was 14930, checked in by tbretz, 12 years ago
Reformatted help output.
File size: 2.2 KB
Line 
1//****************************************************************
2/**
3
4 */
5 //****************************************************************
6#include "Configuration.h"
7
8#include "externals/fits.h"
9
10using namespace std;
11
12
13void 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
30void PrintHelp()
31{
32}
33
34void SetupConfiguration(Configuration& conf)
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
52int main(int argc, const char** argv)
53{
54 Configuration conf(argv[0]);
55 conf.SetPrintUsage(PrintUsage);
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}
Note: See TracBrowser for help on using the repository browser.