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

97 lines
4.8 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 "cutprofile.h"
int main(int argc, char** argv) try
{
gctl::flags_parser fp;
fp.set_proname("cutprofile");
fp.set_proinfo("v1.1 extract profile data from a group of 3-D data points. \
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-file", required_argument, NULL, "input data points, every line of the file contains a x-coordinate, a y-coordinate, a z-coordinate and a data value", "<filename>", true);
fp.add_opt('o', "out-file", required_argument, NULL, "output data points, every line contains a x-coordinate and a z-coordinate of the point on the line and 3-D coordinates of the point, and the point's value", "filename", true);
fp.add_opt('l', "line", required_argument, NULL, "line parameters, you need to specify where the profile starts and ends, plus interval of data points on the profile", "<p1-x>/<p1-y>/<p1-z>/<p2-x>/<p2-y>/<p2-z>/<x-spacing>/<z-spacing>", false);
fp.add_opt('s', "sphere", required_argument, NULL, "sphere parameters, cut data on a sphere", "<lonmin>/<lonmax>/<latmin>/<latmax>/<dlon>/<dlat>/<ele>", false);
fp.add_opt('g', "grid", required_argument, NULL, "griding parameters, the program will automaticly using the mean space of input points to estimate a griding size if no -b option has been setted. Note that if input points are under spherical coordinates the -b option is indispensable", "<grid-x>/<grid-y>/<grid-z>", false);
fp.add_opt('r', "refer-system", required_argument, NULL, "reference system for spherical points, the input poinits are considerated under Cartesian coordinates if no -r option is set", "<refrad>/<refRad>|EarthR|WGS84", false);
fp.add_opt('c', "column", required_argument, NULL, "set alternative columon orders of input data, the default 0,1,2,3 is corrsponding to x, y, z and val columons", "<col1>,<col2>,...", false);
fp.add_opt('h', "help", no_argument, NULL, "Show this info", 0, false);
fp.configure(argc, argv);
if (argc == 1 || fp.set_opt('h'))
{
fp.show_help_page();
return 0;
}
std::string infilename, outfilename, boxpara, linepara, spherepara, syspara, dataorder;
fp.get_argv({'i', 'o', 'l', 's', 'g', 'r', 'c'}, {&infilename, &outfilename, &linepara, &spherepara, &boxpara, &syspara, &dataorder});
// 查看是否通过强制参数检查
if (!fp.pass_mandatory()) return 0;
if (syspara == "NULL") syspara = "0/0";
if (dataorder == "NULL") dataorder = "0,1,2,3";
cutProfile cp;
if(cp.setorder(dataorder)) return 0;
if(cp.setref(syspara)) return 0;
if(cp.getInputNode(infilename)) return 0;
cp.initBox(boxpara);
if (linepara != "NULL")
{
if(cp.initVecProfile(linepara)) return 0;
}
else if (spherepara != "NULL")
{
if(cp.initSphProfile(spherepara)) return 0;
}
else
{
throw gctl::runtime_error("no profile tpye specified.");
}
cp.interProfile();
if (spherepara != "NULL")
{
cp.outProfile(outfilename, 2);
}
else if (linepara != "NULL" && syspara != "0/0")
{
cp.outProfile(outfilename, 1);
}
else cp.outProfile(outfilename, 0);
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}