本文整理汇总了C++中NcVar::values方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::values方法的具体用法?C++ NcVar::values怎么用?C++ NcVar::values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcVar
的用法示例。
在下文中一共展示了NcVar::values方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eavlFloatArray
eavlField*
eavlNetCDFImporter::GetField(const string &name, const string &mesh, int)
{
for (unsigned int v=0; v<vars.size(); v++)
{
NcVar *var = vars[v];
if (name != var->name())
continue;
if (debugoutput) cerr << "reading var "<<v+1<<" / "<<vars.size()<<endl;
eavlFloatArray *arr = new eavlFloatArray(var->name(), 1);
arr->SetNumberOfTuples(var->num_vals());
NcValues *vals = var->values();
int n = var->num_vals();
for (int i=0; i<n; i++)
{
arr->SetComponentFromDouble(i,0, vals->as_double(i));
}
eavlField *field = new eavlField(1, arr, eavlField::ASSOC_POINTS);
return field;
}
return NULL;
}
示例2: dumpdata
void DumpableNcFile::dumpdata( )
{
NcVar* vp;
for (int n = 0; vp = get_var(n); n++) {
cout << " " << vp->name() << " = ";
NcValues* vals = vp->values();
cout << *vals << " ;" << endl ;
delete vals;
}
}
示例3: data
const kvs::AnyValueArray data(
const size_t offset = 0,
const size_t dim1 = 1,
const size_t dim2 = 1,
const size_t dim3 = 1 ) const
{
const void* head = m_var->values()->base();
const size_t nvalues = dim1 * dim2 * dim3;
switch ( m_var->type() )
{
case ncByte:
{
kvs::UInt8* values = (kvs::UInt8*)( head ) + offset;
return( kvs::AnyValueArray( this->flip( dim1, dim2, dim3, values ), nvalues ) );
}
case ncChar:
{
kvs::Int8* values = (kvs::Int8*)( head ) + offset;
return( kvs::AnyValueArray( this->flip( dim1, dim2, dim3, values ), nvalues ) );
}
case ncShort:
{
kvs::Int16* values = (kvs::Int16*)( head ) + offset;
return( kvs::AnyValueArray( this->flip( dim1, dim2, dim3, values ), nvalues ) );
}
case ncInt:
{
kvs::Int32* values = (kvs::Int32*)( head ) + offset;
return( kvs::AnyValueArray( this->flip( dim1, dim2, dim3, values ), nvalues ) );
}
case ncFloat:
{
kvs::Real32* values = (kvs::Real32*)( head ) + offset;
return( kvs::AnyValueArray( this->flip( dim1, dim2, dim3, values ), nvalues ) );
}
case ncDouble:
{
kvs::Real64* values = (kvs::Real64*)( head ) + offset;
return( kvs::AnyValueArray( this->flip( dim1, dim2, dim3, values ), nvalues ) );
}
default: return( kvs::AnyValueArray() );
}
}
示例4: loadNetCdfFile
bool EpidemicDataSet::loadNetCdfFile(const char * filename)
{
#if USE_NETCDF // TODO: should handle this differently
// change netcdf library error behavior
NcError err(NcError::verbose_nonfatal);
// open the netcdf file
NcFile ncFile(filename, NcFile::ReadOnly);
if(!ncFile.is_valid())
{
put_flog(LOG_FATAL, "invalid file %s", filename);
return false;
}
// get dimensions
NcDim * timeDim = ncFile.get_dim("time");
NcDim * nodesDim = ncFile.get_dim("nodes");
NcDim * stratificationsDim = ncFile.get_dim("stratifications");
if(timeDim == NULL || nodesDim == NULL || stratificationsDim == NULL)
{
put_flog(LOG_FATAL, "could not find a required dimension");
return false;
}
numTimes_ = timeDim->size();
// make sure we have the expected number of nodes
if(nodesDim->size() != numNodes_)
{
put_flog(LOG_FATAL, "got %i nodes, expected %i", nodesDim->size(), numNodes_);
return false;
}
put_flog(LOG_DEBUG, "file contains %i timesteps, %i nodes", numTimes_, numNodes_);
// make sure number of stratifications matches our expectation...
int numExpectedStratifications = 1;
for(unsigned int i=0; i<NUM_STRATIFICATION_DIMENSIONS; i++)
{
numExpectedStratifications *= stratifications_[i].size();
}
if(stratificationsDim->size() != numExpectedStratifications)
{
put_flog(LOG_FATAL, "got %i stratifications, expected %i", stratificationsDim->size(), numExpectedStratifications);
return false;
}
// get all float variables with dimensions (time, nodes, stratifications)
for(int i=0; i<ncFile.num_vars(); i++)
{
NcVar * ncVar = ncFile.get_var(i);
if(ncVar->num_dims() == 3 && ncVar->type() == ncFloat && strcmp(ncVar->get_dim(0)->name(), "time") == 0 && strcmp(ncVar->get_dim(1)->name(), "nodes") == 0 && strcmp(ncVar->get_dim(2)->name(), "stratifications") == 0)
{
put_flog(LOG_INFO, "found variable: %s", ncVar->name());
// full shape
blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> shape;
shape(0) = numTimes_;
shape(1) = numNodes_;
for(int j=0; j<NUM_STRATIFICATION_DIMENSIONS; j++)
{
shape(2 + j) = stratifications_[j].size();
}
blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> var((float *)ncVar->values()->base(), shape, blitz::duplicateData);
variables_[std::string(ncVar->name())].reference(var);
}
}
#endif
return true;
}
示例5: nf
vtkDataArray *
avtS3DFileFormat::GetVar(int timeState, int domain, const char *varname)
{
debug5 << "avtS3DFileFormat::GetVar( timeState=" << timeState << ", domain="
<< domain << ", varname=" << varname << ")" << endl;
// Calculate the timestep directory that the data lives in.
char *pathcopy = strdup(mainFilename);
string dir = parse_dirname(pathcopy);
string timestepDir = CreateStringFromDouble(fileTimes[timeState]);
debug4 << "Timestep directory is <" << timestepDir << ">" << endl;
// Figure out how big this piece is.
CalculateSubpiece(domain);
// Open up the NetCDF file.
char path[256];
SNPRINTF(path,256,"%s%s%s%sfield.%05d",dir.c_str(),VISIT_SLASH_STRING, timestepDir.c_str(), VISIT_SLASH_STRING, domain);
debug5 << "avtS3DFileFormat::GetVar: Full path to data file is " << path << endl;
NcFile nf(path);
if (!nf.is_valid())
{
debug1 << nc_strerror(NcError().get_err()) << endl;
EXCEPTION1(InvalidFilesException, path);
}
debug5 << "avtS3DFileFormat::GetVar: Got valid file." << endl;
// Pull out the appropriate variable.
NcVar *v = nf.get_var(varname);
if (!v)
{
debug1 << nc_strerror(NcError().get_err()) << endl;
EXCEPTION1(InvalidVariableException, varname);
}
// Check if it fits the size of the mesh. Always node-centered, remember.
int ntuples = localDims[0] * localDims[1] * localDims[2];
debug5 << "ntuples:" << ntuples << endl;
int nvals = v->num_vals();
if (ntuples != nvals)
{
debug1 << "The variable " << v->name() <<
" does not conform to its mesh (" << nvals << " != " <<
ntuples << ")" << endl;
EXCEPTION1(InvalidVariableException, v->name());
}
// Set up the VTK dataset.
vtkFloatArray *rv = vtkFloatArray::New();
rv->SetNumberOfTuples(ntuples);
float *p = (float*)rv->GetVoidPointer(0);
NcValues *input = v->values();
if (!input)
{
debug1 << nc_strerror(NcError().get_err()) << endl;
EXCEPTION1(InvalidVariableException, v->name());
}
// Get the scaling factor.
NcAtt *scaling = v->get_att(NcToken("scale_factor"));
float scaling_factor = 1;
if (scaling)
{
scaling_factor = scaling->as_float(0);
debug5 << "avtS3DFileFormat::GetVar: Set the scaling factor as " << scaling_factor << endl;
}
// Process the variable into the returned data.
float *base = (float*)input->base();
for(int i=0;i<ntuples;i++)
{
p[i] = *(base + i) * scaling_factor;
}
return rv;
}