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,18 +87,7 @@ 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";
}
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 ;
......
This diff is collapsed.
......@@ -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,74 +150,19 @@ 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";
}
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 ;
......
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