solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit b7b61d6fb3918aee2a49145e0ef8cab1598f80fb
parent 2656fd88292e5c917005d006a3f012e9f7ff30ff
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  3 Jan 2017 15:12:53 +0100

Handle the input filename command line argument

Diffstat:
Msrc/solstice.c | 42++++++++++++++++++++++++++++++++++++++++++
Msrc/solstice_args.c | 4++++
Msrc/solstice_args.h.in | 4+++-
3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/solstice.c b/src/solstice.c @@ -142,6 +142,45 @@ error: goto exit; } +static res_T +load_data(struct solstice* solstice, const struct solstice_args* args) +{ + FILE* file = stdin; + const char* name = "stdin"; + res_T res = RES_OK; + ASSERT(solstice && args); + + if(args->input_filename) { + file = fopen(args->input_filename, "r"); + if(!file) { + fprintf(stderr, "Could not open the file `%s'.\n", args->input_filename); + res = RES_IO_ERR; + goto error; + } + name = args->input_filename; + } else if(!args->quiet) { +#ifndef OS_WINDOWS + fprintf(stderr, + "Enter the solar facility data. Type ^D (i.e. CTRL+d) to stop:\n"); +#else + fprintf(stderr, + "Enter the solar facility data. Type ^Z (i.e. CTRL+z) to stop:\n"); +#endif + } + + res = solparser_setup(solstice->parser, name, file); + if(res != RES_OK) goto error; + + res = solparser_load(solstice->parser); + if(res != RES_OK) goto error; + +exit: + if(file && file != stdin) fclose(file); + return res; +error: + goto exit; +} + /******************************************************************************* * Solstice local functions ******************************************************************************/ @@ -180,6 +219,9 @@ solstice_init if(res != RES_OK) goto error; } + res = load_data(solstice, args); + if(res != RES_OK) goto error; + exit: return res; error: diff --git a/src/solstice_args.c b/src/solstice_args.c @@ -266,6 +266,10 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv) } } + if(optind < argc) { + args->input_filename = argv[optind]; + } + exit: optind = 1; return res; diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in @@ -21,6 +21,7 @@ struct solstice_args { const char* output_filename; unsigned long nrealisations; /* #realisations */ + const char* input_filename; /* May be NULL <=> read data from stdin */ struct { double pos[3]; @@ -42,8 +43,9 @@ struct solstice_args { static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__; #define SOLSTICE_ARGS_DEFAULT__ { \ - NULL, /* Output_filename */ \ + NULL, /* output_filename */ \ @SOLSTICE_ARGS_DEFAULT_NREALISATIONS@, \ + NULL, /* input_filename */ \ \ { /* Camera */ \ { @SOLSTICE_ARGS_DEFAULT_CAMERA_POS@ }, \