/********************************************************
 *  ██████╗  ██████╗████████╗██╗
 * ██╔════╝ ██╔════╝╚══██╔══╝██║
 * ██║  ███╗██║        ██║   ██║
 * ██║   ██║██║        ██║   ██║
 * ╚██████╔╝╚██████╗   ██║   ███████╗
 *  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
 * 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/io.h"

using namespace gctl;

int main(int argc, char const *argv[]) try
{

    dsv_io tc;
    tc.delimeter('|');
    tc.head_number(1);
    tc.load_text("tmp/world_data", ".txt", ColHead|RowHead);
    tc.info(AttInfo|HeadInfo|TagInfo);

    tc.filter("America", "Continent_s", ColHead);
    //tc.filter("America", "BLZ", RowHead);
    //tc.save_text("out");

    if (tc.has_column("Continent_s")) std::cout << "Find Column\n";

    dsv_io tc2 = tc.export_table();
    //tc2.head_records(tc.head_records());
    tc2.delimeter('|');
    tc2.save_text("out");

/*
    geodsv_io tc;
    tc.load_text("tmp/topo", ".txt", ColumnHead);
    tc.set_column_names({"x (m)", "y (m)", "elev (m)"});
    tc.set_column_type(Float, "x (m)");
    tc.set_column_type(Float, "y (m)");
    tc.set_column_type(Float, "elev (m)");

    array<point3dc> topo;
    tc.get_column_point3dc(topo, 1, 2, 3);

    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);
    
    array<double> elev;
    tc.get_column(elev, "elev (m)");
    elev.for_each([](double &d, size_t i){d += 100.0;});

    tc.add_column(2, "elev_plus");
    tc.fill_column(elev, "elev_plus");

    tc.add_column(-1, "dist");
    tc.cal_column("dist := sqrt(C1*C1 + C3*C3)", {"dist", "C1", "C3"});

    tc.add_row(3);
    tc.fill_row(array<double>{5.5, 4.4, 3.3, 2.2, 1.1}, 3);

    geodsv_io out_table;
    tc.filt_column("dist > 1000", {"dist"}, {"x (m)", "y (m)", "elev (m)"}, out_table);
    out_table.save_text("out2");

    _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(c, 2, 1, 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);
}