YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_read_mpiom.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#include <stdlib.h>
6#include <string.h>
7#include <unistd.h>
8
9#include "tests.h"
10#include "test_common.h"
11#include "grid_file_common.h"
12#include "read_mpiom_grid.h"
13#include "grid2vtk.h"
14#include "io_utils.h"
15
21int main(int argc, char** argv) {
22
23 if (argc != 2) {
24 PUT_ERR("ERROR: missing grid file directory");
25 return TEST_EXIT_CODE;
26 }
27
28 char * grid_filename =
29 strcat(
30 strcpy(
31 malloc(strlen(argv[1]) + 32), argv[1]), "GR30_lsm.nc");
32
33 if (!yac_file_exists(grid_filename)) return EXIT_SKIP_TEST;
34
35 {
36 struct yac_basic_grid_data mpiom_grid =
37 yac_read_mpiom_basic_grid_data(grid_filename);
38
39 if (mpiom_grid.num_cells != 12120)
40 PUT_ERR("wrong number of grid cells");
41
42// #define WRITE_VTK_GRID_FILE
43#ifdef WRITE_VTK_GRID_FILE
44 yac_write_basic_grid_data_to_file(&mpiom_grid, "mpiom");
45#endif // WRITE_VTK_GRID_FILE
46
47 yac_basic_grid_data_free(mpiom_grid);
48 }
49
50 {
51 struct yac_basic_grid * mpiom_grid =
52 yac_read_mpiom_basic_grid(grid_filename, "mpiom");
53
54
55 if (yac_basic_grid_get_data_size(mpiom_grid, YAC_LOC_CELL) != 12120)
56 PUT_ERR("wrong number of grid cells");
57
58 yac_basic_grid_delete(mpiom_grid);
59 }
60
61 free(grid_filename);
62
63 { // grids whose longitudes are outside of [0;360], which have to be
64 // shifted into that range before duplicated coordinates can be
65 // detected; the first one additionally uses a four dimensional mask
66 // variable
67
68 char * dummy_grid_filename = "test_read_mpiom_dummy.nc";
69 enum {NUM_X = 20, NUM_Y = 10};
70
71 struct {
72 double lon_range[2];
73 int mask_ndims;
74 } configs[] = {{.lon_range = {-360.0, 0.0}, .mask_ndims = 4},
75 {.lon_range = {360.0, 720.0}, .mask_ndims = 3}};
76 enum {NUM_CONFIGS = sizeof(configs) / sizeof(configs[0])};
77
78 for (int i = 0; i < NUM_CONFIGS; ++i) {
79
81 dummy_grid_filename, NUM_X, NUM_Y,
82 configs[i].lon_range, (double[]){-80.0, 80.0}, configs[i].mask_ndims);
83
84 struct yac_basic_grid_data mpiom_grid =
85 yac_read_mpiom_basic_grid_data(dummy_grid_filename);
86
87 if (mpiom_grid.num_cells != NUM_X * NUM_Y)
88 PUT_ERR("wrong number of grid cells");
89
90 yac_basic_grid_data_free(mpiom_grid);
91
92 unlink(dummy_grid_filename);
93 }
94 }
95
96 return TEST_EXIT_CODE;
97}
98
size_t yac_basic_grid_get_data_size(struct yac_basic_grid *grid, enum yac_location location)
Definition basic_grid.c:145
void yac_basic_grid_delete(struct yac_basic_grid *grid)
Definition basic_grid.c:77
void yac_basic_grid_data_free(struct yac_basic_grid_data grid)
void yac_write_basic_grid_data_to_file(struct yac_basic_grid_data *grid, char const *name)
Definition grid2vtk.c:54
void write_dummy_mpiom_grid_file(char *grid_filename, size_t num_x, size_t num_y, double lon_range[2], double lat_range[2], int mask_ndims)
int yac_file_exists(const char *filename)
Check whether a file exists.
Definition io_utils.c:394
@ YAC_LOC_CELL
Definition location.h:14
struct yac_basic_grid * yac_read_mpiom_basic_grid(char const *filename, char const *gridname)
struct yac_basic_grid_data yac_read_mpiom_basic_grid_data(char const *filename)
#define TEST_EXIT_CODE
Definition tests.h:15
#define PUT_ERR(string)
Definition tests.h:10
#define EXIT_SKIP_TEST
Definition tests.h:16