initial upload
This commit is contained in:
138
2minfo/2minfo.cpp
Normal file
138
2minfo/2minfo.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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.
|
||||
******************************************************/
|
||||
|
||||
// add gctl head files
|
||||
#include "gctl/mesh.h"
|
||||
#include "gctl/utility.h"
|
||||
|
||||
#define create_mesh(mesh_ptr, mesh_dimen, mesh_tp) \
|
||||
if (mesh_dimen == gctl::MESH_2D && mesh_tp == gctl::REGULAR_MESH) \
|
||||
mesh_ptr = new gctl::regular_mesh_2d; \
|
||||
else if (mesh_dimen == gctl::MESH_2D && mesh_tp == gctl::LINEAR_MESH) \
|
||||
mesh_ptr = new gctl::linear_mesh_2d; \
|
||||
else if (mesh_dimen == gctl::MESH_2D && mesh_tp == gctl::TRI_TET_MESH) \
|
||||
mesh_ptr = new gctl::triangle_mesh; \
|
||||
else if (mesh_dimen == gctl::MESH_3D && mesh_tp == gctl::REGULAR_MESH) \
|
||||
mesh_ptr = new gctl::regular_mesh_3d; \
|
||||
else if (mesh_dimen == gctl::MESH_3D && mesh_tp == gctl::LINEAR_MESH) \
|
||||
mesh_ptr = new gctl::linear_mesh_3d; \
|
||||
else if (mesh_dimen == gctl::MESH_3D && mesh_tp == gctl::TRI_TET_MESH) \
|
||||
mesh_ptr = new gctl::tetrahedron_mesh; \
|
||||
else if (mesh_dimen == gctl::MESH_2D && mesh_tp == gctl::REGULAR_GRID) \
|
||||
mesh_ptr = new gctl::regular_grid; \
|
||||
else throw "Unknown mesh format.";
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
const char* pro_name = "2minfo";
|
||||
const char* pro_info = "1.0 - Inspect a GCTL .2m file and show information. \
|
||||
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* in_file_str = "Name of a GCTL .2m model file.";
|
||||
|
||||
char in_file[1024] = "NULL";
|
||||
|
||||
// option format
|
||||
// char* info, char* format, bool manda
|
||||
static struct gctl::option_info long_opts_help[] =
|
||||
{
|
||||
{in_file_str, "<filename>", true},
|
||||
{"Show help information.", 0, false},
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
static struct option long_opts[] =
|
||||
{
|
||||
{"input-file", required_argument, NULL, 'i'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int curr;
|
||||
while (1)
|
||||
{
|
||||
int opt_index = 0;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
gctl::display_logo(std::clog);
|
||||
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, pro_info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
curr = getopt_long(argc, argv, "hi:", long_opts, &opt_index);
|
||||
|
||||
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':
|
||||
sscanf(optarg, "%s", in_file);
|
||||
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 (!strcmp(in_file, "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);
|
||||
gctl::getopt_long_option_info('i', long_opts, long_opts_help);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gctl::base_mesh *input_mesh = nullptr;
|
||||
std::ifstream infile;
|
||||
gctl::open_infile(infile, in_file, ".2m", std::ios::in|std::ios::binary);
|
||||
|
||||
// 网格头信息
|
||||
int mesh_dimension, mesh_type;
|
||||
infile.read((char*)&mesh_type, sizeof(int));
|
||||
infile.read((char*)&mesh_dimension, sizeof(int));
|
||||
infile.close();
|
||||
|
||||
create_mesh(input_mesh, mesh_dimension, mesh_type);
|
||||
|
||||
input_mesh->load_binary(in_file);
|
||||
input_mesh->show_info();
|
||||
|
||||
if (input_mesh != nullptr) delete input_mesh;
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
43
2minfo/CMakeLists.txt
Normal file
43
2minfo/CMakeLists.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
set(TOOL_NAME 2minfo)
|
||||
set(BIN_DIR bin)
|
||||
set(INSTALL_DIR sbin)
|
||||
|
||||
find_package(GCTL REQUIRED)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
|
||||
find_package(GCTL_GRAPHIC REQUIRED)
|
||||
include_directories(${GCTL_GRAPHIC_INC_DIR})
|
||||
|
||||
find_package(GCTL_MESH REQUIRED)
|
||||
include_directories(${GCTL_MESH_INC_DIR})
|
||||
|
||||
if(GCTL_GRAPHIC_MATHGL)
|
||||
find_package(MathGL2 REQUIRED FLTK)
|
||||
message(STATUS "mathGL Version: " ${MathGL2_VERSION})
|
||||
include_directories(${MathGL2_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
if(WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${BIN_DIR})
|
||||
|
||||
aux_source_directory(. TOOL_SRC)
|
||||
add_executable(${TOOL_NAME} ${TOOL_SRC})
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${GCTL_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${GCTL_GRAPHIC_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${GCTL_MESH_LIB})
|
||||
|
||||
|
||||
if(GCTL_GRAPHIC_MATHGL)
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${MathGL2_LIBRARIES} ${MathGL2_FLTK_LIBRARIES})
|
||||
endif()
|
||||
|
||||
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION ${INSTALL_DIR})
|
Reference in New Issue
Block a user