YAC 3.13.2
Yet Another Coupler
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#include <errno.h>
30
31#include "yac.h"
32#include "utils_mci.h"
33#include "config_yaml.h"
34#include "mtime_calendar.h"
35#include "geometry.h"
36#include "io_utils.h"
49#include "instance.h"
50#include "fields.h"
53
54typedef struct fy_document * fy_document_t;
55typedef struct fy_node * fy_node_t;
56typedef struct fy_node_pair * fy_node_pair_t;
57
58enum {
59 EMITTER_DEFAULT = FYECF_DEFAULT,
60 EMITTER_JSON = FYECF_MODE_JSON,
62 PARSER_JSON_AUTO = FYPCF_JSON_AUTO,
63 PARSER_JSON_FORCE = FYPCF_JSON_FORCE,
64};
65
71
72char const * yac_time_to_ISO(
73 char const * time, enum yac_time_unit_type time_unit);
74
109
118
145
152
159
164
169
178
183
184#define CAST_NAME_TYPE_PAIRS(...) (struct yac_name_type_pair[]) {__VA_ARGS__}
185#define COUNT_NAME_TYPE_PAIRS(...) \
186 sizeof(CAST_NAME_TYPE_PAIRS(__VA_ARGS__)) / sizeof(struct yac_name_type_pair)
187#define DEF_NAME_TYPE_PAIR(NAME, TYPE) {.name = #NAME, .type = (int)(TYPE)}
188#define DEF_NAME_TYPE_PAIRS(NAME, ...) \
189 static const struct yac_name_type_pair NAME [] = {__VA_ARGS__}; \
190 static const size_t num_ ## NAME = COUNT_NAME_TYPE_PAIRS(__VA_ARGS__);
191
193 yaml_base_keys,
194 DEF_NAME_TYPE_PAIR(start_date, START_DATE),
195 DEF_NAME_TYPE_PAIR(start_datetime, START_DATE),
196 DEF_NAME_TYPE_PAIR(end_date, END_DATE),
197 DEF_NAME_TYPE_PAIR(end_datetime, END_DATE),
198 DEF_NAME_TYPE_PAIR(calendar, CALENDAR),
199 DEF_NAME_TYPE_PAIR(timestep_unit, TIMESTEP_UNIT),
200 DEF_NAME_TYPE_PAIR(coupling, COUPLING),
202
204 yaml_couple_keys,
206 DEF_NAME_TYPE_PAIR(src_component, SOURCE_COMPONENT),
209 DEF_NAME_TYPE_PAIR(tgt_component, TARGET_COMPONENT),
212 DEF_NAME_TYPE_PAIR(coupling_period, COUPLING_PERIOD),
213 DEF_NAME_TYPE_PAIR(time_reduction, TIME_REDUCTION),
218 DEF_NAME_TYPE_PAIR(weight_file_on_existing, WEIGHT_FILE_ON_EXISTING),
219 DEF_NAME_TYPE_PAIR(mapping_side, MAPPING_SIDE),
220 DEF_NAME_TYPE_PAIR(scale_factor, SCALE_FACTOR),
221 DEF_NAME_TYPE_PAIR(scale_summand, SCALE_SUMMAND),
222 DEF_NAME_TYPE_PAIR(interpolation, INTERPOLATION),
223 DEF_NAME_TYPE_PAIR(src_mask_name, SOURCE_MASK_NAME),
224 DEF_NAME_TYPE_PAIR(src_mask_names, SOURCE_MASK_NAMES),
225 DEF_NAME_TYPE_PAIR(tgt_mask_name, TARGET_MASK_NAME),
227 DEF_NAME_TYPE_PAIR(yaxt_exchanger_name, YAXT_EXCHANGER_NAME),
228 DEF_NAME_TYPE_PAIR(collection_selection, COLLECTION_SELECTION),
229 DEF_NAME_TYPE_PAIR(use_raw_exchange, USE_RAW_EXCHANGE))
230
232 yaml_debug_sync_loc_keys,
241
243 yaml_debug_output_grid_keys,
246
248 bool_names,
249 DEF_NAME_TYPE_PAIR(true, true),
250 DEF_NAME_TYPE_PAIR(TRUE, true),
251 DEF_NAME_TYPE_PAIR(yes, true),
252 DEF_NAME_TYPE_PAIR(YES, true),
253 DEF_NAME_TYPE_PAIR(false, false),
254 DEF_NAME_TYPE_PAIR(FALSE, false),
255 DEF_NAME_TYPE_PAIR(no, false),
256 DEF_NAME_TYPE_PAIR(NO, false))
257
259 timestep_units,
260 DEF_NAME_TYPE_PAIR(millisecond, C_MILLISECOND),
267 DEF_NAME_TYPE_PAIR(ISO_format, C_ISO_FORMAT))
268
270 time_operations,
276
278 calendar_types,
279 DEF_NAME_TYPE_PAIR(proleptic-gregorian, PROLEPTIC_GREGORIAN),
280 DEF_NAME_TYPE_PAIR(360d, YEAR_OF_360_DAYS),
281 DEF_NAME_TYPE_PAIR(365d, YEAR_OF_365_DAYS))
282
284 mapping_sides,
285 DEF_NAME_TYPE_PAIR(source, 1),
286 DEF_NAME_TYPE_PAIR(target, 0))
287
289 yaml_debug_keys,
290 DEF_NAME_TYPE_PAIR(global_config, GLOBAL_CONFIG),
291 DEF_NAME_TYPE_PAIR(output_grids, OUTPUT_GRIDS),
292 DEF_NAME_TYPE_PAIR(missing_definition_is_fatal, MISSING_DEF))
293
295 config_filetypes,
300
302 role_types,
303 DEF_NAME_TYPE_PAIR(target, TARGET),
304 DEF_NAME_TYPE_PAIR(source, SOURCE),
305 DEF_NAME_TYPE_PAIR(nothing, NOTHING))
306
308 yaml_comp_grid_names_keys,
309 DEF_NAME_TYPE_PAIR(component, COMP_NAME),
311
313 yaml_weight_file_data_keys,
316
318 weight_file_on_existing_types,
322
323enum interp_method_parameter_value_type{
324 ENUM_PARAM,
325 INT_PARAM,
326 DBLE_PARAM,
327 BOOL_PARAM,
328 STR_PARAM,
329 DEG_PARAM,
330 MAP_PARAM,
331 SEQ_PARAM,
332};
333
336
337#if defined __NVCOMPILER && (__NVCOMPILER_MAJOR__ <= 23 || __NVCOMPILER_MAJOR__ == 24 && __NVCOMPILER_MINOR__ <= 3)
338// Older versions of NVHPC have serious problems with unions that contain
339// pointers that are not the first members: versions 23.7 and older fail with
340// 'Internal compiler error. unhandled type', the newer versions produce code
341// that fails at the runtime with
342// 'Segmentation fault: address not mapped to object'.
343 struct
344#else
345 union
346#endif
347 {
352 char const * str_value;
354 struct {
356 size_t count;
361
363
364 char const * name;
365 enum interp_method_parameter_value_type type;
366
367#if defined __NVCOMPILER && (__NVCOMPILER_MAJOR__ <= 23 || __NVCOMPILER_MAJOR__ == 24 && __NVCOMPILER_MINOR__ <= 3)
368 // Older versions of NVHPC generate invalid LLVM IR for unions that contain
369 // structures with doubles: an attempt to initialize a member of type double
370 // that is not the first member of the respective structure will lead to a
371 // type mismatch.
372 struct
373#else
374 union
375#endif
376 {
377 struct { // enum
381 struct { // integer
382 int valid_min, valid_max;
384 struct { // double
388 struct { // string
391 struct { // bool
392 int dummy;
394 struct {
398 struct {
403};
404
407#define DEF_INTERP_METHOD_ADD_FUNC(NAME, FUNC) \
408 static void add_interp_method_ ## NAME ( \
409 struct yac_interp_stack_config * interp_stack, \
410 interp_method_parameter_value parameter_value, \
411 char const * yaml_filename) { \
412 char const * routine_name = "add_interp_method_" #NAME; \
413 (void)parameter_value; \
414 (void)yaml_filename; \
415 (void)routine_name; \
416 {FUNC} }
419#define DEF_INTERP_METHOD_GET_FUNC(NAME, FUNC) \
420 static void get_interp_method_ ## NAME ( \
421 union yac_interp_stack_config_entry const * interp_stack_entry, \
422 interp_method_parameter_value * parameter_value) { \
423 char const * routine_name = "get_interp_method_" #NAME; \
424 (void)interp_stack_entry; \
425 (void)parameter_value; \
426 (void)routine_name; \
427 {FUNC} }
428
429// macros for generating various types of interpolation parameters
430#define DEF_ENUM_PARAM(NAME, DEFAULT, ...) \
431 {.name = #NAME, \
432 .type = ENUM_PARAM, \
433 .data.enum_param = \
434 {.valid_values = CAST_NAME_TYPE_PAIRS(__VA_ARGS__), \
435 .num_valid_values = COUNT_NAME_TYPE_PAIRS(__VA_ARGS__)}, \
436 .default_value.data.enum_value = (int)(DEFAULT)}
437#define DEF_INT_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX) \
438 {.name = #NAME, \
439 .type = INT_PARAM, \
440 .data.int_param = \
441 {.valid_min = (int)(VALID_MIN), \
442 .valid_max = (int)(VALID_MAX)}, \
443 .default_value.data.int_value = (int)(DEFAULT)}
444#define DEF_DBLE_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX, ALLOW_NAN) \
445 {.name = #NAME, \
446 .type = DBLE_PARAM, \
447 .data.dble_param = \
448 {.valid_min = (double)(VALID_MIN), \
449 .valid_max = (double)(VALID_MAX), \
450 .allow_nan = (int)(ALLOW_NAN) \
451 }, \
452 .default_value.data.dble_value = (double)(DEFAULT)}
453#define DEF_DEG_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX) \
454 {.name = #NAME, \
455 .type = DEG_PARAM, \
456 .data.dble_param = \
457 {.valid_min = (double)(VALID_MIN), \
458 .valid_max = (double)(VALID_MAX), \
459 .allow_nan = (int)false}, \
460 .default_value.data.dble_value = (double)(DEFAULT)}
461#define DEF_BOOL_PARAM(NAME, DEFAULT) \
462 {.name = #NAME, \
463 .type = BOOL_PARAM, \
464 .default_value.data.bool_value = (int)(DEFAULT)}
465#define DEF_STR_PARAM(NAME, DEFAULT, MAX_STR_LEN) \
466 {.name = #NAME, \
467 .type = STR_PARAM, \
468 .data.str_param.max_str_len = (MAX_STR_LEN), \
469 .default_value.data.str_value = (DEFAULT)}
470#define DEF_MAP_PARAM(NAME, SUBPARAMS) \
471 {.name = #NAME, \
472 .type = MAP_PARAM, \
473 .data.map_param.sub_params = (SUBPARAMS ## _subparams), \
474 .data.map_param.num_sub_params = (SUBPARAMS ## _subparams_count), \
475 .default_value.data.map_values = NULL}
476#define DEF_MAP_SUBPARAMS(NAME, ...) \
477 static struct interp_method_parameter \
478 NAME ## _subparams [] = {__VA_ARGS__}; \
479 enum { \
480 NAME ## _subparams_count = \
481 sizeof(NAME ## _subparams) / sizeof(NAME ## _subparams[0])};
482#define DEF_SEQ_PARAM(NAME, SUBPARAM) \
483 {.name = #NAME, \
484 .type = SEQ_PARAM, \
485 .data.seq_param.sub_param = (SUBPARAM), \
486 .default_value.data.seq.values = NULL, \
487 .default_value.data.seq.count = 0}
488
489// definition of some assert macros
490#define YAML_ASSERT(CHECK, MSG) \
491 YAC_ASSERT_F((CHECK), \
492 "ERROR(%s): " MSG " in YAML configuration file \"%s\"", \
493 routine_name, yaml_filename)
494#define YAML_ASSERT_F(CHECK, MSG, ...) \
495 YAC_ASSERT_F((CHECK), \
496 "ERROR(%s): " MSG " in YAML configuration file \"%s\"", \
497 routine_name, __VA_ARGS__, yaml_filename)
498#define YAML_UNREACHABLE_DEFAULT(MSG) \
499 YAC_UNREACHABLE_DEFAULT_F( \
500 "ERROR(%s): " MSG " in YAML configuration file \"%s\"", \
501 routine_name, yaml_filename)
502#define YAML_UNREACHABLE_DEFAULT_F(MSG, ...) \
503 YAC_UNREACHABLE_DEFAULT_F( \
504 "ERROR(%s): " MSG " in YAML configuration file \"%s\"", \
505 routine_name, __VA_ARGS__, yaml_filename)
506
507#define DEF_INTERP_STACK_ADD(NAME, ...) \
508 yac_interp_stack_config_add_ ## NAME ( \
509 interp_stack, __VA_ARGS__);
510
511#define DEF_INTERP_STACK_ADD_NO_PARAM(NAME) \
512 yac_interp_stack_config_add_ ## NAME ( \
513 interp_stack);
514
515#define DEF_INTERP_STACK_GET(NAME, ...) \
516 yac_interp_stack_config_entry_get_ ## NAME ( \
517 interp_stack_entry, __VA_ARGS__);
518
519#define DEF_INTERP_STACK_GET_NO_PARAM(NAME) \
520 {}
521
522#define DEF_INTERP_METHOD(YAML_NAME, FUNC_ADD, FUNC_GET, ...) \
523 DEF_INTERP_METHOD_ADD_FUNC(YAML_NAME, FUNC_ADD) \
524 DEF_INTERP_METHOD_GET_FUNC(YAML_NAME, FUNC_GET) \
525 DEF_MAP_SUBPARAMS(YAML_NAME, __VA_ARGS__)
526
527#define DEF_INTERP_METHOD_NO_PARAM(YAML_NAME, UI_NAME) \
528 DEF_INTERP_METHOD_ADD_FUNC( \
529 YAML_NAME, DEF_INTERP_STACK_ADD_NO_PARAM(UI_NAME)) \
530 DEF_INTERP_METHOD_GET_FUNC( \
531 YAML_NAME, DEF_INTERP_STACK_GET_NO_PARAM(UI_NAME))
532
533// interpolation method average
535 DEF_INTERP_STACK_ADD(average,
537 parameter_value.data.map_values[0].data.enum_value,
538 parameter_value.data.map_values[1].data.bool_value),
539 enum yac_interp_avg_weight_type reduction_type;
540 DEF_INTERP_STACK_GET(average,
541 &reduction_type,
542 &parameter_value->data.map_values[1].data.bool_value)
543 parameter_value->data.map_values[0].data.enum_value =
544 (int)reduction_type;,
545 // paramters(map):
546 // weighted(enum)
547 // partial_coverage(bool)
550 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_AVG_DIST),
552 DEF_NAME_TYPE_PAIR(barycentric_coordinate, YAC_INTERP_AVG_BARY)),
555
556// interpolation method nearest corner cells
560 parameter_value.data.map_values[0].data.enum_value,
561 parameter_value.data.map_values[1].data.bool_value),
565 &parameter_value->data.map_values[1].data.bool_value)
566 parameter_value->data.map_values[0].data.enum_value =
567 (int)weight_type;,
568 // parameters(map):
569 // weighted(enum)
570 // partial_coverage(bool)
573 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_NCC_AVG),
574 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_NCC_DIST)),
577
578// interpolation method n-nearest neighbor
582 parameter_value.data.map_values[0].data.enum_value,
583 (size_t)parameter_value.data.map_values[1].data.int_value,
584 parameter_value.data.map_values[2].data.dble_value,
585 parameter_value.data.map_values[3].data.dble_value),
587 size_t n;
589 &type, &n, &parameter_value->data.map_values[2].data.dble_value,
590 &parameter_value->data.map_values[3].data.dble_value)
591 parameter_value->data.map_values[0].data.enum_value = (int)type;
592 parameter_value->data.map_values[1].data.int_value = (int)n;
593 parameter_value->data.map_values[2].data.dble_value /= YAC_RAD;,
596 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_NNN_DIST),
598 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_NNN_AVG),
601 // paramters:
602 // weighted(enum)
603 // n(int)
604 // max_search_distance(deg)
605 // gauss_scale(dble)
608 0.0, 179.9999),
610 gauss_scale, YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT, -DBL_MAX, DBL_MAX, false))
611
612// interpolation method conservative
613DEF_INTERP_METHOD(conservative,
614 DEF_INTERP_STACK_ADD(conservative,
615 parameter_value.data.map_values[0].data.int_value,
616 parameter_value.data.map_values[1].data.bool_value,
617 parameter_value.data.map_values[2].data.bool_value,
619 parameter_value.data.map_values[3].data.enum_value),
621 DEF_INTERP_STACK_GET(conservative,
622 &parameter_value->data.map_values[0].data.int_value,
623 &parameter_value->data.map_values[1].data.bool_value,
624 &parameter_value->data.map_values[2].data.bool_value,
625 &normalisation)
626 parameter_value->data.map_values[3].data.enum_value =
627 (int)normalisation;,
628 // parameter:
629 // order(int)
630 // enforced_conservation(bool)
631 // partial_coverage(bool)
632 // normalisation(enum)
635 enforced_conservation, YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT),
642
643static struct yac_spmap_cell_area_config * parse_cell_area_config_parameters(
644 interp_method_parameter_value cell_area_config_param_values,
645 char const * routine_name, char const * yaml_filename, char const * type) {
646
648 cell_area_config_param_values.data.map_values[0];
650 cell_area_config_param_values.data.map_values[1];
651
652 static struct yac_spmap_cell_area_config * cell_area_config;
653
654 // if no cell area configuration is provided
655 if ((!yac_values.is_set) && (!file_values.is_set)) {
657 } else {
658
659 // ensure that not two cell area provider types are given
661 (yac_values.is_set ^ file_values.is_set),
662 "configurations for the computation and reading of %s cell areas "
663 "were provided (only one is allowed)", type);
664
665 if (yac_values.is_set) {
666 cell_area_config =
668 yac_values.data.map_values[0].data.dble_value);
669 } else {
670 cell_area_config =
672 file_values.data.map_values[0].data.str_value,
673 file_values.data.map_values[1].data.str_value,
674 file_values.data.map_values[2].data.int_value);
675 }
676 }
677
678 return cell_area_config;
679}
680
682 struct yac_spmap_cell_area_config const * cell_area_config,
683 double * sphere_radius, char const ** filename, char const ** varname,
684 int * min_global_id, char const * desc) {
685
687 yac_spmap_cell_area_config_get_type(cell_area_config);
688
689 switch(type) {
691 "ERROR(get_cell_area_config_parameters): "
692 "invalid cell area configuration type (%s)", desc);
699 break;
700 }
707 break;
708 }
709 }
710}
711
713 interp_method_parameter_value const * parameters,
714 double * lon, double * lat) {
715
717 parameters[0].is_set,
718 "ERROR(parse_point_coordinates): longitude coordinate is not defined");
720 parameters[1].is_set,
721 "ERROR(parse_point_coordinates): longitude coordinate is not defined");
722
723 *lon = parameters[0].data.dble_value;
724 *lat = parameters[1].data.dble_value;
725}
726
728 interp_method_parameter_value const parameter) {
729
731 parameter.data.map_values[0].is_set,
732 "ERROR(parse_point_selection_parameter_bnd_circle): "
733 "bounding circle center is not defined");
735 parameter.data.map_values[1].is_set,
736 "ERROR(parse_point_selection_parameter_bnd_circle): "
737 "bounding circle radius is not defined");
738
742 inc_angle = parameter.data.map_values[1].data.dble_value;
743
744 return
746}
747
749 bounding_circle_center,
750 DEF_DEG_PARAM(lon, DBL_MAX, -720.0, 720.0),
751 DEF_DEG_PARAM(lat, DBL_MAX, -90.0, 90.0))
754 DEF_MAP_PARAM(center, bounding_circle_center),
755 DEF_DEG_PARAM(radius, DBL_MAX, 0.0, 179.9999))
757 source_to_target_map_overwrite_condition,
759static struct yac_point_selection * parse_point_selection_parameter(
760 interp_method_parameter_value const parameter) {
761
762 size_t point_selection_type_idx = SIZE_MAX;
763 for (size_t i = 0;
764 i < source_to_target_map_overwrite_condition_subparams_count; ++i) {
765 if (parameter.data.map_values[i].is_set) {
767 point_selection_type_idx == SIZE_MAX,
768 "ERROR(parse_point_selection_parameter): "
769 "more than one point selection type was provided")
770 point_selection_type_idx = i;
771 }
772 }
773
775 point_selection_type_idx != SIZE_MAX,
776 "ERROR(parse_point_selection_parameter): point selection is defined")
777
778 struct yac_point_selection * src_point_selection;
779 switch (point_selection_type_idx) {
780
781 YAC_UNREACHABLE_DEFAULT("unsupported point selection type");
782
783 // bounding circle
784 case (0): {
785 src_point_selection =
787 parameter.data.map_values[0]);
788 break;
789 }
790 }
791
792 return src_point_selection;
793}
794
796 interp_method_parameter_value const * parameter_value,
797 struct yac_spmap_scale_config * scale_config) {
798
808 // extract data from parameter
809 struct yac_point_selection * src_point_selection =
810 parse_point_selection_parameter(
811 parameter_value->data.map_values[0]);
812 double spread_distance =
813 parameter_value->data.map_values[1].data.dble_value;
814 double max_search_distance =
815 parameter_value->data.map_values[2].data.dble_value;
816
819 parameter_value->data.map_values[3].data.enum_value;
820 struct yac_interp_spmap_config * spmap_config =
823
824 struct yac_spmap_overwrite_config * overwrite_config =
826
827 yac_interp_spmap_config_delete(spmap_config);
829
830 return overwrite_config;
831}
832
834 struct yac_point_selection const * point_selection,
835 interp_method_parameter_value * parameter_value) {
836
846 switch (yac_point_selection_get_type(point_selection)) {
847
849 "ERROR(get_point_selection_parameters): %s point selection type",
850 (yac_point_selection_get_type(point_selection) ==
851 YAC_POINT_SELECTION_TYPE_EMPTY)?"empty":"invalid");
852
854 double center_lon, center_lat, radius;
856 point_selection, &center_lon, &center_lat, &radius);
857 parameter_value[0]. // condition
858 data.map_values[0]. // bnd_circle
859 data.map_values[0]. // center
860 data.map_values[0].data.dble_value = // lon
861 center_lon / YAC_RAD;
862 parameter_value[0]. // condition
863 data.map_values[0]. // bnd_circle
864 data.map_values[0]. // center
865 data.map_values[1].data.dble_value = // lat
866 center_lat / YAC_RAD;
867 parameter_value[0]. // condition
868 data.map_values[0]. // bnd_circle
869 data.map_values[1].data.dble_value = // radius
870 radius / YAC_RAD;
871 break;
872 }
873 }
874}
875
878 struct interp_method_parameter parameter);
879
881 source_to_target_map_overwrite,
882 DEF_MAP_PARAM(condition, source_to_target_map_overwrite_condition),
884 spread_distance, YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT, 0.0, 89.9999),
886 max_search_distance,
890 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_SPMAP_DIST),
891 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_SPMAP_AVG)))
892static struct interp_method_parameter
893 source_to_target_map_overwrite_seq =
894 DEF_MAP_PARAM(overwrite, source_to_target_map_overwrite);
895static void get_overwrite_config_parameters(
896 struct yac_spmap_overwrite_config const * overwrite_config,
897 interp_method_parameter_value * parameter_value) {
898
906 struct yac_point_selection const * src_point_selection =
908 struct yac_interp_spmap_config const * spmap_config =
910
911 *parameter_value =
913 source_to_target_map_overwrite_seq);
914
916 src_point_selection, parameter_value->data.map_values + 0);
917 parameter_value->data.map_values[1].data.dble_value =
919 parameter_value->data.map_values[2].data.dble_value =
921 parameter_value->data.map_values[3].data.enum_value =
923}
924
925// interpolation method source to target mapping
927 source_to_target_map_cell_area_provider_yac,
929 sphere_radius, YAC_INTERP_SPMAP_SPHERE_RADIUS_DEFAULT, 1e-9, DBL_MAX, false))
931 source_to_target_map_cell_area_provider_file,
933 DEF_STR_PARAM(varname, NULL, 128),
935 min_global_id, YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT, -INT_MAX, INT_MAX))
937 source_to_target_map_cell_area_provider,
938 DEF_MAP_PARAM(yac, source_to_target_map_cell_area_provider_yac),
939 DEF_MAP_PARAM(file, source_to_target_map_cell_area_provider_file))
940
941DEF_INTERP_METHOD(source_to_target_map,
942
943 // extracting configuration from parametersm, which were read from file
944 double spread_distance =
945 parameter_value.data.map_values[0].data.dble_value;
946 double max_search_distance =
947 parameter_value.data.map_values[1].data.dble_value;
950 parameter_value.data.map_values[2].data.enum_value;
951 enum yac_interp_spmap_scale_type scale_type =
953 parameter_value.data.map_values[3].data.enum_value;
954 struct yac_spmap_cell_area_config * source_cell_area_config =
955 parse_cell_area_config_parameters(
956 parameter_value.data.map_values[4],
957 routine_name, yaml_filename, "source");
958 struct yac_spmap_cell_area_config * target_cell_area_config =
959 parse_cell_area_config_parameters(
960 parameter_value.data.map_values[5],
961 routine_name, yaml_filename, "target");
964 scale_type, source_cell_area_config, target_cell_area_config);
965 yac_spmap_cell_area_config_delete(source_cell_area_config);
966 yac_spmap_cell_area_config_delete(target_cell_area_config);
967 struct yac_interp_spmap_config * default_config =
970 struct yac_spmap_overwrite_config ** overwrite_configs =
971 (parameter_value.data.map_values[6].data.seq.count > 0)?
972 xcalloc(
973 (parameter_value.data.map_values[6].data.seq.count + 1),
974 sizeof(*overwrite_configs)):NULL;
975 for (size_t i = 0; i < parameter_value.data.map_values[6].data.seq.count;
976 ++i)
977 overwrite_configs[i] =
979 parameter_value.data.map_values[6].data.seq.values + i, scale_config);
981
982 // set configuration
983 DEF_INTERP_STACK_ADD(spmap_ext, default_config, overwrite_configs)
984 yac_spmap_overwrite_configs_delete(overwrite_configs);
985 yac_interp_spmap_config_delete(default_config);,
986
987 // generate parameters from configuration in order to be written to file
988 struct yac_interp_spmap_config const * default_config;
989 struct yac_spmap_overwrite_config const ** overwrite_configs;
990 DEF_INTERP_STACK_GET(spmap_ext, &default_config, &overwrite_configs)
991 struct yac_spmap_scale_config const * scale_config =
993 parameter_value->data.map_values[0].data.dble_value =
995 parameter_value->data.map_values[1].data.dble_value =
997 parameter_value->data.map_values[2].data.enum_value =
998 (int)yac_interp_spmap_config_get_weight_type(default_config);
999 parameter_value->data.map_values[3].data.enum_value =
1003 &parameter_value->data.map_values[4].data.map_values[0].data.map_values[0].data.dble_value,
1004 &parameter_value->data.map_values[4].data.map_values[1].data.map_values[0].data.str_value,
1005 &parameter_value->data.map_values[4].data.map_values[1].data.map_values[1].data.str_value,
1006 &parameter_value->data.map_values[4].data.map_values[1].data.map_values[2].data.int_value,
1007 "source");
1010 &parameter_value->data.map_values[5].data.map_values[0].data.map_values[0].data.dble_value,
1011 &parameter_value->data.map_values[5].data.map_values[1].data.map_values[0].data.str_value,
1012 &parameter_value->data.map_values[5].data.map_values[1].data.map_values[1].data.str_value,
1013 &parameter_value->data.map_values[5].data.map_values[1].data.map_values[2].data.int_value,
1014 "target");
1015 size_t overwrite_config_count = 0;
1016 for (;
1017 (overwrite_configs != NULL) &&
1018 (overwrite_configs[overwrite_config_count] != NULL);
1019 ++overwrite_config_count);
1020 parameter_value->data.map_values[6].data.seq.values =
1021 xmalloc(
1022 overwrite_config_count *
1023 sizeof(
1024 *(parameter_value->data.map_values[6].data.seq.values)));
1025 parameter_value->data.map_values[6].data.seq.count =
1026 overwrite_config_count;
1027 for (size_t i = 0; i < overwrite_config_count; ++i)
1028 get_overwrite_config_parameters(
1029 overwrite_configs[i],
1030 parameter_value->data.map_values[6].data.seq.values + i);,
1031
1032 // define parameters:
1033 // parameter_values[0] spread_distance
1034 // parameter_values[1] max_search_distance
1035 // parameter_values[2] weighted
1036 // parameter_values[3] scale
1037 // parameter_values[4] src_cell_area
1038 // parameter_values[4][0] .yac
1039 // parameter_values[4][0][0] .sphere_radius
1040 // parameter_values[4][1] .file
1041 // parameter_values[4][1][0] .filename
1042 // parameter_values[4][1][1] .varname
1043 // parameter_values[4][1][2] .min_global_id
1044 // parameter_values[5] tgt_cell_area
1045 // parameter_values[5][0] .yac
1046 // parameter_values[5][0][0] .sphere_radius
1047 // parameter_values[5][1] .file
1048 // parameter_values[5][1][0] .filename
1049 // parameter_values[5][1][1] .varname
1050 // parameter_values[5][1][2] .min_global_id
1058 DEF_NAME_TYPE_PAIR(distance_weighted, YAC_INTERP_SPMAP_DIST),
1059 DEF_NAME_TYPE_PAIR(arithmetic_average, YAC_INTERP_SPMAP_AVG)),
1067 src_cell_area, source_to_target_map_cell_area_provider),
1069 tgt_cell_area, source_to_target_map_cell_area_provider),
1071 overwrite, &source_to_target_map_overwrite_seq))
1072
1073// interpolation method fixed
1074DEF_INTERP_METHOD(fixed,
1076 (isnan(parameter_value.data.map_values[0].data.dble_value) ||
1077 parameter_value.data.map_values[0].data.dble_value != DBL_MAX),
1078 "parameter 'user_value' of interpolation method 'fixed' is unset");
1080 fixed, parameter_value.data.map_values[0].data.dble_value),
1082 fixed, &parameter_value->data.map_values[0].data.dble_value),
1083 // paramters:
1084 // fixed(dble)
1086 user_value, YAC_INTERP_FIXED_VALUE_DEFAULT, -DBL_MAX, DBL_MAX, true))
1087
1088// interpolation method user file
1089DEF_INTERP_METHOD(user_file,
1091 parameter_value.data.map_values[0].data.str_value,
1092 "parameter \"filename\" of interpolation method \"user file\" is unset");
1093 DEF_INTERP_STACK_ADD(user_file,
1094 (char*)(parameter_value.data.map_values[0].data.str_value),
1096 parameter_value.data.map_values[1].data.enum_value,
1098 parameter_value.data.map_values[2].data.enum_value),
1099 enum yac_interp_file_on_missing_file on_missing_file;
1100 enum yac_interp_file_on_success on_success;
1101 DEF_INTERP_STACK_GET(user_file,
1102 &parameter_value->data.map_values[0].data.str_value,
1103 &on_missing_file, &on_success)
1104 parameter_value->data.map_values[1].data.enum_value =
1105 (int)on_missing_file;
1106 parameter_value->data.map_values[2].data.enum_value =
1107 (int)on_success;,
1108 // paramter:
1109 // filename(str)
1110 // on_missing_file(enum)
1111 // on_success(enum)
1125
1126// interpolation method check
1127DEF_INTERP_METHOD(check,
1129 (char*)(parameter_value.data.map_values[0].data.str_value),
1130 (char*)(parameter_value.data.map_values[1].data.str_value)),
1132 &parameter_value->data.map_values[0].data.str_value,
1133 &parameter_value->data.map_values[1].data.str_value),
1134 // paramters:
1135 // constructor_key(str)
1136 // do_search_key(str)
1143
1144// interpolation method Bernstein Bezier
1145DEF_INTERP_METHOD_NO_PARAM(bernstein_bezier, hcsbb)
1146
1147// interpolation method radial basis function
1150 (size_t)parameter_value.data.map_values[0].data.int_value,
1151 parameter_value.data.map_values[1].data.dble_value,
1152 parameter_value.data.map_values[2].data.dble_value),
1153 size_t n;
1155 &n, &parameter_value->data.map_values[1].data.dble_value,
1156 &parameter_value->data.map_values[2].data.dble_value)
1157 parameter_value->data.map_values[0].data.int_value = (int)n;
1158 parameter_value->data.map_values[1].data.dble_value /= YAC_RAD;
1159 parameter_value->data.map_values[3].data.enum_value = (int)0;,
1160 // parameters:
1161 // n(int)
1162 // max_search_distance(dble)
1163 // rbf_scale(dble)
1164 // rbf_kernel(enum)
1168 0.0, 179.9999),
1170 rbf_scale, YAC_INTERP_RBF_SCALE_DEFAULT, -DBL_MAX, DBL_MAX, false),
1173 DEF_NAME_TYPE_PAIR(gauss_kernel, 0)))
1174
1175// interpolation method creep
1176DEF_INTERP_METHOD(creep,
1178 creep, parameter_value.data.map_values[0].data.int_value),
1180 creep, &parameter_value->data.map_values[0].data.int_value),
1181 // parameters:
1182 // creep_distance(int)
1184 creep_distance, YAC_INTERP_CREEP_DISTANCE_DEFAULT, -1, INT_MAX))
1185
1186// interpolation method user_callback
1187DEF_INTERP_METHOD(user_callback,
1189 parameter_value.data.map_values[0].data.str_value,
1190 "parameter \"func_compute_weights\" "
1191 "of interpolation method \"user callback\" is unset")
1193 user_callback,
1194 (char*)(parameter_value.data.map_values[0].data.str_value)),
1196 user_callback,
1197 &parameter_value->data.map_values[0].data.str_value),
1198 // parameters:
1199 // func_compute_weights(str)
1203
1204#define ADD_INTERPOLATION(NAME, TYPE) \
1205 {.name = #NAME , \
1206 .type = TYPE , \
1207 .add_interpolation = add_interp_method_ ## NAME , \
1208 .get_interpolation = get_interp_method_ ## NAME , \
1209 .parameter = DEF_MAP_PARAM(NAME, NAME)}
1210#define ADD_INTERPOLATION_NO_PARAM(NAME, TYPE) \
1211 {.name = #NAME , \
1212 .type = TYPE , \
1213 .add_interpolation = add_interp_method_ ## NAME , \
1214 .get_interpolation = get_interp_method_ ## NAME , \
1215 .parameter = \
1216 {.name = #NAME, \
1217 .type = MAP_PARAM, \
1218 .data.map_param.sub_params = NULL, \
1219 .data.map_param.num_sub_params = 0, \
1220 .default_value.data.map_values = NULL}}
1221
1222// data structure containing all available interpolation methods
1223struct yac_interpolation_method {
1224 char const * name;
1226 void(*add_interpolation)(
1227 struct yac_interp_stack_config * interp_stack,
1228 interp_method_parameter_value parameter_value,
1229 char const * yaml_filename);
1230 void(*get_interpolation)(
1231 union yac_interp_stack_config_entry const * interp_stack_entry,
1232 interp_method_parameter_value * parameter_value);
1233 struct interp_method_parameter parameter;
1235 {ADD_INTERPOLATION(average, YAC_AVERAGE),
1238 ADD_INTERPOLATION(conservative, YAC_CONSERVATIVE),
1239 ADD_INTERPOLATION(source_to_target_map, YAC_SOURCE_TO_TARGET_MAP),
1241 ADD_INTERPOLATION(user_file, YAC_USER_FILE),
1246 ADD_INTERPOLATION(user_callback, YAC_USER_CALLBACK)};
1247enum {
1250};
1251
1252static char const * yaml_parse_string_value(
1253 fy_node_t value_node, char const * name, char const * yaml_filename) {
1254 char const * routine_name = "yaml_parse_string_value";
1255
1257 value_node && fy_node_is_scalar(value_node),
1258 "unsupported node type for \"%s\" (the node is expected to be scalar)",
1259 name);
1260
1261 return fy_node_get_scalar0(value_node);
1262}
1263
1264static calendarType yaml_parse_calendar_value(
1265 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1266 char const * routine_name = "yaml_parse_calendar_value";
1267
1268 char const * calendar_name =
1269 yaml_parse_string_value(value_node, key_name, yaml_filename);
1270
1271 int calendar_type =
1273 calendar_types, num_calendar_types, calendar_name);
1274
1276 calendar_type != INT_MAX,
1277 "\"%s\" is not a valid calendar name", calendar_name);
1278
1279 return (calendarType)calendar_type;
1280}
1281
1282static char const * yaml_parse_timestep_value(
1283 fy_node_t value_node, char const * key_name, char const * yaml_filename,
1284 enum yac_time_unit_type time_unit) {
1285 char const * routine_name = "yaml_parse_timestep_value";
1286
1288 time_unit != TIME_UNIT_UNDEFINED, "time unit is not yet defined");
1290 value_node && fy_node_is_scalar(value_node),
1291 "unsupported node type for \"%s\" (the node is expected to be scalar)",
1292 key_name);
1293 char const * timestep =
1294 yaml_parse_string_value(value_node, key_name, yaml_filename);
1295 char const * timestep_iso =
1296 yac_time_to_ISO(timestep, time_unit);
1297
1299 timestep_iso, "valid to convert timestep \"%s\" to ISO 8601 format",
1300 timestep);
1301
1302 return strdup(timestep_iso);
1303}
1304
1306 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1307 char const * routine_name = "yaml_parse_timestep_unit_value";
1308
1309 char const * timestep_unit_str =
1310 yaml_parse_string_value(value_node, key_name, yaml_filename);
1311
1312 int timestep_unit =
1314 timestep_units, num_timestep_units, timestep_unit_str);
1315
1317 timestep_unit != INT_MAX,
1318 "\"%s\" is not a valid time step unit", timestep_unit_str);
1319
1320 return (enum yac_time_unit_type)timestep_unit;
1321}
1322
1324 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1325 char const * routine_name = "yaml_parse_time_reduction_value";
1326
1327 char const * time_reduction_str =
1328 yaml_parse_string_value(value_node, key_name, yaml_filename);
1329
1330 int time_reduction =
1332 time_operations, num_time_operations, time_reduction_str);
1333
1335 time_reduction != INT_MAX,
1336 "\"%s\" is not a valid time reduction type in", time_reduction_str);
1337
1338 return (enum yac_reduction_type)time_reduction;
1339}
1340
1342 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1343 char const * routine_name = "yaml_parse_integer_value";
1344
1345 char const * integer_str =
1346 yaml_parse_string_value(value_node, key_name, yaml_filename);
1347
1348 char * endptr;
1349 long int long_value = strtol(integer_str, &endptr, 10);
1350
1352 (endptr != integer_str) && (*endptr == '\0') &&
1353 (long_value >= INT_MIN) && (long_value <= INT_MAX),
1354 "\"%s\" is not a valid integer value", integer_str);
1355
1356 return (int)long_value;
1357}
1358
1360 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1361 char const * routine_name = "yaml_parse_size_t_value";
1362
1363 char const * size_t_str =
1364 yaml_parse_string_value(value_node, key_name, yaml_filename);
1365
1366 errno = 0;
1367 char *endptr = NULL;
1368 uintmax_t temp = strtoumax(size_t_str, &endptr, 10);
1369
1371 (errno == 0) && (endptr != size_t_str) && (*endptr == '\0') &&
1372 (temp <= SIZE_MAX),
1373 "\"%s\" is not a valid size_t value", size_t_str);
1374
1375 return (size_t)temp;
1376}
1377
1379 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1380 char const * routine_name = "yaml_parse_double_value";
1381
1382 char const * double_str =
1383 yaml_parse_string_value(value_node, key_name, yaml_filename);
1384
1385 char * endptr;
1386 double dble_value = strtod(double_str, &endptr);
1387
1389 (endptr != double_str) && (*endptr == '\0'),
1390 "\"%s\" is not a valid double value for \"%s\"", double_str, key_name);
1391
1392 return dble_value;
1393}
1394
1396 struct yac_name_type_pair const * valid_values, size_t num_valid_values,
1397 fy_node_t value_node, char const * key_name, char const * yaml_filename) {
1398 char const * routine_name = "yaml_parse_enum_value";
1399
1400 char const * value_str =
1401 yaml_parse_string_value(value_node, key_name, yaml_filename);
1402
1403 int value =
1405 valid_values, num_valid_values, value_str);
1406
1408 value != INT_MAX,
1409 "\"%s\" is not a valid enum value for \"%s\" ", value_str, key_name);
1410
1411 return value;
1412}
1413
1424 char const ** interpolation_type_str, fy_node_t * parameter_node,
1425 fy_node_t interp_method_node, char const * yaml_filename) {
1426 char const * routine_name = "yaml_parse_base_interp_method_node";
1427
1428 fy_node_t interpolation_name_node;
1429
1430 // determine type of interpolation node
1431 switch(fy_node_get_type(interp_method_node)) {
1433 "unsupported interpolation method node type "
1434 "(interpolation methods are expected to be defined as either scalar "
1435 "or maps)");
1436
1437 // interpolation node only contains the name and not parameters
1438 case (FYNT_SCALAR):
1439 interpolation_name_node = interp_method_node;
1440 *parameter_node = NULL;
1441 break;
1442
1443 // interpolation node contains name and parameters
1444 case (FYNT_MAPPING):
1445
1447 fy_node_mapping_item_count(interp_method_node) == 1,
1448 "base interpolation method node is only allowed to have one pair ");
1449
1450 fy_node_pair_t base_interp_method_pair =
1451 fy_node_mapping_get_by_index(interp_method_node, 0);
1452
1453 interpolation_name_node = fy_node_pair_key(base_interp_method_pair);
1454
1455 fy_node_t base_interp_method_value_node =
1456 fy_node_pair_value(base_interp_method_pair);
1457
1459 fy_node_is_mapping(base_interp_method_value_node),
1460 "unsupported base interpolation method value node type "
1461 "for interpolation method \"%s\" "
1462 "(interpolation method parameters are expected to be "
1463 "defined as maps)",
1465 interpolation_name_node, "interpolation method name", yaml_filename));
1466
1467 *parameter_node = base_interp_method_value_node;
1468 break;
1469 }
1470
1471 *interpolation_type_str =
1473 interpolation_name_node, "interpolation method name", yaml_filename);
1474}
1475
1482 struct interp_method_parameter parameter) {
1483
1484 interp_method_parameter_value parameter_value = {.is_set = 0};
1485
1486 switch(parameter.type) {
1487
1489 "ERROR(yaml_interp_method_parameter_get_default): "
1490 "unsupported parameter type");
1491
1492 // parameter is a sequence
1493 case (SEQ_PARAM): {
1494
1495 // by default all sequences are empty
1496 parameter_value.data.seq.values = NULL;
1497 parameter_value.data.seq.count = 0;
1498 break;
1499 }
1500
1501 // parameter is a map
1502 case (MAP_PARAM): {
1503
1504 parameter_value.data.map_values =
1505 xmalloc(
1506 parameter.data.map_param.num_sub_params *
1507 sizeof(*(parameter_value.data.map_values)));
1508 for (size_t i = 0; i < parameter.data.map_param.num_sub_params; ++i)
1509 parameter_value.data.map_values[i] =
1511 parameter.data.map_param.sub_params[i]);
1512 break;
1513 }
1514
1515 // parameter is a scalar
1516 case (ENUM_PARAM):
1517 case (INT_PARAM):
1518 case (DBLE_PARAM):
1519 case (BOOL_PARAM):
1520 case (STR_PARAM):
1521 case (DEG_PARAM):
1522 {
1523 parameter_value = parameter.default_value;
1524 break;
1525 }
1526 }
1527
1528 return parameter_value;
1529}
1530
1535 interp_method_parameter_value parameter_value,
1536 struct interp_method_parameter parameter) {
1537
1538 switch(parameter.type) {
1539
1541 "ERROR(yaml_interp_method_parameter_free): "
1542 "unsupported parameter type");
1543
1544 // parameter is a sequence
1545 case (SEQ_PARAM): {
1546
1547 for (size_t seq_idx = 0;
1548 seq_idx < parameter_value.data.seq.count; ++seq_idx) {
1550 parameter_value.data.seq.values[seq_idx],
1551 *parameter.data.seq_param.sub_param);
1552 }
1553 free(parameter_value.data.seq.values);
1554
1555 break;
1556 }
1557
1558 // parameter is a map
1559 case (MAP_PARAM): {
1560
1561 for (size_t param_idx = 0;
1562 param_idx < parameter.data.map_param.num_sub_params; ++param_idx)
1564 parameter_value.data.map_values[param_idx],
1565 parameter.data.map_param.sub_params[param_idx]);
1566 free(parameter_value.data.map_values);
1567 break;
1568 }
1569
1570 // parameter is a scalar
1571 case (ENUM_PARAM):
1572 case (INT_PARAM):
1573 case (DBLE_PARAM):
1574 case (BOOL_PARAM):
1575 case (STR_PARAM):
1576 case (DEG_PARAM):
1577 // nothing to be done
1578 break;
1579 }
1580}
1581
1583 struct interp_method_parameter parameter,
1584 interp_method_parameter_value * parameter_value,
1585 fy_node_t value_node, char const * interpolation_name,
1586 char const * yaml_filename);
1587
1599 struct interp_method_parameter map_parameter,
1600 interp_method_parameter_value * map_parameter_values,
1601 fy_node_t value_node, char const * interpolation_name,
1602 char const * yaml_filename) {
1603 char const * routine_name = "yaml_parse_interp_method_map_parameter";
1604
1605 // the parameter value node has to be a map
1607 !value_node || fy_node_is_mapping(value_node),
1608 "invalid node type for parameter \"%s\" of interpolation method "
1609 "\"%s\" (has to be a map)", map_parameter.name, interpolation_name);
1610
1611 struct interp_method_parameter const * sub_parameters =
1612 map_parameter.data.map_param.sub_params;
1613 size_t num_sub_parameters = map_parameter.data.map_param.num_sub_params;
1614
1615 // for all key value pairs of the map
1616 void * iter = NULL;
1617 fy_node_pair_t parameter_pair;
1618 while ((parameter_pair = fy_node_mapping_iterate(value_node, &iter))) {
1619
1620 // get the key of the pair and match it with the valid key of the map
1621 char const * sub_parameter_name =
1623 fy_node_pair_key(parameter_pair),
1624 "interpolation method parameter name", yaml_filename);
1625 size_t sub_param_idx = SIZE_MAX;
1626 for (size_t i = 0;
1627 (i < num_sub_parameters) && (sub_param_idx == SIZE_MAX); ++i)
1628 if (!strcmp(sub_parameter_name, sub_parameters[i].name))
1629 sub_param_idx = i;
1631 sub_param_idx != SIZE_MAX,
1632 "\"%s\" is not a valid parameter for interpolation method \"%s\"",
1633 sub_parameter_name, interpolation_name);
1634
1635 fy_node_t parameter_value_node = fy_node_pair_value(parameter_pair);
1636
1638 sub_parameters[sub_param_idx], &map_parameter_values[sub_param_idx],
1639 parameter_value_node, interpolation_name, yaml_filename);
1640 }
1641}
1642
1655 struct interp_method_parameter seq_parameter,
1656 interp_method_parameter_value ** seq_parameter_values,
1657 size_t * seq_parameter_count,
1658 fy_node_t value_node, char const * interpolation_name,
1659 char const * yaml_filename) {
1660 char const * routine_name = "yaml_parse_interp_method_seq_parameter";
1661
1662 // the parameter value node has to be a sequence
1664 fy_node_is_sequence(value_node),
1665 "invalid node type for parameter \"%s\" of interpolation method "
1666 "\"%s\" (has to be a sequence)", seq_parameter.name, interpolation_name);
1667
1668 // get the number of item in the sequence and allocate sub parameter
1669 // values accordingly
1670 *seq_parameter_count =
1671 (size_t)fy_node_sequence_item_count(value_node);
1672 *seq_parameter_values =
1673 xmalloc(*seq_parameter_count * sizeof(**seq_parameter_values));
1674
1675 // parse the sequence
1676 for (size_t seq_idx = 0; seq_idx < *seq_parameter_count; ++seq_idx) {
1677 (*seq_parameter_values)[seq_idx] =
1679 *seq_parameter.data.seq_param.sub_param);
1681 *seq_parameter.data.seq_param.sub_param,
1682 (*seq_parameter_values) + seq_idx,
1683 fy_node_sequence_get_by_index(
1684 value_node, (int)seq_idx),
1685 interpolation_name, yaml_filename);
1686 }
1687}
1688
1702 struct interp_method_parameter parameter,
1703 interp_method_parameter_value * parameter_value,
1704 fy_node_t value_node, char const * interpolation_name,
1705 char const * yaml_filename) {
1706 char const * routine_name = "yaml_parse_interp_method_parameter_value";
1707
1708 // ensures that the parameter is not yet set
1710 !parameter_value->is_set,
1711 "\"%s\" parameter of interpolation method \"%s\" has already been set",
1712 parameter.name, interpolation_name);
1713
1714 // check the type of parameter
1715 switch(parameter.type) {
1717 "unsupported type parameter \"%s\" of interpolation method \"%s\"",
1718 parameter.name, interpolation_name);
1719 case (ENUM_PARAM):
1720 parameter_value->data.enum_value =
1722 parameter.data.enum_param.valid_values,
1724 value_node, "interpolation method enum parameter value",
1726 break;
1727 case (INT_PARAM):
1728 parameter_value->data.int_value =
1730 value_node, "interpolation method integer parameter value",
1733 (parameter_value->data.int_value >= parameter.data.int_param.valid_min) &&
1734 (parameter_value->data.int_value <= parameter.data.int_param.valid_max),
1735 "\"%d\" is not a valid integer parameter value for parameter \"%s\" "
1736 "of interpolation method \"%s\" "
1737 "(valid range: %d <= value <= %d)",
1738 parameter_value->data.int_value, parameter.name, interpolation_name,
1739 parameter.data.int_param.valid_min,
1740 parameter.data.int_param.valid_max);
1741 break;
1742 case (DBLE_PARAM):
1743 parameter_value->data.dble_value =
1745 value_node, "interpolation method double parameter value",
1748 (parameter.data.dble_param.allow_nan &&
1749 isnan(parameter_value->data.dble_value)) ||
1750 (!isnan(parameter_value->data.dble_value) &&
1751 (parameter_value->data.dble_value >=
1752 parameter.data.dble_param.valid_min) &&
1753 (parameter_value->data.dble_value <=
1754 parameter.data.dble_param.valid_max)),
1755 "\"%lf\" is not a valid double parameter value for parameter \"%s\" "
1756 "of interpolation method \"%s\" "
1757 "(valid range: %e <= value <= %e; NaN allowed: %s)",
1758 parameter_value->data.dble_value, parameter.name, interpolation_name,
1759 parameter.data.dble_param.valid_min,
1760 parameter.data.dble_param.valid_max,
1761 parameter.data.dble_param.allow_nan?"true":"false");
1762 break;
1763 case (DEG_PARAM):
1764 parameter_value->data.dble_value =
1766 value_node, "interpolation method degree parameter value",
1769 (parameter_value->data.dble_value >=
1770 parameter.data.dble_param.valid_min) &&
1771 (parameter_value->data.dble_value <=
1772 parameter.data.dble_param.valid_max),
1773 "\"%lf\" is not a valid degree parameter value for parameter \"%s\" "
1774 "of interpolation method \"%s\" "
1775 "(valid range: %e <= value <= %e)",
1776 parameter_value->data.dble_value, parameter.name, interpolation_name,
1777 parameter.data.dble_param.valid_min,
1778 parameter.data.dble_param.valid_max);
1779 parameter_value->data.dble_value *= YAC_RAD;
1780 break;
1781 case (BOOL_PARAM):
1782 parameter_value->data.bool_value =
1784 bool_names, num_bool_names, value_node,
1785 "interpolation method bool parameter value", yaml_filename);
1786 break;
1787 case (STR_PARAM):
1788 parameter_value->data.str_value =
1790 value_node, "interpolation method string parameter value",
1793 strlen(parameter_value->data.str_value) <
1794 parameter.data.str_param.max_str_len,
1795 "\"%s\" is not a valid string parameter value for parameter \"%s\" "
1796 "of interpolation method \"%s\" "
1797 "(maximum string length: %d)",
1798 parameter_value->data.str_value, parameter.name, interpolation_name,
1799 (int)(parameter.data.str_param.max_str_len - 1));
1800 break;
1801 case (MAP_PARAM): {
1803 parameter, parameter_value->data.map_values,
1804 value_node, interpolation_name, yaml_filename);
1805 break;
1806 }
1807 case (SEQ_PARAM): {
1809 parameter, &parameter_value->data.seq.values,
1810 &parameter_value->data.seq.count,
1811 value_node, interpolation_name, yaml_filename);
1812 }
1813 };
1814
1815 parameter_value->is_set = 1;
1816}
1817
1819 struct yac_interp_stack_config * interp_stack,
1820 fy_node_t interp_method_node, char const * yaml_filename) {
1821 char const * routine_name = "yaml_parse_interp_method";
1822
1823 char const * interpolation_type_str;
1824 fy_node_t parameter_node;
1825
1826 // get name of interpolations
1828 &interpolation_type_str, &parameter_node,
1829 interp_method_node, yaml_filename);
1830
1831 // match interpolation name with list of valid interpolation methods
1832 struct yac_interpolation_method const * interp_method = NULL;
1833 for (int i = 0; (i < NUM_INTERPOLATION_METHODS) && (!interp_method); ++i)
1834 if (!strcmp(interpolation_type_str, interpolation_methods[i].name))
1836
1839 "\"%s\" is not a valid interpolation method",
1840 interpolation_type_str);
1841
1842 // allocate and initialise interpolation method parameter with default values
1845 // parse user-provided interpolation method configuration
1848 parameter_node, interp_method->name, yaml_filename);
1849 // add interpolation method to stack using user-provied interpolation
1850 // method configuration
1851 interp_method->add_interpolation(
1853 // free interpolation method parameters
1856}
1857
1859 struct yac_interp_stack_config * interp_stack,
1860 fy_node_t interp_stack_node, char const * yaml_filename) {
1861 char const * routine_name = "yaml_parse_interp_stack_value";
1862
1864 fy_node_is_sequence(interp_stack_node),
1865 "unsupported interpolation stack node type"
1866 "(interpolation stacks are expected to be defined as a sequence)");
1867
1868 // parse couplings
1869 void * iter = NULL;
1870 fy_node_t interp_stack_item;
1871 while ((interp_stack_item =
1872 fy_node_sequence_iterate(interp_stack_node, &iter)))
1874 interp_stack, interp_stack_item, yaml_filename);
1875}
1876
1877static struct field_couple_field_names yaml_parse_field_name(
1878 fy_node_t field_node, const char * yaml_filename) {
1879 char const * routine_name = "yaml_parse_field_name";
1880
1881 struct field_couple_field_names field_name;
1882
1883 switch(fy_node_get_type(field_node)) {
1884
1886 "unsupported field name node type "
1887 "(field name is either scalars or a map)");
1888
1889 // the node contains one name for both source and target field
1890 case (FYNT_SCALAR): {
1891
1892 field_name.src =
1893 ((field_name.tgt =
1894 yaml_parse_string_value(field_node, "field name", yaml_filename)));
1895
1896 break;
1897 }
1898
1899 // the node contains different names for the source and target field
1900 case (FYNT_MAPPING): {
1901
1902 field_name.src =
1903 fy_node_mapping_lookup_scalar0_by_simple_key(
1904 field_node, "src", (size_t)-1);
1905 field_name.tgt =
1906 fy_node_mapping_lookup_scalar0_by_simple_key(
1907 field_node, "tgt", (size_t)-1);
1908
1910 field_name.src && field_name.tgt &&
1911 (fy_node_mapping_item_count(field_node) == 2),
1912 "invalid field name mapping node "
1913 "(field name mapping node has to contain two maps "
1914 "with the keys \"src\" and \"tgt\")")
1915
1916 break;
1917 }
1918 }
1919
1920 return field_name;
1921}
1922
1924 size_t ** values, size_t * num_values,
1925 fy_node_t values_node, char const * sequence_name,
1926 const char * yaml_filename) {
1927
1928 char const * routine_name = "yaml_parse_size_t_sequence";
1929
1931 (*values == NULL) && (*num_values == 0),
1932 "values have already been set for sequence \"%s\"",
1933 sequence_name);
1934
1935 // handle sequence node
1936 if (fy_node_is_sequence(values_node)) {
1937
1938 *num_values = (size_t)fy_node_sequence_item_count(values_node);
1939 *values = xmalloc(*num_values * sizeof(**values));
1940
1941 for (size_t value_idx = 0; value_idx < *num_values; ++value_idx)
1942 (*values)[value_idx] =
1944 fy_node_sequence_get_by_index(values_node, value_idx),
1945 sequence_name, yaml_filename);
1946 } else {
1947 // single scalar node
1948 *num_values = 1;
1949 *values = xmalloc(sizeof(**values));
1950 **values=
1951 yaml_parse_size_t_value(values_node, sequence_name, yaml_filename);
1952 }
1953}
1954
1956 struct yac_collection_selection ** collection_selection,
1957 fy_node_t values_node, char const * sequence_name,
1958 const char * yaml_filename) {
1959
1960 char const * routine_name = "yaml_parse_collection_selection_sequence";
1961
1963 *collection_selection == NULL,
1964 "values have already been set for sequence \"%s\"",
1965 sequence_name);
1966
1967 size_t collection_size = 0;
1968 size_t * indices = NULL;
1969
1971 &indices, &collection_size, values_node, sequence_name, yaml_filename);
1972
1973 *collection_selection =
1975
1976 free(indices);
1977}
1978
1980 char const *** values, size_t * num_values,
1981 fy_node_t values_node, char const * sequence_name,
1982 const char * yaml_filename) {
1983 char const * routine_name = "yaml_parse_string_sequence";
1984
1986 (*values == NULL) && (*num_values == 0),
1987 "values have already been set for sequence \"%s\"",
1988 sequence_name);
1989
1990 // if the field node contains multiple fields
1991 if (fy_node_is_sequence(values_node)) {
1992
1993 *num_values = (size_t)fy_node_sequence_item_count(values_node);
1994 *values = xmalloc(*num_values * sizeof(**values));
1995 for (size_t value_idx = 0; value_idx < *num_values; ++value_idx)
1996 (*values)[value_idx] =
1998 fy_node_sequence_get_by_index(values_node, value_idx),
1999 sequence_name, yaml_filename);
2000 } else {
2001 *num_values = 1;
2002 *values = xmalloc(sizeof(**values));
2003 **values =
2005 values_node, sequence_name, yaml_filename);
2006 }
2007}
2008
2010 struct field_couple_field_names ** field_names,
2011 size_t * num_field_names, fy_node_t fields_node,
2012 const char * yaml_filename) {
2013
2014 // if the field node contains multiple fields
2015 if (fy_node_is_sequence(fields_node)) {
2016
2017 size_t start_idx = *num_field_names;
2018 *num_field_names += (size_t)fy_node_sequence_item_count(fields_node);
2019 *field_names =
2020 xrealloc(*field_names, *num_field_names * sizeof(**field_names));
2021 for (size_t i = start_idx; i < *num_field_names; ++i)
2022 (*field_names)[i] =
2024 fy_node_sequence_get_by_index(fields_node, i), yaml_filename);
2025 } else {
2026 ++*num_field_names;
2027 *field_names =
2028 xrealloc(*field_names, *num_field_names * sizeof(**field_names));
2029 (*field_names)[*num_field_names-1] =
2031 }
2032}
2033
2035 char const ** comp_name, char const *** grid_names, size_t * num_grid_names,
2036 fy_node_t values_node, char const * type_name, const char * yaml_filename) {
2037 char const * routine_name = "yaml_parse_comp_grids_names";
2038
2040 *comp_name == NULL, "%s component name already set", type_name);
2042 (*grid_names == NULL) && (*num_grid_names == 0),
2043 "%s grid names already set", type_name);
2044
2046 fy_node_is_mapping(values_node),
2047 "unsupported component/grid names node type (has to be a map)");
2048
2049 // parse component/grid names
2050 void * iter = NULL;
2051 fy_node_pair_t pair;
2052 while((pair = fy_node_mapping_iterate(values_node, &iter))) {
2053
2054 enum yaml_comp_grid_names_key_types comp_grid_names_key_type =
2057 yaml_comp_grid_names_keys, num_yaml_comp_grid_names_keys,
2058 fy_node_pair_key(pair),
2059 "component/grid names parameter name", yaml_filename);
2060 char const * comp_grid_names_key_name =
2062 yaml_comp_grid_names_keys, num_yaml_comp_grid_names_keys,
2063 comp_grid_names_key_type);
2064
2065 fy_node_t name_node = fy_node_pair_value(pair);
2066
2067 switch(comp_grid_names_key_type) {
2068 YAML_UNREACHABLE_DEFAULT("invalid component/grid name key type");
2069 case(COMP_NAME):
2070 *comp_name =
2072 name_node, comp_grid_names_key_name, yaml_filename);
2073 break;
2074 case(GRID_NAMES):
2076 grid_names, num_grid_names,
2077 name_node, comp_grid_names_key_name, yaml_filename);
2078 break;
2079 }
2080 }
2081}
2082
2084 char const ** weight_file_name,
2085 enum yac_weight_file_on_existing * on_existing,
2086 fy_node_t values_node, char const * type_name, const char * yaml_filename) {
2087 char const * routine_name = "yaml_parse_weight_file";
2088
2090 *weight_file_name == NULL, "%s weight file name already set", type_name);
2092 *on_existing == YAC_WEIGHT_FILE_UNDEFINED,
2093 "%s \"on existing\" already set ", type_name);
2094
2096 fy_node_is_mapping(values_node),
2097 "unsupported weight file data node type (has to be a map)");
2098
2099 // parse component/grid names
2100 void * iter = NULL;
2101 fy_node_pair_t pair;
2102 while((pair = fy_node_mapping_iterate(values_node, &iter))) {
2103
2104 enum yaml_weight_file_data_key_types weight_file_data_key_type =
2107 yaml_weight_file_data_keys, num_yaml_weight_file_data_keys,
2108 fy_node_pair_key(pair),
2109 "weight file data parameter name", yaml_filename);
2110 char const * weight_file_data_key_name =
2112 yaml_weight_file_data_keys, num_yaml_weight_file_data_keys,
2113 weight_file_data_key_type);
2114
2115 fy_node_t weight_file_data_node = fy_node_pair_value(pair);
2116
2117 switch(weight_file_data_key_type) {
2118 YAML_UNREACHABLE_DEFAULT("invalid weight file data key type");
2122 weight_file_data_node, weight_file_data_key_name, yaml_filename);
2123 break;
2125 *on_existing =
2128 weight_file_on_existing_types,
2129 num_weight_file_on_existing_types,
2130 weight_file_data_node, weight_file_data_key_name,
2132 break;
2133 }
2134 }
2135}
2136
2138 struct field_couple_buffer * field_buffer,
2139 fy_node_pair_t couple_pair, const char * yaml_filename,
2140 enum yac_time_unit_type time_unit) {
2141 char const * routine_name = "yaml_parse_couple_map_pair";
2142
2143 enum yaml_couple_key_types couple_key_type =
2146 yaml_couple_keys, num_yaml_couple_keys,
2147 fy_node_pair_key(couple_pair),
2148 "couple configuration parameter name", yaml_filename);
2149 char const * couple_key_name =
2151 yaml_couple_keys, num_yaml_couple_keys, couple_key_type);
2152
2153 fy_node_t value_node = fy_node_pair_value(couple_pair);
2154
2155 switch (couple_key_type) {
2156 YAML_UNREACHABLE_DEFAULT("invalid couple key type");
2157 case (SOURCE_NAMES):
2159 &(field_buffer->src.comp_name),
2160 &(field_buffer->src.grid.name),
2161 &(field_buffer->src.grid.count),
2162 value_node, couple_key_name, yaml_filename);
2163 break;
2164 case (SOURCE_COMPONENT):
2165 field_buffer->src.comp_name =
2166 yaml_parse_string_value(value_node, couple_key_name, yaml_filename);
2167 break;
2168 case (SOURCE_GRID):
2170 &field_buffer->src.grid.name, &field_buffer->src.grid.count,
2171 value_node, couple_key_name, yaml_filename);
2172 break;
2173 case (TARGET_NAMES):
2175 &(field_buffer->tgt.comp_name),
2176 &(field_buffer->tgt.grid.name),
2177 &(field_buffer->tgt.grid.count),
2178 value_node, couple_key_name, yaml_filename);
2179 break;
2180 case (TARGET_COMPONENT):
2181 field_buffer->tgt.comp_name =
2182 yaml_parse_string_value(value_node, couple_key_name, yaml_filename);
2183 break;
2184 case (TARGET_GRID):
2186 &field_buffer->tgt.grid.name, &field_buffer->tgt.grid.count,
2187 value_node, couple_key_name, yaml_filename);
2188 break;
2189 case (FIELD):
2191 &(field_buffer->field_names),
2192 &(field_buffer->num_field_names),
2193 value_node, yaml_filename);
2194 break;
2195 case (COUPLING_PERIOD):
2196 field_buffer->coupling_period =
2198 value_node, couple_key_name, yaml_filename, time_unit);
2199 break;
2200 case (TIME_REDUCTION):
2201 field_buffer->time_reduction =
2203 value_node, couple_key_name, yaml_filename);
2204 break;
2205 case (SOURCE_LAG):
2206 field_buffer->src.lag =
2208 value_node, couple_key_name, yaml_filename);
2209 break;
2210 case (TARGET_LAG):
2211 field_buffer->tgt.lag =
2213 value_node, couple_key_name, yaml_filename);
2214 break;
2215 case (WEIGHT_FILE_NAME):
2216 field_buffer->weight_file.name =
2218 value_node, couple_key_name, yaml_filename);
2219 break;
2221 field_buffer->weight_file.on_existing =
2224 weight_file_on_existing_types,
2225 num_weight_file_on_existing_types,
2226 value_node, couple_key_name, yaml_filename);
2227 break;
2228 case (WEIGHT_FILE_DATA):
2230 &(field_buffer->weight_file.name),
2231 &(field_buffer->weight_file.on_existing),
2232 value_node, couple_key_name, yaml_filename);
2233 break;
2234 case (MAPPING_SIDE):
2235 field_buffer->mapping_on_source =
2237 mapping_sides, num_mapping_sides,
2238 value_node, couple_key_name, yaml_filename);
2239 break;
2240 case (SCALE_FACTOR):
2241 field_buffer->scale_factor =
2243 value_node, couple_key_name, yaml_filename);
2244 break;
2245 case (SCALE_SUMMAND):
2246 field_buffer->scale_summand =
2248 value_node, couple_key_name, yaml_filename);
2249 break;
2250 case (INTERPOLATION):
2252 field_buffer->interp_stack, value_node, yaml_filename);
2253 break;
2254 case (SOURCE_MASK_NAME):
2255 case (SOURCE_MASK_NAMES):
2257 &(field_buffer->src_mask_names),
2258 &(field_buffer->num_src_mask_names),
2259 value_node, couple_key_name, yaml_filename);
2260 break;
2261 case (TARGET_MASK_NAME):
2262 field_buffer->tgt_mask_name =
2264 value_node, couple_key_name, yaml_filename);
2265 break;
2266 case (YAXT_EXCHANGER_NAME):
2267 field_buffer->yaxt_exchanger_name =
2269 value_node, couple_key_name, yaml_filename);
2270 break;
2271 case (COLLECTION_SELECTION):
2273 &field_buffer->collection_selection,
2274 value_node, couple_key_name, yaml_filename);
2275 break;
2276 case (USE_RAW_EXCHANGE):
2277 field_buffer->use_raw_exchange =
2279 bool_names, num_bool_names,
2280 value_node, couple_key_name, yaml_filename);
2281 break;
2282 }
2283}
2284
2286 struct yac_couple_config * couple_config, fy_node_t couple_node,
2287 char const * yaml_filename, enum yac_time_unit_type time_unit) {
2288 char const * routine_name = "yaml_parse_couple";
2289
2291 fy_node_is_mapping(couple_node),
2292 "unsupported couple node type "
2293 "(couples are expected to be defined as a mapping)");
2294
2295 // initialise field configuration buffer with default values
2296 struct field_couple_buffer field_buffer = {
2297 .src.comp_name = NULL,
2298 .src.grid.name = NULL,
2299 .src.grid.count = 0,
2300 .tgt.comp_name = NULL,
2301 .tgt.grid.name = NULL,
2302 .tgt.grid.count = 0,
2303 .field_names = NULL,
2304 .num_field_names = 0,
2305 .coupling_period = NULL,
2306 .time_reduction = TIME_NONE,
2307 .interp_stack = yac_interp_stack_config_new(),
2308 .src.lag = 0,
2309 .tgt.lag = 0,
2310 .weight_file.name = NULL,
2311 .weight_file.on_existing = YAC_WEIGHT_FILE_UNDEFINED,
2312 .mapping_on_source = 1,
2313 .scale_factor = 1.0,
2314 .scale_summand = 0.0,
2315 .src_mask_names = NULL,
2316 .num_src_mask_names = 0,
2317 .tgt_mask_name = NULL,
2318 .yaxt_exchanger_name = NULL,
2319 .collection_selection = NULL,
2320 .use_raw_exchange = 0};
2321
2322 // parse couple
2323 void * iter = NULL;
2324 fy_node_pair_t pair;
2325 while ((pair = fy_node_mapping_iterate(couple_node, &iter)))
2327 &field_buffer, pair, yaml_filename, time_unit);
2328
2330 field_buffer.src.comp_name, "missing source component name");
2332 field_buffer.src.grid.count > 0,
2333 "missing source grid name (component \"%s\")",
2334 field_buffer.src.comp_name);
2335 for (size_t i = 0; i < field_buffer.src.grid.count; ++i)
2337 (field_buffer.src.grid.name[i] != NULL) &&
2338 (field_buffer.src.grid.name[i][0] != '\0'),
2339 "invalid source grid name (component \"%s\" grid idx %zu)",
2340 field_buffer.src.comp_name, i);
2342 field_buffer.tgt.comp_name,
2343 "missing target component name");
2345 field_buffer.tgt.grid.count > 0,
2346 "missing target grid name (component \"%s\")",
2347 field_buffer.tgt.comp_name);
2348 for (size_t i = 0; i < field_buffer.tgt.grid.count; ++i)
2350 (field_buffer.tgt.grid.name[i] != NULL) &&
2351 (field_buffer.tgt.grid.name[i][0] != '\0'),
2352 "invalid target grid name (component \"%s\" grid idx %zu)",
2353 field_buffer.tgt.comp_name, i);
2355 field_buffer.num_field_names > 0,
2356 "missing field names "
2357 "(source component \"%s\" source grid \"%s\" "
2358 "target component \"%s\" target grid \"%s\")",
2359 field_buffer.src.comp_name, field_buffer.src.grid.name[0],
2360 field_buffer.tgt.comp_name, field_buffer.tgt.grid.name[0]);
2362 field_buffer.coupling_period,
2363 "missing coupling period "
2364 "(source component \"%s\" source grid \"%s\" "
2365 "target component \"%s\" target grid \"%s\")",
2366 field_buffer.src.comp_name, field_buffer.src.grid.name[0],
2367 field_buffer.tgt.comp_name, field_buffer.tgt.grid.name[0]);
2368
2369 for (size_t i = 0; i < field_buffer.num_field_names; ++i)
2370 for (size_t j = 0; j < field_buffer.src.grid.count; ++j)
2371 for (size_t k = 0; k < field_buffer.tgt.grid.count; ++k)
2373 couple_config,
2374 field_buffer.src.comp_name,
2375 field_buffer.src.grid.name[j],
2376 field_buffer.field_names[i].src,
2377 field_buffer.tgt.comp_name,
2378 field_buffer.tgt.grid.name[k],
2379 field_buffer.field_names[i].tgt,
2380 field_buffer.coupling_period,
2381 field_buffer.time_reduction,
2382 field_buffer.interp_stack,
2383 field_buffer.src.lag,
2384 field_buffer.tgt.lag,
2385 field_buffer.weight_file.name,
2388 field_buffer.weight_file.on_existing,
2389 field_buffer.mapping_on_source,
2390 field_buffer.scale_factor,
2391 field_buffer.scale_summand,
2392 field_buffer.num_src_mask_names,
2393 field_buffer.src_mask_names,
2394 field_buffer.tgt_mask_name,
2395 field_buffer.yaxt_exchanger_name,
2396 field_buffer.collection_selection,
2397 field_buffer.use_raw_exchange);
2398
2399 // cleanup
2401 free((void*)field_buffer.src.grid.name);
2402 free((void*)field_buffer.tgt.grid.name);
2403 free((void*)field_buffer.field_names);
2404 free((void*)field_buffer.coupling_period);
2406 free((void*)field_buffer.src_mask_names);
2407}
2408
2410 struct yac_couple_config * couple_config,
2411 fy_node_t coupling_node, char const * yaml_filename,
2412 enum yac_time_unit_type time_unit) {
2413 char const * routine_name = "yaml_parse_coupling";
2414
2415 // check if the coupling node is empty -> nothing to be read
2416 if (!coupling_node) return;
2417
2419 fy_node_is_sequence(coupling_node),
2420 "unsupported coupling node type "
2421 "(couplings are expected to be defined as a sequence)");
2422
2423 // parse couplings
2424 void * iter = NULL;
2425 fy_node_t couple_node;
2426 while ((couple_node = fy_node_sequence_iterate(coupling_node, &iter)))
2427 yaml_parse_couple(couple_config, couple_node, yaml_filename, time_unit);
2428}
2429
2430static struct debug_config_file yaml_parse_config_file_value(
2431 fy_node_t config_file_node, char const * file_type_name,
2432 const char * yaml_filename) {
2433 char const * routine_name = "yaml_parse_config_file_value";
2434
2435 struct debug_config_file config_file =
2436 {.name = NULL, .type = YAC_TEXT_FILETYPE_YAML, .include_definitions = 0};
2437
2438 char * str_buffer = xmalloc(strlen(file_type_name) + 32);
2439
2440 switch(fy_node_get_type(config_file_node)) {
2441
2443 "unsupported config file node type "
2444 "(%s is either scalar or a map)", file_type_name);
2445
2446 // the node contains only the filename
2447 case (FYNT_SCALAR): {
2448
2449 config_file.name =
2451 config_file_node,
2452 strcat(strcpy(str_buffer, file_type_name), " name"),
2454
2455 break;
2456 }
2457
2458 // the node contains the name and the type
2459 case (FYNT_MAPPING): {
2460
2461 fy_node_t filename_node =
2462 fy_node_mapping_lookup_by_string(
2463 config_file_node, "filename", (size_t)-1);
2464 fy_node_t filetype_node =
2465 fy_node_mapping_lookup_by_string(
2466 config_file_node, "filetype", (size_t)-1);
2467 fy_node_t include_definitions_node =
2468 fy_node_mapping_lookup_by_string(
2469 config_file_node, "include_definitions", (size_t)-1);
2470
2472 filename_node,
2473 "invalid %s mapping node "
2474 "(global config file mapping node has to include a map "
2475 "with the keys \"filename\")", file_type_name)
2476
2477 config_file.name =
2479 filename_node, strcat(strcpy(str_buffer, file_type_name), " name"),
2481 config_file.type =
2482 (filetype_node)?
2483 (enum yac_text_filetype)
2485 config_filetypes, num_config_filetypes,
2486 filetype_node, strcat(strcpy(str_buffer, file_type_name), " type"),
2488 config_file.include_definitions =
2489 (include_definitions_node)?
2491 bool_names, num_bool_names,
2492 include_definitions_node,
2493 strcat(strcpy(str_buffer, file_type_name), " include definitions"),
2494 yaml_filename):0;
2495 break;
2496 }
2497 }
2498
2500 config_file.name, "missing filename for %s", file_type_name);
2501
2502 free(str_buffer);
2503
2504 return config_file;
2505}
2506
2508 struct debug_config_file_buffer * config_file_buffer,
2509 fy_node_pair_t config_file_pair, char const * config_file_type_name,
2510 const char * yaml_filename) {
2511
2513 debug_sync_loc_key_type =
2516 yaml_debug_sync_loc_keys,
2517 num_yaml_debug_sync_loc_keys,
2518 fy_node_pair_key(config_file_pair),
2519 "config synchronisation location parameter name",
2521 char const * debug_sync_loc_key_name =
2523 yaml_debug_sync_loc_keys, num_yaml_debug_sync_loc_keys,
2524 debug_sync_loc_key_type);
2525
2526 fy_node_t value_node = fy_node_pair_value(config_file_pair);
2527
2528 char config_file_type_name_sync[
2529 strlen(config_file_type_name) + strlen(debug_sync_loc_key_name) + 8];
2530 sprintf(
2531 config_file_type_name_sync, "%s (%s)",
2532 config_file_type_name, debug_sync_loc_key_name);
2533
2534 config_file_buffer->config_file[debug_sync_loc_key_type] =
2536 value_node, config_file_type_name_sync, yaml_filename);
2537}
2538
2540 fy_node_t config_file_node, char const * config_file_type_name,
2541 char const * yaml_filename) {
2542 char const * routine_name = "yaml_parse_debug_config_file_buffer";
2543
2545 fy_node_is_mapping(config_file_node),
2546 "unsupported %s node type "
2547 "(%s is expected to be defined as a mapping)",
2548 config_file_type_name, config_file_type_name);
2549
2550 struct debug_config_file_buffer config_file_buffer;
2551 config_file_buffer.sync_loc_ref[SYNC_LOC_DEF_COMP] =
2553 config_file_buffer.sync_loc_ref[SYNC_LOC_SYNC_DEF] =
2555 config_file_buffer.sync_loc_ref[SYNC_LOC_ENDDEF] =
2557 for (int i = 0; i < SYNC_LOC_COUNT; ++i) {
2558 config_file_buffer.config_file[i].name = NULL;
2559 config_file_buffer.config_file[i].type = YAC_TEXT_FILETYPE_YAML;
2560 config_file_buffer.config_file[i].include_definitions = 0;
2562 config_file_buffer.sync_loc_ref[i] != NULL,
2563 "invalid unsupported synchronisation location (%d) for %s",
2564 i, config_file_type_name);
2565 }
2566
2567 // parse couplings
2568 void * iter = NULL;
2569 fy_node_pair_t pair;
2570 while ((pair = fy_node_mapping_iterate(config_file_node, &iter)))
2572 &config_file_buffer, pair, config_file_type_name, yaml_filename);
2573
2574 return config_file_buffer;
2575}
2576
2578 struct yac_couple_config * couple_config, fy_node_t global_config_node,
2579 char const * yaml_filename) {
2580 char const * routine_name = "yaml_parse_debug_global_config";
2581
2582 char const * config_file_type_name = "debug global config file";
2583
2585 fy_node_is_mapping(global_config_node),
2586 "unsupported %s node type "
2587 "(%s is expected to be defined as a mapping)",
2588 config_file_type_name, config_file_type_name);
2589
2590 struct debug_config_file_buffer global_config_buffer =
2592 global_config_node, config_file_type_name, yaml_filename);
2593
2594 for (int i = 0; i < SYNC_LOC_COUNT; ++i)
2595 if (global_config_buffer.config_file[i].name != NULL)
2597 couple_config, global_config_buffer.config_file[i].name,
2598 global_config_buffer.config_file[i].type,
2599 global_config_buffer.sync_loc_ref[i],
2600 global_config_buffer.config_file[i].include_definitions);
2601}
2602
2604 char const ** grid_name, char const ** file_name,
2605 fy_node_pair_t output_grid_pair, char const * yaml_filename) {
2606 char const * routine_name = "yaml_parse_output_grid_pair";
2607
2608 enum yaml_debug_output_grid_key_types output_grid_key_type =
2611 yaml_debug_output_grid_keys, num_yaml_debug_output_grid_keys,
2612 fy_node_pair_key(output_grid_pair),
2613 "output grid parameter name", yaml_filename);
2614 char const * debug_output_key_name =
2616 yaml_debug_output_grid_keys, num_yaml_debug_output_grid_keys,
2617 output_grid_key_type);
2618
2619 fy_node_t value_node = fy_node_pair_value(output_grid_pair);
2620
2621 switch(output_grid_key_type) {
2622 YAML_UNREACHABLE_DEFAULT("invalid output grid key type");
2623 case(OUTPUT_GRID_GRID_NAME): {
2624 *grid_name =
2625 yaml_parse_string_value(value_node, debug_output_key_name, yaml_filename);
2626 break;
2627 }
2628 case(OUTPUT_GRID_FILE_NAME): {
2629 *file_name =
2630 yaml_parse_string_value(value_node, debug_output_key_name, yaml_filename);
2631 break;
2632 }
2633 };
2634}
2635
2637 struct yac_couple_config * couple_config, fy_node_t output_grid_node,
2638 char const * yaml_filename) {
2639 char const * routine_name = "yaml_parse_output_grid";
2640
2642 fy_node_is_mapping(output_grid_node),
2643 "unsupported output grid node type "
2644 "(output grids are expected to be defined as a mapping)");
2645
2646 char const * grid_name = NULL;
2647 char const * file_name = NULL;
2648
2649 // parse output grid
2650 void * iter = NULL;
2651 fy_node_pair_t pair;
2652 while ((pair = fy_node_mapping_iterate(output_grid_node, &iter)))
2654
2655 YAML_ASSERT(grid_name, "missing grid name");
2656 YAML_ASSERT_F(file_name, "missing file name for grid \"%s\"", grid_name);
2657
2658 yac_couple_config_add_grid(couple_config, grid_name);
2660 couple_config, grid_name, file_name);
2661}
2662
2664 struct yac_couple_config * couple_config, fy_node_t output_grids_node,
2665 char const * yaml_filename) {
2666 char const * routine_name = "yaml_parse_debug_output_grids";
2667
2669 fy_node_is_sequence(output_grids_node),
2670 "unsupported debug output grids node type "
2671 "(debug output grids is expected to be defined as a sequence)");
2672
2673 // parse output grids
2674 void * iter = NULL;
2675 fy_node_t output_grid_node;
2676 while ((output_grid_node =
2677 fy_node_sequence_iterate(output_grids_node, &iter)))
2679 couple_config, output_grid_node, yaml_filename);
2680}
2681
2683 struct yac_couple_config * couple_config, fy_node_pair_t debug_pair,
2684 const char * yaml_filename) {
2685 char const * routine_name = "yaml_parse_debug_map_pair";
2686
2687 enum yaml_debug_key_types debug_key_type =
2690 yaml_debug_keys, num_yaml_debug_keys,
2691 fy_node_pair_key(debug_pair),
2692 "debug configuration parameter name", yaml_filename);
2693
2694 fy_node_t value_node = fy_node_pair_value(debug_pair);
2695
2696 switch (debug_key_type) {
2697 YAML_UNREACHABLE_DEFAULT("invalid debug_key_type");
2698 case(GLOBAL_CONFIG):
2700 couple_config, value_node, yaml_filename);
2701 break;
2702 case(OUTPUT_GRIDS):
2704 couple_config, value_node, yaml_filename);
2705 break;
2706 case(MISSING_DEF):
2708 couple_config,
2710 bool_names, num_bool_names, value_node,
2711 "\"missing definition is fatal\" bool value", yaml_filename));
2712 break;
2713 };
2714}
2715
2717 struct yac_couple_config * couple_config,
2718 fy_node_t debug_node, char const * yaml_filename) {
2719 char const * routine_name = "yaml_parse_debug";
2720
2721 // check if the debug node is empty -> nothing to be read
2722 if (!debug_node) return;
2723
2725 fy_node_is_mapping(debug_node),
2726 "unsupported debug node type "
2727 "(debug is expected to be defined as a mapping)");
2728
2729 // parse couplings
2730 void * iter = NULL;
2731 fy_node_pair_t pair;
2732 while ((pair = fy_node_mapping_iterate(debug_node, &iter)))
2733 yaml_parse_debug_map_pair(couple_config, pair, yaml_filename);
2734}
2735
2737 struct yac_couple_config * couple_config, fy_node_pair_t base_pair,
2738 const char * yaml_filename, enum yac_time_unit_type * time_unit,
2739 char const ** start_datetime, char const ** end_datetime) {
2740 char const * routine_name = "yaml_parse_base_map_pair";
2741
2742 fy_node_t key_node = fy_node_pair_key(base_pair);
2743
2745 fy_node_is_scalar(key_node),
2746 "unsupported key node type "
2747 "(key nodes are expected to be scalar nodes)");
2748
2749 char const * base_key_name = fy_node_get_scalar0(key_node);
2750 int base_key_type =
2752 yaml_base_keys, num_yaml_base_keys, base_key_name);
2753
2754 fy_node_t value_node = fy_node_pair_value(base_pair);
2755
2756 switch (base_key_type) {
2757 case (START_DATE):
2758 *start_datetime =
2760 value_node, base_key_name, yaml_filename);
2761 break;
2762 case (END_DATE):
2763 *end_datetime =
2765 value_node, base_key_name, yaml_filename);
2766 break;
2767 case (CALENDAR):
2770 value_node, base_key_name, yaml_filename));
2771 break;
2772 case (TIMESTEP_UNIT): {
2773 enum yac_time_unit_type time_unit_ =
2775 value_node, base_key_name, yaml_filename);
2777 (*time_unit == TIME_UNIT_UNDEFINED) || (*time_unit == time_unit_),
2778 "inconsistent redefinition of time unit")
2779 *time_unit = time_unit_;
2780 break;
2781 }
2782 case (COUPLING):
2784 (*time_unit != TIME_UNIT_UNDEFINED),
2785 "time unit has to be defined before the couplings")
2787 couple_config, value_node, yaml_filename, *time_unit);
2788 break;
2789 case (DEBUG):
2791 couple_config, value_node, yaml_filename);
2792 default:
2793 // nothing to be done
2794 break;
2795 }
2796}
2797
2799 struct yac_couple_config * couple_config, fy_document_t document,
2800 const char * yaml_filename) {
2801 char const * routine_name = "yaml_parse_document";
2802
2803 // get root node of document
2804 fy_node_t root_node = fy_document_root(document);
2805
2806 // if the configuration file is empty
2807 if (!root_node) return;
2808
2810 fy_node_is_mapping(root_node),
2811 "unsupported root node type (root node is expected to be a mapping node)");
2812
2813 char const * start_datetime = NULL;
2814 char const * end_datetime = NULL;
2815
2816 // parse base root mappings
2817 enum yac_time_unit_type time_unit = TIME_UNIT_UNDEFINED;
2818 void * iter = NULL;
2819 fy_node_pair_t pair;
2820 while ((pair = fy_node_mapping_iterate(root_node, &iter)))
2822 couple_config, pair, yaml_filename, &time_unit,
2823 &start_datetime, &end_datetime);
2824
2825 if ((start_datetime != NULL) || (end_datetime != NULL)) {
2826
2827 YAC_ASSERT(
2829 "ERROR(yaml_parse_document): "
2830 "cannot set start/end datetime because calendar has not yet been set");
2831
2833 couple_config, start_datetime, end_datetime);
2834 }
2835}
2836
2838 struct yac_couple_config * couple_config, const char * yaml_filename,
2839 int parse_flags) {
2840 char const * routine_name = "yac_yaml_read_coupling";
2841
2842 // check whether the yaml configuration file exists
2845 "ERROR(%s): YAML configuration file could not be found \"%s\"",
2846 routine_name, yaml_filename);
2847
2848 // open yaml configuration file
2849 FILE * config_file = xfopen(yaml_filename, "r");
2852 "ERROR(%s): could not open YAML configuration file \"%s\"",
2853 routine_name, yaml_filename);
2854
2855 // parse yaml configuration file into document
2856 struct fy_parse_cfg parse_config =
2857 {.search_path = ".",
2858 .userdata = NULL,
2859 .diag = NULL};
2860 parse_config.flags =
2861 (enum fy_parse_cfg_flags)parse_flags;
2862
2863 fy_document_t document =
2864 fy_document_build_from_fp(&parse_config, config_file);
2866 document,
2867 "ERROR(%s): could not parse YAML configuration file \"%s\"",
2868 routine_name, yaml_filename);
2869
2870 // resolve anchors and merge keys
2872 !fy_document_resolve(document),
2873 "could not resolve anchors and merge keys");
2874
2875 // parse document into couple configuration
2876 yaml_parse_document(couple_config, document, yaml_filename);
2877
2878 // cleanup
2879 fy_document_destroy(document);
2880 xfclose(config_file);
2881
2882 return;
2883}
2884
2887 char const * str_interp_stack_config, int parse_flags) {
2888 char const * routine_name =
2889 "yac_yaml_parse_interp_stack_config_string";
2890 char const * yaml_filename =
2891 "user-provided interp stack config string";
2892
2894 str_interp_stack_config != NULL, "interpolation stack string is NULL");
2895
2896 // parse string into document
2897 struct fy_parse_cfg parse_config =
2898 {.search_path = ".",
2899 .userdata = NULL,
2900 .diag = NULL};
2901 parse_config.flags =
2902 (enum fy_parse_cfg_flags)parse_flags;
2903
2904 fy_document_t document =
2905 fy_document_build_from_string(
2906 &parse_config, str_interp_stack_config, (size_t)-1);
2907 YAML_ASSERT(document, "failed parsing");
2908
2909 // resolve anchors and merge keys
2911 !fy_document_resolve(document),
2912 "could not resolve anchors and merge keys");
2913
2914 fy_node_t interp_stack_config_node = fy_document_root(document);
2915 YAML_ASSERT(interp_stack_config_node, "invalid root node");
2916
2917 struct yac_interp_stack_config * interp_stack_config =
2919
2921 interp_stack_config, interp_stack_config_node,
2923
2924 // cleanup
2925 fy_document_destroy(document);
2926
2927 return interp_stack_config;
2928}
2929
2931 fy_document_t document, char const * value) {
2932
2933 // return NULL if value is empty
2934 if (!value) return (fy_node_t)NULL;
2935
2936 fy_node_t scalar_node =
2937 fy_node_create_scalar_copy(document, value, strlen(value));
2938 YAC_ASSERT(
2939 scalar_node,
2940 "ERROR(yac_yaml_create_scalar): failed to create scalar node");
2941
2942 return scalar_node;
2943}
2944
2946 fy_document_t document, int value) {
2947
2948 char str_value[16];
2949 int value_size = snprintf(str_value, sizeof(str_value), "%d", value);
2951 (value_size >= 0) && ((size_t)value_size < sizeof(str_value)),
2952 "ERROR(yac_yaml_create_scalar_int): "
2953 "could not write \"%d\" to string buffer of size %zu",
2954 value, sizeof(str_value));
2955
2956 return yac_yaml_create_scalar(document, str_value);
2957}
2958
2960 fy_document_t document, size_t value) {
2961
2962 char str_value[32];
2963 int value_size = snprintf(str_value, sizeof(str_value), "%zu", value);
2965 (value_size >= 0) && ((size_t)value_size < sizeof(str_value)),
2966 "ERROR(yac_yaml_create_scalar_size_t): "
2967 "could not write \"%zu\" to string buffer of size %zu",
2968 value, sizeof(str_value));
2969
2970 return yac_yaml_create_scalar(document, str_value);
2971}
2972
2974 fy_document_t document, double value) {
2975
2976 char str_value[32];
2977 int value_size = snprintf(str_value, sizeof(str_value), "%g", value);
2979 (value_size >= 0) && ((size_t)value_size < sizeof(str_value)),
2980 "ERROR(yac_yaml_create_scalar_dble): "
2981 "could not write \"%g\" to string buffer of size %zu",
2982 value, sizeof(str_value));
2983
2984 return yac_yaml_create_scalar(document, str_value);
2985}
2986
2988 fy_document_t document, char const * const * values, size_t num_values) {
2989
2990 // return NULL if sequence is empty
2991 if (num_values == 0) return (fy_node_t)NULL;
2992
2993 YAC_ASSERT(
2994 values, "ERROR(yac_yaml_create_sequence_scalar): no values provided");
2995
2996 // create sequence node
2997 fy_node_t sequence_node = fy_node_create_sequence(document);
2998 YAC_ASSERT(
2999 sequence_node, "ERROR(yac_yaml_create_sequence_scalar): "
3000 "failed to create sequence node");
3001
3002 for (size_t value_idx = 0; value_idx < num_values; ++value_idx) {
3003 char const * value = values[value_idx];
3005 value, "ERROR(yac_yaml_create_sequence_scalar): "
3006 "invalid value at idx %zu", value_idx);
3007 int appending_failed =
3008 fy_node_sequence_append(
3009 sequence_node, yac_yaml_create_scalar(document, value));
3010 YAC_ASSERT(
3011 !appending_failed, "ERROR(yac_yaml_create_sequence_scalar): "
3012 "failed to append interpolation node");
3013 }
3014
3015 return sequence_node;
3016}
3017
3019 fy_document_t document, size_t const * values, size_t num_values) {
3020
3021 // return NULL if sequence is empty
3022 if (num_values == 0) return (fy_node_t)NULL;
3023
3024 YAC_ASSERT(
3025 values, "ERROR(yac_yaml_create_sequence_scalar_size_t): "
3026 "no values provided");
3027
3028 // create sequence node
3029 fy_node_t sequence_node = fy_node_create_sequence(document);
3030 YAC_ASSERT(
3031 sequence_node, "ERROR(yac_yaml_create_sequence_scalar_size_t): "
3032 "failed to create sequence node");
3033
3034 char str_value[32]; // enough for any size_t
3035 for (size_t value_idx = 0; value_idx < num_values; ++value_idx) {
3036 int value_size =
3037 snprintf(str_value, sizeof(str_value), "%zu", values[value_idx]);
3039 (value_size >= 0) && ((size_t)value_size < sizeof(str_value)),
3040 "ERROR(yac_yaml_create_sequence_scalar_size_t): "
3041 "could not write \"%zu\" to string buffer of size %zu",
3042 values[value_idx], sizeof(str_value));
3043 fy_node_t scalar_node = yac_yaml_create_scalar(document, str_value);
3045 scalar_node,
3046 "ERROR(yac_yaml_create_sequence_scalar_size_t): "
3047 "failed to create scalar at idx %zu", value_idx);
3048 int appending_failed = fy_node_sequence_append(sequence_node, scalar_node);
3049 YAC_ASSERT(
3050 !appending_failed,
3051 "ERROR(yac_yaml_create_sequence_scalar_size_t): "
3052 "failed to append sequence element");
3053 }
3054
3055 return sequence_node;
3056}
3057
3058
3060 fy_node_t map, char const * key, fy_node_t value) {
3061
3062 // if the value node is empty, return
3063 if (!value) return;
3064
3065 YAC_ASSERT(
3066 key, "ERROR(yac_yaml_map_append): NULL key is not supported");
3067
3068 fy_document_t document = fy_node_document(map);
3069 YAC_ASSERT(
3070 document,
3071 "ERROR(yac_yaml_map_append): failed to get document from node");
3072
3073 // set key and value for root node
3074 int appending_failed =
3075 fy_node_mapping_append(
3076 map, yac_yaml_create_scalar(document, key), value);
3077 YAC_ASSERT(
3078 !appending_failed,
3079 "ERROR(yac_yaml_map_append): failed to append mapping node pair");
3080}
3081
3083 fy_node_t map, char const * key, char const * value) {
3084
3085 fy_document_t document = fy_node_document(map);
3086 YAC_ASSERT(
3087 document, "ERROR(yac_yaml_map_append_scalar): "
3088 "failed to get document from node");
3089
3091}
3092
3094 fy_node_t map, char const * key, int value) {
3095
3096 fy_document_t document = fy_node_document(map);
3097 YAC_ASSERT(
3098 document, "ERROR(yac_yaml_map_append_scalar_int): "
3099 "failed to get document from node");
3100
3102 map, key, yac_yaml_create_scalar_int(document, value));
3103}
3104
3106 fy_node_t map, char const * key, size_t value) {
3107
3108 fy_document_t document = fy_node_document(map);
3109 YAC_ASSERT(
3110 document, "ERROR(yac_yaml_map_append_scalar_size_t): "
3111 "failed to get document from node");
3112
3114 map, key, yac_yaml_create_scalar_size_t(document, value));
3115}
3116
3118 fy_node_t map, char const * key, double value) {
3119
3120 fy_document_t document = fy_node_document(map);
3121 YAC_ASSERT(
3122 document, "ERROR(yac_yaml_map_append_scalar_dble): "
3123 "failed to get document from node");
3124
3126 map, key, yac_yaml_create_scalar_dble(document, value));
3127}
3128
3130 fy_document_t document, struct yac_couple_config * couple_config,
3131 size_t couple_idx, size_t field_couple_idx) {
3132
3133 const char * src_field_name;
3134 const char * tgt_field_name;
3136 couple_config, couple_idx, field_couple_idx,
3137 &src_field_name, &tgt_field_name);
3138
3139 // if both names are identical
3140 if (!strcmp(src_field_name, tgt_field_name))
3141 return yac_yaml_create_scalar(document, src_field_name);
3142
3143 // create field name node
3144 fy_node_t field_name_node = fy_node_create_mapping(document);
3145 YAC_ASSERT(
3146 field_name_node, "ERROR(yac_yaml_create_field_name_node): "
3147 "failed to create mapping node");
3148
3149 // add source field name
3150 yac_yaml_map_append_scalar(field_name_node, "src", src_field_name);
3151
3152 // add target field name
3153 yac_yaml_map_append_scalar(field_name_node, "tgt", tgt_field_name);
3154
3155 return field_name_node;
3156}
3157
3159 fy_document_t document, struct interp_method_parameter parameter,
3160 interp_method_parameter_value parameter_value) {
3161
3162 fy_node_t parameter_node = NULL;
3163
3164 switch (parameter.type) {
3166 "ERROR(yac_yaml_create_scalar_parameter_node): "
3167 "unsupported parameter type");
3168 case (ENUM_PARAM): {
3169 parameter_node =
3171 document,
3173 parameter.data.enum_param.valid_values,
3175 parameter_value.data.enum_value));
3176 break;
3177 }
3178 case (INT_PARAM): {
3179 parameter_node =
3180 yac_yaml_create_scalar_int(document, parameter_value.data.int_value);
3181 break;
3182 }
3183 case (DEG_PARAM):
3184 case (DBLE_PARAM): {
3185 parameter_node =
3186 yac_yaml_create_scalar_dble(document, parameter_value.data.dble_value);
3187 break;
3188 }
3189 case (BOOL_PARAM): {
3190 parameter_node =
3192 document,
3194 bool_names, num_bool_names, parameter_value.data.bool_value));
3195 break;
3196 }
3197 case (STR_PARAM): {
3198 parameter_node =
3199 yac_yaml_create_scalar(document, parameter_value.data.str_value);
3200 break;
3201 }
3202 };
3203
3204 return parameter_node;
3205}
3206
3208 fy_document_t document, fy_node_t map,
3209 struct interp_method_parameter parameter,
3210 interp_method_parameter_value parameter_value) {
3211
3213 map, parameter.name,
3215 document, parameter, parameter_value));
3216}
3217
3221 struct interp_method_parameter parameter) {
3222
3223 int ret = 0;
3224 switch (parameter.type) {
3226 "ERROR(compare_parameter_values): "
3227 "invalid interpolation method parameter value type");
3228 case (ENUM_PARAM):
3229 ret = (a->data.enum_value > b->data.enum_value) -
3230 (a->data.enum_value < b->data.enum_value);
3231 break;
3232 case (INT_PARAM):
3233 ret = (a->data.int_value > b->data.int_value) -
3234 (a->data.int_value < b->data.int_value);
3235 break;
3236 case (DEG_PARAM):
3237 ret = (a->data.dble_value > b->data.dble_value) -
3238 (a->data.dble_value < b->data.dble_value);
3239 break;
3240 case (DBLE_PARAM):
3241 // use memcpy to support NaNs
3242 ret = memcmp(&(a->data.dble_value),
3243 &(b->data.dble_value), sizeof(a->data.dble_value));
3244 break;
3245 case (BOOL_PARAM):
3246 ret = (a->data.bool_value > b->data.bool_value) -
3247 (a->data.bool_value < b->data.bool_value);
3248 break;
3249 case (STR_PARAM):
3250 if ((a->data.str_value != NULL) && (b->data.str_value != NULL))
3251 ret = strcmp(a->data.str_value, b->data.str_value);
3252 else
3253 ret = (a->data.str_value != NULL) - (b->data.str_value != NULL);
3254 break;
3255 }
3256 return ret;
3257}
3258
3260 fy_document_t document,
3261 interp_method_parameter_value const * map_parameter_values,
3262 struct interp_method_parameter parameter);
3263
3265 fy_document_t document,
3266 interp_method_parameter_value const * seq_parameter_values,
3267 size_t seq_parameter_values_count,
3268 struct interp_method_parameter parameter) {
3269
3271 parameter.type == SEQ_PARAM,
3272 "ERROR(yac_yaml_create_seq_parameter_node): "
3273 "parameter \"%s\" is not a map", parameter.name);
3274
3275 // create parameter node
3276 fy_node_t sequence_node =
3277 (seq_parameter_values_count > 0)?fy_node_create_sequence(document):NULL;
3278 YAC_ASSERT(
3279 sequence_node || (seq_parameter_values_count == 0),
3280 "ERROR(yac_yaml_create_seq_parameter_node): "
3281 "failed to create sequence node");
3282
3283 struct interp_method_parameter sub_parameter =
3284 *parameter.data.seq_param.sub_param;
3285
3286 for (size_t seq_idx = 0; seq_idx < seq_parameter_values_count; ++seq_idx) {
3287
3288 fy_node_t sub_parameter_node = NULL;
3289 interp_method_parameter_value sub_paramter_value =
3290 seq_parameter_values[seq_idx];
3291
3292 switch (sub_parameter.type) {
3293
3295 "ERROR(yac_yaml_create_seq_parameter_node): "
3296 "parameter \"%s\" has unsupported parameter type",
3297 sub_parameter.name);
3298
3299 // parameter is a map
3300 case (MAP_PARAM): {
3301
3302 sub_parameter_node =
3304 document, sub_paramter_value.data.map_values, sub_parameter);
3305 break;
3306 }
3307
3308 /*
3309 * currently, there is no use-case for this branch, therefore this would
3310 * be untested -> activate once it is being used
3311
3312 // parameter is a scalar
3313 case (ENUM_PARAM):
3314 case (INT_PARAM):
3315 case (DBLE_PARAM):
3316 case (BOOL_PARAM):
3317 case (STR_PARAM):
3318 case (DEG_PARAM):
3319 {
3320 if (compare_parameter_values(
3321 &sub_parameter.default_value,
3322 &sub_paramter_value, sub_parameter))
3323 sub_parameter_node =
3324 yac_yaml_create_scalar_parameter_node(
3325 document, sub_parameter, sub_paramter_value);
3326 break;
3327 }
3328 */
3329 }
3330
3331 // if the current parameter value is equal to the default values,
3332 // the parameter node is NULL, which is fine
3333 int appending_failed =
3334 fy_node_sequence_append(sequence_node, sub_parameter_node);
3336 !appending_failed,
3337 "ERROR(yac_yaml_create_seq_parameter_node): "
3338 "failed to append parameter \"%s\" to sequence", parameter.name);
3339 }
3340
3341 return sequence_node;
3342}
3343
3345 fy_document_t document,
3346 interp_method_parameter_value const * map_parameter_values,
3347 struct interp_method_parameter parameter) {
3348
3350 parameter.type == MAP_PARAM,
3351 "ERROR(yac_yaml_create_non_default_map_parameter_node): "
3352 "parameter \"%s\" is not a map", parameter.name);
3353
3354 // create parameter node
3355 fy_node_t parameter_node = fy_node_create_mapping(document);
3356 YAC_ASSERT(
3357 parameter_node, "ERROR(yac_yaml_create_non_default_map_parameter_node): "
3358 "failed to create mapping node");
3359
3360 int contains_non_default_values = 0;
3361 for (size_t sub_param_idx = 0;
3362 sub_param_idx < parameter.data.map_param.num_sub_params;
3363 ++sub_param_idx) {
3364
3365 struct interp_method_parameter sub_parameter =
3366 parameter.data.map_param.sub_params[sub_param_idx];
3367 interp_method_parameter_value sub_parameter_value =
3368 map_parameter_values[sub_param_idx];
3369
3370 switch(sub_parameter.type) {
3371
3373 "ERROR(yac_yaml_create_non_default_map_parameter_node): "
3374 "parameter \"%s\" has unsupported parameter type",
3375 sub_parameter.name)
3376
3377 // parameter is a map
3378 case (MAP_PARAM): {
3379
3380 fy_node_t sub_parameter_node =
3382 document, sub_parameter_value.data.map_values, sub_parameter);
3383
3384 // if the map contained non-default parameter values
3385 if (sub_parameter_node) {
3387 parameter_node, sub_parameter.name, sub_parameter_node);
3388 contains_non_default_values = 1;
3389 }
3390 break;
3391 }
3392
3393 // parameter is a sequence
3394 case (SEQ_PARAM): {
3395
3396 fy_node_t sub_parameter_node =
3398 document, sub_parameter_value.data.seq.values,
3399 sub_parameter_value.data.seq.count, sub_parameter);
3400
3401 // if the sequence contained parameter values
3402 if (sub_parameter_node) {
3404 parameter_node, sub_parameter.name, sub_parameter_node);
3405 contains_non_default_values = 1;
3406 }
3407 break;
3408 }
3409
3410 // parameter is a scalar
3411 case (ENUM_PARAM):
3412 case (INT_PARAM):
3413 case (DBLE_PARAM):
3414 case (BOOL_PARAM):
3415 case (STR_PARAM):
3416 case (DEG_PARAM):
3417 {
3419 &sub_parameter.default_value,
3420 &sub_parameter_value, sub_parameter)) {
3422 document, parameter_node, sub_parameter, sub_parameter_value);
3423 contains_non_default_values = 1;
3424 }
3425 break;
3426 }
3427 }
3428 }
3429
3430 // if there were no non-default parameters
3431 if (!contains_non_default_values) {
3432 fy_node_free(parameter_node);
3433 parameter_node = NULL;
3434 }
3435 return parameter_node;
3436}
3437
3439 fy_document_t document,
3440 union yac_interp_stack_config_entry const * interp_stack_entry) {
3441
3442 // get the interpolation data matching the interpolation stack entry
3443 enum yac_interpolation_list interp_type =
3444 yac_interp_stack_config_entry_get_type(interp_stack_entry);
3445 struct yac_interpolation_method const * interp_method = NULL;
3446 for (size_t i = 0;
3448 if (interpolation_methods[i].type == interp_type)
3450
3451 // get the interpolation parameter configuration and their default values
3452 struct interp_method_parameter parameter =
3453 interp_method->parameter;
3454
3455 fy_node_t parameter_node;
3456
3457 interp_method_parameter_value parameter_value =
3459
3460 // get parameter values set in the interpolation stack entry
3461 interp_method->get_interpolation(interp_stack_entry, &parameter_value);
3462
3463 // create parameter node containing all non-default values
3464 parameter_node =
3466 document, parameter_value.data.map_values, parameter);
3467
3468 yaml_interp_method_parameter_free(parameter_value, parameter);
3469
3470 fy_node_t interpolation_node;
3471
3472 // if the interpolation contains non-default parameter values
3473 if (parameter_node) {
3474
3475 // create interpolation node
3476 interpolation_node = fy_node_create_mapping(document);
3477 YAC_ASSERT(
3478 interpolation_node, "ERROR(yac_yaml_create_interpolation_node): "
3479 "failed to create mapping node");
3480
3482 interpolation_node, interp_method->name, parameter_node);
3483 } else {
3484
3485 interpolation_node =
3486 yac_yaml_create_scalar(document, interp_method->name);
3487 }
3488
3489 return interpolation_node;
3490}
3491
3493 fy_document_t document, struct yac_couple_config * couple_config,
3494 size_t couple_idx, size_t field_couple_idx) {
3495
3496 struct yac_interp_stack_config * interp_stack =
3498 couple_config, couple_idx, field_couple_idx);
3499
3500 YAC_ASSERT(
3501 interp_stack, "ERROR(yac_yaml_create_interpolation_stack_node): "
3502 "invalid interpolation stack");
3503
3504 // create interpolation stack node
3505 fy_node_t interp_stack_node = fy_node_create_sequence(document);
3506 YAC_ASSERT(
3507 interp_stack_node, "ERROR(yac_yaml_create_interpolation_stack_node): "
3508 "failed to create sequence node");
3509
3510 size_t interp_stack_size =
3512 YAC_ASSERT(
3513 interp_stack_size, "ERROR(yac_yaml_create_interpolation_stack_node): "
3514 "invalid interpolation stack size");
3515
3516 for (size_t interp_stack_idx = 0; interp_stack_idx < interp_stack_size;
3517 ++interp_stack_idx) {
3518 int appending_failed =
3519 fy_node_sequence_append(
3520 interp_stack_node,
3522 document,
3524 interp_stack, interp_stack_idx)));
3525 YAC_ASSERT(
3526 !appending_failed,
3527 "ERROR(yac_yaml_create_interpolation_stack_node): "
3528 "failed to append interpolation node");
3529 }
3530
3531 return interp_stack_node;
3532}
3533
3535 fy_node_t coupling_node, struct yac_couple_config * couple_config,
3536 size_t couple_idx, size_t field_couple_idx) {
3537
3538 fy_document_t document = fy_node_document(coupling_node);
3539 YAC_ASSERT(
3540 document, "ERROR(yac_yaml_append_couple_field_nodes): "
3541 "failed to get document from node");
3542
3543 // create couple node
3544 fy_node_t field_couple_node = fy_node_create_mapping(document);
3545 YAC_ASSERT(
3546 coupling_node, "ERROR(yac_yaml_append_couple_field_nodes): "
3547 "failed to create mapping node");
3548
3549 // get component names
3550 char const * src_component_name;
3551 char const * tgt_component_name;
3553 couple_config, couple_idx, field_couple_idx,
3554 &src_component_name, &tgt_component_name);
3555
3556 // add source component name
3558 field_couple_node,
3560 yaml_couple_keys, num_yaml_couple_keys, SOURCE_COMPONENT),
3561 src_component_name);
3562
3563 // add target component name
3565 field_couple_node,
3567 yaml_couple_keys, num_yaml_couple_keys, TARGET_COMPONENT),
3568 tgt_component_name);
3569
3570 // get grid names
3571 char const * src_grid_name;
3572 char const * tgt_grid_name;
3574 couple_config, couple_idx, field_couple_idx,
3576
3577 // add source grid name
3579 field_couple_node,
3581 yaml_couple_keys, num_yaml_couple_keys, SOURCE_GRID),
3583
3584 // add target grid name
3586 field_couple_node,
3588 yaml_couple_keys, num_yaml_couple_keys, TARGET_GRID),
3590
3591 // add field names
3593 field_couple_node,
3595 yaml_couple_keys, num_yaml_couple_keys, FIELD),
3597 document, couple_config, couple_idx, field_couple_idx));
3598
3599 // add coupling period
3601 field_couple_node,
3603 yaml_couple_keys, num_yaml_couple_keys, COUPLING_PERIOD),
3605 couple_config, couple_idx, field_couple_idx));
3606
3607 // add time reduction
3609 field_couple_node,
3611 yaml_couple_keys, num_yaml_couple_keys, TIME_REDUCTION),
3613 time_operations, num_time_operations,
3615 couple_config, couple_idx, field_couple_idx)));
3616
3617 // add source lag
3619 field_couple_node,
3621 yaml_couple_keys, num_yaml_couple_keys, SOURCE_LAG),
3623 couple_config, couple_idx, field_couple_idx));
3624
3625 // add target lag
3627 field_couple_node,
3629 yaml_couple_keys, num_yaml_couple_keys, TARGET_LAG),
3631 couple_config, couple_idx, field_couple_idx));
3632
3633 // add weight file name
3635 couple_config, couple_idx, field_couple_idx)) {
3637 field_couple_node,
3639 yaml_couple_keys, num_yaml_couple_keys, WEIGHT_FILE_NAME),
3641 couple_config, couple_idx, field_couple_idx));
3643 field_couple_node,
3645 yaml_couple_keys, num_yaml_couple_keys, WEIGHT_FILE_ON_EXISTING),
3647 weight_file_on_existing_types, num_weight_file_on_existing_types,
3649 couple_config, couple_idx, field_couple_idx)));
3650 }
3651
3652 // add mapping side
3654 field_couple_node,
3656 yaml_couple_keys, num_yaml_couple_keys, MAPPING_SIDE),
3658 mapping_sides, num_mapping_sides,
3660 couple_config, couple_idx, field_couple_idx)));
3661
3662 // add scale factor
3664 field_couple_node,
3666 yaml_couple_keys, num_yaml_couple_keys, SCALE_FACTOR),
3668 couple_config, couple_idx, field_couple_idx));
3669
3670 // add scale summand
3672 field_couple_node,
3674 yaml_couple_keys, num_yaml_couple_keys, SCALE_SUMMAND),
3676 couple_config, couple_idx, field_couple_idx));
3677
3678 // add interpolation
3680 field_couple_node,
3682 yaml_couple_keys, num_yaml_couple_keys, INTERPOLATION),
3684 document, couple_config, couple_idx, field_couple_idx));
3685
3686 // add source mask names
3687 char const * const * src_mask_names;
3688 size_t num_src_mask_names;
3690 couple_config, couple_idx, field_couple_idx,
3691 &src_mask_names, &num_src_mask_names);
3692 if (num_src_mask_names == 1)
3694 field_couple_node,
3696 yaml_couple_keys, num_yaml_couple_keys, SOURCE_MASK_NAME),
3697 src_mask_names[0]);
3698 else if (num_src_mask_names > 1)
3700 field_couple_node,
3702 yaml_couple_keys, num_yaml_couple_keys, SOURCE_MASK_NAMES),
3704 document, src_mask_names, num_src_mask_names));
3705
3706 // add target mask name
3707 char const * tgt_mask_name =
3709 couple_config, couple_idx, field_couple_idx);
3710 if (tgt_mask_name)
3712 field_couple_node,
3714 yaml_couple_keys, num_yaml_couple_keys, TARGET_MASK_NAME),
3715 tgt_mask_name);
3716
3717 // add yaxt exchanger name
3718 char const * yaxt_exchanger_name =
3720 couple_config, couple_idx, field_couple_idx);
3721 if (yaxt_exchanger_name)
3723 field_couple_node,
3725 yaml_couple_keys, num_yaml_couple_keys, YAXT_EXCHANGER_NAME),
3726 yaxt_exchanger_name);
3727
3728 // add collection selection
3729 struct yac_collection_selection const * collection_selection =
3731 couple_config, couple_idx, field_couple_idx);
3732 if (collection_selection) {
3733 size_t collection_size =
3735 size_t const * indices =
3736 yac_collection_selection_get_indices(collection_selection);
3737 size_t * continous_indices = NULL;
3738 if (indices == NULL) {
3739 continous_indices =
3740 xmalloc(collection_size * sizeof(*continous_indices));
3741 for (size_t i = 0; i < collection_size; ++i) continous_indices[i] = i;
3742 indices = continous_indices;
3743 }
3744 if (collection_size == 1) {
3746 field_couple_node,
3748 yaml_couple_keys, num_yaml_couple_keys, COLLECTION_SELECTION),
3749 indices[0]);
3750 } else if (collection_size > 1) {
3752 field_couple_node,
3754 yaml_couple_keys, num_yaml_couple_keys, COLLECTION_SELECTION),
3756 document, indices, collection_size));
3757 }
3758 free(continous_indices);
3759 }
3760
3761 // add use raw exchange
3763 field_couple_node,
3765 yaml_couple_keys, num_yaml_couple_keys, USE_RAW_EXCHANGE),
3767 bool_names, num_bool_names,
3769 couple_config, couple_idx, field_couple_idx)));
3770
3771 int appending_failed =
3772 fy_node_sequence_append(coupling_node, field_couple_node);
3773 YAC_ASSERT(
3774 !appending_failed,
3775 "ERROR(yac_yaml_append_couple_field_nodes): "
3776 "failed to append field couple node");
3777}
3778
3780 fy_node_t coupling_node, struct yac_couple_config * couple_config,
3781 size_t couple_idx) {
3782
3783 size_t num_couple_fields =
3784 yac_couple_config_get_num_couple_fields(couple_config, couple_idx);
3785
3786 for (size_t field_couple_idx = 0;
3787 field_couple_idx < num_couple_fields; ++field_couple_idx)
3789 coupling_node, couple_config, couple_idx, field_couple_idx);
3790}
3791
3793 fy_document_t document, char const * grid_name, char const * file_name) {
3794
3795 fy_node_t output_grid_node = fy_node_create_mapping(document);
3796 YAC_ASSERT(
3797 output_grid_node, "ERROR(yac_yaml_create_output_grid_node): "
3798 "failed to create mapping node");
3799
3801 output_grid_node,
3803 yaml_debug_output_grid_keys, num_yaml_debug_output_grid_keys,
3805 grid_name);
3807 output_grid_node,
3809 yaml_debug_output_grid_keys, num_yaml_debug_output_grid_keys,
3811 file_name);
3812
3813 return output_grid_node;
3814}
3815
3817 fy_document_t document, struct yac_couple_config * couple_config) {
3818
3819 // count the number of output grids
3820 size_t num_output_grids = 0;
3821 size_t num_grids =
3822 yac_couple_config_get_num_grids(couple_config);
3823 for (size_t grid_idx = 0; grid_idx < num_grids; ++grid_idx)
3825 couple_config,
3826 yac_couple_config_get_grid_name(couple_config, grid_idx)) != NULL)
3827 ++num_output_grids;
3828
3829 fy_node_t output_grids_node = NULL;
3830
3831 if (num_output_grids > 0) {
3832
3833 // create output grids node
3834 output_grids_node = fy_node_create_sequence(document);
3835 YAC_ASSERT(
3836 output_grids_node, "ERROR(yac_yaml_create_output_grids_node): "
3837 "failed to create sequence node");
3838
3839 // for all output grids
3840 for (size_t grid_idx = 0; grid_idx < num_grids; ++grid_idx) {
3841
3842 char const * grid_name =
3844 char const * file_name =
3845 yac_couple_config_grid_get_output_filename(couple_config, grid_name);
3846
3847 if (file_name != NULL) {
3848 int appending_failed =
3849 fy_node_sequence_append(
3850 output_grids_node,
3851 yac_yaml_create_output_grid_node(document, grid_name, file_name));
3852 YAC_ASSERT(
3853 !appending_failed, "ERROR(yac_yaml_create_output_grids_node): "
3854 "failed to append output grid node");
3855 }
3856 }
3857 }
3858
3859 return output_grids_node;
3860}
3861
3863 fy_document_t document, struct yac_couple_config * couple_config) {
3864
3865 // create debug node
3866 fy_node_t debug_node = fy_node_create_mapping(document);
3867 YAC_ASSERT(
3868 debug_node, "ERROR(yac_yaml_create_debug_node): "
3869 "failed to create mapping node");
3870
3871 // add output grids node
3873 debug_node,
3875 yaml_debug_keys, num_yaml_debug_keys, OUTPUT_GRIDS),
3876 yac_yaml_create_output_grids_node(document, couple_config));
3877
3878 // add "missing_definition_is_fatal" node
3880 debug_node,
3882 yaml_debug_keys, num_yaml_debug_keys, MISSING_DEF),
3884 bool_names, num_bool_names,
3886
3887 return debug_node;
3888}
3889
3891 fy_document_t document, struct yac_couple_config * couple_config) {
3892
3893 size_t num_couples =
3894 yac_couple_config_get_num_couples(couple_config);
3895
3896 if (!num_couples) return NULL;
3897
3898 // create coupling node
3899 fy_node_t coupling_node = fy_node_create_sequence(document);
3900 YAC_ASSERT(
3901 coupling_node, "ERROR(yac_yaml_create_coupling_node): "
3902 "failed to create sequence node");
3903
3904 // for all couples
3905 for (size_t couple_idx = 0; couple_idx < num_couples; ++couple_idx)
3907 coupling_node, couple_config, couple_idx);
3908
3909 return coupling_node;
3910}
3911
3913 fy_document_t document, struct yac_couple_config * couple_config,
3914 size_t component_idx, size_t field_idx) {
3915
3916 fy_node_t field_node = fy_node_create_mapping(document);
3917 YAC_ASSERT(
3918 field_node, "ERROR(yac_yaml_create_field_node): "
3919 "failed to create mapping node");
3920
3921 // get field parameters
3922 char const * component_name =
3924 couple_config, component_idx);
3925 char const * field_name =
3927 couple_config, component_idx, field_idx);
3928 char const * grid_name =
3930 couple_config, component_idx, field_idx);
3931 char const * metadata =
3933 couple_config, component_name, grid_name, field_name);
3934 size_t collection_size =
3936 couple_config, component_name, grid_name, field_name);
3937 char const * timestep =
3939 couple_config, component_name, grid_name, field_name);
3940 int role =
3942 couple_config, component_name, grid_name, field_name);
3943 double frac_mask_fallback_value =
3945 couple_config, component_name, grid_name, field_name);
3946
3947 // add field name
3948 yac_yaml_map_append_scalar(field_node, "name", field_name);
3949
3950 // add grid name
3951 yac_yaml_map_append_scalar(field_node, "grid_name", grid_name);
3952
3953 // add metadata
3954 if (metadata)
3955 yac_yaml_map_append_scalar(field_node, "metadata", metadata);
3956
3957 // add collection_size
3958 if (collection_size != SIZE_MAX)
3960 field_node, "collection_size", (int)collection_size);
3961
3962 // add timestep
3963 if (timestep)
3964 yac_yaml_map_append_scalar(field_node, "timestep", timestep);
3965
3966 // add role
3968 field_node, "role",
3970 role_types, num_role_types, (enum yac_field_exchange_type)role));
3971
3972 // add fractional fallback value
3973 if (YAC_FRAC_MASK_VALUE_IS_VALID(frac_mask_fallback_value))
3975 field_node, "frac_mask_fallback_value", frac_mask_fallback_value);
3976
3977 return field_node;
3978}
3979
3981 fy_document_t document, struct yac_couple_config * couple_config,
3982 size_t component_idx) {
3983
3984 size_t num_fields =
3986
3987 if (num_fields == 0) return (fy_node_t)NULL;
3988
3989 fy_node_t fields_node = fy_node_create_sequence(document);
3990 YAC_ASSERT(
3991 fields_node, "ERROR(yac_yaml_create_fields_node): "
3992 "failed to create sequence node");
3993
3994 for (size_t field_idx = 0; field_idx < num_fields; ++field_idx) {
3995
3996 int appending_failed =
3997 fy_node_sequence_append(
3998 fields_node,
4000 document, couple_config, component_idx, field_idx));
4001 YAC_ASSERT(
4002 !appending_failed, "ERROR(yac_yaml_create_fields_node): "
4003 "failed to append field node");
4004 }
4005
4006 return fields_node;
4007}
4008
4010 fy_document_t document, struct yac_couple_config * couple_config,
4011 size_t component_idx) {
4012
4013 fy_node_t component_node = fy_node_create_mapping(document);
4014 YAC_ASSERT(
4015 component_node, "ERROR(yac_yaml_create_component_node): "
4016 "failed to create mapping node");
4017
4018 // get component name, component metadata, and fields
4019 char const * component_name =
4021 char const * metadata =
4022 yac_couple_config_component_get_metadata(couple_config, component_name);
4023 fy_node_t fields_node =
4025 document, couple_config, component_idx);
4026
4027 // add component name
4028 yac_yaml_map_append_scalar(component_node, "name", component_name);
4029
4030 // add metadata
4031 if (metadata)
4032 yac_yaml_map_append_scalar(component_node, "metadata", metadata);
4033
4034 // add fields
4035 yac_yaml_map_append(component_node, "fields", fields_node);
4036
4037 return component_node;
4038}
4039
4041 fy_document_t document, struct yac_couple_config * couple_config) {
4042
4043 // get number of components in coupling configuration
4045
4046 if (num_components == 0) return (fy_node_t)NULL;
4047
4048 // create sequence node
4049 fy_node_t components_node = fy_node_create_sequence(document);
4050 YAC_ASSERT(
4051 components_node, "ERROR(yac_yaml_create_components_node): "
4052 "failed to create sequence node");
4053
4054 for (size_t component_idx = 0; component_idx < num_components;
4055 ++component_idx) {
4056
4057 int appending_failed =
4058 fy_node_sequence_append(
4059 components_node,
4060 yac_yaml_create_component_node(document, couple_config, component_idx));
4061 YAC_ASSERT(
4062 !appending_failed, "ERROR(yac_yaml_create_components_node): "
4063 "failed to append component node");
4064 }
4065
4066 return components_node;
4067}
4068
4070 fy_document_t document, struct yac_couple_config * couple_config,
4071 size_t grid_idx) {
4072
4073 fy_node_t grid_node = fy_node_create_mapping(document);
4074 YAC_ASSERT(
4075 grid_node, "ERROR(yac_yaml_create_grid_node): "
4076 "failed to create mapping node");
4077
4078 // get grid name and metadata
4079 char const * grid_name =
4081 char const * metadata =
4082 yac_couple_config_grid_get_metadata(couple_config, grid_name);
4083
4084 // add grid name
4085 yac_yaml_map_append_scalar(grid_node, "name", grid_name);
4086
4087 // add metadata
4088 if (metadata)
4089 yac_yaml_map_append_scalar(grid_node, "metadata", metadata);
4090
4091 return grid_node;
4092}
4093
4095 fy_document_t document, struct yac_couple_config * couple_config) {
4096
4097 // get number of grids in coupling configuration
4098 size_t num_grids = yac_couple_config_get_num_grids(couple_config);
4099
4100 if (num_grids == 0) return (fy_node_t)NULL;
4101
4102 // create sequence node
4103 fy_node_t grids_node = fy_node_create_sequence(document);
4104 YAC_ASSERT(
4105 grids_node, "ERROR(yac_yaml_create_grids_node): "
4106 "failed to create sequence node");
4107
4108 for (size_t grids_idx = 0; grids_idx < num_grids; ++grids_idx) {
4109
4110 int appending_failed =
4111 fy_node_sequence_append(
4112 grids_node,
4113 yac_yaml_create_grid_node(document, couple_config, grids_idx));
4114 YAC_ASSERT(
4115 !appending_failed, "ERROR(yac_yaml_create_grids_node): "
4116 "failed to append grid node");
4117 }
4118
4119 return grids_node;
4120}
4121
4123 fy_document_t document, struct yac_couple_config * couple_config) {
4124
4125 // create definition
4126 fy_node_t definition_node = fy_node_create_mapping(document);
4127 YAC_ASSERT(
4128 definition_node,
4129 "ERROR(yac_yaml_create_definitions_node): "
4130 "failed to create mapping node");
4131
4132 // add components
4134 definition_node,
4135 "components", yac_yaml_create_components_node(document, couple_config));
4136
4137 // add grids
4139 definition_node, "grids", yac_yaml_create_grids_node(document, couple_config));
4140
4141 return definition_node;
4142}
4143
4145 fy_document_t document, struct yac_couple_config * couple_config,
4146 int include_definitions) {
4147
4148 // create root node
4149 fy_node_t root_node = fy_node_create_mapping(document);
4150 YAC_ASSERT(
4151 root_node,
4152 "ERROR(yac_yaml_create_couple_config_nodes): "
4153 "failed to create mapping node");
4154
4155 // add debug
4157 root_node,
4159 yaml_base_keys, num_yaml_base_keys, DEBUG),
4160 yac_yaml_create_debug_node(document, couple_config));
4161
4162 // add user definitions (components, grids, and fields)
4163 if (include_definitions)
4165 root_node, "definitions",
4166 yac_yaml_create_definitions_node(document, couple_config));
4167
4168 // add start datetime
4169 char * start_datetime = yac_couple_config_get_start_datetime(couple_config);
4171 root_node,
4173 yaml_base_keys, num_yaml_base_keys, START_DATE), start_datetime);
4174 free(start_datetime);
4175
4176 // add end datetime
4177 char * end_datetime = yac_couple_config_get_end_datetime(couple_config);
4179 root_node,
4181 yaml_base_keys, num_yaml_base_keys, END_DATE), end_datetime);
4182 free(end_datetime);
4183
4184 // add calendar
4186 root_node,
4188 yaml_base_keys, num_yaml_base_keys, CALENDAR),
4190 calendar_types, num_calendar_types, getCalendarType()));
4191
4192 // add timestep unit
4194 root_node,
4196 yaml_base_keys, num_yaml_base_keys, TIMESTEP_UNIT),
4198 timestep_units, num_timestep_units, C_ISO_FORMAT));
4199
4200 // add couplings
4202 root_node,
4204 yaml_base_keys, num_yaml_base_keys, COUPLING),
4205 yac_yaml_create_coupling_node(document, couple_config));
4206
4207 return root_node;
4208}
4209
4211 struct yac_couple_config * couple_config, int emit_flags,
4212 int include_definitions) {
4213
4214 // create an empty document
4215 fy_document_t document = fy_document_create(NULL);
4216 YAC_ASSERT(
4217 document, "ERROR(yac_yaml_emit): failed to create document");
4218
4219 // create nodes from coupling configuration
4220 fy_node_t root_node =
4222 document, couple_config, include_definitions);
4223
4224 // set root node of the document
4225 int setting_root_failed =
4226 fy_document_set_root(document, root_node);
4227 YAC_ASSERT(
4228 !setting_root_failed,
4229 "ERROR(yac_yaml_emit): failed to add root node to document");
4230
4231 // emit document to string
4232 char * str_document =
4233 fy_emit_document_to_string(
4234 document, (enum fy_emitter_cfg_flags)emit_flags);
4235
4236 YAC_ASSERT(
4237 str_document, "ERROR(yac_yaml_emit): failed to emit document to string");
4238
4239 // destroy document
4240 fy_document_destroy(document);
4241
4242 return str_document;
4243}
char const * grid_names[]
unsigned component_idx[3]
unsigned num_fields
unsigned num_components
char const * field_names[8]
char const * file_name
unsigned grid_idx[3]
#define YAC_ASSERT(exp, msg)
static struct yac_point_selection * parse_point_selection_parameter_bnd_circle(interp_method_parameter_value const parameter)
static double yaml_parse_double_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
yaml_debug_sync_loc_key_types
@ SYNC_LOC_COUNT
@ SYNC_LOC_ENDDEF
@ SYNC_LOC_DEF_COMP
@ SYNC_LOC_SYNC_DEF
#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)
#define DEF_STR_PARAM(NAME, DEFAULT, MAX_STR_LEN)
struct yac_interp_stack_config * yac_yaml_parse_interp_stack_config_string(char const *str_interp_stack_config, int parse_flags)
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)
static void yac_yaml_append_couple_nodes(fy_node_t coupling_node, struct yac_couple_config *couple_config, size_t couple_idx)
static struct yac_spmap_overwrite_config * parse_overwrite_config_parameter(interp_method_parameter_value const *parameter_value, struct yac_spmap_scale_config *scale_config)
static fy_node_t yac_yaml_create_scalar_dble(fy_document_t document, double value)
#define YAML_UNREACHABLE_DEFAULT_F(MSG,...)
#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:56
static fy_node_t yac_yaml_create_field_node(fy_document_t document, struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
static calendarType yaml_parse_calendar_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static fy_node_t yac_yaml_create_grids_node(fy_document_t document, struct yac_couple_config *couple_config)
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, char const **start_datetime, char const **end_datetime)
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 fy_node_t yac_yaml_create_output_grids_node(fy_document_t document, struct yac_couple_config *couple_config)
static fy_node_t yac_yaml_create_sequence_scalar_size_t(fy_document_t document, size_t const *values, size_t num_values)
int const YAC_YAML_PARSER_JSON_AUTO
Definition config_yaml.c:69
yaml_debug_key_types
@ GLOBAL_CONFIG
@ GLOBAL_DEFS
@ OUTPUT_GRIDS
@ MISSING_DEF
static void yaml_parse_size_t_sequence(size_t **values, size_t *num_values, fy_node_t values_node, char const *sequence_name, const char *yaml_filename)
#define YAML_UNREACHABLE_DEFAULT(MSG)
char * yac_yaml_emit_coupling(struct yac_couple_config *couple_config, int emit_flags, int include_definitions)
static size_t yaml_parse_size_t_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static fy_node_t yac_yaml_create_components_node(fy_document_t document, struct yac_couple_config *couple_config)
static fy_node_t yac_yaml_create_couple_config_nodes(fy_document_t document, struct yac_couple_config *couple_config, int include_definitions)
static fy_node_t yac_yaml_create_grid_node(fy_document_t document, struct yac_couple_config *couple_config, size_t grid_idx)
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)
#define DEF_INTERP_METHOD_NO_PARAM(YAML_NAME, UI_NAME)
static void yaml_parse_interp_method_seq_parameter(struct interp_method_parameter seq_parameter, interp_method_parameter_value **seq_parameter_values, size_t *seq_parameter_count, fy_node_t value_node, char const *interpolation_name, char const *yaml_filename)
int const YAC_YAML_EMITTER_DEFAULT
emit to YAML format
Definition config_yaml.c:66
@ EMITTER_DEFAULT
Definition config_yaml.c:59
@ PARSER_JSON_AUTO
Definition config_yaml.c:62
@ EMITTER_JSON
Definition config_yaml.c:60
@ PARSER_JSON_FORCE
Definition config_yaml.c:63
@ PARSER_DEFAULT
Definition config_yaml.c:61
void yac_yaml_read_coupling(struct yac_couple_config *couple_config, const char *yaml_filename, int parse_flags)
#define DEF_SEQ_PARAM(NAME, SUBPARAM)
static fy_node_t yac_yaml_create_non_default_map_parameter_node(fy_document_t document, interp_method_parameter_value const *map_parameter_values, struct interp_method_parameter parameter)
yaml_couple_key_types
@ WEIGHT_FILE_NAME
@ SCALE_SUMMAND
@ TARGET_COMPONENT
@ SOURCE_GRID
@ SOURCE_MASK_NAME
@ INTERPOLATION
@ SOURCE_MASK_NAMES
@ YAXT_EXCHANGER_NAME
@ MAPPING_SIDE
@ TIME_REDUCTION
@ SOURCE_LAG
@ WEIGHT_FILE_ON_EXISTING
@ COLLECTION_SELECTION
@ FIELD
@ TARGET_GRID
@ COUPLING_PERIOD
@ TARGET_NAMES
@ WEIGHT_FILE_DATA
@ SOURCE_COMPONENT
@ SCALE_FACTOR
@ TARGET_LAG
@ TARGET_MASK_NAME
@ USE_RAW_EXCHANGE
@ SOURCE_NAMES
static int yaml_parse_integer_value(fy_node_t value_node, char const *key_name, char const *yaml_filename)
static fy_node_t yac_yaml_create_scalar_parameter_node(fy_document_t document, struct interp_method_parameter parameter, interp_method_parameter_value parameter_value)
static void yaml_parse_debug_output_grids(struct yac_couple_config *couple_config, fy_node_t output_grids_node, char const *yaml_filename)
int const YAC_YAML_EMITTER_JSON
emit to JSON format
Definition config_yaml.c:67
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)
static int compare_parameter_values(interp_method_parameter_value const *a, interp_method_parameter_value const *b, struct interp_method_parameter parameter)
struct fy_document * fy_document_t
Definition config_yaml.c:54
int const YAC_YAML_PARSER_DEFAULT
default parse flags (YAML format)
Definition config_yaml.c:68
static fy_node_t yac_yaml_create_output_grid_node(fy_document_t document, char const *grid_name, char const *file_name)
#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)
reads interpolation name and user-provided parameters from YAML node
static void yaml_parse_weight_file_data(char const **weight_file_name, enum yac_weight_file_on_existing *on_existing, fy_node_t values_node, char const *type_name, const char *yaml_filename)
static void parse_point_coordinates(interp_method_parameter_value const *parameters, double *lon, double *lat)
yaml_weight_file_data_key_types
@ WEIGHT_FILE_DATA_ON_EXISTING
@ WEIGHT_FILE_DATA_NAME
#define DEF_INTERP_METHOD(YAML_NAME, FUNC_ADD, FUNC_GET,...)
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)
static void get_cell_area_config_parameters(struct yac_spmap_cell_area_config const *cell_area_config, double *sphere_radius, char const **filename, char const **varname, int *min_global_id, char const *desc)
#define DEF_MAP_PARAM(NAME, SUBPARAMS)
#define ADD_INTERPOLATION(NAME, TYPE)
static void get_point_selection_parameters(struct yac_point_selection const *point_selection, interp_method_parameter_value *parameter_value)
static struct debug_config_file_buffer yaml_parse_debug_config_file_buffer(fy_node_t config_file_node, char const *config_file_type_name, char const *yaml_filename)
#define DEF_NAME_TYPE_PAIR(NAME, TYPE)
#define YAML_ASSERT_F(CHECK, MSG,...)
static fy_node_t yac_yaml_create_component_node(fy_document_t document, struct yac_couple_config *couple_config, size_t component_idx)
@ NUM_INTERPOLATION_METHODS
static void yaml_parse_interp_method_map_parameter(struct interp_method_parameter map_parameter, interp_method_parameter_value *map_parameter_values, fy_node_t value_node, char const *interpolation_name, char const *yaml_filename)
yaml_debug_output_grid_key_types
@ OUTPUT_GRID_FILE_NAME
@ OUTPUT_GRID_GRID_NAME
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)
#define DEF_INT_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX)
static void yaml_parse_output_grid_pair(char const **grid_name, char const **file_name, fy_node_pair_t output_grid_pair, 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)
static void yac_yaml_map_append_scalar_size_t(fy_node_t map, char const *key, size_t value)
static fy_node_t yac_yaml_create_scalar_size_t(fy_document_t document, size_t value)
static interp_method_parameter_value yaml_interp_method_parameter_get_default(struct interp_method_parameter parameter)
allocates parameter values and assigns default values based on provided interpolation parameter defin...
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
Definition event.c:329
int const YAC_YAML_PARSER_JSON_FORCE
assume JSON format
Definition config_yaml.c:70
static void yac_yaml_map_append_parameter(fy_document_t document, fy_node_t map, struct interp_method_parameter parameter, interp_method_parameter_value parameter_value)
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)
static void yaml_parse_interp_stack_value(struct yac_interp_stack_config *interp_stack, fy_node_t interp_stack_node, char const *yaml_filename)
static fy_node_t yac_yaml_create_debug_node(fy_document_t document, struct yac_couple_config *couple_config)
struct fy_node * fy_node_t
Definition config_yaml.c:55
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 fy_node_t yac_yaml_create_seq_parameter_node(fy_document_t document, interp_method_parameter_value const *seq_parameter_values, size_t seq_parameter_values_count, struct interp_method_parameter parameter)
static char const * yaml_parse_string_value(fy_node_t value_node, char const *name, char const *yaml_filename)
static void yaml_parse_interp_method_parameter_value(struct interp_method_parameter parameter, interp_method_parameter_value *parameter_value, fy_node_t value_node, char const *interpolation_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)
static void yaml_parse_comp_grid_names(char const **comp_name, char const ***grid_names, size_t *num_grid_names, fy_node_t values_node, char const *type_name, const char *yaml_filename)
#define YAML_ASSERT(CHECK, MSG)
static fy_node_t yac_yaml_create_fields_node(fy_document_t document, struct yac_couple_config *couple_config, size_t component_idx)
static void yaml_parse_debug_config_file_map_pair(struct debug_config_file_buffer *config_file_buffer, fy_node_pair_t config_file_pair, char const *config_file_type_name, const char *yaml_filename)
yaml_base_key_types
@ DEBUG
@ TIMESTEP_UNIT
@ START_DATE
@ COUPLING
@ CALENDAR
@ END_DATE
static void yaml_interp_method_parameter_free(interp_method_parameter_value parameter_value, struct interp_method_parameter parameter)
free memory associated with
static void yaml_parse_interp_method(struct yac_interp_stack_config *interp_stack, fy_node_t interp_method_node, char const *yaml_filename)
#define DEF_NAME_TYPE_PAIRS(NAME,...)
yaml_comp_grid_names_key_types
@ COMP_NAME
@ GRID_NAMES
static fy_node_t yac_yaml_create_scalar(fy_document_t document, char const *value)
static void yaml_parse_output_grid(struct yac_couple_config *couple_config, fy_node_t output_grid_node, char const *yaml_filename)
static fy_node_t yac_yaml_create_scalar_int(fy_document_t document, int value)
#define DEF_DBLE_PARAM(NAME, DEFAULT, VALID_MIN, VALID_MAX, ALLOW_NAN)
static void yaml_parse_collection_selection_sequence(struct yac_collection_selection **collection_selection, fy_node_t values_node, char const *sequence_name, const char *yaml_filename)
static struct debug_config_file yaml_parse_config_file_value(fy_node_t config_file_node, char const *file_type_name, const char *yaml_filename)
#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)
struct interp_method_parameter_value interp_method_parameter_value
#define DEF_MAP_SUBPARAMS(NAME,...)
static fy_node_t yac_yaml_create_definitions_node(fy_document_t document, struct yac_couple_config *couple_config)
char const * yac_couple_config_get_yaxt_exchanger_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
size_t yac_couple_config_get_num_fields(struct yac_couple_config *couple_config, size_t component_idx)
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)
const char * yac_couple_config_grid_get_output_filename(struct yac_couple_config *couple_config, const char *grid_name)
char * yac_couple_config_get_start_datetime(struct yac_couple_config *couple_config)
void yac_couple_config_set_datetime(struct yac_couple_config *couple_config, char const *start, char const *end)
char const * yac_couple_config_get_field_timestep(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
int yac_couple_config_mapping_on_source(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
int yac_couple_config_get_field_role(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
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)
enum yac_weight_file_on_existing yac_couple_config_get_weight_file_on_existing(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
char const * yac_couple_config_get_field_name(struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
size_t yac_couple_config_get_field_collection_size(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
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)
int yac_couple_config_get_use_raw_exchange(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
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)
double yac_couple_config_get_frac_mask_fallback_value(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
int yac_couple_config_get_source_lag(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
const char * yac_couple_config_field_get_metadata(struct yac_couple_config *couple_config, const char *comp_name, const char *grid_name, const char *field_name)
const char * yac_couple_config_grid_get_metadata(struct yac_couple_config *couple_config, const char *grid_name)
const char * yac_couple_config_component_get_metadata(struct yac_couple_config *couple_config, const char *comp_name)
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_tgt_mask_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_add_grid(struct yac_couple_config *couple_config, char const *name)
char const * yac_couple_config_get_grid_name(struct yac_couple_config *couple_config, size_t grid_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)
struct yac_collection_selection const * yac_couple_config_get_collection_selection(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_grid_set_output_filename(struct yac_couple_config *couple_config, char const *grid_name, const char *output_filename)
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)
int yac_couple_config_get_missing_definition_is_fatal(struct yac_couple_config *couple_config)
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_component_name(struct yac_couple_config *couple_config, size_t component_idx)
void yac_couple_config_set_missing_definition_is_fatal(struct yac_couple_config *couple_config, int missing_definition_is_fatal)
size_t yac_couple_config_get_num_grids(struct yac_couple_config *couple_config)
char const * yac_couple_config_get_field_grid_name(struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
void yac_couple_config_set_config_output_filename(struct yac_couple_config *couple_config, char const *filename, enum yac_text_filetype filetype, char const *ref, int include_definitions)
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 weight_file_on_existing, 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, char const *yaxt_exchanger_name, struct yac_collection_selection const *collection_selection, int use_raw_exchange)
char * yac_couple_config_get_end_datetime(struct yac_couple_config *couple_config)
size_t yac_couple_config_get_num_components(struct yac_couple_config *couple_config)
yac_text_filetype
@ YAC_TEXT_FILETYPE_YAML
YAML format.
@ YAC_TEXT_FILETYPE_JSON
JSON format.
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
#define YAC_RAD
yac_field_exchange_type
Definition fields.h:12
@ SOURCE
Definition fields.h:14
@ TARGET
Definition fields.h:15
@ NOTHING
Definition fields.h:13
size_t yac_collection_selection_get_collection_size(struct yac_collection_selection const *collection_selection)
Get the size of the collection selection.
size_t const * yac_collection_selection_get_indices(struct yac_collection_selection const *collection_selection)
Get explicit selection indices if non-contiguous.
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
#define YAC_INSTANCE_CONFIG_OUTPUT_REF_ENDDEF
Definition instance.h:15
#define YAC_INSTANCE_CONFIG_OUTPUT_REF_COMP
Definition instance.h:13
#define YAC_INSTANCE_CONFIG_OUTPUT_REF_SYNC
Definition instance.h:14
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
enum callback_type type
struct @34::@35 value
#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_ON_SUCCESS_DEFAULT
#define YAC_INTERP_FILE_WEIGHT_FILE_NAME_DEFAULT
yac_interp_file_on_missing_file
@ YAC_INTERP_FILE_MISSING_CONT
continue on missing file
@ YAC_INTERP_FILE_MISSING_ERROR
abort on missing file
yac_interp_file_on_success
@ YAC_INTERP_FILE_SUCCESS_CONT
@ YAC_INTERP_FILE_SUCCESS_STOP
#define YAC_INTERP_FILE_ON_MISSING_FILE_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_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_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_RBF_N_DEFAULT
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_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
char const * yac_spmap_cell_area_config_get_filename(struct yac_spmap_cell_area_config const *cell_area_config)
struct yac_spmap_cell_area_config const * yac_spmap_scale_config_get_tgt_cell_area_config(struct yac_spmap_scale_config const *scale_config)
struct yac_interp_spmap_config const * yac_spmap_overwrite_config_get_spmap_config(struct yac_spmap_overwrite_config const *overwrite_config)
double yac_spmap_cell_area_config_get_sphere_radius(struct yac_spmap_cell_area_config const *cell_area_config)
struct yac_spmap_cell_area_config * yac_spmap_cell_area_config_file_new(char const *filename, char const *varname, yac_int min_global_id)
struct yac_spmap_overwrite_config * yac_spmap_overwrite_config_new(struct yac_point_selection const *src_point_selection, struct yac_interp_spmap_config const *config)
void yac_spmap_overwrite_configs_delete(struct yac_spmap_overwrite_config **overwrite_configs)
struct yac_point_selection const * yac_spmap_overwrite_config_get_src_point_selection(struct yac_spmap_overwrite_config const *overwrite_config)
yac_int yac_spmap_cell_area_config_get_min_global_id(struct yac_spmap_cell_area_config const *cell_area_config)
enum yac_interp_spmap_cell_area_provider yac_spmap_cell_area_config_get_type(struct yac_spmap_cell_area_config const *cell_area_config)
double yac_interp_spmap_config_get_max_search_distance(struct yac_interp_spmap_config const *spmap_config)
struct yac_spmap_cell_area_config const * yac_spmap_scale_config_get_src_cell_area_config(struct yac_spmap_scale_config const *scale_config)
char const * yac_spmap_cell_area_config_get_varname(struct yac_spmap_cell_area_config const *cell_area_config)
struct yac_interp_spmap_config * yac_interp_spmap_config_new(double spread_distance, double max_search_distance, enum yac_interp_spmap_weight_type weight_type, struct yac_spmap_scale_config const *scale_config)
void yac_spmap_scale_config_delete(struct yac_spmap_scale_config *scale_config)
void yac_interp_spmap_config_delete(struct yac_interp_spmap_config *config)
struct yac_spmap_scale_config const * yac_interp_spmap_config_get_scale_config(struct yac_interp_spmap_config const *spmap_config)
double yac_interp_spmap_config_get_spread_distance(struct yac_interp_spmap_config const *spmap_config)
void yac_spmap_cell_area_config_delete(struct yac_spmap_cell_area_config *cell_area_config)
enum yac_interp_spmap_scale_type yac_spmap_scale_config_get_type(struct yac_spmap_scale_config const *scale_config)
struct yac_spmap_cell_area_config * yac_spmap_cell_area_config_yac_new(double sphere_radius)
enum yac_interp_spmap_weight_type yac_interp_spmap_config_get_weight_type(struct yac_interp_spmap_config const *spmap_config)
struct yac_spmap_scale_config * yac_spmap_scale_config_new(enum yac_interp_spmap_scale_type scale_type, struct yac_spmap_cell_area_config const *source_cell_area_config, struct yac_spmap_cell_area_config const *target_cell_area_config)
#define YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_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_CELL_AREA_CONFIG_DEFAULT
#define YAC_INTERP_SPMAP_VARNAME_DEFAULT
#define YAC_INTERP_SPMAP_FILENAME_DEFAULT
#define YAC_INTERP_SPMAP_WEIGHTED_DEFAULT
#define YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT
yac_interp_spmap_cell_area_provider
@ YAC_INTERP_SPMAP_CELL_AREA_FILE
@ YAC_INTERP_SPMAP_CELL_AREA_YAC
#define YAC_INTERP_SPMAP_SPHERE_RADIUS_DEFAULT
#define YAC_INTERP_SPMAP_SCALE_TYPE_DEFAULT
yac_interp_spmap_weight_type
@ YAC_INTERP_SPMAP_AVG
@ YAC_INTERP_SPMAP_DIST
#define YAC_INTERP_SPMAP_MIN_GLOBAL_ID_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
#define YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE
yac_weight_file_on_existing
@ YAC_WEIGHT_FILE_KEEP
keep existing weight file
@ YAC_WEIGHT_FILE_UNDEFINED
@ YAC_WEIGHT_FILE_OVERWRITE
overwrite existing weight file
@ YAC_WEIGHT_FILE_ERROR
error when weight file existis already
Defines internal basic interpolation definitions.
#define YAC_FRAC_MASK_VALUE_IS_VALID(value)
Test whether a fractional mask value is valid.
int yac_file_exists(const char *filename)
Definition utils_core.c:12
struct yac_point_selection * yac_point_selection_bnd_circle_new(double center_lon, double center_lat, double inc_angle)
void yac_point_selection_delete(struct yac_point_selection *point_select)
void yac_point_selection_bnd_circle_get_config(struct yac_point_selection const *point_selection, double *center_lon, double *center_lat, double *inc_angle)
enum yac_point_selection_type yac_point_selection_get_type(struct yac_point_selection const *point_select)
@ YAC_POINT_SELECTION_TYPE_BND_CIRCLE
@ YAC_POINT_SELECTION_TYPE_EMPTY
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xcalloc(nmemb, size)
Definition ppm_xfuncs.h:64
#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
struct debug_config_file_buffer::debug_config_file config_file[SYNC_LOC_COUNT]
char const * sync_loc_ref[SYNC_LOC_COUNT]
char const ** src_mask_names
Definition config_yaml.c:99
char const * yaxt_exchanger_name
char const * coupling_period
Definition config_yaml.c:84
enum yac_weight_file_on_existing on_existing
Definition config_yaml.c:89
char const * name
Definition config_yaml.c:88
char const * tgt_mask_name
char const * comp_name
Definition config_yaml.c:77
struct yac_interp_stack_config * interp_stack
Definition config_yaml.c:86
struct field_couple_buffer::@65 src
struct field_couple_buffer::@66 weight_file
struct field_couple_buffer::@65::@67 grid
struct yac_collection_selection * collection_selection
struct field_couple_buffer::field_couple_field_names * field_names
char const ** name
Definition config_yaml.c:79
struct field_couple_buffer::@65 tgt
enum yac_reduction_type time_reduction
Definition config_yaml.c:85
struct interp_method_parameter_value * values
struct interp_method_parameter_value::@68::@69 seq
struct interp_method_parameter_value * map_values
union interp_method_parameter_value::@68 data
struct interp_method_parameter::@70::@72 int_param
struct interp_method_parameter * sub_params
struct yac_name_type_pair const * valid_values
struct interp_method_parameter::@70::@71 enum_param
struct interp_method_parameter::@70::@75 bool_param
enum interp_method_parameter_value_type type
struct interp_method_parameter * sub_param
struct interp_method_parameter::@70::@77 seq_param
struct interp_method_parameter::@70::@76 map_param
struct interp_method_parameter::@70::@73 dble_param
struct interp_method_parameter::@70::@74 str_param
union interp_method_parameter::@70 data
interp_method_parameter_value const default_value
struct yac_spmap_scale_config * scale_config
struct yac_point_selection * src_point_selection
@ error
Definition test_cxc.c:17
int collection_size
char * yaml_filename
double * data
char const * weight_file_name
char const src_grid_name[]
char const tgt_grid_name[]
char const * name
Definition toy_scrip.c:114
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
size_t num_grids
Definition yac.c:156
void yac_cdef_calendar(int calendar)
Definition yac.c:769
int yac_cget_calendar()
Definition yac.c:786
int const YAC_CALENDAR_NOT_SET
Definition yac.c:67
#define YAC_UNREACHABLE_DEFAULT_F(format,...)
Definition yac_assert.h:50
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:30
#define YAC_UNREACHABLE_DEFAULT(msg)
Definition yac_assert.h:43