This commit is contained in:
张壹 2025-02-05 14:11:40 +08:00
parent b011a82f64
commit 2215a17d5f
8 changed files with 154 additions and 194 deletions

View File

@ -33,7 +33,7 @@ if(GCTL_FFTW3)
if(NOT FFTW3_FOUND)
find_package(FFTW3 REQUIRED)
message(STATUS "Found FFTW3")
include_directories(${FFTW3_INC_DIR})
include_directories(${FFTW3_INCLUDE_DIRS})
endif()
endif()

View File

@ -45,7 +45,7 @@ endif()
if(@PROJECT_NAME@_FFTW3)
if(NOT FFTW3_FOUND)
find_package(FFTW3 REQUIRED)
include_directories(${FFTW3_INC_DIR})
include_directories(${FFTW3_INCLUDE_DIRS})
endif()
endif()

View File

@ -25,7 +25,6 @@
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/core.h"
#include "../lib/io.h"
using namespace gctl;
@ -34,7 +33,7 @@ int main(int argc, char const *argv[]) try
{
dsv_io tc, tout;
tc.set_delimeter('|');
tc.delimeter('|');
tc.load_text("tmp/world_data", ".txt", BothHead);
//tc.info();
@ -51,7 +50,7 @@ int main(int argc, char const *argv[]) try
int lr_id = tout.add_row();
tout.fill_row(array<std::string>{"Asia", "China", "14000000", "1949"}, lr_id);
tout.set_delimeter('|');
tout.delimeter('|');
tout.save_text("out");
/*

View File

@ -51,10 +51,9 @@ endif()
#
if(GCTL_FFTW3)
# 使find_library
find_library(LIB_TAR ${FFTW3_LIB} HINTS ${FFTW3_LIB_DIR})
target_link_libraries(gctl PUBLIC ${LIB_TAR})
target_link_libraries(gctl_static ${LIB_TAR})
find_library(FFTW_LIB ${FFTW3_LIBRARIES} HINTS ${FFTW3_LIBRARY_DIRS})
target_link_libraries(gctl PUBLIC ${FFTW_LIB})
target_link_libraries(gctl_static ${FFTW_LIB})
endif()
if(GCTL_EEMD)

View File

@ -145,7 +145,7 @@ namespace gctl
*
* @param init_val Initial values
*/
array(std::vector<ArrValType> init_val);
array(std::initializer_list<ArrValType> init_val);
/**
* @brief Construct a new array object as a sequence
@ -394,7 +394,7 @@ namespace gctl
*
* @param init_val Initial values
*/
void resize(std::vector<ArrValType> init_val);
void resize(std::initializer_list<ArrValType> init_val);
/**
* @brief Resize a new array object as a sequence
@ -894,7 +894,7 @@ namespace gctl
}
template <typename ArrValType>
array<ArrValType>::array(std::vector<ArrValType> init_val)
array<ArrValType>::array(std::initializer_list<ArrValType> init_val)
{
length_ = 0;
val_ = nullptr;
@ -1244,12 +1244,15 @@ namespace gctl
}
template <typename ArrValType>
void array<ArrValType>::resize(std::vector<ArrValType> init_val)
void array<ArrValType>::resize(std::initializer_list<ArrValType> init_val)
{
resize(init_val.size());
typename std::initializer_list<ArrValType>::iterator iter = init_val.begin();
for (size_t i = 0; i < length_; i++)
{
val_[i] = init_val[i];
val_[i] = *iter;
iter++;
}
return;
}

View File

@ -74,27 +74,17 @@ void gctl::dsv_io::clear()
return;
}
void gctl::dsv_io::get_row_names(std::vector<std::string> &names)
std::vector<std::string> gctl::dsv_io::row_names()
{
names.resize(row_num_);
_1s_vector names(row_num_);
for (size_t i = 1; i <= row_num_; i++)
{
names[i - 1] = table_[i][0].str_;
}
return;
return names;
}
void gctl::dsv_io::get_column_names(std::vector<std::string> &names)
{
names.resize(col_num_);
for (size_t i = 1; i <= col_num_; i++)
{
names[i - 1] = table_[0][i].str_;
}
return;
}
void gctl::dsv_io::set_row_names(const std::vector<std::string> &names, const std::vector<int> &idx, std::string corner_name)
void gctl::dsv_io::row_names(const std::vector<std::string> &names, const std::vector<int> &idx, std::string corner_name)
{
if (!idx.empty())
{
@ -117,7 +107,17 @@ void gctl::dsv_io::set_row_names(const std::vector<std::string> &names, const st
return;
}
void gctl::dsv_io::set_column_names(const std::vector<std::string> &names, const std::vector<int> &idx)
std::vector<std::string> gctl::dsv_io::column_names()
{
_1s_vector names(col_num_);
for (size_t i = 1; i <= col_num_; i++)
{
names[i - 1] = table_[0][i].str_;
}
return names;
}
void gctl::dsv_io::column_names(const std::vector<std::string> &names, const std::vector<int> &idx)
{
if (!idx.empty())
{
@ -138,7 +138,7 @@ void gctl::dsv_io::set_column_names(const std::vector<std::string> &names, const
return;
}
void gctl::dsv_io::set_row_type(cell_type_e t, int idx)
void gctl::dsv_io::row_type(table_cell_type t, int idx)
{
if (idx > row_num_ || idx <= 0)
{
@ -151,12 +151,12 @@ void gctl::dsv_io::set_row_type(cell_type_e t, int idx)
}
}
void gctl::dsv_io::set_row_type(cell_type_e t, std::string name)
void gctl::dsv_io::row_type(table_cell_type t, std::string name)
{
set_row_type(t, name_index(name, true));
row_type(t, name_index(name, true));
}
void gctl::dsv_io::set_column_type(cell_type_e t, int idx)
void gctl::dsv_io::column_type(table_cell_type t, int idx)
{
if (idx > col_num_ || idx <= 0)
{
@ -170,9 +170,9 @@ void gctl::dsv_io::set_column_type(cell_type_e t, int idx)
return;
}
void gctl::dsv_io::set_column_type(cell_type_e t, std::string name)
void gctl::dsv_io::column_type(table_cell_type t, std::string name)
{
set_column_type(t, name_index(name, false));
column_type(t, name_index(name, false));
}
void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table_headtype_e t)
@ -225,7 +225,7 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table
// 动态调整列数
cn = tmp_cols.size();
cn_max = std::max(cn, cn_max);
cn_max = GCTL_MAX(cn, cn_max);
table_[i].resize(tmp_cols.size());
for (size_t j = 0; j < tmp_cols.size(); j++)
@ -292,7 +292,7 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table
void gctl::dsv_io::load_csv(std::string filename, table_headtype_e t)
{
set_delimeter(',');
delimeter(',');
load_text(filename, ".csv", t);
return;
}
@ -338,59 +338,14 @@ void gctl::dsv_io::save_text(std::string filename, std::string file_exten)
}
outfile << std::endl;
}
/*
// 单独处理第一行 即列头
bool line_st = false;
if (table_[0][0].out_ok_ && table_[0][0].str_ != "")
{
outfile << table_[0][0].str_;
line_st = true;
}
for (int j = 1; j <= col_num_; j++)
{
if (line_st && table_[0][j].out_ok_ && table_[0][j].str_ != "") outfile << deli_sym_ << table_[0][j].str_; // line started
else if (table_[0][j].out_ok_ && table_[0][j].str_ != "") // line not started
{
outfile << table_[0][j].str_;
line_st = true; // start line
}
}
if (line_st) outfile << std::endl;
// 处理余下的行
for (int i = 1; i <= row_num_; i++)
{
line_st = false;
// 单独处理第一列 即行头
if (table_[i][0].out_ok_ && table_[i][0].str_ != "")
{
outfile << table_[i][0].str_;
line_st = true;
}
for (int j = 1; j <= col_num_; j++)
{
if (line_st && table_[i][j].out_ok_) outfile << deli_sym_ << table_[i][j].str_; // line started
else if (table_[i][j].out_ok_) // line not started
{
outfile << table_[i][j].str_;
line_st = true; // start line
}
}
outfile << std::endl;
}
*/
outfile.close();
return;
}
void gctl::dsv_io::save_csv(std::string filename)
{
set_delimeter(',');
delimeter(',');
save_text(filename, ".csv");
return;
}
@ -684,7 +639,7 @@ void gctl::dsv_io::filt_column(std::string cnd_str, std::string cnd_col,
std::vector<std::string> io_col;
if (out_row)
{
get_column_names(io_col);
column_names(io_col);
out_table.cell(table_[0][0].str_, 0, 0);
}
else
@ -697,8 +652,8 @@ void gctl::dsv_io::filt_column(std::string cnd_str, std::string cnd_col,
}
}
out_table.set_column_names(io_col);
out_table.set_row_names(row_names, {}, table_[0][0].str_);
out_table.column_names(io_col);
out_table.row_names(row_names, {}, table_[0][0].str_);
destroy_vector(row_names);
destroy_vector(io_col);
@ -761,7 +716,7 @@ void gctl::dsv_io::filt_column(rowbool_func_t func, const std::vector<std::strin
std::vector<std::string> io_col;
if (out_row)
{
get_column_names(io_col);
column_names(io_col);
out_table.cell(table_[0][0].str_, 0, 0);
}
else
@ -772,8 +727,8 @@ void gctl::dsv_io::filt_column(rowbool_func_t func, const std::vector<std::strin
}
}
out_table.set_column_names(io_col);
out_table.set_row_names(row_names, {}, table_[0][0].str_);
out_table.column_names(io_col);
out_table.row_names(row_names, {}, table_[0][0].str_);
destroy_vector(row_names);
destroy_vector(io_col);
@ -924,7 +879,7 @@ void gctl::dsv_io::filt_column(std::string cnd_str, const std::vector<std::strin
std::vector<std::string> io_col;
if (out_row)
{
get_column_names(io_col);
column_names(io_col);
out_table.cell(table_[0][0].str_, 0, 0);
}
else
@ -940,8 +895,8 @@ void gctl::dsv_io::filt_column(std::string cnd_str, const std::vector<std::strin
}
}
out_table.set_column_names(io_col);
out_table.set_row_names(row_names, {}, table_[0][0].str_);
out_table.column_names(io_col);
out_table.row_names(row_names, {}, table_[0][0].str_);
destroy_vector(row_names);
destroy_vector(io_col);

View File

@ -29,18 +29,22 @@
#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
#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 cell_type_e
enum table_cell_type
{
String,
Int,
@ -50,7 +54,7 @@ namespace gctl
struct table_cell
{
std::string str_; // 单元格的内容 统一保存为字符串
cell_type_e type_; // 类型字符串
table_cell_type type_; // 类型字符串
bool out_ok_; // 是否可输出到文件
table_cell()
@ -165,13 +169,6 @@ namespace gctl
*/
void clear();
/**
* @brief
*
* @return
*/
int head_number(){return head_num_;}
/**
* @brief
*
@ -187,109 +184,102 @@ namespace gctl
int col_number(){return col_num_;}
/**
* @brief
* @brief
*
* @return
* @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
*
* @param deli_sym
*/
void set_delimeter(char deli_sym){deli_sym_ = deli_sym;}
/**
* @brief
*
* @return
*/
char get_delimeter(){return deli_sym_;}
int head_number(){return head_num_;}
/**
* @brief
*
* @param num
*/
void set_head_number(char num){head_num_ = num;}
void head_number(char num){head_num_ = num;}
/**
* @brief
*
* @return
*/
int get_head_number(){return head_num_;}
/**
* @brief
* @brief
*
* @param att_sym
* @return
*/
void set_annotation_symbol(char att_sym){att_sym_ = att_sym;}
/**
* @brief
*
* @return
*/
char get_annotation_symbol(){return att_sym_;}
/**
* @brief
*
* @param tag_sym
*/
void set_tag_symbol(char tag_sym){tag_sym_ = tag_sym;}
const std::vector<std::string> &head_records(){return heads_;}
/**
* @brief
*
* @param heads
*/
void set_head_records(const std::vector<std::string> &heads){heads_ = heads; head_num_ = heads_.size();}
void head_records(const std::vector<std::string> &heads){heads_ = heads; head_num_ = heads_.size();}
/**
* @brief
*
* @param deli_sym
*/
void delimeter(char deli_sym){deli_sym_ = deli_sym;}
/**
* @brief
*
* @return
*/
char delimeter(){return deli_sym_;}
/**
* @brief
*
* @param att_sym
*/
void annotation_symbol(char att_sym){att_sym_ = att_sym;}
/**
* @brief
*
* @return
*/
char annotation_symbol(){return att_sym_;}
/**
* @brief
*
* @param att
*/
void set_annotoations(const std::vector<std::string> &att){annotates_ = att;}
void annotoations(const std::vector<std::string> &att){annotates_ = att;}
/**
* @brief
*
* @return
*/
const std::vector<std::string> &annotoations(){return annotates_;}
/**
* @brief
*
* @param tag_sym
*/
void tag_symbol(char tag_sym){tag_sym_ = tag_sym;}
/**
* @brief
*
* @return
*/
char tag_symbol(){return tag_sym_;}
/**
* @brief
*
* @param tags
*/
void set_tags(const std::vector<std::string> &tags){tags_ = tags;}
void tags(const std::vector<std::string> &tags){tags_ = tags;}
/**
* @brief
*
* @return
*/
const std::vector<std::string> &tags(){return tags_;}
/**
* @brief
@ -298,7 +288,14 @@ namespace gctl
* @param idx
* @param corner_name RowNames
*/
void set_row_names(const std::vector<std::string> &names, const std::vector<int> &idx = {}, std::string corner_name = "RowNames");
void row_names(const std::vector<std::string> &names, const std::vector<int> &idx = {}, std::string corner_name = "RowNames");
/**
* @brief
*
* @return
*/
std::vector<std::string> row_names();
/**
* @brief
@ -306,7 +303,14 @@ namespace gctl
* @param names
* @param idx
*/
void set_column_names(const std::vector<std::string> &names, const std::vector<int> &idx = {});
void column_names(const std::vector<std::string> &names, const std::vector<int> &idx = {});
/**
* @brief
*
* @return
*/
std::vector<std::string> column_names();
/**
* @brief
@ -314,7 +318,7 @@ namespace gctl
* @param t String|Float|Int
* @param idx
*/
void set_row_type(cell_type_e t, int idx);
void row_type(table_cell_type t, int idx);
/**
* @brief
@ -322,7 +326,7 @@ namespace gctl
* @param t String|Float|Int
* @param name
*/
void set_row_type(cell_type_e t, std::string name);
void row_type(table_cell_type t, std::string name);
/**
* @brief
@ -330,7 +334,7 @@ namespace gctl
* @param t String|Float|Int
* @param idx
*/
void set_column_type(cell_type_e t, int idx);
void column_type(table_cell_type t, int idx);
/**
* @brief
@ -338,7 +342,7 @@ namespace gctl
* @param t String|Float|Int
* @param name
*/
void set_column_type(cell_type_e t, std::string name);
void column_type(table_cell_type t, std::string name);
/**
* @brief

View File

@ -238,7 +238,7 @@ void head(const std::vector<std::string> &cmd_units)
for (size_t i = 1; i <= h; i++)
{
tc.get_row(line, i);
line.show(std::cout, tc.get_delimeter());
line.show(std::cout, tc.delimeter());
}
return;
}
@ -254,7 +254,7 @@ void tail(const std::vector<std::string> &cmd_units)
for (size_t i = tc.row_number() - h + 1; i <= tc.row_number(); i++)
{
tc.get_row(line, i);
line.show(std::cout, tc.get_delimeter());
line.show(std::cout, tc.delimeter());
}
return;
}
@ -328,11 +328,11 @@ void load_file(const std::vector<std::string> &cmd_units)
int hnum = 0;
if (copy_str[1] != "null") hnum = atoi(copy_str[1].c_str());
if (hnum != 0) tc.set_head_number(hnum);
if (hnum != 0) tc.head_number(hnum);
if (copy_str[2] != "null") tc.set_delimeter(copy_str[2][0]);
if (copy_str[3] != "null") tc.set_annotation_symbol(copy_str[3][0]);
if (copy_str[4] != "null") tc.set_tag_symbol(copy_str[4][0]);
if (copy_str[2] != "null") tc.delimeter(copy_str[2][0]);
if (copy_str[3] != "null") tc.annotation_symbol(copy_str[3][0]);
if (copy_str[4] != "null") tc.tag_symbol(copy_str[4][0]);
std::string naked_name, exten_name;
parse_filename(cmd_units[1], naked_name, exten_name);
@ -353,9 +353,9 @@ void save_file(const std::vector<std::string> &cmd_units)
copy_str[i] = cmd_units[i + 2];
}
if (copy_str[0] != "null") tc.set_delimeter(copy_str[0][0]);
if (copy_str[1] != "null") tc.set_annotation_symbol(copy_str[1][0]);
if (copy_str[2] != "null") tc.set_tag_symbol(copy_str[2][0]);
if (copy_str[0] != "null") tc.delimeter(copy_str[0][0]);
if (copy_str[1] != "null") tc.annotation_symbol(copy_str[1][0]);
if (copy_str[2] != "null") tc.tag_symbol(copy_str[2][0]);
std::string naked_name, exten_name;
parse_filename(cmd_units[1], naked_name, exten_name);