Commit 680f1ca7 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

lock call to nc_close (bug fix).

parent eca25789
......@@ -3,6 +3,10 @@
* Using CDI library version 1.9.8
* Version 1.9.8 release
2019-10-17 Uwe Schulzweida
* lock call to nc_close (bug fix)
2019-10-14 Uwe Schulzweida
* Timstat: added support for cell_methods
......
......@@ -133,9 +133,8 @@ import_e5ml(const char *filename, VAR **vars)
size_t attlen;
double *xvals, *yvals, *vct, *levs;
/* open file and check file type */
/* nce(nc_open(filename, NC_NOWRITE, &nc_file_id)); */
nc_file_id = cdf_openread(filename);
// open file and check file type
nc_file_id = cdo_cdf_openread(filename);
nce(nc_get_att_text(nc_file_id, NC_GLOBAL, "file_type", filetype));
nce(nc_inq_attlen(nc_file_id, NC_GLOBAL, "file_type", &attlen));
......@@ -276,8 +275,8 @@ import_e5ml(const char *filename, VAR **vars)
nce(nc_inq_varid(nc_file_id, "STP", &nc_var_id));
nce(nc_get_vara_double(nc_file_id, nc_var_id, start, count, (*vars)[nvars_ml].ptr));
/*close input file */
nce(nc_close(nc_file_id));
// close input file
cdo_cdf_close(nc_file_id);
nvars = nvars_ml + 1;
......@@ -754,9 +753,8 @@ import_e5res(const char *filename, VAR **vars, ATTS *atts)
const int attstringlen = 8192;
char attstring[8192];
/* open file and check file type */
/* nce(nc_open(filename, NC_NOWRITE, &nc_file_id)); */
nc_file_id = cdf_openread(filename);
// open file and check file type
nc_file_id = cdo_cdf_openread(filename);
nce(nc_get_att_text(nc_file_id, NC_GLOBAL, "file_type", filetype));
nce(nc_inq_attlen(nc_file_id, NC_GLOBAL, "file_type", &attlen));
......@@ -1094,8 +1092,8 @@ import_e5res(const char *filename, VAR **vars, ATTS *atts)
}
}
/*close input file */
nce(nc_close(nc_file_id));
// close input file
cdo_cdf_close(nc_file_id);
nvars = varid;
......
......@@ -268,8 +268,7 @@ readRemapFileScrip(const char *remapFile, RemapAttributes &remapAtts, RemapMetho
// The routine reads a NetCDF file to extract remapping info in SCRIP format
// Open file and read some global information
// nce(nc_open(remapFile, NC_NOWRITE, &ncfileid));
const int ncfileid = cdf_openread(remapFile);
const int ncfileid = cdo_cdf_openread(remapFile);
cdfReadAttText(ncfileid, NC_GLOBAL, "history", remapAtts.history);
......@@ -347,7 +346,7 @@ readRemapFileScrip(const char *remapFile, RemapAttributes &remapAtts, RemapMetho
if (rv.num_links > 0) readRemapWeightsScrip(ncfileid, rv);
// Close input file
nce(nc_close(ncfileid));
cdo_cdf_close(ncfileid);
} // remapReadDataScrip
static int
......@@ -682,9 +681,6 @@ checkAreas(size_t n_a, const Varray<double> &area_a, const Varray<double> &area_
static void
verifyWeights(const char *remapFile)
{
// int ncfileid = cdf_openread(weights_file);
// nce(nc_close(ncfileid));
RemapMethod mapType(RemapMethod::UNDEF);
SubmapType submapType(SubmapType::NONE);
int numNeighbors = 0;
......
......@@ -92,7 +92,8 @@ int cdoDefineGrid(const std::string & p_gridfile);
int grid_read(FILE *gfp, const char *dname); // TODO: Find better place for this
int cdf_openread(const char *filename);
int cdo_cdf_openread(const char *filename);
void cdo_cdf_close(int nc_file_id);
void cdo_set_grids(const char *gridarg);
#endif /* GRIDDES_H */
......@@ -39,16 +39,17 @@ nce(int istat)
#endif
int
cdf_openread(const char *filename)
cdo_cdf_openread(const char *filename)
{
int fileID = -1;
#ifdef HAVE_LIBNETCDF
int nc_file_id; /* NetCDF grid file id */
int nc_file_id; // NetCDF grid file id
openLock();
int istat = nc_open(filename, NC_NOWRITE, &nc_file_id);
const auto istat = nc_open(filename, NC_NOWRITE, &nc_file_id);
openUnlock();
if (istat != NC_NOERR) cdoAbort("Open failed on %s! %s", filename, nc_strerror(istat));
if (istat != NC_NOERR) cdoAbort("nc_open failed on %s! %s", filename, nc_strerror(istat));
fileID = nc_file_id;
#else
cdoWarning("NetCDF support not compiled in!");
......@@ -57,6 +58,19 @@ cdf_openread(const char *filename)
return fileID;
}
void
cdo_cdf_close(int nc_file_id)
{
#ifdef HAVE_LIBNETCDF
openLock();
const auto istat = nc_close(nc_file_id);
openUnlock();
if (istat != NC_NOERR) cdoAbort("nc_close failed! %s", nc_strerror(istat));
#else
cdoWarning("NetCDF support not compiled in!");
#endif
}
int
gridFromNCfile(const char *gridfile)
{
......@@ -80,7 +94,7 @@ gridFromNCfile(const char *gridfile)
// open grid file and read grid size/name data
int nc_file_id = cdf_openread(gridfile);
int nc_file_id = cdo_cdf_openread(gridfile);
if (nc_inq_dimid(nc_file_id, "grid_size", &nc_gridsize_id) == NC_NOERR
&& nc_inq_dimid(nc_file_id, "grid_rank", &nc_gridrank_id) == NC_NOERR
......@@ -157,7 +171,7 @@ gridFromNCfile(const char *gridfile)
gridID = gridDefine(grid);
}
nce(nc_close(nc_file_id));
cdo_cdf_close(nc_file_id);
#else
cdoWarning("NetCDF support not compiled in!");
......
......@@ -544,8 +544,7 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
// Open file and read some global information
// nce(nc_open(interp_file, NC_NOWRITE, &nc_file_id));
int nc_file_id = cdf_openread(interp_file);
int nc_file_id = cdo_cdf_openread(interp_file);
// Map name
......@@ -813,7 +812,7 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
}
// Close input file
nce(nc_close(nc_file_id));
cdo_cdf_close(nc_file_id);
#else
cdoAbort("NetCDF support not compiled in!");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment