Commit 483333ad authored by COULAUD Olivier's avatar COULAUD Olivier

New management of input, output data format.

For visualization data file the format is specified by the extension of the file name.
parent 26a2aa07
......@@ -18,6 +18,8 @@
#include "Utils/FPoint.hpp"
#include "Utils/FParameters.hpp"
#include "Utils/FGenerateDistribution.hpp"
#include "Files/FExportWriter.hpp"
#include "Utils/FParameterNames.hpp"
//
......@@ -35,7 +37,6 @@
//! \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
//! \param -visufmt format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default
//!
//!
//! \b examples
......@@ -44,6 +45,7 @@
//!
//! changeFormat -fin unitCubeXYZQ100.fma -fout unitCubeXYZQ100 -bin
// \param -visufmt format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default
int main(int argc, char ** argv){
......@@ -51,8 +53,7 @@ int main(int argc, char ** argv){
"Driver to change the format of the input file. "
"fdlpoly is not supported for now.",
FParameterDefinitions::InputFile, FParameterDefinitions::OutputFile,
FParameterDefinitions::OutputVisuFile,FParameterDefinitions::FormatVisuFile,
FParameterDefinitions::OutputBinFormat);
FParameterDefinitions::OutputVisuFile);
FSize NbPoints;
FReal * particles = nullptr ;
......@@ -86,19 +87,8 @@ int main(int argc, char ** argv){
// Generate file for ScalFMM FMAGenericLoader
//
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputFile.options)){
std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output"));
std::string ext(".");
if(name.find(ext) !=std::string::npos) {
std::cout << "No file with extension permitted for output name : " << name << std::endl;
exit(-1);
}
if( FParameters::existParameter(argc, argv, FParameterDefinitions::OutputBinFormat.options)){
name += ".bfma";
}
else {
name += ".fma";
}
FFmaGenericWriter writer(name) ;
std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.fma"));
FFmaGenericWriter writer(name) ;
writer.writeHeader( loader->getCenterOfBox(), loader->getBoxWidth() , NbPoints, sizeof(FReal), nbData) ;
writer.writeArrayOfReal(particles, nbData, NbPoints);
}
......@@ -106,53 +96,8 @@ int main(int argc, char ** argv){
// Generate file for visualization purpose
//
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output"));
std::string visufile(""), fmt(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options, "vtp"));
if( fmt == "vtp" ){
visufile = outfilename + ".vtp" ;
}
else if( fmt == "vtk" ){
visufile = outfilename + ".vtk" ;
}
else if( fmt == "cosmo" ){
if(nbData !=4) {
std::cerr << "Cosmos export accept only 4 data per particles. here: "<<nbData<<std::endl;
std::exit(EXIT_FAILURE);
}
visufile = outfilename + ".cosmo" ;
}
else {
visufile = outfilename + ".csv" ;
}
std::ofstream file( visufile, std::ofstream::out);
if(!file) {
std::cout << "Cannot open file."<< std::endl;
exit(-1) ;
} //
//
// Export data in cvs format
//
if( fmt == "vtp" ){
std::cout << "Writes in XML VTP format (visualization) in file "<< visufile <<std::endl ;
if(nbData==4){
exportVTKxml( file, particles, NbPoints) ;
}
else {
exportVTKxml( file, particles, NbPoints,nbData) ;
}
}
else if( fmt == "vtk" ){
std::cout << "Writes in VTK format (visualization) in file "<< visufile <<std::endl ;
exportVTK( file, particles, NbPoints,nbData) ;
}
else if( fmt == "cosmo" ){
std::cout << "Writes in COSMO format (visualization) in file "<< visufile <<std::endl ;
exportCOSMOS( file, particles, NbPoints) ;
}
else {
std::cout << "Writes in CVS format (visualization) in file "<<visufile<<std::endl ;
exportCVS( file, particles, NbPoints,nbData) ;
}
std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.vtp"));
driverExportData(outfilename, particles , NbPoints);
}
//
delete particles ;
......
......@@ -16,6 +16,7 @@
#include "Utils/FPoint.hpp"
#include "Utils/FGenerateDistribution.hpp"
#include "Files/FFmaGenericLoader.hpp"
#include "Files/FExportWriter.hpp"
#include "Utils/FParameterNames.hpp"
......@@ -74,6 +75,10 @@
int main(int argc, char ** argv){
const FParameterNames LocalOptionEllipsoid = {
{"-ellipsoid"} ,
" non uniform distribution on an ellipsoid of aspect ratio given by \n -ar a:b:c with a, b and c > 0\n"
};
FHelpDescribeAndExit(argc, argv,
">> Driver to generate N points (non)uniformly distributed on a given geometry.\n"
"Options \n"
......@@ -97,12 +102,13 @@ int main(int argc, char ** argv){
" -radius R - default value 10.0\n"
" Physical values\n"
" -charge generate physical values between -1 and 1 otherwise generate between 0 and 1 \n"
" -zeromean the average of the physical values is zero \n"
" Output \n"
" -filename name: generic name for files (without extension) and save data\n"
" with following format in name.fma or name.bfma in -bin is set\n"
" -visufmt vtk, vtp, cosmo or cvs format.",
FParameterDefinitions::InputFile, FParameterDefinitions::OutputBinFormat, FParameterDefinitions::NbParticles);
" -zeromean the average of the physical values is zero \n",
// " Output \n"
// " -filename name: generic name for files (without extension) and save data\n"
// " with following format in name.fma or name.bfma in -bin is set\n"
// " -visufmt vtk, vtp, cosmo or cvs format.",
FParameterDefinitions::OutputFile,
FParameterDefinitions::NbParticles,FParameterDefinitions::OutputVisuFile,LocalOptionEllipsoid);
......@@ -188,14 +194,16 @@ int main(int argc, char ** argv){
std::cout << "A: "<<A<<" B "<< B << " C: " << C<<std::endl;
unifRandonPointsOnProlate(NbPoints,A,C,particles);
BoxWith = 2.0*C;
}
} //const int NbPoints = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 20000);
else if(FParameters::existParameter(argc, argv, "-ellipsoid")){
// else if(FParameters::existParameter(argc, argv, "-ellipsoid")){
std::string dd(":"),aspectRatio = FParameters::getStr(argc,argv,"-ar", "1:1:2");
// std::string dd(":"),aspectRatio = FParameters::getStr(argc,argv,"-ar", "1:1:2");
FReal A,B,C ;
size_t pos = aspectRatio.find(":"); aspectRatio.replace(pos,1," ");
pos = aspectRatio.find(":"); aspectRatio.replace(pos,1," ");
std::stringstream ss(aspectRatio); ss >>A >> B >> C ;
// std::cout << "A: "<<A<<" B "<< B << " C: " << C<<std::endl;
std::cout << "A: "<<A<<" B "<< B << " C: " << C<<std::endl;
nonunifRandonPointsOnElipsoid(NbPoints,A,B,C,particles);
BoxWith = 2.0*FMath::Max( A,FMath::Max( B,C)) ;
}
......@@ -220,14 +228,7 @@ int main(int argc, char ** argv){
BoxWith += 2*extraRadius ;
}
std::string name(genericFileName);
if( FParameters::existParameter(argc, argv, FParameterDefinitions::OutputBinFormat.options)){
name += ".bfma";
}
else {
name += ".fma";
}
std::cout << "Write "<< NbPoints <<" Particles in file " << name <<std::endl;
std::cout << "Write "<< NbPoints <<" Particles in file " << name << std::endl;
FFmaGenericWriter writer(name) ;
writer.writeHeader(Centre,BoxWith, NbPoints, *ppart) ;
writer.writeArrayOfParticles(ppart, NbPoints);
......@@ -237,43 +238,8 @@ int main(int argc, char ** argv){
// Generate file for visualization
//
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
std::string visufile(""), fmt(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options, "vtp"));
if( fmt == "vtp" ){
visufile = genericFileName + ".vtp" ;
}
else if( fmt == "vtk" ){
visufile = genericFileName + ".vtk" ;
}
else if( fmt == "cosmo" ){
visufile = genericFileName + ".cosmo" ;
}
else {
visufile = genericFileName + ".csv" ;
}
std::ofstream file( visufile.c_str(), std::ofstream::out);
if(!file) {
std::cout << "Cannot open file."<< std::endl;
exit(-1) ;
} //
//
// Export data in VTK format
//
if( fmt == "vtp" ){
std::cout << "Writes in XML VTP format (visualization) in file "<< visufile <<std::endl ;
exportVTKxml( file, particles, NbPoints) ;
}
else if( fmt == "vtk" ){
std::cout << "Writes in VTK format (visualization) in file "<< visufile <<std::endl ;
exportVTK( file, particles, NbPoints) ;
}
else if( fmt == "cosmo" ){
std::cout << "Writes in COSMO format (visualization) in file "<< visufile <<std::endl ;
exportCOSMOS( file, particles, NbPoints) ;
}
else {
std::cout << "Writes in CVS format (visualization) in file "<<visufile<<std::endl ;
exportCVS( file, particles, NbPoints) ;
}
std::string visufile(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options, "output.vtp"));
driverExportData(visufile, particles , NbPoints);
}
//
delete [] particles ;
......
// ===================================================================================
// Copyright ScalFmm 2014 INRIA
//
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#ifndef FEXPORTDATA_HPP
#define FEXPORTDATA_HPP
// @author O. Coulaud
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
//! \fn void exportCVS(std::ofstream& file, const FReal * particles , const int N, const int nbDataPerParticle=4)
//! \brief Export particles in CVS Format
//!
//! Export particles in CVS Format as follow
//! x , y , z , physicalValue, P, FX, FY, FY
//! It is useful to plot the distribution with paraView
//!
//! @param file stream to save the data
//! @param N number of particles
//! @param particles array of particles of type FReal (float or double) Its size is N*nbDataPerParticle
//! @param nbDataPerParticle number of values per particles (default value 4)
//!
void exportCVS(std::ofstream& file, const FReal * particles , const int N, const int nbDataPerParticle=4){
int j = 0;
if (nbDataPerParticle==4){
file << " x , y , z, q " <<std::endl;
}
else {
file << " x , y , z, q P FX FY FZ" <<std::endl;
}
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
file << particles[j] ;
for (int k = 1 ; k< nbDataPerParticle ; ++k) {
file << " , " << particles[j+k] ;
}
file << std::endl;
}
}
//
//! \fn void exportCOSMOS(std::ofstream& file, const FReal * particles, const int N )
//! \brief Export particles in COSMOS Format
//!
//! Export particles in CVS Format as follow
//! x , y , z , 0.0, 0.0, 0.0, physicalValue
//!
//! @param file stream to save the data
//! @param particles array of particles of type FReal (float or double) Its size is 4*N (X,Y,Z,M)
//! @param N number of particles
//!
void exportCOSMOS(std::ofstream& file, const FReal * particles , const int N){
int j = 0;
file << " x , y , z, q " <<std::endl;
for(int i = 0 ; i< N; ++i, j+=4){
file << particles[j] << " " << particles[j+1] << " " << particles[j+2] << " 0.0 0.0 0.0 " << particles[j+3] <<" " << i << std::endl;
}
}
//
//
//! \fn void exportVTK(std::ofstream& file, const FReal * particles, const int N )
//! \brief Export particles in CVS Format
//!
//! Export particles in old polydata Format.
//! A particle is composed of 4 fields x , y , z , physicalValue
//! It is useful to plot the distribution with paraView
//!
//! @param file stream to save the data
//! @param particles array of particles of type FReal (float or double) Its size is 4*N (X,Y,Z,M)
//! @param N number of particles
//!
void exportVTK(std::ofstream& VTKfile, const FReal * particles, const int N, const int nbDataPerParticle=4 ){
int j = 0;
//---------------------------
// print generic information
//---------------------------
VTKfile << "# vtk DataFile Version 3.0" << "\n";
VTKfile << "# Generated bt exportVTK" << "\n";
VTKfile << "ASCII" << "\n";
VTKfile << "DATASET POLYDATA" << "\n";
//
//---------------------------------
// print nodes ordered by their TAG
//---------------------------------
VTKfile << "POINTS " << N << " float" << "\n";
//
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j] << " " << particles[j+1] << " " << particles[j+2] <<std::endl;
}
// ------------------------------------------
VTKfile << "\n";
VTKfile << "VERTICES " << N << " " << 2*N << "\n";
for(int i = 0 ; i< N; ++i){
VTKfile << " 1 " << " " <<i<<std::endl;
}
VTKfile << "POINT_DATA " << N << "\n";
VTKfile << "SCALARS PhysicalValue float 1" << "\n"
<< "LOOKUP_TABLE default" << "\n" ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j+3] << " " <<std::endl;
}
VTKfile << "\n";
};
//
//
//! \fn void exportVTKxml(std::ofstream& file, const FReal * particles, const int N )
//! \brief Export particles in xml polydata VTK Format
//!
//! Export particles in the xml polydata VTK Format.
//! A particle is composed of 4 fields x , y , z , physicalValue
//! It is useful to plot the distribution with paraView
//!
//! @param file stream to save the data
//! @param particles array of particles of type FReal (float or double) Its size is 4*N (X,Y,Z,M)
//! @param N number of particles
//!
void exportVTKxml(std::ofstream& VTKfile, const FReal * particles, const int N ){
int j = 0;
VTKfile << "<?xml version=\"1.0\"?>" <<std::endl
<< "<VTKFile type=\"PolyData\" version=\"0.1\" byte_order=\"LittleEndian\"> "<<std::endl
<< "<PolyData>"<<std::endl
<< "<Piece NumberOfPoints=\" " << N << " \" NumberOfVerts=\" "<<N <<" \" NumberOfLines=\" 0\" NumberOfStrips=\"0\" NumberOfPolys=\"0\">"<<std::endl
<< "<Points>"<<std::endl
<< "<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\"> "<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << particles[j] << " " << particles[j+1] << " " << particles[j+2] << " " ;
}
VTKfile <<std::endl<< "</DataArray> "<<std::endl
<< "</Points> "<<std::endl
<< "<PointData Scalars=\"PhysicalValue\" > "<<std::endl
<< "<DataArray type=\"Float64\" Name=\"PhysicalValue\" format=\"ascii\">"<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << particles[j+3] << " " ;
}
VTKfile <<std::endl << "</DataArray>"<<std::endl
<< " </PointData>"<<std::endl
<< " <CellData>"<<" </CellData>"<<std::endl
<< " <Verts>"<<std::endl
<< " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"<<std::endl ;
for(int i = 0 ; i< N; ++i){
VTKfile << i << " " ;
}
VTKfile<<std::endl << "</DataArray>" <<std::endl
<< "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"<<std::endl ;
for(int i = 1 ; i< N+1; ++i){
VTKfile << i << " " ;
}
VTKfile<<std::endl << "</DataArray>"<<std::endl
<< " </Verts>"<<std::endl
<< "<Lines></Lines>"<<std::endl
<< "<Strips></Strips>"<<std::endl
<< "<Polys></Polys>"<<std::endl
<< "</Piece>"<<std::endl
<< "</PolyData>"<<std::endl
<< "</VTKFile>"<<std::endl;
} ;
//
//
//
//! \fn void exportVTKxml(std::ofstream& file, const FReal * particles, const int N, const int nbDataPerParticle )
//! \brief Export particles in CVS Format
//!
//! Export particles in the new PolyData Format.
//! A particle is composed of 4 fields x , y , z , physicalValue
//! It is useful to plot the distribution with paraView
//!
//! @param file stream to save the data
//! @param particles array of particles of type FReal (float or double) Its size is nbDataPerParticle*N
//! @param N number of particles
//! @param nbDataPerParticle number of values per particles (default value 4)
//!
void exportVTKxml(std::ofstream& VTKfile, const FReal * particles, const int N, const int nbDataPerParticle ){
int j = 0;
VTKfile << "<?xml version=\"1.0\"?>" <<std::endl
<< "<VTKFile type=\"PolyData\" version=\"0.1\" byte_order=\"LittleEndian\"> "<<std::endl
<< "<PolyData>"<<std::endl
<< "<Piece NumberOfPoints=\" " << N << " \" NumberOfVerts=\" "<<N <<" \" NumberOfLines=\" 0\" NumberOfStrips=\"0\" NumberOfPolys=\"0\">"<<std::endl
<< "<Points>"<<std::endl
<< "<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\"> "<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j] << " " << particles[j+1] << " " << particles[j+2] << " " ;
}
VTKfile <<std::endl<< "</DataArray> "<<std::endl
<< "</Points> "<<std::endl ;
if (nbDataPerParticle==8 ) {
VTKfile<< "<PointData Scalars=\"PhysicalValue\" > "<<std::endl
<< "<DataArray type=\"Float64\" Name=\"PhysicalValue\" format=\"ascii\">"<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j+3] << " " ;
}
VTKfile <<std::endl << "</DataArray>"<<std::endl ;
VTKfile << "<DataArray type=\"Float64\" Name=\"Potential\" format=\"ascii\">"<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j+4] << " " ;
}
VTKfile <<std::endl << "</DataArray>"<<std::endl ;
VTKfile<< "<DataArray type=\"Float64\" Name=\"Force\" NumberOfComponents=\"3\" format=\"ascii\"> "<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j+5] << " " << particles[j+6] << " " << particles[j+7] << " " ;
}
VTKfile <<std::endl<< "</DataArray> "<<std::endl;
}
else {
VTKfile << "<PointData Scalars=\"PhysicalValue\" > "<<std::endl
<< "<DataArray type=\"Float64\" Name=\"PhysicalValue\" format=\"ascii\">"<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=nbDataPerParticle){
VTKfile << particles[j+3] << " " ;
}
VTKfile <<std::endl << "</DataArray>"<<std::endl ;
}
VTKfile << " </PointData>"<<std::endl
<< " <CellData>"<<" </CellData>"<<std::endl
<< " <Verts>"<<std::endl
<< " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"<<std::endl ;
for(int i = 0 ; i< N; ++i){
VTKfile << i << " " ;
}
VTKfile<<std::endl << "</DataArray>" <<std::endl
<< "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"<<std::endl ;
for(int i = 1 ; i< N+1; ++i){
VTKfile << i << " " ;
}
VTKfile<<std::endl << "</DataArray>"<<std::endl
<< " </Verts>"<<std::endl
<< "<Lines></Lines>"<<std::endl
<< "<Strips></Strips>"<<std::endl
<< "<Polys></Polys>"<<std::endl
<< "</Piece>"<<std::endl
<< "</PolyData>"<<std::endl
<< "</VTKFile>"<<std::endl;
} ;
//
////////////////////////////////////////////////////////////////////////////////////////////////////
// The Driver
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//! \fn void driverExportData(std::ofstream& file, const FReal * particles , const int N, const int nbDataPerParticle=4)
//! \brief The driver to select the right format to write the data
//!
//! The driver select the right format (CVS, COSMOS, VTK, VTP,, ...) according to the extention of the filename
//! . cvs CVS Format
//! .vtk the old vtk format
//! .vtp the xml vtk format
//! .cosmo the cosmos format
//! It is useful to plot the distribution with paraView
//!
//! @param filename the name of the file to store the data
//! @param N number of particles
//! @param particles array of particles of type FReal (float or double) Its size is N*nbDataPerParticle
//! @param nbDataPerParticle number of values per particles (default value 4)
//!
void driverExportData(std::string & filename, const FReal * particles , const int NbPoints, const int nbDataPerParticle=4){
//
std::ofstream file( filename.c_str(), std::ofstream::out);
// open particle file
std::cout << "Write "<< NbPoints<<" Particles in file " << filename <<std::endl;
if(filename.find(".vtp") != std::string::npos) {
exportVTKxml( file, particles, NbPoints,nbDataPerParticle) ;
}
else if(filename.find(".vtk")!=std::string::npos ) {
exportVTK( file, particles, NbPoints,nbDataPerParticle) ;
}
else if(filename.find(".cvs")!=std::string::npos ) {
exportCVS( file, particles, NbPoints,nbDataPerParticle) ;
}
else if(filename.find(".cosmo")!=std::string::npos ) {
exportCOSMOS( file, particles, NbPoints) ;
}
else {
std::cout << "Output file not allowed only .cvs, .cosmo, .vtk or .vtp extensions" <<std::endl;
std::exit ( EXIT_FAILURE) ;
}
}
#endif
......@@ -561,7 +561,7 @@ public:
FFmaGenericWriter(const std::string & filename): binaryFile(false) {
std::string ext(".bfma");
// open particle file
if(filename.find(ext) !=std::string::npos) {
if(filename.find(".bfma") !=std::string::npos) {
binaryFile = true;
this->file = new std::fstream (filename.c_str(),std::ifstream::out| std::ios::binary);
}
......
......@@ -241,6 +241,8 @@ void unifRandonPlummer(const int N , const FReal R, const FReal M, FReal * point
<<100*static_cast<FReal>(cpt-N)/cpt << " %" <<std::endl;
} ;
#ifdef TOREMOVEOC
//! \fn void exportCVS(std::ofstream& file, const FReal * particles , const int N, const int nbDataPerParticle=4)
//! \brief Export particles in CVS Format
......@@ -477,5 +479,6 @@ void exportVTKxml(std::ofstream& VTKfile, const FReal * particles, const int N,
<< "</PolyData>"<<std::endl
<< "</VTKFile>"<<std::endl;
} ;
#endif
//
#endif
......@@ -99,17 +99,17 @@ static const FParameterNames InputBinFormat = {
static const FParameterNames OutputFile = {
{"-fout", "--output-filename"} ,
"To give the output filename."
"To give the output filename with extension .fma or .bfma (binary fma format)."
};
static const FParameterNames OutputVisuFile = {
{"-fvisuout"} ,
"To give the output filename in visu format."
"Specify the name (with extension) and the format of the file for visualization purpose.\n Available format are vtk, vtp, cvs or cosmo. vtp is the default."
};
static const FParameterNames FormatVisuFile{
{"-visufmt","-visu-fmt"},
"To specify format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default"
};
//static const FParameterNames FormatVisuFile{
// {"-visufmt","-visu-fmt"},
// "To specify format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default"
// };
static const FParameterNames OutputBinFormat = {
......
......@@ -17,6 +17,9 @@
#include "Files/FDlpolyLoader.hpp"
#include "Utils/FParameters.hpp"
#include "Utils/FGenerateDistribution.hpp"
#include "Utils/FParameterNames.hpp"
#include "Files/FExportWriter.hpp"
//
/// \file stamp2Fma.cpp
......@@ -52,16 +55,17 @@ void genDistusage() {
<< " -help to see the parameters " << std::endl
<< " Input: only one option is allowed" << std::endl
<< " -fin name: file name to convert (with extension .fma (ascii) or bfma (binary) " <<std::endl
<< " -fdlpoly name: file name to convert with extension (.bin if binary file) " <<std::endl
<< " Output " << std::endl
<< " -fout name: generic name for files (without extension) and save data" <<std::endl
<< " with following format in name.fma or name.bfma if -bin is set" <<std::endl
<< " -bin save output in binary mode (name file name.bfma)" <<std::endl
<< " -visufmt vtk, vtp, cosmo or cvs format for visualization " <<std::endl;
<< " -fdlpoly name: file name to convert with extension (.bin if binary file) " <<<<std::endl;
}
int main(int argc, char ** argv){
//
FHelpDescribeAndExit(argc, argv,
"Driver to change the format of the input file. "
"fdlpoly is not supported for now.",
FParameterDefinitions::InputFile, FParameterDefinitions::OutputFile,
FParameterDefinitions::OutputVisuFile,);
if(FParameters::existParameter(argc, argv, "-h")||FParameters::existParameter(argc, argv, "-help")|| (argc < 3 )){
genDistusage() ;
exit(-1);
......@@ -146,75 +150,20 @@ int main(int argc, char ** argv){
//
// Generate file for ScalFMM FMAGenericLoader
//
if(FParameters::existParameter(argc, argv, "-fout")){
std::string name(FParameters::getStr(argc,argv,"-fout", "output"));
std::string ext(".");
if(name.find(ext) !=std::string::npos) {
std::cout << "No file with extension permitted for output name : " << name << std::endl;
exit(-1);
}
if( FParameters::existParameter(argc, argv, "-bin")){
name += ".bfma";
}
else {
name += ".fma";
}
FFmaGenericWriter writer(name) ;
writer.writeHeader( loader->getCenterOfBox(), loader->getBoxWidth() , NbPoints, sizeof(FReal), nbData) ;
writer.writeArrayOfReal(particles, nbData, NbPoints);
}
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputFile.options)){
std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.fma"));
FFmaGenericWriter writer(name) ;
writer.writeHeader( loader->getCenterOfBox(), loader->getBoxWidth() , NbPoints, sizeof(FReal), nbData) ;
writer.writeArrayOfReal(particles, nbData, NbPoints);
}
//
// Generate file for visualization purpose
//
if(FParameters::existParameter(argc, argv, "-visufmt")){
std::string outfilename(FParameters::getStr(argc,argv,"-fout", "output"));
std::string visufile(""), fmt(FParameters::getStr(argc,argv,"-visufmt", "vtp"));
if( fmt == "vtp" ){
visufile = outfilename + ".vtp" ;
}
else if( fmt == "vtk" ){
visufile = outfilename + ".vtk" ;
}
else if( fmt == "cosmo" ){
if(nbData !=4) {
std::cerr << "Cosmos export accept only 4 data per particles. here: "<<nbData<<std::endl;
std::exit(EXIT_FAILURE);
}
visufile = outfilename + ".cosmo" ;
}
else {
visufile = outfilename + ".csv" ;
}
std::ofstream file( visufile, std::ofstream::out);
if(!file) {
std::cout << "Cannot open file."<< std::endl;
exit(-1) ;
} //
//
// Export data in cvs format
//
if( fmt == "vtp" ){
std::cout << "Writes in XML VTP format (visualization) in file "<< visufile <<std::endl ;
if(nbData==4){
exportVTKxml( file, particles, NbPoints) ;
}
else {
exportVTKxml( file, particles, NbPoints,nbData) ;
}
}
else if( fmt == "vtk" ){
std::cout << "Writes in VTK format (visualization) in file "<< visufile <<std::endl ;
exportVTK( file, particles, NbPoints,nbData) ;
}
else if( fmt == "cosmo" ){
std::cout << "Writes in COSMO format (visualization) in file "<< visufile <<std::endl ;
exportCOSMOS( file, particles, NbPoints) ;
}
else {
std::cout << "Writes in CVS format (visualization) in file "<<visufile<<std::endl ;
exportCVS( file, particles, NbPoints,nbData) ;
}
}
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.vtp"));
driverExportData(outfilename, particles , NbPoints);
}
//
delete particles ;
......