145 lines
5.5 KiB
C++
145 lines
5.5 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 "trackline.h"
|
|
|
|
int main(int argc, char *argv[]) try
|
|
{
|
|
const char* pro_name = "trackline";
|
|
const char* pro_info = "1.1 - Extract data along a line or at given locations \
|
|
from a group of 2-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.";
|
|
const char* in_str = "Input data table. a +d option could be attached to the \
|
|
filename to select data columns of the input data, the default is 0,1,2. \
|
|
Note that any line starts with '#' will be skipped.";
|
|
const char* out_str = "Output data table, every line contains a x-coordinate \
|
|
of a point on the line and 2-D coordinates of the point, and the point's value.";
|
|
const char* line_para_str = "Line parameters, you can either specify where the \
|
|
line starts and ends, plus interval of data points on the line.\
|
|
Or you can give point locations via a file, a +d option could be attached \
|
|
to the filename to select data columns of the input data,\
|
|
the default is 0,1. Note that any line starts with '#' will be skipped.";
|
|
const char* grid_para_str = "Griding parameters. the program will automatically \
|
|
using the mean area-size of input points to estimate a griding size \
|
|
if no -g option has been set.";
|
|
|
|
|
|
trackLine tl;
|
|
char infilename[1024] = "NULL";
|
|
char outfilename[1024] = "NULL";
|
|
char boxpara[1024] = "NULL";
|
|
char linepara[1024] = "NULL";
|
|
|
|
// option format
|
|
// char* info, char* format, bool manda
|
|
static struct gctl::option_info long_opts_help[] =
|
|
{
|
|
{in_str, "<input-file>[+d<x-col>,<y-col>,<z-col>]", true},
|
|
{out_str, "<output-file>", true},
|
|
{line_para_str, "<input-file>[+d<x-col>,<y-col>]|<p1-x>/<p1-y>/<p2-x>/<p2-y>/<spacing>", true},
|
|
{grid_para_str, "<grid-x>/<grid-y>", false},
|
|
{"Show help information.", 0, false},
|
|
{0, 0, 0}
|
|
};
|
|
|
|
static struct option long_opts[] =
|
|
{
|
|
{"input-file", required_argument, NULL, 'i'},
|
|
{"output-file", required_argument, NULL, 'o'},
|
|
{"line-parameter", required_argument, NULL, 'l'},
|
|
{"grid-parameter", required_argument, NULL, 'g'},
|
|
{"help", no_argument, NULL, 'h'},
|
|
{0, 0, 0, 0}
|
|
};
|
|
|
|
int curr;
|
|
while(1)
|
|
{
|
|
int optIndex = 0;
|
|
|
|
if (argc == 1){
|
|
gctl::display_logo(std::clog);
|
|
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, pro_info);
|
|
return 0;
|
|
}
|
|
|
|
curr = getopt_long(argc, argv, "hi:o:l:g:", long_opts, &optIndex);
|
|
|
|
if (curr == -1) break;
|
|
|
|
switch (curr)
|
|
{
|
|
case 'h': //显示帮助信息
|
|
gctl::display_logo(std::clog);
|
|
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, pro_info);
|
|
return 0;
|
|
case 'i':
|
|
sscanf(optarg,"%s",infilename);
|
|
break;
|
|
case 'o':
|
|
sscanf(optarg,"%s",outfilename);
|
|
break;
|
|
case 'l':
|
|
sscanf(optarg,"%s",linepara);
|
|
break;
|
|
case 'g':
|
|
sscanf(optarg,"%s",boxpara);
|
|
break;
|
|
case '?':
|
|
gctl::getopt_long_help(long_opts, long_opts_help, pro_name, " - Unknown options. Please see the help information below.");
|
|
break;
|
|
default:
|
|
abort();
|
|
}
|
|
}
|
|
|
|
// check for mandatory option(s)
|
|
if (!strcmp(infilename, "NULL") || !strcmp(outfilename, "NULL") || !strcmp(linepara, "NULL"))
|
|
{
|
|
GCTL_ShowWhatError("Missing arguments for mandatory option(s).", GCTL_ERROR_ERROR,
|
|
0, "See tips below. Or use -h option to see the full instruction.", 0);
|
|
if (!strcmp(infilename, "NULL"))
|
|
gctl::getopt_long_option_info('i', long_opts, long_opts_help);
|
|
if (!strcmp(outfilename, "NULL"))
|
|
gctl::getopt_long_option_info('o', long_opts, long_opts_help);
|
|
if (!strcmp(linepara, "NULL"))
|
|
gctl::getopt_long_option_info('l', long_opts, long_opts_help);
|
|
return 0;
|
|
}
|
|
|
|
if (tl.getInputNode(infilename)) return 0;
|
|
tl.initBox(boxpara);
|
|
if (tl.initLine(linepara)) return 0;
|
|
tl.interLine();
|
|
tl.outLine(outfilename);
|
|
return 0;
|
|
}
|
|
catch(std::exception &e)
|
|
{
|
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
} |