schiff

Estimate the radiative properties of soft particless
git clone git://git.meso-star.com/schiff.git
Log | Files | Refs | README | LICENSE

commit c5c174672604ec776595ac4cccd8ba4e628675c2
parent f97d1846cfd9dc83df5661283ed969767540197c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  8 Mar 2016 15:53:51 +0100

Begin the parsing of the YAML geometry distributions

Diffstat:
Msrc/schiff_args.c | 55++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/src/schiff_args.c b/src/schiff_args.c @@ -36,6 +36,8 @@ #include <rsys/str.h> #include <rsys/stretchy_array.h> +#include <yaml.h> + #ifdef COMPILER_CL #include <getopt.h> #define strtok_r strtok_s @@ -519,6 +521,54 @@ error: goto exit; } +static res_T +parse_yaml(const char* filename) +{ + yaml_parser_t parser; + yaml_document_t document; + yaml_node_t* node; + size_t nvals; + FILE* file = NULL; + res_T res = RES_OK; + ASSERT(filename); + + if(!yaml_parser_initialize(&parser)) { + fprintf(stderr, "Couldn't intialise the YAML parser.\n"); + res = RES_UNKNOWN_ERR; + goto exit; + } + + file = fopen(filename, "rb"); + if(!file) { + fprintf(stderr, "Couldn't open the YAML file `%s'.\n", filename); + res = RES_IO_ERR; + goto error; + } + + yaml_parser_set_input_file(&parser, file); + + if(!yaml_parser_load(&parser, &document)) { + fprintf(stderr, "Error in parsing the YAML file `%s'.\n", filename); + res = RES_IO_ERR; + goto error; + } + + node = yaml_document_get_root_node(&document); + if(node->type != YAML_SEQUENCE_NODE) { + fprintf(stderr, "Expecting YAML sequence.\n"); + res = RES_BAD_ARG; + goto error; + } + +exit: + yaml_parser_delete(&parser); + yaml_document_delete(&document); + if(file) fclose(file); + return res; +error: + goto exit; +} + /******************************************************************************* * Local function ******************************************************************************/ @@ -534,7 +584,7 @@ schiff_args_init ASSERT(argc && argv && args); *args = SCHIFF_ARGS_NULL; - while((opt = getopt(argc, argv, "c:C:d:g:G:hn:o:qs:u:w:")) != -1) { + while((opt = getopt(argc, argv, "c:C:d:g:G:hi:n:o:qs:u:w:")) != -1) { switch(opt) { case 'c': res = parse_cylinder_distribution(optarg, args); break; case 'C': res = parse_cylinder_as_sphere_distribution(optarg, args); break; @@ -545,6 +595,9 @@ schiff_args_init print_help(argv[0]); schiff_args_release(args); return RES_OK; + case 'i': + res = parse_yaml(optarg); + break; case 'n': res = cstr_to_uint(optarg, &args->nthreads); if(res == RES_OK && args->nthreads == 0)