ocssw
V2022
|
#include "nc_gridutils.h"
Go to the source code of this file.
Macros | |
#define | NEW_CACHE_SIZE 240000000 |
#define | NEW_CACHE_NELEMS 1001 |
#define | NEW_CACHE_PREEMPTION .75 |
Functions | |
void | handle_nc_error (int status, char *file, int line) |
var_info_t * | allocate_varinfo () |
var_info_t * | load_varinfo (int ncid, int varid) |
int | find_varid (int ncid, const char *varnames[], int *varid) |
grid_info_t * | allocate_gridinfo () |
int | init_gridinfo (char *filename, const char *varnames[], grid_info_t *grid) |
int | fix_latlon (float *lat, float *lon) |
int | latlon_findex (grid_info_t *grid, float lat, float lon, double *findex) |
int | latlon_index (grid_info_t *grid, float lat, float lon, size_t *index) |
int | get_bylatlon (grid_info_t *grid, float lat, float lon, double *value) |
int | has_extra_column (grid_info_t *grid) |
int | get_grid_area (grid_info_t *grid, float north, float south, float east, float west, grid_area_t *area) |
int | interp_gridvar (grid_info_t *grid, float lat, float lon, double *result) |
void | print_gridinfo (grid_info_t grid) |
Detailed Description
Convenience utilities for handling NetCDF4 gridded variables.
Definition in file nc_gridutils.c.
Macro Definition Documentation
◆ NEW_CACHE_NELEMS
#define NEW_CACHE_NELEMS 1001 |
Definition at line 10 of file nc_gridutils.c.
◆ NEW_CACHE_PREEMPTION
#define NEW_CACHE_PREEMPTION .75 |
Definition at line 11 of file nc_gridutils.c.
◆ NEW_CACHE_SIZE
#define NEW_CACHE_SIZE 240000000 |
Definition at line 9 of file nc_gridutils.c.
Function Documentation
◆ allocate_gridinfo()
grid_info_t* allocate_gridinfo | ( | ) |
Allocate memory for structure describing grid.
- Return values
-
grid Empty structure for describing gridded variable.
Definition at line 107 of file nc_gridutils.c.
◆ allocate_varinfo()
var_info_t* allocate_varinfo | ( | ) |
Allocate memory for structure describing NetCDF variable.
- Return values
-
var Empty structure for describing NetCDF variable.
Definition at line 34 of file nc_gridutils.c.
◆ find_varid()
int find_varid | ( | int | ncid, |
const char * | varnames[], | ||
int * | varid | ||
) |
Find ID of first variable found in input list.
- Parameters
-
[in] ncid NetCDF ID, from a previous call to nc_open(), [in] varnames Null-terminated list of possible variable names. [out] varid NetCDF variable ID
- Returns
- Error if no variable found.
Definition at line 83 of file nc_gridutils.c.
◆ fix_latlon()
int fix_latlon | ( | float * | lat, |
float * | lon | ||
) |
Force coordinates into range: {-90 <= lat < 90} and {-180 <= lon < 190}
- Parameters
-
[in,out] lat,lon Desired geographic coordinates.
- Returns
- Error if either coordinate is NaN.
Definition at line 281 of file nc_gridutils.c.
◆ get_bylatlon()
int get_bylatlon | ( | grid_info_t * | grid, |
float | lat, | ||
float | lon, | ||
double * | value | ||
) |
Read gridded variable value nearest to specified coordinates.
- Parameters
-
[in] grid Structure describing grid. [in] lat,lon Desired geographic coordinates. [out] value Pointer to value, or FillValue if not found.
- Returns
- Error if coordinates outside of grid range. (0=good)
Definition at line 368 of file nc_gridutils.c.
◆ get_grid_area()
int get_grid_area | ( | grid_info_t * | grid, |
float | north, | ||
float | south, | ||
float | east, | ||
float | west, | ||
grid_area_t * | area | ||
) |
Read gridded variable values covering specified boundaries.
- Parameters
-
[in] grid Structure describing grid. [in] north,south,east,west Geographic boundaries of desired area. [out] area Structure contains and describes extracted area.
- Returns
- Error if any boundary set outside of grid range.
Definition at line 406 of file nc_gridutils.c.
◆ handle_nc_error()
void handle_nc_error | ( | int | status, |
char * | file, | ||
int | line | ||
) |
Print NetCDF error message and exit.
- Parameters
-
[in] status NetCDF error status. [in] file Originating FILE. [in] line Originating LINE.
Definition at line 21 of file nc_gridutils.c.
◆ has_extra_column()
int has_extra_column | ( | grid_info_t * | grid | ) |
Determine whether grid has extra longitude column. Needed when extracting area crossing +/- 180 degrees.
- Parameters
-
[in] grid Structure describing grid.
- Returns
- TRUE: has extra longitude column.
- FALSE: no extra longitude column.
Definition at line 394 of file nc_gridutils.c.
◆ init_gridinfo()
int init_gridinfo | ( | char * | filename, |
const char * | varnames[], | ||
grid_info_t * | grid | ||
) |
Load information about gridded variable from a file.
- Parameters
-
[in] filename [in] varnames Null-terminated list of possible variable names. [out] grid Structure describing grid.
- Returns
- Error status.
Definition at line 132 of file nc_gridutils.c.
◆ interp_gridvar()
int interp_gridvar | ( | grid_info_t * | grid, |
float | lat, | ||
float | lon, | ||
double * | result | ||
) |
Get bilinear interpolation of any gridded variable.
- Parameters
-
[in] grid Structure describing grid. [in] lat,lon Desired geographic coordinates. [out] result Pointer to interpolated value, or FillValue if not found.
- Returns
- Error if coordinates outside of grid range.
- Remarks
- nc_get_var1_double will automatically convert native type to double - see http://www.unidata.ucar.edu/software/netcdf/docs/netcdf/Type-Conversion.html
Definition at line 529 of file nc_gridutils.c.
◆ latlon_findex()
int latlon_findex | ( | grid_info_t * | grid, |
float | lat, | ||
float | lon, | ||
double * | findex | ||
) |
Find floating point index of specified coordinates within gridded variable.
- Parameters
-
[in] grid Structure describing grid. [in] lat,lon Desired geographic coordinates. [out] findex Indices of [y,x] corresponding to [lat,lon].
- Returns
- Error if coordinates outside of grid range.
Definition at line 312 of file nc_gridutils.c.
◆ latlon_index()
int latlon_index | ( | grid_info_t * | grid, |
float | lat, | ||
float | lon, | ||
size_t * | index | ||
) |
Find integer index of specified coordinates within gridded variable.
- Parameters
-
[in] grid Structure describing grid. [in] lat,lon Desired geographic coordinates. [out] index Indices of [y,x] corresponding to [lat,lon].
- Returns
- Error if coordinates outside of grid range. (0=good)
Definition at line 342 of file nc_gridutils.c.
◆ load_varinfo()
var_info_t* load_varinfo | ( | int | ncid, |
int | varid | ||
) |
Read NetCDF variable attributes and load into structure.
- Parameters
-
[in] ncid NetCDF ID, from a previous call to nc_open(), [in] varid NetCDF variable ID
- Return values
-
var Structure describing NetCDF variable.
Definition at line 52 of file nc_gridutils.c.
◆ print_gridinfo()
void print_gridinfo | ( | grid_info_t | grid | ) |
Print grid description structure.
- Parameters
-
[in] grid Structure describing grid.
Definition at line 592 of file nc_gridutils.c.