[project @ 13]
[mussa.git] / mussa.cc
index 25c83ddf2fd8da0ba0321855955b8654ceb9a27e..150d92f9e3043f658d4e76d7ab0ef1be524d2c62 100644 (file)
--- a/mussa.cc
+++ b/mussa.cc
@@ -1,56 +1,19 @@
-#include "mussa_gui_conn_window.hh"
+//  This file is part of the Mussa source distribution.
+//  http://mussa.caltech.edu/
+//  Contact author: Tristan  De Buysscher, tristan@caltech.edu
 
-char
-parse_args(int argc, char **argv, string *a_file_path, int *window, 
-           int *threshold)
-{
-  int i;
-  string an_arg;
-  char run_mode;
-
-  *window = 0;
-  *threshold = 0;
+// This program and all associated source code files are Copyright (C) 2005
+// the California Institute of Technology, Pasadena, CA, 91125 USA.  It is
+// under the GNU Public License; please see the included LICENSE.txt
+// file for more information, or contact Tristan directly.
 
-  // minimal arg reading structure, not very robust to errors
 
+#include "mussa_gui_conn_window.hh"
 
-  run_mode = 'g';
-  i = 1;
-  while (i < argc)
-  {
-    an_arg = * ++argv;
-    i++;
 
-    if (an_arg == "-v")
-    {
-      *a_file_path = * ++argv;
-      i++;
-      run_mode = 'v';
-    }
-    else if (an_arg == "-n")
-    {
-      *a_file_path = * ++argv;
-      i++;
-      run_mode = 'n';
-    }
-    else if (an_arg == "-w")
-    {
-      *window = atoi(* ++argv);
-      i++;
-    }
-    else if (an_arg == "-t")
-    {
-      *threshold = atoi(* ++argv);
-      i++;
-    }
-    else
-    {
-      *a_file_path = an_arg;
-      run_mode = 'f';
-    }
-  }
-  return run_mode;
-}
+char
+parse_args(int argc, char **argv, string *a_file_path, int *window, 
+           int *threshold, char *ana_mode, float *ent_thres);
 
 
 int main(int argc, char **argv) 
@@ -59,51 +22,171 @@ int main(int argc, char **argv)
   string a_file_path;
   char * picked_file;
   int window, threshold;
-  char run_mode;
+  float ent_thres;
+  char run_mode, ana_mode;
   int x_max=1000;
   int y_max=500;
   string err_msg;
 
+
   err_msg = "";
 
   // yeah, its horrible to be passing these by reference, but I just don't see
   // any other way without making parse_args part of MussaClass, which just
   // seems wrong (args are after all, an io type thing, and the gui only mode
   // will have it own way as well...
-  run_mode = parse_args(argc, argv, &a_file_path, &window, &threshold);
+  run_mode = parse_args(argc, argv, &a_file_path, &window, &threshold,
+                       &ana_mode, &ent_thres);
 
-  if ((run_mode == 'f') || (run_mode == 'n'))
-    err_msg = an_analysis.analyze(a_file_path, window, threshold);
-    //an_overlord.do_analysis();
+  cout << "mussa: run mode = " << run_mode;
+  cout << "\tfile_path = "<< a_file_path << endl;
+  cout << "mussa: ent_thres = " << ent_thres << endl;
 
-  if  (run_mode == 'v')
-    err_msg = an_analysis.load(a_file_path);
+  // if no error from parse args (run_mode = 'e', ie error), run in proper mode
+  if (run_mode != 'e')
+  {
+    if ((run_mode == 'f') || (run_mode == 'n'))
+    {
+      err_msg = an_analysis.load_mupa_file(a_file_path);
+      err_msg = an_analysis.analyze(window, threshold, ana_mode, ent_thres);
+      //an_overlord.do_analysis();
+    }
+
+    if (run_mode == 'v')
+      err_msg = an_analysis.load(a_file_path);
       //an_overlord.get_analysis();
 
-  // no longer needed, but still semi-useful reality check...
-  if (run_mode == 'g')
-  {
-    cout << "GTV - All Gui, All the Time\n";
-  }
+    // no longer needed, but still semi-useful reality check...
+    if (run_mode == 'g')
+    {
+      cout << "GTV - All Gui, All the Time\n";
+    }
 
-  if (err_msg == "")
-  {
-    if  ((run_mode == 'f') || (run_mode == 'v') || (run_mode == 'g'))
+    if (err_msg == "")
     {
-      //an_overlord.spawnConnView(1000,500);
-      ConnWindow *a_conn_win = new ConnWindow(x_max, y_max, "Mussa");
+      if  ((run_mode == 'f') || (run_mode == 'v') || (run_mode == 'g'))
+      {
+       //an_overlord.spawnConnView(1000,500);
+       ConnWindow *a_conn_win = new ConnWindow(x_max, y_max, "Mussa");
 
-      // we have an analysis already if in these 2 modes
-      if  ((run_mode == 'f') || (run_mode == 'v'))
-        a_conn_win->add_ana(&an_analysis);
+       // we have an analysis already if in these 2 modes
+       if  ((run_mode == 'f') || (run_mode == 'v'))
+         a_conn_win->add_ana(&an_analysis);
 
-      Fl::run();
+       Fl::run();
+      }
     }
+    else
+      cout << err_msg << endl;
+  }
+}
+
+
+// minimal arg reading function, not very robust to errors
+char
+parse_args(int argc, char **argv, string *a_file_path, int *window, 
+           int *threshold, char *ana_mode, float *ent_thres)
+{
+  int i, else_i;
+  string an_arg;
+  char run_mode;
+
+  // initialize these to 0 as flag if they are not changed
+  *window = 0;
+  *threshold = 0;
+  *ent_thres = 0.0;
+  run_mode = 'e'; //error default if no run mode set implicitly or explicitly
+  *ana_mode = 't'; // default to transitivie analyses mode
+
+
+  // no args means gui only mode
+  if (argc == 1)
+    run_mode = 'g';
+  // 1 arg means its a mupa file and run in full mode
+  /*
+  else if (argc == 2)
+  {
   }
+  */
   else
-    cout << err_msg << endl;
+  {
+    else_i = 0;
+    i = 1;
+    while (i < argc)
+    {
+      an_arg = * ++argv;
+      i++;
+
+      // see what alternate mode the user wants to run in
+      if (an_arg == "-m")
+      {
+       an_arg = * ++argv;
+       i++;
+       if ( (an_arg == "v") || (an_arg == "n") ) //only 2 valid modes so far
+         run_mode = an_arg[0];
+       else
+       {
+         cout << "Error: \'" << an_arg;
+         cout << "\' is not a valid analysis mode for -a argument" << endl; 
+         run_mode = 'e';
+       }
+       *a_file_path = * ++argv;
+       i++;
+      }
+      // alternate analyses modes
+      else if (an_arg == "-a")
+      {
+       an_arg = * ++argv;
+       i++;
+       // t = transitive, r = radial, e = entropy
+       if ( (an_arg == "t") || (an_arg == "r") || (an_arg == "e") )
+         *ana_mode = an_arg[0];
+       else
+       {
+         cout << "Error: \'" << an_arg;
+         cout << "\' is not a valid run mode for -m argument" << endl; 
+         run_mode = 'e';
+       }
+
+      }
+      else if (an_arg == "-w") // alternate window size arg
+      {
+       *window = atoi(* ++argv);
+       i++;
+      }
+      else if (an_arg == "-t") // alternate threshold arg
+      {
+       *threshold = atoi(* ++argv);
+       i++;
+      }
+      else if (an_arg == "-et") // alternate entropy threshold arg
+      {
+       *ent_thres = atof(* ++argv);
+       i++;
+      }
+      else
+      {
+       if (else_i == 0)
+       {
+         *a_file_path = an_arg;
+         run_mode = 'f';
+         else_i++;
+       }
+       else
+       {
+         //cout << "Error, unknown arg: \'" << an_arg << "\'" << endl;
+         cout << "Error, too many filenames: \'" << an_arg << "\'" << endl;
+         run_mode == 'e';
+       }
+      }
+    }
+  }
+
+  return run_mode;
 }
 
+
 /*
       cout << "fee\n";
       cout << "fie\n";