gctl_toolkits/gmsh2vtk/main.cpp
2024-09-10 20:25:18 +08:00

109 lines
4.0 KiB
C++

/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. 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, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "func_msh2vtk.h"
int main(int argc, char* argv[])
{
const char* pro_name = "gmsh2vtk";
const char* pro_info = "1.0 - Convert Gmsh(.msh) file to Paraview(.vtk) file. \
This program is a toolkit of the GCTL package. The GCTL comes with ABSOLUTE NO WARRANTY. \
Please see instructions or contact the author for more information.";
const char* data_name_str = "Name of the model data that needs to be converted. The names should be rounded by quotations. \
Supported elements types are 2-node line, 3-node triangle, 4-node quadrangle, 4-node tetrahedron, \
6-node prism and 8-node hexahedron. Blank data entries will be filled with a dummy value 1e+30.";
mshvtk mv;
string mshname = "NULL", dataname = "NULL";
static struct gctl::option_info long_opts_help[] =
{
{"Input Gmsh(.msh) file.", "<msh-file>", true},
{data_name_str, "<data-name> [-d<data-name> ...]", true},
{"Show help information.", 0, false},
{0, 0, 0}
};
static struct option long_opts[] =
{
{"input-file", required_argument, NULL, 'i'},
{"data-name", required_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
if (argc == 1){
gctl::display_logo(std::clog);
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, pro_info);
return 0;
}
int curr;
while(1)
{
int optIndex = 0;
curr = getopt_long(argc, argv, "hi:d:", long_opts, &optIndex);
if (curr == -1) break;
switch (curr)
{
case 'h': //显示帮助信息
gctl::display_logo(std::clog);
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, pro_info);
return 0;
case 'i':
mshname = optarg;
break;
case 'd':
dataname = optarg;
mv.addname(dataname);
break;
case '?':
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, " - Unknown options. Please see the help information below.");
break;
default:
abort();
}
}
// check for mandatory option(s)
if (mshname == "NULL" || dataname == "NULL")
{
GCTL_ShowWhatError("Missing arguments for mandatory option(s).", GCTL_ERROR_ERROR,
0, "See tips below. Or use -h option to see the full instruction.", 0);
if (mshname == "NULL")
gctl::getopt_long_option_info('i', long_opts, long_opts_help);
if (dataname == "NULL")
gctl::getopt_long_option_info('d', long_opts, long_opts_help);
return 0;
}
mv.runtine(mshname);
return 0;
}