2024-09-10 15:45:07 +08:00
|
|
|
/********************************************************
|
|
|
|
* ██████╗ ██████╗████████╗██╗
|
|
|
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
|
|
|
* ██║ ███╗██║ ██║ ██║
|
|
|
|
* ██║ ██║██║ ██║ ██║
|
|
|
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
|
|
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
|
|
|
* Geophysical Computational Tools & Library (GCTL)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
|
|
|
*
|
|
|
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
|
|
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, either version 2
|
|
|
|
* of the License, or (at your option) any later version. You should have
|
|
|
|
* received a copy of the GNU Lesser General Public License along with this
|
|
|
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
|
|
|
* the GCTL, please consider the option to obtain a commercial license for a
|
|
|
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
|
|
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
|
|
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
|
|
|
* to include some tcription of your company and the realm of its activities.
|
|
|
|
* Also add information on how to contact you by electronic and paper mail.
|
|
|
|
******************************************************/
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
#include "dsv_io.h"
|
2024-09-10 15:45:07 +08:00
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
gctl::dsv_io::dsv_io()
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
2024-12-15 21:14:12 +08:00
|
|
|
file_ = "";
|
2024-09-10 15:45:07 +08:00
|
|
|
att_sym_ = '#';
|
2024-11-21 12:43:10 +08:00
|
|
|
tag_sym_ = '!';
|
2024-09-10 15:45:07 +08:00
|
|
|
deli_sym_ = ' ';
|
|
|
|
head_num_ = 0;
|
2024-12-12 16:55:06 +08:00
|
|
|
row_num_ = 0;
|
|
|
|
col_num_ = 0;
|
2024-12-16 09:31:46 +08:00
|
|
|
thead_ = ColumnHead;
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
gctl::dsv_io::~dsv_io()
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
gctl::dsv_io::dsv_io(std::string filename, std::string file_exten, table_headtype_e t)
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
2024-12-15 21:14:12 +08:00
|
|
|
file_ = "";
|
2024-09-10 15:45:07 +08:00
|
|
|
att_sym_ = '#';
|
2024-11-21 12:43:10 +08:00
|
|
|
tag_sym_ = '!';
|
2024-09-10 15:45:07 +08:00
|
|
|
deli_sym_ = ' ';
|
|
|
|
head_num_ = 0;
|
2024-12-12 16:55:06 +08:00
|
|
|
row_num_ = 0;
|
|
|
|
col_num_ = 0;
|
2024-12-16 09:31:46 +08:00
|
|
|
thead_ = ColumnHead;
|
|
|
|
|
|
|
|
if (file_exten == ".csv") load_csv(filename, t);
|
|
|
|
else load_text(filename, file_exten, t);
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::clear()
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
2024-12-15 21:14:12 +08:00
|
|
|
file_ = "";
|
|
|
|
att_sym_ = '#';
|
|
|
|
tag_sym_ = '!';
|
|
|
|
deli_sym_ = ' ';
|
|
|
|
head_num_ = 0;
|
|
|
|
row_num_ = 0;
|
|
|
|
col_num_ = 0;
|
2024-12-16 09:31:46 +08:00
|
|
|
thead_ = ColumnHead;
|
|
|
|
|
2024-11-04 16:03:39 +08:00
|
|
|
destroy_vector(heads_);
|
|
|
|
destroy_vector(annotates_);
|
|
|
|
destroy_vector(tags_);
|
|
|
|
destroy_vector(table_);
|
2024-12-28 09:42:02 +08:00
|
|
|
destroy_vector(bool_table_);
|
2024-09-10 15:45:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table_headtype_e t)
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
|
|
|
std::ifstream infile;
|
|
|
|
open_infile(infile, filename, file_exten);
|
|
|
|
|
2024-12-25 19:06:27 +08:00
|
|
|
int h = 0;
|
2024-09-10 15:45:07 +08:00
|
|
|
std::string tmp_line;
|
2024-12-16 09:31:46 +08:00
|
|
|
std::vector<std::string> lines;
|
2024-09-10 15:45:07 +08:00
|
|
|
while (std::getline(infile, tmp_line))
|
|
|
|
{
|
2024-12-25 19:06:27 +08:00
|
|
|
if (tmp_line.empty()) continue; // 跳过空行 空行不会并记入头信息计数中
|
2024-11-21 12:43:10 +08:00
|
|
|
else if (tmp_line[0] == att_sym_) // 注释行或者标记行 # #!
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
2024-11-21 12:43:10 +08:00
|
|
|
if (tmp_line[1] == tag_sym_) // #!
|
|
|
|
{
|
|
|
|
tmp_line = tmp_line.substr(2); // 去掉前两个字符
|
|
|
|
tmp_line.erase(0, tmp_line.find_first_not_of(" \t"));
|
|
|
|
tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1);
|
|
|
|
tags_.push_back(tmp_line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// #
|
|
|
|
tmp_line = tmp_line.substr(1); // 去掉第一个字符
|
2024-09-10 15:45:07 +08:00
|
|
|
tmp_line.erase(0, tmp_line.find_first_not_of(" \t"));
|
|
|
|
tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1);
|
|
|
|
annotates_.push_back(tmp_line);
|
|
|
|
}
|
2024-12-25 19:06:27 +08:00
|
|
|
else if (h < head_num_) //读入到头信息中
|
|
|
|
{
|
|
|
|
heads_.push_back(tmp_line);
|
|
|
|
h++;
|
|
|
|
}
|
2024-12-16 09:31:46 +08:00
|
|
|
else lines.push_back(tmp_line);
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
|
|
|
infile.close();
|
2024-12-12 23:23:55 +08:00
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
// 首先初始化行数
|
|
|
|
row_num_ = lines.size();
|
2024-12-12 16:55:06 +08:00
|
|
|
table_.resize(row_num_);
|
2024-11-04 16:03:39 +08:00
|
|
|
|
2024-12-12 16:55:06 +08:00
|
|
|
int cn;
|
|
|
|
std::vector<std::string> tmp_cols;
|
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
|
|
|
{
|
|
|
|
tmp_cols.clear();
|
2024-12-16 09:31:46 +08:00
|
|
|
parse_string_to_vector(lines[i], deli_sym_, tmp_cols);
|
2024-12-12 16:55:06 +08:00
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
// 动态调整列数
|
2024-12-12 16:55:06 +08:00
|
|
|
cn = tmp_cols.size();
|
|
|
|
col_num_ = std::max(cn, col_num_);
|
|
|
|
|
|
|
|
table_[i].resize(tmp_cols.size());
|
|
|
|
for (size_t j = 0; j < tmp_cols.size(); j++)
|
2024-11-04 16:03:39 +08:00
|
|
|
{
|
2024-12-12 16:55:06 +08:00
|
|
|
table_[i][j].str_ = tmp_cols[j];
|
|
|
|
}
|
|
|
|
}
|
2024-11-04 16:03:39 +08:00
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
// 补齐可能的空格
|
2024-12-17 09:59:06 +08:00
|
|
|
table_cell empty_cell;
|
2024-12-12 16:55:06 +08:00
|
|
|
empty_cell.str_ = "";
|
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
|
|
|
{
|
|
|
|
cn = table_[i].size();
|
|
|
|
for (size_t j = cn; j < col_num_; j++)
|
|
|
|
{
|
|
|
|
table_[i].push_back(empty_cell);
|
2024-11-04 16:03:39 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-13 10:11:47 +08:00
|
|
|
|
2024-12-28 09:42:02 +08:00
|
|
|
bool_table_.resize(row_num_);
|
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
|
|
|
{
|
|
|
|
bool_table_[i].resize(col_num_);
|
|
|
|
for (size_t j = 0; j < col_num_; j++)
|
|
|
|
{
|
|
|
|
bool_table_[i][j] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
thead_ = t;
|
2024-12-13 10:11:47 +08:00
|
|
|
file_ = filename + file_exten;
|
2024-12-16 09:31:46 +08:00
|
|
|
destroy_vector(lines);
|
2024-12-13 10:11:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::load_csv(std::string filename, table_headtype_e t)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
|
|
|
set_delimeter(',');
|
|
|
|
load_text(filename, ".csv", t);
|
2024-09-10 15:45:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
void gctl::dsv_io::save_text(std::string filename, std::string file_exten)
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
|
|
|
std::ofstream outfile;
|
|
|
|
open_outfile(outfile, filename, file_exten);
|
|
|
|
|
|
|
|
for (int i = 0; i < heads_.size(); i++)
|
|
|
|
{
|
|
|
|
outfile << heads_[i] << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < tags_.size(); i++)
|
|
|
|
{
|
2024-11-21 12:43:10 +08:00
|
|
|
outfile << "#! " << tags_[i] << std::endl;
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < annotates_.size(); i++)
|
|
|
|
{
|
|
|
|
outfile << "# " << annotates_[i] << std::endl;
|
|
|
|
}
|
|
|
|
|
2024-12-28 09:42:02 +08:00
|
|
|
bool line_st;
|
2024-12-12 16:55:06 +08:00
|
|
|
for (int i = 0; i < row_num_; i++)
|
2024-09-10 15:45:07 +08:00
|
|
|
{
|
2024-12-28 09:42:02 +08:00
|
|
|
line_st = false;
|
|
|
|
|
|
|
|
if (bool_table_[i][0])
|
|
|
|
{
|
|
|
|
outfile << table_[i][0].str_;
|
|
|
|
line_st = true;
|
|
|
|
}
|
|
|
|
|
2024-12-12 16:55:06 +08:00
|
|
|
for (size_t j = 1; j < col_num_; j++)
|
2024-11-04 16:03:39 +08:00
|
|
|
{
|
2024-12-28 09:42:02 +08:00
|
|
|
if (line_st && bool_table_[i][j]) outfile << deli_sym_ << table_[i][j].str_; // line started
|
|
|
|
else if (bool_table_[i][j]) // line not started
|
|
|
|
{
|
|
|
|
outfile << table_[i][j].str_;
|
|
|
|
line_st = true; // start line
|
|
|
|
}
|
2024-11-04 16:03:39 +08:00
|
|
|
}
|
2024-12-12 16:55:06 +08:00
|
|
|
outfile << std::endl;
|
2024-11-04 16:03:39 +08:00
|
|
|
}
|
2024-12-12 16:55:06 +08:00
|
|
|
outfile.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
void gctl::dsv_io::save_csv(std::string filename)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
|
|
|
set_delimeter(',');
|
2024-12-16 09:31:46 +08:00
|
|
|
save_text(filename, ".csv");
|
2024-12-13 10:11:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::init_table(int row, int col, table_headtype_e t)
|
2024-12-12 16:55:06 +08:00
|
|
|
{
|
|
|
|
row_num_ = row;
|
|
|
|
col_num_ = col;
|
2024-12-16 09:31:46 +08:00
|
|
|
thead_ = t;
|
2024-12-12 16:55:06 +08:00
|
|
|
|
|
|
|
table_.resize(row_num_);
|
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
2024-11-04 16:03:39 +08:00
|
|
|
{
|
2024-12-12 16:55:06 +08:00
|
|
|
table_[i].resize(col_num_);
|
|
|
|
for (size_t j = 0; j < col_num_; j++)
|
2024-11-04 16:03:39 +08:00
|
|
|
{
|
2024-12-12 16:55:06 +08:00
|
|
|
table_[i][j].str_ = "";
|
2024-11-04 16:03:39 +08:00
|
|
|
}
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
2024-12-13 10:11:47 +08:00
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
if (t == RowHead || t == BothHead)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
2024-12-15 21:14:12 +08:00
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
|
|
|
{
|
2024-12-16 09:31:46 +08:00
|
|
|
table_[i][0].str_ = "row-" + std::to_string(i);
|
2024-12-15 21:14:12 +08:00
|
|
|
}
|
2024-12-13 10:11:47 +08:00
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
if (t == ColumnHead || t == BothHead)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < col_num_; i++)
|
|
|
|
{
|
2024-12-16 09:31:46 +08:00
|
|
|
table_[0][i].str_ = "col-" + std::to_string(i);
|
2024-12-15 21:14:12 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-16 09:31:46 +08:00
|
|
|
|
|
|
|
if (t == BothHead)
|
|
|
|
{
|
|
|
|
table_[0][0].str_ = "row-idx";
|
|
|
|
}
|
2024-12-13 10:11:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::set_head_records(const std::vector<std::string> &heads)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
|
|
|
heads_ = heads;
|
|
|
|
head_num_ = heads_.size();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::set_annotoations(const std::vector<std::string> &att)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
|
|
|
annotates_ = att;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::set_tags(const std::vector<std::string> &tags)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
|
|
|
tags_ = tags;
|
2024-09-10 15:45:07 +08:00
|
|
|
return;
|
2024-12-12 23:23:55 +08:00
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::dsv_io::info()
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
|
|
|
std::clog << "File: " << file_ << "\n------------\n";
|
|
|
|
std::clog << "Head(s): " << head_num_ << "\n";
|
|
|
|
std::clog << "Annotation(s): " << annotates_.size() << "\n";
|
|
|
|
std::clog << "Tag(s): " << tags_.size() << "\n";
|
2024-12-27 12:28:17 +08:00
|
|
|
std::clog << "------------\nColumns:\n";
|
2024-12-13 10:11:47 +08:00
|
|
|
|
2024-12-27 12:28:17 +08:00
|
|
|
for (size_t i = 0; i < col_num_; i++)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
2024-12-27 12:28:17 +08:00
|
|
|
if (thead_ == ColumnHead || thead_ == BothHead)
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
2024-12-28 13:47:25 +08:00
|
|
|
std::clog << table_[0][i].str_ << ": " << table_[1][i].str_ << " -> " << table_[row_num_ - 1][i].str_;
|
2024-12-13 10:11:47 +08:00
|
|
|
}
|
2024-12-27 12:28:17 +08:00
|
|
|
else
|
2024-12-13 10:11:47 +08:00
|
|
|
{
|
2024-12-28 21:02:10 +08:00
|
|
|
std::clog << table_[0][i].str_ << " -> " << table_[row_num_ - 1][i].str_;
|
2024-12-13 10:11:47 +08:00
|
|
|
}
|
2024-12-28 13:47:25 +08:00
|
|
|
|
|
|
|
if (!bool_table_[0][i]) std::clog << " (No output)";
|
|
|
|
std::clog << std::endl;
|
2024-12-13 10:11:47 +08:00
|
|
|
}
|
2024-12-27 12:28:17 +08:00
|
|
|
std::clog << "============\n";
|
2024-12-13 10:11:47 +08:00
|
|
|
return;
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
int gctl::dsv_io::name_index(std::string name, bool iter_row)
|
2024-12-16 09:31:46 +08:00
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
if (iter_row)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
|
|
|
{
|
|
|
|
if (table_[i][0].str_ == name) return i;
|
|
|
|
}
|
|
|
|
|
2024-12-28 13:47:25 +08:00
|
|
|
return -1;
|
2024-12-17 09:59:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < col_num_; i++)
|
|
|
|
{
|
|
|
|
if (table_[0][i].str_ == name) return i;
|
|
|
|
}
|
|
|
|
|
2024-12-28 13:47:25 +08:00
|
|
|
return -1;
|
2024-12-17 09:59:06 +08:00
|
|
|
}
|
2024-12-16 09:31:46 +08:00
|
|
|
}
|
|
|
|
|
2024-12-28 13:47:25 +08:00
|
|
|
void gctl::dsv_io::column_output(int idx, switch_type_e s)
|
2024-12-28 09:42:02 +08:00
|
|
|
{
|
|
|
|
if (idx >= col_num_)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < row_num_; i++)
|
|
|
|
{
|
2024-12-28 13:47:25 +08:00
|
|
|
if (s == Enable) bool_table_[i][idx] = true;
|
|
|
|
else bool_table_[i][idx] = false;
|
2024-12-28 09:42:02 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-28 13:47:25 +08:00
|
|
|
void gctl::dsv_io::column_output(std::string name, switch_type_e s)
|
2024-12-28 09:42:02 +08:00
|
|
|
{
|
2024-12-28 13:47:25 +08:00
|
|
|
column_output(name_index(name), s);
|
2024-12-28 09:42:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-28 13:47:25 +08:00
|
|
|
void gctl::dsv_io::row_output(int idx, switch_type_e s)
|
2024-12-28 09:42:02 +08:00
|
|
|
{
|
|
|
|
if (idx >= row_num_)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < col_num_; i++)
|
|
|
|
{
|
2024-12-28 13:47:25 +08:00
|
|
|
if (s == Enable) bool_table_[idx][i] = true;
|
|
|
|
else bool_table_[idx][i] = false;
|
2024-12-28 09:42:02 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-28 13:47:25 +08:00
|
|
|
void gctl::dsv_io::row_output(std::string name, switch_type_e s)
|
2024-12-28 09:42:02 +08:00
|
|
|
{
|
2024-12-28 13:47:25 +08:00
|
|
|
row_output(name_index(name), s);
|
2024-12-28 09:42:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
gctl::geodsv_io::geodsv_io(){}
|
|
|
|
|
|
|
|
gctl::geodsv_io::~geodsv_io(){}
|
|
|
|
|
2024-12-16 09:31:46 +08:00
|
|
|
gctl::geodsv_io::geodsv_io(std::string filename, std::string file_exten, table_headtype_e t)
|
|
|
|
{
|
|
|
|
file_ = "";
|
|
|
|
att_sym_ = '#';
|
|
|
|
tag_sym_ = '!';
|
|
|
|
deli_sym_ = ' ';
|
|
|
|
head_num_ = 0;
|
|
|
|
row_num_ = 0;
|
|
|
|
col_num_ = 0;
|
|
|
|
thead_ = ColumnHead;
|
|
|
|
|
|
|
|
if (file_exten == ".csv") load_csv(filename, t);
|
|
|
|
else load_text(filename, file_exten, t);
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::geodsv_io::fill_column_point2dc(int xid, int yid, const array<point2dc> &data, int p)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
|
|
|
if (xid >= col_num_ || yid >= col_num_ || xid == yid)
|
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
|
2024-12-19 09:45:55 +08:00
|
|
|
int st = 0;
|
|
|
|
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
|
|
|
|
2024-12-15 11:22:25 +08:00
|
|
|
std::stringstream ss;
|
|
|
|
std::string s;
|
2024-12-19 09:45:55 +08:00
|
|
|
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
|
|
|
ss.clear();
|
|
|
|
ss << data[i].x;
|
|
|
|
ss >> s;
|
2024-12-19 09:45:55 +08:00
|
|
|
table_[i + st][xid].str_ = s;
|
2024-12-15 11:22:25 +08:00
|
|
|
|
|
|
|
ss.clear();
|
|
|
|
ss << data[i].y;
|
|
|
|
ss >> s;
|
2024-12-19 09:45:55 +08:00
|
|
|
table_[i + st][yid].str_ = s;
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
void gctl::geodsv_io::fill_column_point2dc(std::string xname, std::string yname, const array<point2dc> &data, int p)
|
|
|
|
{
|
|
|
|
fill_column_point2dc(name_index(xname, false), name_index(yname, false), data, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::geodsv_io::fill_column_point3dc(int xid, int yid, int zid, const array<point3dc> &data, int p)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
|
|
|
if (xid >= col_num_ || yid >= col_num_ || zid >= col_num_ || xid == yid || yid == zid || xid == zid)
|
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
int st = 0;
|
|
|
|
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
|
|
|
|
2024-12-15 11:22:25 +08:00
|
|
|
std::stringstream ss;
|
|
|
|
std::string s;
|
2024-12-19 09:45:55 +08:00
|
|
|
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
|
|
|
ss.clear();
|
2024-12-19 09:45:55 +08:00
|
|
|
ss << data[i].x;
|
2024-12-15 11:22:25 +08:00
|
|
|
ss >> s;
|
2024-12-19 09:45:55 +08:00
|
|
|
table_[i + st][xid].str_ = s;
|
2024-12-15 11:22:25 +08:00
|
|
|
|
|
|
|
ss.clear();
|
2024-12-19 09:45:55 +08:00
|
|
|
ss << data[i].y;
|
2024-12-15 11:22:25 +08:00
|
|
|
ss >> s;
|
2024-12-19 09:45:55 +08:00
|
|
|
table_[i + st][yid].str_ = s;
|
2024-12-15 11:22:25 +08:00
|
|
|
|
|
|
|
ss.clear();
|
2024-12-19 09:45:55 +08:00
|
|
|
ss << data[i].z;
|
2024-12-15 11:22:25 +08:00
|
|
|
ss >> s;
|
2024-12-19 09:45:55 +08:00
|
|
|
table_[i + st][zid].str_ = s;
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
void gctl::geodsv_io::fill_column_point3dc(std::string xname, std::string yname, std::string zname, const array<point3dc> &data, int p)
|
|
|
|
{
|
|
|
|
fill_column_point3dc(name_index(xname, false), name_index(yname, false), name_index(zname, false), data, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::geodsv_io::get_column_point2dc(int xid, int yid, array<point2dc> &data)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
|
|
|
if (xid >= col_num_ || yid >= col_num_ || xid == yid)
|
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
int st = 0;
|
|
|
|
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
|
|
|
|
|
|
|
data.resize(row_num_ - st);
|
|
|
|
for (size_t i = st; i < row_num_; i++)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
data[i - st].x = table_[i][xid].value<double>();
|
|
|
|
data[i - st].y = table_[i][yid].value<double>();
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
void gctl::geodsv_io::get_column_point2dc(std::string xname, std::string yname, array<point2dc> &data)
|
|
|
|
{
|
|
|
|
get_column_point2dc(name_index(xname, false), name_index(yname, false), data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 21:14:12 +08:00
|
|
|
void gctl::geodsv_io::get_column_point3dc(int xid, int yid, int zid, array<point3dc> &data)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
|
|
|
if (xid >= col_num_ || yid >= col_num_ || zid >= col_num_ || xid == yid || yid == zid || xid == zid)
|
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
|
2024-12-17 09:59:06 +08:00
|
|
|
int st = 0;
|
|
|
|
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
|
|
|
|
|
|
|
|
data.resize(row_num_ - st);
|
|
|
|
for (size_t i = st; i < row_num_; i++)
|
2024-12-15 11:22:25 +08:00
|
|
|
{
|
2024-12-17 09:59:06 +08:00
|
|
|
data[i - st].x = table_[i][xid].value<double>();
|
|
|
|
data[i - st].y = table_[i][yid].value<double>();
|
|
|
|
data[i - st].z = table_[i][zid].value<double>();
|
2024-12-15 11:22:25 +08:00
|
|
|
}
|
|
|
|
return;
|
2024-12-17 09:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void gctl::geodsv_io::get_column_point3dc(std::string xname, std::string yname, std::string zname, array<point3dc> &data)
|
|
|
|
{
|
|
|
|
get_column_point3dc(name_index(xname, false), name_index(yname, false), name_index(zname, false), data);
|
|
|
|
return;
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|