0ca578c05d9c0e01d850f02651576fbaf1b99c47
[ctsim.git] / tools / pjinfo.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          pjfinfo.cpp
5 **   Purpose:       Convert an projection data file to an image file
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  April 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: pjinfo.cpp,v 1.1 2000/09/02 05:17:29 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 /* FILE
29  *   pjfinfo.c                  Convert Raysum to image
30  *
31  * DATE
32  *   August 2000
33  */
34
35 #include "ct.h"
36 #include "timer.h"
37
38
39 enum { O_DUMP, O_HELP, O_VERSION };
40
41 static struct option my_options[] =
42 {
43   {"dump", 0, 0, O_DUMP},
44   {"help", 0, 0, O_HELP},
45   {"version", 0, 0, O_VERSION},
46   {0, 0, 0, 0}
47 };
48
49 static const char* g_szIdStr = "$Id: pjinfo.cpp,v 1.1 2000/09/02 05:17:29 kevin Exp $";
50
51 void 
52 pjfinfo_usage (const char *program)
53 {
54   cout << "usage: " << fileBasename(program) << " proj-file [OPTIONS]" << endl;
55   cout << "Display projection file information" << endl;
56   cout << endl;
57   cout << "   --dump      Dump all scan data" << endl;
58   cout << "   --version   Print version" << endl;
59   cout << "   --help      Print this help message" << endl;
60 }
61
62           
63
64 int 
65 pjfinfo_main (const int argc, char *const argv[])
66 {
67   string pj_name;
68   bool optDump = false;
69   extern int optind;
70   Timer timerProgram;
71
72   while (1)
73     {
74       int c = getopt_long (argc, argv, "", my_options, NULL);
75       if (c == -1)
76         break;
77       
78       switch (c)
79         {
80         case O_DUMP:
81           optDump = true;
82           break;
83         case O_VERSION:
84 #ifdef VERSION
85           cout << "Version " << VERSION << endl << g_szIdStr << endl;
86 #else
87           cout << "Unknown version number" << endl;
88 #endif
89           return (0);
90         case O_HELP:
91         case '?':
92           pjfinfo_usage(argv[0]);
93           return (0);
94         default:
95           pjfinfo_usage(argv[0]);
96           return (1);
97         }
98     }
99   
100   if (argc - optind != 1) {
101     pjfinfo_usage(argv[0]);
102     return (1);
103   }
104
105   pj_name = argv[optind];
106
107   Projections pj;
108   if (! pj.read (pj_name)) {
109     sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name.c_str());
110     return (1);
111   }
112
113   if (optDump)
114     pj.printProjectionData();
115   else {
116     ostringstream os;
117     pj.printScanInfo (os);
118     cout << os.str();
119   }
120   
121   return(0);
122 }
123
124
125 #ifndef NO_MAIN
126 int 
127 main (const int argc, char *const argv[])
128 {
129   int retval = 1;
130
131   try {
132     retval = pjfinfo_main(argc, argv);
133   } catch (exception e) {
134     cerr << "Exception: " << e.what() << endl;
135   } catch (...) {
136     cerr << "Unknown exception" << endl;
137   }
138
139   return (retval);
140 }
141 #endif