Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ContrastMgrOptions.cc
Mark Woolrich, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
/* CCOPYRIGHT */
#define WANT_STREAM
#define WANT_MATH
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include "newmatap.h"
#include "newmatio.h"
#include "ContrastMgrOptions.h"
#ifndef NO_NAMESPACE
using namespace NEWMAT;
namespace TACO {
#endif
ContrastMgrOptions* ContrastMgrOptions::gopt = NULL;
void ContrastMgrOptions::parse_command_line(int argc, char** argv, ofstream& logfile)
{
if(argc<2){
print_usage(argc,argv);
exit(1);
}
int inp = 1;
int n=1;
string arg;
char first;
logfile << "Arguments: " << endl;
while (n<argc) {
arg=argv[n];
// output argument to logfile:
logfile << arg << " ";
if (arg.size()<1) { n++; continue; }
first = arg[0];
if (first!='-') {
if(inp == 1)
gopt->datadir = arg;
else if(inp == 2)
else
{
cerr << "Mismatched argument " << arg << endl;
break;
}
n++;
inp++;
continue;
}
// put options without arguments here
if ( arg == "-help" ) {
print_usage(argc,argv);
exit(0);
} else if ( arg == "-v" ) {
gopt->verbose = true;
n++;
continue;
}
if ( arg == "-cope") {
gopt->copenumber = atoi(argv[n+1]);
logfile << argv[n+1] << " ";
n+=2;
continue;
}
gopt->suffix = argv[n+1];
logfile << argv[n+1] << " ";
n+=2;
continue;
}
else if (arg == "-f") {
gopt->fcontrastfname = argv[n+1];
logfile << argv[n+1] << " ";
n+=2;
continue;
}
if (n+1>=argc)
{
cerr << "Lacking argument to option " << arg << endl;
break;
}
} // while (n<argc)
logfile << endl << "---------------------------------------------" << endl << endl;
if (gopt->datadir.size()<1) {
print_usage(argc,argv);
throw Exception("Data directory not found");
}
if (gopt->contrastfname.size()<1) {
print_usage(argc,argv);
throw Exception("Contrast filename not found");
}
}
void ContrastMgrOptions::print_usage(int argc, char *argv[])
{
cout << "Usage: " << argv[0] << " [options] <datadir> <tcontrastfile>\n\n"
<< " Available options are:\n"
<< " -v (outputs full data)\n"
<< " -cope <num> (contrast number to start labelling copes from, default is 1)\n"
<< " -suffix <string> (suffix to put on the end of the cope filename before the contrast number, default is nothing)\n"
<< " -help\n\n";
}
#ifndef NO_NAMESPACE
}
#endif