📄 cmesh.cpp
字号:
/*==============================================================================
O F E L I
Object Finite Element Library
==============================================================================
Copyright (C) 1998 - 2004 Rachid Touzani
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; Version 2 of the License.
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 License for more
details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the :
Free Software Foundation
Inc., 59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
==============================================================================
c m e s h
A Program to convert various formats of mesh files
==============================================================================*/
#include "Mesh.h"
#include "FFI.h"
#include "FromToMDF.h"
using namespace OFELI;
int main(int argc, char *argv[])
{
char file[FILENAME_LENGTH], input_file[FILENAME_LENGTH];
char output_file[FILENAME_LENGTH];
int input_flag=0;
int output_flag=0;
cout << "\n\n";
cout << "cmesh, version 1.1, Copyright (c) 1998 - 2004 by Rachid Touzani\n";
cout << "cmesh comes with ABSOLUTELY NO WARRANTY.\n";
cout << "This is free software, and your are allowed to redistribute it\n";
cout << "under certain conditions. Details are distributed with the software." << endl;
// Expand arguments
if (argc < 4) {
cout << "\n\nUsage: cmesh <file> <input format> <output format> [<options>]";
cout << "\n\nAvailable formats are:";
cout << "\n\n Input Output ";
cout << "\n -mdf * * MDF File (*.m)";
cout << "\n -bin * * Binary mesh file (*.bm)";
cout << "\n -em * EasyMesh Files (*.s *.e *.n)";
cout << "\n -amd * * AMD - BA Mesh file";
cout << "\n -gpl * GnuPlot File (*.gpl)";
cout << "\n -bamg * BAMG File (*.bamg)";
cout << "\n -emc2 * EMC2 Formatted File (*.msh)";
cout << "\n -gmsh * * Gmsh File (*.geo)";
cout << "\n -netgen * Netgen File (*.vol)";
cout << "\n -tetgen * Tetgen Files (*.node and *.ele)";
cout << "\n -tec * TecPlot file";
cout << "\n -vtk * vtk file";
cout << "\n -matlab * Matlab file";
cout << endl;
return 0;
}
strcpy(file,argv[1]);
if (strcmp(argv[2],"-mdf") == 0)
input_flag = 1;
else if (strcmp(argv[2],"-em") == 0)
input_flag = 2;
else if (strcmp(argv[2],"-bamg") == 0)
input_flag = 3;
else if (strcmp(argv[2],"-emc2") == 0)
input_flag = 4;
else if (strcmp(argv[2],"-amd") == 0)
input_flag = 5;
else if (strcmp(argv[2],"-gmsh") == 0)
input_flag = 6;
else if (strcmp(argv[2],"-netgen") == 0)
input_flag = 7;
else if (strcmp(argv[2],"-tetgen") == 0)
input_flag = 8;
else if (strcmp(argv[2],"-bin") == 0)
input_flag = 9;
else {
cout << "Error in cmesh : Unknown Input File Option : ";
cout << argv[2] << ".\n";
exit(1);
}
if (strcmp(argv[3],"-mdf") == 0)
output_flag = 1;
else if (strcmp(argv[3],"-gpl") == 0)
output_flag = 2;
else if (strcmp(argv[3],"-tec") == 0)
output_flag = 3;
else if (strcmp(argv[3],"-amd") == 0)
output_flag = 4;
else if (strcmp(argv[3],"-matlab") == 0)
output_flag = 5;
else if (strcmp(argv[3],"-bin") == 0)
output_flag = 6;
else if (strcmp(argv[3],"-gmsh") == 0)
output_flag = 7;
else if (strcmp(argv[3],"-vtk") == 0)
output_flag = 8;
else if (strcmp(argv[3],"-bvtk") == 0)
output_flag = 9;
else {
cout << "Error in cmesh : Unknown Output File Option : ";
cout << argv[3] << ".\n";
exit(1);
}
int nb_dof = 1;
if (argc > 4)
nb_dof = atoi(argv[4]);
Mesh mesh;
cout << " cmesh\n\n";
cout << " A Program to convert various formats of mesh files\n\n";
//----------
// I N P U T
//----------
switch (input_flag) {
// MDF File
case 1 : strcpy(input_file,strcat(strcpy(file,argv[1]),".m"));
cout << "Reading mesh file " << input_file << " ...\n";
mesh.Get(input_file);
break;
// EasyMesh Files
case 2 : cout << "Reading mesh files " << argv[1] << " ...\n";
Easymesh2MDF(argv[1],mesh,nb_dof);
break;
// BAMG Files
case 3 : strcpy(input_file,strcat(strcpy(file,argv[1]),".bamg"));
cout << "Reading mesh file " << input_file << " ...\n";
Bamg2MDF(input_file,mesh,nb_dof);
break;
// EMC2 File
case 4 : strcpy(input_file,strcat(strcpy(file,argv[1]),".msh"));
cout << "Reading mesh file " << input_file << " ...\n";
EMC2MDF(input_file,mesh,nb_dof);
break;
// AMD-BA File
case 5 : strcpy(input_file,strcat(strcpy(file,argv[1]),".amd"));
cout << "Reading mesh file " << input_file << " ...\n";
AMD2MDF(input_file,mesh,nb_dof);
break;
// Gmsh File
case 6 : strcpy(input_file,strcat(strcpy(file,argv[1]),".msh"));
cout << "Reading mesh file " << input_file << " ...\n";
Gmsh2MDF(input_file,mesh,nb_dof);
break;
// Netgen File
case 7 : strcpy(input_file,argv[1]);
cout << "Reading mesh files " << input_file << " ...\n";
Netgen2MDF(input_file,mesh,nb_dof);
break;
// Tetgen File
case 8 : strcpy(input_file,argv[1]);
cout << "Reading mesh files " << input_file << " ...\n";
Tetgen2MDF(input_file,mesh,nb_dof);
break;
// Binary File
case 9 : strcpy(input_file,strcat(strcpy(file,argv[1]),".bm"));
cout << "Reading mesh file " << input_file << " ...\n";
mesh.BGet(input_file);
break;
}
//------------
// O U T P U T
//------------
switch (output_flag) {
// MDF File
case 1 : strcpy(output_file,strcat(strcpy(file,argv[1]),".m"));
cout << "Saving mesh file " << output_file << " ...\n";
mesh.Put(output_file);
break;
// Gnuplot File
case 2 : strcpy(output_file,strcat(strcpy(file,argv[1]),".gpl"));
cout << "Saving mesh file " << output_file << " ...\n";
MDF2Gnuplot(output_file,mesh);
break;
// Tecplot File
case 3 : strcpy(output_file,strcat(strcpy(file,argv[1]),"_tecplot.dat"));
cout << "Saving mesh file " << output_file << " ...\n";
MDF2Tecplot(output_file,mesh);
break;
// AMD-BA File
case 4 : strcpy(output_file,strcat(strcpy(file,argv[1]),".amd"));
cout << "Saving mesh file " << output_file << " ...\n";
MDF2AMD(output_file,mesh);
break;
// Matlab File
case 5 : strcpy(output_file,strcat(strcpy(file,argv[1]),"_mat.m"));
cout << "Saving mesh file " << output_file << " ...\n";
MDF2Matlab(output_file,mesh);
break;
// Binary File
case 6 : strcpy(output_file,strcat(strcpy(file,argv[1]),".bm"));
cout << "Saving mesh file " << output_file << " ...\n";
mesh.BPut(output_file);
break;
// Gmsh File
case 7 : strcpy(output_file,strcat(strcpy(file,argv[1]),"_gmsh.geo"));
cout << "Saving mesh file " << output_file << " ...\n";
MDF2Gmsh(output_file,mesh);
break;
// vtk File
case 8 : strcpy(output_file,strcat(strcpy(file,argv[1]),".vtk"));
cout << "Saving mesh file " << output_file << " ...\n";
MDF2VTK(output_file,mesh);
break;
// Binary vtk File
case 9 : strcpy(output_file,strcat(strcpy(file,argv[1]),".vtk"));
cout << "Saving mesh file " << output_file << " ...\n";
// MDF2VTK(output_file,mesh,1);
break;
}
cout << "done." << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -