changeFmaFormat.cpp 3.55 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>
//
14
#include "Files/FFmaGenericLoader.hpp"
15
#include "Files/FDlpolyLoader.hpp"
COULAUD Olivier's avatar
COULAUD Olivier committed
16 17 18
//
#include "Utils/FGlobal.hpp"
#include "Utils/FPoint.hpp"
19
#include "Utils/FParameters.hpp"
20
#include "Files/FGenerateDistribution.hpp"
21 22
#include "Files/FExportWriter.hpp"

COULAUD Olivier's avatar
COULAUD Olivier committed
23
#include "Utils/FParameterNames.hpp"
24

25
//
COULAUD Olivier's avatar
COULAUD Olivier committed
26
/// \file  changeFmaFormat.cpp
27 28 29
//!
//! \brief changeFormat: Driver to transform a FMA format and to build a visualization file
//!
COULAUD Olivier's avatar
COULAUD Olivier committed
30 31
//!  Driver to transform a FMA format and/or to build a visualization file<br>
//! For a description of the FMA format see FFmaGenericLoader<br>
32 33 34
//!  <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)
35
//!     \param  -fdlpoly name  file coming from a DLpoly simulation
36 37 38 39 40 41 42 43 44 45
//!
//!     \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
//!
46
//!   changeFormat -fin unitCubeXYZQ100.fma  -fout unitCubeXYZQ100 -bin
47

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

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

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

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

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

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

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

74

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