Newer
Older
Mark Woolrich, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
/* CCOPYRIGHT */
#include <iostream>
#include <fstream>
#include "fslio/fslio.h"
#include "newmatap.h"
#include "newmatio.h"
// the real defaults are provided in the function parse_command_line
class globaloptions {
public:
string doffile1;
string doffile2;
string zscoresfname;
public:
globaloptions();
~globaloptions() {};
};
globaloptions globalopts;
globaloptions::globaloptions()
{
// set up defaults
zscoresfname = "zstats";
}
void print_usage(int argc, char *argv[])
{
cout << "Usage: " << argv[0] << " [options] <fsfile> <dof1> <dof2> \n"
<< " Available options are:\n"
<< " -zout <outputvol> (default is "
<< globalopts.zscoresfname << ")\n"
<< " -help\n\n";
}
void parse_command_line(int argc, char* argv[])
{
if(argc<2){
print_usage(argc,argv);
exit(1);
}
int inp = 1;
int n=1;
string arg;
char first;
while (n<argc) {
arg=argv[n];
if (arg.size()<1) { n++; continue; }
first = arg[0];
if (first!='-') {
if(inp == 1)
globalopts.doffile1 = argv[n];
globalopts.doffile2 = argv[n];
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
else
{
cerr << "Mismatched argument " << arg << endl;
break;
}
n++;
inp++;
continue;
}
// put options without arguments here
if ( arg == "-help" ) {
print_usage(argc,argv);
exit(0);
}
if (n+1>=argc)
{
cerr << "Lacking argument to option " << arg << endl;
break;
}
// put options with 1 argument here
if ( arg == "-zout") {
globalopts.zscoresfname = argv[n+1];
n+=2;
} else {
cerr << "Unrecognised option " << arg << endl;
n++;
}
} // while (n<argc)
if (globalopts.fsfname.size()<1) {
cerr << "Fs filename not found\n\n";
print_usage(argc,argv);
exit(2);
}
}
int main(int argc,char *argv[])
{
try{
parse_command_line(argc, argv);
Volume fs;
fs.read(globalopts.fsfname.c_str());
Volume dof1, dof2;
if(FslFileExists(globalopts.doffile1.c_str())){ //dof1 is avw file
dof1.read(globalopts.doffile1);
}
else {
dof1 = fs;
dof1 = atof(globalopts.doffile1.c_str());
}
if(FslFileExists(globalopts.doffile2.c_str())){ //dof2 is avw file
dof2.read(globalopts.doffile2);
}
else {
dof2 = fs;
dof2 = atof(globalopts.doffile2.c_str());
}
F2z::ComputeFStats(fs, dof1, dof2, zs);
VolumeInfo volinfo = fs.getInfo();
volinfo.intent_code = NIFTI_INTENT_ZSCORE;
volinfo.intent_p1 = 0.0;
zs.setInfo(volinfo);