#include <netcdf.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tests.h"
#include "test_common.h"
#define DUMMY_GRID_NAME ("dummy_grid")
#ifndef HAVE_OASIS_FILES
static void write_dummy_grid_file(
char * grid_name, char * grid_filename, char * mask_filename);
#endif
#ifdef HAVE_OASIS_FILES
char * grid_filename = "../examples/OASIS-grid/grids.nc";
char * mask_filename = "../examples/OASIS-grid/masks_no_atm.nc";
#else
char * grid_filename = "test_read_scrip_grids.nc";
char * mask_filename = "test_read_scrip_masks.nc";
write_dummy_grid_file(DUMMY_GRID_NAME, grid_filename, mask_filename);
#endif
int valid_mask_value = 0;
{
#ifdef HAVE_OASIS_FILES
char * gridname = "sse7";
#else
char * gridname = DUMMY_GRID_NAME;
#endif
size_t * duplicated_cell_idx = NULL;
yac_int * orig_cell_global_ids = NULL;
size_t nbr_duplicated_cells = 0;
size_t cell_coord_idx;
grid_filename, mask_filename, gridname, valid_mask_value, gridname,
0, &cell_coord_idx, &duplicated_cell_idx, &orig_cell_global_ids,
&nbr_duplicated_cells);
free(duplicated_cell_idx);
free(orig_cell_global_ids);
#ifdef WRITE_VTK_GRID_FILE
#else
char const * vtk_gridname = "test_read_scrip_grid";
char const * vtk_filename = "test_read_scrip_grid.vtk";
PUT_ERR("ERROR in yac_write_basic_grid_to_file");
unlink(vtk_filename);
#endif
}
{
#ifdef HAVE_OASIS_FILES
char * gridname = "torc";
#else
char * gridname = DUMMY_GRID_NAME;
#endif
grid_filename, mask_filename, gridname, valid_mask_value, gridname,
1, NULL, NULL, NULL, NULL);
#ifdef WRITE_VTK_GRID_FILE
char vtk_gridname[64];
scrip_grid, strcat(strcpy(vtk_gridname, gridname), "_ll"));
#endif
}
#ifndef HAVE_OASIS_FILES
unlink(grid_filename);
unlink(mask_filename);
#endif
return TEST_EXIT_CODE;
}
#ifndef HAVE_OASIS_FILES
static void write_dummy_grid_file(
char * grid_name, char * grid_filename, char * mask_filename) {
enum {NUM_LAT = 10, NUM_LON = 361};
{
int ncid;
char crn_dim_name[128];
char x_dim_name[128];
char y_dim_name[128];
sprintf(crn_dim_name, "crn_%s", grid_name);
sprintf(x_dim_name, "x_%s", grid_name);
sprintf(y_dim_name, "y_%s", grid_name);
int dim_crn_id;
int dim_x_id;
int dim_y_id;
char cla_var_name[128];
char clo_var_name[128];
char lat_var_name[128];
char lon_var_name[128];
sprintf(cla_var_name, "%s.cla", grid_name);
sprintf(clo_var_name, "%s.clo", grid_name);
sprintf(lat_var_name, "%s.lat", grid_name);
sprintf(lon_var_name, "%s.lon", grid_name);
int corner_dim_ids[3] = {dim_crn_id, dim_y_id, dim_x_id};
int cell_dim_ids[2] = {dim_y_id, dim_x_id};
int var_cla_id;
int var_clo_id;
int var_lat_id;
int var_lon_id;
char degree[] = "degree";
char title[] = "This is a reg lon-lat dummy grid";
nc_def_var(
ncid, cla_var_name, NC_DOUBLE, 3, corner_dim_ids, &var_cla_id));
nc_put_att_text(ncid, var_cla_id, "units", strlen(degree), degree));
nc_put_att_text(ncid, var_cla_id, "title", strlen(title), title));
nc_def_var(
ncid, clo_var_name, NC_DOUBLE, 3, corner_dim_ids, &var_clo_id));
nc_put_att_text(ncid, var_clo_id, "units", strlen(degree), degree));
nc_put_att_text(ncid, var_clo_id, "title", strlen(title), title));
nc_def_var(
ncid, lat_var_name, NC_DOUBLE, 2, cell_dim_ids, &var_lat_id));
nc_put_att_text(ncid, var_lat_id, "units", strlen(degree), degree));
nc_put_att_text(ncid, var_lat_id, "title", strlen(title), title));
nc_def_var(
ncid, lon_var_name, NC_DOUBLE, 2, cell_dim_ids, &var_lon_id));
nc_put_att_text(ncid, var_lon_id, "units", strlen(degree), degree));
nc_put_att_text(ncid, var_lon_id, "title", strlen(title), title));
double cla[4][NUM_LAT][NUM_LON];
double clo[4][NUM_LAT][NUM_LON];
double lat[NUM_LAT][NUM_LON];
double lon[NUM_LAT][NUM_LON];
for (int i = 0; i < NUM_LON; ++i) {
for (int j = 0; j < NUM_LAT; ++j) {
cla[0][j][i] = (double)(j+0-90);
cla[1][j][i] = (double)(j+0-90);
cla[2][j][i] = (double)(j+1-90);
cla[3][j][i] = (double)(j+1-90);
clo[0][j][i] = (double)(i+0);
clo[1][j][i] = (double)(i+1);
clo[2][j][i] = (double)(i+1);
clo[3][j][i] = (double)(i+0);
lat[j][i] = 0.5 + (double)(j-90);
lon[j][i] = 0.5 + (double)i;
}
}
}
{
int ncid;
char x_dim_name[128];
char y_dim_name[128];
sprintf(x_dim_name, "x_%s", grid_name);
sprintf(y_dim_name, "y_%s", grid_name);
int dim_x_id;
int dim_y_id;
char frc_var_name[128];
char msk_var_name[128];
sprintf(frc_var_name, "%s.frc", grid_name);
sprintf(msk_var_name, "%s.msk", grid_name);
int dim_ids[2] = {dim_y_id, dim_x_id};
int var_frc_id;
int var_msk_id;
char adim[] = "adim";
nc_def_var(
ncid, frc_var_name, NC_DOUBLE, 2, dim_ids, &var_frc_id));
nc_put_att_text(ncid, var_frc_id, "units", strlen(adim), adim));
nc_def_var(
ncid, msk_var_name, NC_INT, 2, dim_ids, &var_msk_id));
nc_put_att_text(ncid, var_msk_id, "units", strlen(adim), adim));
double frc[NUM_LAT][NUM_LON];
int msk[NUM_LAT][NUM_LON];
for (int i = 0; i < NUM_LON; ++i) {
for (int j = 0; j < NUM_LAT; ++j) {
frc[j][i] = 1;
msk[j][i] = 0;
}
}
}
}
#endif
void yac_basic_grid_delete(struct yac_basic_grid *grid)
int main(int argc, char **argv)
void yac_write_basic_grid_to_file(struct yac_basic_grid *grid, char const *name)
void yac_nc_create(const char *path, int cmode, int *ncidp)
int yac_file_exists(const char *filename)
#define YAC_HANDLE_ERROR(exp)
struct yac_basic_grid * yac_read_scrip_basic_grid(char const *grid_filename, char const *mask_filename, char const *grid_name, int valid_mask_value, char const *name, int use_ll_edges, size_t *cell_coord_idx, size_t **duplicated_cell_idx, yac_int **orig_cell_global_ids, size_t *nbr_duplicated_cells)