-
Mark Woolrich authoredMark Woolrich authored
ftoz.cc 2.68 KiB
/* ftoz.cc
Mark Woolrich, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
/* CCOPYRIGHT */
#include <iostream>
#include <fstream>
#define WANT_STREAM
#define WANT_MATH
#include "newmatap.h"
#include "newmatio.h"
#include "f2z.h"
#include "Volume.h"
#include <string>
using namespace NEWMAT;
using namespace FILM;
using namespace MISCMATHS;
// the real defaults are provided in the function parse_command_line
class globaloptions {
public:
string fsfname;
int dof1;
int dof2;
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.fsfname = arg;
else if(inp == 2)
globalopts.dof1 = atoi(argv[n]);
else if(inp == 3)
globalopts.dof2 = atoi(argv[n]);
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());
int numTS = fs.Nrows();
cerr << numTS << endl;
Volume zs(numTS);
F2z::ComputeFStats(fs, globalopts.dof1, globalopts.dof2, zs);
zs.setDims(fs.getDims());
zs.writeAsFloat(globalopts.zscoresfname.c_str());
}
catch(Exception p_excp)
{
cerr << p_excp.what() << endl;
throw;
}
catch(...)
{
cerr << "Image error" << endl;
throw;
}
}