changeFmaFormat.cpp 3.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * genarateDistributions.cpp
 *
 *  Created on: 23 mars 2014
 *      Author: Olivier Coulaud
 */


#include <iostream>
#include <fstream>
#include <string>
COULAUD Olivier's avatar
COULAUD Olivier committed
12 13
#include <cstdlib>
//
COULAUD Olivier's avatar
COULAUD Olivier committed
14 15
//
#include "Utils/FGlobal.hpp"
COULAUD Olivier's avatar
COULAUD Olivier committed
16

17
#include "Utils/FParameters.hpp"
COULAUD Olivier's avatar
COULAUD Olivier committed
18 19 20
#include "Utils/FParameterNames.hpp"

#include "Files/FFmaGenericLoader.hpp"
21 22
#include "Files/FExportWriter.hpp"

23

24
//
COULAUD Olivier's avatar
COULAUD Olivier committed
25
/// \file  changeFmaFormat.cpp
26 27 28
//!
//! \brief changeFormat: Driver to transform a FMA format and to build a visualization file
//!
COULAUD Olivier's avatar
COULAUD Olivier committed
29 30
//!  Driver to transform a FMA format and/or to build a visualization file<br>
//! For a description of the FMA format see FFmaGenericLoader<br>
31 32 33
//!  <b> General arguments:</b>
//!     \param   -help (-h)      to see the parameters available in this driver
//!     \param   -fin name:  file name  to convert (with extension .fma (ascii) or bfma (binary)
34
//!     \param  -fdlpoly name  file coming from a DLpoly simulation
35 36 37 38 39 40 41 42 43 44
//!
//!     \param   -fout name: generic name for files (without extension) and save data
//!                  with following format in name.fma or name.bfma if -bin is set"
//!      \param   -bin save output in binary mode (name file  name.bfma
//!
//!
//! \b examples
//!
//!  Transform an ascii file in a binary file
//!
45
//!   changeFormat -fin unitCubeXYZQ100.fma  -fout unitCubeXYZQ100 -bin
46

47
//    \param  -visufmt format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default
48 49

int main(int argc, char ** argv){
50

51 52 53 54
    FHelpDescribeAndExit(argc, argv,
                         "Driver to change the format of the input file. "
                         "fdlpoly is not supported for now.",
                         FParameterDefinitions::InputFile, FParameterDefinitions::OutputFile,
55
                         FParameterDefinitions::OutputVisuFile);
56
    typedef double FReal;
57
    const std::string filename(FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options,   "data.fma"));
58

59 60 61
    FFmaGenericLoader<FReal> loader(filename);

    const FSize NbPoints  = loader.getNumberOfParticles();
62
    const unsigned int nbData   = loader.getNbRecordPerline() ;
63
    const FSize arraySize =nbData*NbPoints;
64 65

    FReal * particles = new FReal[arraySize] ;
66
    std::memset(particles,0,arraySize*sizeof(FReal));
67

68 69
    FSize j = 0 ;
    for(FSize idxPart = 0 ; idxPart < NbPoints ;++idxPart, j+=nbData){
70
        loader.fillParticle(&particles[j],nbData);
71
    }
72

73

74 75 76 77 78 79
    /////////////////////////////////////////////////////////////////////////
    //                                           Save data
    /////////////////////////////////////////////////////////////////////////
    //
    //  Generate file for ScalFMM FMAGenericLoader
    //
80
    if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputFile.options)){
81
        std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options,   "output.fma"));
82 83
          FFmaGenericWriter<FReal> writer(name) ;
        writer.writeHeader( loader.getCenterOfBox(), loader.getBoxWidth() , NbPoints, sizeof(FReal), nbData) ;
84
        writer.writeArrayOfReal(particles, nbData, NbPoints);
85 86 87 88
    }
    //
    //   Generate file for visualization purpose
    //
89
    if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
90
        std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options,   "output.vtp"));
91
        driverExportData(outfilename, particles , NbPoints,loader.getNbRecordPerline() );
92 93
    }
    //
94
    delete[] particles ;
95
    return 0;
96
}