gctl_toolkits/lki/lki.cpp
2024-09-10 20:25:18 +08:00

96 lines
5.3 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 "lki.h"
int main(int argc, char *argv[]) try
{
gctl::flags_parser fp;
fp.set_proname("lki");
fp.set_proinfo("Limited memory Kriging Interpolation of 2D arbitrary located data. \
This program is a toolkit of the GCTL package. The GCTL comes with ABSOLUTE NO WARRANTY. \
Please see instructions or contact the author for more information.");
fp.add_opt('i', "in-table", required_argument, NULL, "Input table name of the constraint locations and data.", "<file-name>", true);
fp.add_opt('t', "target-table", required_argument, NULL, "Input table name of the target locations or parameters of output grid locations.", "<file-name>|<xmin>/<dx>/<xmax>/<ymin>/<dx>/<ymax>", true);
fp.add_opt('o', "out-table", required_argument, NULL, "Output table name of the interpolated data.", "<file-name>", true);
fp.add_opt('k', "kernel-size", required_argument, NULL, "Kernel size for solving the linear system of the Variogram functions (default is 200).", "<size>", false);
fp.add_opt('e', "epsilon", required_argument, NULL, "Threshold for solving the linear system of the Variogram functions (default is 1e-10).", "<value>", false);
fp.add_opt('b', "box-dimension", required_argument, NULL, "2D boxes' dimensions used for pre-processing the constraint data (default is 10).", "<size>", false);
fp.add_opt('v', "variogram", required_argument, NULL, "Variogram function used for interpolation. Available functions are spherical (default), gaussian, \
wave, rational, circular and linear.", "<function>", false);
fp.add_opt('p', "parameter", required_argument, NULL, "Parameters of the variogram function. The default values are 0.1, 10 and 100, respectively.", "<nugget>/<sill>/<range>", false);
fp.add_opt('c', "column", required_argument, NULL, "Column index of x, y and data. The defaults are 0,1,2", "<col-x>,<col-y>,<col-data>", false);
fp.add_opt('h', "head-record", required_argument, NULL, "Input file has [0] Header record(s).", "<size>", false);
fp.add_opt('a', "annotate", required_argument, NULL, "The starting symbol of an annotate line.", "<sym>", false);
fp.add_opt('d', "delimeter", required_argument, NULL, "Delimeter between different columns.", "<sym>", false);
fp.configure(argc, argv);
if (argc == 1)
{
fp.show_help_page();
return 0;
}
std::string in_name, out_name, tar_name, kernel_str, eps_str, box_str, variogram_str, para_str, col_str, head_str, ant_str, del_str;
fp.get_argv({'i', 't', 'o', 'k', 'e', 'b', 'v', 'p', 'c'},
{&in_name, &tar_name, &out_name, &kernel_str, &eps_str, &box_str, &variogram_str, &para_str, &col_str, &head_str, &ant_str, &del_str});
// 查看是否通过强制参数检查
if (!fp.pass_mandatory()) return 0;
int kernel_size, box_size;
double epsilon;
std::string variogram_type, variogram_para;
if (kernel_str == "NULL") kernel_size = 200;
else gctl::str2type(kernel_str, kernel_size);
if (eps_str == "NULL") epsilon = 1e-10;
else gctl::str2type(eps_str, epsilon);
if (box_str == "NULL") box_size = 10;
else gctl::str2type(box_str, box_size);
if (variogram_str == "NULL") variogram_type = "spherical";
else variogram_type = variogram_str;
if (para_str == "NULL") variogram_para = "0.1/10/100";
else variogram_para = para_str;
if (col_str == "NULL") col_str = "0,1,2";
gctl::text_descriptor desc;
if (head_str != "NULL") gctl::str2type(head_str, desc.head_num_);
if (ant_str != "NULL") gctl::str2type(ant_str, desc.att_sym_);
if (del_str != "NULL") gctl::str2type(del_str, desc.delimiter_);
LKI ki;
ki.Routine(in_name, tar_name, out_name, col_str, desc, kernel_size, box_size, epsilon, variogram_type, variogram_para);
return 0;
}
catch (std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}