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


C++ Attributes::keyAt方法代码示例

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


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

示例1: main


//.........这里部分代码省略.........
    std::map<Cell, Boundary> chains = chainComplex(complex, field);

    std::vector<Cell> const sources =
        criticalCellsSorted(complex, scalars, field);
    size_t const n = sources.size();

    SimpleComplex const simple = simpleChainComplex(
        complex, scalars, chains, sources);

    std::vector<Pairing<Cell> > const pairs = persistencePairing(simple);

    // Generate metadata
    std::string const parentID = guessDatasetID(fieldPath, info.attributes());
    std::string const thisID   = derivedID(parentID, "persistence", "PP");

    std::string const outfile =
        argc > 3 ? argv[3] : (stripTimestamp(thisID) + ".txt");

    js::Array const predecessors = js::Array
        (parentID)
        (guessDatasetID(scalarPath, readFileInfo(scalarPath).attributes()));

    js::Object const description = js::Object
        ("id"          , thisID)
        ("process"     , "Critical Cell Persistence Pairs")
        ("sourcefile"  , __FILE__)
        ("revision"    , js::Object("id", GIT_REVISION)("date", GIT_TIMESTAMP))
        ("parent"      , parentID)
        ("predecessors", predecessors)
        ("parameters"  , js::Object());

    // Write data
    std::stringstream tmp;

    tmp << "# Persistence pairs for " << scalarPath
        << std::endl
        << "#   format: <birth> <death> <dimension> <creator xyz> <destructor xyz>"
        << std::endl;

    for (size_t i = 0; i < pairs.size(); ++i)
    {
        size_t const j = pairs.at(i).partner;

        if (j > i)
        {
            Cell const v = sources.at(i);
            Cell const w = j >= n ? sources.at(i) : sources.at(j);

            tmp << std::fixed << std::setprecision(6);

            tmp << std::setw(12) << cellValue(v, scalars, vertices) << " "
                << std::setw(12);

            if (w == v)
                tmp << "inf";
            else
                tmp << cellValue(w, scalars, vertices);

            tmp << "    "
                << complex.cellDimension(v) << "    "
                << complex.cellPosition(v) << "    ";

            if (w == v)
                tmp << "   -      -      -  ";
            else
                tmp << complex.cellPosition(w);

            tmp << std::endl;
        }
    }

    std::ofstream ofs(outfile.c_str());
    ofs << tmp.str();

    // Write metadata
    ofs << "#" << std::endl
        << "# Metadata:" << std::endl;

    Attributes const attr = inheritableAttributes(info.attributes());
    for (size_t i = 0; i < attr.size(); ++i)
    {
        std::string const key = attr.keyAt(i);
        ofs << "#" << std::endl
            << "#+ " << key << std::endl;
        if (key == "dataset_id")
            ofs << "#= " << thisID << std::endl;
        else if (key == "zdim_total")
            ofs << "#= " << dims.at(2) << std::endl;
        else if (key == "number_of_files")
            ofs << "#= 1" << std::endl;
        else if (key == "zdim_range")
            ofs << "#= 0, " << dims.at(2)-1 << std::endl;
        else
            printWithPrefix(ofs, attr(key).valuesAsString(), "#= ");
    }

    ofs << "#" << std::endl
        << "#+ " << "history_"+thisID << std::endl;
    ofs << js::toString(description, 2, "#= ") << std::endl;
}
开发者ID:AppliedMathematicsANU,项目名称:diamorse,代码行数:101,代码来源:PersistencePairs.C

示例2: main

int main(int argc, char* argv[])
{
    char* infile = argv[1];

    if (argc < 2)
    {
        std::cerr << "Usage:" << argv[0] << " INPUT" << std::endl;
        return 1;
    }

    FileBuffer data(infile);
    NCFile<FileBuffer> file(data);

    std::vector<Dimension> const dims  = file.dimensions();
    std::vector<Variable>  const vars  = file.variables();
    Attributes const attrs = file.attributes();
    size_t i;

    std::cout << "netcdf " << stripname(infile) << " {" << std::endl;

    std::cout << "dimensions:" << std::endl;
    for (i = 0; i < dims.size(); ++i)
    {
        Dimension d = dims.at(i);
        std::cout << "\t" << d.name << " = " << d.size
                  << " ;" << std::endl;
    }
    std::cout << std::endl;

    std::cout << "variables:" << std::endl;
    for (i = 0; i < vars.size(); ++i)
    {
        Variable v = vars.at(i);
        std::cout << "\t" << tname(v.type()) << " " << v.name()
                  << "(" << toString(v.dimensionNames())
                  << ") ;" << std::endl;

        Attributes const attrs = v.attributes();
        for (size_t j = 0; j < attrs.size(); ++j)
        {
            Attribute a = attrs.at(j);
            std::cout << "\t\t" << v.name() << ":" << attrs.keyAt(j) << " = "
                      << formatString(a.valuesAsString())
                      << " ;" << std::endl;
        }
    }
    std::cout << std::endl;

    std::cout << "// global attributes:" << std::endl;
    for (i = 0; i < attrs.size(); ++i)
    {
        Attribute a = attrs.at(i);
        std::cout << "\t\t:" << attrs.keyAt(i) << " = "
                  << formatString(a.valuesAsString())
                  << " ;" << std::endl;
    }
    std::cout << std::endl;

    std::cout << "data:" << std::endl;
    for (i = 0; i < vars.size(); ++i)
    {
        Variable v = vars.at(i);
        std::cout << std::endl << " " << v.name() << " =" << std::endl;
        std::cout << "  " << file.valueAsString(v, 0, 0, 0)
                  << ", " << file.valueAsString(v, 1, 0, 0)
                  << ", " << file.valueAsString(v, 2, 0, 0)
                  << ", " << file.valueAsString(v, 3, 0, 0)
                  << ", " << file.valueAsString(v, 4, 0, 0)
                  << ", ... ;"
                  << std::endl;
    }

    std::cout << "}" << std::endl;
}
开发者ID:lzs203511,项目名称:diamorse,代码行数:74,代码来源:ncdump.C


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