This example tests query interface routines.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mpi.h>
#include "tests.h"
#include "yaxt.h"
MPI_Init(NULL, NULL);
xt_initialize(MPI_COMM_WORLD);
int yac_id;
int global_rank, global_size;
MPI_Comm_rank(MPI_COMM_WORLD, &global_rank);
MPI_Comm_size(MPI_COMM_WORLD, &global_size);
int rank_type = global_rank%5;
if (rank_type == 0) {
} else {
char comp_name[16];
int comp_id, comp_id_instance;
sprintf(comp_name, "comp_%d", global_rank);
{
int size, rank;
if (size != 1) PUT_ERR("error in yac_cget_comp_size_c2py");
if (rank != 0) PUT_ERR("erro in yac_cget_comp_rank_c2py");
}
if (rank_type > 1) {
char comp_meta_data[64];
sprintf(comp_meta_data, "%s METADATA_C", comp_name);
sprintf(comp_meta_data, "%s METADATA_C_instance", comp_name);
char grid_name[16];
int grid_id;
sprintf(grid_name, "grid_%d_0", global_rank);
grid_name, (int[]){2, 2}, (int[]){0,0},
(double[]){0.,180.}, (double[]){-45.,45.}, &grid_id);
(
double[]){90.}, (
double[]){0.}, &
point_id);
if (rank_type > 2) {
sprintf(grid_name, "grid_%d_1", global_rank);
grid_name, (int[]){2, 2}, (int[]){0,0},
(double[]){0.,180.}, (double[]){-45.,45.}, &grid_id);
(
double[]){90.}, (
double[]){0.}, &
point_id);
char grid_meta_data[64];
sprintf(grid_meta_data, "%s METADATA_G", grid_name);
sprintf(grid_meta_data, "%s METADATA_G_instance", grid_name);
if (rank_type > 3) {
sprintf(grid_name, "grid_%d_2", global_rank);
grid_name, (int[]){2, 2}, (int[]){0,0},
(double[]){0.,180.}, (double[]){-45.,45.}, &grid_id);
(
double[]){90.}, (
double[]){0.}, &
point_id);
char grid_meta_data[64];
sprintf(grid_meta_data, "%s METADATA_G", grid_name);
sprintf(grid_meta_data, "%s METADATA_G_instance", grid_name);
char field_name[16];
int field_id, field_id_instance;
int point_ids[1];
sprintf(field_name, "field_%d_0", global_rank);
field_name, comp_id, point_ids, 1, 1, "PT5M",
field_name, comp_id_instance, point_ids, 1, 1, "PT5M",
sprintf(field_name, "field_%d_1", global_rank);
field_name, comp_id, point_ids, 1, 1, "PT5M",
field_name, comp_id_instance, point_ids, 1, 1, "PT5M",
char field_meta_data[64];
sprintf(field_meta_data, "%s METADATA_F", field_name);
comp_name, grid_name, field_name, field_meta_data);
sprintf(field_meta_data, "%s METADATA_F_instance", field_name);
yac_id, comp_name, grid_name, field_name, field_meta_data);
PUT_ERR("ERROR in yac_cget_field_id");
if (field_id_instance !=
yac_id, comp_name, grid_name, field_name))
PUT_ERR("ERROR in yac_cget_field_id_instance");
PUT_ERR("ERROR in yac_cget_component_name_from_field_id");
if (strcmp(comp_name,
PUT_ERR("ERROR in yac_cget_component_name_from_field_id");
PUT_ERR("ERROR in yac_cget_grid_name_from_field_id");
if (strcmp(grid_name,
PUT_ERR("ERROR in yac_cget_grid_name_from_field_id");
PUT_ERR("ERROR in yac_cget_field_name_from_field_id");
if (strcmp(field_name,
PUT_ERR("ERROR in yac_cget_field_name_from_field_id");
PUT_ERR("ERROR in yac_cget_timestep_from_field_id");
if (strcmp("PT5M",
PUT_ERR("ERROR in yac_cget_timestep_from_field_id");
PUT_ERR("ERROR in yac_cget_collection_size_from_field_id");
PUT_ERR("ERROR in yac_cget_collection_size_from_field_id");
PUT_ERR("ERROR in yac_cget_role_from_field_id");
PUT_ERR("ERROR in yac_cget_role_from_field_id");
}
}
}
}
int const ref_nbr_comps = 4 * ((global_size - 1) / 5) + ((global_size - 1) % 5);
PUT_ERR("ERROR in yac_cget_nbr_comps");
PUT_ERR("ERROR in yac_cget_nbr_comps_instance");
char const ** comp_names =
malloc((size_t)ref_nbr_comps * sizeof(*comp_names));
char const ** comp_names_instance =
malloc((size_t)ref_nbr_comps * sizeof(*comp_names_instance));
int const ref_nbr_grids =
3 * ((global_size - 1) / 5) +
((global_size - 1) % 5 > 2) +
2 * ((global_size - 1) % 5 > 3);
PUT_ERR("ERROR in yac_cget_nbr_grids");
PUT_ERR("ERROR in yac_cget_nbr_grids_instance");
char const ** grid_names =
malloc((size_t)ref_nbr_grids * sizeof(*grid_names));
char const ** grid_names_instance =
malloc((size_t)ref_nbr_grids * sizeof(*grid_names_instance));
for (int rank = 0; rank < global_size; ++rank) {
int idx;
int rank_type = rank % 5;
char ref_comp_name[16];
char ref_grid_names[3][32];
char ref_field_names[2][32];
sprintf(ref_comp_name, "comp_%d", rank);
for (int i = 0; i < 3; ++i)
sprintf(ref_grid_names[i], "grid_%d_%d", rank, i);
for (int i = 0; i < 2; ++i)
sprintf(ref_field_names[i], "field_%d_%d", rank, i);
if (rank_type == 0) {
for (idx = 0; idx < ref_nbr_comps; ++idx)
if (!strcmp(ref_comp_name, comp_names[idx])) break;
if (idx != ref_nbr_comps) PUT_ERR("ERROR in yac_cget_comp_names");
for (idx = 0; idx < ref_nbr_comps; ++idx)
if (!strcmp(ref_comp_name, comp_names_instance[idx])) break;
if (idx != ref_nbr_comps) PUT_ERR("ERROR in yac_cget_comp_names_instance");
for (int i = 0; i < 3; ++i) {
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[i], grid_names[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[i], grid_names_instance[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names_instance");
}
} else {
for (idx = 0; idx < ref_nbr_comps; ++idx)
if (!strcmp(ref_comp_name, comp_names[idx])) break;
if (idx == ref_nbr_comps) PUT_ERR("ERROR in yac_cget_comp_names");
for (idx = 0; idx < ref_nbr_comps; ++idx)
if (!strcmp(ref_comp_name, comp_names_instance[idx])) break;
if (idx == ref_nbr_comps) PUT_ERR("ERROR in yac_cget_comp_names_instance");
if (rank_type == 1) {
PUT_ERR("ERROR in yac_cget_component_metadata");
PUT_ERR("ERROR in yac_cget_component_metadata_instance");
for (int i = 0; i < 3; ++i) {
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[i], grid_names[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[i], grid_names_instance[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names_instance");
}
PUT_ERR("ERROR in yac_cget_comp_nbr_grids");
PUT_ERR("ERROR in yac_cget_comp_nbr_grids_instance");
} else {
char ref_comp_meta_data[64], ref_comp_meta_data_instance[64];
sprintf(ref_comp_meta_data, "%s METADATA_C", ref_comp_name);
sprintf(ref_comp_meta_data_instance, "%s METADATA_C_instance",
ref_comp_name);
if (strcmp(
ref_comp_meta_data,
PUT_ERR("ERROR in yac_cget_component_metadata");
if (strcmp(
ref_comp_meta_data_instance,
PUT_ERR("ERROR in yac_cget_component_metadata_instance");
if (rank_type == 2) {
for (int i = 0; i < 3; ++i) {
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[i], grid_names[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[i], grid_names_instance[idx])) break;
if (idx != ref_nbr_grids)
PUT_ERR("ERROR in yac_cget_grid_names_instance");
}
PUT_ERR("ERROR in yac_cget_comp_nbr_grids");
PUT_ERR("ERROR in yac_cget_comp_nbr_grids_instance");
} else {
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[0], grid_names[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[0], grid_names_instance[idx])) break;
if (idx != ref_nbr_grids)
PUT_ERR("ERROR in yac_cget_grid_names_instance");
char ref_grid_meta_data[2][64];
char ref_grid_meta_data_instance[2][64];
for (int i = 0; i < 2; ++i) {
sprintf(ref_grid_meta_data[i], "%s METADATA_G",
ref_grid_names[i+1]);
sprintf(ref_grid_meta_data_instance[i], "%s METADATA_G_instance",
ref_grid_names[i+1]);
}
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[1], grid_names[idx])) break;
if (idx == ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[1], grid_names_instance[idx])) break;
if (idx == ref_nbr_grids)
PUT_ERR("ERROR in yac_cget_grid_names_instance");
if (strcmp(
ref_grid_meta_data[0],
PUT_ERR("ERROR in yac_cget_grid_metadata");
if (strcmp(
ref_grid_meta_data_instance[0],
PUT_ERR("ERROR in yac_cget_grid_metadata_instance");
PUT_ERR("ERROR in yac_cget_nbr_fields");
yac_id, ref_comp_name, ref_grid_names[1]))
PUT_ERR("ERROR in yac_cget_nbr_fields_instance");
if (rank_type == 3) {
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[2], grid_names[idx])) break;
if (idx != ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[2], grid_names_instance[idx])) break;
if (idx != ref_nbr_grids)
PUT_ERR("ERROR in yac_cget_grid_names_instance");
PUT_ERR("ERROR in yac_cget_comp_nbr_grids");
PUT_ERR("ERROR in yac_cget_comp_nbr_grids_instance");
} else {
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[2], grid_names[idx])) break;
if (idx == ref_nbr_grids) PUT_ERR("ERROR in yac_cget_grid_names");
for (idx = 0; idx < ref_nbr_grids; ++idx)
if (!strcmp(ref_grid_names[2], grid_names_instance[idx])) break;
if (idx == ref_nbr_grids)
PUT_ERR("ERROR in yac_cget_grid_names_instance");
if (strcmp(
ref_grid_meta_data[1],
PUT_ERR("ERROR in yac_cget_grid_metadata");
if (strcmp(
ref_grid_meta_data_instance[1],
PUT_ERR("ERROR in yac_cget_grid_metadata_instance");
int const ref_nbr_fields = 2;
char const * field_names[2];
char const * field_names_instance[2];
char ref_field_meta_data[64];
char ref_field_meta_data_instance[64];
sprintf(ref_field_meta_data, "%s METADATA_F", ref_field_names[1]);
sprintf(ref_field_meta_data_instance, "%s METADATA_F_instance",
ref_field_names[1]);
ref_comp_name, ref_grid_names[2]) != ref_nbr_fields)
PUT_ERR("ERROR in yac_cget_nbr_fields");
yac_id, ref_comp_name, ref_grid_names[2]) != ref_nbr_fields)
PUT_ERR("ERROR in yac_cget_nbr_fields_instance");
ref_comp_name, ref_grid_names[2], ref_nbr_fields, field_names);
yac_id, ref_comp_name, ref_grid_names[2], ref_nbr_fields,
field_names_instance);
for (int i = 0; i < ref_nbr_fields; ++i) {
for (idx = 0; idx < ref_nbr_fields ; ++idx)
if (!strcmp(ref_field_names[i], field_names[idx])) break;
if (idx == ref_nbr_fields)
PUT_ERR("ERROR in yac_cget_field_names");
for (idx = 0; idx < ref_nbr_fields; ++idx)
if (!strcmp(
ref_field_names[i], field_names_instance[idx])) break;
if (idx == ref_nbr_fields)
PUT_ERR("ERROR in yac_cget_field_names_instance");
}
ref_comp_name, ref_grid_names[2], ref_field_names[0]))
PUT_ERR("ERROR in yac_cget_field_metadata");
yac_id, ref_comp_name, ref_grid_names[2],
ref_field_names[0]))
PUT_ERR("ERROR in yac_cget_field_metadata_instance");
if (strcmp(
ref_field_meta_data,
ref_comp_name, ref_grid_names[2], ref_field_names[1])))
PUT_ERR("ERROR in yac_cget_field_metadata");
if (strcmp(
ref_field_meta_data_instance,
yac_id, ref_comp_name, ref_grid_names[2],
ref_field_names[1])))
PUT_ERR("ERROR in yac_cget_field_metadata_instance");
PUT_ERR("ERROR in yac_cget_comp_nbr_grids");
PUT_ERR("ERROR in yac_cget_comp_nbr_grids_instance");
char const * comp_grid_name;
if (strcmp(comp_grid_name, ref_grid_names[2]))
PUT_ERR("ERROR in yac_cget_comp_grid_names");
if (strcmp(comp_grid_name, ref_grid_names[2]))
PUT_ERR("ERROR in yac_cget_comp_grid_names_instance");
ref_comp_name, ref_grid_names[2],
PUT_ERR("ERROR in yac_cget_field_role");
yac_id, ref_comp_name, ref_grid_names[2],
PUT_ERR("ERROR in yac_cget_field_role_instance");
ref_comp_name, ref_grid_names[2],
ref_field_names[0]) != 1)
PUT_ERR("ERROR in yac_cget_field_collection_size");
yac_id, ref_comp_name, ref_grid_names[2],
ref_field_names[0]) != 1)
PUT_ERR("ERROR in yac_cget_field_collection_size_instance");
if (strcmp(
ref_comp_name, ref_grid_names[2],
ref_field_names[0]), "PT5M"))
PUT_ERR("ERROR in yac_cget_field_timestep");
if (strcmp(
yac_id, ref_comp_name, ref_grid_names[2],
ref_field_names[0]), "PT5M"))
PUT_ERR("ERROR in yac_cget_field_timestep");
}
}
}
}
}
free(grid_names_instance);
free(grid_names);
free(comp_names_instance);
free(comp_names);
xt_finalize();
MPI_Finalize();
return TEST_EXIT_CODE;
}
int main(int argc, char **argv)
void yac_cget_grid_names(int nbr_grids, const char **grid_names)
const char * yac_cget_field_metadata_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
int yac_cget_role_from_field_id(int field_id)
int yac_cget_nbr_grids_instance(int yac_instance_id)
const char * yac_cget_grid_metadata_instance(int yac_instance_id, const char *grid_name)
int const YAC_LOCATION_CELL
void yac_cdef_grid_metadata(const char *grid_name, const char *metadata)
void yac_cget_grid_names_instance(int yac_instance_id, int nbr_grids, const char **grid_names)
void yac_cdef_component_metadata(const char *comp_name, const char *metadata)
void yac_cget_comp_rank_c2py(int comp_id, int *rank)
int yac_cget_field_role(const char *comp_name, const char *grid_name, const char *field_name)
void yac_cget_comp_size_c2py(int comp_id, int *size)
int yac_cget_field_id_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
int yac_cget_comp_nbr_grids_instance(int yac_instance_id, const char *comp_name)
const char * yac_cget_timestep_from_field_id(int field_id)
int yac_cget_nbr_fields(const char *comp_name, const char *grid_name)
void yac_csync_def_instance(int yac_instance_id)
void yac_cfinalize_instance(int yac_instance_id)
const char * yac_cget_field_name_from_field_id(int field_id)
int yac_cget_nbr_comps_instance(int yac_instance_id)
int yac_cget_nbr_fields_instance(int yac_instance_id, const char *comp_name, const char *grid_name)
void yac_cdef_grid_metadata_instance(int yac_instance_id, const char *grid_name, const char *metadata)
const char * yac_cget_component_metadata_instance(int yac_instance_id, const char *comp_name)
const char * yac_cget_field_timestep_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
void yac_cdef_comp_instance(int yac_instance_id, char const *comp_name, int *comp_id)
int yac_cget_field_id(const char *comp_name, const char *grid_name, const char *field_name)
const char * yac_cget_grid_name_from_field_id(int field_id)
int yac_cget_collection_size_from_field_id(int field_id)
void yac_cdef_grid_reg2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
int const YAC_EXCHANGE_TYPE_NONE
void yac_cdef_points_reg2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
const char * yac_cget_grid_metadata(const char *grid_name)
const char * yac_cget_component_name_from_field_id(int field_id)
int yac_cget_field_collection_size(const char *comp_name, const char *grid_name, const char *field_name)
void yac_cdef_component_metadata_instance(int yac_instance_id, const char *comp_name, const char *metadata)
void yac_cdef_calendar(int calendar)
void yac_cget_comp_names(int nbr_comps, const char **comp_names)
void yac_cdef_comps(char const **comp_names, int num_comps, int *comp_ids)
const char * yac_cget_field_metadata(const char *comp_name, const char *grid_name, const char *field_name)
int const YAC_PROLEPTIC_GREGORIAN
void yac_cget_comp_grid_names_instance(int yac_instance_id, const char *comp_name, int nbr_grids, const char **grid_names)
int yac_cget_comp_nbr_grids(const char *comp_name)
int const YAC_TIME_UNIT_ISO_FORMAT
int yac_cget_field_role_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
int yac_cget_field_collection_size_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
void yac_cinit_instance(int *yac_instance_id)
void yac_cdef_comp(char const *comp_name, int *comp_id)
void yac_cdef_field(char const *name, int const comp_id, int const *point_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
int yac_cget_nbr_comps(void)
void yac_cdef_field_metadata_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name, const char *metadata)
void yac_cget_comp_grid_names(const char *comp_name, int nbr_grids, const char **grid_names)
void yac_cget_field_names_instance(int yac_instance_id, const char *comp_name, const char *grid_name, int nbr_fields, const char **field_names)
void yac_cdef_comps_instance(int yac_instance_id, char const **comp_names, int num_comps, int *comp_ids)
void yac_cget_comp_names_instance(int yac_instance_id, int nbr_comps, const char **comp_names)
void yac_cdef_field_metadata(const char *comp_name, const char *grid_name, const char *field_name, const char *metadata)
const char * yac_cget_component_metadata(const char *comp_name)
const char * yac_cget_field_timestep(const char *comp_name, const char *grid_name, const char *field_name)
void yac_cget_field_names(const char *comp_name, const char *grid_name, int nbr_fields, const char **field_names)