| kspaceFirstOrder3D-OMP 1.1 The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Friends Pages
CommandLineParameters.cpp
Go to the documentation of this file.
1 /**
2 * @file CommandLineParameters.cpp
3 * @author Jiri Jaros \n
4 * Faculty of Information Technology\n
5 * Brno University of Technology \n
6 * jarosjir@fit.vutbr.cz
7 *
8 * @brief The implementation file containing the command line parameters.
9 *
10 * @version kspaceFirstOrder3D 2.15
11 *
12 * @date 29 August 2012, 11:25 (created) \n
13 * 29 September 2014, 12:23 (revised)
14 *
15 *
16 * @section License
17 * This file is part of the C++ extension of the k-Wave Toolbox (http://www.k-wave.org).\n
18 * Copyright (C) 2014 Jiri Jaros and Bradley Treeby
19 *
20 * This file is part of k-Wave. k-Wave is free software: you can redistribute it
21 * and/or modify it under the terms of the GNU Lesser General Public License as
22 * published by the Free Software Foundation, either version 3 of the License,
23 * or (at your option) any later version.
24 *
25 * k-Wave is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 * See the GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with k-Wave. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34
35 //Linux build
36 #ifdef __linux__
37 #include <getopt.h>
38 #endif
39
40 //Windows build
41 #ifdef _WIN64
42 #include <GetoptWin64/Getopt.h>
43 #endif
44
45 #include <stdio.h>
46 #include <string.h>
47 #ifdef _OPENMP
48 #include <omp.h>
49 #endif
50
51 #include <Parameters/CommandLineParameters.h>
52
53 #include <Utils/ErrorMessages.h>
54 //----------------------------------------------------------------------------//
55 //---------------------------- Constants -------------------------------------//
56 //----------------------------------------------------------------------------//
57
58 //----------------------------------------------------------------------------//
59 //----------------------------- Public -------------------------------------//
60 //----------------------------------------------------------------------------//
61
62
63
64 /**
65 * Constructor.
66 */
67 TCommandLineParameters::TCommandLineParameters() :
68 InputFileName(""), OutputFileName (""), CheckpointFileName(""),
69 #ifdef _OPENMP
70 NumberOfThreads(omp_get_num_procs()),
71 #else
72 NumberOfThreads(1),
73 #endif
74 VerboseInterval(DefaultVerboseInterval), CompressionLevel (DefaultCompressionLevel),
75 BenchmarkFlag (false), BenchmarkTimeStepsCount(0), CheckpointInterval(0),
76 PrintVersion (false),
77 Store_p_raw(false), Store_p_rms(false), Store_p_max(false), Store_p_min(false),
78 Store_p_max_all(false), Store_p_min_all(false), Store_p_final(false),
79 Store_u_raw(false), Store_u_non_staggered_raw(false),
80 Store_u_rms(false), Store_u_max(false), Store_u_min(false),
81 Store_u_max_all(false), Store_u_min_all(false), Store_u_final(false),
82 CopySensorMask(false),
83 StartTimeStep(0)
84 {
85
86 }// end of TCommandLineParameters
87 //------------------------------------------------------------------------------
88
89 /**
90 * Print usage and exit.
91 */
92 void TCommandLineParameters::PrintUsageAndExit()
93 {
94 printf("---------------------------------- Usage ---------------------------------\n");
95 printf("Mandatory parameters:\n");
96 printf(" -i <input_file_name> : HDF5 input file\n");
97 printf(" -o <output_file_name> : HDF5 output file\n");
98 printf("\n");
99 printf("Optional parameters: \n");
100
101 #ifdef _OPENMP
102 printf(" -t <num_threads> : Number of CPU threads\n");
103 printf(" (default = %d)\n", omp_get_num_procs());
104 #endif
105
106 printf(" -r <interval_in_%%> : Progress print interval\n");
107 printf(" (default = %ld%%)\n", DefaultVerboseInterval);
108 printf(" -c <comp_level> : Output file compression level <0,9>\n");
109 printf(" (default = %ld)\n", DefaultCompressionLevel);
110 printf(" --benchmark <steps> : Run a specified number of time steps\n");
111 printf("\n");
112 printf(" --checkpoint_file <file_name> : HDF5 Checkpoint file\n");
113 printf(" --checkpoint_interval <seconds> : Stop after a given number of seconds and\n");
114 printf(" store the actual state\n");
115 printf("\n");
116 printf(" -h : Print help\n");
117 printf(" --help : Print help\n");
118 printf(" --version : Print version\n");
119 printf("\n");
120 printf("Output flags:\n");
121 printf(" -p : Store acoustic pressure \n");
122 printf(" (default if nothing else is on)\n");
123 printf(" (the same as --p_raw)\n");
124 printf(" --p_raw : Store raw time series of p (default)\n");
125 printf(" --p_rms : Store rms of p\n");
126 printf(" --p_max : Store max of p\n");
127 printf(" --p_min : Store min of p\n");
128 printf(" --p_max_all : Store max of p (whole domain)\n");
129 printf(" --p_min_all : Store min of p (whole domain)\n");
130 printf(" --p_final : Store final pressure field \n");
131 printf("\n");
132 printf(" -u : Store ux, uy, uz\n");
133 printf(" (the same as --u_raw)\n");
134 printf(" --u_raw : Store raw time series of ux, uy, uz\n");
135 printf(" --u_non_staggered_raw : Store non-staggered raw time series of\n");
136 printf(" ux, uy, uz \n");
137 printf(" --u_rms : Store rms of ux, uy, uz\n");
138 printf(" --u_max : Store max of ux, uy, uz\n");
139 printf(" --u_min : Store min of ux, uy, uz\n");
140 printf(" --u_max_all : Store max of ux, uy, uz (whole domain)\n");
141 printf(" --u_min_all : Store min of ux, uy, uz (whole domain)\n");
142 printf(" --u_final : Store final acoustic velocity\n");
143 printf("\n");
144 printf(" --copy_sensor_mask : Copy sensor mask to the output file\n");
145 printf("\n");
146 printf(" -s <timestep> : Time step when data collection begins\n");
147 printf(" (default = 1)\n");
148 printf("--------------------------------------------------------------------------\n");
149 printf("\n");
150
151 exit(EXIT_FAILURE);
152 }// end of PrintUsageAndExit
153 //------------------------------------------------------------------------------
154
155 /**
156 * Print setup.
157 */
158 void TCommandLineParameters::PrintSetup()
159 {
160 printf("List of enabled parameters:\n");
161
162 printf(" Input file %s\n", InputFileName.c_str());
163 printf(" Output file %s\n", OutputFileName.c_str());
164 printf("\n");
165 printf(" Number of threads %ld\n", NumberOfThreads);
166 printf(" Verbose interval[%%] %ld\n", VerboseInterval);
167 printf(" Compression level %ld\n", CompressionLevel);
168 printf("\n");
169 printf(" Benchmark flag %d\n", BenchmarkFlag);
170 printf(" Benchmark time steps %ld\n", BenchmarkTimeStepsCount);
171 printf("\n");
172 printf(" Checkpoint_file %s\n", CheckpointFileName.c_str());
173 printf(" Checkpoint_interval %ld\n", CheckpointInterval);
174 printf("\n");
175 printf(" Store p_raw %d\n", Store_p_raw);
176 printf(" Store p_rms %d\n", Store_p_rms);
177 printf(" Store p_max %d\n", Store_p_max);
178 printf(" Store p_min %d\n", Store_p_min);
179 printf(" Store p_max_all %d\n", Store_p_max_all);
180 printf(" Store p_min_all %d\n", Store_p_min_all);
181 printf(" Store p_final %d\n", Store_p_final);
182 printf("\n");
183 printf(" Store u_raw %d\n", Store_u_raw);
184 printf(" Store u_non_staggered_raw %d\n", Store_u_non_staggered_raw);
185 printf(" Store u_rms %d\n", Store_u_rms);
186 printf(" Store u_max %d\n", Store_u_max);
187 printf(" Store u_min %d\n", Store_u_min);
188 printf(" Store u_max_all %d\n", Store_u_max_all);
189 printf(" Store u_min_all %d\n", Store_u_min_all);
190 printf(" Store u_final %d\n", Store_u_final);
191 printf("\n");
192 printf(" Copy sensor mask %d\n", CopySensorMask);
193 printf("\n");
194 printf(" Collection begins at %ld\n", StartTimeStep + 1);
195 }// end of PrintSetup
196 //------------------------------------------------------------------------------
197
198 /**
199 * Parse command line.
200 * @param [in, out] argc
201 * @param [in, out] argv
202 */
203 void TCommandLineParameters::ParseCommandLine(int argc, char** argv)
204 {
205
206 char c;
207 int longIndex;
208 bool CheckpointFlag = false;
209
210 #ifdef _OPENMP
211 const char * shortOpts = "i:o:r:c:t:puhs:";
212 #else
213 const char * shortOpts = "i:o:r:c:puIhs:";
214 #endif
215
216 const struct option longOpts[] =
217 {
218 { "benchmark", required_argument, NULL, 0},
219 { "help", no_argument, NULL, 'h'},
220 { "version", no_argument, NULL, 0},
221 { "checkpoint_file" , required_argument, NULL, 0 },
222 { "checkpoint_interval", required_argument, NULL, 0 },
223
224 { "p_raw", no_argument, NULL, 'p'},
225 { "p_rms", no_argument, NULL, 0},
226 { "p_max", no_argument, NULL, 0},
227 { "p_min", no_argument, NULL, 0},
228 { "p_max_all", no_argument, NULL, 0},
229 { "p_min_all", no_argument, NULL, 0},
230 { "p_final", no_argument, NULL, 0},
231
232 { "u_raw", no_argument, NULL, 'u'},
233 { "u_non_staggered_raw", no_argument, NULL, 0},
234 { "u_rms", no_argument, NULL, 0},
235 { "u_max", no_argument, NULL, 0},
236 { "u_min", no_argument, NULL, 0},
237 { "u_max_all", no_argument, NULL, 0},
238 { "u_min_all", no_argument, NULL, 0},
239 { "u_final", no_argument, NULL, 0},
240
241 { "copy_sensor_mask", no_argument, NULL, 0},
242 { NULL, no_argument, NULL, 0}
243 };
244
245
246 // Short parameters //
247 while ((c = getopt_long (argc, argv, shortOpts, longOpts, &longIndex )) != -1)
248 {
249 switch (c)
250 {
251 case 'i':
252 {
253 InputFileName = optarg;
254 break;
255 }
256
257 case 'o':
258 {
259 OutputFileName = optarg;
260 break;
261 }
262
263 case 'r':
264 {
265 if ((optarg == NULL) || (atol(optarg) <= 0))
266 {
267 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoVerboseIntreval);
268 PrintUsageAndExit();
269 }
270 else
271 {
272 VerboseInterval = atol(optarg);
273 }
274 break;
275 }
276
277 case 't':
278 {
279 if ((optarg == NULL) || (atol(optarg) <= 0))
280 {
281 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoThreadNumbers);
282 PrintUsageAndExit();
283 }
284 else
285 {
286 NumberOfThreads = atol(optarg);
287 }
288 break;
289 }
290
291 case 'c':
292 {
293 if ((optarg == NULL) || (atol(optarg) < 0) || atol(optarg) > 9)
294 {
295 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoCompressionLevel);
296 PrintUsageAndExit();
297 }
298 else
299 {
300 CompressionLevel = atol(optarg);
301 }
302 break;
303 }
304
305 case 'p':
306 {
307 Store_p_raw = true;
308 break;
309 }
310
311 case 'u':
312 {
313 Store_u_raw = true;
314 break;
315 }
316
317 case 'h':
318 {
319 PrintUsageAndExit();
320 break;
321 }
322
323 case 's':
324 {
325 if ((optarg == NULL) || (atol(optarg) < 1))
326 {
327 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoStartTimestep);
328 PrintUsageAndExit();
329 }
330 StartTimeStep = (size_t) (atol(optarg) - 1);
331 break;
332 }
333
334 // long option without a short arg
335 case 0:
336 {
337 if( strcmp( "benchmark", longOpts[longIndex].name ) == 0 )
338 {
339 BenchmarkFlag = true;
340 if ((optarg == NULL) || (atol(optarg) <= 0))
341 {
342 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoBenchmarkTimeStepCount);
343 PrintUsageAndExit();
344 }
345 else
346 {
347 BenchmarkTimeStepsCount = atol(optarg);
348 }
349 }
350 else if( strcmp( "checkpoint_file", longOpts[longIndex].name ) == 0 )
351 {
352 CheckpointFlag = true;
353 if ((optarg == NULL))
354 {
355 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoCheckpointFile);
356 PrintUsageAndExit();
357 }
358 else
359 {
360 CheckpointFileName = optarg;
361 }
362 }
363 else if( strcmp( "checkpoint_interval", longOpts[longIndex].name ) == 0 )
364 {
365 CheckpointFlag = true ;
366 if ((optarg == NULL) || (atol(optarg) <= 0))
367 {
368 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoCheckpointInterval);
369 PrintUsageAndExit();
370 }
371 else
372 {
373 CheckpointInterval = atol(optarg);
374 }
375 }
376 else if (strcmp("version", longOpts[longIndex].name) == 0)
377 {
378 PrintVersion = true;
379 return;
380 }
381
382 //-- pressure related flags
383 else if (strcmp("p_rms", longOpts[longIndex].name) == 0)
384 {
385 Store_p_rms = true;
386 }
387 else if (strcmp("p_max", longOpts[longIndex].name) == 0)
388 {
389 Store_p_max = true;
390 }
391 else if (strcmp("p_min", longOpts[longIndex].name) == 0)
392 {
393 Store_p_min = true;
394 }
395 else if (strcmp("p_max_all", longOpts[longIndex].name) == 0)
396 {
397 Store_p_max_all = true;
398 }
399 else if (strcmp("p_min_all", longOpts[longIndex].name) == 0)
400 {
401 Store_p_min_all = true;
402 }
403 else if (strcmp("p_final", longOpts[longIndex].name) == 0)
404 {
405 Store_p_final = true;
406 }
407
408 //-- velocity related flags
409 else if (strcmp("u_non_staggered_raw", longOpts[longIndex].name) == 0)
410 {
411 Store_u_non_staggered_raw = true;
412 }
413 else if (strcmp("u_rms", longOpts[longIndex].name) == 0)
414 {
415 Store_u_rms = true;
416 }
417 else if (strcmp("u_max", longOpts[longIndex].name) == 0)
418 {
419 Store_u_max = true;
420 }
421 else if (strcmp("u_min", longOpts[longIndex].name) == 0)
422 {
423 Store_u_min = true;
424 }
425 else if (strcmp("u_max_all", longOpts[longIndex].name) == 0)
426 {
427 Store_u_max_all = true;
428 }
429 else if (strcmp("u_min_all", longOpts[longIndex].name) == 0)
430 {
431 Store_u_min_all = true;
432 }
433 else if (strcmp("u_final", longOpts[longIndex].name) == 0)
434 {
435 Store_u_final = true;
436 }
437
438 else if (strcmp("copy_sensor_mask", longOpts[longIndex].name) == 0)
439 {
440 CopySensorMask = true;
441 }
442 else
443 {
444 PrintUsageAndExit();
445 }
446
447 break;
448 }
449 default:
450 {
451 PrintUsageAndExit();
452 }
453 }
454 }
455
456
457 //-- Post checks --//
458 if (InputFileName == "")
459 {
460 fprintf(stderr, "%s", CommandlineParameters_ERR_FMT_NoInputFile);
461 PrintUsageAndExit();
462 }
463
464
465 if (OutputFileName == "")
466 {
467 fprintf(stderr, "%s", CommandlineParameters_ERR_FMT_NoOutputFile);
468 PrintUsageAndExit();
469 }
470
471 if (CheckpointFlag)
472 {
473 if (CheckpointFileName == "")
474 {
475 fprintf(stderr, "%s", CommandlineParameters_ERR_FMT_NoCheckpointFile);
476 PrintUsageAndExit();
477 }
478 if (CheckpointInterval == 0)
479 {
480 fprintf(stderr, "%s", CommandlineParameters_ERR_FMT_NoCheckpointInterval);
481 PrintUsageAndExit();
482 }
483 }
484
485 if (!(Store_p_raw || Store_p_rms || Store_p_max || Store_p_min ||
486 Store_p_max_all || Store_p_min_all || Store_p_final ||
487 Store_u_raw || Store_u_non_staggered_raw ||
488 Store_u_rms || Store_u_max || Store_u_min ||
489 Store_u_max_all || Store_u_min_all || Store_u_final ))
490 {
491 Store_p_raw = true;
492 }
493
494 //PrintSetup();
495
496 }// end of ParseCommandLine
497 //------------------------------------------------------------------------------
TCommandLineParameters::OutputFileName
std::string OutputFileName
Output file name.
Definition: CommandLineParameters.h:290
TCommandLineParameters::Store_u_raw
bool Store_u_raw
Store_u_raw value.
Definition: CommandLineParameters.h:327
TCommandLineParameters::PrintUsageAndExit
void PrintUsageAndExit()
Print usage and exit.
Definition: CommandLineParameters.cpp:92
TCommandLineParameters::CompressionLevel
size_t CompressionLevel
CompressionLevel value.
Definition: CommandLineParameters.h:299
CommandlineParameters_ERR_FMT_NoCheckpointFile
const char *const CommandlineParameters_ERR_FMT_NoCheckpointFile
Command line parameters error message.
Definition: ErrorMessages.h:121
CommandlineParameters_ERR_FMT_NoInputFile
const char *const CommandlineParameters_ERR_FMT_NoInputFile
Command line parameters error message.
Definition: ErrorMessages.h:117
TCommandLineParameters::Store_u_min
bool Store_u_min
Store_u_min value.
Definition: CommandLineParameters.h:335
TCommandLineParameters::Store_u_max
bool Store_u_max
Store_u_max value.
Definition: CommandLineParameters.h:333
TCommandLineParameters::VerboseInterval
size_t VerboseInterval
VerboseInterval value.
Definition: CommandLineParameters.h:297
TCommandLineParameters::Store_u_non_staggered_raw
bool Store_u_non_staggered_raw
Store_u_non_staggered_raw value.
Definition: CommandLineParameters.h:329
TCommandLineParameters::Store_p_max
bool Store_p_max
Store_p_max value.
Definition: CommandLineParameters.h:316
TCommandLineParameters::Store_p_min_all
bool Store_p_min_all
Store_p_min_all value.
Definition: CommandLineParameters.h:322
CommandlineParameters_ERR_FMT_NoThreadNumbers
const char *const CommandlineParameters_ERR_FMT_NoThreadNumbers
Command line parameters error message.
Definition: ErrorMessages.h:109
TCommandLineParameters::PrintSetup
void PrintSetup()
Print setup.
Definition: CommandLineParameters.cpp:158
TCommandLineParameters::Store_p_raw
bool Store_p_raw
Store_p_raw value.
Definition: CommandLineParameters.h:312
TCommandLineParameters::Store_u_final
bool Store_u_final
Store_u_final value.
Definition: CommandLineParameters.h:341
CommandlineParameters_ERR_FMT_NoVerboseIntreval
const char *const CommandlineParameters_ERR_FMT_NoVerboseIntreval
Command line parameters error message.
Definition: ErrorMessages.h:107
TCommandLineParameters::Store_p_min
bool Store_p_min
Store_p_min value.
Definition: CommandLineParameters.h:318
ErrorMessages.h
The header file containing all error messages of the project.
TCommandLineParameters::InputFileName
std::string InputFileName
Input file name.
Definition: CommandLineParameters.h:288
TCommandLineParameters::Store_p_max_all
bool Store_p_max_all
Store_p_max_all value.
Definition: CommandLineParameters.h:320
TCommandLineParameters::TCommandLineParameters
TCommandLineParameters()
Constructor.
Definition: CommandLineParameters.cpp:67
TCommandLineParameters::Store_u_rms
bool Store_u_rms
Store_u_rms value.
Definition: CommandLineParameters.h:331
TCommandLineParameters::BenchmarkFlag
bool BenchmarkFlag
BenchmarkFlag value.
Definition: CommandLineParameters.h:302
TCommandLineParameters::Store_p_final
bool Store_p_final
Store_p_final value.
Definition: CommandLineParameters.h:324
TCommandLineParameters::StartTimeStep
size_t StartTimeStep
StartTimeStep value.
Definition: CommandLineParameters.h:346
CommandlineParameters_ERR_FMT_NoStartTimestep
const char *const CommandlineParameters_ERR_FMT_NoStartTimestep
Command line parameters error message.
Definition: ErrorMessages.h:113
CommandlineParameters_ERR_FMT_NoCheckpointInterval
const char *const CommandlineParameters_ERR_FMT_NoCheckpointInterval
Command line parameters error message.
Definition: ErrorMessages.h:123
CommandlineParameters_ERR_FMT_NoOutputFile
const char *const CommandlineParameters_ERR_FMT_NoOutputFile
Command line parameters error message.
Definition: ErrorMessages.h:119
TCommandLineParameters::Store_u_min_all
bool Store_u_min_all
Store_u_min_all value.
Definition: CommandLineParameters.h:339
CommandLineParameters.h
The header file containing the command line parameters.
TCommandLineParameters::CheckpointFileName
std::string CheckpointFileName
Checkpoint file name.
Definition: CommandLineParameters.h:292
TCommandLineParameters::DefaultCompressionLevel
static const size_t DefaultCompressionLevel
Default compression level.
Definition: CommandLineParameters.h:350
TCommandLineParameters::CopySensorMask
bool CopySensorMask
Copy sensor mask to the output file.
Definition: CommandLineParameters.h:344
CommandlineParameters_ERR_FMT_NoBenchmarkTimeStepCount
const char *const CommandlineParameters_ERR_FMT_NoBenchmarkTimeStepCount
Command line parameters error message.
Definition: ErrorMessages.h:115
TCommandLineParameters::Store_u_max_all
bool Store_u_max_all
Store_u_max_all value.
Definition: CommandLineParameters.h:337
TCommandLineParameters::BenchmarkTimeStepsCount
size_t BenchmarkTimeStepsCount
BenchmarkTimeStepsCount value.
Definition: CommandLineParameters.h:304
TCommandLineParameters::PrintVersion
bool PrintVersion
PrintVersion value.
Definition: CommandLineParameters.h:309
TCommandLineParameters::CheckpointInterval
size_t CheckpointInterval
Checkpoint interval in seconds.
Definition: CommandLineParameters.h:306
CommandlineParameters_ERR_FMT_NoCompressionLevel
const char *const CommandlineParameters_ERR_FMT_NoCompressionLevel
Command line parameters error message.
Definition: ErrorMessages.h:111
TCommandLineParameters::DefaultVerboseInterval
static const size_t DefaultVerboseInterval
Default verbose interval.
Definition: CommandLineParameters.h:352
TCommandLineParameters::Store_p_rms
bool Store_p_rms
Store_p_rms value.
Definition: CommandLineParameters.h:314
TCommandLineParameters::ParseCommandLine
void ParseCommandLine(int argc, char **argv)
Parse command line.
Definition: CommandLineParameters.cpp:203
TCommandLineParameters::NumberOfThreads
size_t NumberOfThreads
NumberOfThreads value.
Definition: CommandLineParameters.h:295