-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathMeshconv_main.cpp
More file actions
188 lines (157 loc) · 4.75 KB
/
Copy pathMeshconv_main.cpp
File metadata and controls
188 lines (157 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Copyright (C) 2006 Imperial College London and others.
Please see the AUTHORS file in the main source directory for a full list
of copyright holders.
Prof. C Pain
Applied Modelling and Computation Group
Department of Earth Science and Engineering
Imperial College London
amcgsoftware@imperial.ac.uk
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation,
version 2.1 of the License.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
#include <iostream>
#include <map>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "confdefs.h"
#include "c++debug.h"
#include "flmpi.h"
using namespace std;
extern "C"{
void meshconv(const char* input_basename, size_t input_basename_len, const char* input_mesh_format,
size_t input_mesh_format_len, const char* output_mesh_format, size_t output_mesh_format_len);
}
void Usage(){
cerr << "Usage: meshconv [OPTIONS] ... inputname \n"
<< "with 'inputname' being the basename of the input mesh file\n"
<< "\n"
<< "Options:\n"
<< "\n"
<< "-h\t\tDisplay this help\n"
<< "-i\t\tInput mesh format\n"
<< "-o\t\tOutput mesh format\n"
<< "-l\t\tWrite output to log files\n"
<< "-v\t\tVerbose mode\n"
<< "\n"
<< "With the options 'i' and 'o' being one of the following:\n"
<< " * triangle\n"
<< " * gmsh\n"
<< " * exodusii\n"
<< "whereas 'exodusii' is only allowed as an input-mesh-format." << endl;
}
int main(int argc, char** argv){
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
// Undo some MPI init shenanigans
int ierr = chdir(getenv("PWD"));
if (ierr == -1) {
cerr << "Unable to switch to directory " << getenv("PWD");
abort();
}
#endif
// Modified version of fldecomp argument parsing
// Get any command line arguments
// Reset optarg so we can detect changes
optarg = NULL;
char c;
map<char, string> args;
while((c = getopt(argc, argv, "i:o:hlv")) != -1){
if (c != '?'){
if(optarg == NULL){
args[c] = "true";
}else{
args[c] = optarg;
}
}else{
if(isprint(optopt)){
cerr << "Unknown option " << optopt << endl;
}else{
cerr << "Unknown option " << hex << optopt << endl;
}
Usage();
exit(-1);
}
}
// Logging
if(args.count('l')){
int rank = 0;
#ifdef HAVE_MPI
int init_flag;
MPI_Initialized(&init_flag);
if(init_flag){
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
}
#endif
ostringstream buffer;
buffer << "meshconv.log-" << rank;
if(freopen(buffer.str().c_str(), "w", stdout) == NULL){
cerr << "Failed to redirect stdout" << endl;
exit(-1);
}
buffer.str("");
buffer << "meshconv.err-" << rank;
if(freopen(buffer.str().c_str(), "w", stderr) == NULL){
cerr << "Failed to redirect stderr" << endl;
exit(-1);
}
buffer.str("");
}
// Help
if(args.count('h')){
Usage();
exit(0);
}
// Verbosity
int verbosity = 0;
if(args.count('v') > 0){
verbosity = 3;
}
set_global_debug_level_fc(&verbosity);
// Input and output base names
string input_basename;
if(argc == optind + 2){
input_basename = argv[optind + 1];
}else if(argc == optind + 1){
input_basename = argv[optind];
}else{
Usage();
exit(-1);
}
// Input and output mesh formats:
string input_mesh_format, output_mesh_format;
if(args.count('i') == 0){
Usage();
exit(-1);
}
input_mesh_format = args['i'].c_str();
if(args.count('o') == 0){
Usage();
exit(-1);
}
output_mesh_format = args['o'].c_str();
// Stop the program if 'exodusii' was given as output format:
if (output_mesh_format.compare("exodusii") == 0){
cerr << "Error: ExodusII is only allowed as an INPUT mesh format." << endl;
exit(-1);
}
size_t input_basename_len = input_basename.size();
size_t input_mesh_format_len = input_mesh_format.size();
size_t output_mesh_format_len = output_mesh_format.size();
meshconv(input_basename.c_str(), input_basename_len, input_mesh_format.c_str(), input_mesh_format_len, output_mesh_format.c_str(), output_mesh_format_len);
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return 0;
}