OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
nc_gridutils.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <netcdf.h>
Include dependency graph for nc_gridutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  grid_info_struct
 
struct  var_info_struct
 
struct  grid_area_t
 

Macros

#define BAD_VALUE   -32767
 

Functions

void handle_nc_error (int status, char *file, int line)
 
var_info_t * allocate_varinfo ()
 
int find_varid (int ncid, const char *varnames[], int *varid)
 
var_info_t * load_varinfo (int ncid, 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 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)
 

Macro Definition Documentation

◆ BAD_VALUE

#define BAD_VALUE   -32767

Definition at line 13 of file nc_gridutils.h.

Function Documentation

◆ allocate_gridinfo()

grid_info_t* allocate_gridinfo ( )

Allocate memory for structure describing grid.

Return values
gridEmpty 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
varEmpty 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]ncidNetCDF ID, from a previous call to nc_open(),
[in]varnamesNull-terminated list of possible variable names.
[out]varidNetCDF 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,lonDesired 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]gridStructure describing grid.
[in]lat,lonDesired geographic coordinates.
[out]valuePointer 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]gridStructure describing grid.
[in]north,south,east,westGeographic boundaries of desired area.
[out]areaStructure 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]statusNetCDF error status.
[in]fileOriginating FILE.
[in]lineOriginating LINE.

Definition at line 21 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]varnamesNull-terminated list of possible variable names.
[out]gridStructure 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]gridStructure describing grid.
[in]lat,lonDesired geographic coordinates.
[out]resultPointer 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]gridStructure describing grid.
[in]lat,lonDesired geographic coordinates.
[out]findexIndices 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]gridStructure describing grid.
[in]lat,lonDesired geographic coordinates.
[out]indexIndices 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]ncidNetCDF ID, from a previous call to nc_open(),
[in]varidNetCDF variable ID
Return values
varStructure 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]gridStructure describing grid.

Definition at line 592 of file nc_gridutils.c.