#include <stdlib.h>
#include <unistd.h>
#include <mpi.h>
#include <yaxt.h>
#include <netcdf.h>
#include <string.h>
#include "tests.h"
#include "test_common.h"
#include "weight_file_common.h"
static void compute_weights_callback(
double const tgt_coords[3], int src_cell_id, size_t src_cell_idx,
int const ** global_results_points, double ** result_weights,
int main(
int argc,
char** argv) {
MPI_Init(NULL, NULL);
xt_initialize(MPI_COMM_WORLD);
int comm_rank, comm_size;
MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
set_even_io_rank_list(MPI_COMM_WORLD);
if (argc != 2) {
PUT_ERR("ERROR: missing grid file directory");
xt_finalize();
MPI_Finalize();
return TEST_EXIT_CODE;
}
char * filenames[2];
char * grid_filenames[] ={"icon_grid_0030_R02B03_G.nc", "icon_grid_0043_R02B04_G.nc"};
for (int i = 0; i < 2; ++i)
filenames[i] =
strcat(
strcpy(
malloc(strlen(argv[1]) + strlen(grid_filenames[i]) + 2), argv[1]),
grid_filenames[i]);
for (int i = 0; i < 2; ++i)
grid_data[i] =
filenames[i], MPI_COMM_WORLD);
size_t num_src_fields = sizeof(src_fields) / sizeof(src_fields[0]);
for (int i = 0; i < 2; ++i) {
free(filenames[i]);
}
{
char const * weight_file_empty =
"test_interp_method_parallel_weights_empty.nc";
char const * weight_file_fixed =
"test_interp_method_parallel_weights_fixed.nc";
char const * src_grid_name = "src_grid";
char const * tgt_grid_name = "tgt_grid";
if (comm_rank == 0) {
{
int * tgt_indices = NULL;
int * src_indices = NULL;
double * weights = NULL;
size_t num_links = 0;
enum {
NUM_SRC_FIELDS = sizeof(src_locations) / sizeof(src_locations[0])};
int num_links_per_field[NUM_SRC_FIELDS] = {num_links};
int * tgt_id_fixed = NULL;
size_t num_fixed_tgt = 0;
double * fixed_values = NULL;
int * num_tgt_per_fixed_value = NULL;
size_t num_fixed_values = 0;
write_weight_file(
weight_file_empty, src_indices, tgt_indices, weights, num_links,
src_locations, NUM_SRC_FIELDS, num_links_per_field, tgt_id_fixed,
num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
num_fixed_values, tgt_location, src_grid_name, tgt_grid_name);
}
{
int * tgt_indices = NULL;
int * src_indices = NULL;
double * weights = NULL;
size_t num_links = 0;
enum {
NUM_SRC_FIELDS = sizeof(src_locations) / sizeof(src_locations[0])};
int num_links_per_field[NUM_SRC_FIELDS] = {num_links};
int tgt_id_fixed[] = {0, 1, 2, 3};
size_t num_fixed_tgt = 4;
double fixed_values[] = {999.0};
int num_tgt_per_fixed_value[] = {4};
size_t num_fixed_values = 1;
write_weight_file(
weight_file_fixed, src_indices, tgt_indices, weights, num_links,
src_locations, NUM_SRC_FIELDS, num_links_per_field, tgt_id_fixed,
num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
num_fixed_values, tgt_location, src_grid_name, tgt_grid_name);
}
}
double coordinates_x[] = {0.0, 1.0, 2.0};
double coordinates_y[] = {0.0, 1.0, 2.0};
size_t num_vertices[2] = {3,3};
int cyclic[2] = {0,0};
src_grid_name, num_vertices, cyclic, coordinates_x, coordinates_y);
tgt_grid_name, num_vertices, cyclic, coordinates_x, coordinates_y);
double cell_coords[4][3];
double cell_coords_x[] = {0.5, 1.5};
double cell_coords_y[] = {0.5, 1.5};
for (int i = 0, k = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j, ++k)
LLtoXYZ_deg(cell_coords_x[j], cell_coords_y[i], cell_coords[k]);
size_t num_src_fields = sizeof(src_fields) / sizeof(src_fields[0]);
.type =
PUT_ERR(
"error in handling of interpolation_complete argument by do_search");
if (comm_rank == 0) {
unlink(weight_file_empty);
unlink(weight_file_fixed);
}
}
xt_finalize();
MPI_Finalize();
return TEST_EXIT_CODE;
}
static void compute_weights_callback(
double const tgt_coords[3], int src_cell_id, size_t src_cell_idx,
int const ** global_results_points, double ** result_weights,
UNUSED(global_results_points);
PUT_ERR("ERROR: in handling interpolation_complete in do_search_callback");
}
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
struct yac_basic_grid * yac_basic_grid_reg_2d_deg_new(char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
size_t yac_basic_grid_add_coordinates(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
void yac_basic_grid_delete(struct yac_basic_grid *grid)
int main(int argc, char **argv)
void yac_dist_grid_pair_delete(struct yac_dist_grid_pair *grid_pair)
struct yac_dist_grid_pair * yac_dist_grid_pair_new(struct yac_basic_grid *grid_a, struct yac_basic_grid *grid_b, MPI_Comm comm)
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
void yac_interp_grid_delete(struct yac_interp_grid *interp_grid)
struct yac_interp_grid * yac_interp_grid_new(struct yac_dist_grid_pair *grid_pair, char const *src_grid_name, char const *tgt_grid_name, size_t num_src_fields, struct yac_interp_field const *src_fields, struct yac_interp_field const tgt_field)
void yac_interp_method_delete(struct interp_method **method)
struct yac_interp_weights * yac_interp_method_do_search(struct interp_method **method, struct yac_interp_grid *interp_grid)
struct interp_method * yac_interp_method_avg_new(enum yac_interp_avg_weight_type weight_type, int partial_coverage)
#define YAC_INTERP_AVG_PARTIAL_COVERAGE_DEFAULT
yac_interp_avg_weight_type
#define YAC_INTERP_AVG_WEIGHT_TYPE_DEFAULT
struct interp_method * yac_interp_method_callback_new(yac_func_compute_weights compute_weights_callback, void *user_data)
struct interp_method * yac_interp_method_check_new(func_constructor constructor_callback, void *constructor_user_data, func_do_search do_search_callback, void *do_search_user_data)
struct interp_method * yac_interp_method_conserv_new(int order, int enforced_conserv, int partial_coverage, enum yac_interp_method_conserv_normalisation normalisation)
#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
struct interp_method * yac_interp_method_creep_new(int creep_distance)
#define YAC_INTERP_CREEP_DISTANCE_DEFAULT
struct interp_method * yac_interp_method_file_new(char const *weight_file_name, enum yac_interp_file_on_missing_file on_missing_file, enum yac_interp_file_on_success on_success)
@ YAC_INTERP_FILE_MISSING_ERROR
abort on missing file
@ YAC_INTERP_FILE_SUCCESS_CONT
@ YAC_INTERP_FILE_SUCCESS_STOP
struct interp_method * yac_interp_method_fixed_new(double value)
#define YAC_INTERP_FIXED_VALUE_DEFAULT
struct interp_method * yac_interp_method_hcsbb_new()
struct interp_method * yac_interp_method_ncc_new(enum yac_interp_ncc_weight_type weight_type, int partial_coverage)
#define YAC_INTERP_NCC_PARTIAL_COVERAGE_DEFAULT
#define YAC_INTERP_NCC_WEIGHT_TYPE_DEFAULT
yac_interp_ncc_weight_type
struct interp_method * yac_interp_method_nnn_new(struct yac_nnn_config config)
#define YAC_INTERP_NNN_WEIGHTED_DEFAULT
yac_interp_nnn_weight_type
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT
#define YAC_INTERP_NNN_N_DEFAULT
struct interp_method * yac_interp_method_spmap_new(double spread_distance, double max_search_distance, enum yac_interp_spmap_weight_type weight_type, struct yac_spmap_scale_config scale_config)
#define YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_SPMAP_SCALE_CONFIG_DEFAULT
#define YAC_INTERP_SPMAP_WEIGHTED_DEFAULT
#define YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT
void yac_interp_weights_delete(struct yac_interp_weights *weights)
struct yac_interpolation * yac_interp_weights_get_interpolation(struct yac_interp_weights *weights, enum yac_interp_weights_reorder_type reorder, size_t collection_size, double frac_mask_fallback_value, double scaling_factor, double scaling_summand, char const *yaxt_exchanger_name)
size_t yac_interp_weights_get_interp_count(struct yac_interp_weights *weights)
@ YAC_MAPPING_ON_TGT
weights will be applied at target processes
@ YAC_MAPPING_ON_SRC
weights will be applied at source processes
void yac_interpolation_delete(struct yac_interpolation *interp)
double const YAC_FRAC_MASK_NO_VALUE
struct yac_basic_grid_data yac_read_icon_basic_grid_data_parallel(const char *filename, MPI_Comm comm)
enum yac_location location
struct yac_interp_field tgt_field
struct yac_dist_grid_pair * grid_pair
struct yac_interp_field src_fields[]
struct yac_basic_grid ** grids