gctl/example/text_io_ex.cpp
2024-12-30 22:09:39 +08:00

87 lines
3.1 KiB
C++

/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* 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 description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/core.h"
#include "../lib/io.h"
using namespace gctl;
int main(int argc, char const *argv[]) try
{
/*
dsv_io tc;
tc.set_delimeter('|');
tc.load_text("tmp/world_data", ".txt", BothHead);
tc.info();
//_1s_vector name = tc.get_row_names();
//display_vector(name);
_1s_array name;
tc.get_column("Name_s", name);
name.show(std::cout, '|');
tc.get_row("AUS", name);
name.show(std::cout, ',');
tc.save_csv("out");
*/
geodsv_io tc;
tc.load_text("tmp/topo", ".txt", ColumnHead);
tc.cell(0, 1, std::string("x (m)"));
tc.cell(0, 2, std::string("y (m)"));
tc.cell(0, 3, std::string("elevation (m)"));
array<point3dc> topo;
tc.get_column_point3dc(1, 2, 3, topo);
std::clog << std::setprecision(11) << topo.front().z << "\n";
std::clog << topo.back().x << "," << topo.back().y << "," << topo.back().z << "\n";
display_vector(tc.get_tags(), std::clog, '\n');
display_vector(tc.get_annotoations(), std::clog, '\n');
display_vector(tc.get_head_records(), std::clog, '\n');
tc.column_output("C3", Disable);
_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(2, 1, c, 12);
std::clog << std::setprecision(12) << tc.cell<double>(2, 1) << "\n";
tc.info();
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}