massive code move
[mussa.git] / mussa.cxx
1 //  This file is part of the Mussa source distribution.
2 //  http://mussa.caltech.edu/
3 //  Contact author: Tristan  De Buysscher, tristan@caltech.edu
4
5 // This program and all associated source code files are Copyright (C) 2005
6 // the California Institute of Technology, Pasadena, CA, 91125 USA.  It is
7 // under the GNU Public License; please see the included LICENSE.txt
8 // file for more information, or contact Tristan directly.
9
10
11 #include "ConnWindow.hh"
12 #include <iostream>
13 using namespace std;
14
15 char
16 parse_args(int argc, char **argv, string *a_file_path, int *window, 
17            int *threshold, char *ana_mode, float *ent_thres);
18
19
20 int main(int argc, char **argv) 
21 {
22   Mussa an_analysis;
23   string a_file_path;
24   char * picked_file;
25   int window, threshold;
26   float ent_thres;
27   char run_mode, ana_mode;
28   int x_max=1000;
29   int y_max=500;
30   string err_msg;
31
32
33   err_msg = "";
34
35   // yeah, its horrible to be passing these by reference, but I just don't see
36   // any other way without making parse_args part of MussaClass, which just
37   // seems wrong (args are after all, an io type thing, and the gui only mode
38   // will have it own way as well...
39   run_mode = parse_args(argc, argv, &a_file_path, &window, &threshold,
40                         &ana_mode, &ent_thres);
41
42   cout << "mussa: run mode = " << run_mode;
43   cout << "\tfile_path = "<< a_file_path << endl;
44   cout << "mussa: ent_thres = " << ent_thres << endl;
45
46   // if no error from parse args (run_mode = 'e', ie error), run in proper mode
47   if (run_mode != 'e')
48   {
49     if ((run_mode == 'f') || (run_mode == 'n'))
50     {
51       err_msg = an_analysis.load_mupa_file(a_file_path);
52       err_msg = an_analysis.analyze(window, threshold, ana_mode, ent_thres);
53       //an_overlord.do_analysis();
54     }
55
56     if (run_mode == 'v')
57       err_msg = an_analysis.load(a_file_path);
58       //an_overlord.get_analysis();
59
60     // no longer needed, but still semi-useful reality check...
61     if (run_mode == 'g')
62     {
63       cout << "GTV - All Gui, All the Time\n";
64     }
65
66     if (err_msg == "")
67     {
68       if  ((run_mode == 'f') || (run_mode == 'v') || (run_mode == 'g'))
69       {
70         //an_overlord.spawnConnView(1000,500);
71         ConnWindow *a_conn_win = new ConnWindow(x_max, y_max, "Mussa");
72
73         // we have an analysis already if in these 2 modes
74         if  ((run_mode == 'f') || (run_mode == 'v'))
75           a_conn_win->add_ana(&an_analysis);
76
77         Fl::run();
78       }
79     }
80     else
81       cout << err_msg << endl;
82   }
83 }
84
85
86 // minimal arg reading function, not very robust to errors
87 char
88 parse_args(int argc, char **argv, string *a_file_path, int *window, 
89            int *threshold, char *ana_mode, float *ent_thres)
90 {
91   int i, else_i;
92   string an_arg;
93   char run_mode;
94
95   // initialize these to 0 as flag if they are not changed
96   *window = 0;
97   *threshold = 0;
98   *ent_thres = 0.0;
99   run_mode = 'e'; //error default if no run mode set implicitly or explicitly
100   *ana_mode = 't'; // default to transitivie analyses mode
101
102
103  
104   // no args means gui only mode
105   if (argc == 1)
106     run_mode = 'g';
107   // 1 arg means its a mupa file and run in full mode
108   /*
109   else if (argc == 2)
110   {
111   }
112   */
113   else
114   {
115     else_i = 0;
116     i = 1;
117     while (i < argc)
118     {
119       an_arg = * ++argv;
120       i++;
121
122       // see what alternate mode the user wants to run in
123       if (an_arg == "-m")
124       {
125         an_arg = * ++argv;
126         i++;
127         if ( (an_arg == "v") || (an_arg == "n") ) //only 2 valid modes so far
128           run_mode = an_arg[0];
129         else
130         {
131           cout << "Error: \'" << an_arg;
132           cout << "\' is not a valid analysis mode for -a argument" << endl; 
133           run_mode = 'e';
134         }
135         *a_file_path = * ++argv;
136         i++;
137       }
138       // alternate analyses modes
139       else if (an_arg == "-a")
140       {
141         an_arg = * ++argv;
142         i++;
143         // t = transitive, r = radial, e = entropy
144         if ( (an_arg == "t") || (an_arg == "r") || (an_arg == "e") )
145           *ana_mode = an_arg[0];
146         else
147         {
148           cout << "Error: \'" << an_arg;
149           cout << "\' is not a valid run mode for -m argument" << endl; 
150           run_mode = 'e';
151         }
152
153       }
154       else if (an_arg == "-w") // alternate window size arg
155       {
156         *window = atoi(* ++argv);
157         i++;
158       }
159       else if (an_arg == "-t") // alternate threshold arg
160       {
161         *threshold = atoi(* ++argv);
162         i++;
163       }
164       else if (an_arg == "-et") // alternate entropy threshold arg
165       {
166         *ent_thres = atof(* ++argv);
167         i++;
168       }
169       else
170       {
171         if (else_i == 0)
172         {
173           *a_file_path = an_arg;
174           run_mode = 'f';
175           else_i++;
176         }
177         else
178         {
179           //cout << "Error, unknown arg: \'" << an_arg << "\'" << endl;
180           cout << "Error, too many filenames: \'" << an_arg << "\'" << endl;
181           run_mode == 'e';
182         }
183       }
184     }
185   }
186
187   return run_mode;
188 }
189
190
191 /*
192       cout << "fee\n";
193       cout << "fie\n";
194       cout << "foe\n";
195       cout << "fum\n";
196 */