Add missing NcFile::enddef() method, so can create files of all format types

This commit is contained in:
Russ Rew 2013-12-23 13:04:05 -07:00
parent e013ab35f0
commit 92ec0a9f40
3 changed files with 19 additions and 14 deletions

View File

@ -82,3 +82,8 @@ NcFile::NcFile(const string& filePath, const FileMode fMode, const FileFormat fF
void NcFile::sync(){
ncCheck(nc_sync(myId),__FILE__,__LINE__);
}
// Leave define mode, used for classic model
void NcFile::enddef() {
ncCheck(nc_enddef(myId),__FILE__,__LINE__);
}

View File

@ -65,6 +65,9 @@ namespace netCDF
//! Synchronize an open netcdf dataset to disk
void sync();
//! Leave define mode, used for classic model
void enddef();
private:
/* Do not allow definition of NcFile involving copying any NcFile or NcGroup.
Because the destructor closes the file and releases al resources such

View File

@ -62,8 +62,8 @@ int create_file(string filename, NcFile::FileFormat format) {
// In the classic model, must explicitly leave define mode
// before writing data. Need a method that calls nc_enddef().
// if(format != NcFile::nc4)
// dataFile.
if(format != NcFile::nc4)
dataFile.enddef();
// Write the data to the file. Although netCDF supports
// reading and writing subsets of data, in this case we write all
@ -90,20 +90,17 @@ int main()
return ret;
cout << "*** SUCCESS creating nc4 file" << endl;
// The following three tests don't work yet. Uncomment when can write
// files of nc4classic, classic, and classic64 formats.
if(ret = create_file("simple_xy_nc4classic.nc", NcFile::nc4classic))
return ret;
cout << "*** SUCCESS creating nc4classic file" << endl;
// if(ret = create_file("simple_xy_nc4classic.nc", NcFile::nc4classic))
// return ret;
// cout << "*** SUCCESS creating nc4classic file" << endl;
if(ret = create_file("simple_xy_classic.nc", NcFile::classic))
return ret;
cout << "*** SUCCESS creating classic file" << endl;
// if(ret = create_file("simple_xy_classic.nc", NcFile::classic))
// return ret;
// cout << "*** SUCCESS creating classic file" << endl;
// if(ret = create_file("simple_xy_classic64.nc", NcFile::classic64))
// return ret;
// cout << "*** SUCCESS creating classic64 file" << endl;
if(ret = create_file("simple_xy_classic64.nc", NcFile::classic64))
return ret;
cout << "*** SUCCESS creating classic64 file" << endl;
return 0;
}