当前位置: 首页>>代码示例>>C++>>正文


C++ NcVar::num_atts方法代码示例

本文整理汇总了C++中NcVar::num_atts方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::num_atts方法的具体用法?C++ NcVar::num_atts怎么用?C++ NcVar::num_atts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NcVar的用法示例。


在下文中一共展示了NcVar::num_atts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QString

QMap<QString, double> DataInterfaceNetCdfVector::metaScalars(const QString& field)
{
  QMap<QString, double> fieldScalars;
  NcVar *var = netcdf._ncfile->get_var(field.toLatin1().constData());
  fieldScalars["NbAttributes"] = var->num_atts();
  for (int i=0; i<var->num_atts(); ++i) {
    NcAtt *att = var->get_att(i);
    // Only handle char attributes as fieldStrings, the others as fieldScalars
    if (att->type() == NC_BYTE || att->type() == NC_SHORT || att->type() == NC_INT
        || att->type() == NC_LONG || att->type() == NC_FLOAT || att->type() == NC_DOUBLE) {
      // Some attributes may have multiple values => load the first as is, and for the others
      // add a -2, -3, etc... suffix as obviously we can have only one value per scalar.
      // Do it in two steps to avoid a test in the loop while keeping a "clean" name for the first one
      fieldScalars[QString(att->name())] = att->values()->as_double(0);
      for (int j=1; j<att->values()->num(); ++j) {
        fieldScalars[QString(att->name()) + QString("-") + QString::number(j+1)] = att->values()->as_double(j);
      }
    }
  }
  return fieldScalars;
}
开发者ID:,项目名称:,代码行数:21,代码来源:

示例2: read_from_netcdf

void ConstantSet::read_from_netcdf(NcFile &nc, std::string const &vname)
{
	NcVar *ncvar = giss::get_var_safe(nc, vname.c_str(), true);
	if (!ncvar) {
		fprintf(stderr, "ConstantSet::read_from_netcdf() cannot find variable %s\n", vname.c_str());
		throw std::exception();
	}
	int n = ncvar->num_atts();

	// Read through the attributes, getting units and names separately
	std::map<std::string, std::string> units;
	std::map<std::string, double> consts;
	std::map<std::string, std::string> descriptions;
	for (int i=0; i<n; ++i) {
		auto att = giss::get_att(ncvar, i);
		std::string att_name(att->name());
		if (giss::ends_with(att_name, "_description")) {
			descriptions.insert(std::make_pair(
				att_name.substr(0, att_name.size() - std::strlen("_description")),
				std::string(att->as_string(0))));
		} else if (giss::ends_with(att_name, "_units")) {
			units.insert(std::make_pair(
				att_name.substr(0, att_name.size() - std::strlen("_units")),
				std::string(att->as_string(0))));
		} else {
			consts.insert(std::make_pair(
				att_name, att->as_double(0)));
		}
	}

	// Now go through them again, matching up constants and units
	for (auto ii = consts.begin(); ii != consts.end(); ++ii) {
		std::string const &name = ii->first;
		double const val = ii->second;

		auto ui = units.find(name);
		if (ui == units.end()) {
			fprintf(stderr, "Could not find _units attribute for %s\n", name.c_str());
		}

		auto di = descriptions.find(name);
		if (di == descriptions.end()) {
			fprintf(stderr, "Could not find _description attribute for %s\n", name.c_str());
		}

		std::string const &u = units.find(name)->second;
		std::string const &d = descriptions.find(name)->second;

		set(name, val, u, d);
	}
}
开发者ID:seifer08ms,项目名称:icebin,代码行数:51,代码来源:ConstantSet.cpp


注:本文中的NcVar::num_atts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。