Newer
Older
/* ttoz.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 "fslio/fslio.h"
#include "newmatap.h"
#include "newmatio.h"
// the real defaults are provided in the function parse_command_line
class globaloptions {
public:
string varsfname;
string cbsfname;
string doffile;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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] <varsfile> <cbsfile> <dof> \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.varsfname = arg;
else if(inp == 2)
globalopts.cbsfname = arg;
else if(inp == 3)
globalopts.doffile = arg;
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
112
113
114
115
116
117
118
119
120
121
122
123
124
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.varsfname.size()<1) {
cerr << "Vars filename not found\n\n";
print_usage(argc,argv);
exit(2);
}
}
int main(int argc,char *argv[])
{
try{
parse_command_line(argc, argv);
Volume vars, cbs, dofs;
vars.read(globalopts.varsfname.c_str());
cbs.read(globalopts.cbsfname.c_str());
int numTS = vars.Nrows();
// cerr << numTS << endl;
if(FslFileExists(globalopts.doffile.c_str())){ //dof1 is avw file
dofs.read(globalopts.doffile);
}
else {
dofs = vars;
dofs = atof(globalopts.doffile.c_str());
}
T2z::ComputeZStats(vars, cbs, dofs, zs);
VolumeInfo volinfo = vars.getInfo();
volinfo.intent_code = NIFTI_INTENT_ZSCORE;
volinfo.intent_p1 = 0.0;
zs.setInfo(volinfo);