10 |
#include "Diderot/diderot.h" |
#include "Diderot/diderot.h" |
11 |
#include <teem/hest.h> |
#include <teem/hest.h> |
12 |
|
|
13 |
|
bool VerboseFlg = false; //! true if running in verbose mode |
14 |
|
bool TimingFlg = false; //! true if timing computation |
15 |
|
bool NrrdOutputFlg = false; //! true if output is in Nrrd format |
16 |
|
|
17 |
//! Option type tags |
//! Option type tags |
18 |
typedef enum { |
typedef enum { |
19 |
optTypeUnknown, // 0 |
optTypeUnknown, // 0 |
43 |
void *valp; //!< pointer to Diderot global variable being set |
void *valp; //!< pointer to Diderot global variable being set |
44 |
} opt_def_t; |
} opt_def_t; |
45 |
|
|
46 |
/*! container for *all* options, and the machinery for parsing them, |
/*! container for *all* options, the machinery for parsing them, |
47 |
* and means of managing their allocation. There is an opaque typedef |
* and means of managing their allocation. There is an opaque typedef |
48 |
* around this in src/include/Diderot/options.h. |
* around this in src/include/Diderot/options.h. |
49 |
* |
* |
62 |
* was reallocated for a different length. |
* was reallocated for a different length. |
63 |
*/ |
*/ |
64 |
struct Diderot_struct_options { |
struct Diderot_struct_options { |
65 |
char *progInfo; //!< documentation string for describing whole program, |
char *progInfo; //!< documentation string for describing whole |
66 |
//! intended to be one or more sentences |
//! program, intended to be one or more sentences |
67 |
hestOpt *hopt; //!< dynamically managed hest options |
hestOpt *hopt; //!< dynamically managed hest options |
68 |
hestParm *hparm; //!< hest parameters |
hestParm *hparm; //!< hest parameters |
69 |
opt_def_t **odef; //!< dynamically reallocated via odefArr |
opt_def_t **odef; //!< dynamically reallocated via odefArr |
96 |
return 0; |
return 0; |
97 |
} |
} |
98 |
|
|
99 |
/*! create the container for all option information |
/*! create the container for all option information and register standard |
100 |
|
* command-line options. |
101 |
*/ |
*/ |
102 |
Diderot_Options_t *Diderot_OptNew () |
Diderot_Options_t *Diderot_OptNew () |
103 |
{ |
{ |
104 |
static const char *me = "Diderot_Options_New"; |
static const char *me = "Diderot_Options_New"; |
105 |
Diderot_Options_t *dopts = AIR_CALLOC(1, Diderot_Options_t); |
Diderot_Options_t *opts = AIR_CALLOC(1, Diderot_Options_t); |
106 |
if (dopts == 0) { |
if (opts == 0) { |
107 |
fprintf(stderr, "%s: unable to allocate output\n", me); |
fprintf(stderr, "%s: unable to allocate output\n", me); |
108 |
exit(1); |
exit(1); |
109 |
} |
} |
110 |
dopts->progInfo = NULL; |
opts->progInfo = 0; |
111 |
dopts->mop = airMopNew(); |
opts->mop = airMopNew(); |
112 |
dopts->hopt = NULL; |
opts->hopt = 0; |
113 |
dopts->hparm = hestParmNew(); |
opts->hparm = hestParmNew(); |
114 |
dopts->hparm->noArgsIsNoProblem = AIR_TRUE; |
opts->hparm->noArgsIsNoProblem = AIR_TRUE; |
115 |
airMopAdd(dopts->mop, dopts->hparm, (airMopper)hestParmFree, airMopAlways); |
airMopAdd (opts->mop, opts->hparm, (airMopper)hestParmFree, airMopAlways); |
116 |
dopts->odef = NULL; |
opts->odef = 0; |
117 |
dopts->odefNum = 0; |
opts->odefNum = 0; |
118 |
/* |
/* |
119 |
** the airArray odefArr manages the allocation of odef, and as a |
** the airArray odefArr manages the allocation of odef, and as a |
120 |
** convenience also sets odefNum to the number of values reliably |
** convenience also sets odefNum to the number of values reliably |
121 |
** set in odef |
** set in odef |
122 |
*/ |
*/ |
123 |
dopts->odefArr = airArrayNew ( |
opts->odefArr = airArrayNew ( |
124 |
(void**)(&dopts->odef), |
(void**)(&opts->odef), |
125 |
&dopts->odefNum, |
&opts->odefNum, |
126 |
sizeof(opt_def_t*), |
sizeof(opt_def_t*), |
127 |
8 /* allocation increment */); |
8 /* allocation increment */); |
128 |
|
|
129 |
if (dopts->odefArr == 0) { |
if (opts->odefArr == 0) { |
130 |
fprintf(stderr, "%s: unable to allocate option array\n", me); |
fprintf(stderr, "%s: unable to allocate option array\n", me); |
131 |
exit(1); |
exit(1); |
132 |
} |
} |
135 |
** elements I of odef, and will call optDefNix(odef[I]) for |
** elements I of odef, and will call optDefNix(odef[I]) for |
136 |
** elements of odef that are about to be freed |
** elements of odef that are about to be freed |
137 |
*/ |
*/ |
138 |
airArrayPointerCB (dopts->odefArr, OptDefNew, optDefNix); |
airArrayPointerCB (opts->odefArr, OptDefNew, optDefNix); |
139 |
airMopAdd (dopts->mop, dopts->odefArr, (airMopper)airArrayNuke, airMopAlways); |
airMopAdd (opts->mop, opts->odefArr, (airMopper)airArrayNuke, airMopAlways); |
140 |
|
|
141 |
|
// register standard command-line options |
142 |
|
Diderot_OptAddFlag (opts, "verbose", "enable runtime-system messages", &VerboseFlg); |
143 |
|
Diderot_OptAddFlag (opts, "timing", "enable execution timing", &TimingFlg); |
144 |
|
Diderot_OptAddFlag (opts, "nrrd", "enable nrrd output", &NrrdOutputFlg); |
145 |
|
|
146 |
return dopts; |
return opts; |
147 |
} |
} |
148 |
|
|
149 |
/*! free everything associated with a Diderot_Options_t |
/*! free everything associated with a Diderot_Options_t |
277 |
{ |
{ |
278 |
char buf[AIR_STRLEN_HUGE] = ""; |
char buf[AIR_STRLEN_HUGE] = ""; |
279 |
if (hasDflt) { |
if (hasDflt) { |
280 |
sprintf(buf, "%ld", (long)*v); |
snprintf(buf, sizeof(buf), "%ld", (long)*v); |
281 |
} |
} |
282 |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeInt); |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeInt); |
283 |
hestOptAdd ( |
hestOptAdd ( |
298 |
{ |
{ |
299 |
char buf[AIR_STRLEN_HUGE] = ""; |
char buf[AIR_STRLEN_HUGE] = ""; |
300 |
if (hasDflt) { |
if (hasDflt) { |
301 |
sprintf(buf, "%lf", (double)*v); |
snprintf(buf, sizeof(buf), "%lf", (double)*v); |
302 |
} |
} |
303 |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeReal); |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeReal); |
304 |
hestOptAdd ( |
hestOptAdd ( |
322 |
if (hasDflt) { |
if (hasDflt) { |
323 |
Diderot_union2_t u; |
Diderot_union2_t u; |
324 |
u.v = *v; |
u.v = *v; |
325 |
sprintf(buf, "%lf %lf", (double)(u.r[0]), (double)(u.r[1])); |
snprintf(buf, sizeof(buf), "%lf %lf", (double)(u.r[0]), (double)(u.r[1])); |
326 |
} |
} |
327 |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeReal2); |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeReal2); |
328 |
hestOptAdd ( |
hestOptAdd ( |
346 |
if (hasDflt) { |
if (hasDflt) { |
347 |
Diderot_union3_t u; |
Diderot_union3_t u; |
348 |
u.v = *v; |
u.v = *v; |
349 |
sprintf(buf, "%lf %lf %lf", |
snprintf(buf, sizeof(buf), "%lf %lf %lf", |
350 |
(double)(u.r[0]), (double)(u.r[1]), (double)(u.r[2])); |
(double)(u.r[0]), (double)(u.r[1]), (double)(u.r[2])); |
351 |
} |
} |
352 |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeReal3); |
opt_def_t *odf = OptAdd(dopts, name, desc, (void*)v, optTypeReal3); |
372 |
if (hasDflt) { |
if (hasDflt) { |
373 |
Diderot_union4_t u; |
Diderot_union4_t u; |
374 |
u.v = *v; |
u.v = *v; |
375 |
sprintf(buf, "%lf %lf %lf %lf", |
snprintf(buf, sizeof(buf), "%lf %lf %lf %lf", |
376 |
(double)(u.r[0]), (double)(u.r[1]), |
(double)(u.r[0]), (double)(u.r[1]), |
377 |
(double)(u.r[2]), (double)(u.r[3])); |
(double)(u.r[2]), (double)(u.r[3])); |
378 |
} |
} |