* /trunk/src/gpstools/doc/gnuplot.txt
[gpstools.git] / addpoints
blob9d770eafbfd028d3b3500f25105806970b20b785
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # File ID: d9355770-f923-11dd-b366-0001805bf4b1
6 # Add new waypoints or trackpoints to the database.
8 # Character set: UTF-8
9 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 BEGIN {
15 our @version_array;
18 use strict;
19 use Getopt::Long;
21 $| = 1;
23 our $Debug = 0;
25 our %Std = (
27 'database' => "gps",
28 'timezone' => "",
29 'type' => "track",
33 our %Opt = (
35 'database' => $Std{'database'},
36 'debug' => 0,
37 'help' => 0,
38 'timezone' => $Std{'timezone'},
39 'type' => $Std{'type'},
40 'verbose' => 0,
41 'version' => 0,
42 'waypoint' => 0,
46 our $progname = $0;
47 $progname =~ s/^.*\/(.*?)$/$1/;
49 my $rcs_id = '$Id$';
50 my $id_date = $rcs_id;
51 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
53 push(@main::version_array, $rcs_id);
55 Getopt::Long::Configure("bundling");
56 GetOptions(
58 "database|D=s" => \$Opt{'database'},
59 "debug" => \$Opt{'debug'},
60 "help|h" => \$Opt{'help'},
61 "timezone|T=s" => \$Opt{'timezone'},
62 "type|t=s" => \$Opt{'type'},
63 "verbose|v+" => \$Opt{'verbose'},
64 "version" => \$Opt{'version'},
65 "waypoint|w" => \$Opt{'waypoint'},
67 ) || die("$progname: Option error. Use -h for help.\n");
69 $Opt{'debug'} && ($Debug = 1);
70 $Opt{'help'} && usage(0);
71 if ($Opt{'version'}) {
72 print_version();
73 exit(0);
76 my $tz_str = "";
77 if (length($Opt{'timezone'})) {
78 if ($Opt{'timezone'} =~ /^[\+\-][0-2][0-9]{3}$/) {
79 $tz_str = $Opt{'timezone'};
80 } elsif ($Opt{'timezone'} =~ /^z$/i) {
81 $tz_str = $Opt{'timezone'};
82 } elsif ($Opt{'timezone'} =~ /^[a-z]+$/i) {
83 $tz_str = " $Opt{'timezone'}";
84 } else {
85 die("$progname: $Opt{'timezone'}: Invalid time zone\n");
89 for my $Currarg (@ARGV) {
90 for my $Currfile (glob($Currarg)) {
91 D("Currfile = '$Currfile'");
92 if ($Opt{'type'} =~ /picture/) {
93 if ($Currfile =~ /\.jpg$/i) {
94 my $tz_str = length($Opt{'timezone'})
95 ? "-T $Opt{'timezone'} "
96 : "";
97 my $exec_str =
98 "gpst-pic $tz_str$Currfile | psql -c \"COPY pictures (" .
99 join(", ",
100 "version",
101 "date",
102 "coor",
103 "descr",
104 "filename",
105 "author"
107 ") FROM stdin\" $Opt{'database'}";
108 msg(1, "Executing '$exec_str'...");
109 system($exec_str);
112 if ($Opt{'type'} =~ /track/) {
113 my $exec_str =
114 "gpst -o pgtab -d -rpt $Currfile | " .
115 "psql -a -c \"COPY logg (" .
116 join(", ",
117 "date",
118 "coor",
119 "ele",
120 "name",
121 "dist",
122 "description"
124 ") FROM stdin\" $Opt{'database'}";
125 msg(1, "Executing '$exec_str'...");
126 system($exec_str);
128 if ($Opt{'type'} =~ /waypoint/) {
129 my $exec_str =
130 "gpst -o pgwtab $Currfile | " .
131 "psql -a -c \"COPY wayp_new (" .
132 join(", ",
133 "coor",
134 "name",
135 "ele",
136 "type",
137 "time",
138 "cmt",
139 "descr",
140 "src",
141 "sym"
143 ") FROM stdin\" $Opt{'database'}";
144 msg(1, "Executing '$exec_str'...");
145 system($exec_str);
150 sub print_version {
151 # Print program version {{{
152 for (@main::version_array) {
153 print("$_\n");
155 # }}}
156 } # print_version()
158 sub usage {
159 # Send the help message to stdout {{{
160 my $Retval = shift;
162 if ($Opt{'verbose'}) {
163 print("\n");
164 print_version();
166 print(<<END);
168 Usage: $progname [options] [file [files [...]]]
170 Options:
172 -D X, --database X
173 Load into PostgreSQL database X. Default: "$Std{'database'}".
174 -h, --help
175 Show this help.
176 -T X, --timezone X
177 Prepend X as timezone to the date. Valid formats:
178 UTC offset
179 A '+' or '-' followed by a four-digit number (HHMM) which
180 indicates the offset relative to UTC. Examples:
181 +0000
182 -1600
183 +0630
184 Time zone abbreviation. Examples:
188 -t X, --type X
189 Comma-separated list of point types to extract from files:
190 picture
191 track
192 waypoint
193 Default: "$Std{'type'}".
194 -v, --verbose
195 Increase level of verbosity. Can be repeated.
196 --version
197 Print version information.
198 --debug
199 Print debugging messages.
202 exit($Retval);
203 # }}}
204 } # usage()
206 sub msg {
207 # Print a status message to stderr based on verbosity level {{{
208 my ($verbose_level, $Txt) = @_;
210 if ($Opt{'verbose'} >= $verbose_level) {
211 print(STDERR "$progname: $Txt\n");
213 # }}}
214 } # msg()
216 sub D {
217 # Print a debugging message {{{
218 $Debug || return;
219 my @call_info = caller;
220 chomp(my $Txt = shift);
221 my $File = $call_info[1];
222 $File =~ s#\\#/#g;
223 $File =~ s#^.*/(.*?)$#$1#;
224 print(STDERR "$File:$call_info[2] $$ $Txt\n");
225 return("");
226 # }}}
227 } # D()
229 __END__
231 # Plain Old Documentation (POD) {{{
233 =pod
235 =head1 NAME
239 =head1 REVISION
241 $Id$
243 =head1 SYNOPSIS
245 [options] [file [files [...]]]
247 =head1 DESCRIPTION
251 =head1 OPTIONS
253 =over 4
255 =item B<-h>, B<--help>
257 Print a brief help summary.
259 =item B<-v>, B<--verbose>
261 Increase level of verbosity. Can be repeated.
263 =item B<--version>
265 Print version information.
267 =item B<--debug>
269 Print debugging messages.
271 =back
273 =head1 BUGS
277 =head1 AUTHOR
279 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
281 =head1 COPYRIGHT
283 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
284 This is free software; see the file F<COPYING> for legalese stuff.
286 =head1 LICENCE
288 This program is free software; you can redistribute it and/or modify it
289 under the terms of the GNU General Public License as published by the
290 Free Software Foundation; either version 2 of the License, or (at your
291 option) any later version.
293 This program is distributed in the hope that it will be useful, but
294 WITHOUT ANY WARRANTY; without even the implied warranty of
295 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
296 See the GNU General Public License for more details.
298 You should have received a copy of the GNU General Public License along
299 with this program; if not, write to the Free Software Foundation, Inc.,
300 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
302 =head1 SEE ALSO
304 =cut
306 # }}}
308 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
309 # End of file $Id$