Skip to content

Commit

Permalink
add options.conf specification at command line (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
adokter committed Feb 15, 2022
1 parent d8365d2 commit ce4e697
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@
// Name of the program, to be stored as task attribute in ODIM
#define PROGRAM "vol2bird"
// Version of the program, to be stored as task_version attribute in ODIM
#define VERSION "0.5.0.9185"
#define VERSION "0.5.0.9186"
// Date of latest version of the program
#define VERSIONDATE "07-Feb-2022"
#define VERSIONDATE "15-Feb-2022"


//-------------------------------------------------------//
Expand Down
11 changes: 9 additions & 2 deletions lib/libvol2bird.c
Original file line number Diff line number Diff line change
Expand Up @@ -4561,13 +4561,20 @@ RaveIO_t* vol2birdIO_open(const char* filename)


// loads configuration data in the alldata struct
int vol2birdLoadConfig(vol2bird_t* alldata) {
int vol2birdLoadConfig(vol2bird_t* alldata, const char* optionsFile) {

alldata->misc.loadConfigSuccessful = FALSE;

// load options.conf path from environment variable
const char * optsConfFilename = getenv(OPTIONS_CONF);

if (optsConfFilename == NULL) {
optsConfFilename = OPTIONS_FILE;
if(optionsFile == NULL){
optsConfFilename = OPTIONS_FILE;
}
else{
optsConfFilename = optionsFile;
}
}
else{
fprintf(stderr, "Searching user configuration file '%s' specified in environmental variable '%s'\n",optsConfFilename,OPTIONS_CONF);
Expand Down
2 changes: 1 addition & 1 deletion lib/libvol2bird.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void vol2birdPrintPointsArray(vol2bird_t* alldata);

void vol2birdPrintPointsArraySimple(vol2bird_t* alldata);

int vol2birdLoadConfig(vol2bird_t* alldata);
int vol2birdLoadConfig(vol2bird_t* alldata, const char* optionsFile);

int vol2birdSetUp(PolarVolume_t* volume, vol2bird_t* alldata);

Expand Down
26 changes: 21 additions & 5 deletions src/rsl2odim.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

void usage(char* programName, int verbose){
fprintf(stderr,"rsl2odim version %s (%s)\n", VERSION, VERSIONDATE);
fprintf(stderr,"usage: %s <RSL polar volume input> <ODIM hdf5 volume output>\n",programName);
fprintf(stderr,"usage: %s -i <polar volume or scan> [-i <polar scan> [-i <polar scan>] ...] -o <ODIM hdf5 volume output>\n",programName);
fprintf(stderr,"usage: %s --help\n", programName);
fprintf(stderr," usage: %s <RSL polar volume input> <ODIM hdf5 volume output>\n",programName);
fprintf(stderr," usage: %s -i <polar volume or scan> [-i <polar scan> [-i <polar scan>] ...] [-c <vol2bird configuration file>] -o <ODIM hdf5 volume output>\n",programName);
fprintf(stderr," usage: %s --help\n", programName);

if (verbose){
fprintf(stderr,"rsl2odim version %s (%s)\n", VERSION, VERSIONDATE);
Expand Down Expand Up @@ -67,12 +67,15 @@ int main(int argc, char** argv) {
char* fileIn[INPUTFILESMAX];
// the (optional) vertical profile file that the user specified as output
const char* fileVolOut = NULL;
// the (optional) options.conf file path that the user specified as input
const char* optionsFile = NULL;

// determine whether we deal with legacy command line format (0) or getopt command line format (1)
int commandLineFormat = 0;
for (int i=0; i<argc; i++){
if(strcmp("-i",argv[i])==0 || strcmp("--input",argv[i])==0 || \
strcmp("-o",argv[i])==0 || strcmp("--output",argv[i])==0 || \
strcmp("-c",argv[i])==0 || strcmp("--config",argv[i])==0 || \
strcmp("-h",argv[i])==0 || strcmp("--help",argv[i])==0 || \
strcmp("-v",argv[i])==0 || strcmp("--version",argv[i])==0)
{
Expand Down Expand Up @@ -115,13 +118,14 @@ int main(int argc, char** argv) {
{"version", no_argument, 0, 'v'},
{"input", required_argument, 0, 'i'},
{"output", required_argument, 0, 'o'},
{"config", required_argument, 0, 'c'},
{0, 0, 0, 0}
};

/* getopt_long stores the option index here. */
int option_index = 0;

c = getopt_long (argc, argv, "hvi:o:",
c = getopt_long (argc, argv, "hvi:o:c:",
long_options, &option_index);

/* Detect the end of the options. */
Expand Down Expand Up @@ -161,6 +165,10 @@ int main(int argc, char** argv) {
case 'o':
fileVolOut = optarg;
break;

case 'c':
optionsFile = optarg;
break;

case '?':
/* getopt_long already printed an error message. */
Expand Down Expand Up @@ -200,13 +208,21 @@ int main(int argc, char** argv) {
}
}

// check that options files exist
if(optionsFile != NULL){
if(!isRegularFile(optionsFile)){
fprintf(stderr, "Error: configuration file '%s' does not exist.\n", optionsFile);
return -1;
}
}

// initialize hlhdf library and Rave
HL_init();
Rave_initializeDebugger();
Rave_setDebugLevel(RAVE_WARNING);

// read configuration options
int configSuccessful = vol2birdLoadConfig(&alldata) == 0;
int configSuccessful = vol2birdLoadConfig(&alldata, optionsFile) == 0;

if (configSuccessful == FALSE) {
fprintf(stderr,"Error: failed to load configuration\n");
Expand Down
22 changes: 19 additions & 3 deletions src/vol2bird.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
void usage(char* programName, int verbose){
fprintf(stderr,"vol2bird version %s (%s)\n", VERSION, VERSIONDATE);
fprintf(stderr," usage: %s <polar volume> [<ODIM hdf5 profile output> [<ODIM hdf5 volume output>]]\n",programName);
fprintf(stderr," usage: %s -i <polar volume or scan> [-i <polar scan> [-i <polar scan>] ...] [-o <ODIM hdf5 profile output>] [-p <ODIM hdf5 volume output>]\n",programName);
fprintf(stderr," usage: %s -i <polar volume or scan> [-i <polar scan> [-i <polar scan>] ...] [-o <ODIM hdf5 profile output>] [-p <ODIM hdf5 volume output>] [-c <vol2bird configuration file>]\n",programName);
fprintf(stderr," usage: %s --help\n", programName);

if(verbose){
Expand Down Expand Up @@ -122,13 +122,16 @@ int main(int argc, char** argv) {
const char* fileVpOut = NULL;
// the (optional) vertical profile file that the user specified as output
const char* fileVolOut = NULL;
// the (optional) options.conf file path that the user specified as input
const char* optionsFile = NULL;

// determine whether we deal with legacy command line format (0) or getopt command line format (1)
int commandLineFormat = 0;
for (int i=0; i<argc; i++){
if(strcmp("-i",argv[i])==0 || strcmp("--input",argv[i])==0 || \
strcmp("-o",argv[i])==0 || strcmp("--output",argv[i])==0 || \
strcmp("-p",argv[i])==0 || strcmp("--pvol",argv[i])==0 || \
strcmp("-c",argv[i])==0 || strcmp("--config",argv[i])==0 || \
strcmp("-h",argv[i])==0 || strcmp("--help",argv[i])==0 || \
strcmp("-v",argv[i])==0 || strcmp("--version",argv[i])==0)
{
Expand Down Expand Up @@ -181,13 +184,14 @@ int main(int argc, char** argv) {
{"input", required_argument, 0, 'i'},
{"output", required_argument, 0, 'o'},
{"pvol", required_argument, 0, 'p'},
{"config", required_argument, 0, 'c'},
{0, 0, 0, 0}
};

/* getopt_long stores the option index here. */
int option_index = 0;

c = getopt_long (argc, argv, "hvi:o:p:",
c = getopt_long (argc, argv, "hvi:o:p:c:",
long_options, &option_index);

/* Detect the end of the options. */
Expand Down Expand Up @@ -232,6 +236,10 @@ int main(int argc, char** argv) {
fileVolOut = optarg;
break;

case 'c':
optionsFile = optarg;
break;

case '?':
/* getopt_long already printed an error message. */
break;
Expand All @@ -257,6 +265,14 @@ int main(int argc, char** argv) {
return -1;
}
}

// check that options files exist
if(optionsFile != NULL){
if(!isRegularFile(optionsFile)){
fprintf(stderr, "Error: configuration file '%s' does not exist.\n", optionsFile);
return -1;
}
}

// Initialize hlhdf library
HL_init();
Expand All @@ -279,7 +295,7 @@ int main(int argc, char** argv) {
}

// read configuration options
int configSuccessful = vol2birdLoadConfig(&alldata) == 0;
int configSuccessful = vol2birdLoadConfig(&alldata, optionsFile) == 0;

if (configSuccessful == FALSE) {
fprintf(stderr,"Error: failed to load configuration\n");
Expand Down

0 comments on commit ce4e697

Please sign in to comment.