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