Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.
Hello, One of the biggest pains with NetCDF is having to write your I/O routines three times: one for define, one for write and one for read. I've developed some techniques that greatly ease this burden; for many standard cases, only a SINGLE subroutine needs to be written. What I've done is in C++, but it would apply equally well to Fortran 2003. Would anyone be interested in exploring this further? Example is below. -- Elizabeth ``` void GridSpec_LonLat::ncio(ibmisc::NcIO &ncio, std::string const &vname) { auto lonb_d = get_or_add_dim(ncio, vname + ".lon_boundaries.length", this->lonb.size()); ncio_vector(ncio, this->lonb, true, vname + ".lon_boundaries", ncDouble, {lonb_d}); auto latb_d = get_or_add_dim(ncio, vname + ".lat_boundaries.length", this->latb.size()); ncio_vector(ncio, this->latb, true, vname + ".lat_boundaries", ncDouble, {latb_d}); NcVar info_v = get_or_add_var(ncio, vname + ".info", ncInt, {}); get_or_put_att(info_v, ncio.rw, "north_pole_cap", north_pole); get_or_put_att(info_v, ncio.rw, "south_pole_cap", south_pole); get_or_put_att(info_v, ncio.rw, "points_in_side", ncInt, points_in_side); if (ncio.rw == 'w') { int n; n = nlon(); get_or_put_att(info_v, ncio.rw, "nlon", ncInt, n); n = nlat(); get_or_put_att(info_v, ncio.rw, "nlat", ncInt, n); } } ``` To write: ``` ibmisc::NcIO ncio(spec.name + ".nc", netCDF::NcFile::replace); spec.ncio(ncio, "grid"); ncio.close(); ``` To read: ``` ibmisc::NcIO ncio(spec.name + ".nc", netCDF::NcFile::read); spec.ncio(ncio, "grid"); ncio.close(); ```
netcdfgroup
archives: