Improved command line parsing for main corsika binary
This MR implements a completely new command line parser for the corsika
example to make it significantly more user friendly for running showers. The
parsing is implemented with the CLI11
command line library (provided by Conan); this is hands-down the best CLI
library for C++ and is provided as a single header-file (seriously, it's
awesome).
This new example exposes more options to the command line as well as performs validation during parsing of the options to make it more resilient.
If you run corsika -h
, you will get the following help message:
Simulate standard (downgoing) showers with CORSIKA 8.
Usage: ./bin/corsika [OPTIONS]
Options:
-h,--help Print this help message and exit
Primary:
-Z INT:INT in [0 - 26] Excludes: --pdg
Atomic number for primary
-A INT:INT in [1 - 58] Needs: -Z Excludes: --pdg
Atomic mass number for primary
-p,--pdg Excludes: -Z -A PDG code for primary.
-E,--energy :POSITIVE REQUIRED
Primary energy in GeV
-z,--zenith :INT in [0 - 90]=0 REQUIRED
Primary zenith angle (deg)
-a,--azimuth :INT in [0 - 360]=0
Primary azimuth angle (deg)
Library/Output:
-N,--nevent INT:POSITIVE REQUIRED
The number of events/showers to run.
-f,--filename :PATH(non-existing)=corsika_library REQUIRED
Filename for output library.
Misc.:
-s,--seed :NONNEGATIVE=12351739
The random number seed.
--force-interaction Force the location of the first interaction.
CLI11 makes this super reliable - arguments can be given in any order with any combination of short and long form arguments.
The following validations are performed by CLI11 during parsing,
- The user can provide
--pdg
for an explicit PDG code, or can provide-A
and-Z
but not both. - A/Z is currently limited to iron (I'm happy to change this but it seems like a good starting place until we are more confident about C8?) and are checked to be greater than 1 and 0 respectively.
- Zenith angle is restricted to between 0 and 90 degrees.
- Azimuth angle is restricted to between 0 and 360 degrees.
- The number of events is checked to be a positive integer.
- CLI11 also checks that the path given for the output doesn't already exist.
This is still a WIP and anyone is welcome to contribute to this MR to add more options. I am planning to add (latitude, longitude, altitude) options once the open IGRF MR is approved as well as some minor cleanup.
If people you have suggestions for options to add, please leave a comment!