1 /*****************************************************************************
5 ** Purpose: Convert an projection data file to an image file
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: April 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: pjinfo.cpp,v 1.4 2000/12/17 22:30:34 kevin Exp $
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.
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.
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 ******************************************************************************/
29 * pjinfo.c Convert Raysum to image
39 enum { O_BINARYHEADER, O_BINARYVIEWS, O_STARTVIEW, O_ENDVIEW, O_DUMP, O_HELP, O_VERSION };
41 static struct option my_options[] =
43 {"binaryheader", 0, 0, O_BINARYHEADER},
44 {"binaryviews", 0, 0, O_BINARYVIEWS},
45 {"startview", 1, 0, O_STARTVIEW},
46 {"endview", 1, 0, O_ENDVIEW},
47 {"dump", 0, 0, O_DUMP},
48 {"help", 0, 0, O_HELP},
49 {"version", 0, 0, O_VERSION},
53 static const char* g_szIdStr = "$Id: pjinfo.cpp,v 1.4 2000/12/17 22:30:34 kevin Exp $";
56 pjinfo_usage (const char *program)
58 std::cout << "usage: " << fileBasename(program) << " proj-file [OPTIONS]\n";
59 std::cout << "Display projection file information\n";
61 std::cout << " --binaryheader Dump binary header data\n";
62 std::cout << " --binaryviews Dump binary view data\n";
63 std::cout << " --startview n Beginning view number to display (default=0)\n";
64 std::cout << " --endview n Ending view number to display (default=last view)\n";
65 std::cout << " --dump Print all scan data ASCII format\n";
66 std::cout << " --version Print version\n";
67 std::cout << " --help Print this help message\n";
73 pjinfo_main (const int argc, char *const argv[])
77 bool optBinaryHeader = false;
78 bool optBinaryViews = false;
80 int optEndView = -1; // tells copyViewData to use default last view
85 char *endptr, *endstr;
86 int c = getopt_long (argc, argv, "", my_options, NULL);
96 optBinaryHeader = true;
99 optBinaryViews = true;
102 optStartView = strtol(optarg, &endptr, 10);
103 endstr = optarg + strlen(optarg);
104 if (endptr != endstr) {
105 std::cerr << "Error setting --startview to %s" << optarg << std::endl;
106 pjinfo_usage(argv[0]);
111 optEndView = strtol(optarg, &endptr, 10);
112 endstr = optarg + strlen(optarg);
113 if (endptr != endstr) {
114 std::cerr << "Error setting --endview to %s" << optarg << std::endl;
115 pjinfo_usage(argv[0]);
121 std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
123 std::cout << "Unknown version number\n";
128 pjinfo_usage(argv[0]);
131 pjinfo_usage(argv[0]);
136 if (argc - optind != 1) {
137 pjinfo_usage(argv[0]);
141 pj_name = argv[optind];
144 Projections::copyHeader (pj_name, std::cout);
145 else if (optBinaryViews)
146 Projections::copyViewData (pj_name, std::cout, optStartView, optEndView);
149 if (! pj.read (pj_name)) {
150 sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name.c_str());
155 pj.printProjectionData (optStartView, optEndView);
157 std::ostringstream os;
158 pj.printScanInfo (os);
159 std::cout << os.str();
169 main (const int argc, char *const argv[])
174 retval = pjinfo_main(argc, argv);
175 } catch (exception e) {
176 std::cerr << "Exception: " << e.what() << std::endl;
178 std::cerr << "Unknown exception\n";