gctl/example/text_io_ex.cpp

100 lines
3.5 KiB
C++
Raw Normal View History

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 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
{
2025-01-01 17:14:19 +08:00
/*
2024-12-15 21:14:12 +08:00
dsv_io tc;
2024-12-13 11:02:59 +08:00
tc.set_delimeter('|');
2024-12-15 21:14:12 +08:00
tc.load_text("tmp/world_data", ".txt", BothHead);
2024-12-31 09:29:54 +08:00
tc.info(BothHead);
2024-12-13 10:11:47 +08:00
2024-12-15 21:14:12 +08:00
//_1s_vector name = tc.get_row_names();
//display_vector(name);
2024-12-31 09:29:54 +08:00
//_1s_array name;
//tc.get_column("Name_s", name);
//name.show(std::cout, '|');
2024-12-15 21:14:12 +08:00
2024-12-31 09:29:54 +08:00
//tc.get_row("AUS", name);
//name.show(std::cout, ',');
2024-12-13 11:02:59 +08:00
2024-12-16 09:31:46 +08:00
tc.save_csv("out");
2025-01-01 17:14:19 +08:00
*/
2024-12-15 21:14:12 +08:00
geodsv_io tc;
tc.load_text("tmp/topo", ".txt", ColumnHead);
2025-01-01 22:43:59 +08:00
tc.set_column_names({"x (m)", "y (m)", "elev (m)"});
2025-01-02 12:58:13 +08:00
tc.set_column_type(Float, "x (m)");
tc.set_column_type(Float, "y (m)");
2025-01-02 09:40:27 +08:00
tc.set_column_type(Float, "elev (m)");
2024-09-10 15:45:07 +08:00
2024-12-15 11:22:25 +08:00
array<point3dc> topo;
2025-01-01 17:14:19 +08:00
tc.get_column_point3dc(topo, 1, 2, 3);
2024-09-10 15:45:07 +08:00
2024-12-15 11:22:25 +08:00
std::clog << std::setprecision(11) << topo.front().z << "\n";
std::clog << topo.back().x << "," << topo.back().y << "," << topo.back().z << "\n";
2024-12-13 10:11:47 +08:00
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');
2025-01-01 17:14:19 +08:00
//tc.column_output("C3", Disable);
array<double> elev;
2025-01-01 22:43:59 +08:00
tc.get_column(elev, "elev (m)");
2025-01-01 17:14:19 +08:00
elev.for_each([](double &d, size_t i){d += 100.0;});
2025-01-01 22:43:59 +08:00
tc.add_column(2, "elev_plus");
2025-01-01 17:14:19 +08:00
tc.fill_column(elev, "elev_plus");
2024-12-28 09:42:02 +08:00
2025-01-02 12:58:13 +08:00
tc.add_column(-1, "dist");
tc.cal_column("dist := sqrt(C1*C1 + C3*C3)", {"dist", "C1", "C3"});
2025-01-01 22:43:59 +08:00
tc.add_row(3);
2025-01-02 12:58:13 +08:00
tc.fill_row(array<double>{5.5, 4.4, 3.3, 2.2, 1.1}, 3);
2025-01-01 22:43:59 +08:00
2024-12-13 10:11:47 +08:00
_1s_vector s = tc.get_tags();
s.push_back("Elev = 1000");
tc.set_tags(s);
tc.save_csv("out");
double c = 4.25242153654;
2025-01-01 17:14:19 +08:00
tc.cell(c, 2, 1, 12);
2024-12-30 22:09:39 +08:00
std::clog << std::setprecision(12) << tc.cell<double>(2, 1) << "\n";
2024-12-12 23:23:55 +08:00
2024-12-13 10:11:47 +08:00
tc.info();
2024-09-10 15:45:07 +08:00
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}