本文整理汇总了C++中NcAtt::as_int方法的典型用法代码示例。如果您正苦于以下问题:C++ NcAtt::as_int方法的具体用法?C++ NcAtt::as_int怎么用?C++ NcAtt::as_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcAtt
的用法示例。
在下文中一共展示了NcAtt::as_int方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
//.........这里部分代码省略.........
示例2: err
bool
NetworkObject::loadNetCDF(QString flnm)
{
m_fileName = flnm;
NcError err(NcError::verbose_nonfatal);
NcFile ncfFile(flnm.toLatin1().data(), NcFile::ReadOnly);
NcAtt *att;
NcVar *var;
// ---- get gridsize -----
att = ncfFile.get_att("gridsize");
m_nX = att->as_int(0);
m_nY = att->as_int(1);
m_nZ = att->as_int(2);
//------------------------
// ---- get vertex centers -----
var = ncfFile.get_var("vertex_centers");
if (!var)
var = ncfFile.get_var("vertex_center");
if (!var)
var = ncfFile.get_var("vertex_centres");
if (!var)
var = ncfFile.get_var("vertex_centre");
int nv = var->get_dim(0)->size();
float *vc = new float [3*nv];
var->get(vc, nv, 3);
m_vertexCenters.resize(nv);
for(int i=0; i<nv; i++)
m_vertexCenters[i] = Vec(vc[3*i+0], vc[3*i+1], vc[3*i+2]);
delete [] vc;
//------------------------
// ---- get edges -----
var = ncfFile.get_var("edge_neighbours");
int ne = var->get_dim(0)->size();
int *ed = new int [2*ne];
var->get(ed, ne, 2);
m_edgeNeighbours.resize(ne);
for(int i=0; i<ne; i++)
m_edgeNeighbours[i] = qMakePair(ed[2*i], ed[2*i+1]);
delete [] ed;
//------------------------
Vec bmin = m_vertexCenters[0];
Vec bmax = m_vertexCenters[0];
for(int i=0; i<m_vertexCenters.count(); i++)
{
bmin = StaticFunctions::minVec(bmin, m_vertexCenters[i]);
bmax = StaticFunctions::maxVec(bmax, m_vertexCenters[i]);
}
m_centroid = (bmin + bmax)/2;
m_enclosingBox[0] = Vec(bmin.x, bmin.y, bmin.z);
m_enclosingBox[1] = Vec(bmax.x, bmin.y, bmin.z);
m_enclosingBox[2] = Vec(bmax.x, bmax.y, bmin.z);
m_enclosingBox[3] = Vec(bmin.x, bmax.y, bmin.z);
m_enclosingBox[4] = Vec(bmin.x, bmin.y, bmax.z);
m_enclosingBox[5] = Vec(bmax.x, bmin.y, bmax.z);
m_enclosingBox[6] = Vec(bmax.x, bmax.y, bmax.z);
m_enclosingBox[7] = Vec(bmin.x, bmax.y, bmax.z);
// QStringList vatt, eatt;
int nvars = ncfFile.num_vars();
// for (int i=0; i < nvars; i++)
// {
// var = ncfFile.get_var(i);
// QString attname = var->name();
// attname.toLower();
// if (attname.contains("vertex_") &&
// ( attname != "vertex_centers" ||
// attname != "vertex_centres"))
// vatt.append(attname);
// else if (attname.contains("edge_") &&
// attname != "edge_neighbours")
// eatt.append(attname);
// }
m_vertexAttribute.clear();
m_edgeAttribute.clear();
m_vertexRadiusAttribute = -1;
m_edgeRadiusAttribute = -1;
int vri = 0;
int eri = 0;
for (int i=0; i < nvars; i++)
{
var = ncfFile.get_var(i);
QString attname = var->name();
attname.toLower();
if (attname.contains("vertex_") &&
//.........这里部分代码省略.........
示例3: init
void PolygonManager::init()
{
string fileName;
ConfigTools::read("parcel_polygon_file", fileName);
NOTICE("PolygonManager::init", "Reading polygons from \""+fileName+"\" ...");
NcFile file(fileName.c_str(), NcFile::ReadOnly);
if (!file.is_valid()) {
REPORT_ERROR(string("Failed to open file "+fileName+"."))
}
NcError ncError(NcError::silent_nonfatal);
if (TimeManager::onLine()) {
NcAtt *timeAtt = file.get_att("time");
NcAtt *timeStepAtt = file.get_att("time_step");
NcAtt *stepsAtt = file.get_att("steps");
if (timeAtt != NULL && timeStepAtt != NULL && stepsAtt != NULL) {
TimeManager::reset();
double dt = timeStepAtt->as_double(0);
double second = timeAtt->as_double(0);
double steps = stepsAtt->as_int(0);
TimeManager::setClock(dt, second, steps);
}
}
NcDim *numVertexDim = file.get_dim("num_total_vertex");
if (numVertexDim == NULL) {
Message message;
message << "Failed to find \"num_total_vertex\" dimension in file \"";
message << fileName << "\"!";
REPORT_ERROR(message.str());
}
NcDim *numEdgeDim = file.get_dim("num_total_edge");
if (numEdgeDim == NULL) {
Message message;
message << "Failed to find \"num_total_edge\" dimension in file \"";
message << fileName << "\"!";
REPORT_ERROR(message.str());
}
NcDim *numPolygonDim = file.get_dim("num_total_polygon");
if (numPolygonDim == NULL) {
Message message;
message << "Failed to find \"num_total_polygon\" dimension in file \"";
message << fileName << "\"!";
REPORT_ERROR(message.str());
}
int numVertex = static_cast<int>(numVertexDim->size());
int numEdge = static_cast<int>(numEdgeDim->size());
int numPolygon = static_cast<int>(numPolygonDim->size());
// -------------------------------------------------------------------------
// vertices part
vertices.create(numVertex);
double *oldVtxLon = new double[numVertex];
double *oldVtxLat = new double[numVertex];
double *oldVtxLev = new double[numVertex];
double *newVtxLon = new double[numVertex];
double *newVtxLat = new double[numVertex];
double *newVtxLev = new double[numVertex];
file.get_var("old_vertex_lon")->get(oldVtxLon, numVertex);
file.get_var("old_vertex_lat")->get(oldVtxLat, numVertex);
file.get_var("new_vertex_lon")->get(newVtxLon, numVertex);
file.get_var("new_vertex_lat")->get(newVtxLat, numVertex);
if (file.get_var("old_vertex_lev") != NULL) {
file.get_var("old_vertex_lev")->get(oldVtxLev, numVertex);
file.get_var("new_vertex_lev")->get(newVtxLev, numVertex);
} else {
for (int i = 0; i < vertices.size(); ++i) {
oldVtxLev[i] = 0.0;
newVtxLev[i] = 0.0;
}
}
// change the units from degree to rad
for (int i = 0; i < numVertex; ++i) {
oldVtxLon[i] /= Rad2Deg;
oldVtxLat[i] /= Rad2Deg;
newVtxLon[i] /= Rad2Deg;
newVtxLat[i] /= Rad2Deg;
}
Vertex *vertexMap[vertices.size()];
Vertex *vertex = vertices.front();
for (int i = 0; i < vertices.size(); ++i) {
vertexMap[i] = vertex;
vertex->setCoordinate(newVtxLon[i], newVtxLat[i], newVtxLev[i], NewTimeLevel);
vertex->setCoordinate(oldVtxLon[i], oldVtxLat[i], oldVtxLev[i], OldTimeLevel);
vertex = vertex->next;
}
delete [] newVtxLon;
delete [] newVtxLat;
delete [] newVtxLev;
delete [] oldVtxLon;
delete [] oldVtxLat;
delete [] oldVtxLev;
// -------------------------------------------------------------------------
// edges part
edges.create(numEdge);
int *firstPoint = new int[numEdge];
int *secondPoint = new int[numEdge];
file.get_var("first_point_idx")->get(firstPoint, numEdge);
file.get_var("second_point_idx")->get(secondPoint, numEdge);
Edge *edgeMap[edges.size()];
Edge *edge = edges.front();
//.........这里部分代码省略.........
示例4: err
bool
RemapWidget::getVolumeInfo(QString volfile,
int &skipheaderbytes,
uchar &voxelType,
int &voxelUnit,
float &vx, float &vy, float &vz,
QString &description,
QList<float> &rawMap,
QList<uchar> &pvlMap,
int &depth,
int &width,
int &height)
{
NcError err(NcError::verbose_nonfatal);
NcFile pvlFile(volfile.toAscii().data(), NcFile::ReadOnly);
if (!pvlFile.is_valid())
{
QMessageBox::information(0, "Error",
QString("%1 is not a valid preprocessed volume file").arg(volfile));
return false;
}
int i;
NcAtt *att;
char *attval;
QString pvalue;
att = pvlFile.get_att("description");
if (att)
{
attval = att->as_string(0);
description = attval;
delete [] attval;
}
att = pvlFile.get_att("voxeltype");
if (att)
{
attval = att->as_string(0);
pvalue = attval;
if (pvalue == "unsigned char")
voxelType = Raw2Pvl::_UChar;
if (pvalue == "char")
voxelType = Raw2Pvl::_Char;
if (pvalue == "unsigned short")
voxelType = Raw2Pvl::_UShort;
if (pvalue == "short")
voxelType = Raw2Pvl::_Short;
if (pvalue == "int")
voxelType = Raw2Pvl::_Int;
if (pvalue == "float")
voxelType = Raw2Pvl::_Float;
delete [] attval;
}
att = pvlFile.get_att("voxelunit");
if (att)
{
attval = att->as_string(0);
pvalue = attval;
voxelUnit = Raw2Pvl::_Nounit;
if (pvalue == "angstrom")
voxelUnit = Raw2Pvl::_Angstrom;
else if (pvalue == "nanometer")
voxelUnit = Raw2Pvl::_Nanometer;
else if (pvalue == "micron")
voxelUnit = Raw2Pvl::_Micron;
else if (pvalue == "millimeter")
voxelUnit = Raw2Pvl::_Millimeter;
else if (pvalue == "centimeter")
voxelUnit = Raw2Pvl::_Centimeter;
else if (pvalue == "meter")
voxelUnit = Raw2Pvl::_Meter;
else if (pvalue == "kilometer")
voxelUnit = Raw2Pvl::_Kilometer;
else if (pvalue == "parsec")
voxelUnit = Raw2Pvl::_Parsec;
else if (pvalue == "kiloparsec")
voxelUnit = Raw2Pvl::_Kiloparsec;
delete [] attval;
}
att = pvlFile.get_att("gridsize");
if (att)
{
depth = att->as_int(0);
width = att->as_int(1);
height = att->as_int(2);
}
att = pvlFile.get_att("voxelsize");
if (att)
{
vx = att->as_float(0);
vy = att->as_float(1);
vz = att->as_float(2);
//.........这里部分代码省略.........