diff --git a/src/parser.c b/src/parser.c index cbadbf1ca405f9cf726343ea18551b0869582161..a57b7c1ec633fa4f9fefdd13e519dff817a1b1e5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -350,8 +350,9 @@ static void parse_value(char *line, struct swift_params *params) { /* Take second token as the parameter value. */ token = trim_both(strtok(NULL, "#\n")); - /* If second token is NULL then the line must be a section heading. */ - if (token == NULL) { + /* If second token is NULL or empty then the line must be a section + * heading. */ + if (token == NULL || strlen(token) == 0) { strcpy(tmpSectionName, tmpStr); strcat(tmpSectionName, PARSER_VALUE_STRING); diff --git a/tests/testParser.c b/tests/testParser.c index f1211199924df728dfe57376781dc07fe862cec7..c0d49ab9e44643d9c186fde4a3c45297fe96cf88 100644 --- a/tests/testParser.c +++ b/tests/testParser.c @@ -55,12 +55,20 @@ int main(int argc, char *argv[]) { char ic_file[PARSER_MAX_LINE_SIZE]; parser_get_param_string(¶m_file, "IO:ic_file", ic_file); + float sides[3]; + parser_get_param_float_array(¶m_file, "Box:sides", 1, 3, sides); + + float optsides[5] = {1.f, 2.f, 3.f, 4.f, 5.f}; + int haveopt = parser_get_param_float_array(¶m_file, "Box:moresides", + 0, 3, optsides); + /* Print the variables to check their values are correct. */ printf( "no_of_threads: %d, no_of_time_steps: %d, max_h: %f, start_time: %lf, " "ic_file: %s, kernel: %d optional: %d\n", no_of_threads, no_of_time_steps, max_h, start_time, ic_file, kernel, optional); + printf("sides of box: %f %f %f\n", sides[0], sides[1], sides[2]); assert(no_of_threads == 16); assert(no_of_time_steps == 10); @@ -69,6 +77,16 @@ int main(int argc, char *argv[]) { assert(strcmp(ic_file, "ic_file.ini") == 0); /*strcmp returns 0 if correct.*/ assert(kernel == 4); assert(optional == 1); + assert(sides[0] == 2); + assert(sides[1] == 3); + assert(sides[2] == 4); + + assert(haveopt == 0); + assert(optsides[0] == 1); + assert(optsides[1] == 2); + assert(optsides[2] == 3); + assert(optsides[3] == 4); + assert(optsides[4] == 5); return 0; } diff --git a/tests/testParserInput.yaml b/tests/testParserInput.yaml index c55a549718c97e172ed3c7b20803c11e1a568467..8dc2936e5f9cac63649dffd9a5e49d38be1257a0 100644 --- a/tests/testParserInput.yaml +++ b/tests/testParserInput.yaml @@ -9,7 +9,7 @@ Scheduler: kernel: 4 Simulation: - no_of_time_steps: 10 + no_of_time_steps: 10 max_h: 1.1255 start_time: 1.23456789 @@ -17,6 +17,6 @@ IO: #Input file ic_file: ic_file.ini -#Box: -# sides: [2, 3, 4] +Box: + sides: [2, 3, 4] ...