YetAnotherCoupler 3.5.2
Loading...
Searching...
No Matches
read_scrip_grid.c File Reference
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <mpi.h>
#include "read_scrip_grid.h"
#include "geometry.h"
#include "utils_common.h"
#include "io_utils.h"
#include "yac_mpi_internal.h"
#include <netcdf.h>
Include dependency graph for read_scrip_grid.c:

Go to the source code of this file.

Data Structures

struct  point_with_index
 
struct  cell_vertices_with_index
 
struct  cell_vertex_ids_with_index
 

Functions

static void remove_duplicated_vertices (double **vertex_lon, double **vertex_lat, size_t *nbr_vertices, int *old_to_new_id)
 
static void remove_duplicated_vertices_parallel (double **vertex_lon, double **vertex_lat, size_t *nbr_vertices, int *old_to_new_id, yac_int **vertex_ids, MPI_Comm comm)
 
static void detect_duplicated_cells (int *cell_to_vertex, int *num_vertices_per_cell, int *cell_mask, size_t nbr_cells, size_t **duplicated_cell_idx, size_t **orig_cell_idx, size_t *nbr_duplicated_cells)
 
static void detect_duplicated_cells_parallel (int *cell_to_vertex, int *num_vertices_per_cell, int *cell_mask, yac_int *cell_ids, size_t num_cells, yac_int *vertex_ids, MPI_Comm comm, size_t **duplicated_cell_idx, yac_int **orig_cell_ids, size_t *num_duplicated_cells_)
 
static int compare_int (const void *a, const void *b)
 
static int compare_yac_int (const void *a, const void *b)
 
static int compare_cell_vertex_ids_with_index_ids (const void *a_, const void *b_)
 
static int compare_cell_vertex_ids_with_index_ids_id (const void *a_, const void *b_)
 
static int compare_point_with_index_coord_id (const void *a_, const void *b_)
 
static int compare_point_with_index_coord (const void *a_, const void *b_)
 
static int compare_point_with_index_rank (const void *a_, const void *b_)
 
static int compare_point_with_index_i (const void *a_, const void *b_)
 
static void yac_read_scrip_basic_grid_information (const char *filename, const char *grid_name, size_t cell_mask_size, int *cell_mask, size_t *num_vertices_, size_t *num_cells_, int **num_vertices_per_cell_, int **cell_to_vertex_, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, size_t **duplicated_cell_idx_, size_t **orig_cell_idx_, size_t *nbr_duplicated_cells_)
 
static void yac_read_part_scrip_basic_grid_information (const char *filename, const char *grid_name, size_t cell_mask_size, int *cell_mask, size_t *num_vertices_, size_t *num_cells_, int **num_vertices_per_cell_, int **cell_to_vertex_, double **x_vertices_, double **y_vertices_, yac_int **vertex_ids_, double **x_cells_, double **y_cells_, yac_int **cell_ids_, size_t **duplicated_cell_idx_, yac_int **orig_cell_ids_, size_t *nbr_duplicated_cells_, int io_rank_idx, int num_io_ranks, MPI_Comm comm)
 
static void yac_read_scrip_mask_information (const char *filename, const char *grid_name, size_t *num_cells_, int **cell_mask)
 
static void yac_read_part_scrip_mask_information (const char *filename, const char *grid_name, size_t *num_cells_, int **cell_mask, int io_rank_idx, int num_io_ranks)
 
void yac_read_scrip_grid_information (char const *grid_filename, char const *mask_filename, char const *grid_name, int valid_mask_value, size_t *num_vertices, size_t *num_cells, int **num_vertices_per_cell, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, int **cell_to_vertex, int **cell_core_mask, size_t **duplicated_cell_idx, size_t **orig_cell_idx, size_t *nbr_duplicated_cells)
 
static void yac_read_part_scrip_grid_information (char const *grid_filename, char const *mask_filename, MPI_Comm comm, char const *grid_name, int valid_mask_value, size_t *num_vertices, size_t *num_cells, int **num_vertices_per_cell, double **x_vertices, double **y_vertices, yac_int **vertex_ids, double **x_cells, double **y_cells, yac_int **cell_ids, int **cell_to_vertex, int **cell_core_mask, size_t **duplicated_cell_idx, yac_int **orig_cell_ids, size_t *nbr_duplicated_cells)
 
static struct yac_basic_grid_data yac_read_scrip_basic_grid_data_ (char const *grid_filename, char const *mask_filename, MPI_Comm comm, char const *grid_name, int valid_mask_value, int use_ll, double **x_cells, double **y_cells, size_t **duplicated_cell_idx, yac_int **orig_cell_global_ids, size_t *nbr_duplicated_cells)
 
struct yac_basic_grid_data yac_read_scrip_basic_grid_data (char const *grid_filename, char const *mask_filename, char const *grid_name, int valid_mask_value, int use_ll_edges)
 
struct yac_basic_gridyac_read_scrip_basic_grid_parallel (char const *grid_filename, char const *mask_filename, MPI_Comm comm, 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)
 
struct yac_basic_gridyac_read_scrip_basic_grid_parallel_f2c (char const *grid_filename, char const *mask_filename, MPI_Fint comm, 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)
 
struct yac_basic_gridyac_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)
 
static int compare_cell_vertices_with_index (const void *a, const void *b)
 
static struct point_with_indexremove_duplicated_vertices_ (double **vertex_lon, double **vertex_lat, yac_int **vertex_ids, size_t *nbr_vertices, int *old_to_new_id)
 
unsigned long djb2_hash (unsigned char *values, size_t count)
 
static int compute_bucket (void *data, size_t data_size, int comm_size)
 
static MPI_Datatype get_point_with_index_mpi_datatype (MPI_Comm comm)
 
static MPI_Datatype get_cell_to_vertex_ids_mpi_datatype (MPI_Comm comm, size_t count)
 

Function Documentation

◆ compare_cell_vertex_ids_with_index_ids()

static int compare_cell_vertex_ids_with_index_ids ( const void * a_,
const void * b_ )
inlinestatic

Definition at line 76 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_cell_vertex_ids_with_index_ids_id()

static int compare_cell_vertex_ids_with_index_ids_id ( const void * a_,
const void * b_ )
inlinestatic

Definition at line 96 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_cell_vertices_with_index()

static int compare_cell_vertices_with_index ( const void * a,
const void * b )
inlinestatic

Definition at line 959 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_int()

static int compare_int ( const void * a,
const void * b )
inlinestatic

Definition at line 65 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_point_with_index_coord()

static int compare_point_with_index_coord ( const void * a_,
const void * b_ )
inlinestatic

Definition at line 123 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_point_with_index_coord_id()

static int compare_point_with_index_coord_id ( const void * a_,
const void * b_ )
inlinestatic

Definition at line 110 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_point_with_index_i()

static int compare_point_with_index_i ( const void * a_,
const void * b_ )
inlinestatic

Definition at line 143 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_point_with_index_rank()

static int compare_point_with_index_rank ( const void * a_,
const void * b_ )
inlinestatic

Definition at line 134 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compare_yac_int()

static int compare_yac_int ( const void * a,
const void * b )
inlinestatic

Definition at line 70 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ compute_bucket()

static int compute_bucket ( void * data,
size_t data_size,
int comm_size )
static

Definition at line 1061 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect_duplicated_cells()

static void detect_duplicated_cells ( int * cell_to_vertex,
int * num_vertices_per_cell,
int * cell_mask,
size_t nbr_cells,
size_t ** duplicated_cell_idx,
size_t ** orig_cell_idx,
size_t * nbr_duplicated_cells )
static

Definition at line 1190 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect_duplicated_cells_parallel()

static void detect_duplicated_cells_parallel ( int * cell_to_vertex,
int * num_vertices_per_cell,
int * cell_mask,
yac_int * cell_ids,
size_t num_cells,
yac_int * vertex_ids,
MPI_Comm comm,
size_t ** duplicated_cell_idx,
yac_int ** orig_cell_ids,
size_t * num_duplicated_cells_ )
static

Definition at line 1256 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ djb2_hash()

unsigned long djb2_hash ( unsigned char * values,
size_t count )

Definition at line 1049 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ get_cell_to_vertex_ids_mpi_datatype()

static MPI_Datatype get_cell_to_vertex_ids_mpi_datatype ( MPI_Comm comm,
size_t count )
static

Definition at line 1246 of file read_scrip_grid.c.

Here is the caller graph for this function:

◆ get_point_with_index_mpi_datatype()

static MPI_Datatype get_point_with_index_mpi_datatype ( MPI_Comm comm)
static

Definition at line 1068 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_duplicated_vertices()

static void remove_duplicated_vertices ( double ** vertex_lon,
double ** vertex_lat,
size_t * nbr_vertices,
int * old_to_new_id )
static

Definition at line 1039 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_duplicated_vertices_()

static struct point_with_index * remove_duplicated_vertices_ ( double ** vertex_lon,
double ** vertex_lat,
yac_int ** vertex_ids,
size_t * nbr_vertices,
int * old_to_new_id )
static

Definition at line 972 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_duplicated_vertices_parallel()

static void remove_duplicated_vertices_parallel ( double ** vertex_lon,
double ** vertex_lat,
size_t * nbr_vertices,
int * old_to_new_id,
yac_int ** vertex_ids,
MPI_Comm comm )
static

Definition at line 1092 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_part_scrip_basic_grid_information()

static void yac_read_part_scrip_basic_grid_information ( const char * filename,
const char * grid_name,
size_t cell_mask_size,
int * cell_mask,
size_t * num_vertices_,
size_t * num_cells_,
int ** num_vertices_per_cell_,
int ** cell_to_vertex_,
double ** x_vertices_,
double ** y_vertices_,
yac_int ** vertex_ids_,
double ** x_cells_,
double ** y_cells_,
yac_int ** cell_ids_,
size_t ** duplicated_cell_idx_,
yac_int ** orig_cell_ids_,
size_t * nbr_duplicated_cells_,
int io_rank_idx,
int num_io_ranks,
MPI_Comm comm )
static

Definition at line 326 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_part_scrip_grid_information()

static void yac_read_part_scrip_grid_information ( char const * grid_filename,
char const * mask_filename,
MPI_Comm comm,
char const * grid_name,
int valid_mask_value,
size_t * num_vertices,
size_t * num_cells,
int ** num_vertices_per_cell,
double ** x_vertices,
double ** y_vertices,
yac_int ** vertex_ids,
double ** x_cells,
double ** y_cells,
yac_int ** cell_ids,
int ** cell_to_vertex,
int ** cell_core_mask,
size_t ** duplicated_cell_idx,
yac_int ** orig_cell_ids,
size_t * nbr_duplicated_cells )
static

Definition at line 704 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_part_scrip_mask_information()

static void yac_read_part_scrip_mask_information ( const char * filename,
const char * grid_name,
size_t * num_cells_,
int ** cell_mask,
int io_rank_idx,
int num_io_ranks )
static

Definition at line 590 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_scrip_basic_grid()

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 )

reads in grid data from a SCRIP formated file

Parameters
[in]grid_filenamename of the SCRIP grid netcdf file
[in]mask_filenamename of the SCRIP mask netcdf file
[in]grid_namename of the grid in the file
[in]valid_mask_valuevalue that marks cells as valid
[in]namename of the grid
[in]use_ll_edgesif possible represent all edges using lon/lat circles
[out]cell_coord_idxindex at which cell centers are registerd in the basic grid
[out]duplicated_cell_idxindices of all duplicated cells
[out]orig_cell_global_idsglobal ids of the original cells
[out]nbr_duplicated_cellsnumber of duplicated cells
Returns
basic grid
Remarks
This routine will allocate the arrays duplicated_cell_idx and orig_cell_global_ids. The user is responsible for freeing them.
NULL is a valid argument for cell_coord_idx, duplicated_cell_idx, orig_cell_global_ids, and nbr_duplicated_cells
Examples
test_read_scrip.c.

Definition at line 943 of file read_scrip_grid.c.

Here is the call graph for this function:

◆ yac_read_scrip_basic_grid_data()

struct yac_basic_grid_data yac_read_scrip_basic_grid_data ( char const * grid_filename,
char const * mask_filename,
char const * grid_name,
int valid_mask_value,
int use_ll_edges )

reads in an grid in SCRIP format

Parameters
[in]grid_filenamename of the SCRIP grid netcdf file
[in]mask_filenamename of the SCRIP mask netcdf file
[in]grid_namename of the grid in the file
[in]valid_mask_valuevalue that marks cells as valid
[in]use_ll_edgesif possible represent all edges using lon/lat circles
Returns
yac_basic_grid_data structure that contains the grid

Definition at line 879 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_scrip_basic_grid_data_()

static struct yac_basic_grid_data yac_read_scrip_basic_grid_data_ ( char const * grid_filename,
char const * mask_filename,
MPI_Comm comm,
char const * grid_name,
int valid_mask_value,
int use_ll,
double ** x_cells,
double ** y_cells,
size_t ** duplicated_cell_idx,
yac_int ** orig_cell_global_ids,
size_t * nbr_duplicated_cells )
static

Definition at line 807 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_scrip_basic_grid_information()

static void yac_read_scrip_basic_grid_information ( const char * filename,
const char * grid_name,
size_t cell_mask_size,
int * cell_mask,
size_t * num_vertices_,
size_t * num_cells_,
int ** num_vertices_per_cell_,
int ** cell_to_vertex_,
double ** x_vertices,
double ** y_vertices,
double ** x_cells,
double ** y_cells,
size_t ** duplicated_cell_idx_,
size_t ** orig_cell_idx_,
size_t * nbr_duplicated_cells_ )
static

Definition at line 152 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_scrip_basic_grid_parallel()

struct yac_basic_grid * yac_read_scrip_basic_grid_parallel ( char const * grid_filename,
char const * mask_filename,
MPI_Comm comm,
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 )

reads in grid data from a SCRIP formated file in parallel and applies a IO decomposition to it

Parameters
[in]grid_filenamename of the SCRIP grid netcdf file
[in]mask_filenamename of the SCRIP mask netcdf file
[in]commMPI communicator containing all proceses that will get a part of the grid
[in]grid_namename of the grid in the file
[in]valid_mask_valuevalue that marks cells as valid
[in]namename of the grid
[in]use_ll_edgesif possible represent all edges using lon/lat circles
[out]cell_coord_idxindex at which cell centers are registerd in the basic grid
[out]duplicated_cell_idxindices of all duplicated cells
[out]orig_cell_global_idsglobal ids of the original cells
[out]nbr_duplicated_cellsnumber of duplicated cells
Returns
basic grid
Remarks
This routine will allocate the arrays duplicated_cell_idx and orig_cell_global_ids. The user is responsible for freeing them.
NULL is a valid argument for cell_coord_idx, duplicated_cell_idx, orig_cell_global_ids, and nbr_duplicated_cells

Definition at line 890 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_scrip_basic_grid_parallel_f2c()

struct yac_basic_grid * yac_read_scrip_basic_grid_parallel_f2c ( char const * grid_filename,
char const * mask_filename,
MPI_Fint comm,
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 )

Definition at line 929 of file read_scrip_grid.c.

Here is the call graph for this function:

◆ yac_read_scrip_grid_information()

void yac_read_scrip_grid_information ( char const * grid_filename,
char const * mask_filename,
char const * grid_name,
int valid_mask_value,
size_t * num_vertices,
size_t * num_cells,
int ** num_vertices_per_cell,
double ** x_vertices,
double ** y_vertices,
double ** x_cells,
double ** y_cells,
int ** cell_to_vertex,
int ** cell_core_mask,
size_t ** duplicated_cell_idx,
size_t ** orig_cell_idx,
size_t * nbr_duplicated_cells )

reads in an grid in SCRIP format

Parameters
[in]grid_filenamename of the SCRIP grid netcdf file
[in]mask_filenamename of the SCRIP mask netcdf file
[in]grid_namename of the grid in the file
[in]valid_mask_valuevalue that marks cells as valid
[out]num_verticesnumber of vertices in the grid
[out]num_cellsnumber of cells in the grid
[out]num_vertices_per_cellnumber of vertices per cell
[out]x_verticeslongitude coordinates of the vertices
[out]y_verticeslatitude coordinates of the vertices
[out]x_cellslongitude coordinates of cell points
[out]y_cellslatitude coordinates of cell points
[out]cell_to_vertexvertices indices per cell
[out]cell_core_maskcell core mask
[out]duplicated_cell_idxindices of all duplicated cells
[out]orig_cell_idxindices of the original cells
[out]nbr_duplicated_cellsnumber of duplicated cells
Remarks
NULL is a valid argument for duplicated_cell_idx, orig_cell_idx, and nbr_duplicated_cells

Definition at line 658 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_read_scrip_mask_information()

static void yac_read_scrip_mask_information ( const char * filename,
const char * grid_name,
size_t * num_cells_,
int ** cell_mask )
static

Definition at line 542 of file read_scrip_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function: