本文整理汇总了C++中NcVar::rec_size方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::rec_size方法的具体用法?C++ NcVar::rec_size怎么用?C++ NcVar::rec_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcVar
的用法示例。
在下文中一共展示了NcVar::rec_size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: samplesPerFrame
int NetcdfSource::samplesPerFrame(const QString& field) {
if (field.toLower() == "index") {
return 1;
}
QByteArray bytes = field.toLatin1();
NcVar *var = _ncfile->get_var(bytes.constData());
if (!var) {
return 0;
}
return var->rec_size();
}
示例2: initFile
bool NetcdfSource::initFile() {
_ncfile = new NcFile(_filename.toUtf8().data(), NcFile::ReadOnly);
if (!_ncfile->is_valid()) {
qDebug() << _filename << ": failed to open in initFile()" << endl;
return false;
}
KST_DBG qDebug() << _filename << ": building field list" << endl;
_fieldList.clear();
_fieldList += "INDEX";
int nb_vars = _ncfile->num_vars();
KST_DBG qDebug() << nb_vars << " vars found in total" << endl;
_maxFrameCount = 0;
for (int i = 0; i < nb_vars; i++) {
NcVar *var = _ncfile->get_var(i);
if (var->num_dims() == 0) {
_scalarList += var->name();
} else if (var->num_dims() == 1) {
_fieldList += var->name();
int fc = var->num_vals() / var->rec_size();
_maxFrameCount = qMax(_maxFrameCount, fc);
_frameCounts[var->name()] = fc;
} else if (var->num_dims() == 2) {
_matrixList += var->name();
}
}
// Get strings
int globalAttributesNb = _ncfile->num_atts();
for (int i = 0; i < globalAttributesNb; ++i) {
// Get only first value, should be enough for a start especially as strings are complete
NcAtt *att = _ncfile->get_att(i);
if (att) {
QString attrName = QString(att->name());
char *attString = att->as_string(0);
QString attrValue = QString(att->as_string(0));
delete[] attString;
//TODO port
//KstString *ms = new KstString(KstObjectTag(attrName, tag()), this, attrValue);
_stringList += attrName;
}
delete att;
}
// TODO update(); // necessary? slows down initial loading
return true;
}
示例3: lastUpdateResult
Kst::Object::UpdateType NetcdfSource::internalDataSourceUpdate() {
//TODO port
/*
if (KstObject::checkUpdateCounter(u)) {
return lastUpdateResult();
}
*/
_ncfile->sync();
bool updated = false;
/* Update member variables _ncfile, _maxFrameCount, and _frameCounts
and indicate that an update is needed */
int nb_vars = _ncfile->num_vars();
for (int j = 0; j < nb_vars; j++) {
NcVar *var = _ncfile->get_var(j);
int fc = var->num_vals() / var->rec_size();
_maxFrameCount = qMax(_maxFrameCount, fc);
updated = updated || (_frameCounts[var->name()] != fc);
_frameCounts[var->name()] = fc;
}
return updated ? Object::Updated : Object::NoChange;
}
示例4: readField
int NetcdfSource::readField(double *v, const QString& field, int s, int n) {
NcType dataType = ncNoType; /* netCDF data type */
/* Values for one record */
NcValues *record = 0;// = new NcValues(dataType,numFrameVals);
KST_DBG qDebug() << "Entering NetcdfSource::readField with params: " << field << ", from " << s << " for " << n << " frames" << endl;
/* For INDEX field */
if (field.toLower() == "index") {
if (n < 0) {
v[0] = double(s);
return 1;
}
for (int i = 0; i < n; ++i) {
v[i] = double(s + i);
}
return n;
}
/* For a variable from the netCDF file */
QByteArray bytes = field.toLatin1();
NcVar *var = _ncfile->get_var(bytes.constData()); // var is owned by _ncfile
if (!var) {
KST_DBG qDebug() << "Queried field " << field << " which can't be read" << endl;
return -1;
}
dataType = var->type();
if (s >= var->num_vals() / var->rec_size()) {
return 0;
}
bool oneSample = n < 0;
int recSize = var->rec_size();
switch (dataType) {
case ncShort:
{
if (oneSample) {
record = var->get_rec(s);
v[0] = record->as_short(0);
delete record;
} else {
for (int i = 0; i < n; i++) {
record = var->get_rec(i+s);
for (int j = 0; j < recSize; j++) {
v[i*recSize + j] = record->as_short(j);
}
delete record;
}
}
}
break;
case ncInt:
{
if (oneSample) {
record = var->get_rec(s);
v[0] = record->as_int(0);
delete record;
} else {
for (int i = 0; i < n; i++) {
record = var->get_rec(i+s);
KST_DBG qDebug() << "Read record " << i+s << endl;
for (int j = 0; j < recSize; j++) {
v[i*recSize + j] = record->as_int(j);
}
delete record;
}
}
}
break;
case ncFloat:
{
if (oneSample) {
record = var->get_rec(s);
v[0] = record->as_float(0);
delete record;
} else {
for (int i = 0; i < n; i++) {
record = var->get_rec(i+s);
for (int j = 0; j < recSize; j++) {
v[i*recSize + j] = record->as_float(j);
}
delete record;
}
}
}
break;
case ncDouble:
{
if (oneSample) {
record = var->get_rec(s);
v[0] = record->as_double(0);
delete record;
} else {
for (int i = 0; i < n; i++) {
//.........这里部分代码省略.........