本文整理汇总了C++中NcDim::is_unlimited方法的典型用法代码示例。如果您正苦于以下问题:C++ NcDim::is_unlimited方法的具体用法?C++ NcDim::is_unlimited怎么用?C++ NcDim::is_unlimited使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcDim
的用法示例。
在下文中一共展示了NcDim::is_unlimited方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dumpdims
void DumpableNcFile::dumpdims( void )
{
for (int n=0; n < num_dims(); n++) {
NcDim* dim = get_dim(n);
cout << "\t" << dim->name() << " = " ;
if (dim->is_unlimited())
cout << "UNLIMITED" << " ;\t " << "// " << dim->size() <<
" currently\n";
else
cout << dim->size() << " ;\n";
}
}
示例2: CopyNcVar
void CopyNcVar(
NcFile & ncIn,
NcFile & ncOut,
const std::string & strVarName,
bool fCopyAttributes,
bool fCopyData
) {
if (!ncIn.is_valid()) {
_EXCEPTIONT("Invalid input file specified");
}
if (!ncOut.is_valid()) {
_EXCEPTIONT("Invalid output file specified");
}
NcVar * var = ncIn.get_var(strVarName.c_str());
if (var == NULL) {
_EXCEPTION1("NetCDF file does not contain variable \"%s\"",
strVarName.c_str());
}
NcVar * varOut;
std::vector<NcDim *> dimOut;
dimOut.resize(var->num_dims());
std::vector<long> counts;
counts.resize(var->num_dims());
long nDataSize = 1;
for (int d = 0; d < var->num_dims(); d++) {
NcDim * dimA = var->get_dim(d);
dimOut[d] = ncOut.get_dim(dimA->name());
if (dimOut[d] == NULL) {
if (dimA->is_unlimited()) {
dimOut[d] = ncOut.add_dim(dimA->name());
} else {
dimOut[d] = ncOut.add_dim(dimA->name(), dimA->size());
}
if (dimOut[d] == NULL) {
_EXCEPTION2("Failed to add dimension \"%s\" (%i) to file",
dimA->name(), dimA->size());
}
}
if (dimOut[d]->size() != dimA->size()) {
if (dimA->is_unlimited() && !dimOut[d]->is_unlimited()) {
_EXCEPTION2("Mismatch between input file dimension \"%s\" and "
"output file dimension (UNLIMITED / %i)",
dimA->name(), dimOut[d]->size());
} else if (!dimA->is_unlimited() && dimOut[d]->is_unlimited()) {
_EXCEPTION2("Mismatch between input file dimension \"%s\" and "
"output file dimension (%i / UNLIMITED)",
dimA->name(), dimA->size());
} else if (!dimA->is_unlimited() && !dimOut[d]->is_unlimited()) {
_EXCEPTION3("Mismatch between input file dimension \"%s\" and "
"output file dimension (%i / %i)",
dimA->name(), dimA->size(), dimOut[d]->size());
}
}
counts[d] = dimA->size();
nDataSize *= counts[d];
}
// ncByte / ncChar type
if ((var->type() == ncByte) || (var->type() == ncChar)) {
DataVector<char> data;
data.Initialize(nDataSize);
varOut =
ncOut.add_var(
var->name(), var->type(),
dimOut.size(), (const NcDim**)&(dimOut[0]));
if (varOut == NULL) {
_EXCEPTION1("Cannot create variable \"%s\"", var->name());
}
var->get(&(data[0]), &(counts[0]));
varOut->put(&(data[0]), &(counts[0]));
}
// ncShort type
if (var->type() == ncShort) {
DataVector<short> data;
data.Initialize(nDataSize);
varOut =
ncOut.add_var(
var->name(), var->type(),
dimOut.size(), (const NcDim**)&(dimOut[0]));
if (varOut == NULL) {
_EXCEPTION1("Cannot create variable \"%s\"", var->name());
}
if (fCopyData) {
var->get(&(data[0]), &(counts[0]));
//.........这里部分代码省略.........
示例3: main
int main(int argc, char** argv)
{
if (!cmdline(argc, argv))
{
printhelp();
return EXIT_FAILURE;
}
NcFile infile(infilename.c_str(), NcFile::ReadOnly);
if (!infile.is_valid())
{
std::cerr << "Error: invalid input file -- '" << infilename << "'" << std::endl;
infile.close();
return EXIT_FAILURE;
}
NcFile outfile(outfilename.c_str(), NcFile::Replace);
if (!outfile.is_valid())
{
std::cerr << "Error: cannot open output file -- '" << outfilename << "'" << std::endl;
outfile.close();
return EXIT_FAILURE;
}
if (varstrings.size() == 0)
{
std::cerr << "Warning: no variables specified" << std::endl;
}
std::vector<NcVar*> invars;
for (std::vector<std::string>::const_iterator it = varstrings.begin();
it != varstrings.end(); ++it)
{
NcVar* var = infile.get_var((*it).c_str());
if (var == NULL)
{
std::cerr << "Error: " << *it << ": no such variable" << std::endl;
infile.close();
outfile.close();
return EXIT_FAILURE;
}
invars.push_back(var);
}
// extract the distinct set of dims
std::map<std::string, NcDim*> indims;
for (std::vector<NcVar*>::const_iterator it = invars.begin();
it != invars.end(); ++it)
{
NcVar* var = *it;
for (int i = 0; i < var->num_dims(); ++i)
{
NcDim* dim = var->get_dim(i);
indims[dim->name()] = dim;
}
}
// add dims to outfile
std::map<std::string, NcDim*> outdims;
for (std::map<std::string, NcDim*>::const_iterator it = indims.begin();
it != indims.end(); ++it)
{
NcDim* dim = (*it).second;
NcDim* outdim = NULL;
if (dim->is_unlimited())
{
outdim = outfile.add_dim(dim->name());
}
else
{
outdim = outfile.add_dim(dim->name(), dim->size());
}
if (outdim != NULL)
{
outdims[outdim->name()] = outdim;
}
}
// create variables
for (std::vector<NcVar*>::const_iterator it = invars.begin();
it != invars.end(); ++it)
{
NcVar* var = *it;
std::vector<const NcDim*> dims(var->num_dims());
for (int i = 0; i < var->num_dims(); ++i)
{
dims[i] = outdims[var->get_dim(i)->name()];
}
NcVar* outvar = outfile.add_var(var->name(), var->type(), var->num_dims(), &dims[0]);
// identify largest dim, if dim (nearly) exceeds main memory, split along that dim
int maxdim = -1;
long maxdimsize = 0;
long totallen = 1;
for (int i = 0; i < var->num_dims(); ++i)
{
NcDim* dim = var->get_dim(i);
if (dim->size() > maxdimsize)
{
//.........这里部分代码省略.........