Developer documentation
Version 3.0.3-105-gd3941f44
command.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __command_h__
18#define __command_h__
19
20
21#ifdef FLUSH_TO_ZERO
22# include <xmmintrin.h>
23#endif
24
25#include "app.h"
26#include "exec_version.h"
27#ifdef MRTRIX_PROJECT
28namespace MR {
29 namespace App {
30 void set_project_version ();
31 }
32}
33#endif
34
35#define MRTRIX_UPDATED_API
36
37#ifdef MRTRIX_AS_R_LIBRARY
38
39extern "C" void R_main (int* cmdline_argc, char** cmdline_argv)
40{
42#ifdef MRTRIX_PROJECT
43 ::MR::App::set_project_version();
44#endif
47 ::MR::App::OPTIONS.clear();
48 try {
49 usage();
51 ::MR::App::init (*cmdline_argc, cmdline_argv);
53 run ();
54 }
55 catch (MR::Exception& E) {
56 E.display();
57 return;
58 }
59 catch (int retval) {
60 return;
61 }
62}
63
64extern "C" void R_usage (char** output)
65{
68 ::MR::App::OPTIONS.clear();
69 usage();
70 std::string s = MR::App::full_usage();
71 *output = new char [s.size()+1];
72 strncpy(*output, s.c_str(), s.size()+1);
73}
74
75#else
76
77int main (int cmdline_argc, char** cmdline_argv)
78{
79#ifdef FLUSH_TO_ZERO
80 // use gcc switches: -msse -mfpmath=sse -ffast-math
81 int mxcsr = _mm_getcsr ();
82 // Sets denormal results from floating-point calculations to zero:
83 mxcsr |= (1<<15) | (1<<11); // flush-to-zero
84 // Treats denormal values used as input to floating-point instructions as zero:
85 mxcsr |= (1<<6); // denormals-are-zero
86 _mm_setcsr (mxcsr);
87#endif
89#ifdef MRTRIX_PROJECT
90 ::MR::App::set_project_version();
91#endif
92 try {
93 ::MR::App::init (cmdline_argc, cmdline_argv);
94 usage ();
97#ifdef __gui_app_h__
98 ::MR::GUI::App app (cmdline_argc, cmdline_argv);
99#endif
101 run ();
102 }
103 catch (::MR::Exception& E) {
104 E.display();
105 return 1;
106 }
107 catch (int retval) {
108 return retval;
109 }
111}
112
113#endif
114
115#endif
116
117
void run()
void usage()
void display(int log_level=0) const
Definition: exception.h:92
int main(int cmdline_argc, char **cmdline_argv)
Definition: command.h:77
std::string full_usage()
dump formatted help page [used internally]
void verify_usage()
verify that command's usage() function has set requisite fields [used internally]
void init(int argc, const char *const *argv)
initialise MRtrix and parse command-line arguments
OptionList OPTIONS
the options accepted by the command
int exit_error_code
Definition: exception.h:35
void parse_special_options()
option parsing that should happen before GUI creation [used internally]
Description DESCRIPTION
additional description of the command over and above the synopsis
void set_executable_uses_mrtrix_version()
ArgumentList ARGUMENTS
the arguments expected by the command
void parse()
do the actual parsing of the command-line [used internally]
Definition: base.h:24