14#define MODULE "geofile"
24 string::size_type last_slash = path.find_last_of(
'/');
26 return (last_slash == string::npos) ? path: path.substr(last_slash);
33 size_t f = file_name.rfind(
".");
34 if (f != string::npos)
35 return file_name.substr(0, f) +
"_stare.nc";
37 string sidecarFileName = file_name;
38 return sidecarFileName.append(
"_stare.nc");
57 BESDEBUG(MODULE,
"Reading sidecar file " << fileName << endl);
61 if ((ret = nc_open(fileName.c_str(), NC_NOWRITE, &d_ncid)))
65 char title_in[NC_MAX_NAME + 1];
66 if ((ret = nc_get_att_text(d_ncid, NC_GLOBAL, SSC_TITLE_NAME, title_in)))
68 if (strncmp(title_in, SSC_TITLE, NC_MAX_NAME))
69 return SSC_NOT_SIDECAR;
73 if ((ret = nc_inq(d_ncid, &ndims, &nvars, NULL, NULL)))
78 for (
int v = 0; v < nvars; v++) {
80 char var_name[NC_MAX_NAME + 1];
82 int ndims, dimids[NDIM2], natts;
83 if ((ret = nc_inq_var(d_ncid, v, var_name, &xtype, &ndims, dimids, &natts)))
86 BESDEBUG(MODULE,
"var " << var_name <<
" type " << xtype <<
" ndims " << ndims << endl);
89 char long_name_in[NC_MAX_NAME + 1];
90 if ((ret = nc_get_att_text(d_ncid, v, SSC_LONG_NAME, long_name_in)))
94 if (!strncmp(long_name_in, SSC_INDEX_LONG_NAME, NC_MAX_NAME)) {
96 d_stare_varid.push_back(v);
100 if ((ret = nc_inq_dimlen(d_ncid, dimids[0], &dimlen[0])))
102 if ((ret = nc_inq_dimlen(d_ncid, dimids[1], &dimlen[1])))
106 char variables_in[NC_MAX_NAME + 1];
107 if ((ret = nc_get_att_text(d_ncid, v, SSC_INDEX_VAR_ATT_NAME, variables_in)))
110 d_variables.emplace_back(
string(variables_in));
113 d_stare_index_name.emplace_back(var_name);
116 d_size_i.push_back(dimlen[0]);
117 d_size_j.push_back(dimlen[1]);
121 BESDEBUG(MODULE,
"variable_in " << variables_in << endl);
139 BESDEBUG(MODULE,
"get_stare_indices called for '" << variable_name <<
"'" << endl);
143 for (
unsigned long v = 0; v < d_variables.size(); ++v) {
144 BESDEBUG(MODULE,
"Looking st: '" << d_variables[v] <<
"'" << endl);
147 if (d_variables[v].find(variable_name) != string::npos) {
148 BESDEBUG(MODULE,
"found" << endl);
150 values.resize(d_size_i[v] * d_size_j[v]);
151 int status = nc_get_var(d_ncid, d_stare_varid[v], values.data());
152 if (status != NC_NOERR)
155 +
" for " + variable_name +
" - " + nc_strerror(status), __FILE__, __LINE__);
160size_t GeoFile::get_variable_rows(
string variable_name)
const {
161 for (
unsigned long v = 0; v < d_variables.size(); ++v) {
162 if (d_variables[v].find(variable_name) != string::npos) {
169 +
" for " + variable_name, __FILE__, __LINE__);
172size_t GeoFile::get_variable_cols(
string variable_name)
const {
173 for (
unsigned long v = 0; v < d_variables.size(); ++v) {
174 if (d_variables[v].find(variable_name) != string::npos) {
181 +
" for " + variable_name, __FILE__, __LINE__);
193 BESDEBUG(MODULE,
"Closing sidecar file with ncid " << d_ncid << endl);
196 (void) nc_close(d_ncid);
exception thrown if internal error encountered
int read_sidecar_file(const std::string &file_name)
Read a sidecar file.
std::string sidecar_filename(const std::string &file_name) const
std::string sanitize_pathname(string path) const
Strip away path info. Use in error messages.
void close_sidecar_file()
void get_stare_indices(const std::string &var_name, std::vector< STARE_ArrayIndexSpatialValue > &values)