예제 #1
0
bool FileCSV::read(TimeSeries &ts, int valuesColumn, int timeColumn)
{
    if (!isOpen() ||
            valuesColumn < 0 || valuesColumn >= (int)m_header.size() ||
            timeColumn < 0   || timeColumn >= (int)m_header.size())
        return false;

    seekRow(0);

    Row row;
    ReadResult rr;

    FL::TimeSeries::Data values, time;

    while ( (rr = readRow(row)) == rrOK )
    {
        values.push_back(row[valuesColumn]);
        time.push_back(row[timeColumn]);
    }

    ts.setData(values, time);
    ts.header()[0] = m_header[valuesColumn];
    ts.header()[1] = m_header[timeColumn];

    return rr == rrEmpty;
}
예제 #2
0
bool FileCSV::save(const std::string &fileName, TimeSeries &ts)
{
    std::ofstream file(fileName.c_str());
    if (!file.is_open())
        return false;

    // Write header
    for (unsigned int i = 0; i < ts.header().size(); ++i)
    {
        file << ts.header()[i];
        if (i < ts.header().size() - 1)
            file << m_separator;
    }

    // Write data
    for (int row = 0; row < ts.size(); ++row)
    {
        file << std::endl << ts.time(row) << m_separator << ts.value(row);
    }
    file << std::endl;
    file.close();

    return true;
}