1 #include <odindata/fileio.h>
2 #include <odindata/utils.h>
3 #include <odindata/filter.h>
31 quiet.set_cmdline_option(
"q").
set_description(
"Quiet mode: do not print progress");
34 protfile.set_cmdline_option(
"p").
set_description(
"Load this protocol for defaults");
37 parlist.set_cmdline_option(
"l").
set_description(
"Lists space-separated set of protocol parameters and exits. Use '-l help' to get a list of possible parameters and '-l all' to list all parameters. The parameter 'output-file' must be omitted when using this option.");
50 STD_cout <<
"miconv: Converts medical image data between formats." << STD_endl;
51 STD_cout <<
" File formats are automatically identified by their file extension." << STD_endl;
52 STD_cout <<
" It expects at least two filenames/directories (for the input and output file) at the end of the command line." << STD_endl;
53 STD_cout <<
" An exception is the option '-l' which requires only one filename/directory to list its content." << STD_endl;
56 STD_cout <<
"Usage: miconv [options] <input-file> [<output-file>]" << STD_endl;
57 STD_cout <<
"General options:" << STD_endl;
58 STD_cout << mopts.get_cmdline_usage(
"\t");
59 STD_cout <<
"Protocol options (overrides parameters in input data):" << STD_endl;
60 STD_cout << prot.get_cmdline_usage(
"\t");
61 STD_cout <<
"File read options (will be applied to input data before processing):" << STD_endl;
62 STD_cout << ropts.get_cmdline_usage(
"\t");
63 STD_cout <<
"File write options (will be applied to output data after processing):" << STD_endl;
64 STD_cout << wopts.get_cmdline_usage(
"\t");
65 STD_cout <<
"Filters/processing, applied in the order they appear on the command line:" << STD_endl;
67 STD_cout <<
"Other options:" << STD_endl;
69 STD_cout <<
"\t" <<
helpUsage() << STD_endl;
70 STD_cout <<
"Supported file extensions(formats):" << STD_endl;
77 int main(
int argc,
char* argv[]) {
82 char optval[ODIN_MAXCHAR];
89 if(
hasHelpOption(argc,argv)) {usage(prot_template);
return 0;}
90 if(argc<3) {usage(prot_template);
return 0;}
97 mopts.parse_cmdline_options(argc,argv);
99 if(mopts.quiet) FileIO::set_trace_status(
false);
105 if(mopts.parlist!=
"") {
109 outfile=argv[argc-1];
112 if(mopts.parlist==
"help") {
113 STD_cout <<
"Possible protocol parameters:" << STD_endl;
114 for(
unsigned int i=0; i<prot_template.
numof_pars(); i++) {
124 if(mopts.parlist==
"all") {
125 for(
unsigned int i=0; i<prot_template.
numof_pars(); i++) {
130 pars=
tokens(mopts.parlist);
133 int npars=pars.size();
134 if(npars) FileIO::set_trace_status(
false);
136 if(mopts.protfile!=
"") {
137 ODINLOG(odinlog,infoLog) <<
"Loading default protocol " << optval << STD_endl;
138 prot_template.
load(mopts.protfile);
142 prot_template.parse_cmdline_options(argc,argv,
false);
147 ropts.parse_cmdline_options(argc,argv);
149 ProgressDisplayConsole display;
152 if(!mopts.quiet) progmeter_ptr=&progmeter;
154 int readresult=
FileIO::autoread(pdmap_in, infile, ropts, prot_template, progmeter_ptr);
157 ODINLOG(odinlog,errorLog) <<
"autoread failed" << STD_endl;
166 int ndsets=pdmap_in.size();
172 sarray table(nrows,ncols);
174 for(
int ipar=0; ipar<npars; ipar++) {
175 table(0,ipar)=pars[ipar];
177 table(0,npars)=
"Dataset";
180 for(FileIO::ProtocolDataMap::const_iterator pdit=pdmap_in.begin(); pdit!=pdmap_in.end(); ++pdit) {
181 for(
int ipar=0; ipar<npars; ipar++) {
182 table(irow,ipar)=
rmblock(pdit->first.printval(pars[ipar]),
"\n",
"");
185 STD_ostringstream oss;
186 oss << pdit->second.shape();
187 table(irow,npars)=oss.str();
201 for(FileIO::ProtocolDataMap::const_iterator pdit=pdmap_in.begin(); pdit!=pdmap_in.end(); ++pdit) {
203 prot.parse_cmdline_options(argc,argv);
204 pdmap_out[prot].reference(pdit->second);
210 wopts.parse_cmdline_options(argc,argv);
215 if(!filterchain.apply(pdmap_out))
return -1;
221 if(result>0) result=0;
STD_map< Protocol, Data< float, 4 > > ProtocolDataMap
static int autowrite(const ProtocolDataMap &pdmap, const STD_string &filename, const FileWriteOpts &opts)
static int autoread(ProtocolDataMap &pdmap, const STD_string &filename, const FileReadOpts &opts, const Protocol &protocol_template, ProgressMeter *progmeter=0)
static STD_string autoformats_str(const STD_string &indent="")
STD_string get_cmdline_usage(const STD_string &lineprefix) const
LDRbase & set_description(const STD_string &descr)
virtual fileMode get_filemode() const
int load(const STD_string &filename, const LDRserBase &serializer=LDRserJDX())
LDRblock & append_member(LDRbase &ldr, const STD_string ldrlabel="")
unsigned int numof_pars() const
const STD_string & get_label() const
static bool set_log_levels(int argc, char *argv[], bool trigger_error=true)
static STD_string get_usage()
static STD_string get_memory_usage()
SeqPars & set_MatrixSize(direction dir, unsigned int size, parameterMode parmode=edit)
const char * configInfo()
int hasHelpOption(int argc, char *argv[])
STD_string print_table(const sarray &table)
STD_string rmblock(const STD_string &s, const STD_string &blockbegin, const STD_string &blockend, bool rmbegin=true, bool rmend=true, bool rmall=true, bool hierachical=false)
svector tokens(const STD_string &tokenstring, char custom_separator=0, char escape_begin='"', char escape_end='"')