本文整理汇总了C++中NcFile::get_att方法的典型用法代码示例。如果您正苦于以下问题:C++ NcFile::get_att方法的具体用法?C++ NcFile::get_att怎么用?C++ NcFile::get_att使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcFile
的用法示例。
在下文中一共展示了NcFile::get_att方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
bool ReadAstro::open(const char *path)
{
assert(!m_ncfile);
m_ncfile = new NcFile(path, NcFile::ReadOnly);
if (!m_ncfile->is_valid())
{
close();
sendError("failed to open NetCDF file %s", path);
return false;
}
if (m_ncfile->get_format() == NcFile::BadFormat)
{
close();
sendError("bad NetCDF file");
return false;
}
fprintf(stderr, "dims=%d, vars=%d, attrs=%d\n",
m_ncfile->num_dims(), m_ncfile->num_vars(), m_ncfile->num_atts());
for (int i = 0; i < m_ncfile->num_dims(); ++i)
{
fprintf(stderr, "%s: %ld\n",
m_ncfile->get_dim(i)->name(),
m_ncfile->get_dim(i)->size());
}
for (int i = 0; i < m_ncfile->num_vars(); ++i)
{
fprintf(stderr, "%s: dims=%d atts=%d vals=%ld type=%d\n",
m_ncfile->get_var(i)->name(),
m_ncfile->get_var(i)->num_dims(),
m_ncfile->get_var(i)->num_atts(),
m_ncfile->get_var(i)->num_vals(),
m_ncfile->get_var(i)->type());
//int dims = m_ncfile->get_var(i)->num_dims();
NcVar *var = m_ncfile->get_var(i);
for (int j = 0; j < var->num_dims(); ++j)
{
fprintf(stderr, " %s: %ld edge=%ld\n",
var->get_dim(j)->name(),
var->get_dim(j)->size(),
var->edges()[j]);
}
}
for (int i = 0; i < m_ncfile->num_atts(); ++i)
{
fprintf(stderr, "%s\n", m_ncfile->get_att(i)->name());
}
return true;
}
示例2: initFromFile
//
// Reads variable data from dump file
//
bool DataVar::initFromFile(const string& filename, const_DomainChunk_ptr dom)
{
cleanup();
#if ESYS_HAVE_NETCDF
NcError ncerr(NcError::silent_nonfatal);
NcFile* input = new NcFile(filename.c_str());
if (!input->is_valid()) {
cerr << "Could not open input file " << filename << "." << endl;
delete input;
return false;
}
NcDim* dim;
NcAtt* att;
att = input->get_att("type_id");
int typeID = att->as_int(0);
if (typeID != 2) {
cerr << "WARNING: Only expanded data supported!" << endl;
delete input;
return false;
}
att = input->get_att("rank");
rank = att->as_int(0);
dim = input->get_dim("num_data_points_per_sample");
ptsPerSample = dim->size();
att = input->get_att("function_space_type");
funcSpace = att->as_int(0);
centering = dom->getCenteringForFunctionSpace(funcSpace);
dim = input->get_dim("num_samples");
numSamples = dim->size();
#ifdef _DEBUG
cout << varName << ":\t" << numSamples << " samples, "
<< ptsPerSample << " pts/s, rank: " << rank << endl;
#endif
domain = dom;
NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
if (nodes == NULL) {
delete input;
return false;
}
meshName = nodes->getName();
siloMeshName = nodes->getFullSiloName();
initialized = true;
size_t dimSize = 1;
vector<long> counts;
if (rank > 0) {
dim = input->get_dim("d0");
int d = dim->size();
shape.push_back(d);
counts.push_back(d);
dimSize *= d;
}
if (rank > 1) {
dim = input->get_dim("d1");
int d = dim->size();
shape.push_back(d);
counts.push_back(d);
dimSize *= d;
}
if (rank > 2) {
cerr << "WARNING: Rank " << rank << " data is not supported!\n";
initialized = false;
}
if (initialized && numSamples > 0) {
sampleID.insert(sampleID.end(), numSamples, 0);
NcVar* var = input->get_var("id");
var->get(&sampleID[0], numSamples);
size_t dataSize = dimSize*numSamples*ptsPerSample;
counts.push_back(ptsPerSample);
counts.push_back(numSamples);
float* tempData = new float[dataSize];
var = input->get_var("data");
var->get(tempData, &counts[0]);
const float* srcPtr = tempData;
for (size_t i=0; i < dimSize; i++, srcPtr++) {
float* c = averageData(srcPtr, dimSize);
dataArray.push_back(c);
}
delete[] tempData;
initialized = reorderSamples();
}
//.........这里部分代码省略.........
示例3: netcdf_mpas_report
void netcdf_mpas_report ( string filename )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_REPORT reads an MPAS NETCDF grid file and reports.
//
// Discussion:
//
// In this example, we want to extract all the information from a file
// of unknown type.
//
// Here, we are pretending we have no idea what's in the file, so we
// have to go step by step, making inquiries to NETCDF.
//
// As we go, we print out what we have discovered. We don't attempt
// to return any of the data.
//
// 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 FILENAME, the name of the NETCDF file to examine.
//
{
NcAtt *att;
NcDim *dim;
int i;
int j;
long int len;
NcToken name;
int num_atts;
int num_dims;
int num_vars;
NcType type;
NcDim *unlimdimid;
NcVar *var;
cout << "\n";
cout << "NETCDF_MPAS_REPORT:\n";
cout << " Report the information stored in a NETCDF\n";
cout << " file. Although we wish to examine a file containing\n";
cout << " grid data generated by MPAS, we will assume we do not\n";
cout << " have any idea of what is in the file. So we just read,\n";
cout << " inquire, and print out.\n";
cout << "\n";
cout << " The name of the file is \"" << filename << "\"\n";
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Return information about the NETCDF file.
//
num_dims = ncid.num_dims ( );
num_vars = ncid.num_vars ( );
num_atts = ncid.num_atts ( );
unlimdimid = ncid.rec_dim ( );
cout << "\n";
cout << "PRIMARY PARAMETERS:\n";
cout << "\n";
cout << " The number of dimensions NUM_DIMS = " << num_dims << "\n";
cout << " The number of variables NUM_VARS = " << num_vars << "\n";
cout << " The number of global attributes NUM_ATTS = " << num_atts << "\n";
cout << " The unlimited dimension (if any) UNLIMDIMID = \"" << (*unlimdimid).name ( ) << "\"\n";
//
// Retrieve global attributes.
// First, we must evaluate the constant "NC_GLOBAL".
//
// nc_global = netcdf.getConstant ( 'NC_GLOBAL' );
cout << "\n";
cout << "GLOBAL ATTRIBUTES:\n";
cout << " Att --------Name-------- Type Len\n";
cout << "\n";
for ( i = 0; i < num_atts; i++ )
{
att = ncid.get_att ( i );
name = (*att).name ( );
type = (*att).type ( );
//.........这里部分代码省略.........