diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f78279..c13dbbc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15.2)
# 设置项目名称与语言
-project(GCTL VERSION 1.0)
+project(GCTL VERSION 1.1)
# 添加配置配件编写的函数
include(CMakePackageConfigHelpers)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 27a7353..8c65443 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -5,11 +5,10 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# 设定库源文件文件夹
-aux_source_directory(geometry/ GCTL_GEOMETRY_SRC)
-aux_source_directory(algorithms/ GCTL_ALGORITHMS_SRC)
+aux_source_directory(core/ GCTL_CORE_SRC)
aux_source_directory(io/ GCTL_IO_SRC)
aux_source_directory(utility/ GCTL_UTILITY_SRC)
-aux_source_directory(maths/ GCTL_MATHS_SRC)
+aux_source_directory(math/ GCTL_MATH_SRC)
aux_source_directory(graphic/ GCTL_GRAPHIC_SRC)
# 在windows系统下使用改编过的getopt_win源文件替代GNU getopt
# 若在linux系统下则不适用此源文件
@@ -24,11 +23,11 @@ endif()
# 以下部分为库的编译
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
-add_library(gctl SHARED ${GCTL_UTILITY_SRC} ${GCTL_ALGORITHMS_SRC} ${GCTL_GRAPHIC_SRC}
- ${GCTL_GEOMETRY_SRC} ${GCTL_IO_SRC} ${GCTL_MATHS_SRC})
+add_library(gctl SHARED ${GCTL_CORE_SRC} ${GCTL_UTILITY_SRC}
+ ${GCTL_GRAPHIC_SRC} ${GCTL_IO_SRC} ${GCTL_MATH_SRC})
# 首先添加静态库的生成命令
-add_library(gctl_static STATIC ${GCTL_UTILITY_SRC} ${GCTL_ALGORITHMS_SRC} ${GCTL_GRAPHIC_SRC}
- ${GCTL_GEOMETRY_SRC} ${GCTL_IO_SRC} ${GCTL_MATHS_SRC})
+add_library(gctl_static STATIC ${GCTL_CORE_SRC} ${GCTL_UTILITY_SRC}
+ ${GCTL_GRAPHIC_SRC} ${GCTL_IO_SRC} ${GCTL_MATH_SRC})
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
set_target_properties(gctl_static PROPERTIES OUTPUT_NAME "gctl")
# 设置输出目标属性以同时输出动态库与静态库
diff --git a/lib/algorithms.h b/lib/algorithms.h
deleted file mode 100644
index 221d8a0..0000000
--- a/lib/algorithms.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/********************************************************
- * ██████╗ ██████╗████████╗██╗
- * ██╔════╝ ██╔════╝╚══██╔══╝██║
- * ██║ ███╗██║ ██║ ██║
- * ██║ ██║██║ ██║ ██║
- * ╚██████╔╝╚██████╗ ██║ ███████╗
- * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
- * Geophysical Computational Tools & Library (GCTL)
- *
- * Copyright (c) 2023 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 .
- *
- * 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.
- ******************************************************/
-
-#ifndef _GCTL_ALGORITHM_H
-#define _GCTL_ALGORITHM_H
-
-#include "algorithms/algorithm_func.h"
-#include "algorithms/glni.h"
-#include "algorithms/interpolate.h"
-#include "algorithms/extrapolate.h"
-#include "algorithms/heap_sort.h"
-#include "algorithms/boxsort2d.h"
-#include "algorithms/boxsort_sph.h"
-#include "algorithms/variogram.h"
-#include "algorithms/fir_filter.h"
-#include "algorithms/space_filter.h"
-#include "algorithms/sinkhorn.h"
-#include "algorithms/kde.h"
-#include "algorithms/autodiff.h"
-#include "algorithms/multinary.h"
-#include "algorithms/emd.h"
-#include "algorithms/fft_filter.h"
-
-#endif // _GCTL_ALGORITHM_H
\ No newline at end of file
diff --git a/lib/core.h b/lib/core.h
index 82cf29d..324a028 100644
--- a/lib/core.h
+++ b/lib/core.h
@@ -37,5 +37,6 @@
#include "core/matrix.h"
#include "core/spmat.h"
#include "core/sparray.h"
+#include "core/str.h"
#endif // _GCTL_CORE_H
\ No newline at end of file
diff --git a/lib/core/str.cpp b/lib/core/str.cpp
new file mode 100644
index 0000000..d18d82c
--- /dev/null
+++ b/lib/core/str.cpp
@@ -0,0 +1,207 @@
+/********************************************************
+ * ██████╗ ██████╗████████╗██╗
+ * ██╔════╝ ██╔════╝╚══██╔══╝██║
+ * ██║ ███╗██║ ██║ ██║
+ * ██║ ██║██║ ██║ ██║
+ * ╚██████╔╝╚██████╗ ██║ ███████╗
+ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
+ * Geophysical Computational Tools & Library (GCTL)
+ *
+ * Copyright (c) 2023 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 .
+ *
+ * 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 "str.h"
+
+//替换str中所有lod_value为new_value,返回被替换的old_value的个数
+int gctl::replace_all(std::string& new_str, const std::string& old_str,const std::string& old_value,const std::string& new_value)
+{
+ int count = 0;
+ new_str = old_str;
+ for(std::string::size_type pos(0);pos!=std::string::npos;pos+=new_value.length())
+ {
+ if((pos=new_str.find(old_value,pos))!=std::string::npos)
+ {
+ new_str.replace(pos,old_value.length(),new_value);
+ count++;
+ }
+ else break;
+ }
+ return count;
+}
+
+//在输入字符串末尾添加一段字符串,如果输入字符串的尾端与待添加的字符串一致则不添加并返回原字符串
+std::string gctl::patch_string(std::string in_str, std::string patch_str)
+{
+ int inlen = in_str.length();
+ int exlen = patch_str.length();
+
+ std::string out_str = in_str;
+
+ if (exlen > inlen)
+ {
+ out_str += patch_str;
+ return out_str;
+ }
+
+ if (exlen == inlen && in_str != patch_str)
+ {
+ out_str += patch_str;
+ return out_str;
+ }
+
+ if (in_str.substr(inlen - exlen, inlen) != patch_str)
+ {
+ out_str += patch_str;
+ return out_str;
+ }
+
+ return out_str;
+}
+
+//转换string对象为stringstream对象
+void gctl::str2ss(std::string in_str, std::stringstream &out_ss, std::string delimiter)
+{
+ if (delimiter != "")
+ {
+ std::string replace_str;
+ replace_all(replace_str, in_str, delimiter, " ");
+ out_ss.clear();
+ out_ss.str(replace_str);
+ }
+ else
+ {
+ out_ss.clear();
+ out_ss.str(in_str);
+ }
+ return;
+}
+
+/**
+ * @brief 转换string字符串为double类型的数值
+ *
+ * 这个函数的主要作用是检查输入字符串是否为nan或者inf等表示无效值的符号。有的编译器
+ * 可以在>>输入符中完成此检测,但为了函数功能的稳定,所以在此处自定了这个函数。
+ *
+ * @param[in] instr 输入字符串
+ *
+ * @return 返回的double类型的数值
+ */
+double gctl::str2double(std::string instr)
+{
+ if (instr == "NAN" || instr == "nan" || instr == "NaN")
+ return NAN;
+ else if (instr == "INF" || instr == "inf" || instr == "Inf")
+ return INFINITY;
+ else
+ {
+ auto e(instr.find_first_of("dD"));
+ if (e != std::string::npos) instr[e] = 'e';
+
+ return atof(instr.c_str());
+ }
+}
+
+/**
+ * @brief 转换double类型数值为string类型字符串
+ *
+ * @param[in] in_d 输入数值
+ *
+ * @return 输出字符串
+ */
+std::string gctl::double2str(double in_d)
+{
+ std::string tmp_str;
+ std::stringstream tmp_ss;
+
+ tmp_ss.clear();
+ if (std::isnan(in_d))
+ tmp_ss.str("nan");
+ else if (std::isinf(in_d))
+ tmp_ss.str("inf");
+ else tmp_ss << in_d;
+
+ tmp_ss >> tmp_str;
+ return tmp_str;
+}
+
+//返回指定长度的随机字符串
+void gctl::random_char(unsigned int length, char* out)
+{
+ char str[76] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*+_-=?";
+ int i,lstr;
+ char ss[2] = {0};
+ lstr = strlen(str);//计算字符串长度
+ srand((unsigned int)time((time_t *)NULL));//使用系统时间来初始化随机数发生器
+ //按指定大小返回相应的字符串
+ for(i = 1; i <= length; i++)
+ {
+ snprintf(ss, 2, "%c",str[(rand()%lstr)]);//rand()%lstr 可随机返回0-61之间的整数, str[0-61]可随机得到其中的字符
+ strcat(out,ss);//将随机生成的字符串连接到指定数组后面
+ }
+ return;
+}
+
+void gctl::random_str(unsigned int length, std::string &out_str)
+{
+ char *out_char = new char [length];
+ random_char(length, out_char);
+ out_str = out_char;
+ delete[] out_char;
+ return;
+}
+
+void gctl::parse_string_with_quotes(std::string in_str, std::vector &str_vec)
+{
+ std::vector tmp_units;
+ parse_string_to_vector(in_str, ' ', tmp_units);
+
+ // Combine strings into one if they are enclosed by quotes
+ std::string tmp_str = "";
+ int i = 0;
+ while (i < tmp_units.size())
+ {
+ if (tmp_units[i].front() == '"' && tmp_units[i].back() == '"')
+ {
+ str_vec.push_back(tmp_units[i].substr(1, tmp_units[i].length() - 1));
+ i++;
+ }
+ else if (tmp_units[i].front() == '"')
+ {
+ tmp_str = tmp_units[i].substr(1, tmp_units[i].length());
+ i++;
+
+ while (tmp_units[i].back() != '"')
+ {
+ tmp_str += " " + tmp_units[i];
+ i++;
+ }
+
+ tmp_str += " " + tmp_units[i].substr(0, tmp_units[i].length() - 1);
+ i++;
+
+ str_vec.push_back(tmp_str);
+ tmp_str = "";
+ }
+ else
+ {
+ str_vec.push_back(tmp_units[i]);
+ i++;
+ }
+ }
+ return;
+}
\ No newline at end of file
diff --git a/lib/utility/stream_t.h b/lib/core/str.h
similarity index 73%
rename from lib/utility/stream_t.h
rename to lib/core/str.h
index 4e5afd9..3eb1d5e 100644
--- a/lib/utility/stream_t.h
+++ b/lib/core/str.h
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -25,32 +25,17 @@
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
-#ifndef _GCTL_STREAM_TEMPLATE_H
-#define _GCTL_STREAM_TEMPLATE_H
+#ifndef _GCTL_STR_H
+#define _GCTL_STR_H
-#include
+#include "exceptions.h"
+
+#include
+#include
+#include
+#include
#include
-
-#include "../core/exceptions.h"
-#include "../core/vector_t.h"
-
-/**
- * terminal control symbols
- */
-#define GCTL_BOLD "\033[1m" ///< 设置终端字体与颜色为粗体
-#define GCTL_BOLDRED "\033[1m\033[31m" ///< 设置终端字体与颜色为粗体红色
-#define GCTL_BOLDGREEN "\033[1m\033[32m" ///< 设置终端字体与颜色为粗体绿色
-#define GCTL_BOLDBLUE "\033[1m\033[34m" ///< 设置终端字体与颜色为粗体蓝色
-#define GCTL_BOLDYELLOW "\033[1m\033[33m" ///< 设置后续字符字体为黄色加粗
-#define GCTL_UNDERLINE "\033[1m\033[4m" ///< 设置终端字体为下划线
-#define GCTL_RESET "\033[0m" ///< 重置字体与颜色设定
-#define GCTL_CLEARLINE "\033[K" ///< 清空终端当前行
-#define GCTL_CLEARALL "\033[2J" ///< 清空终端窗口
-#define GCTL_MOVEUP(os, x) do {os << "\033[" << x << "A";} while (0); ///< 终端光标上移x行
-#define GCTL_MOVEDOWN(os, x) do {os << "\033[" << x << "B";} while (0); ///< 终端光标下移x行
-#define GCTL_MOVERIGHT(os, x) do {os << "\033[" << x << "C";} while (0); ///< 终端光标右移x列
-#define GCTL_MOVELEFT(os, x) do {os << "\033[" << x << "D";} while (0); ///< 终端光标左移x列
-#define GCTL_MOVETO(os, r, c) do {os << "\033[" << c << ";" << r << "H";} while (0); ///< 终端光标移动至r行c列位置
+#include
namespace gctl
{
@@ -198,52 +183,6 @@ namespace gctl
return;
}
- /**
- * @brief Parse a string argument into an element array
- *
- * @param[in] val_str The input value string
- * @param out_vec The output array
- * @param[in] separator The separator
- *
- * @tparam ValueType Runtime value type
- *
- * @return 0 for success, -1 for failure
- */
- template
- int parse_string_to_vector(std::string val_str, char separator, std::vector &out_vec)
- {
- val_str.erase(0, val_str.find_first_not_of(" \t"));
- val_str.erase(val_str.find_last_not_of(" \t") + 1);
-
- int pos;
- bool bk = false;
- ValueType val;
- std::string l_str;
- while (1)
- {
- pos = val_str.find(separator);
- if (pos == val_str.npos)
- {
- l_str = val_str;
- bk = true;
- }
- else
- {
- l_str = val_str.substr(0, pos);
- val_str = val_str.substr(pos+1, val_str.length());
- val_str.erase(0, val_str.find_first_not_of(" \t"));
- }
-
- // 如果输出也是字符串 就直接赋值即可(避免l_str中含有空格会出现bug)
- if constexpr (std::is_same::value) val = l_str;
- else str2type(l_str, val);
-
- out_vec.push_back(val);
- if (bk) break;
- }
- return 0;
- }
-
/**
* @brief Parse a string argument into separated elements.
*
@@ -318,6 +257,132 @@ namespace gctl
return parse_string_to_value(tmp_str, separator, throw_err, rest...) + 1;
}
-}
-#endif // _GCTL_STREAM_TEMPLATE_H
\ No newline at end of file
+ /**
+ * @brief 替换字符串中的指定子串
+ *
+ * @param new_str 替换后的字符串
+ * @param old_str 需要操作的字符串
+ * @param old_value 需要被替换的字串
+ * @param new_value 替换的字串
+ *
+ * @return 替换的次数
+ */
+ int replace_all(std::string& new_str, const std::string& old_str, const std::string& old_value,
+ const std::string& new_value);
+
+ /**
+ * @brief 在输入字符串末尾添加一段字符串,如果输入字符串的尾端与待添加的字符串一致则不添加并返回原字符串
+ *
+ * @param in_str 输入字符串
+ * @param patch_str 待匹配的字符串
+ * @return 输出字符串
+ */
+ std::string patch_string(std::string in_str, std::string patch_str);
+
+ /**
+ * @brief 转换string对象为stringstream对象
+ *
+ * @param[in] in_str 输入的string字符串
+ * @param out_ss 引用返回的stringstreams对象
+ * @param[in] delimiter 分割string对象时的分隔符。如果不为空,
+ * 函数会将delimiter转换为空格
+ */
+ void str2ss(std::string in_str, std::stringstream &out_ss, std::string delimiter = "");
+
+ /**
+ * @brief 转换string字符串为double类型的数值
+ *
+ * 这个函数的主要作用是检查输入字符串是否为nan或者inf等表示无效值的符号。有的编译器
+ * 可以在>>输入符中完成此检测,但为了函数功能的稳定,所以在此处自定了这个函数。这个函数
+ * 还可以将fortran输出文件中以D标注的科学数字转换为浮点类型
+ *
+ * @param[in] instr 输入字符串
+ *
+ * @return 返回的double类型的数值
+ */
+ double str2double(std::string instr);
+
+ /**
+ * @brief 转换double类型数值为string类型字符串 标准库中有to_string函数,以后就不用这个了。
+ *
+ * @param[in] in_d 输入数值
+ *
+ * @return 输出字符串
+ */
+ std::string double2str(double in_d);
+
+ /**
+ * @brief 返回一定长度的随机字符串
+ *
+ * @param[in] length 字符串的长度
+ * @param out 输出字符串
+ */
+ void random_char(unsigned int length, char* out);
+
+ /**
+ * @brief 返回一定长度的随机字符串
+ *
+ * @param[in] length 字符串的长度
+ * @param out_str 输出字符串
+ */
+ void random_str(unsigned int lenght, std::string &out_str);
+
+ /**
+ * @brief Parse a string argument into an element array
+ *
+ * @param[in] val_str The input value string
+ * @param out_vec The output array
+ * @param[in] separator The separator
+ *
+ * @tparam ValueType Runtime value type
+ *
+ * @return 0 for success, -1 for failure
+ */
+ template
+ int parse_string_to_vector(std::string val_str, char separator, std::vector &out_vec)
+ {
+ val_str.erase(0, val_str.find_first_not_of(" \t"));
+ val_str.erase(val_str.find_last_not_of(" \t") + 1);
+
+ int pos;
+ bool bk = false;
+ ValueType val;
+ std::string l_str;
+ while (1)
+ {
+ pos = val_str.find(separator);
+ if (pos == val_str.npos)
+ {
+ l_str = val_str;
+ bk = true;
+ }
+ else
+ {
+ l_str = val_str.substr(0, pos);
+ val_str = val_str.substr(pos+1, val_str.length());
+ val_str.erase(0, val_str.find_first_not_of(" \t"));
+ }
+
+ // 如果输出也是字符串 就直接赋值即可(避免l_str中含有空格会出现bug)
+ if constexpr (std::is_same::value) val = l_str;
+ else str2type(l_str, val);
+
+ out_vec.push_back(val);
+ if (bk) break;
+ }
+ return 0;
+ }
+
+ /**
+ * @brief 解析字符串并返回以空格分割的字符串向量
+ *
+ * @note 双引号括起来的部分将解析为一个字符串
+ *
+ * @param in_str 输入字符串
+ * @param str_vec 输出字符串向量
+ */
+ void parse_string_with_quotes(std::string in_str, std::vector &str_vec);
+};
+
+#endif // _GCTL_STR_H
\ No newline at end of file
diff --git a/lib/geometry.h b/lib/geometry.h
deleted file mode 100644
index d8fbe64..0000000
--- a/lib/geometry.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/********************************************************
- * ██████╗ ██████╗████████╗██╗
- * ██╔════╝ ██╔════╝╚══██╔══╝██║
- * ██║ ███╗██║ ██║ ██║
- * ██║ ██║██║ ██║ ██║
- * ╚██████╔╝╚██████╗ ██║ ███████╗
- * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
- * Geophysical Computational Tools & Library (GCTL)
- *
- * Copyright (c) 2023 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 .
- *
- * 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.
- ******************************************************/
-
-#ifndef _GCTL_GEOMETRY_H
-#define _GCTL_GEOMETRY_H
-
-#include "geometry/refellipsoid.h"
-#include "geometry/geometry2d.h"
-#include "geometry/geometry3d.h"
-
-#endif // _GCTL_GEOMETRY_H
\ No newline at end of file
diff --git a/lib/graphic/cliplot.h b/lib/graphic/cliplot.h
index e919978..277d594 100644
--- a/lib/graphic/cliplot.h
+++ b/lib/graphic/cliplot.h
@@ -36,7 +36,7 @@
#include
#include
-#include "../utility/stream_t.h"
+#include "../io/term_io.h"
namespace gctl
{
diff --git a/lib/graphic/gmt.h b/lib/graphic/gmt.h
index 816d743..acbb4bd 100644
--- a/lib/graphic/gmt.h
+++ b/lib/graphic/gmt.h
@@ -34,8 +34,8 @@
#include
#include "gmt/gmt.h"
-#include "../utility/stream.h"
#include "../core/array.h"
+#include "../io/file_io.h"
#include "../io/netcdf_io.h"
#ifndef GMT_VF_LEN
diff --git a/lib/graphic/gnuplot.h b/lib/graphic/gnuplot.h
index 73b9f32..56ece74 100644
--- a/lib/graphic/gnuplot.h
+++ b/lib/graphic/gnuplot.h
@@ -33,7 +33,7 @@
#include
#include
-#include "../utility/stream.h"
+#include "../io/file_io.h"
namespace gctl
{
diff --git a/lib/io.h b/lib/io.h
index 2777008..de841e6 100644
--- a/lib/io.h
+++ b/lib/io.h
@@ -28,18 +28,22 @@
#ifndef _GCTL_IO_H
#define _GCTL_IO_H
-#include "io/netcdf_io.h"
-#include "io/mesh_io.h"
+#include "io/term_io.h"
+#include "io/file_io.h"
#include "io/native_io.h"
-#include "io/text_io.h"
-#include "io/dsv_io.h"
-#include "io/gmsh_io.h"
+
#include "io/surfer_io.h"
-#include "io/tetgen_io.h"
-#include "io/triangle_io.h"
+#include "io/netcdf_io.h"
+
#include "io/off_io.h"
#include "io/stl_io.h"
#include "io/ply_io.h"
-#include "io/cli_viewer.h"
+#include "io/tetgen_io.h"
+#include "io/triangle_io.h"
+#include "io/gmsh_io.h"
+#include "io/mesh_io.h"
+
+#include "io/text_io.h"
+#include "io/dsv_io.h"
#endif // _GCTL_IO_H
\ No newline at end of file
diff --git a/lib/io/dsv_io.cpp b/lib/io/dsv_io.cpp
index 4428acb..e3357cb 100644
--- a/lib/io/dsv_io.cpp
+++ b/lib/io/dsv_io.cpp
@@ -26,7 +26,6 @@
******************************************************/
#include "dsv_io.h"
-#include "cli_viewer.h"
gctl::dsv_io::dsv_io()
{
diff --git a/lib/io/dsv_io.h b/lib/io/dsv_io.h
index 9f09b77..789916c 100644
--- a/lib/io/dsv_io.h
+++ b/lib/io/dsv_io.h
@@ -28,20 +28,20 @@
#ifndef _GCTL_DSV_IO_H
#define _GCTL_DSV_IO_H
-#include "../gctl_config.h"
+#include "regex.h"
+
+#include "../core/matrix.h"
+#include "../poly/point2c.h"
+#include "../poly/point2p.h"
+#include "../poly/point3c.h"
+#include "../poly/point3s.h"
+#include "file_io.h"
+#include "term_io.h"
+
#ifdef GCTL_EXPRTK
#include "exprtk.hpp"
#endif // GCTL_EXPRTK
-#include "regex.h"
-
-#include "../core.h"
-#include "../utility/stream.h"
-#include "../geometry/point2c.h"
-#include "../geometry/point2p.h"
-#include "../geometry/point3c.h"
-#include "../geometry/point3s.h"
-
namespace gctl
{
enum table_cell_type
diff --git a/lib/utility/stream.cpp b/lib/io/file_io.cpp
similarity index 50%
rename from lib/utility/stream.cpp
rename to lib/io/file_io.cpp
index 3988607..7bfcca2 100644
--- a/lib/utility/stream.cpp
+++ b/lib/io/file_io.cpp
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -25,166 +25,7 @@
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
-#include
-
-#if defined _WINDOWS || __WIN32__
-#include
-// Test for file existence
-#define F_OK 0
-#endif
-
-#include "stream.h"
-
-//在终端显示一个简易的GCTL图标
-void gctl::display_logo(std::ostream &sout)
-{
- sout << " ___ ___ _____ __\n";
- sout << " / _ \\ / __\\/__ \\ / /\n";
- sout << " / /_\\// / / /\\// /\n";
- sout << "/ /_\\\\/ /___ / / / /___\n";
- sout << "\\____/\\____/ \\/ \\____/\n";
- sout << "Geophysical Computational Tools & Library\n";
- sout << "Author: Dr. Yi Zhang (yizhang-geo@zju.edu.cn)\n\n";
- return;
-}
-
-//替换str中所有lod_value为new_value,返回被替换的old_value的个数
-int gctl::replace_all(std::string& new_str, const std::string& old_str,const std::string& old_value,const std::string& new_value)
-{
- int count = 0;
- new_str = old_str;
- for(std::string::size_type pos(0);pos!=std::string::npos;pos+=new_value.length())
- {
- if((pos=new_str.find(old_value,pos))!=std::string::npos)
- {
- new_str.replace(pos,old_value.length(),new_value);
- count++;
- }
- else break;
- }
- return count;
-}
-
-//在输入字符串末尾添加一段字符串,如果输入字符串的尾端与待添加的字符串一致则不添加并返回原字符串
-std::string gctl::patch_string(std::string in_str, std::string patch_str)
-{
- int inlen = in_str.length();
- int exlen = patch_str.length();
-
- std::string out_str = in_str;
-
- if (exlen > inlen)
- {
- out_str += patch_str;
- return out_str;
- }
-
- if (exlen == inlen && in_str != patch_str)
- {
- out_str += patch_str;
- return out_str;
- }
-
- if (in_str.substr(inlen - exlen, inlen) != patch_str)
- {
- out_str += patch_str;
- return out_str;
- }
-
- return out_str;
-}
-
-//转换string对象为stringstream对象
-void gctl::str2ss(std::string in_str, std::stringstream &out_ss, std::string delimiter)
-{
- if (delimiter != "")
- {
- std::string replace_str;
- replace_all(replace_str, in_str, delimiter, " ");
- out_ss.clear();
- out_ss.str(replace_str);
- }
- else
- {
- out_ss.clear();
- out_ss.str(in_str);
- }
- return;
-}
-
-/**
- * @brief 转换string字符串为double类型的数值
- *
- * 这个函数的主要作用是检查输入字符串是否为nan或者inf等表示无效值的符号。有的编译器
- * 可以在>>输入符中完成此检测,但为了函数功能的稳定,所以在此处自定了这个函数。
- *
- * @param[in] instr 输入字符串
- *
- * @return 返回的double类型的数值
- */
-double gctl::str2double(std::string instr)
-{
- if (instr == "NAN" || instr == "nan" || instr == "NaN")
- return NAN;
- else if (instr == "INF" || instr == "inf" || instr == "Inf")
- return INFINITY;
- else
- {
- auto e(instr.find_first_of("dD"));
- if (e != std::string::npos) instr[e] = 'e';
-
- return atof(instr.c_str());
- }
-}
-
-/**
- * @brief 转换double类型数值为string类型字符串
- *
- * @param[in] in_d 输入数值
- *
- * @return 输出字符串
- */
-std::string gctl::double2str(double in_d)
-{
- std::string tmp_str;
- std::stringstream tmp_ss;
-
- tmp_ss.clear();
- if (std::isnan(in_d))
- tmp_ss.str("nan");
- else if (std::isinf(in_d))
- tmp_ss.str("inf");
- else tmp_ss << in_d;
-
- tmp_ss >> tmp_str;
- return tmp_str;
-}
-
-//返回指定长度的随机字符串
-void gctl::random_char(unsigned int length, char* out)
-{
- char str[76] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*+_-=?";
- int i,lstr;
- char ss[2] = {0};
- lstr = strlen(str);//计算字符串长度
- srand((unsigned int)time((time_t *)NULL));//使用系统时间来初始化随机数发生器
- //按指定大小返回相应的字符串
- for(i = 1; i <= length; i++)
- {
- snprintf(ss, 2, "%c",str[(rand()%lstr)]);//rand()%lstr 可随机返回0-61之间的整数, str[0-61]可随机得到其中的字符
- strcat(out,ss);//将随机生成的字符串连接到指定数组后面
- }
- return;
-}
-
-void gctl::random_str(unsigned int length, std::string &out_str)
-{
- char *out_char = new char [length];
- random_char(length, out_char);
- out_str = out_char;
- delete[] out_char;
- return;
-}
+#include "file_io.h"
//测试打开输入文件 如果成功则返回0并输出信息 否则返回1
void gctl::open_infile(std::ifstream &infile, std::string filename, std::string extension,
@@ -192,7 +33,7 @@ void gctl::open_infile(std::ifstream &infile, std::string filename, std::string
{
if (filename == "")
{
- throw domain_error("Empty file name. From open_infile(...)");
+ throw std::domain_error("Empty file name. From open_infile(...)");
}
// 文件流开启则先关闭文件
@@ -209,7 +50,7 @@ void gctl::open_infile(std::ifstream &infile, std::string filename, std::string
infile.open(filename+extension, mode);
if (!infile)
{
- throw domain_error("Fail to open file: " + filename + extension + ". From open_infile(...)");
+ throw gctl::domain_error("Fail to open file: " + filename + extension + ". From open_infile(...)");
}
return;
}
@@ -219,7 +60,7 @@ void gctl::open_infile(std::ifstream &infile, std::string filename, std::string
infile.open(filename, mode);
if (!infile)
{
- throw domain_error("Fail to open file: " + filename + ". From open_infile(...)");
+ throw gctl::domain_error("Fail to open file: " + filename + ". From open_infile(...)");
}
return;
}
@@ -229,7 +70,7 @@ void gctl::open_matched_infile(std::ifstream &infile, std::string filename,
{
if (exten_pattern == "" || filename == "")
{
- throw domain_error("Empty file name or extension(s). From open_matched_infile(...)");
+ throw std::domain_error("Empty file name or extension(s). From open_matched_infile(...)");
}
if (infile.is_open()) infile.close();
@@ -354,81 +195,6 @@ void gctl::open_matched_outfile(std::ofstream &outfile, std::string filename,
return;
}
-int gctl::terminal_width()
-{
- int width;
- //获取终端窗口的行列数
-#ifdef _WINDOWS
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
- width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
-#else
- struct winsize w;
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
- width = w.ws_col;
-#endif
-
- return width;
-}
-
-int gctl::terminal_height()
-{
- int height;
- //获取终端窗口的行列数
-#ifdef _WINDOWS
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
- height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
-#else
- struct winsize w;
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
- height = w.ws_row;
-#endif
-
- return height;
-}
-
-void gctl::parse_string_with_quotes(std::string in_str, std::vector &str_vec)
-{
- std::vector tmp_units;
- parse_string_to_vector(in_str, ' ', tmp_units);
-
- // Combine strings into one if they are enclosed by quotes
- std::string tmp_str = "";
- int i = 0;
- while (i < tmp_units.size())
- {
- if (tmp_units[i].front() == '"' && tmp_units[i].back() == '"')
- {
- str_vec.push_back(tmp_units[i].substr(1, tmp_units[i].length() - 1));
- i++;
- }
- else if (tmp_units[i].front() == '"')
- {
- tmp_str = tmp_units[i].substr(1, tmp_units[i].length());
- i++;
-
- while (tmp_units[i].back() != '"')
- {
- tmp_str += " " + tmp_units[i];
- i++;
- }
-
- tmp_str += " " + tmp_units[i].substr(0, tmp_units[i].length() - 1);
- i++;
-
- str_vec.push_back(tmp_str);
- tmp_str = "";
- }
- else
- {
- str_vec.push_back(tmp_units[i]);
- i++;
- }
- }
- return;
-}
-
void gctl::parse_filename(std::string filename, std::string &naked_name, std::string &exten_name)
{
naked_name = filename.substr(0, filename.rfind("."));
diff --git a/lib/utility/stream.h b/lib/io/file_io.h
similarity index 51%
rename from lib/utility/stream.h
rename to lib/io/file_io.h
index 6778305..fdeba67 100644
--- a/lib/utility/stream.h
+++ b/lib/io/file_io.h
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -24,104 +24,15 @@
* 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.
******************************************************/
-#ifndef _GCTL_STREAM_H
-#define _GCTL_STREAM_H
-// system's head files
-#include
-#include
-#include
-#include
-#include
-#include
+#ifndef _GCTL_FILE_IO_H
+#define _GCTL_FILE_IO_H
-#ifdef _WINDOWS
-#include
-#else
-#include
-#endif
-
-// library's head files
-#include "stream_t.h"
+#include "../core/str.h"
namespace gctl
{
- /**
- * @brief 在终端显示一个简易的GCTL图标
- */
- void display_logo(std::ostream &sout = std::cout);
-
- /**
- * @brief 替换字符串中的指定子串
- *
- * @param new_str 替换后的字符串
- * @param old_str 需要操作的字符串
- * @param old_value 需要被替换的字串
- * @param new_value 替换的字串
- *
- * @return 替换的次数
- */
- int replace_all(std::string& new_str, const std::string& old_str, const std::string& old_value,
- const std::string& new_value);
-
- /**
- * @brief 在输入字符串末尾添加一段字符串,如果输入字符串的尾端与待添加的字符串一致则不添加并返回原字符串
- *
- * @param in_str 输入字符串
- * @param patch_str 待匹配的字符串
- * @return 输出字符串
- */
- std::string patch_string(std::string in_str, std::string patch_str);
-
- /**
- * @brief 转换string对象为stringstream对象
- *
- * @param[in] in_str 输入的string字符串
- * @param out_ss 引用返回的stringstreams对象
- * @param[in] delimiter 分割string对象时的分隔符。如果不为空,
- * 函数会将delimiter转换为空格
- */
- void str2ss(std::string in_str, std::stringstream &out_ss, std::string delimiter = "");
-
- /**
- * @brief 转换string字符串为double类型的数值
- *
- * 这个函数的主要作用是检查输入字符串是否为nan或者inf等表示无效值的符号。有的编译器
- * 可以在>>输入符中完成此检测,但为了函数功能的稳定,所以在此处自定了这个函数。这个函数
- * 还可以将fortran输出文件中以D标注的科学数字转换为浮点类型
- *
- * @param[in] instr 输入字符串
- *
- * @return 返回的double类型的数值
- */
- double str2double(std::string instr);
-
- /**
- * @brief 转换double类型数值为string类型字符串 标准库中有to_string函数,以后就不用这个了。
- *
- * @param[in] in_d 输入数值
- *
- * @return 输出字符串
- */
- std::string double2str(double in_d);
-
- /**
- * @brief 返回一定长度的随机字符串
- *
- * @param[in] length 字符串的长度
- * @param out 输出字符串
- */
- void random_char(unsigned int length, char* out);
-
- /**
- * @brief 返回一定长度的随机字符串
- *
- * @param[in] length 字符串的长度
- * @param out_str 输出字符串
- */
- void random_str(unsigned int lenght, std::string &out_str);
-
- /**
+ /**
* @brief 打开输入文件
*
* @param infile ifstream对象
@@ -165,30 +76,6 @@ namespace gctl
void open_matched_outfile(std::ofstream &outfile, std::string filename, std::string exten_pattern,
std::ios_base::openmode mode = std::ios_base::out);
- /**
- * @brief 返回当前终端窗口的字符宽度
- *
- * @return 宽度
- */
- int terminal_width();
-
- /**
- * @brief 返回当前终端窗口的字符高度
- *
- * @return 高度
- */
- int terminal_height();
-
- /**
- * @brief 解析字符串并返回以空格分割的字符串向量
- *
- * @note 双引号括起来的部分将解析为一个字符串
- *
- * @param in_str 输入字符串
- * @param str_vec 输出字符串向量
- */
- void parse_string_with_quotes(std::string in_str, std::vector &str_vec);
-
/**
* @brief 解析文件路径
*
@@ -199,4 +86,4 @@ namespace gctl
void parse_filename(std::string filename, std::string &naked_name, std::string &exten_name);
};
-#endif // _GCTL_STREAM_H
\ No newline at end of file
+#endif // _GCTL_FILE_IO_H
\ No newline at end of file
diff --git a/lib/io/gmsh_io.h b/lib/io/gmsh_io.h
index 99cb155..0a1c6ec 100644
--- a/lib/io/gmsh_io.h
+++ b/lib/io/gmsh_io.h
@@ -29,9 +29,21 @@
#define _GCTL_GMSH_IO_H
// library's head files
-#include "../core.h"
-#include "../geometry.h"
-#include "../utility.h"
+#include "../core/matrix.h"
+#include "../poly/node.h"
+#include "../poly/sphere.h"
+#include "../poly/triangle2d.h"
+#include "../poly/triangle2d2o.h"
+#include "../poly/rectangle2d.h"
+#include "../poly/edge2d.h"
+#include "../poly/block.h"
+#include "../poly/prism.h"
+#include "../poly/tesseroid.h"
+#include "../poly/tetrahedron.h"
+#include "../poly/tri_cone.h"
+#include "../poly/triangle.h"
+#include "../poly/edge.h"
+#include "file_io.h"
#ifdef GCTL_EIGEN
#include "Eigen/Dense"
diff --git a/lib/io/mesh_io.cpp b/lib/io/mesh_io.cpp
index 687b4c2..fcac492 100644
--- a/lib/io/mesh_io.cpp
+++ b/lib/io/mesh_io.cpp
@@ -1821,7 +1821,7 @@ void gctl::mesh_io::save_data_to_xyz(std::string filename, std::string dataname,
{
if (out_coor == Spherical)
{
- ps = vptr->c2s();
+ ps = c2s(*vptr);
ps.rad -= ellipse_radius_2d(refR, refr, ps.lat*GCTL_Pi/180.0);
ofile << ps.lon << " " << ps.lat << " " << ps.rad << " " << datas_[i].val[n] << "\n";
@@ -1852,7 +1852,7 @@ void gctl::mesh_io::save_data_to_xyz(std::string filename, std::string dataname,
if (out_coor == Spherical)
{
- ps = pc.c2s();
+ ps = c2s(pc);
ps.rad -= ellipse_radius_2d(refR, refr, ps.lat*GCTL_Pi/180.0);
ofile << ps.lon << " " << ps.lat << " " << ps.rad << " " << datas_[i].val[e] << "\n";
diff --git a/lib/io/mesh_io.h b/lib/io/mesh_io.h
index 5832001..2698039 100644
--- a/lib/io/mesh_io.h
+++ b/lib/io/mesh_io.h
@@ -29,16 +29,12 @@
#define _GCTL_MESH_IO_H
#include
+#include