* /branches/gpst.gpxfix/.
[gpstools.git] / makemesh
blob93d9e2977762487ca76e79e01ae5e3542e69fa6d
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # Create random 3D surface for use in plotting programs.
7 # Character set: UTF-8
8 # ©opyleft 2007– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License version 2 or later, see end of
10 # file for legal stuff.
11 #=======================================================================
13 BEGIN {
14 our @version_array;
17 use strict;
18 use Getopt::Long;
20 $| = 1;
22 our $Debug = 0;
24 our %Opt = (
25 'debug' => 0,
26 'help' => 0,
27 'max' => 1000,
28 'min' => 0,
29 'verbose' => 0,
30 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
36 my $rcs_id = '$Id$';
37 my $id_date = $rcs_id;
38 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
40 push(@main::version_array, $rcs_id);
42 Getopt::Long::Configure("bundling");
43 GetOptions(
44 "debug" => \$Opt{'debug'},
45 "help|h" => \$Opt{'help'},
46 "max=f" => \$Opt{'max'},
47 "min=f" => \$Opt{'min'},
48 "verbose|v+" => \$Opt{'verbose'},
49 "version" => \$Opt{'version'},
50 ) || die("$progname: Option error. Use -h for help.\n");
52 $Opt{'debug'} && ($Debug = 1);
53 $Opt{'help'} && usage(0);
54 $Opt{'version'} && print_version();
56 my ($Lat, $Lon) =
57 ( 0, 0);
59 my @Ele = ();
61 my $Size = 20;
63 while (1) {
64 D("Lon = '$Lon'");
65 for $Lon (0..$Size) {
66 my $Left = defined($Ele[$Lat][$Lon-1]) ? $Ele[$Lat][$Lon-1] : rand(1);
67 my $Right = defined($Ele[$Lat][$Lon+1]) ? $Ele[$Lat][$Lon+1] : rand(1);
68 my $Over = defined($Ele[$Lat+1][$Lon]) ? $Ele[$Lat+1][$Lon] : rand(1);
69 my $Under = defined($Ele[$Lat-1][$Lon]) ? $Ele[$Lat-1][$Lon] : rand(1);
70 my $Curr = ($Left+$Right+$Over+$Under)/4;
71 $Curr += rand(1) >= 0.5 ? rand(1) : 0-rand(1);
72 # until ($Curr >= $Opt{'min'}) {
73 # D("Curr >= Min");
74 # $Curr += rand(1) * 1.0;
75 # }
76 # until ($Curr <= $Opt{'max'}) {
77 # D("Curr <= Max");
78 # $Curr -= rand(1) * 1.0;
79 # }
80 if ($Lat > 0 && $Lat < $Size && $Lon > 0 && $Lon < $Size) {
81 # print("$Lat\t$Lon\t$Curr\n");
82 # print($Lat . "\t" . $Lon-1 . "\t" . $Left . "\n");
83 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
84 # print("\n");
85 print($Lat+1 . "\t" . $Lon . "\t" . $Over . "\n");
86 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
87 # print("\n");
88 # print($Lat . "\t" . $Lon+1 . "\t" . $Right . "\n");
89 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
90 # print("\n");
91 print($Lat-1 . "\t" . $Lon . "\t" . $Under . "\n");
92 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
93 # print("\n");
95 $Ele[$Lat][$Lon] = $Curr;
96 print("\n");
98 $Lat += 1;
99 last if ($Lat > $Size);
102 sub print_version {
103 # Print program version {{{
104 for (@main::version_array) {
105 print("$_\n");
107 exit(0);
108 # }}}
109 } # print_version()
111 sub usage {
112 # Send the help message to stdout {{{
113 my $Retval = shift;
115 print(<<END);
117 $rcs_id
119 Usage: $progname [options] [file [files [...]]]
121 Options:
123 -h, --help
124 Show this help.
125 -v, --verbose
126 Increase level of verbosity. Can be repeated.
127 --version
128 Print version information.
129 --debug
130 Print debugging messages.
133 exit($Retval);
134 # }}}
135 } # usage()
137 sub msg {
138 # Print a status message to stderr based on verbosity level {{{
139 my ($verbose_level, $Txt) = @_;
141 if ($Opt{'verbose'} >= $verbose_level) {
142 print(STDERR "$progname: $Txt\n");
144 # }}}
145 } # msg()
147 sub D {
148 # Print a debugging message {{{
149 $Debug || return;
150 my @call_info = caller;
151 chomp(my $Txt = shift);
152 my $File = $call_info[1];
153 $File =~ s#\\#/#g;
154 $File =~ s#^.*/(.*?)$#$1#;
155 print(STDERR "$File:$call_info[2] $$ $Txt\n");
156 return("");
157 # }}}
158 } # D()
160 __END__
162 # Plain Old Documentation (POD) {{{
164 =pod
166 =head1 NAME
170 =head1 REVISION
172 $Id$
174 =head1 SYNOPSIS
176 [options] [file [files [...]]]
178 =head1 DESCRIPTION
182 =head1 OPTIONS
184 =over 4
186 =item B<-h>, B<--help>
188 Print a brief help summary.
190 =item B<-v>, B<--verbose>
192 Increase level of verbosity. Can be repeated.
194 =item B<--version>
196 Print version information.
198 =item B<--debug>
200 Print debugging messages.
202 =back
204 =head1 BUGS
208 =head1 AUTHOR
210 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
212 =head1 COPYRIGHT
214 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
215 This is free software; see the file F<COPYING> for legalese stuff.
217 =head1 LICENCE
219 This program is free software; you can redistribute it and/or modify it
220 under the terms of the GNU General Public License as published by the
221 Free Software Foundation; either version 2 of the License, or (at your
222 option) any later version.
224 This program is distributed in the hope that it will be useful, but
225 WITHOUT ANY WARRANTY; without even the implied warranty of
226 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
227 See the GNU General Public License for more details.
229 You should have received a copy of the GNU General Public License along
230 with this program; if not, write to the Free Software Foundation, Inc.,
231 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
233 =head1 SEE ALSO
235 =cut
237 # }}}
239 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
240 # End of file $Id$