001: #!/usr/bin/perl -w
002: #!/usr/bin/perl -d:ptkdb -w
003: #
004: 
005: use strict;
006: 
007: 
008: BEGIN
009: {
010:     #! make check
011: 
012:     push @INC, '../perl';
013: 
014:     #! make distcheck
015: 
016:     push @INC, '../../perl';
017: 
018:     #! normal run
019: 
020:     push @INC, './perl';
021: 
022:     #! after install
023: 
024:     push @INC, '/usr/local/glue/swig/perl';
025: }
026: 
027: 
028: use Data::Dumper;
029: 
030: use Getopt::Long;
031: 
032: use YAML;
033: 
034: 
035: BEGIN
036: {
037:     $SIG{__DIE__}
038:         = sub {
039:             use Carp;
040: 
041:             confess @_;
042:         };
043: }
044: 
045: 
046: my $option_commands = [];
047: my $option_gui;
048: our $option_verbose;
049: my $option_yaml_stdout;
050: 
051: 
052: sub main
053: {
054:     read_cmd_line();
055: 
056:     require Neurospaces;
057:     require Neurospaces::Exchange;
058: 
059:     my $parser = Neurospaces::Exchange::Parser->new();
060: 
061:     my $parse_error = $parser->read($ARGV[0], { verbose => $option_verbose, yaml_stdout => $option_yaml_stdout, }, );
062: 
063:     if ($parse_error)
064:     {
065:         die "$0: parsing of $ARGV[0] failed ($parse_error)";
066:     }
067: 
068:     my $model_container = $parser->{model_container};
069: 
070:     if (@$option_commands)
071:     {
072:         foreach my $command (@$option_commands)
073:         {
074: #           print "command $command\n";
075: 
076:             $model_container->querymachine($command);
077:         }
078:     }
079: 
080:     if ($option_gui)
081:     {
082:         require Neurospaces::GUI;
083: 
084:         Neurospaces::GUI::gui($0);
085:     }
086: 
087: 
088: }
089: 
090: 
091: sub read_cmd_line
092: {
093:     my $option_help;
094:     my $option_version;
095: 
096:     my $result
097:         = GetOptions
098:             (
099:              "commands=s" => $option_commands,
100:              "gui!" => \$option_gui,
101:              "help!" => \$option_help,
102:              "v|verbose+" => \$option_verbose,
103:              "version" => \$option_version,
104:              "yaml-stdout" => \$option_yaml_stdout,
105:             );
106: 
107:     if ($option_version)
108:     {
109:         require Neurospaces::Exchange;
110: 
111:         my $version = Neurospaces::Exchange::version();
112: 
113:         print $version . "\n";
114: 
115:         exit 1;
116:     }
117: 
118:     if ($option_help || @ARGV eq 0)
119:     {
120:         print
121:             "
122: $0 <model-filename>
123: 
124: $0: parse a model description, interact with the model.
125: 
126: options :
127:     --commands               execute these query machine commands after loading a file.
128:     --gui                    enter the gui.
129:     --help                   print usage information.
130:     --verbose                set verbosity level.
131:     --version                give version information.
132:     --yaml-stdout            output yamlified xml to stdout.
133: ";
134: 
135:         exit 1;
136:     }
137: }
138: 
139: 
140: main();
141: 
142: 
143: