本文整理汇总了C++中NcVar::getVar方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::getVar方法的具体用法?C++ NcVar::getVar怎么用?C++ NcVar::getVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcVar
的用法示例。
在下文中一共展示了NcVar::getVar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openKernelNetcdf
void kernel::openKernelNetcdf () {
// Open the kernel file output from the solver.
using namespace netCDF;
using namespace netCDF::exceptions;
// Local mpi variables.
int myRank = MPI::COMM_WORLD.Get_rank ();
int worldSize = MPI::COMM_WORLD.Get_size ();
if (myRank == 0)
std::cout << "Opening kernel file: " << blu << fileName << rst << " with " << worldSize
<< " processors." << std::flush << std::endl;
try {
// Open the file.
NcFile dataFile (fileName, NcFile::read);
// Get variable.
NcVar NcKernel = dataFile.getVar ("rawKernel");
// Get array sizes.
NcDim procDim = NcKernel.getDim (0);
NcDim kernDim = NcKernel.getDim (1);
numWroteProcs = procDim.getSize ();
numGLLPoints = kernDim.getSize ();
if (myRank == 0)
std::cout << mgn << "Number of solver processers:\t " << numWroteProcs
<< "\nNumber of GLL points:\t\t " << numGLLPoints << rst << "\n" << std::endl;
// Set up the MPI read chunk array.
std::vector<size_t> start;
std::vector<size_t> count;
start.resize(2);
count.resize(2);
// Row major MPI read. Start at [myRank, 0]
start[0] = myRank;
start[1] = 0;
// Read until end of line [myrank, numGLLPoints]
count[0] = 1;
count[1] = numGLLPoints;
// Of course only read in with the number of processors used to create the file.
if (myRank < numWroteProcs) {
rawKernel = new float [numGLLPoints];
NcKernel.getVar (start, count, rawKernel);
}
// Destructor will close file.
} catch (NcException &error) {
std::cout << error.what() << std::endl;
std::cout << red << "Failure reading: " << fileName << std::endl;
std::exit (EXIT_FAILURE);
}
}
示例2: openCoordNetcdf
void kernel::openCoordNetcdf () {
// Open the NetCDF coordinate file output from the solver.
using namespace netCDF;
using namespace netCDF::exceptions;
// Local mpi variables.
int myRank = MPI::COMM_WORLD.Get_rank ();
int worldSize = MPI::COMM_WORLD.Get_size ();
if (myRank == 0)
std::cout << "Opening coordinate file: " << blu << "./krn/xyzCrustMantle.nc" << rst
<< " with " << worldSize << " processors." << std::flush << std::endl;
try {
std::string coordName = "./krn/xyzCrustMantle.nc";
// Open the file.
NcFile dataFile (coordName, NcFile::read);
// Get variable.
NcVar NcRadius = dataFile.getVar ("radius");
NcVar NcTheta = dataFile.getVar ("theta");
NcVar NcPhi = dataFile.getVar ("phi");
// Get array sizes.
NcDim procDim = NcRadius.getDim (0);
NcDim coordDim = NcRadius.getDim (1);
numWroteProcs = procDim.getSize ();
numGLLPoints = coordDim.getSize ();
if (myRank == 0)
std::cout << mgn << "Number of solver processers:\t " << numWroteProcs
<< "\nNumber of GLL points:\t\t " << numGLLPoints << rst << "\n" << std::endl;
// Current error handling. Only can have as many cores as we did for the simulation.
if (worldSize > numWroteProcs) {
if (myRank == 0)
std::cout << red << "Currently, you can only use as many cores for processing as were used "
<< "in the forward run. Exiting.\n" << rst << std::flush << std::endl;
MPI::COMM_WORLD.Abort (EXIT_FAILURE);
exit (EXIT_FAILURE);
}
// Set up the MPI read chunk array.
std::vector<size_t> start;
std::vector<size_t> count;
start.resize(2);
count.resize(2);
// Row major MPI read. Start at [myRank, 0]
start[0] = myRank;
start[1] = 0;
// Read until end of line [myrank, numGLLPoints]
count[0] = 1;
count[1] = numGLLPoints;
// Preallocate cartesian arrays.
xStore = new float [numGLLPoints];
yStore = new float [numGLLPoints];
zStore = new float [numGLLPoints];
// Of course only read in with the number of processors used to create the file.
if (myRank < numWroteProcs) {
radius = new float [numGLLPoints];
theta = new float [numGLLPoints];
phi = new float [numGLLPoints];
NcRadius.getVar (start, count, radius);
NcTheta.getVar (start, count, theta);
NcPhi.getVar (start, count, phi);
}
// Save original arrays.
radiusOrig = new float [numGLLPoints];
thetaOrig = new float [numGLLPoints];
phiOrig = new float [numGLLPoints];
for (size_t i=0; i<numGLLPoints; i++) {
radiusOrig[i] = radius[i];
thetaOrig[i] = theta[i];
phiOrig[i] = phi[i];
}
// Destructor will close file.
} catch (NcException &error) {
std::cout << error.what() << std::endl;
std::cout << red << "Failure reading: " << fileName << std::endl;
std::exit (EXIT_FAILURE);
}
//.........这里部分代码省略.........