Skip to content
Snippets Groups Projects
convertodf.cpp 1.66 KiB
Newer Older
Brown's avatar
Brown committed
#include <iostream>
#include "H5Cpp.h"
Brown's avatar
Brown committed
#include "OdfIO.h"
#include "Hdf5IO.h"
Brown's avatar
Brown committed

int main(int argc, char const *argv[])
{
    // -------------------------------------------------------------------------
    // --- Grabbing the input args
    // -------------------------------------------------------------------------
    if( argc < 3 ){
        std::cerr << "Wrong number of arguments given." << std::endl
                  << "Specify input ODF file and output HDF5 file." << std::endl;
        return -1;
    }
    
    std::string  odfFilename = argv[1];
    std::string hdf5Filename = argv[2];

    std::cout << "Reading from file: " << odfFilename << std::endl;
    std::cout << "Writing to file:   " << hdf5Filename << std::endl;

    // -------------------------------------------------------------------------
    // --- Read ODF file
    // -------------------------------------------------------------------------
Brown's avatar
Brown committed
    sammy::OdfIO odf;
Brown's avatar
Brown committed
    std::vector<std::vector<double>> data;

    // --- Open file ---
    std::ifstream in( odfFilename, std::ios::in | std::ios::binary );
    // --- kill bad open  ---
    if( !in.is_open() ){
        std::cerr << "Error opening file: " << odfFilename << std::endl;
        return 1;
    }

Brown's avatar
Brown committed
    int unix = false;
Brown's avatar
Brown committed
    // --- read header ---
Brown's avatar
Brown committed
    odf.readHeader(in,unix);
Brown's avatar
Brown committed

    // --- read data sections ---
Brown's avatar
Brown committed
    data = odf.getAllSections(in);
Brown's avatar
Brown committed

    in.close();

    // -------------------------------------------------------------------------
    // --- Output HDF5 file
    // -------------------------------------------------------------------------

Brown's avatar
Brown committed
    sammy::Hdf5IO h5writer;
    h5writer.writeODFtoHDF5(odf.getHeader(),data,hdf5Filename);
Brown's avatar
Brown committed

    return 0;
}