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 @@ ...@@ -18,6 +18,8 @@
#include "Utils/FPoint.hpp" #include "Utils/FPoint.hpp"
#include "Utils/FParameters.hpp" #include "Utils/FParameters.hpp"
#include "Utils/FGenerateDistribution.hpp" #include "Utils/FGenerateDistribution.hpp"
#include "Files/FExportWriter.hpp"
#include "Utils/FParameterNames.hpp" #include "Utils/FParameterNames.hpp"
// //
...@@ -35,7 +37,6 @@ ...@@ -35,7 +37,6 @@
//! \param -fout name: generic name for files (without extension) and save data //! \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" //! 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 -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 //! \b examples
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
//! //!
//! changeFormat -fin unitCubeXYZQ100.fma -fout unitCubeXYZQ100 -bin //! 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){ int main(int argc, char ** argv){
...@@ -51,8 +53,7 @@ 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. " "Driver to change the format of the input file. "
"fdlpoly is not supported for now.", "fdlpoly is not supported for now.",
FParameterDefinitions::InputFile, FParameterDefinitions::OutputFile, FParameterDefinitions::InputFile, FParameterDefinitions::OutputFile,
FParameterDefinitions::OutputVisuFile,FParameterDefinitions::FormatVisuFile, FParameterDefinitions::OutputVisuFile);
FParameterDefinitions::OutputBinFormat);
FSize NbPoints; FSize NbPoints;
FReal * particles = nullptr ; FReal * particles = nullptr ;
...@@ -86,19 +87,8 @@ int main(int argc, char ** argv){ ...@@ -86,19 +87,8 @@ int main(int argc, char ** argv){
// Generate file for ScalFMM FMAGenericLoader // Generate file for ScalFMM FMAGenericLoader
// //
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputFile.options)){ if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputFile.options)){
std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output")); std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.fma"));
std::string ext("."); FFmaGenericWriter writer(name) ;
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) ;
writer.writeHeader( loader->getCenterOfBox(), loader->getBoxWidth() , NbPoints, sizeof(FReal), nbData) ; writer.writeHeader( loader->getCenterOfBox(), loader->getBoxWidth() , NbPoints, sizeof(FReal), nbData) ;
writer.writeArrayOfReal(particles, nbData, NbPoints); writer.writeArrayOfReal(particles, nbData, NbPoints);
} }
...@@ -106,53 +96,8 @@ int main(int argc, char ** argv){ ...@@ -106,53 +96,8 @@ int main(int argc, char ** argv){
// Generate file for visualization purpose // Generate file for visualization purpose
// //
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){ if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output")); std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.vtp"));
std::string visufile(""), fmt(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options, "vtp")); driverExportData(outfilename, particles , NbPoints);
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) ;
}
} }
// //
delete particles ; delete particles ;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "Utils/FPoint.hpp" #include "Utils/FPoint.hpp"
#include "Utils/FGenerateDistribution.hpp" #include "Utils/FGenerateDistribution.hpp"
#include "Files/FFmaGenericLoader.hpp" #include "Files/FFmaGenericLoader.hpp"
#include "Files/FExportWriter.hpp"
#include "Utils/FParameterNames.hpp" #include "Utils/FParameterNames.hpp"
...@@ -74,6 +75,10 @@ ...@@ -74,6 +75,10 @@
int main(int argc, char ** argv){ 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, FHelpDescribeAndExit(argc, argv,
">> Driver to generate N points (non)uniformly distributed on a given geometry.\n" ">> Driver to generate N points (non)uniformly distributed on a given geometry.\n"
"Options \n" "Options \n"
...@@ -97,12 +102,13 @@ int main(int argc, char ** argv){ ...@@ -97,12 +102,13 @@ int main(int argc, char ** argv){
" -radius R - default value 10.0\n" " -radius R - default value 10.0\n"
" Physical values\n" " Physical values\n"
" -charge generate physical values between -1 and 1 otherwise generate between 0 and 1 \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" " -zeromean the average of the physical values is zero \n",
" Output \n" // " Output \n"
" -filename name: generic name for files (without extension) and save data\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" // " with following format in name.fma or name.bfma in -bin is set\n"
" -visufmt vtk, vtp, cosmo or cvs format.", // " -visufmt vtk, vtp, cosmo or cvs format.",
FParameterDefinitions::InputFile, FParameterDefinitions::OutputBinFormat, FParameterDefinitions::NbParticles); FParameterDefinitions::OutputFile,
FParameterDefinitions::NbParticles,FParameterDefinitions::OutputVisuFile,LocalOptionEllipsoid);
...@@ -188,14 +194,16 @@ int main(int argc, char ** argv){ ...@@ -188,14 +194,16 @@ int main(int argc, char ** argv){
std::cout << "A: "<<A<<" B "<< B << " C: " << C<<std::endl; std::cout << "A: "<<A<<" B "<< B << " C: " << C<<std::endl;
unifRandonPointsOnProlate(NbPoints,A,C,particles); unifRandonPointsOnProlate(NbPoints,A,C,particles);
BoxWith = 2.0*C; 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")){
// 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");
// std::string dd(":"),aspectRatio = FParameters::getStr(argc,argv,"-ar", "1:1:2");
FReal A,B,C ; FReal A,B,C ;
size_t pos = aspectRatio.find(":"); aspectRatio.replace(pos,1," "); size_t pos = aspectRatio.find(":"); aspectRatio.replace(pos,1," ");
pos = aspectRatio.find(":"); aspectRatio.replace(pos,1," "); pos = aspectRatio.find(":"); aspectRatio.replace(pos,1," ");
std::stringstream ss(aspectRatio); ss >>A >> B >> C ; 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); nonunifRandonPointsOnElipsoid(NbPoints,A,B,C,particles);
BoxWith = 2.0*FMath::Max( A,FMath::Max( B,C)) ; BoxWith = 2.0*FMath::Max( A,FMath::Max( B,C)) ;
} }
...@@ -220,14 +228,7 @@ int main(int argc, char ** argv){ ...@@ -220,14 +228,7 @@ int main(int argc, char ** argv){
BoxWith += 2*extraRadius ; BoxWith += 2*extraRadius ;
} }
std::string name(genericFileName); std::string name(genericFileName);
std::cout << "Write "<< NbPoints <<" Particles in file " << name << std::endl;
if( FParameters::existParameter(argc, argv, FParameterDefinitions::OutputBinFormat.options)){
name += ".bfma";
}
else {
name += ".fma";
}
std::cout << "Write "<< NbPoints <<" Particles in file " << name <<std::endl;
FFmaGenericWriter writer(name) ; FFmaGenericWriter writer(name) ;
writer.writeHeader(Centre,BoxWith, NbPoints, *ppart) ; writer.writeHeader(Centre,BoxWith, NbPoints, *ppart) ;
writer.writeArrayOfParticles(ppart, NbPoints); writer.writeArrayOfParticles(ppart, NbPoints);
...@@ -237,43 +238,8 @@ int main(int argc, char ** argv){ ...@@ -237,43 +238,8 @@ int main(int argc, char ** argv){
// Generate file for visualization // Generate file for visualization
// //
if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){ if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
std::string visufile(""), fmt(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options, "vtp")); std::string visufile(FParameters::getStr(argc,argv,FParameterDefinitions::OutputVisuFile.options, "output.vtp"));
if( fmt == "vtp" ){ driverExportData(visufile, particles , NbPoints);
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) ;
}
} }
// //
delete [] particles ; delete [] particles ;
......
This diff is collapsed.
...@@ -561,7 +561,7 @@ public: ...@@ -561,7 +561,7 @@ public:
FFmaGenericWriter(const std::string & filename): binaryFile(false) { FFmaGenericWriter(const std::string & filename): binaryFile(false) {
std::string ext(".bfma"); std::string ext(".bfma");
// open particle file // open particle file
if(filename.find(ext) !=std::string::npos) { if(filename.find(".bfma") !=std::string::npos) {
binaryFile = true; binaryFile = true;
this->file = new std::fstream (filename.c_str(),std::ifstream::out| std::ios::binary); 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 ...@@ -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; <<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) //! \fn void exportCVS(std::ofstream& file, const FReal * particles , const int N, const int nbDataPerParticle=4)
//! \brief Export particles in CVS Format //! \brief Export particles in CVS Format
...@@ -477,5 +479,6 @@ void exportVTKxml(std::ofstream& VTKfile, const FReal * particles, const int N, ...@@ -477,5 +479,6 @@ void exportVTKxml(std::ofstream& VTKfile, const FReal * particles, const int N,
<< "</PolyData>"<<std::endl << "</PolyData>"<<std::endl
<< "</VTKFile>"<<std::endl; << "</VTKFile>"<<std::endl;
} ; } ;
#endif
// //
#endif #endif
...@@ -99,17 +99,17 @@ static const FParameterNames InputBinFormat = { ...@@ -99,17 +99,17 @@ static const FParameterNames InputBinFormat = {
static const FParameterNames OutputFile = { static const FParameterNames OutputFile = {
{"-fout", "--output-filename"} , {"-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 = { static const FParameterNames OutputVisuFile = {
{"-fvisuout"} , {"-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{ //static const FParameterNames FormatVisuFile{
{"-visufmt","-visu-fmt"}, // {"-visufmt","-visu-fmt"},
"To specify format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default" // "To specify format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default"
}; // };
static const FParameterNames OutputBinFormat = { static const FParameterNames OutputBinFormat = {
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include "Files/FDlpolyLoader.hpp" #include "Files/FDlpolyLoader.hpp"
#include "Utils/FParameters.hpp" #include "Utils/FParameters.hpp"
#include "Utils/FGenerateDistribution.hpp" #include "Utils/FGenerateDistribution.hpp"
#include "Utils/FParameterNames.hpp"
#include "Files/FExportWriter.hpp"
// //
/// \file stamp2Fma.cpp /// \file stamp2Fma.cpp
...@@ -52,16 +55,17 @@ void genDistusage() { ...@@ -52,16 +55,17 @@ void genDistusage() {
<< " -help to see the parameters " << std::endl << " -help to see the parameters " << std::endl
<< " Input: only one option is allowed" << 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 << " -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 << " -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;
} }
int main(int argc, char ** argv){ 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 )){ if(FParameters::existParameter(argc, argv, "-h")||FParameters::existParameter(argc, argv, "-help")|| (argc < 3 )){
genDistusage() ; genDistusage() ;
exit(-1); exit(-1);
...@@ -146,75 +150,20 @@ int main(int argc, char ** argv){ ...@@ -146,75 +150,20 @@ int main(int argc, char ** argv){
// //
// Generate file for ScalFMM FMAGenericLoader // Generate file for ScalFMM FMAGenericLoader
// //
if(FParameters::existParameter(argc, argv, "-fout")){ if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputFile.options)){
std::string name(FParameters::getStr(argc,argv,"-fout", "output")); std::string name(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.fma"));
std::string ext("."); FFmaGenericWriter writer(name) ;
if(name.find(ext) !=std::string::npos) { writer.writeHeader( loader->getCenterOfBox(), loader->getBoxWidth() , NbPoints, sizeof(FReal), nbData) ;
std::cout << "No file with extension permitted for output name : " << name << std::endl; writer.writeArrayOfReal(particles, nbData, NbPoints);
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);
}
// //
// Generate file for visualization purpose // Generate file for visualization purpose
// //
if(FParameters::existParameter(argc, argv, "-visufmt")){ if(FParameters::existParameter(argc, argv, FParameterDefinitions::OutputVisuFile.options)){
std::string outfilename(FParameters::getStr(argc,argv,"-fout", "output")); std::string outfilename(FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "output.vtp"));
std::string visufile(""), fmt(FParameters::getStr(argc,argv,"-visufmt", "vtp")); driverExportData(outfilename, particles , NbPoints);
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) ;
}
}
// //
delete particles ; delete particles ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment