dev_yi #1
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ build/
|
||||
.vscode/
|
||||
tmp/
|
||||
doc/html
|
||||
doc/man
|
||||
doc/man
|
||||
installer
|
@ -10,6 +10,7 @@ option(GCTL_NETCDF "Use the NetCDF library" ON)
|
||||
option(GCTL_FFTW3 "Use the FFTW3 library" ON)
|
||||
option(GCTL_EEMD "Use the EEMD library" ON)
|
||||
option(GCTL_OPENBLAS "Use the Openblas library" OFF)
|
||||
option(GCTL_EXPRTK "Use the ExprTK library" ON)
|
||||
option(GCTL_CHECK_BOUNDER "Check array's index" OFF)
|
||||
option(GCTL_CHECK_SIZE "Check array's size" OFF)
|
||||
# 传递安装地址给编译期宏变量
|
||||
@ -24,6 +25,7 @@ message(STATUS "[GCTL] Use the NetCDF library: " ${GCTL_NETCDF})
|
||||
message(STATUS "[GCTL] Use the FFTW3 library: " ${GCTL_FFTW3})
|
||||
message(STATUS "[GCTL] Use the EEMD library: " ${GCTL_EEMD})
|
||||
message(STATUS "[GCTL] Use the Openblas library: " ${GCTL_OPENBLAS})
|
||||
message(STATUS "[GCTL] Use the ExprTK library: " ${GCTL_EXPRTK})
|
||||
message(STATUS "[GCTL] Check Bounder: " ${GCTL_CHECK_BOUNDER})
|
||||
message(STATUS "[GCTL] Check Size: " ${GCTL_CHECK_SIZE})
|
||||
|
||||
|
@ -15,6 +15,7 @@ set(@PROJECT_NAME@_FFTW3 @GCTL_FFTW3@)
|
||||
set(@PROJECT_NAME@_EEMD @GCTL_EEMD@)
|
||||
set(@PROJECT_NAME@_OPENMP @GCTL_OPENMP@)
|
||||
set(@PROJECT_NAME@_OPENBLAS @GCTL_OPENBLAS@)
|
||||
set(@PROJECT_NAME@_EXPRTK @GCTL_EXPRTK@)
|
||||
set(@PROJECT_NAME@_CHECK_BOUNDER @GCTL_CHECK_BOUNDER@)
|
||||
set(@PROJECT_NAME@_CHECK_SIZE @GCTL_CHECK_SIZE@)
|
||||
|
||||
@ -23,6 +24,7 @@ message(STATUS "[GCTL] Use the FFTW3 library: " @GCTL_FFTW3@)
|
||||
message(STATUS "[GCTL] Use the EEMD library: " @GCTL_EEMD@)
|
||||
message(STATUS "[GCTL] Use the OpenMP library: " @GCTL_OPENMP@)
|
||||
message(STATUS "[GCTL] Use the Openblas library: " @GCTL_OPENBLAS@)
|
||||
message(STATUS "[GCTL] Use the ExprTK library: " @GCTL_EXPRTK@)
|
||||
message(STATUS "[GCTL] Check Bounder: " @GCTL_CHECK_BOUNDER@)
|
||||
message(STATUS "[GCTL] Check Size: " @GCTL_CHECK_SIZE@)
|
||||
|
||||
|
@ -4,5 +4,6 @@
|
||||
#cmakedefine GCTL_FFTW3
|
||||
#cmakedefine GCTL_EEMD
|
||||
#cmakedefine GCTL_OPENBLAS
|
||||
#cmakedefine GCTL_EXPRTK
|
||||
#cmakedefine GCTL_CHECK_BOUNDER
|
||||
#cmakedefine GCTL_CHECK_SIZE
|
@ -32,33 +32,31 @@ using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
/*
|
||||
dsv_io tc;
|
||||
|
||||
dsv_io tc, tout;
|
||||
tc.set_delimeter('|');
|
||||
tc.load_text("tmp/world_data", ".txt", BothHead);
|
||||
tc.info();
|
||||
//tc.info();
|
||||
|
||||
//_1s_vector name = tc.get_row_names();
|
||||
//display_vector(name);
|
||||
//tc.set_column_type(Int, "IndepYear_n");
|
||||
//tc.filt_column("IndepYear_n < 0", {"IndepYear_n"}, {"Name_s", "Population_n", "GNP_n"}, tout);
|
||||
|
||||
_1s_array name;
|
||||
tc.get_column("Name_s", name);
|
||||
name.show(std::cout, ',');
|
||||
tc.filt_column("America", "Continent_s", {"Name_s", "Population_n", "GNP_n"}, tout);
|
||||
//tc.match_column("America", "Continent_s", {}, tout);
|
||||
|
||||
tc.get_row("AUS", name);
|
||||
name.show(std::cout, ',');
|
||||
|
||||
tc.save_csv("out");
|
||||
*/
|
||||
tout.set_delimeter('|');
|
||||
tout.save_text("out");
|
||||
|
||||
/*
|
||||
geodsv_io tc;
|
||||
tc.load_text("tmp/topo", ".txt", ColumnHead);
|
||||
tc.cell(0, 0, std::string("x (m)"));
|
||||
tc.cell(0, 1, std::string("y (m)"));
|
||||
tc.cell(0, 2, std::string("elevation (m)"));
|
||||
tc.set_column_names({"x (m)", "y (m)", "elev (m)"});
|
||||
tc.set_column_type(Float, "x (m)");
|
||||
tc.set_column_type(Float, "y (m)");
|
||||
tc.set_column_type(Float, "elev (m)");
|
||||
|
||||
array<point3dc> topo;
|
||||
tc.get_column_point3dc(0, 1, 2, topo);
|
||||
tc.get_column_point3dc(topo, 1, 2, 3);
|
||||
|
||||
std::clog << std::setprecision(11) << topo.front().z << "\n";
|
||||
std::clog << topo.back().x << "," << topo.back().y << "," << topo.back().z << "\n";
|
||||
@ -66,17 +64,36 @@ int main(int argc, char const *argv[]) try
|
||||
display_vector(tc.get_annotoations(), std::clog, '\n');
|
||||
display_vector(tc.get_head_records(), std::clog, '\n');
|
||||
|
||||
//tc.column_output("C3", Disable);
|
||||
|
||||
array<double> elev;
|
||||
tc.get_column(elev, "elev (m)");
|
||||
elev.for_each([](double &d, size_t i){d += 100.0;});
|
||||
|
||||
tc.add_column(2, "elev_plus");
|
||||
tc.fill_column(elev, "elev_plus");
|
||||
|
||||
tc.add_column(-1, "dist");
|
||||
tc.cal_column("dist := sqrt(C1*C1 + C3*C3)", {"dist", "C1", "C3"});
|
||||
|
||||
tc.add_row(3);
|
||||
tc.fill_row(array<double>{5.5, 4.4, 3.3, 2.2, 1.1}, 3);
|
||||
|
||||
geodsv_io out_table;
|
||||
tc.filt_column("dist > 1000", {"dist"}, {"x (m)", "y (m)", "elev (m)"}, out_table);
|
||||
out_table.save_text("out2");
|
||||
|
||||
_1s_vector s = tc.get_tags();
|
||||
s.push_back("Elev = 1000");
|
||||
tc.set_tags(s);
|
||||
tc.save_csv("out");
|
||||
|
||||
double c = 4.25242153654;
|
||||
tc.cell(1, 0, c, 12);
|
||||
std::clog << std::setprecision(12) << tc.cell<double>(1, 0) << "\n";
|
||||
tc.cell(c, 2, 1, 12);
|
||||
std::clog << std::setprecision(12) << tc.cell<double>(2, 1) << "\n";
|
||||
|
||||
tc.info();
|
||||
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
|
54
installer
54
installer
@ -1,54 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $# == 0 || ${1} == "help" ]]; then
|
||||
echo "Compiles executables/libraries and maintains installed files. Two tools 'Cmake' and 'stow' are empolyed here. For more information, see https://cmake.org and https://www.gnu.org/software/stow/."
|
||||
echo ""
|
||||
echo "School of Earth Sciences, Zhejiang University"
|
||||
echo "Yi Zhang (yizhang-geo@zju.edu.cn)"
|
||||
echo ""
|
||||
echo "Usage: ./config.sh [option] [Cmake options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo "(1) configure: Configure Cmake project(s). This option could take extra Cmake options as in <option>=<value>."
|
||||
echo "(2) build: Build executables/libraries."
|
||||
echo "(3) install: Install executables/libraries to the directory of CMAKE_INSTALL_PREFIX and sym-links them to the target address. This offers a quick and clean remove of the installed files."
|
||||
echo "(4) clean: Clean build/ folder(s)."
|
||||
echo "(5) uninstall: Delete the installed files and sym-links."
|
||||
echo "(6) info: Print out current setups."
|
||||
echo "(7) help: Show help information."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
package=gctl
|
||||
address=/opt/stow
|
||||
taress=/usr/local
|
||||
option="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${address}/${package}"
|
||||
|
||||
if [[ $# -gt 1 ]]; then
|
||||
for opt in "$@"; do
|
||||
if [[ ${opt} != "configure" ]]; then
|
||||
option="${option} -D${opt}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${1} == "configure" && ! -d "build/" ]]; then
|
||||
mkdir build && cd build && cmake .. ${option}
|
||||
elif [[ ${1} == "configure" ]]; then
|
||||
cd build && rm -rf * && cmake .. ${option}
|
||||
elif [[ ${1} == "build" ]]; then
|
||||
cd build && make
|
||||
elif [[ ${1} == "install" ]]; then
|
||||
cd build && sudo make install
|
||||
sudo stow --dir=${address} --target=${taress} -S ${package}
|
||||
elif [[ ${1} == "clean" ]]; then
|
||||
rm -rf build/
|
||||
elif [[ ${1} == "uninstall" ]]; then
|
||||
sudo stow --dir=${address} --target=${taress} -D ${package}
|
||||
sudo rm -rf ${address}/${package}
|
||||
elif [[ ${1} == "info" ]]; then
|
||||
echo "package name:" ${package}
|
||||
echo "stow address:" ${address}
|
||||
echo "target address:" ${taress}
|
||||
echo "Cmake options:" ${option}
|
||||
fi
|
@ -511,27 +511,27 @@ namespace gctl
|
||||
* @param[in] np2 Standard deviation (Gauss) or hig bound value (Even).
|
||||
* @param[in] mode Random types. 'RdNormal' for Gaussian distributed numbers and
|
||||
* 'RdUniform' for even distributed numbers.
|
||||
* @param[in] seed Random seed.
|
||||
* @param[in] seed Random seed. Input 0 to select the seed based on the current time.
|
||||
*/
|
||||
void random_float(ArrValType np1, ArrValType np2, random_type_e mode = RdNormal, unsigned int seed = 0);
|
||||
|
||||
/**
|
||||
* @brief Initialize the array with selected random types.
|
||||
*
|
||||
* @param[in] np1 Mean (Gauss) or low bound value (Even)
|
||||
* @param[in] np2 Standard deviation (Gauss) or hig bound value (Even).
|
||||
* @param[in] seed Random seed.
|
||||
* @param[in] np1 Low bound value.
|
||||
* @param[in] np2 Hig bound value.
|
||||
* @param[in] seed Random seed. Input 0 to select the seed based on the current time.
|
||||
*/
|
||||
void random_int(ArrValType np1, ArrValType np2, unsigned int seed = 0);
|
||||
|
||||
/**
|
||||
* @brief Set elements' value as a sequent.
|
||||
*
|
||||
* @param st_val Start value.
|
||||
* @param inc Increasement.
|
||||
* @param st_id Start index.
|
||||
* @param size Operating size.
|
||||
* @param space Indexing spacing.
|
||||
* @param st_val Start value of the sequent.
|
||||
* @param inc Increasement of the sequent.
|
||||
* @param st_id Start index. The default starts from the first element
|
||||
* @param size Operating size. The default operates on all elements
|
||||
* @param space Indexing spacing. you can skip elements when create the sequent. The default is no skipping.
|
||||
*/
|
||||
void sequence(ArrValType st_val, ArrValType inc, size_t st_id = 0,
|
||||
size_t size = std::numeric_limits<size_t>::max(), size_t space = 0);
|
||||
|
@ -4,5 +4,6 @@
|
||||
#define GCTL_FFTW3
|
||||
#define GCTL_EEMD
|
||||
/* #undef GCTL_OPENBLAS */
|
||||
#define GCTL_EXPRTK
|
||||
/* #undef GCTL_CHECK_BOUNDER */
|
||||
/* #undef GCTL_CHECK_SIZE */
|
||||
|
File diff suppressed because it is too large
Load Diff
671
lib/io/dsv_io.h
671
lib/io/dsv_io.h
@ -28,15 +28,37 @@
|
||||
#ifndef _GCTL_DSV_IO_H
|
||||
#define _GCTL_DSV_IO_H
|
||||
|
||||
#include "../gctl_config.h"
|
||||
#include "../core.h"
|
||||
#include "../utility.h"
|
||||
#include "../geometry.h"
|
||||
#include "regex.h"
|
||||
|
||||
#ifdef GCTL_EXPRTK
|
||||
#include "exprtk.hpp"
|
||||
#endif // GCTL_EXPRTK
|
||||
|
||||
namespace gctl
|
||||
{
|
||||
enum cell_type_e
|
||||
{
|
||||
String,
|
||||
Int,
|
||||
Float,
|
||||
};
|
||||
|
||||
struct table_cell
|
||||
{
|
||||
std::string str_;
|
||||
std::string str_; // 单元格的内容 统一保存为字符串
|
||||
cell_type_e type_; // 类型字符串
|
||||
bool out_ok_; // 是否可输出到文件
|
||||
|
||||
table_cell()
|
||||
{
|
||||
str_ = "";
|
||||
type_ = Float;
|
||||
out_ok_ = true;
|
||||
}
|
||||
|
||||
template <typename T> T value()
|
||||
{
|
||||
@ -52,6 +74,18 @@ namespace gctl
|
||||
|
||||
template <typename T> void value(const T &in, int p = 6)
|
||||
{
|
||||
// 单元被赋值时使用的类型
|
||||
const std::type_info &tinfo = typeid(T);
|
||||
|
||||
std::smatch ret;
|
||||
std::regex pat("basic_string");
|
||||
|
||||
std::string t_str = tinfo.name();
|
||||
if (regex_search(t_str, ret, pat)) type_ = String;
|
||||
else if (t_str == "i") type_ = Int;
|
||||
else if (t_str == "f") type_ = Float;
|
||||
else if (t_str == "d") type_ = Float;
|
||||
|
||||
// 对于double类型 可以设置转换的有效数字位数(精度)
|
||||
if constexpr (std::is_same<T, double>::value)
|
||||
{
|
||||
@ -86,21 +120,21 @@ namespace gctl
|
||||
* 2. 以'#!'开始的行均为标记行,标识符可由用户指定;
|
||||
* 3. 文本开始可以包含n行头信息;
|
||||
* 4. 数据体为一个row*col大小的表格;
|
||||
* 5. 数据体可以包含一列行名称与列名称。
|
||||
*
|
||||
* 5. 数据表格文件可以额外包含一列行名称与列名称;
|
||||
* 6. 如论文件内是否包含行头或列头,均可使用内置的行名称R<id>或列名称C<id>指定相应的行或列
|
||||
*/
|
||||
class dsv_io
|
||||
{
|
||||
protected:
|
||||
// 文件名
|
||||
std::string file_;
|
||||
table_headtype_e thead_;
|
||||
// 头信息行数 表格行数 表格列数
|
||||
// 头信息行数 表格行数(不包括表头) 表格列数(不包括表头)
|
||||
int head_num_, row_num_, col_num_;
|
||||
// 注释行起始符 标记行起始符 分割符
|
||||
char att_sym_, tag_sym_, deli_sym_;
|
||||
// 头信息行 注释行 标记行
|
||||
std::vector<std::string> heads_, annotates_, tags_;
|
||||
// 内容表格
|
||||
// 内容表格(大小为row_num_+1 * col_num_+1)
|
||||
std::vector<std::vector<table_cell> > table_;
|
||||
|
||||
public:
|
||||
@ -121,9 +155,72 @@ namespace gctl
|
||||
*
|
||||
* @param filename 文件名
|
||||
* @param file_exten 文件扩展名
|
||||
* @param t 表格是否有行和列名称
|
||||
*/
|
||||
dsv_io(std::string filename, std::string file_exten = ".txt", table_headtype_e t = NoHead);
|
||||
|
||||
/**
|
||||
* @brief 清理字符串向量对象
|
||||
*
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* @brief 返回头信息行数
|
||||
*
|
||||
* @return 行数
|
||||
*/
|
||||
int head_number(){return head_num_;}
|
||||
|
||||
/**
|
||||
* @brief 返回数据行数
|
||||
*
|
||||
* @return 行数
|
||||
*/
|
||||
int row_number(){return row_num_;}
|
||||
|
||||
/**
|
||||
* @brief 返回数据列数
|
||||
*
|
||||
* @return 列数
|
||||
*/
|
||||
int col_number(){return col_num_;}
|
||||
|
||||
/**
|
||||
* @brief 返回头信息
|
||||
*
|
||||
* @return 头信息
|
||||
*/
|
||||
const std::vector<std::string>& get_head_records(){return heads_;}
|
||||
|
||||
/**
|
||||
* @brief 返回注释行
|
||||
*
|
||||
* @return 注释行
|
||||
*/
|
||||
const std::vector<std::string>& get_annotoations(){return annotates_;}
|
||||
|
||||
/**
|
||||
* @brief 返回标记行
|
||||
*
|
||||
* @return 标记
|
||||
*/
|
||||
const std::vector<std::string>& get_tags(){return tags_;}
|
||||
|
||||
/**
|
||||
* @brief 获取行名称
|
||||
*
|
||||
* @param names 名称
|
||||
*/
|
||||
void get_row_names(std::vector<std::string> &names);
|
||||
|
||||
/**
|
||||
* @brief 获取列名称
|
||||
*
|
||||
* @param names 名称
|
||||
*/
|
||||
void get_column_names(std::vector<std::string> &names);
|
||||
|
||||
/**
|
||||
* @brief 设置列分隔符
|
||||
*
|
||||
@ -152,80 +249,79 @@ namespace gctl
|
||||
*/
|
||||
void set_tag_symbol(char tag_sym){tag_sym_ = tag_sym;}
|
||||
|
||||
/**
|
||||
* @brief 返回头信息行数
|
||||
*
|
||||
* @return 行数
|
||||
*/
|
||||
int head_number(){return head_num_;}
|
||||
|
||||
/**
|
||||
* @brief 返回行数
|
||||
*
|
||||
* @return 行数
|
||||
*/
|
||||
int row_number(){return row_num_;}
|
||||
|
||||
/**
|
||||
* @brief 返回列数
|
||||
*
|
||||
* @return 列数
|
||||
*/
|
||||
int col_number(){return col_num_;}
|
||||
|
||||
/**
|
||||
* @brief 返回头信息
|
||||
*
|
||||
* @return 头信息
|
||||
*/
|
||||
const std::vector<std::string>& get_head_records(){return heads_;}
|
||||
|
||||
/**
|
||||
* @brief 返回注释行
|
||||
*
|
||||
* @return 注释行
|
||||
*/
|
||||
const std::vector<std::string>& get_annotoations(){return annotates_;}
|
||||
|
||||
/**
|
||||
* @brief 返回标记行
|
||||
*
|
||||
* @return 标记
|
||||
*/
|
||||
const std::vector<std::string>& get_tags(){return tags_;}
|
||||
|
||||
/**
|
||||
* @brief 设置头信息
|
||||
*
|
||||
* @param heads 头信息
|
||||
*/
|
||||
void set_head_records(const std::vector<std::string> &heads);
|
||||
void set_head_records(const std::vector<std::string> &heads){heads_ = heads; head_num_ = heads_.size();}
|
||||
|
||||
/**
|
||||
* @brief 设置注释
|
||||
*
|
||||
* @param att 注释
|
||||
*/
|
||||
void set_annotoations(const std::vector<std::string> &att);
|
||||
void set_annotoations(const std::vector<std::string> &att){annotates_ = att;}
|
||||
|
||||
/**
|
||||
* @brief 设置标记
|
||||
*
|
||||
* @param tags 标记
|
||||
*/
|
||||
void set_tags(const std::vector<std::string> &tags);
|
||||
void set_tags(const std::vector<std::string> &tags){tags_ = tags;}
|
||||
|
||||
/**
|
||||
* @brief 清理字符串向量对象
|
||||
*
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* @brief 设置行名称
|
||||
*
|
||||
* @param names 名称
|
||||
*/
|
||||
void set_row_names(const std::vector<std::string> &names, std::string corner_name = "row-idx");
|
||||
|
||||
/**
|
||||
* @brief 设置列名称
|
||||
*
|
||||
* @param names 名称
|
||||
*/
|
||||
void set_column_names(const std::vector<std::string> &names);
|
||||
|
||||
/**
|
||||
* @brief 设置行类型
|
||||
*
|
||||
* @param t 类型名称 String|Float|Int
|
||||
* @param idx 行索引
|
||||
*/
|
||||
void set_row_type(cell_type_e t, int idx);
|
||||
|
||||
/**
|
||||
* @brief 设置行类型
|
||||
*
|
||||
* @param t 类型名称 String|Float|Int
|
||||
* @param name 行名称
|
||||
*/
|
||||
void set_row_type(cell_type_e t, std::string name);
|
||||
|
||||
/**
|
||||
* @brief 设置列类型
|
||||
*
|
||||
* @param t 类型名称 String|Float|Int
|
||||
* @param idx 列索引
|
||||
*/
|
||||
void set_column_type(cell_type_e t, int idx);
|
||||
|
||||
/**
|
||||
* @brief 设置列类型
|
||||
*
|
||||
* @param t 类型名称 String|Float|Int
|
||||
* @param name 列名称
|
||||
*/
|
||||
void set_column_type(cell_type_e t, std::string name);
|
||||
|
||||
/**
|
||||
* @brief 读入文本文件
|
||||
*
|
||||
* @param filename 文件名
|
||||
* @param file_exten 文件扩展名
|
||||
* @param t 表格是否有行和列名称
|
||||
*/
|
||||
void load_text(std::string filename, std::string file_exten = ".txt", table_headtype_e t = NoHead);
|
||||
|
||||
@ -254,34 +350,176 @@ namespace gctl
|
||||
/**
|
||||
* @brief 初始化表格
|
||||
*
|
||||
* @param row 行数
|
||||
* @param col 列数
|
||||
* @param row 数据行数
|
||||
* @param col 数据列数
|
||||
*/
|
||||
void init_table(int row, int col, table_headtype_e t = ColumnHead);
|
||||
void init_table(int row, int col);
|
||||
|
||||
/**
|
||||
* @brief 返回表格信息
|
||||
*
|
||||
* @param t 显示表格信息的类型
|
||||
*/
|
||||
void info();
|
||||
void info(table_headtype_e t = ColumnHead);
|
||||
|
||||
/**
|
||||
* @brief 返回名称为name的行或列的索引
|
||||
* @brief 返回名称为name和R<id>和C<id>的行或列的索引
|
||||
*
|
||||
* @param name 名称
|
||||
* @param iter_row 搜索行名称(默认为搜索列名称)
|
||||
* @return 索引
|
||||
* @param name 名称 可以是具体的名称(如有),或者是R<id>和C<id>
|
||||
* @param iter_row 搜索行名称(默认为搜索列名称),如果name参数为R<id>和C<id>则此参数无效
|
||||
* @return 索引 返回的索引(大于等于1 小于等于行数或列数)失败则返回-1
|
||||
*/
|
||||
int name_index(std::string name, bool iter_row = false);
|
||||
|
||||
/**
|
||||
* @brief 设置列输出。你仍然可以使用这些数据,它们只是不会被输出
|
||||
*
|
||||
* @param idx 列索引 从1开始
|
||||
* @param s 设置输出类型
|
||||
*/
|
||||
void column_output(int idx, switch_type_e s = Disable);
|
||||
|
||||
/**
|
||||
* @brief 设置列输出。你仍然可以使用这些数据,它们只是不会被输出
|
||||
*
|
||||
* @param name 列名称
|
||||
* @param s 设置输出类型
|
||||
*/
|
||||
void column_output(std::string name, switch_type_e s = Disable);
|
||||
|
||||
/**
|
||||
* @brief 设置行输出。你仍然可以使用这些数据,它们只是不会被输出
|
||||
*
|
||||
* @param idx 行索引 从1开始
|
||||
* @param s 设置输出类型
|
||||
*/
|
||||
void row_output(int idx, switch_type_e s = Disable);
|
||||
|
||||
/**
|
||||
* @brief 设置行输出。你仍然可以使用这些数据,它们只是不会被输出
|
||||
*
|
||||
* @param name 行名称
|
||||
* @param s 设置输出类型
|
||||
*/
|
||||
void row_output(std::string name, switch_type_e s = Disable);
|
||||
|
||||
/**
|
||||
* @brief 在表格末尾添加一个空白列
|
||||
*
|
||||
* @param name 设置列名称
|
||||
*/
|
||||
void add_column(std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief 在索引为idx的列插入一个空白列
|
||||
*
|
||||
* @param idx 列索引 小于等于0时将在表尾添加一列
|
||||
* @param name 设置列名称
|
||||
*/
|
||||
void add_column(int idx, std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief 在名称为id_name的列插入一个空白列
|
||||
*
|
||||
* @param id_name 索引列名称
|
||||
* @param name 设置列名称
|
||||
*/
|
||||
void add_column(std::string id_name, std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief 在表格末尾添加一个空白行
|
||||
*
|
||||
* @param name 设置行名称
|
||||
*/
|
||||
void add_row(std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief 在索引为idx的列插入一个空白行
|
||||
*
|
||||
* @param idx 行索引 小于等于0时将在表尾添加一行
|
||||
* @param name 设置行名称
|
||||
*/
|
||||
void add_row(int idx, std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief 在名称为id_name的列插入一个空白行
|
||||
*
|
||||
* @param id_name 索引行名称
|
||||
* @param name 设置行名称
|
||||
*/
|
||||
void add_row(std::string id_name, std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief 按行过滤并返回符合条件的列数据
|
||||
*
|
||||
* @param cnd_str 正则表达式
|
||||
* @param cnd_col 用于匹配正则表达式的列名称
|
||||
* @param out_col 输出的列索引列表(列表为空时则会输出所有列),正则表达式为真时即筛选这些行与列上对应的数据
|
||||
* @param out_table 输出的表格
|
||||
*/
|
||||
void filt_column(std::string cnd_str, std::string cnd_col,
|
||||
const std::vector<std::string> &out_col, dsv_io &out_table);
|
||||
|
||||
/**
|
||||
* @brief row operate function pointer
|
||||
*
|
||||
*/
|
||||
typedef bool (*rowbool_func_t)(const std::vector<table_cell> &table_row);
|
||||
|
||||
/**
|
||||
* @brief 按行过滤并返回符合条件的列数据
|
||||
*
|
||||
* @param func 处理行类容的布尔函数
|
||||
* @param out_col 输出的列索引列表(列表为空时则会输出所有列),正则表达式为真时即筛选这些行与列上对应的数据
|
||||
* @param out_table 输出的表格
|
||||
*/
|
||||
void filt_column(rowbool_func_t func, const std::vector<std::string> &out_col, dsv_io &out_table);
|
||||
|
||||
#ifdef GCTL_EXPRTK
|
||||
|
||||
/**
|
||||
* @brief 使用现有的表格数据计算新的列数据。使用时需要提供计算表达式,例如:C3 := C1 + C2
|
||||
* 表示将C1与C2列数据的和保存到C3列,其中C<id>表示计算所使用数据的索引,你也可以使用具体的列名称。
|
||||
*
|
||||
* @note 只有单元格类型为float和Int类型的列数据才能用于计算。计算由exprtk库完成,支持的表达式见其说明文档。
|
||||
*
|
||||
* @param expr_str 计算表达式 如C3 := C1 + C2
|
||||
* @param col_list 列索引列表 如C3 C1 C2 (注意保存计算结果的列要放在开头)
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
void cal_column(std::string expr_str, const std::vector<std::string> &col_list, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 按行过滤并返回符合条件的列数据
|
||||
*
|
||||
* @note 只有单元格类型为float和Int类型的列数据才能用于计算。计算由exprtk库完成,支持的表达式见其说明文档。
|
||||
* 因为没有使用strtk库的相关内容,所以并不支持对字符串与数字类型的混合条件判断。基于字符串的内容提取请使用其他函数。
|
||||
*
|
||||
* @param cnd_str 条件表达式
|
||||
* @param cnd_col 用于条件表达式的列索引列表
|
||||
* @param out_col 输出的列索引列表(列表为空时则会输出所有列),即条件判断为真时即筛选这些行与列上对应的数据
|
||||
* @param out_table 输出的表格
|
||||
*/
|
||||
void filt_column(std::string cnd_str, const std::vector<std::string> &cnd_col,
|
||||
const std::vector<std::string> &out_col, dsv_io &out_table);
|
||||
|
||||
#endif // GCTL_EXPRTK
|
||||
|
||||
/**
|
||||
* @brief 初始化表格
|
||||
*
|
||||
* @param data 向量表格 每行元素个数必须相等(不包含行与列的名称)
|
||||
*/
|
||||
template <typename T> void init_table(const std::vector<std::vector<T> > &data, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充表格
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param data 矩阵数据
|
||||
* @param data 矩阵数据 大小与表格一致
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
template <typename T> void fill_table(const matrix<T> &data, int p = 6);
|
||||
template <typename T> void init_table(const matrix<T> &data, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 获取表格
|
||||
@ -295,11 +533,11 @@ namespace gctl
|
||||
* @brief 填充列
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param idx 列索引
|
||||
* @param idx 列索引 从1开始
|
||||
* @param data 列数据
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
template <typename T> void fill_column(int idx, const array<T> &data, int p = 6);
|
||||
template <typename T> void fill_column(const array<T> &data, int idx, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充列
|
||||
@ -309,17 +547,17 @@ namespace gctl
|
||||
* @param data 列数据
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
template <typename T> void fill_column(std::string name, const array<T> &data, int p = 6);
|
||||
template <typename T> void fill_column(const array<T> &data, std::string name, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充行
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param idx 行索引
|
||||
* @param idx 行索引 从1开始
|
||||
* @param data 行数据
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
template <typename T> void fill_row(int idx, const array<T> &data, int p = 6);
|
||||
template <typename T> void fill_row(const array<T> &data, int idx, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充行
|
||||
@ -329,16 +567,16 @@ namespace gctl
|
||||
* @param data 行数据
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
template <typename T> void fill_row(std::string name, const array<T> &data, int p = 6);
|
||||
template <typename T> void fill_row(const array<T> &data, std::string name, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 获取列数据
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param idx 列索引
|
||||
* @param idx 列索引 从1开始
|
||||
* @param data 列数据
|
||||
*/
|
||||
template <typename T> void get_column(int idx, array<T> &data);
|
||||
template <typename T> void get_column(array<T> &data, int idx);
|
||||
|
||||
/**
|
||||
* @brief 获取列数据
|
||||
@ -347,16 +585,16 @@ namespace gctl
|
||||
* @param name 列名称
|
||||
* @param data 列数据
|
||||
*/
|
||||
template <typename T> void get_column(std::string name, array<T> &data);
|
||||
template <typename T> void get_column(array<T> &data, std::string name);
|
||||
|
||||
/**
|
||||
* @brief 获取行数据
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param idx 行索引
|
||||
* @param idx 行索引 从1开始
|
||||
* @param data 行数据
|
||||
*/
|
||||
template <typename T> void get_row(int idx, array<T> &data);
|
||||
template <typename T> void get_row(array<T> &data, int idx);
|
||||
|
||||
/**
|
||||
* @brief 获取行数据
|
||||
@ -365,14 +603,14 @@ namespace gctl
|
||||
* @param name 行名称
|
||||
* @param data 行数据
|
||||
*/
|
||||
template <typename T> void get_row(std::string name, array<T> &data);
|
||||
template <typename T> void get_row(array<T> &data, std::string name);
|
||||
|
||||
/**
|
||||
* @brief 获取表格单元数据
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param r 行号
|
||||
* @param c 列号
|
||||
* @param r 行号 从0开始(可以操作行或列名称)
|
||||
* @param c 列号 从0开始(可以操作行或列名称)
|
||||
* @return T 单元数据
|
||||
*/
|
||||
template <typename T> T cell(int r, int c){return table_[r][c].value<T>();}
|
||||
@ -381,28 +619,59 @@ namespace gctl
|
||||
* @brief 填充表格单元数据
|
||||
*
|
||||
* @tparam T 数据类型
|
||||
* @param r 行号
|
||||
* @param c 列号
|
||||
* @param r 行号 从0开始(可以操作行或列名称)
|
||||
* @param c 列号 从0开始(可以操作行或列名称)
|
||||
* @param d 数据
|
||||
* @param p 浮点类数据保存时的有效数字位数
|
||||
*/
|
||||
template <typename T> void cell(int r, int c, T d, int p = 6){table_[r][c].value(d, p); return;}
|
||||
template <typename T> void cell(T d, int r, int c, int p = 6){table_[r][c].value(d, p); return;}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::fill_table(const matrix<T> &data, int p)
|
||||
void dsv_io::init_table(const std::vector<std::vector<T> > &data, int p)
|
||||
{
|
||||
int st = 0;
|
||||
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
||||
if (!table_.empty()) clear();
|
||||
|
||||
int ft = 0;
|
||||
if (thead_ == RowHead || thead_ == BothHead) ft = 1;
|
||||
row_num_ = data.size();
|
||||
col_num_ = data[0].size();
|
||||
|
||||
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.row_size()); i++)
|
||||
// 初始的列头和行头均为空白
|
||||
table_.resize(row_num_ + 1);
|
||||
for (size_t i = 0; i < row_num_ + 1; i++)
|
||||
{
|
||||
for (size_t j = 0; j < std::min(col_num_ - ft, (int) data.col_size()); j++)
|
||||
table_[i].resize(col_num_ + 1);
|
||||
}
|
||||
|
||||
for (size_t i = 1; i <= row_num_; i++)
|
||||
{
|
||||
for (size_t j = 1; j <= col_num_; j++)
|
||||
{
|
||||
table_[i + st][j + ft].value(data[i][j], p);
|
||||
table_[i][j].value(data[i - 1][j - 1], p);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::init_table(const matrix<T> &data, int p)
|
||||
{
|
||||
if (!table_.empty()) clear();
|
||||
|
||||
row_num_ = data.row_size();
|
||||
col_num_ = data.col_size();
|
||||
|
||||
// 初始的列头和行头均为空白
|
||||
table_.resize(row_num_ + 1);
|
||||
for (size_t i = 0; i < row_num_ + 1; i++)
|
||||
{
|
||||
table_[i].resize(col_num_ + 1);
|
||||
}
|
||||
|
||||
for (size_t i = 1; i <= row_num_; i++)
|
||||
{
|
||||
for (size_t j = 1; j <= col_num_; j++)
|
||||
{
|
||||
table_[i][j].value(data[i - 1][j - 1], p);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -411,122 +680,104 @@ namespace gctl
|
||||
template <typename T>
|
||||
void dsv_io::get_table(matrix<T> &data)
|
||||
{
|
||||
int st = 0;
|
||||
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
||||
|
||||
int ft = 0;
|
||||
if (thead_ == RowHead || thead_ == BothHead) ft = 1;
|
||||
|
||||
data.resize(row_num_ - st, col_num_ - ft);
|
||||
for (size_t i = st; i < row_num_; i++)
|
||||
data.resize(row_num_, col_num_);
|
||||
for (size_t i = 1; i <= row_num_; i++)
|
||||
{
|
||||
for (size_t j = ft; j < col_num_; j++)
|
||||
for (size_t j = 1; j <= col_num_; j++)
|
||||
{
|
||||
data[i - st][j - ft] = table_[i][j].value<T>();
|
||||
data[i -1][j - 1] = table_[i][j].value<T>();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::fill_column(int idx, const array<T> &data, int p)
|
||||
void dsv_io::fill_column(const array<T> &data, int idx, int p)
|
||||
{
|
||||
if (idx >= col_num_)
|
||||
{
|
||||
throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
|
||||
}
|
||||
|
||||
int st = 0;
|
||||
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
||||
|
||||
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++)
|
||||
{
|
||||
table_[i + st][idx].value(data[i], p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::fill_column(std::string name, const array<T> &data, int p)
|
||||
{
|
||||
fill_column(name_index(name, false), data, p);
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::fill_row(int idx, const array<T> &data, int p)
|
||||
{
|
||||
if (idx >= row_num_)
|
||||
{
|
||||
throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
|
||||
}
|
||||
|
||||
int st = 0;
|
||||
if (thead_ == RowHead || thead_ == BothHead) st = 1;
|
||||
|
||||
for (size_t i = 0; i < std::min(col_num_ - st, (int) data.size()); i++)
|
||||
{
|
||||
table_[idx][i + st].value(data[i], p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::fill_row(std::string name, const array<T> &data, int p)
|
||||
{
|
||||
fill_row(name_index(name, true), data, p);
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_column(int idx, array<T> &data)
|
||||
{
|
||||
if (idx >= col_num_)
|
||||
if (idx > col_num_ || idx <= 0)
|
||||
{
|
||||
throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
|
||||
}
|
||||
|
||||
int st = 0;
|
||||
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
||||
|
||||
data.resize(row_num_ - st);
|
||||
for (size_t i = st; i < row_num_; i++)
|
||||
for (size_t i = 1; i <= std::min(row_num_, (int) data.size()); i++)
|
||||
{
|
||||
data[i - st] = table_[i][idx].value<T>();
|
||||
table_[i][idx].value(data[i - 1], p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_column(std::string name, array<T> &data)
|
||||
void dsv_io::fill_column(const array<T> &data, std::string name, int p)
|
||||
{
|
||||
get_column(name_index(name, false), data);
|
||||
fill_column(data, name_index(name, false), p);
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_row(int idx, array<T> &data)
|
||||
void dsv_io::fill_row(const array<T> &data, int idx, int p)
|
||||
{
|
||||
if (idx >= row_num_)
|
||||
if (idx > row_num_ || idx <= 0)
|
||||
{
|
||||
throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
|
||||
}
|
||||
|
||||
int st = 0;
|
||||
if (thead_ == RowHead || thead_ == BothHead) st = 1;
|
||||
|
||||
data.resize(col_num_ - st);
|
||||
for (size_t i = st; i < col_num_; i++)
|
||||
for (size_t i = 1; i <= std::min(col_num_, (int) data.size()); i++)
|
||||
{
|
||||
data[i - st] = table_[idx][i].value<T>();
|
||||
table_[idx][i].value(data[i - 1], p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_row(std::string name, array<T> &data)
|
||||
void dsv_io::fill_row(const array<T> &data, std::string name, int p)
|
||||
{
|
||||
get_row(name_index(name, true), data);
|
||||
fill_row(data, name_index(name, true), p);
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_column(array<T> &data, int idx)
|
||||
{
|
||||
if (idx > col_num_ || idx <= 0)
|
||||
{
|
||||
throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
|
||||
}
|
||||
|
||||
data.resize(row_num_);
|
||||
for (size_t i = 1; i <= row_num_; i++)
|
||||
{
|
||||
data[i - 1] = table_[i][idx].value<T>();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_column(array<T> &data, std::string name)
|
||||
{
|
||||
get_column(data, name_index(name, false));
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_row(array<T> &data, int idx)
|
||||
{
|
||||
if (idx > row_num_ || idx <= 0)
|
||||
{
|
||||
throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
|
||||
}
|
||||
|
||||
data.resize(col_num_);
|
||||
for (size_t i = 1; i <= col_num_; i++)
|
||||
{
|
||||
data[i - 1] = table_[idx][i].value<T>();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dsv_io::get_row(array<T> &data, std::string name)
|
||||
{
|
||||
get_row(data, name_index(name, true));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -560,12 +811,12 @@ namespace gctl
|
||||
/**
|
||||
* @brief 填充二维坐标列
|
||||
*
|
||||
* @param xid x坐标列索引
|
||||
* @param yid y坐标列索引
|
||||
* @param xid x坐标列索引 从1开始
|
||||
* @param yid y坐标列索引 从1开始
|
||||
* @param data 返回的二维坐标数据
|
||||
* @param p 填入的浮点数据有效位数(精度)
|
||||
*/
|
||||
void fill_column_point2dc(int xid, int yid, const array<point2dc> &data, int p = 6);
|
||||
void fill_column_point2dc(const array<point2dc> &data, int xid, int yid, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充二维坐标列
|
||||
@ -575,18 +826,18 @@ namespace gctl
|
||||
* @param data 返回的二维坐标数据
|
||||
* @param p 填入的浮点数据有效位数(精度)
|
||||
*/
|
||||
void fill_column_point2dc(std::string xname, std::string yname, const array<point2dc> &data, int p = 6);
|
||||
void fill_column_point2dc(const array<point2dc> &data, std::string xname, std::string yname, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充三维坐标列
|
||||
*
|
||||
* @param xid x坐标列索引
|
||||
* @param yid y坐标列索引
|
||||
* @param zid z坐标列索引
|
||||
* @param xid x坐标列索引 从1开始
|
||||
* @param yid y坐标列索引 从1开始
|
||||
* @param zid z坐标列索引 从1开始
|
||||
* @param data 返回的三维坐标数据
|
||||
* @param p 填入的浮点数据有效位数(精度)
|
||||
*/
|
||||
void fill_column_point3dc(int xid, int yid, int zid, const array<point3dc> &data, int p = 6);
|
||||
void fill_column_point3dc(const array<point3dc> &data, int xid, int yid, int zid, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充三维坐标列
|
||||
@ -597,16 +848,38 @@ namespace gctl
|
||||
* @param data 返回的三维坐标数据
|
||||
* @param p 填入的浮点数据有效位数(精度)
|
||||
*/
|
||||
void fill_column_point3dc(std::string xname, std::string yname, std::string zname, const array<point3dc> &data, int p = 6);
|
||||
void fill_column_point3dc(const array<point3dc> &data, std::string xname, std::string yname, std::string zname, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充三维坐标列
|
||||
*
|
||||
* @param rid rad坐标列索引 从1开始
|
||||
* @param pid phi坐标(经度)列索引 从1开始
|
||||
* @param tid theta坐标(纬度)列索引 从1开始
|
||||
* @param data 返回的三维坐标数据
|
||||
* @param p 填入的浮点数据有效位数(精度)
|
||||
*/
|
||||
void fill_column_point3ds(const array<point3ds> &data, int rid, int pid, int tid, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 填充三维坐标列
|
||||
*
|
||||
* @param rname rad坐标列名称 从1开始
|
||||
* @param pname phi坐标(经度)列名称 从1开始
|
||||
* @param tname theta坐标(纬度)列名称 从1开始
|
||||
* @param data 返回的三维坐标数据
|
||||
* @param p 填入的浮点数据有效位数(精度)
|
||||
*/
|
||||
void fill_column_point3ds(const array<point3ds> &data, std::string rname, std::string pname, std::string tname, int p = 6);
|
||||
|
||||
/**
|
||||
* @brief 读取二维坐标列
|
||||
*
|
||||
* @param xid x坐标列索引
|
||||
* @param yid y坐标列索引
|
||||
* @param xid x坐标列索引 从1开始
|
||||
* @param yid y坐标列索引 从1开始
|
||||
* @param data 返回的二维坐标数据
|
||||
*/
|
||||
void get_column_point2dc(int xid, int yid, array<point2dc> &data);
|
||||
void get_column_point2dc(array<point2dc> &data, int xid, int yid);
|
||||
|
||||
/**
|
||||
* @brief 读取二维坐标列
|
||||
@ -615,17 +888,17 @@ namespace gctl
|
||||
* @param yname y坐标列名称
|
||||
* @param data 返回的二维坐标数据
|
||||
*/
|
||||
void get_column_point2dc(std::string xname, std::string yname, array<point2dc> &data);
|
||||
void get_column_point2dc(array<point2dc> &data, std::string xname, std::string yname);
|
||||
|
||||
/**
|
||||
* @brief 读取三维坐标列
|
||||
*
|
||||
* @param xid x坐标列索引
|
||||
* @param yid y坐标列索引
|
||||
* @param zid z坐标列索引
|
||||
* @param xid x坐标列索引 从1开始
|
||||
* @param yid y坐标列索引 从1开始
|
||||
* @param zid z坐标列索引 从1开始
|
||||
* @param data 返回的三维坐标数据
|
||||
*/
|
||||
void get_column_point3dc(int xid, int yid, int zid, array<point3dc> &data);
|
||||
void get_column_point3dc(array<point3dc> &data, int xid, int yid, int zid);
|
||||
|
||||
/**
|
||||
* @brief 读取三维坐标列
|
||||
@ -635,7 +908,27 @@ namespace gctl
|
||||
* @param zname z坐标列名称
|
||||
* @param data 返回的三维坐标数据
|
||||
*/
|
||||
void get_column_point3dc(std::string xname, std::string yname, std::string zname, array<point3dc> &data);
|
||||
void get_column_point3dc(array<point3dc> &data, std::string xname, std::string yname, std::string zname);
|
||||
|
||||
/**
|
||||
* @brief 读取三维坐标列
|
||||
*
|
||||
* @param rid rad坐标列索引 从1开始
|
||||
* @param pid phi坐标(经度)列索引 从1开始
|
||||
* @param tid theta坐标(纬度)列索引 从1开始
|
||||
* @param data 返回的三维坐标数据
|
||||
*/
|
||||
void get_column_point3ds(array<point3ds> &data, int rid, int pid, int tid);
|
||||
|
||||
/**
|
||||
* @brief 读取三维坐标列
|
||||
*
|
||||
* @param rname rad坐标列名称 从1开始
|
||||
* @param pname phi坐标(经度)列名称 从1开始
|
||||
* @param tname theta坐标(纬度)列名称 从1开始
|
||||
* @param data 返回的三维坐标数据
|
||||
*/
|
||||
void get_column_point3ds(array<point3ds> &data, std::string rname, std::string pname, std::string tname);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -207,11 +207,63 @@ void quit(const std::vector<std::string> &cmd_units)
|
||||
|
||||
void info(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
if (cmd_units.size() == 1) // cmd_units[0] == info
|
||||
// info [column|row|both]
|
||||
if (cmd_units.size() > 1)
|
||||
{
|
||||
tc.info();
|
||||
return;
|
||||
if (cmd_units[1] == "row") tc.info(RowHead);
|
||||
if (cmd_units[1] == "both") tc.info(BothHead);
|
||||
}
|
||||
else tc.info();
|
||||
return;
|
||||
}
|
||||
|
||||
void set_enable(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// enable column|row <column> <column>...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("enable: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "column")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
if (tc.name_index(cmd_units[i]) < 0) tc.column_output(atoi(cmd_units[i].c_str()), Enable);
|
||||
else tc.column_output(cmd_units[i], Enable);
|
||||
}
|
||||
}
|
||||
else if (cmd_units[1] == "row")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
if (tc.name_index(cmd_units[i], true) < 0) tc.row_output(atoi(cmd_units[i].c_str()), Enable);
|
||||
else tc.row_output(cmd_units[i], Enable);
|
||||
}
|
||||
}
|
||||
else throw std::runtime_error("enable: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void set_disable(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// disable column|row <column> <column>...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("disable: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "column")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
if (tc.name_index(cmd_units[i]) < 0) tc.column_output(atoi(cmd_units[i].c_str()), Disable);
|
||||
else tc.column_output(cmd_units[i], Enable);
|
||||
}
|
||||
}
|
||||
else if (cmd_units[1] == "row")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
if (tc.name_index(cmd_units[i], true) < 0) tc.row_output(atoi(cmd_units[i].c_str()), Disable);
|
||||
else tc.row_output(cmd_units[i], Enable);
|
||||
}
|
||||
}
|
||||
else throw std::runtime_error("disable: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -279,7 +331,7 @@ void statistic(const std::vector<std::string> &cmd_units)
|
||||
_1d_array data;
|
||||
for (size_t i = 1; i < cmd_units.size(); i++)
|
||||
{
|
||||
tc.get_column(cmd_units[i], data);
|
||||
tc.get_column(data, cmd_units[i]);
|
||||
std::clog << "column: " << cmd_units[i]
|
||||
<< " | " << data.min() << "/" << data.mean() << "/" << data.max()
|
||||
<< " | STD: " << data.std() << "\n";
|
||||
|
@ -48,14 +48,18 @@ void info(const std::vector<std::string> &cmd_units);
|
||||
void load_file(const std::vector<std::string> &cmd_units);
|
||||
void save_file(const std::vector<std::string> &cmd_units);
|
||||
void statistic(const std::vector<std::string> &cmd_units);
|
||||
void set_enable(const std::vector<std::string> &cmd_units);
|
||||
void set_disable(const std::vector<std::string> &cmd_units);
|
||||
|
||||
#define CMD_NUM 6
|
||||
#define CMD_NUM 8
|
||||
const cmd_pair commands[CMD_NUM] = {
|
||||
{"quit", quit, "Quit the program."},
|
||||
{"info", info, "Show the table information."},
|
||||
{"open", load_file, "Open a dsv/csv file."},
|
||||
{"save", save_file, "Save the table to a file."},
|
||||
{"stats", statistic, "Calculate statistics of the selected columns."},
|
||||
{"enable", set_enable, "Enable column/row outputs by name or index."},
|
||||
{"disable", set_disable, "Disable column/row outputs by name or index."},
|
||||
{"null", nullptr, "null"}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user