YetAnotherCoupler 3.2.0
Loading...
Searching...
No Matches
config_yaml.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9// libfyaml is not very clean...so we have to suppress some warnings
10
11#if defined(__NVCOMPILER)
12# pragma diag_suppress unsigned_compare_with_zero
13#elif defined(__GNUC__)
14# pragma GCC diagnostic push
15# pragma GCC diagnostic ignored "-Wpedantic"
16# pragma GCC diagnostic ignored "-Wall"
17# pragma GCC diagnostic ignored "-Wextra"
18#endif
19#include <libfyaml.h>
20#if defined(__NVCOMPILER)
21# pragma diag_default unsigned_compare_with_zero
22#elif defined(__GNUC__)
23# pragma GCC diagnostic pop
24#endif
25
26#include <stdlib.h>
27#include <string.h>
28#include <stdbool.h>
29
30#include "yac.h"
31#include "utils_mci.h"
32#include "config_yaml.h"
33#include "mtime_calendar.h"
34#include "geometry.h"
35#include "io_utils.h"
36#include "interp_method_avg.h"
38#include "interp_method_check.h"
40#include "interp_method_creep.h"
41#include "interp_method_file.h"
42#include "interp_method_fixed.h"
43#include "interp_method_hcsbb.h"
44#include "interp_method_ncc.h"
45#include "interp_method_nnn.h"
46#include "interp_method_spmap.h"
47#include "interp_stack_config.h"
48
49typedef struct fy_document * fy_document_t;
50typedef struct fy_node * fy_node_t;
51typedef struct fy_node_pair * fy_node_pair_t;
52
53enum {
54 EMITTER_DEFAULT = FYECF_DEFAULT,
55 EMITTER_JSON = FYECF_MODE_JSON,
57 PARSER_JSON_AUTO = FYPCF_JSON_AUTO,
58 PARSER_JSON_FORCE = FYPCF_JSON_FORCE,
59};
60
66
67char const * yac_time_to_ISO(
68 char const * time, enum yac_time_unit_type time_unit);
69
92
97
106
126
130
135
136#define CAST_NAME_TYPE_PAIRS(...) (struct yac_name_type_pair[]) {__VA_ARGS__}
137#define COUNT_NAME_TYPE_PAIRS(...) \
138 sizeof(CAST_NAME_TYPE_PAIRS(__VA_ARGS__)) / sizeof(struct yac_name_type_pair)
139#define DEF_NAME_TYPE_PAIR(NAME, TYPE) {.name = #NAME, .type = (int)(TYPE)}
140#define DEF_NAME_TYPE_PAIRS(NAME, ...) \
141 static const struct yac_name_type_pair NAME [] = {__VA_ARGS__}; \
142 static const size_t num_ ## NAME = COUNT_NAME_TYPE_PAIRS(__VA_ARGS__);
143
145 yaml_base_keys,
146 DEF_NAME_TYPE_PAIR(start_date, START_DATE),
147 DEF_NAME_TYPE_PAIR(end_date, END_DATE),
148 DEF_NAME_TYPE_PAIR(calendar, CALENDAR),
149 DEF_NAME_TYPE_PAIR(timestep_unit, TIMESTEP_UNIT),
150 DEF_NAME_TYPE_PAIR(coupling, COUPLING),
152
154 yaml_couple_keys,
155 DEF_NAME_TYPE_PAIR(src_component, SOURCE_COMPONENT),
157 DEF_NAME_TYPE_PAIR(tgt_component, TARGET_COMPONENT),
160 DEF_NAME_TYPE_PAIR(coupling_period, COUPLING_PERIOD),
161 DEF_NAME_TYPE_PAIR(time_reduction, TIME_REDUCTION),
164 DEF_NAME_TYPE_PAIR(weight_file_name, WEIGHT_FILE_NAME),
165 DEF_NAME_TYPE_PAIR(mapping_side, MAPPING_SIDE),
166 DEF_NAME_TYPE_PAIR(scale_factor, SCALE_FACTOR),
167 DEF_NAME_TYPE_PAIR(scale_summand, SCALE_SUMMAND),
168 DEF_NAME_TYPE_PAIR(interpolation, INTERPOLATION),
169 DEF_NAME_TYPE_PAIR(src_mask_name, SOURCE_MASK_NAME),
170 DEF_NAME_TYPE_PAIR(src_mask_names, SOURCE_MASK_NAMES),
171 DEF_NAME_TYPE_PAIR(tgt_mask_name, TARGET_MASK_NAME))
172
174 yaml_debug_global_config_keys,
179
181 bool_names,
182 DEF_NAME_TYPE_PAIR(true, true),
183 DEF_NAME_TYPE_PAIR(TRUE, true),
184 DEF_NAME_TYPE_PAIR(yes, true),
185 DEF_NAME_TYPE_PAIR(YES, true),
186 DEF_NAME_TYPE_PAIR(false, false),
187 DEF_NAME_TYPE_PAIR(FALSE, false),
188 DEF_NAME_TYPE_PAIR(no, false),
189 DEF_NAME_TYPE_PAIR(NO, false))
190
192 timestep_units,
193 DEF_NAME_TYPE_PAIR(millisecond, C_MILLISECOND),
200 DEF_NAME_TYPE_PAIR(ISO_format, C_ISO_FORMAT))
201
203 time_operations,
209
211 calendar_types,
212 DEF_NAME_TYPE_PAIR(proleptic-gregorian, PROLEPTIC_GREGORIAN),
213 DEF_NAME_TYPE_PAIR(360d, YEAR_OF_360_DAYS),
214 DEF_NAME_TYPE_PAIR(365d, YEAR_OF_365_DAYS))
215
217 mapping_sides,
218 DEF_NAME_TYPE_PAIR(source, 1),
219 DEF_NAME_TYPE_PAIR(target, 0))
220
222 yaml_debug_keys,
223 DEF_NAME_TYPE_PAIR(global_config, GLOBAL_CONFIG))
224
226 config_filetypes,
231
232typedef
233#if defined __NVCOMPILER && __NVCOMPILER_MAJOR__ <= 24
234// Older versions of NVHPC have serious problems with unions that contain
235// pointers that are not the first members: versions 23.7 and older fail with
236// 'Internal compiler error. unhandled type', the newer versions produce code
237// that fails at the runtime with
238// 'Segmentation fault: address not mapped to object'.
239struct
240#else
241union
242#endif
244 int enum_value;
245 int int_value;
246 double dble_value;
247 int bool_value;
248 char const * str_value;
250
259
261
262 char const * name;
264
265#if defined __NVCOMPILER && __NVCOMPILER_MAJOR__ <= 24
266 // Older versions of NVHPC generate invalid LLVM IR for unions that contain
267 // structures with doubles: an attempt to initialize a member of type double
268 // that is not the first member of the respective structure will lead to a
269 // type mismatch.
270 struct
271#else
272 union
273#endif
274 {
275 struct { // enum
279 struct { // integer
280 int valid_min, valid_max;
282 struct { // double
285 struct { // string
288 struct { // bool
289 int dummy;
293};
294
295#define DEF_INTERP_METHOD_ADD_FUNC(NAME, FUNC) \
296 static void add_interp_method_ ## NAME ( \
297 struct field_couple_buffer * field_buffer, \
298 interp_method_parameter_value * parameters, \
299 char const * yaml_filename) { \
300 char const * routine_name = "add_interp_method_" #NAME; \
301 (void)parameters; \
302 (void)yaml_filename; \
303 (void)routine_name; \
304 {FUNC} }
305#define DEF_INTERP_METHOD_GET_FUNC(NAME, FUNC) \
306 static void get_interp_method_ ## NAME ( \
307 union yac_interp_stack_config_entry const * interp_stack_entry, \
308 interp_method_parameter_value * parameter_values) { \
309 char const * routine_name = "get_interp_method_" #NAME; \
310 (void)interp_stack_entry; \
311 (void)parameter_values; \
312 (void)routine_name; \
313 {FUNC} }
314
315#define DEF_ENUM_PARAM(NAME, DEFAULT, ...) \
316 {.name = #NAME, \
317 .type = ENUM_PARAM, \
318 .data.enum_param = \
319 {.valid_values = CAST_NAME_TYPE_PAIRS(__VA_ARGS__), \
320 .num_valid_values = COUNT_NAME_TYPE_PAIRS(__VA_ARGS__)}, \
321 .default_value.enum_value = (int)(DEFAULT)}
322#define DEF_INT_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX) \
323 {.name = #NAME, \
324 .type = INT_PARAM, \
325 .data.int_param = \
326 {.valid_min = (int)(VALID_MIN), \
327 .valid_max = (int)(VALID_MAX)}, \
328 .default_value.int_value = (int)(DEFAULT)}
329#define DEF_DBLE_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX) \
330 {.name = #NAME, \
331 .type = DBLE_PARAM, \
332 .data.dble_param = \
333 {.valid_min = (double)(VALID_MIN), \
334 .valid_max = (double)(VALID_MAX)}, \
335 .default_value.dble_value = (double)(DEFAULT)}
336#define DEF_DEG_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX) \
337 {.name = #NAME, \
338 .type = DEG_PARAM, \
339 .data.dble_param = \
340 {.valid_min = (double)(VALID_MIN), \
341 .valid_max = (double)(VALID_MAX)}, \
342 .default_value.dble_value = (double)(DEFAULT)}
343#define DEF_BOOL_PARAM(NAME, DEFAULT) \
344 {.name = #NAME, \
345 .type = BOOL_PARAM, \
346 .default_value.bool_value = (int)(DEFAULT)}
347#define DEF_STR_PARAM(NAME, DEFAULT, MAX_STR_LEN) \
348 {.name = #NAME, \
349 .type = STR_PARAM, \
350 .data.str_param.max_str_len = (MAX_STR_LEN), \
351 .default_value.str_value = (DEFAULT)}
352#define DEF_INTERP_METHOD_PARAM(NAME, ...) \
353 static struct interp_method_parameter \
354 interp_method_parameters_ ## NAME [] = {__VA_ARGS__};
355
356#define YAML_ASSERT(CHECK, MSG) \
357 YAC_ASSERT_F((CHECK), \
358 "ERROR(%s): " MSG " in YAML configuration file \"%s\"", \
359 routine_name, yaml_filename)
360#define YAML_ASSERT_F(CHECK, MSG, ...) \
361 YAC_ASSERT_F((CHECK), \
362 "ERROR(%s): " MSG " in YAML configuration file \"%s\"", \
363 routine_name, __VA_ARGS__, yaml_filename)
364
365#define DEF_INTERP_STACK_ADD(NAME, ...) \
366 yac_interp_stack_config_add_ ## NAME ( \
367 field_buffer->interp_stack, __VA_ARGS__);
368
369#define DEF_INTERP_STACK_ADD_NO_PARAM(NAME) \
370 yac_interp_stack_config_add_ ## NAME ( \
371 field_buffer->interp_stack);
372
373#define DEF_INTERP_STACK_GET(NAME, ...) \
374 yac_interp_stack_config_entry_get_ ## NAME ( \
375 interp_stack_entry, __VA_ARGS__);
376
377#define DEF_INTERP_STACK_GET_NO_PARAM(NAME) \
378 {}
379
380#define DEF_INTERP_METHOD(NAME, FUNC_ADD, FUNC_GET, ...) \
381 DEF_INTERP_METHOD_ADD_FUNC(NAME, FUNC_ADD) \
382 DEF_INTERP_METHOD_GET_FUNC(NAME, FUNC_GET) \
383 DEF_INTERP_METHOD_PARAM(NAME, __VA_ARGS__)
384
385// interpolation method average
387 DEF_INTERP_STACK_ADD(average,
388 (enum yac_interp_avg_weight_type)parameters[0].enum_value,
389 parameters[1].bool_value),
390 enum yac_interp_avg_weight_type reduction_type;
391 DEF_INTERP_STACK_GET(average,
392 &reduction_type, &parameter_values[1].bool_value)
393 parameter_values[0].enum_value = (int)reduction_type;,
396 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_AVG_DIST),
398 DEF_NAME_TYPE_PAIR(barycentric_coordinate, YAC_INTERP_AVG_BARY)),
401
402// interpolation method nearest corner cells
405 (enum yac_interp_ncc_weight_type)parameters[0].enum_value,
406 parameters[1].bool_value),
409 &weight_type, &parameter_values[1].bool_value)
410 parameter_values[0].enum_value = (int)weight_type;,
413 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_NCC_AVG),
414 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_NCC_DIST)),
417
418// interpolation method n-nearest neighbor
421 (enum yac_interp_nnn_weight_type)parameters[0].enum_value,
422 (size_t)parameters[1].int_value,
423 parameters[2].dble_value),
425 size_t n;
427 &type, &n, &parameter_values[2].dble_value)
428 parameter_values[0].enum_value = (int)type;
429 parameter_values[1].int_value = (int)n;,
432 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_NNN_DIST),
434 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_NNN_AVG),
438 gauss_scale, YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT, -DBL_MAX, DBL_MAX))
439
440// interpolation method conservative
441DEF_INTERP_METHOD(conservative,
442 DEF_INTERP_STACK_ADD(conservative,
443 parameters[0].int_value,
444 parameters[1].bool_value,
445 parameters[2].bool_value,
446 (enum yac_interp_method_conserv_normalisation)parameters[3].enum_value),
448 DEF_INTERP_STACK_GET(conservative,
449 &parameter_values[0].int_value,
450 &parameter_values[1].bool_value,
451 &parameter_values[2].bool_value, &normalisation)
452 parameter_values[3].enum_value = (int)normalisation;,
455 enforced_conservation, YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT),
462
463// interpolation method source to target mapping
464DEF_INTERP_METHOD(source_to_target_map,
466 parameters[0].dble_value,
467 parameters[1].dble_value,
468 (enum yac_interp_spmap_weight_type)parameters[2].enum_value,
469 (enum yac_interp_spmap_scale_type)parameters[3].enum_value,
470 parameters[4].dble_value,
471 parameters[5].dble_value),
473 enum yac_interp_spmap_scale_type scale_type;
475 &parameter_values[0].dble_value,
476 &parameter_values[1].dble_value,
477 &weight_type, &scale_type,
478 &parameter_values[4].dble_value,
479 &parameter_values[5].dble_value)
480 parameter_values[0].dble_value /= YAC_RAD;
481 parameter_values[1].dble_value /= YAC_RAD;
482 parameter_values[2].enum_value = (int)weight_type;
483 parameter_values[3].enum_value = (int)scale_type;,
485 spread_distance, YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT, 0.0, 89.9999),
487 max_search_distance,
491 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_SPMAP_DIST),
492 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_SPMAP_AVG)),
500 src_sphere_radius,
503 tgt_sphere_radius,
505
506// interpolation method fixed
509 parameters[0].dble_value != DBL_MAX,
510 "parameter 'user_value' of interpolation method 'fixed' is unset");
511 DEF_INTERP_STACK_ADD(fixed, parameters[0].dble_value),
513 &parameter_values[0].dble_value),
515 user_value, YAC_INTERP_FIXED_VALUE_DEFAULT, -DBL_MAX, DBL_MAX))
516
517// interpolation method user file
518DEF_INTERP_METHOD(user_file,
520 parameters[0].str_value,
521 "parameter \"filename\" of interpolation method \"user file\" is unset")
523 field_buffer->src.grid_name,
524 "source grid name has to be defined before "
525 "the definition of interpolation method \"user_file\"")
527 field_buffer->tgt.grid_name,
528 "target grid name has to be defined before "
529 "the definition of interpolation method \"user_file\"")
530 DEF_INTERP_STACK_ADD(user_file,
531 (char*)(parameters[0].str_value),
532 (char*)(field_buffer->src.grid_name),
533 (char*)(field_buffer->tgt.grid_name)),
534 char const * src_grid_name;
535 char const * tgt_grid_name;
536 DEF_INTERP_STACK_GET(user_file,
537 &parameter_values[0].str_value,
538 &src_grid_name, &tgt_grid_name),
542
543// interpolation method check
546 (char*)(parameters[0].str_value),
547 (char*)(parameters[1].str_value)),
549 &parameter_values[0].str_value,
550 &parameter_values[1].str_value),
557
558// interpolation method Bernstein Bezier
559DEF_INTERP_METHOD(bernstein_bezier,
562 DEF_BOOL_PARAM(dummy, 0))
563
564// interpolation method radial basis function
568 (size_t)parameters[0].int_value,
569 parameters[1].dble_value),
571 size_t n;
573 &type, &n, &parameter_values[1].dble_value)
576 "ERROR(get_interp_method_nnn): n-nearest-neighbor type missmatch");
577 parameter_values[0].int_value = (int)n;
578 parameter_values[2].enum_value = (int)0;,
580 DEF_DBLE_PARAM(rbf_scale, YAC_INTERP_RBF_SCALE_DEFAULT, -DBL_MAX, DBL_MAX),
583 DEF_NAME_TYPE_PAIR(gauss_kernel, 0)))
584
585// interpolation method creep
587 DEF_INTERP_STACK_ADD(creep, parameters[0].int_value),
589 &parameter_values[0].int_value),
591 creep_distance, YAC_INTERP_CREEP_DISTANCE_DEFAULT, -1, INT_MAX))
592
593// interpolation method user_callback
594DEF_INTERP_METHOD(user_callback,
596 parameters[0].str_value,
597 "parameter \"func_compute_weights\" "
598 "of interpolation method \"user callback\" is unset")
599 DEF_INTERP_STACK_ADD(user_callback, (char*)(parameters[0].str_value)),
600 DEF_INTERP_STACK_GET(user_callback,
601 &parameter_values[0].str_value),
605
606
607#define ADD_INTERPOLATION(NAME, TYPE) \
608 {.name = #NAME , \
609 .type = TYPE , \
610 .add_interpolation = add_interp_method_ ## NAME , \
611 .get_interpolation = get_interp_method_ ## NAME , \
612 .parameters = interp_method_parameters_ ## NAME , \
613 .num_parameters = \
614 sizeof(interp_method_parameters_ ## NAME ) / \
615 sizeof(interp_method_parameters_ ## NAME [0])}
616#define ADD_INTERPOLATION_NO_PARAM(NAME, TYPE) \
617 {.name = #NAME , \
618 .type = TYPE , \
619 .add_interpolation = add_interp_method_ ## NAME , \
620 .get_interpolation = get_interp_method_ ## NAME , \
621 .parameters = interp_method_parameters_ ## NAME , \
622 .num_parameters = 0}
623
624struct yac_interpolation_method {
625 char const * name;
627 void(*add_interpolation)(
628 struct field_couple_buffer * field_buffer,
630 char const * yaml_filename);
631 void(*get_interpolation)(
632 union yac_interp_stack_config_entry const * interp_stack_entry,
633 interp_method_parameter_value * parameter_values);
634 struct interp_method_parameter const * parameters;
635 size_t num_parameters;
640 ADD_INTERPOLATION(conservative, YAC_CONSERVATIVE),
641 ADD_INTERPOLATION(source_to_target_map, YAC_SOURCE_TO_TARGET_MAP),
648 ADD_INTERPOLATION(user_callback, YAC_USER_CALLBACK)};
649enum {
652};
653
654static char const * yaml_parse_string_value(
655 fy_node_t value_node, char const * name, char const * yaml_filename) {
656 char const * routine_name = "yaml_parse_string_value";
657
659 value_node && fy_node_is_scalar(value_node),
660 "unsupported node type for \"%s\" (the node is expected to be scalar)",
661 name);
662
663 return fy_node_get_scalar0(value_node);
664}
665
666static calendarType yaml_parse_calendar_value(
667 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
668 char const * routine_name = "yaml_parse_calendar_value";
669
670 char const * calendar_name =
671 yaml_parse_string_value(value_node, key_name, yaml_filename);
672
673 int calendar_type =
675 calendar_types, num_calendar_types, calendar_name);
676
678 calendar_type != INT_MAX,
679 "\"%s\" is not a valid calendar name", calendar_name);
680
681 return (calendarType)calendar_type;
682}
683
684static char const * yaml_parse_timestep_value(
685 fy_node_t value_node, char const * key_name, char const * yaml_filename,
686 enum yac_time_unit_type time_unit) {
687 char const * routine_name = "yaml_parse_timestep_value";
688
690 time_unit != TIME_UNIT_UNDEFINED, "time unit is not yet defined");
692 value_node && fy_node_is_scalar(value_node),
693 "unsupported node type for \"%s\" (the node is expected to be scalar)",
694 key_name);
695 char const * timestep =
696 yaml_parse_string_value(value_node, key_name, yaml_filename);
697 char const * timestep_iso =
698 yac_time_to_ISO(timestep, time_unit);
699
701 timestep_iso, "valid to convert timestep \"%s\" to ISO 8601 format",
702 timestep);
703
704 return strdup(timestep_iso);
705}
706
708 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
709 char const * routine_name = "yaml_parse_timestep_unit_value";
710
711 char const * timestep_unit_str =
712 yaml_parse_string_value(value_node, key_name, yaml_filename);
713
714 int timestep_unit =
716 timestep_units, num_timestep_units, timestep_unit_str);
717
719 timestep_unit != INT_MAX,
720 "\"%s\" is not a valid time step unit", timestep_unit_str);
721
722 return (enum yac_time_unit_type)timestep_unit;
723}
724
726 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
727 char const * routine_name = "yaml_parse_time_reduction_value";
728
729 char const * time_reduction_str =
730 yaml_parse_string_value(value_node, key_name, yaml_filename);
731
732 int time_reduction =
734 time_operations, num_time_operations, time_reduction_str);
735
737 time_reduction != INT_MAX,
738 "\"%s\" is not a valid time reduction type in", time_reduction_str);
739
740 return (enum yac_reduction_type)time_reduction;
741}
742
744 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
745 char const * routine_name = "yaml_parse_integer_value";
746
747 char const * integer_str =
748 yaml_parse_string_value(value_node, key_name, yaml_filename);
749
750 char * endptr;
751 long int long_value = strtol(integer_str, &endptr, 10);
752
754 (endptr != integer_str) && (*endptr == '\0') &&
755 (long_value >= INT_MIN) && (long_value <= INT_MAX),
756 "\"%s\" is not a valid integer value", integer_str);
757
758 return (int)long_value;
759}
760
762 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
763 char const * routine_name = "yaml_parse_double_value";
764
765 char const * double_str =
766 yaml_parse_string_value(value_node, key_name, yaml_filename);
767
768 char * endptr;
769 double dble_value = strtod(double_str, &endptr);
770
772 (endptr != double_str) && (*endptr == '\0'),
773 "\"%s\" is not a valid double value", double_str);
774
775 return dble_value;
776}
777
779 struct yac_name_type_pair const * valid_values, size_t num_valid_values,
780 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
781 char const * routine_name = "yaml_parse_enum_value";
782
783 char const * value_str =
784 yaml_parse_string_value(value_node, key_name, yaml_filename);
785
786 int value =
788 valid_values, num_valid_values, value_str);
789
791 value != INT_MAX,
792 "\"%s\" is not a valid enum value for \"%s\" ", value_str, key_name);
793
794 return value;
795}
796
798 char const ** interpolation_type_str, fy_node_t * parameter_node,
799 fy_node_t interp_method_node, char const * yaml_filename) {
800 char const * routine_name = "yaml_parse_base_interp_method_node";
801
803 fy_node_is_scalar(interp_method_node) ||
804 fy_node_is_mapping(interp_method_node),
805 "unsupported interpolation method node type "
806 "(interpolation methods are expected to be defined as either scalar "
807 "or maps)");
808
809 switch(fy_node_get_type(interp_method_node)) {
810 default:
811 case (FYNT_SCALAR):
812 *interpolation_type_str =
814 interp_method_node, "interpolation method name", yaml_filename);
815 *parameter_node = NULL;
816 break;
817
818 case (FYNT_MAPPING):
819
821 fy_node_mapping_item_count(interp_method_node) == 1,
822 "base interpolation method node is only allowed to have one pair ");
823
824 fy_node_pair_t base_interp_method_pair =
825 fy_node_mapping_get_by_index(interp_method_node, 0);
826
827 fy_node_t base_interp_method_key_node =
828 fy_node_pair_key(base_interp_method_pair);
829
830 *interpolation_type_str =
832 base_interp_method_key_node, "interpolation method name",
833 yaml_filename);
834
835 fy_node_t base_interp_method_value_node =
836 fy_node_pair_value(base_interp_method_pair);
837
839 fy_node_is_mapping(base_interp_method_value_node),
840 "unsupported base interpolation method value node type "
841 "for interpolation method \"%s\" "
842 "(interpolation method parameters are expected to be "
843 "defined as maps)", *interpolation_type_str);
844
845 *parameter_node = base_interp_method_value_node;
846 break;
847 }
848}
849
852 struct interp_method_parameter const * parameter,
853 fy_node_t value_node, char const * interpolation_name,
854 char const * yaml_filename) {
855 char const * routine_name = "yaml_parse_interp_method_parameter_value";
856
858 (parameter->type == ENUM_PARAM) ||
859 (parameter->type == INT_PARAM) ||
860 (parameter->type == DBLE_PARAM) ||
861 (parameter->type == DEG_PARAM) ||
862 (parameter->type == BOOL_PARAM) ||
863 (parameter->type == STR_PARAM),
864 "unsupported parameter type for interpolation method \"%s\"",
865 interpolation_name);
866
867 interp_method_parameter_value parameter_value;
868
869 switch(parameter->type) {
870 default:
871 case (ENUM_PARAM):
872 parameter_value.enum_value =
874 parameter->data.enum_param.valid_values,
876 value_node, "interpolation method enum parameter value",
877 yaml_filename);
878 break;
879 case (INT_PARAM):
880 parameter_value.int_value =
882 value_node, "interpolation method integer parameter value",
883 yaml_filename);
885 (parameter_value.int_value >= parameter->data.int_param.valid_min) &&
886 (parameter_value.int_value <= parameter->data.int_param.valid_max),
887 "\"%d\" is not a valid integer parameter value for parameter \"%s\" "
888 "of interpolation method \"%s\" "
889 "(valid range: %d <= value <= %d)",
890 parameter_value.int_value, parameter->name, interpolation_name,
891 parameter->data.int_param.valid_min,
892 parameter->data.int_param.valid_max);
893 break;
894 case (DBLE_PARAM):
895 parameter_value.dble_value =
897 value_node, "interpolation method double parameter value",
898 yaml_filename);
900 (parameter_value.dble_value >= parameter->data.dble_param.valid_min) &&
901 (parameter_value.dble_value <= parameter->data.dble_param.valid_max),
902 "\"%lf\" is not a valid double parameter value for parameter \"%s\" "
903 "of interpolation method \"%s\" "
904 "(valid range: %e <= value <= %e)",
905 parameter_value.dble_value, parameter->name, interpolation_name,
906 parameter->data.dble_param.valid_min,
907 parameter->data.dble_param.valid_max);
908 break;
909 case (DEG_PARAM):
910 parameter_value.dble_value =
912 value_node, "interpolation method double parameter value",
913 yaml_filename);
915 (parameter_value.dble_value >= parameter->data.dble_param.valid_min) &&
916 (parameter_value.dble_value <= parameter->data.dble_param.valid_max),
917 "\"%lf\" is not a valid double parameter value for parameter \"%s\" "
918 "of interpolation method \"%s\" "
919 "(valid range: %e <= value <= %e)",
920 parameter_value.dble_value, parameter->name, interpolation_name,
921 parameter->data.dble_param.valid_min,
922 parameter->data.dble_param.valid_max);
923 parameter_value.dble_value *= YAC_RAD;
924 break;
925 case (BOOL_PARAM):
926 parameter_value.bool_value =
928 bool_names, num_bool_names, value_node,
929 "interpolation method bool parameter value", yaml_filename);
930 break;
931 case (STR_PARAM):
932 parameter_value.str_value =
934 value_node, "interpolation method string parameter value",
935 yaml_filename);
937 strlen(parameter_value.str_value) <
938 parameter->data.str_param.max_str_len,
939 "\"%s\" is not a valid string parameter value for parameter \"%s\" "
940 "of interpolation method \"%s\" "
941 "(maximum string length: %d)",
942 parameter_value.str_value, parameter->name, interpolation_name,
943 (int)(parameter->data.str_param.max_str_len - 1));
944 break;
945 };
946
947 return parameter_value;
948}
949
951 interp_method_parameter_value * parameter_values,
952 struct interp_method_parameter const * parameters, size_t num_parameters,
953 fy_node_pair_t parameter_pair, char const * interpolation_name,
954 char const * yaml_filename) {
955 char const * routine_name = "yaml_parse_interp_method_parameter";
956
957 char const * parameter_name =
959 fy_node_pair_key(parameter_pair),
960 "interpolation method parameter name", yaml_filename);
961
962 int found_flag = 0;
963 for (size_t i = 0; (i < num_parameters) && !found_flag; ++i)
964 if ((found_flag = !strcmp(parameter_name, parameters[i].name)))
965 parameter_values[i] =
967 &parameters[i], fy_node_pair_value(parameter_pair),
968 interpolation_name, yaml_filename);
969
971 found_flag,
972 "\"%s\" is not a valid parameter for interpolation method \"%s\"",
973 parameter_name, interpolation_name);
974}
975
977 interp_method_parameter_value * parameter_values,
978 struct yac_interpolation_method const * interp_method,
979 fy_node_t parameter_node, char const * yaml_filename) {
980 char const * routine_name = "yaml_parse_interp_method_parameters";
981
982 // set default parameter values
983 for (size_t i = 0; i < interp_method->num_parameters; ++i)
984 parameter_values[i] = interp_method->parameters[i].default_value;
985
986 // if there are no parameters
987 if (!parameter_node) return;
988
990 fy_node_is_mapping(parameter_node),
991 "unsupported interpolation method parameter node type "
992 "for interpolation method \"%s\" "
993 "(interpolation method parameters are expected to be defined as maps)",
994 interp_method->name);
995
996 // parse parameter
997 void * iter = NULL;
998 fy_node_pair_t pair;
999 while ((pair = fy_node_mapping_iterate(parameter_node, &iter)))
1001 parameter_values, interp_method->parameters,
1002 interp_method->num_parameters, pair, interp_method->name,
1003 yaml_filename);
1004}
1005
1007 struct field_couple_buffer * field_buffer,
1008 fy_node_t interp_method_node, char const * yaml_filename) {
1009 char const * routine_name = "yaml_parse_interp_method";
1010
1011 char const * interpolation_type_str;
1012 fy_node_t parameter_node;
1013
1015 &interpolation_type_str, &parameter_node,
1016 interp_method_node, yaml_filename);
1017
1018 struct yac_interpolation_method const * interp_method = NULL;
1019
1020 for (int i = 0; (i < NUM_INTERPOLATION_METHODS) && (!interp_method); ++i)
1021 if (!strcmp(interpolation_type_str, interpolation_methods[i].name))
1023
1026 "\"%s\" is not a valid interpolation method",
1027 interpolation_type_str);
1028
1030 interp_method_paramter_values[interp_method->num_parameters];
1032 interp_method_paramter_values, interp_method,
1033 parameter_node, yaml_filename);
1034 interp_method->add_interpolation(
1035 field_buffer, interp_method_paramter_values, yaml_filename);
1036}
1037
1039 struct field_couple_buffer * field_buffer,
1040 fy_node_t interp_stack_node, char const * yaml_filename) {
1041 char const * routine_name = "yaml_parse_interp_stack_value";
1042
1044 fy_node_is_sequence(interp_stack_node),
1045 "unsupported interpolation stack node type"
1046 "(interpolation stacks are expected to be defined as a sequence)");
1047
1048 // parse couplings
1049 void * iter = NULL;
1050 fy_node_t interp_stack_item;
1051 while ((interp_stack_item =
1052 fy_node_sequence_iterate(interp_stack_node, &iter)))
1054 field_buffer, interp_stack_item, yaml_filename);
1055}
1056
1057static struct field_couple_field_names yaml_parse_field_name(
1058 fy_node_t field_node, const char * yaml_filename) {
1059 char const * routine_name = "yaml_parse_field_name";
1060
1062 fy_node_is_scalar(field_node) ||
1063 fy_node_is_mapping(field_node),
1064 "unsupported field name node type "
1065 "(field name is either scalars or a map)");
1066
1067 struct field_couple_field_names field_name;
1068
1069 // if the node contains one name for both source and target field
1070 if (fy_node_is_scalar(field_node)) {
1071
1072 field_name.src =
1073 ((field_name.tgt =
1074 yaml_parse_string_value(field_node, "field name", yaml_filename)));
1075
1076 // if the node contains different names for the source and target field
1077 } else {
1078 field_name.src =
1079 fy_node_mapping_lookup_scalar0_by_simple_key(
1080 field_node, "src", (size_t)-1);
1081 field_name.tgt =
1082 fy_node_mapping_lookup_scalar0_by_simple_key(
1083 field_node, "tgt", (size_t)-1);
1084
1086 field_name.src && field_name.tgt &&
1087 (fy_node_mapping_item_count(field_node) == 2),
1088 "invalid field name mapping node "
1089 "(field name mapping node has to contain two maps "
1090 "with the keys \"src\" and \"tgt\")")
1091 }
1092
1093 return field_name;
1094}
1095
1097 char const *** values, size_t * num_values,
1098 fy_node_t values_node, char const * sequence_name,
1099 const char * yaml_filename) {
1100 char const * routine_name = "yaml_parse_string_sequence";
1101
1103 (*values == NULL) && (*num_values == 0),
1104 "values have already been set for sequence \"%s\"",
1105 sequence_name);
1106
1107 // if the field node contains multiple fields
1108 if (fy_node_is_sequence(values_node)) {
1109
1110 *num_values = (size_t)fy_node_sequence_item_count(values_node);
1111 *values = xmalloc(*num_values * sizeof(**values));
1112 for (size_t value_idx = 0; value_idx < *num_values; ++value_idx)
1113 (*values)[value_idx] =
1115 fy_node_sequence_get_by_index(values_node, value_idx),
1116 sequence_name, yaml_filename);
1117 } else {
1118 *num_values = 1;
1119 *values = xmalloc(sizeof(**values));
1120 **values =
1122 values_node, sequence_name, yaml_filename);
1123 }
1124}
1125
1127 struct field_couple_field_names ** field_names,
1128 size_t * num_field_names, fy_node_t fields_node,
1129 const char * yaml_filename) {
1130
1131 // if the field node contains multiple fields
1132 if (fy_node_is_sequence(fields_node)) {
1133
1134 size_t start_idx = *num_field_names;
1135 *num_field_names += (size_t)fy_node_sequence_item_count(fields_node);
1136 *field_names =
1137 xrealloc(*field_names, *num_field_names * sizeof(**field_names));
1138 for (size_t i = start_idx; i < *num_field_names; ++i)
1139 (*field_names)[i] =
1141 fy_node_sequence_get_by_index(fields_node, i), yaml_filename);
1142 } else {
1143 ++*num_field_names;
1144 *field_names =
1145 xrealloc(*field_names, *num_field_names * sizeof(**field_names));
1146 (*field_names)[*num_field_names-1] =
1147 yaml_parse_field_name(fields_node, yaml_filename);
1148 }
1149}
1150
1152 struct field_couple_buffer * field_buffer,
1153 fy_node_pair_t couple_pair, const char * yaml_filename,
1154 enum yac_time_unit_type time_unit) {
1155
1156 enum yaml_couple_key_types couple_key_type =
1159 yaml_couple_keys, num_yaml_couple_keys,
1160 fy_node_pair_key(couple_pair),
1161 "couple configuration parameter name", yaml_filename);
1162 char const * couple_key_name =
1164 yaml_couple_keys, num_yaml_couple_keys, couple_key_type);
1165
1166 fy_node_t value_node = fy_node_pair_value(couple_pair);
1167
1168 switch (couple_key_type) {
1169 default:
1170 case (SOURCE_COMPONENT):
1171 field_buffer->src.comp_name =
1172 yaml_parse_string_value(value_node, couple_key_name, yaml_filename);
1173 break;
1174 case (SOURCE_GRID):
1175 field_buffer->src.grid_name =
1176 yaml_parse_string_value(value_node, couple_key_name, yaml_filename);
1177 break;
1178 case (TARGET_COMPONENT):
1179 field_buffer->tgt.comp_name =
1180 yaml_parse_string_value(value_node, couple_key_name, yaml_filename);
1181 break;
1182 case (TARGET_GRID):
1183 field_buffer->tgt.grid_name =
1184 yaml_parse_string_value(value_node, couple_key_name, yaml_filename);
1185 break;
1186 case (FIELD):
1188 &(field_buffer->field_names),
1189 &(field_buffer->num_field_names),
1190 value_node, yaml_filename);
1191 break;
1192 case (COUPLING_PERIOD):
1193 field_buffer->coupling_period =
1195 value_node, couple_key_name, yaml_filename, time_unit);
1196 break;
1197 case (TIME_REDUCTION):
1198 field_buffer->time_reduction =
1200 value_node, couple_key_name, yaml_filename);
1201 break;
1202 case (SOURCE_LAG):
1203 field_buffer->src.lag =
1205 value_node, couple_key_name, yaml_filename);
1206 break;
1207 case (TARGET_LAG):
1208 field_buffer->tgt.lag =
1210 value_node, couple_key_name, yaml_filename);
1211 break;
1212 case (WEIGHT_FILE_NAME):
1213 field_buffer->weight_file_name =
1215 value_node, couple_key_name, yaml_filename);
1216 break;
1217 case (MAPPING_SIDE):
1218 field_buffer->mapping_on_source =
1220 mapping_sides, num_mapping_sides,
1221 value_node, couple_key_name, yaml_filename);
1222 break;
1223 case (SCALE_FACTOR):
1224 field_buffer->scale_factor =
1226 value_node, couple_key_name, yaml_filename);
1227 break;
1228 case (SCALE_SUMMAND):
1229 field_buffer->scale_summand =
1231 value_node, couple_key_name, yaml_filename);
1232 break;
1233 case (INTERPOLATION):
1235 field_buffer, value_node, yaml_filename);
1236 break;
1237 case (SOURCE_MASK_NAME):
1238 case (SOURCE_MASK_NAMES):
1240 &(field_buffer->src_mask_names),
1241 &(field_buffer->num_src_mask_names),
1242 value_node, couple_key_name, yaml_filename);
1243 break;
1244 case (TARGET_MASK_NAME):
1245 field_buffer->tgt_mask_name =
1247 value_node, couple_key_name, yaml_filename);
1248 break;
1249 }
1250}
1251
1253 struct yac_couple_config * couple_config, fy_node_t couple_node,
1254 char const * yaml_filename, enum yac_time_unit_type time_unit) {
1255 char const * routine_name = "yaml_parse_couple";
1256
1258 fy_node_is_mapping(couple_node),
1259 "unsupported couple node type "
1260 "(couples are expected to be defined as a mapping)");
1261
1262 // initialise field configuration buffer with default values
1263 struct field_couple_buffer field_buffer = {
1264 .src.comp_name = NULL,
1265 .src.grid_name = NULL,
1266 .tgt.comp_name = NULL,
1267 .tgt.grid_name = NULL,
1268 .field_names = NULL,
1269 .num_field_names = 0,
1270 .coupling_period = NULL,
1271 .time_reduction = TIME_NONE,
1272 .interp_stack = yac_interp_stack_config_new(),
1273 .src.lag = 0,
1274 .tgt.lag = 0,
1275 .weight_file_name = NULL,
1276 .mapping_on_source = 1,
1277 .scale_factor = 1.0,
1278 .scale_summand = 0.0,
1279 .src_mask_names = NULL,
1280 .num_src_mask_names = 0,
1281 .tgt_mask_name = NULL};
1282
1283 // parse couple
1284 void * iter = NULL;
1285 fy_node_pair_t pair;
1286 while ((pair = fy_node_mapping_iterate(couple_node, &iter)))
1288 &field_buffer, pair, yaml_filename, time_unit);
1289
1291 field_buffer.src.comp_name, "missing source component name");
1293 field_buffer.src.grid_name,
1294 "missing source grid name (component \"%s\")",
1295 field_buffer.src.comp_name);
1297 field_buffer.tgt.comp_name,
1298 "missing target component name");
1300 field_buffer.tgt.grid_name,
1301 "missing target grid name (component \"%s\")",
1302 field_buffer.tgt.comp_name);
1304 field_buffer.num_field_names > 0,
1305 "missing field names "
1306 "(source component \"%s\" source grid \"%s\" "
1307 "target component \"%s\" target grid \"%s\")",
1308 field_buffer.src.comp_name, field_buffer.src.grid_name,
1309 field_buffer.tgt.comp_name, field_buffer.tgt.grid_name);
1311 field_buffer.coupling_period,
1312 "missing coupling period "
1313 "(source component \"%s\" source grid \"%s\" "
1314 "target component \"%s\" target grid \"%s\")",
1315 field_buffer.src.comp_name, field_buffer.src.grid_name,
1316 field_buffer.tgt.comp_name, field_buffer.tgt.grid_name);
1317
1318 for (size_t i = 0; i < field_buffer.num_field_names; ++i)
1320 couple_config,
1321 field_buffer.src.comp_name,
1322 field_buffer.src.grid_name,
1323 field_buffer.field_names[i].src,
1324 field_buffer.tgt.comp_name,
1325 field_buffer.tgt.grid_name,
1326 field_buffer.field_names[i].tgt,
1327 field_buffer.coupling_period,
1328 field_buffer.time_reduction,
1329 field_buffer.interp_stack,
1330 field_buffer.src.lag,
1331 field_buffer.tgt.lag,
1332 field_buffer.weight_file_name,
1333 field_buffer.mapping_on_source,
1334 field_buffer.scale_factor,
1335 field_buffer.scale_summand,
1336 field_buffer.num_src_mask_names,
1337 field_buffer.src_mask_names,
1338 field_buffer.tgt_mask_name);
1339
1340 // cleanup
1341 free((void*)field_buffer.field_names);
1342 free((void*)field_buffer.coupling_period);
1344}
1345
1347 struct yac_couple_config * couple_config,
1348 fy_node_t coupling_node, char const * yaml_filename,
1349 enum yac_time_unit_type time_unit) {
1350 char const * routine_name = "yaml_parse_coupling";
1351
1352 // check if the coupling node is empty -> nothing to be read
1353 if (!coupling_node) return;
1354
1356 fy_node_is_sequence(coupling_node),
1357 "unsupported coupling node type "
1358 "(couplings are expected to be defined as a sequence)");
1359
1360 // parse couplings
1361 void * iter = NULL;
1362 fy_node_t couple_node;
1363 while ((couple_node = fy_node_sequence_iterate(coupling_node, &iter)))
1364 yaml_parse_couple(couple_config, couple_node, yaml_filename, time_unit);
1365}
1366
1368 struct debug_global_config_buffer * global_config_buffer,
1369 fy_node_pair_t global_config_pair,
1370 const char * yaml_filename) {
1371
1372 enum yaml_debug_global_config_key_types debug_global_config_key_type =
1375 yaml_debug_global_config_keys, num_yaml_debug_global_config_keys,
1376 fy_node_pair_key(global_config_pair),
1377 "debug global config configuration parameter name", yaml_filename);
1378 char const * debug_global_config_key_name =
1380 yaml_debug_global_config_keys,
1381 num_yaml_debug_global_config_keys, debug_global_config_key_type);
1382
1383 fy_node_t value_node = fy_node_pair_value(global_config_pair);
1384
1385 switch (debug_global_config_key_type) {
1386 default:
1388 global_config_buffer->filename =
1390 value_node, debug_global_config_key_name, yaml_filename);
1391 break;
1393 global_config_buffer->filetype =
1394 (enum yac_config_filetype)
1396 config_filetypes, num_config_filetypes,
1397 value_node, debug_global_config_key_name, yaml_filename);
1398 break;
1399 };
1400}
1401
1403 struct yac_couple_config * couple_config, fy_node_t global_config_node,
1404 char const * yaml_filename) {
1405 char const * routine_name = "yaml_parse_debug_global_config_value";
1406
1408 fy_node_is_mapping(global_config_node),
1409 "unsupported debug global config node type "
1410 "(debug global config is expected to be defined as a mapping");
1411
1412 struct debug_global_config_buffer global_config_buffer = {
1413 .filename = NULL,
1414 .filetype = YAC_CONFIG_FILETYPE_INVALID};
1415
1416 // parse couplings
1417 void * iter = NULL;
1418 fy_node_pair_t pair;
1419 while ((pair = fy_node_mapping_iterate(global_config_node, &iter)))
1421 &global_config_buffer, pair, yaml_filename);
1422
1424 (global_config_buffer.filename == NULL) ||
1425 (global_config_buffer.filetype != YAC_CONFIG_FILETYPE_INVALID),
1426 "ERROR(yaml_parse_debug_global_config): filename is set but type is not");
1427
1429 (global_config_buffer.filetype == YAC_CONFIG_FILETYPE_INVALID) ||
1430 (global_config_buffer.filename != NULL),
1431 "ERROR(yaml_parse_debug_global_config): filetype is set but name is not");
1432
1433 if (global_config_buffer.filetype != YAC_CONFIG_FILETYPE_INVALID)
1435 couple_config, global_config_buffer.filename,
1436 global_config_buffer.filetype);
1437 else
1438 yac_couple_config_disable_output(couple_config);
1439}
1440
1442 struct yac_couple_config * couple_config, fy_node_pair_t debug_pair,
1443 const char * yaml_filename) {
1444
1445 enum yaml_debug_key_types debug_key_type =
1448 yaml_debug_keys, num_yaml_debug_keys,
1449 fy_node_pair_key(debug_pair),
1450 "debug configuration parameter name", yaml_filename);
1451 // char const * debug_key_name =
1452 // yac_name_type_pair_get_name(
1453 // yaml_debug_keys, num_yaml_debug_keys, debug_key_type);
1454
1455 fy_node_t value_node = fy_node_pair_value(debug_pair);
1456
1457 switch (debug_key_type) {
1458 default:
1459 case(GLOBAL_CONFIG):
1461 couple_config, value_node, yaml_filename);
1462 break;
1463 };
1464}
1465
1467 struct yac_couple_config * couple_config,
1468 fy_node_t debug_node, char const * yaml_filename) {
1469 char const * routine_name = "yaml_parse_debug";
1470
1471 // check if the debug node is empty -> nothing to be read
1472 if (!debug_node) return;
1473
1475 fy_node_is_mapping(debug_node),
1476 "unsupported debug node type "
1477 "(debug is expected to be defined as a mapping)");
1478
1479 // parse couplings
1480 void * iter = NULL;
1481 fy_node_pair_t pair;
1482 while ((pair = fy_node_mapping_iterate(debug_node, &iter)))
1483 yaml_parse_debug_map_pair(couple_config, pair, yaml_filename);
1484}
1485
1487 struct yac_couple_config * couple_config, fy_node_pair_t base_pair,
1488 const char * yaml_filename, enum yac_time_unit_type * time_unit) {
1489 char const * routine_name = "yaml_parse_base_map_pair";
1490
1491 fy_node_t key_node = fy_node_pair_key(base_pair);
1492
1494 fy_node_is_scalar(key_node),
1495 "unsupported key node type "
1496 "(key nodes are expected to be scalar nodes)");
1497
1498 char const * base_key_name = fy_node_get_scalar0(key_node);
1499 int base_key_type =
1501 yaml_base_keys, num_yaml_base_keys, base_key_name);
1502
1504 (base_key_type == INT_MAX) || // for unknown keys, which are skipped
1505 (base_key_type == START_DATE) ||
1506 (base_key_type == END_DATE) ||
1507 (base_key_type == CALENDAR) ||
1508 (base_key_type == TIMESTEP_UNIT) ||
1509 (base_key_type == COUPLING) ||
1510 (base_key_type == DEBUG),
1511 "unsupported base key name \"%s\"",
1512 base_key_name);
1513
1514 fy_node_t value_node = fy_node_pair_value(base_pair);
1515
1516 switch (base_key_type) {
1517 case (START_DATE):
1519 couple_config,
1521 value_node, base_key_name, yaml_filename), NULL);
1522 break;
1523 case (END_DATE):
1525 couple_config, NULL,
1527 value_node, base_key_name, yaml_filename));
1528 break;
1529 case (CALENDAR):
1532 value_node, base_key_name, yaml_filename));
1533 break;
1534 case (TIMESTEP_UNIT): {
1535 enum yac_time_unit_type time_unit_ =
1537 value_node, base_key_name, yaml_filename);
1539 (*time_unit == TIME_UNIT_UNDEFINED) || (*time_unit == time_unit_),
1540 "inconsistent redefinition of time unit")
1541 *time_unit = time_unit_;
1542 break;
1543 }
1544 case (COUPLING):
1546 (*time_unit != TIME_UNIT_UNDEFINED),
1547 "time unit has to be defined before the couplings")
1549 couple_config, value_node, yaml_filename, *time_unit);
1550 break;
1551 case (DEBUG):
1553 couple_config, value_node, yaml_filename);
1554 default:
1555 // nothing to be done
1556 break;
1557 }
1558}
1559
1561 struct yac_couple_config * couple_config, fy_document_t document,
1562 const char * yaml_filename) {
1563 char const * routine_name = "yaml_parse_document";
1564
1565 // get root node of document
1566 fy_node_t root_node = fy_document_root(document);
1567
1568 // if the configuration file is empty
1569 if (!root_node) return;
1570
1572 fy_node_is_mapping(root_node),
1573 "unsupported root node type (root node is expected to be a mapping node)");
1574
1575 // parse base root mappings
1576 enum yac_time_unit_type time_unit = TIME_UNIT_UNDEFINED;
1577 void * iter = NULL;
1578 fy_node_pair_t pair;
1579 while ((pair = fy_node_mapping_iterate(root_node, &iter)))
1580 yaml_parse_base_map_pair(couple_config, pair, yaml_filename, &time_unit);
1581}
1582
1584 struct yac_couple_config * couple_config, const char * yaml_filename,
1585 int parse_flags) {
1586 char const * routine_name = "yac_yaml_read_coupling";
1587
1588 // check whether the yaml configuration file exists
1590 yac_file_exists(yaml_filename),
1591 "ERROR(%s): YAML configuration file could not be found \"%s\"",
1592 routine_name, yaml_filename);
1593
1594 // open yaml configuration file
1595 FILE * config_file = xfopen(yaml_filename, "r");
1597 config_file,
1598 "ERROR(%s): could not open YAML configuration file \"%s\"",
1599 routine_name, yaml_filename);
1600
1601 // parse yaml configuration file into document
1602 struct fy_parse_cfg parse_config =
1603 {.search_path = ".",
1604 .userdata = NULL,
1605 .diag = NULL};
1606 parse_config.flags =
1607 (enum fy_parse_cfg_flags)parse_flags;
1608
1609 fy_document_t document =
1610 fy_document_build_from_fp(&parse_config, config_file);
1612 document,
1613 "ERROR(%s): could not parse YAML configuration file \"%s\"",
1614 routine_name, yaml_filename);
1615
1616 // resolve anchors and merge keys
1618 !fy_document_resolve(document),
1619 "could not resolve anchors and merge keys");
1620
1621 // parse document into couple configuration
1622 yaml_parse_document(couple_config, document, yaml_filename);
1623
1624 // cleanup
1625 fy_document_destroy(document);
1626 xfclose(config_file);
1627
1628 return;
1629}
1630
1632 fy_document_t document, char const * value) {
1633
1634 // return NULL if value is empty
1635 if (!value) return (fy_node_t)NULL;
1636
1637 fy_node_t scalar_node =
1638 fy_node_create_scalar_copy(document, value, strlen(value));
1639 YAC_ASSERT(
1640 scalar_node,
1641 "ERROR(yac_yaml_create_scalar): failed to create scalar node");
1642
1643 return scalar_node;
1644}
1645
1647 fy_document_t document, int value) {
1648
1649 char str_value[16];
1650 int value_size = snprintf(str_value, sizeof(str_value), "%d", value);
1652 (value_size >= 0) && ((size_t)value_size < sizeof(str_value)),
1653 "ERROR(yac_yaml_create_scalar_int): "
1654 "could not write \"%d\" to string buffer of size %zu",
1655 value, sizeof(str_value));
1656
1657 return yac_yaml_create_scalar(document, str_value);
1658}
1659
1661 fy_document_t document, double value) {
1662
1663 char str_value[32];
1664 int value_size = snprintf(str_value, sizeof(str_value), "%g", value);
1666 (value_size >= 0) && ((size_t)value_size < sizeof(str_value)),
1667 "ERROR(yac_yaml_create_scalar_dble): "
1668 "could not write \"%g\" to string buffer of size %zu",
1669 value, sizeof(str_value));
1670
1671 return yac_yaml_create_scalar(document, str_value);
1672}
1673
1675 fy_document_t document, char const * const * values, size_t num_values) {
1676
1677 // return NULL if sequence is empty
1678 if (num_values == 0) return (fy_node_t)NULL;
1679
1680 YAC_ASSERT(
1681 values, "ERROR(yac_yaml_create_sequence_scalar): no values provided");
1682
1683 // create sequence node
1684 fy_node_t sequence_node = fy_node_create_sequence(document);
1685 YAC_ASSERT(
1686 sequence_node, "ERROR(yac_yaml_create_sequence_scalar): "
1687 "failed to create sequence node");
1688
1689 for (size_t value_idx = 0; value_idx < num_values; ++value_idx) {
1690 char const * value = values[value_idx];
1692 value, "ERROR(yac_yaml_create_sequence_scalar): "
1693 "invalid value at idx %zu", value_idx);
1694 int appending_failed =
1695 fy_node_sequence_append(
1696 sequence_node, yac_yaml_create_scalar(document, value));
1697 YAC_ASSERT(
1698 !appending_failed, "ERROR(yac_yaml_create_sequence_scalar): "
1699 "failed to append interpolation node");
1700 }
1701
1702 return sequence_node;
1703}
1704
1706 fy_node_t map, char const * key, fy_node_t value) {
1707
1708 // if the value node is empty, return
1709 if (!value) return;
1710
1711 YAC_ASSERT(
1712 key, "ERROR(yac_yaml_map_append): NULL key is not supported");
1713
1714 fy_document_t document = fy_node_document(map);
1715 YAC_ASSERT(
1716 document,
1717 "ERROR(yac_yaml_map_append): failed to get document from node");
1718
1719 // set key and value for root node
1720 int appending_failed =
1721 fy_node_mapping_append(
1722 map, yac_yaml_create_scalar(document, key), value);
1723 YAC_ASSERT(
1724 !appending_failed,
1725 "ERROR(yac_yaml_map_append): failed to append mapping node pair");
1726}
1727
1729 fy_node_t map, char const * key, char const * value) {
1730
1731 fy_document_t document = fy_node_document(map);
1732 YAC_ASSERT(
1733 document, "ERROR(yac_yaml_map_append_scalar): "
1734 "failed to get document from node");
1735
1737}
1738
1740 fy_node_t map, char const * key, int value) {
1741
1742 fy_document_t document = fy_node_document(map);
1743 YAC_ASSERT(
1744 document, "ERROR(yac_yaml_map_append_scalar_int): "
1745 "failed to get document from node");
1746
1748 map, key, yac_yaml_create_scalar_int(document, value));
1749}
1750
1752 fy_node_t map, char const * key, double value) {
1753
1754 fy_document_t document = fy_node_document(map);
1755 YAC_ASSERT(
1756 document, "ERROR(yac_yaml_map_append_scalar_dble): "
1757 "failed to get document from node");
1758
1760 map, key, yac_yaml_create_scalar_dble(document, value));
1761}
1762
1764 fy_document_t document, struct yac_couple_config * couple_config,
1765 size_t couple_idx, size_t field_couple_idx) {
1766
1767 const char * src_field_name;
1768 const char * tgt_field_name;
1770 couple_config, couple_idx, field_couple_idx,
1771 &src_field_name, &tgt_field_name);
1772
1773 // if both names are identical
1774 if (!strcmp(src_field_name, tgt_field_name))
1775 return yac_yaml_create_scalar(document, src_field_name);
1776
1777 // create field name node
1778 fy_node_t field_name_node = fy_node_create_mapping(document);
1779 YAC_ASSERT(
1780 field_name_node, "ERROR(yac_yaml_create_field_name_node): "
1781 "failed to create mapping node");
1782
1783 // add source field name
1784 yac_yaml_map_append_scalar(field_name_node, "src", src_field_name);
1785
1786 // add target field name
1787 yac_yaml_map_append_scalar(field_name_node, "tgt", tgt_field_name);
1788
1789 return field_name_node;
1790}
1791
1793 fy_node_t map,
1794 struct interp_method_parameter const * parameter,
1796
1797 YAC_ASSERT(
1798 (parameter->type == ENUM_PARAM) ||
1799 (parameter->type == INT_PARAM) ||
1800 (parameter->type == DBLE_PARAM) ||
1801 (parameter->type == BOOL_PARAM) ||
1802 (parameter->type == STR_PARAM) ||
1803 (parameter->type == DEG_PARAM),
1804 "ERROR(yac_yaml_map_append_parameter): unsupported parameter type");
1805
1806 char const * key = parameter->name;
1807
1808 switch (parameter->type) {
1809 default:
1810 case (ENUM_PARAM): {
1812 map, key,
1814 parameter->data.enum_param.valid_values,
1815 parameter->data.enum_param.num_valid_values,
1816 value.enum_value));
1817 break;
1818 }
1819 case (INT_PARAM): {
1820 yac_yaml_map_append_scalar_int(map, key, value.int_value);
1821 break;
1822 }
1823 case (DEG_PARAM):
1824 case (DBLE_PARAM): {
1825 yac_yaml_map_append_scalar_dble(map, key, value.dble_value);
1826 break;
1827 }
1828 case (BOOL_PARAM): {
1830 map, key,
1832 bool_names, num_bool_names, value.bool_value));
1833 break;
1834 }
1835 case (STR_PARAM): {
1836 yac_yaml_map_append_scalar(map, key, value.str_value);
1837 break;
1838 }
1839 };
1840}
1841
1846
1847 YAC_ASSERT(
1848 (type == ENUM_PARAM) ||
1849 (type == INT_PARAM) ||
1850 (type == DBLE_PARAM) ||
1851 (type == BOOL_PARAM) ||
1852 (type == STR_PARAM) ||
1853 (type == DEG_PARAM),
1854 "ERROR(compare_parameter_values): "
1855 "invalid interpolation method parameter value type");
1856
1857 switch (type) {
1858 default:
1859 case (ENUM_PARAM):
1860 return
1861 (a->enum_value > b->enum_value) - (a->enum_value < b->enum_value);
1862 case (INT_PARAM):
1863 return
1864 (a->int_value > b->int_value) - (a->int_value < b->int_value);
1865 case (DEG_PARAM):
1866 case (DBLE_PARAM):
1867 return
1868 (a->dble_value > b->dble_value) - (a->dble_value < b->dble_value);
1869 case (BOOL_PARAM):
1870 return
1871 (a->bool_value > b->bool_value) - (a->bool_value < b->bool_value);
1872 case (STR_PARAM):
1873 if ((a->str_value != NULL) && (b->str_value != NULL))
1874 return strcmp(a->str_value, b->str_value);
1875 else
1876 return (a->str_value != NULL) - (b->str_value != NULL);
1877 }
1878}
1879
1881 fy_document_t document,
1882 union yac_interp_stack_config_entry const * interp_stack_entry) {
1883
1884 enum yac_interpolation_list interp_type =
1885 yac_interp_stack_config_entry_get_type(interp_stack_entry);
1886
1887 struct yac_interpolation_method const * interp_method = NULL;
1888 for (size_t i = 0;
1890 if (interpolation_methods[i].type == interp_type)
1892
1893 struct interp_method_parameter const * parameters =
1894 interp_method->parameters;
1895 size_t num_parameters = interp_method->num_parameters;
1896
1898 parameter_values[MAX(num_parameters,1)];
1899 for (size_t param_idx = 0; param_idx < num_parameters; ++param_idx)
1900 parameter_values[param_idx] = parameters[param_idx].default_value;
1901
1902 interp_method->get_interpolation(interp_stack_entry, parameter_values);
1903
1904 // create parameter node
1905 fy_node_t parameter_node = fy_node_create_mapping(document);
1906 YAC_ASSERT(
1907 parameter_node, "ERROR(yac_yaml_create_interpolation_node): "
1908 "failed to create mapping node");
1909
1910 size_t num_non_default_parameters = 0;
1911 for (size_t param_idx = 0; param_idx < num_parameters; ++param_idx) {
1913 &parameters[param_idx].default_value,
1914 parameter_values + param_idx, parameters[param_idx].type)) {
1915 ++num_non_default_parameters;
1917 parameter_node, parameters + param_idx,
1918 parameter_values[param_idx]);
1919 }
1920 }
1921
1922 fy_node_t interpolation_node;
1923 if (num_non_default_parameters) {
1924
1925 // create interpolation node
1926 interpolation_node = fy_node_create_mapping(document);
1927 YAC_ASSERT(
1928 interpolation_node, "ERROR(yac_yaml_create_interpolation_node): "
1929 "failed to create mapping node");
1930
1932 interpolation_node, interp_method->name, parameter_node);
1933 } else {
1934
1935 // free parameter node
1936 fy_node_free(parameter_node);
1937
1938 interpolation_node =
1939 yac_yaml_create_scalar(document, interp_method->name);
1940 }
1941
1942 return interpolation_node;
1943}
1944
1946 fy_document_t document, struct yac_couple_config * couple_config,
1947 size_t couple_idx, size_t field_couple_idx) {
1948
1949 struct yac_interp_stack_config * interp_stack =
1951 couple_config, couple_idx, field_couple_idx);
1952
1953 YAC_ASSERT(
1954 interp_stack, "ERROR(yac_yaml_create_interpolation_stack_node): "
1955 "invalid interpolation stack");
1956
1957 // create interpolation stack node
1958 fy_node_t interp_stack_node = fy_node_create_sequence(document);
1959 YAC_ASSERT(
1960 interp_stack_node, "ERROR(yac_yaml_create_interpolation_stack_node): "
1961 "failed to create sequence node");
1962
1963 size_t interp_stack_size =
1965 YAC_ASSERT(
1966 interp_stack_size, "ERROR(yac_yaml_create_interpolation_stack_node): "
1967 "invalid interpolation stack size");
1968
1969 for (size_t interp_stack_idx = 0; interp_stack_idx < interp_stack_size;
1970 ++interp_stack_idx) {
1971 int appending_failed =
1972 fy_node_sequence_append(
1973 interp_stack_node,
1975 document,
1977 interp_stack, interp_stack_idx)));
1978 YAC_ASSERT(
1979 !appending_failed,
1980 "ERROR(yac_yaml_create_interpolation_stack_node): "
1981 "failed to append interpolation node");
1982 }
1983
1984 return interp_stack_node;
1985}
1986
1988 fy_node_t coupling_node, struct yac_couple_config * couple_config,
1989 size_t couple_idx, size_t field_couple_idx) {
1990
1991 fy_document_t document = fy_node_document(coupling_node);
1992 YAC_ASSERT(
1993 document, "ERROR(yac_yaml_append_couple_field_nodes): "
1994 "failed to get document from node");
1995
1996 // create couple node
1997 fy_node_t field_couple_node = fy_node_create_mapping(document);
1998 YAC_ASSERT(
1999 coupling_node, "ERROR(yac_yaml_append_couple_field_nodes): "
2000 "failed to create mapping node");
2001
2002 // get component names
2003 char const * src_component_name;
2004 char const * tgt_component_name;
2006 couple_config, couple_idx, field_couple_idx,
2007 &src_component_name, &tgt_component_name);
2008
2009 // add source component name
2011 field_couple_node,
2013 yaml_couple_keys, num_yaml_couple_keys, SOURCE_COMPONENT),
2014 src_component_name);
2015
2016 // add target component name
2018 field_couple_node,
2020 yaml_couple_keys, num_yaml_couple_keys, TARGET_COMPONENT),
2021 tgt_component_name);
2022
2023 // get grid names
2024 char const * src_grid_name;
2025 char const * tgt_grid_name;
2027 couple_config, couple_idx, field_couple_idx,
2028 &src_grid_name, &tgt_grid_name);
2029
2030 // add source grid name
2032 field_couple_node,
2034 yaml_couple_keys, num_yaml_couple_keys, SOURCE_GRID),
2035 src_grid_name);
2036
2037 // add target grid name
2039 field_couple_node,
2041 yaml_couple_keys, num_yaml_couple_keys, TARGET_GRID),
2042 tgt_grid_name);
2043
2044 // add field names
2046 field_couple_node,
2048 yaml_couple_keys, num_yaml_couple_keys, FIELD),
2050 document, couple_config, couple_idx, field_couple_idx));
2051
2052 // add coupling period
2054 field_couple_node,
2056 yaml_couple_keys, num_yaml_couple_keys, COUPLING_PERIOD),
2058 couple_config, couple_idx, field_couple_idx));
2059
2060 // add time reduction
2062 field_couple_node,
2064 yaml_couple_keys, num_yaml_couple_keys, TIME_REDUCTION),
2066 time_operations, num_time_operations,
2068 couple_config, couple_idx, field_couple_idx)));
2069
2070 // add source lag
2072 field_couple_node,
2074 yaml_couple_keys, num_yaml_couple_keys, SOURCE_LAG),
2076 couple_config, couple_idx, field_couple_idx));
2077
2078 // add target lag
2080 field_couple_node,
2082 yaml_couple_keys, num_yaml_couple_keys, TARGET_LAG),
2084 couple_config, couple_idx, field_couple_idx));
2085
2086 // add weight file name
2088 couple_config, couple_idx, field_couple_idx))
2090 field_couple_node,
2092 yaml_couple_keys, num_yaml_couple_keys, WEIGHT_FILE_NAME),
2094 couple_config, couple_idx, field_couple_idx));
2095
2096 // add mapping side
2098 field_couple_node,
2100 yaml_couple_keys, num_yaml_couple_keys, MAPPING_SIDE),
2102 mapping_sides, num_mapping_sides,
2104 couple_config, couple_idx, field_couple_idx)));
2105
2106 // add scale factor
2108 field_couple_node,
2110 yaml_couple_keys, num_yaml_couple_keys, SCALE_FACTOR),
2112 couple_config, couple_idx, field_couple_idx));
2113
2114 // add scale summand
2116 field_couple_node,
2118 yaml_couple_keys, num_yaml_couple_keys, SCALE_SUMMAND),
2120 couple_config, couple_idx, field_couple_idx));
2121
2122 // add interpolation
2124 field_couple_node,
2126 yaml_couple_keys, num_yaml_couple_keys, INTERPOLATION),
2128 document, couple_config, couple_idx, field_couple_idx));
2129
2130 // add source mask names
2131 char const * const * src_mask_names;
2132 size_t num_src_mask_names;
2134 couple_config, couple_idx, field_couple_idx,
2135 &src_mask_names, &num_src_mask_names);
2136 if (num_src_mask_names == 1)
2138 field_couple_node,
2140 yaml_couple_keys, num_yaml_couple_keys, SOURCE_MASK_NAME),
2141 src_mask_names[0]);
2142 else if (num_src_mask_names > 1)
2144 field_couple_node,
2146 yaml_couple_keys, num_yaml_couple_keys, SOURCE_MASK_NAMES),
2148 document, src_mask_names, num_src_mask_names));
2149
2150 // add target mask name
2151 char const * tgt_mask_name =
2153 couple_config, couple_idx, field_couple_idx);
2154 if (tgt_mask_name)
2156 field_couple_node,
2158 yaml_couple_keys, num_yaml_couple_keys, TARGET_MASK_NAME),
2159 tgt_mask_name);
2160
2161 int appending_failed =
2162 fy_node_sequence_append(coupling_node, field_couple_node);
2163 YAC_ASSERT(
2164 !appending_failed,
2165 "ERROR(yac_yaml_append_couple_field_nodes): "
2166 "failed to append field couple node");
2167}
2168
2170 fy_node_t coupling_node, struct yac_couple_config * couple_config,
2171 size_t couple_idx) {
2172
2173 size_t num_couple_fields =
2174 yac_couple_config_get_num_couple_fields(couple_config, couple_idx);
2175
2176 for (size_t field_couple_idx = 0;
2177 field_couple_idx < num_couple_fields; ++field_couple_idx)
2179 coupling_node, couple_config, couple_idx, field_couple_idx);
2180}
2181
2183 fy_document_t document, struct yac_couple_config * couple_config) {
2184
2185 size_t num_couples =
2186 yac_couple_config_get_num_couples(couple_config);
2187
2188 if (!num_couples) return NULL;
2189
2190 // create coupling node
2191 fy_node_t coupling_node = fy_node_create_sequence(document);
2192 YAC_ASSERT(
2193 coupling_node, "ERROR(yac_yaml_create_coupling_node): "
2194 "failed to create sequence node");
2195
2196 // for all couples
2197 for (size_t couple_idx = 0; couple_idx < num_couples; ++couple_idx)
2199 coupling_node, couple_config, couple_idx);
2200
2201 return coupling_node;
2202}
2203
2205 struct yac_couple_config * couple_config,
2206 int emit_flags) {
2207
2208 // create an empty document
2209 fy_document_t document = fy_document_create(NULL);
2210 YAC_ASSERT(
2211 document,
2212 "ERROR(yac_yaml_write_coupling): failed to create document");
2213
2214 // create root node
2215 fy_node_t root_node = fy_node_create_mapping(document);
2216 YAC_ASSERT(
2217 root_node,
2218 "ERROR(yac_yaml_write_coupling): failed to create mapping node");
2219
2220 // add start datetime
2222 root_node,
2224 yaml_base_keys, num_yaml_base_keys, START_DATE),
2226
2227 // add end datetime
2229 root_node,
2231 yaml_base_keys, num_yaml_base_keys, END_DATE),
2232 yac_couple_config_get_end_datetime(couple_config));
2233
2234 // add calendar
2236 root_node,
2238 yaml_base_keys, num_yaml_base_keys, CALENDAR),
2240 calendar_types, num_calendar_types, getCalendarType()));
2241
2242 // add timestep unit
2244 root_node,
2246 yaml_base_keys, num_yaml_base_keys, TIMESTEP_UNIT),
2248 timestep_units, num_timestep_units, C_ISO_FORMAT));
2249
2250 // add couplings
2252 root_node,
2254 yaml_base_keys, num_yaml_base_keys, COUPLING),
2255 yac_yaml_create_coupling_node(document, couple_config));
2256
2257 // set root node of the document
2258 int setting_root_failed =
2259 fy_document_set_root(document, root_node);
2260 YAC_ASSERT(
2261 !setting_root_failed, "ERROR(yac_yaml_write_coupling): "
2262 "failed to add root node to document");
2263
2264
2265 // emit document to string
2266 char * str_couple_config =
2267 fy_emit_document_to_string(
2268 document, (enum fy_emitter_cfg_flags)emit_flags);
2269
2270 YAC_ASSERT(
2271 str_couple_config, "ERROR(yac_yaml_write_coupling): "
2272 "failed to emit document to string");
2273
2274 // destroy document
2275 fy_document_destroy(document);
2276
2277 return str_couple_config;
2278}
static double yaml_parse_double_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
#define DEF_DEG_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX)
#define DEF_ENUM_PARAM(NAME, DEFAULT,...)
static void yaml_parse_couple(struct yac_couple_config *couple_config, fy_node_t couple_node, char const *yaml_filename, enum yac_time_unit_type time_unit)
yaml_debug_global_config_key_types
@ GLOBAL_CONFIG_FILETYPE
@ GLOBAL_CONFIG_FILENAME
#define DEF_INTERP_STACK_GET_NO_PARAM(NAME)
#define DEF_STR_PARAM(NAME, DEFAULT, MAX_STR_LEN)
#define DEF_INTERP_STACK_ADD_NO_PARAM(NAME)
static void yaml_parse_field_names(struct field_couple_field_names **field_names, size_t *num_field_names, fy_node_t fields_node, const char *yaml_filename)
int YAC_YAML_EMITTER_JSON
emit to JSON format
Definition config_yaml.c:62
static void yac_yaml_append_couple_nodes(fy_node_t coupling_node, struct yac_couple_config *couple_config, size_t couple_idx)
interp_method_parameter_value
static fy_node_t yac_yaml_create_scalar_dble(fy_document_t document, double value)
static interp_method_parameter_value yaml_parse_interp_method_parameter_value(struct interp_method_parameter const *parameter, fy_node_t value_node, char const *interpolation_name, char const *yaml_filename)
#define DEF_INTERP_STACK_ADD(NAME,...)
static fy_node_t yac_yaml_create_interpolation_node(fy_document_t document, union yac_interp_stack_config_entry const *interp_stack_entry)
struct fy_node_pair * fy_node_pair_t
Definition config_yaml.c:51
interp_method_parameter_value_type
@ ENUM_PARAM
@ DBLE_PARAM
@ DEG_PARAM
@ INT_PARAM
@ BOOL_PARAM
@ STR_PARAM
static calendarType yaml_parse_calendar_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static void yaml_parse_string_sequence(char const ***values, size_t *num_values, fy_node_t values_node, char const *sequence_name, const char *yaml_filename)
static int compare_parameter_values(interp_method_parameter_value const *a, interp_method_parameter_value const *b, enum interp_method_parameter_value_type type)
yaml_debug_key_types
@ GLOBAL_CONFIG
static void yac_yaml_map_append_scalar_dble(fy_node_t map, char const *key, double value)
static void yaml_parse_document(struct yac_couple_config *couple_config, fy_document_t document, const char *yaml_filename)
static int yaml_parse_enum_value(struct yac_name_type_pair const *valid_values, size_t num_valid_values, fy_node_t value_node, char const *key_name, char const *yaml_filename)
static void yaml_parse_debug_global_config_map_pair(struct debug_global_config_buffer *global_config_buffer, fy_node_pair_t global_config_pair, const char *yaml_filename)
void yac_yaml_read_coupling(struct yac_couple_config *couple_config, const char *yaml_filename, int parse_flags)
yaml_couple_key_types
@ WEIGHT_FILE_NAME
@ SCALE_SUMMAND
@ TARGET_COMPONENT
@ SOURCE_GRID
@ SOURCE_MASK_NAME
@ INTERPOLATION
@ SOURCE_MASK_NAMES
@ MAPPING_SIDE
@ TIME_REDUCTION
@ SOURCE_LAG
@ FIELD
@ TARGET_GRID
@ COUPLING_PERIOD
@ SOURCE_COMPONENT
@ SCALE_FACTOR
@ TARGET_LAG
@ TARGET_MASK_NAME
static int yaml_parse_integer_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static enum yac_time_unit_type yaml_parse_timestep_unit_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static void yac_yaml_map_append_scalar(fy_node_t map, char const *key, char const *value)
struct fy_document * fy_document_t
Definition config_yaml.c:49
#define DEF_INTERP_STACK_GET(NAME,...)
static struct field_couple_field_names yaml_parse_field_name(fy_node_t field_node, const char *yaml_filename)
static void yaml_parse_base_interp_method_node(char const **interpolation_type_str, fy_node_t *parameter_node, fy_node_t interp_method_node, char const *yaml_filename)
static fy_node_t yac_yaml_create_field_name_node(fy_document_t document, struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
static char const * yaml_parse_timestep_value(fy_node_t value_node, char const *key_name, char const *yaml_filename, enum yac_time_unit_type time_unit)
#define ADD_INTERPOLATION(NAME, TYPE)
#define DEF_DBLE_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX)
static void yaml_parse_interp_method(struct field_couple_buffer *field_buffer, fy_node_t interp_method_node, char const *yaml_filename)
#define DEF_NAME_TYPE_PAIR(NAME, TYPE)
int YAC_YAML_PARSER_JSON_AUTO
Definition config_yaml.c:64
#define YAML_ASSERT_F(CHECK, MSG,...)
static void yac_yaml_map_append_parameter(fy_node_t map, struct interp_method_parameter const *parameter, interp_method_parameter_value value)
int YAC_YAML_PARSER_DEFAULT
default parse flags (YAML format)
Definition config_yaml.c:63
static void yaml_parse_interp_stack_value(struct field_couple_buffer *field_buffer, fy_node_t interp_stack_node, char const *yaml_filename)
static void yaml_parse_coupling(struct yac_couple_config *couple_config, fy_node_t coupling_node, char const *yaml_filename, enum yac_time_unit_type time_unit)
static fy_node_t yac_yaml_create_coupling_node(fy_document_t document, struct yac_couple_config *couple_config)
static void yaml_parse_interp_method_parameters(interp_method_parameter_value *parameter_values, struct yac_interpolation_method const *interp_method, fy_node_t parameter_node, char const *yaml_filename)
int YAC_YAML_PARSER_JSON_FORCE
assume JSON format
Definition config_yaml.c:65
#define DEF_INT_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX)
int YAC_YAML_EMITTER_DEFAULT
emit to YAML format
Definition config_yaml.c:61
static void yaml_parse_interp_method_parameter(interp_method_parameter_value *parameter_values, struct interp_method_parameter const *parameters, size_t num_parameters, fy_node_pair_t parameter_pair, char const *interpolation_name, char const *yaml_filename)
static fy_node_t yac_yaml_create_interpolation_stack_node(fy_document_t document, struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
static enum yac_reduction_type yaml_parse_time_reduction_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static void yaml_parse_debug_global_config(struct yac_couple_config *couple_config, fy_node_t global_config_node, char const *yaml_filename)
#define DEF_INTERP_METHOD(NAME, FUNC_ADD, FUNC_GET,...)
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
Definition event.c:329
char * yac_yaml_emit_coupling(struct yac_couple_config *couple_config, int emit_flags)
static void yac_yaml_append_couple_field_nodes(fy_node_t coupling_node, struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
struct fy_node * fy_node_t
Definition config_yaml.c:50
static void yaml_parse_debug(struct yac_couple_config *couple_config, fy_node_t debug_node, char const *yaml_filename)
static void yac_yaml_map_append(fy_node_t map, char const *key, fy_node_t value)
static fy_node_t yac_yaml_create_sequence_scalar(fy_document_t document, char const *const *values, size_t num_values)
const interpolation_methods[]
static char const * yaml_parse_string_value(fy_node_t value_node, char const *name, char const *yaml_filename)
static void yaml_parse_debug_map_pair(struct yac_couple_config *couple_config, fy_node_pair_t debug_pair, const char *yaml_filename)
static void yac_yaml_map_append_scalar_int(fy_node_t map, char const *key, int value)
#define ADD_INTERPOLATION_NO_PARAM(NAME, TYPE)
#define YAML_ASSERT(CHECK, MSG)
yaml_base_key_types
Definition config_yaml.c:98
@ DEBUG
@ TIMESTEP_UNIT
@ START_DATE
Definition config_yaml.c:99
@ COUPLING
@ CALENDAR
@ END_DATE
enum yac_interp_ncc_weight_type weight_type
#define DEF_NAME_TYPE_PAIRS(NAME,...)
static fy_node_t yac_yaml_create_scalar(fy_document_t document, char const *value)
static fy_node_t yac_yaml_create_scalar_int(fy_document_t document, int value)
static void yaml_parse_base_map_pair(struct yac_couple_config *couple_config, fy_node_pair_t base_pair, const char *yaml_filename, enum yac_time_unit_type *time_unit)
#define DEF_BOOL_PARAM(NAME, DEFAULT)
static void yaml_parse_couple_map_pair(struct field_couple_buffer *field_buffer, fy_node_pair_t couple_pair, const char *yaml_filename, enum yac_time_unit_type time_unit)
@ EMITTER_DEFAULT
Definition config_yaml.c:54
@ PARSER_JSON_AUTO
Definition config_yaml.c:57
@ EMITTER_JSON
Definition config_yaml.c:55
@ PARSER_JSON_FORCE
Definition config_yaml.c:58
@ PARSER_DEFAULT
Definition config_yaml.c:56
@ NUM_INTERPOLATION_METHODS
void yac_couple_config_get_field_grid_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const **src_grid_name, char const **tgt_grid_name)
void yac_couple_config_set_datetime(struct yac_couple_config *couple_config, char const *start, char const *end)
void yac_couple_config_disable_output(struct yac_couple_config *couple_config)
int yac_couple_config_mapping_on_source(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
char const * yac_couple_config_get_coupling_period(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
struct yac_interp_stack_config * yac_couple_config_get_interp_stack(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
size_t yac_couple_config_get_num_couple_fields(struct yac_couple_config *couple_config, size_t couple_idx)
void yac_couple_config_get_src_mask_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const *const **mask_names, size_t *num_mask_names)
void yac_couple_config_enable_output(struct yac_couple_config *couple_config, char const *filename, enum yac_config_filetype filetype)
size_t yac_couple_config_get_num_couples(struct yac_couple_config *couple_config)
int yac_couple_config_get_target_lag(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
int yac_couple_config_get_source_lag(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
double yac_couple_config_get_scale_factor(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
char const * yac_couple_config_get_end_datetime(struct yac_couple_config *couple_config)
char const * yac_couple_config_get_tgt_mask_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
double yac_couple_config_get_scale_summand(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
enum yac_reduction_type yac_couple_config_get_coupling_period_operation(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
int yac_couple_config_enforce_write_weight_file(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_def_couple(struct yac_couple_config *couple_config, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_period, int time_reduction, struct yac_interp_stack_config *interp_stack, int src_lag, int tgt_lag, const char *weight_file_name, int mapping_on_source, double scale_factor, double scale_summand, size_t num_src_mask_names, char const *const *src_mask_names, char const *tgt_mask_name)
void yac_couple_config_get_field_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const **src_field_name, const char **tgt_field_name)
char const * yac_couple_config_get_weight_file_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_get_field_couple_component_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const **src_component_name, char const **tgt_component_name)
char const * yac_couple_config_get_start_datetime(struct yac_couple_config *couple_config)
yac_reduction_type
@ TIME_NONE
@ TIME_ACCUMULATE
@ TIME_MAXIMUM
@ TIME_MINIMUM
@ TIME_AVERAGE
yac_time_unit_type
@ C_SECOND
@ TIME_UNIT_UNDEFINED
@ C_HOUR
@ C_DAY
@ C_MILLISECOND
@ C_MINUTE
@ C_MONTH
@ C_ISO_FORMAT
@ C_YEAR
yac_config_filetype
@ YAC_CONFIG_FILETYPE_YAML
YAML format.
@ YAC_CONFIG_FILETYPE_INVALID
invalid format
@ YAC_CONFIG_FILETYPE_JSON
JSON format.
#define YAC_RAD
Definition geometry.h:30
int(* func_compute_weights)(double[3], size_t, yac_const_coordinate_pointer, int *, double *, enum yac_cell_type cell_type)
#define YAC_INTERP_AVG_PARTIAL_COVERAGE_DEFAULT
yac_interp_avg_weight_type
@ YAC_INTERP_AVG_DIST
@ YAC_INTERP_AVG_ARITHMETIC
@ YAC_INTERP_AVG_BARY
#define YAC_INTERP_AVG_WEIGHT_TYPE_DEFAULT
yac_func_compute_weights callback
char * key
#define YAC_INTERP_CALLBACK_COMPUTE_WEIGHTS_KEY_DEFAULT
struct @8::@9 value
enum callback_type type
#define YAC_INTERP_CHECK_CONSTRUCTOR_KEY_DEFAULT
#define YAC_INTERP_CHECK_DO_SEARCH_KEY_DEFAULT
#define YAC_INTERP_CONSERV_NORMALISATION_DEFAULT
#define YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT
#define YAC_INTERP_CONSERV_PARTIAL_COVERAGE_DEFAULT
#define YAC_INTERP_CONSERV_ORDER_DEFAULT
yac_interp_method_conserv_normalisation
@ YAC_INTERP_CONSERV_DESTAREA
@ YAC_INTERP_CONSERV_FRACAREA
#define YAC_INTERP_CREEP_DISTANCE_DEFAULT
#define YAC_INTERP_FILE_WEIGHT_FILE_NAME_DEFAULT
#define YAC_INTERP_FIXED_VALUE_DEFAULT
#define YAC_INTERP_NCC_PARTIAL_COVERAGE_DEFAULT
#define YAC_INTERP_NCC_WEIGHT_TYPE_DEFAULT
yac_interp_ncc_weight_type
@ YAC_INTERP_NCC_DIST
distance weighted average of n source points
@ YAC_INTERP_NCC_AVG
average of n source points
#define YAC_INTERP_NNN_WEIGHTED_DEFAULT
yac_interp_nnn_weight_type
@ YAC_INTERP_NNN_GAUSS
distance with Gauss weights of n source points
@ YAC_INTERP_NNN_RBF
radial basis functions
@ YAC_INTERP_NNN_AVG
average of n source points
@ YAC_INTERP_NNN_DIST
distance weighted average of n source points
@ YAC_INTERP_NNN_ZERO
all weights are set to zero
#define YAC_INTERP_RBF_N_DEFAULT
#define YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT
#define YAC_INTERP_RBF_SCALE_DEFAULT
#define YAC_INTERP_NNN_N_DEFAULT
#define YAC_INTERP_RBF_KERNEL_DEFAULT
#define YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_SPMAP_SCALE_DEFAULT
yac_interp_spmap_scale_type
@ YAC_INTERP_SPMAP_NONE
weights are not scaled
@ YAC_INTERP_SPMAP_INVTGTAREA
@ YAC_INTERP_SPMAP_SRCAREA
@ YAC_INTERP_SPMAP_FRACAREA
#define YAC_INTERP_SPMAP_TGT_SPHERE_RADIUS_DEFAULT
#define YAC_INTERP_SPMAP_WEIGHTED_DEFAULT
#define YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT
yac_interp_spmap_weight_type
@ YAC_INTERP_SPMAP_AVG
@ YAC_INTERP_SPMAP_DIST
#define YAC_INTERP_SPMAP_SRC_SPHERE_RADIUS_DEFAULT
size_t yac_interp_stack_config_get_size(struct yac_interp_stack_config *interp_stack)
union yac_interp_stack_config_entry const * yac_interp_stack_config_get_entry(struct yac_interp_stack_config *interp_stack, size_t interp_stack_idx)
enum yac_interpolation_list yac_interp_stack_config_entry_get_type(union yac_interp_stack_config_entry const *interp_stack_entry)
void yac_interp_stack_config_delete(struct yac_interp_stack_config *interp_stack_config)
struct yac_interp_stack_config * yac_interp_stack_config_new()
yac_interpolation_list
@ YAC_N_NEAREST_NEIGHBOR
@ YAC_CREEP
@ YAC_USER_FILE
@ YAC_USER_CALLBACK
@ YAC_SOURCE_TO_TARGET_MAP
@ YAC_CONSERVATIVE
@ YAC_FIXED_VALUE
@ YAC_CHECK
@ YAC_BERNSTEIN_BEZIER
@ YAC_NEAREST_CORNER_CELLS
@ YAC_RADIAL_BASIS_FUNCTION
@ YAC_AVERAGE
#define YAC_MAX_ROUTINE_NAME_LENGTH
#define YAC_MAX_FILE_NAME_LENGTH
int yac_file_exists(const char *filename)
Definition utils_core.c:12
Definition __init__.py:1
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xmalloc(size)
Definition ppm_xfuncs.h:66
#define xfclose(fp)
Definition ppm_xfuncs.h:79
#define xfopen(path, mode)
Definition ppm_xfuncs.h:74
enum yac_config_filetype filetype
Definition config_yaml.c:95
char const ** src_mask_names
Definition config_yaml.c:88
char const * coupling_period
Definition config_yaml.c:76
struct field_couple_buffer::@52 tgt
char const * weight_file_name
Definition config_yaml.c:79
char const * tgt_mask_name
Definition config_yaml.c:90
char const * comp_name
Definition config_yaml.c:72
struct yac_interp_stack_config * interp_stack
Definition config_yaml.c:78
char const * grid_name
Definition config_yaml.c:73
struct field_couple_buffer::@52 src
struct field_couple_buffer::field_couple_field_names * field_names
enum yac_reduction_type time_reduction
Definition config_yaml.c:77
struct interp_method_parameter::@53::@56 dble_param
struct yac_name_type_pair const * valid_values
struct interp_method_parameter::@53::@57 str_param
enum interp_method_parameter_value_type type
union interp_method_parameter::@53 data
struct interp_method_parameter::@53::@55 int_param
struct interp_method_parameter::@53::@54 enum_param
struct interp_method_parameter::@53::@58 bool_param
interp_method_parameter_value const default_value
int yac_name_type_pair_get_type(struct yac_name_type_pair const *pairs, size_t count, char const *name)
Definition utils_core.c:26
char const * yac_name_type_pair_get_name(struct yac_name_type_pair const *pairs, size_t count, int type)
Definition utils_core.c:17
#define MAX(a, b)
void yac_cdef_calendar(int calendar)
Definition yac.c:616
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:19
#define YAC_ASSERT(exp, msg)
Definition yac_assert.h:16