From 2901590f00122d70f64f1c3afec2cc76c5935598 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 19 Sep 2024 11:24:17 +0800 Subject: [PATCH] tmp update --- addnoise/addnoise.cpp | 9 ++++++--- grd2xyz/grd2xyz.cpp | 4 +++- handyman/handyman.cpp | 19 +++++++++++++------ lbsi/lbsi.h | 12 +++++++----- lki/lki.h | 19 +++++++++++-------- nc2other/nc2other.cpp | 9 ++++++--- slbsi/slbsi.h | 12 +++++++----- tetgm/tetgm.cpp | 3 ++- xyz2nc/xyz2nc.cpp | 14 +++++++++++++- 9 files changed, 68 insertions(+), 33 deletions(-) diff --git a/addnoise/addnoise.cpp b/addnoise/addnoise.cpp index b40a5da..92476a0 100644 --- a/addnoise/addnoise.cpp +++ b/addnoise/addnoise.cpp @@ -47,14 +47,15 @@ int ADDNOSIE::Addnoise(std::string infilename, std::string outfilename, int orde { //读入数据 gctl::text_descriptor desc; + desc.file_name_ = infilename; desc.delimiter_ = delimiter_; - gctl::read_text2vector2d(infilename, in_data_, desc); + gctl::read_text2vector2d(desc, in_data_); //添加噪声 int data_num = in_data_.size(); double tmp_dou; gctl::array noises(data_num); - gctl::random(noises, noise_mean_, noise_dev_); + noises.random_float(noise_mean_, noise_dev_); for (int i = 0; i < data_num; i++) { tmp_dou = in_data_.at(i).at(order) + noises.at(i); @@ -64,7 +65,9 @@ int ADDNOSIE::Addnoise(std::string infilename, std::string outfilename, int orde //保存文件 std::vector head_info(1); head_info[0] = "Generated by 'addnoise' program using " + infilename; - gctl::save_vector2d2text(outfilename, in_data_, delimiter_, '#', &head_info, gctl::RowMajor); + + desc.file_name_ = outfilename; + gctl::save_vector2d2text(desc, in_data_); return 0; } diff --git a/grd2xyz/grd2xyz.cpp b/grd2xyz/grd2xyz.cpp index c455c34..10065c2 100644 --- a/grd2xyz/grd2xyz.cpp +++ b/grd2xyz/grd2xyz.cpp @@ -120,7 +120,9 @@ Please see instructions or contact the author for more information."); } // 保存文本文件 - gctl::save_vector2d2text(out_name + ".txt", out_data, ' ', '#', nullptr, gctl::ColMajor); + gctl::text_descriptor desc; + desc.file_name_ = out_name; + gctl::save_vector2d2text(desc, out_data, gctl::ColMajor); return 0; } catch(std::exception &e) diff --git a/handyman/handyman.cpp b/handyman/handyman.cpp index 3299c28..69e118d 100644 --- a/handyman/handyman.cpp +++ b/handyman/handyman.cpp @@ -140,6 +140,7 @@ void HandyMan::SR_CalPlaneCoeff() void HandyMan::SR_RGB2CPT() { + gctl::text_content tc; std::string rgb_file, cpt_file; std::cout << "Name of the RGB series file (Each line of file contains a R G B group).\n>> "; std::cin >> rgb_file; @@ -147,8 +148,12 @@ void HandyMan::SR_RGB2CPT() std::cout << "Name of the output .cpt file.\n>> "; std::cin >> cpt_file; - std::vector R, G, B; - gctl::read_text2vectors(rgb_file, "0,1,2", ' ', '#', 0, R, G, B); + tc.load_text(rgb_file); + std::vector R(tc.contents_.size()), G(tc.contents_.size()), B(tc.contents_.size()); + for (size_t i = 0; i < tc.contents_.size(); i++) + { + gctl::parse_string_to_value(tc.contents_[i], ' ', true, R[i], G[i], B[i]); + } int c_size = R.size(); int i_type; @@ -196,14 +201,16 @@ void HandyMan::SR_RGB2CPT() } else if (i_type == 2) { - std::string in_str, f_name, d_name; - std::cout << "Name of the .txt input file appended by the index of the data column (+).\n>> "; + std::string in_str, f_name; + std::cout << "Name of the .txt input file.\n>> "; std::cin >> in_str; - gctl::parse_string_to_value(in_str, '+', true, f_name, d_name); + gctl::parse_string_to_value(in_str, '+', true, f_name); + tc.clear(); + tc.load_text(f_name); std::vector D, D_ori; - gctl::read_text2vectors(f_name, d_name, ' ', '#', 0, D_ori); + gctl::str2type_vector(tc.contents_, D_ori); D.reserve(D_ori.size()); for (size_t i = 0; i < D_ori.size(); i++) diff --git a/lbsi/lbsi.h b/lbsi/lbsi.h index 742ffa0..7b8c1e0 100644 --- a/lbsi/lbsi.h +++ b/lbsi/lbsi.h @@ -62,7 +62,7 @@ public: double epsilon); void ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc); void WriteTargetNodes(std::string filename, const gctl::text_descriptor &desc); - void InitTargetNodes(std::string para); + void InitTargetNodes(std::string para, gctl::text_descriptor &desc); void CalKernel(); void CalKernel(const data_point &tar_node); void UpdateTarVec(size_t idx, bool if_global = true); @@ -106,7 +106,7 @@ void LBSI::Routine(std::string in_name, std::string tar_name, } ReadConstrainNodes(in_name, desc); - InitTargetNodes(tar_name); + InitTargetNodes(tar_name, desc); unsigned int k_size = kernel_size; if (k_size <= 1) @@ -233,8 +233,9 @@ void LBSI::Routine(std::string in_name, std::string tar_name, void LBSI::ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc) { + desc.file_name_ = filename; gctl::_2d_vector table_data; - gctl::read_text2vector2d(filename, table_data, desc); + gctl::read_text2vector2d(desc, table_data); if (table_data.size() <= 1) { @@ -303,13 +304,14 @@ void LBSI::WriteTargetNodes(std::string filename, const gctl::text_descriptor &d return; } -void LBSI::InitTargetNodes(std::string para) +void LBSI::InitTargetNodes(std::string para, gctl::text_descriptor &desc) { // try to use the para as a file name if (access(para.c_str(), F_OK) != -1) { + desc.file_name_ = para; std::vector tmp_vec; - read_text2vector(para, tmp_vec); + read_text2vector(desc, tmp_vec); TargNodes.resize(tmp_vec.size()); for (size_t i = 0; i < tmp_vec.size(); ++i) diff --git a/lki/lki.h b/lki/lki.h index 29239a1..5f9bbd6 100644 --- a/lki/lki.h +++ b/lki/lki.h @@ -53,8 +53,8 @@ public: gctl::text_descriptor &desc, int kernel_size, int box_size, double epsilon, std::string variogram_type, std::string variogram_para); void ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc); - void WriteTargetNodes(std::string filename, const gctl::text_descriptor &desc); - void InitTargetNodes(std::string para); + void WriteTargetNodes(std::string filename, gctl::text_descriptor &desc); + void InitTargetNodes(std::string para, gctl::text_descriptor &desc); void CalKernel(); void CalKernel(const gctl::point3dc &tar_node); void set_kernel_size(unsigned int k){MatSize = k+1;} @@ -105,7 +105,7 @@ void LKI::Routine(std::string inname, std::string tarname, std::string outname, } ReadConstrainNodes(inname, desc); - InitTargetNodes(tarname); + InitTargetNodes(tarname, desc); unsigned int k_size = kernel_size; if (k_size <= 1) @@ -211,7 +211,8 @@ void LKI::ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc) //read_text2array(filename, ConsNodes); gctl::_2d_vector table_data; - gctl::read_text2vector2d(filename, table_data, desc); + desc.file_name_ = filename; + gctl::read_text2vector2d(desc, table_data); if (table_data.size() <= 1) { @@ -230,19 +231,21 @@ void LKI::ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc) return; } -void LKI::WriteTargetNodes(std::string filename, const gctl::text_descriptor &desc) +void LKI::WriteTargetNodes(std::string filename, gctl::text_descriptor &desc) { - save_array2text(filename, TargNodes, desc); + desc.file_name_ = filename; + save_array2text(desc, TargNodes); return; } -void LKI::InitTargetNodes(std::string para) +void LKI::InitTargetNodes(std::string para, gctl::text_descriptor &desc) { // try to use the para as a file name if (access(para.c_str(), F_OK) != -1) { + desc.file_name_ = para; std::vector tmp_vec; - gctl::read_text2vector(para, tmp_vec); + gctl::read_text2vector(desc, tmp_vec); TargNodes.resize(tmp_vec.size()); for (int i = 0; i < tmp_vec.size(); ++i) diff --git a/nc2other/nc2other.cpp b/nc2other/nc2other.cpp index a5a8d8b..373e718 100644 --- a/nc2other/nc2other.cpp +++ b/nc2other/nc2other.cpp @@ -133,10 +133,13 @@ Please see instructions or contact the author for more information."); // 保存文本文件 if (type_str == "txt") { - if (del_str == ",") out_name += ".csv"; - else out_name += ".txt"; + gctl::text_descriptor desc; + desc.file_name_ = out_name; + desc.delimiter_ = del_str[0]; + desc.head_strs_ = head_info; + if (del_str == ",") desc.file_ext_ = ".csv"; - gctl::save_vector2d2text(out_name, out_data, del_str[0], '#', &head_info, gctl::ColMajor); + gctl::save_vector2d2text(desc, out_data, gctl::ColMajor); return 0; } diff --git a/slbsi/slbsi.h b/slbsi/slbsi.h index 217a050..3ef66c5 100644 --- a/slbsi/slbsi.h +++ b/slbsi/slbsi.h @@ -62,7 +62,7 @@ public: double epsilon); void ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc); void WriteTargetNodes(std::string filename, const gctl::text_descriptor &desc); - void InitTargetNodes(std::string para); + void InitTargetNodes(std::string para, gctl::text_descriptor &desc); void CalKernel(); void CalKernel(const data_point &tar_node); void UpdateTarVec(size_t idx, bool if_global = true); @@ -102,7 +102,7 @@ void LBSI::Routine(std::string in_name, std::string tar_name, } ReadConstrainNodes(in_name, desc); - InitTargetNodes(tar_name); + InitTargetNodes(tar_name, desc); unsigned int k_size = kernel_size; if (k_size <= 1) @@ -217,7 +217,8 @@ void LBSI::Routine(std::string in_name, std::string tar_name, void LBSI::ReadConstrainNodes(std::string filename, gctl::text_descriptor &desc) { gctl::_2d_vector table_data; - gctl::read_text2vector2d(filename, table_data, desc); + desc.file_name_ = filename; + gctl::read_text2vector2d(desc, table_data); if (table_data.size() <= 1) { @@ -286,13 +287,14 @@ void LBSI::WriteTargetNodes(std::string filename, const gctl::text_descriptor &d return; } -void LBSI::InitTargetNodes(std::string para) +void LBSI::InitTargetNodes(std::string para, gctl::text_descriptor &desc) { // try to use the para as a file name if (access(para.c_str(), F_OK) != -1) { std::vector tmp_vec; - read_text2vector(para, tmp_vec); + desc.file_name_ = para; + read_text2vector(desc, tmp_vec); TargNodes.resize(tmp_vec.size()); for (size_t i = 0; i < tmp_vec.size(); ++i) diff --git a/tetgm/tetgm.cpp b/tetgm/tetgm.cpp index c2a55ca..ce8a42b 100644 --- a/tetgm/tetgm.cpp +++ b/tetgm/tetgm.cpp @@ -217,7 +217,8 @@ int main(int argc, char *argv[]) try if (2 != sscanf(physic_para.c_str(),"%[^+]+d%d", physic_filename, &physic_col)) strcpy(physic_filename, physic_para.c_str()); - gctl::read_text2vector2d(physic_filename, txt_content, desc); + desc.file_name_ = physic_filename; + gctl::read_text2vector2d(desc, txt_content); if (txt_content.size() != tet_num) { diff --git a/xyz2nc/xyz2nc.cpp b/xyz2nc/xyz2nc.cpp index 48290b9..6991852 100644 --- a/xyz2nc/xyz2nc.cpp +++ b/xyz2nc/xyz2nc.cpp @@ -83,10 +83,22 @@ Please see instructions or contact the author for more information."); bool value_only = false; if (format_str != "NULL") value_only = true; + std::string file_ext; + size_t dpos = table_name.find_last_of('.'); + if (dpos != std::string::npos) + { + file_ext = table_name.substr(dpos); + table_name = table_name.substr(0, dpos); + } + else file_ext = ".txt"; + gctl::text_descriptor desc; + desc.file_name_ = table_name; + desc.file_ext_ = file_ext; if (head_str != "NULL") gctl::str2type(head_str, desc.head_num_); if (ant_str != "NULL") gctl::str2type(ant_str, desc.att_sym_); if (del_str != "NULL") gctl::str2type(del_str, desc.delimiter_); + if (grid_name == "NULL") grid_name = table_name; if (interval_str == "NULL" && size_str == "NULL") { @@ -134,7 +146,7 @@ Please see instructions or contact the author for more information."); } gctl::_2d_vector table_data; - gctl::read_text2vector2d(table_name, table_data, desc); + gctl::read_text2vector2d(desc, table_data); // check data for (int i = 0; i < table_data.size(); i++)