本文整理汇总了C++中NcFile类的典型用法代码示例。如果您正苦于以下问题:C++ NcFile类的具体用法?C++ NcFile怎么用?C++ NcFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NcFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: netcdf_mpas_read_xyzcell
void netcdf_mpas_read_xyzcell ( string filename, int ncells, double xcell[],
double ycell[], double zcell[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_XYZCELL reads xCell, yCell, zCell.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 29 December 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int NCELLS, the number of nodes.
//
// Output, double XCELL[NCELLS], YCELL[NCELLS], ZCELL[NCELLS], the
// coordinates of the nodes.
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "xCell" );
(*var_id).get ( &xcell[0], ncells );
var_id = ncid.get_var ( "yCell" );
(*var_id).get ( &ycell[0], ncells );
var_id = ncid.get_var ( "zCell" );
(*var_id).get ( &zcell[0], ncells );
//
// Close the file.
//
ncid.close ( );
return;
}
示例2: netcdf_mpas_read_xyzvertex
void netcdf_mpas_read_xyzvertex ( string filename, int nvertices,
double xvertex[], double yvertex[], double zvertex[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_CELLS gets the cell center coordinates.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 January 2011
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int NVERTICES, the number of vertices.
//
// Output, double XVERTEX[NVERTICES], YVERTEXL[NVERTICES],
// ZVERTEX[NVERTICES], the coordinates of the nodes.
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "xVertex" );
(*var_id).get ( &xvertex[0], nvertices );
var_id = ncid.get_var ( "yVertex" );
(*var_id).get ( &yvertex[0], nvertices );
var_id = ncid.get_var ( "zVertex" );
(*var_id).get ( &zvertex[0], nvertices );
//
// Close the file.
//
ncid.close ( );
return;
}
示例3: netcdf_mpas_read_nvertices
int netcdf_mpas_read_nvertices ( string filename )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_NVERTICES gets the number of vertices.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 30 December 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Output, int NETCDF_MPAS_READ_NVERTICES, the value of NVERTICES.
//
{
int nvertices;
long int nvertices_size;
NcDim *nvertices_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get NCELLS, which is a NETCDF dimension.
//
nvertices_id = ncid.get_dim ( "nVertices" );
nvertices_size = (*nvertices_id).size ( );
//
// Close the file.
//
ncid.close ( );
nvertices = ( int ) nvertices_size;
return nvertices;
}
示例4: netcdf_mpas_read_verticesoncell
void netcdf_mpas_read_verticesoncell ( string filename, int maxedges,
int ncells, int verticesoncell[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_VERTICESONCELLS gets verticesOnCells.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 January 2011
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int MAXEDGES, the maximum number of edges for a cell.
//
// Input, int NCELLS, the number of cells.
//
// Output, int VERTICESONCELLS[MAXEDGES*NCELLS];
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "verticesOnCell" );
(*var_id).get ( &verticesoncell[0], ncells, maxedges );
//
// Close the file.
//
ncid.close ( );
return;
}
示例5: netcdf_mpas_read_maxedges
int netcdf_mpas_read_maxedges ( string filename )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_MAXEDGES gets MAXEDGES.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 January 2011
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Output, int NETCDF_MPAS_READ_MAXEDGES, the value of MAXEDGES.
//
{
int maxedges;
long int maxedges_size;
NcDim *maxedges_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get MAXEDGES, which is a NETCDF dimension.
//
maxedges_id = ncid.get_dim ( "maxEdges" );
maxedges_size = (*maxedges_id).size ( );
//
// Close the file.
//
ncid.close ( );
maxedges = ( int ) maxedges_size;
return maxedges;
}
示例6: NcFile
bool FileArome::isValid(std::string iFilename) {
bool status = false;
NcFile file = NcFile(iFilename.c_str(), NcFile::ReadOnly);
if(file.is_valid()) {
status = hasDim(file, "time") && hasDim(file, "x") && hasDim(file, "y") &&
!hasDim(file, "ensemble_member") &&
hasVar(file, "latitude") && hasVar(file, "longitude");
}
file.close();
return status;
}
示例7: netcdf_mpas_read_cellsonvertex
void netcdf_mpas_read_cellsonvertex ( string filename, int nvertices,
int cellsonvertex[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_CELLSONVERTEX gets the cellsOnVertex information.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 30 December 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int NEDGES, the number of edges.
//
// Output, int CELLSONVERTEX[3*NVERTICES];
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "cellsOnVertex" );
(*var_id).get ( &cellsonvertex[0], nvertices, 3 );
//
// Close the file.
//
ncid.close ( );
return;
}
示例8: bind
boost::function<void()> zd11_c::netcdf_define(NcFile &nc, std::string const &vname)
{
auto oneDim = giss::get_or_add_dim(nc, "one", 1);
auto infoVar = nc.add_var((vname + ".info").c_str(), ncDouble, oneDim);
infoVar->add_att("m", this->m);
infoVar->add_att("n", this->n);
auto neDim = nc.add_dim((vname + ".ne").c_str(), this->ne);
nc.add_var((vname + ".row").c_str(), ncInt, neDim);
nc.add_var((vname + ".col").c_str(), ncInt, neDim);
nc.add_var((vname + ".val").c_str(), ncDouble, neDim);
return boost::bind(&netcdf_write, this, &nc, vname);
}
示例9: read_vector
std::vector<T> read_vector(NcFile &nc, std::string const &var_name)
{
// Read points vector
NcVar *vpoints = nc.get_var(var_name.c_str());
long npoints = vpoints->get_dim(0)->size();
std::vector<T> points(npoints);
vpoints->get(&points[0], npoints);
return points;
}
示例10: NcFile
NCDataSet* NCDataSetBuilder::createDataSet() {
returned = true;
if (RepastProcess::instance()->rank() == 0) {
NcFile* ncfile = new NcFile(dataSet->file_.c_str(), NcFile::Replace, NULL, 0, NcFile::Offset64Bits);
NcDim* runDim = ncfile->add_dim("run", 1);
NcDim* tickDim = ncfile->add_dim("tick");
ncfile->add_var("tick", ncDouble, tickDim);
for (size_t i = 0; i < dataSet->dataSources.size(); i++) {
NCDataSource* ds = dataSet->dataSources[i];
ncfile->add_var(ds->name().c_str(), ds->ncType(), tickDim, runDim);
}
dataSet->ncfile = ncfile;
}
return dataSet;
}
示例11: stat
void FlowManager::output(const string &fileName) const
{
NcFile *file;
struct stat statInfo;
int ret = stat(fileName.c_str(), &statInfo);
NcError ncError(NcError::silent_nonfatal);
if (ret != 0 || TimeManager::isFirstStep()) {
file = new NcFile(fileName.c_str(), NcFile::Replace);
} else {
file = new NcFile(fileName.c_str(), NcFile::Write);
}
if (!file->is_valid()) {
char message[100];
sprintf(message, "Failed to open file %s.", fileName.c_str());
REPORT_ERROR(message)
}
示例12: netcdf_define
boost::function<void ()> netcdf_define(
NcFile &nc,
std::string const &vname,
blitz::Array<T,rank> const &val,
std::vector<NcDim *> const &ddims = {})
{
// Type-check for unit strides
int stride = 1;
for (int i=rank-1; i>=0; --i) {
if (val.stride(i) != stride) {
fprintf(stderr, "Unexpected stride of %d (should be %d) in dimension %d (extent=%d) of %s (rank=%d)\n", val.stride(i), stride, i, val.extent(i), vname.c_str(), rank);
fprintf(stderr, "Are you trying to write a Fortran-style array? Use f_to_c() in blitz.hpp first\n");
throw std::exception();
}
//printf("(stride=%d) *= (val.extent[%d]=%d)\n", stride, i, val.extent(i));
stride *= val.extent(i);
}
// Create the required dimensions
NcDim const *dims[rank];
for (int i=0; i<rank; ++i) {
if (i >= ddims.size()) {
char dim_name[200];
sprintf(dim_name, "%s.dim%d", vname.c_str(), i);
dims[i] = nc.add_dim(dim_name, val.extent(i));
} else {
dims[i] = ddims[i];
}
assert(dims[i] != NULL);
}
// Create the variable
NcVar *nc_var = nc.add_var(vname.c_str(), get_nc_type<T>(), rank, dims);
assert(nc_var != NULL);
// Write it out (later)
return boost::bind(&netcdf_write_blitz<T,rank>, nc_var, val);
}
示例13: load_nc_dim
static int load_nc_dim(const NcFile& ncf, const string& name, bool required = true)
{
NcDim* d = 0;
try
{
d = ncf.get_dim(name.c_str());
}
catch(char* str)
{
check(!required, string(str) + "\ndimension " + name + " not found in netcdf file");
}
int size = d ? d->size() : 0;
return size;
}
示例14: bind
boost::function<void ()> Grid_LonLat::netcdf_define(NcFile &nc, std::string const &vname) const
{
auto parent = Grid::netcdf_define(nc, vname);
NcDim *lonbDim = nc.add_dim((vname + ".lon_boundaries.length").c_str(),
this->lonb.size());
NcVar *lonb_var = nc.add_var((vname + ".lon_boundaries").c_str(),
ncDouble, lonbDim);
NcDim *latbDim = nc.add_dim((vname + ".lat_boundaries.length").c_str(),
this->latb.size());
NcVar *latb_var = nc.add_var((vname + ".lat_boundaries").c_str(),
ncDouble, latbDim);
NcVar *info_var = nc.get_var((vname + ".info").c_str());
info_var->add_att("north_pole_cap", north_pole ? 1 : 0);
info_var->add_att("south_pole_cap", south_pole ? 1 : 0);
info_var->add_att("points_in_side", points_in_side);
info_var->add_att("nlon", nlon());
info_var->add_att("nlat", nlat());
return boost::bind(&Grid_LonLat_netcdf_write, parent, &nc, this, vname);
}
示例15: read_from_netcdf
void Grid_LonLat::read_from_netcdf(NcFile &nc, std::string const &vname)
{
Grid::read_from_netcdf(nc, vname);
NcVar *info_var = nc.get_var((vname + ".info").c_str());
north_pole = (giss::get_att(info_var, "north_pole_cap")->as_int(0) != 0);
south_pole = (giss::get_att(info_var, "south_pole_cap")->as_int(0) != 0);
points_in_side = giss::get_att(info_var, "points_in_side")->as_int(0);
// _nlon = giss::get_att(info_var, "nlon")->as_int(0);
// _nlat = giss::get_att(info_var, "nlat")->as_int(0);
lonb = giss::read_double_vector(nc, vname + ".lon_boundaries");
latb = giss::read_double_vector(nc, vname + ".lat_boundaries");
}