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

Last change on this file since 14915 was 13006, checked in by tbretz, 13 years ago
Reformated the output to make it better fit the help2man conversion.
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 3 if the"
25 " header checksum is ok but the data checksum could not be"
26 " verified."
27 "\n";
28 cout << endl;
29}
30
31void PrintHelp()
32{
33}
34
35void SetupConfiguration(Configuration& conf)
36{
37 po::options_description configs("Fitscheck options");
38 configs.add_options()
39 ("fitsfile,f", var<string>()
40#if BOOST_VERSION >= 104200
41 ->required()
42#endif
43 , "Name of FITS file")
44 ;
45
46 po::positional_options_description p;
47 p.add("fitsfile", 1); // The first positional options
48
49 conf.AddOptions(configs);
50 conf.SetArgumentPositions(p);
51}
52
53int main(int argc, const char** argv)
54{
55 Configuration conf(argv[0]);
56 conf.SetPrintUsage(PrintUsage);
57 SetupConfiguration(conf);
58
59 if (!conf.DoParse(argc, argv, PrintHelp))
60 return -1;
61
62 if (!conf.Has("fitsfile"))
63 {
64 cerr << "Filename required." << endl;
65 return -1;
66 }
67
68 const string fname = conf.Get<string>("fitsfile");
69
70 cout << "Reading '" << fname << "'.." << flush;
71
72 fits file(fname.c_str());
73 if (!file)
74 {
75 cout << "fits::open() failed: " << strerror(errno) << " [errno=" << errno << "]";
76 return 1;
77 }
78
79 if (!file.IsHeaderOk())
80 {
81 cout << " header checksum could not be verified." << endl;
82 return 2;
83 }
84
85 const size_t n = file.GetNumRows()/10;
86
87 while (file.GetNextRow())
88 if (file.GetRow()<n && file.GetRow()%n==0)
89 cout << '.' << flush;
90
91 if (!file.IsFileOk())
92 {
93 cout << " data checksum could not be verified." << endl;
94 return 3;
95 }
96
97 cout << " file ok." << endl;
98
99 return 0;
100}
Note: See TracBrowser for help on using the repository browser.