r357: Conversion to CTSimText shell
[ctsim.git] / tools / ctsimtext.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          ctsimtext.cpp
5 **   Purpose:       Text mode shell for CTSim
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  Jan 2001
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: ctsimtext.cpp,v 1.1 2001/01/07 22:19:44 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 #include "ct.h"
29
30 static const char* g_szIdStr = "$Id: ctsimtext.cpp,v 1.1 2001/01/07 22:19:44 kevin Exp $";
31
32 extern if1_main (int argc, char* const argv[]);
33 extern if2_main (int argc, char* const argv[]);
34 extern ifexport_main (int argc, char* const argv[]);
35 extern ifinfo_main (int argc, char* const argv[]);
36 extern phm2if_main (int argc, char* const argv[]);
37 extern phm2pj_main (int argc, char* const argv[]);
38 extern pj2if_main (int argc, char* const argv[]);
39 extern pjinfo_main (int argc, char* const argv[]);
40 extern pjrec_main (int argc, char* const argv[]);
41
42
43 void 
44 ctsimtext_usage (const char *program)
45 {
46   std::cout << "usage: " << fileBasename(program) << " ctsim-function-name ctstim-function-parameters...\n";
47   std::cout << "CTSim text shell\n\n";
48   std::cout << "  ifinfo        Image file information\n";
49   std::cout << "  if1           Single image file conversion\n";
50   std::cout << "  if2           Dual image file conversions\n";
51   std::cout << "  pjrec         Projection reconstruction\n";
52   std::cout << "  pjinfo        Projection file information\n";
53   std::cout << "  phm2if        Convert a geometric phantom into an imagefile\n";
54   std::cout << "  phm2pj        Take projections of a phantom object\n";
55   std::cout << "  ifexport      Export an imagefile to a graphics file\n";
56   std::cout << "  pj2if         Convert an projection file into an imagefile\n";
57 }
58
59
60 int 
61 ctsimtext_main (int argc, char * argv[])
62 {
63   if (argc < 2) {
64     ctsimtext_usage (argv[0]);
65     return (1);
66   }
67
68   const char* const pszFunction = argv[1];
69   argv = &argv[1];
70   argc--;
71
72   if (strcasecmp (pszFunction, "if1") == 0)
73     return if1_main (argc, argv);
74   else if (strcasecmp (pszFunction, "if2") == 0)
75     return if2_main (argc, argv);
76   else if (strcasecmp (pszFunction, "ifexport") == 0)
77     return ifexport_main (argc, argv);
78   else if (strcasecmp (pszFunction, "ifinfo") == 0)
79     return ifinfo_main (argc, argv);
80   else if (strcasecmp (pszFunction, "phm2if") == 0)
81     return phm2if_main (argc, argv);
82   else if (strcasecmp (pszFunction, "phm2pj") == 0)
83     return phm2pj_main (argc, argv);
84   else if (strcasecmp (pszFunction, "pj2if") == 0)
85     return pj2if_main (argc, argv);
86   else if (strcasecmp (pszFunction, "pjinfo") == 0)
87     return pjinfo_main (argc, argv);
88   else if (strcasecmp (pszFunction, "pjrec") == 0)
89     return pjrec_main (argc, argv);
90   else {
91     std::cout << "Unknown function name" << pszFunction << "\n\n";
92     ctsimtext_usage (argv[0]);
93     return 1;
94   }
95 }
96
97 int 
98 main (int argc, char* argv[])
99 {
100   int retval = 1;
101
102   try {
103     retval = ctsimtext_main(argc, argv);
104   } catch (exception e) {
105           std::cerr << "Exception: " << e.what() << std::endl;
106   } catch (...) {
107           std::cerr << "Unknown exception\n";
108   }
109
110   return (retval);
111 }
112