Go to the documentation of this file.
5 static const char* elevNames[] = {
"height",
"z",
"depth",
NULL};
6 static int elev_initialized = 0;
7 static grid_info_t* elev_global_gridinfo = {0};
8 static grid_info_t* elev_aux_gridinfo = {0};
9 static int elev_global_depthmode = -1;
10 static int elev_aux_depthmode = -1;
12 int initElevFile(
char* elevFilename, grid_info_t* elevGrid,
int* depth_mode) {
18 if (elevFilename ==
NULL) {
19 fprintf(
stderr,
"-E- %s line %d: Elevation file is NULL.\n",
23 status = nc_open(elevFilename, NC_NOWRITE, &elevGrid->ncid);
25 fprintf(
stderr,
"-E- %s line %d: Could not open netCDF File \"%s\".\n",
26 __FILE__, __LINE__, elevFilename);
34 "-E- %s line %d: Could not read grid info from \"%s\".\n",
35 __FILE__, __LINE__, elevFilename);
42 status = nc_inq_att(elevGrid->ncid, elevGrid->varid,
43 "positive", &
type, &len);
44 if ((
status == NC_NOERR) && (
type == NC_CHAR) && (len > 0)) {
45 char*
value = (
char*) malloc(len + 1);
46 status = nc_get_att_text(elevGrid->ncid, elevGrid->varid,
50 depth_mode[0] = (strcmp(
value,
"down") == 0);
66 void elev_init(
char* elevGlobalFilename,
char* elevAuxFilename) {
68 if (elevGlobalFilename !=
NULL && elevGlobalFilename[0] != 0) {
72 &elev_global_depthmode);
74 fprintf(
stderr,
"-E- %s line %d: "
75 "Could not read Global Elevation file \"%s\".\n",
76 __FILE__, __LINE__, elevGlobalFilename);
80 if (elevAuxFilename !=
NULL && elevAuxFilename[0] != 0) {
86 fprintf(
stderr,
"-E- %s line %d: "
87 "Could not read Auxiliary Elevation file \"%s\".\n",
88 __FILE__, __LINE__, elevAuxFilename);
95 float readElev(grid_info_t* elevGrid,
int depth_mode,
float lat,
float lon) {
99 if (elevGrid !=
NULL) {
101 if ((!
status) && (depth_mode))
112 elev =
readElev(elev_global_gridinfo, elev_global_depthmode,
lat,
lon);
char * lowcase(char *instr)
float get_elev(float lat, float lon)
grid_info_t * allocate_gridinfo()
int initElevFile(char *elevFilename, grid_info_t *elevGrid, int *depth_mode)
int get_bylatlon(grid_info_t *grid, float lat, float lon, double *value)
float readElev(grid_info_t *elevGrid, int depth_mode, float lat, float lon)
int init_gridinfo(char *filename, const char *varnames[], grid_info_t *grid)
void elev_init(char *elevGlobalFilename, char *elevAuxFilename)