gctl_examples/examples/xyz_io_ex.cpp
2024-09-10 20:19:20 +08:00

64 lines
2.7 KiB
C++

/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 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 "gctl/core.h"
#include "gctl/io.h"
int main(int argc, char *argv[])
{
gctl::array<gctl::point3dc> in_point;
gctl::text_descriptor desc;
gctl::get_xyz_points("data/obs_topo", in_point, desc, ".xyz");
gctl::array<double> A, B, C;
A.resize(in_point.size() - 100, 1.0);
B.resize(in_point.size() - 200, -10.0);
C.resize(in_point.size() - 500, 2.0);
std::vector<std::string> head_info(2);
head_info[0] = "This is just an example output.";
head_info[1] = "data1(mGal) data2(m) data3(nT)";
gctl::save_arrays2text("data/obs_topo_out.csv", ',', '#', &head_info, nullptr, A, B, C);
gctl::_2d_vector in_table;
gctl::array<gctl::point3dc> in_point2;
gctl::array<double> D, E;
desc.delimiter_ = ',';
gctl::read_text2vector2d("data/obs_topo_out.csv", in_table, desc);
gctl::get_xyz_points(in_table, in_point2, "0,1,2");
gctl::get_data_column(in_table, {&D, &E}, {4, 5});
gctl::destroy_vector(in_table);
for (int i = 0; i < 10; i++)
{
std::cout << in_point2[i].x << " " << in_point2[i].y << " "
<< in_point2[i].z << " " << D[i] << " " << E[i] << std::endl;
}
return 0;
}