本文整理汇总了C++中NcAtt::as_double方法的典型用法代码示例。如果您正苦于以下问题:C++ NcAtt::as_double方法的具体用法?C++ NcAtt::as_double怎么用?C++ NcAtt::as_double使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcAtt
的用法示例。
在下文中一共展示了NcAtt::as_double方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
varOutLon->put(&(dLon[0]), nLon);
CopyNcVarAttributes(varLon, varOutLon);
// Output topography
Announce("Topography");
NcVar * varOutZs = ncdf_out.add_var(
"Zs", ncDouble, dimOutLat, dimOutLon);
varOutZs->set_cur((long)0, (long)0);
varOutZs->put(&(dZs[0][0]), nLat, nLon);
AnnounceEndBlock("Done");
// Done
AnnounceEndBlock("Done");
// Load all variables
Announce("Loading variables");
std::vector<NcVar *> vecNcVar;
for (int v = 0; v < vecVariableStrings.size(); v++) {
vecNcVar.push_back(ncdf_in.get_var(vecVariableStrings[v].c_str()));
if (vecNcVar[v] == NULL) {
_EXCEPTION1("Unable to load variable \"%s\" from file",
vecVariableStrings[v].c_str());
}
}
// Physical constants
Announce("Initializing thermodynamic variables");
NcAtt * attEarthRadius = ncdf_in.get_att("earth_radius");
double dEarthRadius = attEarthRadius->as_double(0);
NcAtt * attRd = ncdf_in.get_att("Rd");
double dRd = attRd->as_double(0);
NcAtt * attCp = ncdf_in.get_att("Cp");
double dCp = attCp->as_double(0);
double dGamma = dCp / (dCp - dRd);
NcAtt * attP0 = ncdf_in.get_att("P0");
double dP0 = attP0->as_double(0);
double dPressureScaling = dP0 * std::pow(dRd / dP0, dGamma);
NcAtt * attZtop = ncdf_in.get_att("Ztop");
double dZtop = attZtop->as_double(0);
// Input data
DataArray3D<double> dataIn(nLev, nLat, nLon);
DataArray3D<double> dataInt(nILev, nLat, nLon);
// Output data
DataArray2D<double> dataOut(nLat, nLon);
// Pressure in column
DataArray1D<double> dataColumnP(nLev);
// Height in column
DataArray1D<double> dataColumnZ(nLev);
DataArray1D<double> dataColumnIZ(nILev);
// Column weights