//
// Copyright (C) 2011 Proteomics Center,
//                    Children's Hospital Boston, Boston, MA 02115
//                    Mathias Wilhelm, Marc Kirchner
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "pwiz/data/msdata/MSDataFile.hpp"
#include <iostream>

using namespace std;
using namespace pwiz::msdata;

void convertToMz5(const string& filename)
{
    // read input file (mzXML, mzML, mz5, RAW, ...)
    MSDataFile msd(filename);
    // create write configuration object
    MSDataFile::WriteConfig writeConfig;
    // set default precision to 64 bit
    writeConfig.binaryDataEncoderConfig.precision
            = BinaryDataEncoder::Precision_64;
    // enable zlib compression
    writeConfig.binaryDataEncoderConfig.compression
            = BinaryDataEncoder::Compression_Zlib;
    // set output format to mz5
    writeConfig.format = MSDataFile::Format_MZ5;
    // write ms data object in mz5 format to filename.mz5
    MSDataFile::write(msd, filename + ".mz5", writeConfig);
}

int main(int argc, char* argv[])
{
    try {
        if (argc != 2)
            throw runtime_error(
                    "Usage: convertToMz5 filename");
        convertToMz5(argv[1]);
        return 0;
    } catch (exception& e) {
        cerr << e.what() << endl;
    } catch (...) {
        cerr << "Caught unknown exception.\n";
    }
    return 1;
}