Merge pull request 'dev_yi' (#1) from dev_yi into main

Reviewed-on: #1
This commit is contained in:
张壹 2025-01-03 15:56:32 +08:00
commit 705d953802
11 changed files with 1395 additions and 422 deletions

View File

@ -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})

View File

@ -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@)

View File

@ -4,5 +4,6 @@
#cmakedefine GCTL_FFTW3
#cmakedefine GCTL_EEMD
#cmakedefine GCTL_OPENBLAS
#cmakedefine GCTL_EXPRTK
#cmakedefine GCTL_CHECK_BOUNDER
#cmakedefine GCTL_CHECK_SIZE

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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
* @brief
*
* @param names
*/
void clear();
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++)
{
table_[i + st][j + ft].value(data[i][j], p);
for (size_t j = 1; j <= col_num_; j++)
{
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_)
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;
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++)
for (size_t i = 1; i <= std::min(row_num_, (int) data.size()); i++)
{
table_[i + st][idx].value(data[i], p);
table_[i][idx].value(data[i - 1], p);
}
return;
}
template <typename T>
void dsv_io::fill_column(std::string name, const array<T> &data, int p)
void dsv_io::fill_column(const array<T> &data, std::string name, int p)
{
fill_column(name_index(name, false), data, p);
fill_column(data, name_index(name, false), p);
return;
}
template <typename T>
void dsv_io::fill_row(int idx, const array<T> &data, int p)
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;
for (size_t i = 0; i < std::min(col_num_ - st, (int) data.size()); i++)
for (size_t i = 1; i <= std::min(col_num_, (int) data.size()); i++)
{
table_[idx][i + st].value(data[i], p);
table_[idx][i].value(data[i - 1], p);
}
return;
}
template <typename T>
void dsv_io::fill_row(std::string name, const array<T> &data, int p)
void dsv_io::fill_row(const array<T> &data, std::string name, int p)
{
fill_row(name_index(name, true), data, p);
fill_row(data, name_index(name, true), p);
return;
}
template <typename T>
void dsv_io::get_column(int idx, array<T> &data)
void dsv_io::get_column(array<T> &data, int idx)
{
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++)
data.resize(row_num_);
for (size_t i = 1; i <= row_num_; i++)
{
data[i - st] = table_[i][idx].value<T>();
data[i - 1] = table_[i][idx].value<T>();
}
return;
}
template <typename T>
void dsv_io::get_column(std::string name, array<T> &data)
void dsv_io::get_column(array<T> &data, std::string name)
{
get_column(name_index(name, false), data);
get_column(data, name_index(name, false));
return;
}
template <typename T>
void dsv_io::get_row(int idx, array<T> &data)
void dsv_io::get_row(array<T> &data, int idx)
{
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++)
data.resize(col_num_);
for (size_t i = 1; i <= col_num_; i++)
{
data[i - st] = table_[idx][i].value<T>();
data[i - 1] = table_[idx][i].value<T>();
}
return;
}
template <typename T>
void dsv_io::get_row(std::string name, array<T> &data)
void dsv_io::get_row(array<T> &data, std::string name)
{
get_row(name_index(name, true), data);
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);
};
}

View File

@ -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();
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";

View File

@ -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"}
};