* /trunk/src/gpstools/poisync
[gpstools.git] / makemesh
blob8cf06058d4c4c6dccc45684eb5b05a529eb2511a
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # File ID: 2036c7c6-f924-11dd-b41d-0001805bf4b1
6 # Create random 3D surface for use in plotting programs.
8 # Character set: UTF-8
9 # ©opyleft 2007– Ø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 %Opt = (
27 'debug' => 0,
28 'help' => 0,
29 'max' => 1000,
30 'min' => 0,
31 'verbose' => 0,
32 'version' => 0,
36 our $progname = $0;
37 $progname =~ s/^.*\/(.*?)$/$1/;
39 my $rcs_id = '$Id$';
40 my $id_date = $rcs_id;
41 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
43 push(@main::version_array, $rcs_id);
45 Getopt::Long::Configure("bundling");
46 GetOptions(
48 "debug" => \$Opt{'debug'},
49 "help|h" => \$Opt{'help'},
50 "max=f" => \$Opt{'max'},
51 "min=f" => \$Opt{'min'},
52 "verbose|v+" => \$Opt{'verbose'},
53 "version" => \$Opt{'version'},
55 ) || die("$progname: Option error. Use -h for help.\n");
57 $Opt{'debug'} && ($Debug = 1);
58 $Opt{'help'} && usage(0);
59 if ($Opt{'version'}) {
60 print_version();
61 exit(0);
64 my ($Lat, $Lon) =
65 ( 0, 0);
67 my @Ele = ();
69 my $Size = 20;
71 while (1) {
72 D("Lon = '$Lon'");
73 for $Lon (0..$Size) {
74 my $Left = defined($Ele[$Lat][$Lon-1]) ? $Ele[$Lat][$Lon-1] : rand(1);
75 my $Right = defined($Ele[$Lat][$Lon+1]) ? $Ele[$Lat][$Lon+1] : rand(1);
76 my $Over = defined($Ele[$Lat+1][$Lon]) ? $Ele[$Lat+1][$Lon] : rand(1);
77 my $Under = defined($Ele[$Lat-1][$Lon]) ? $Ele[$Lat-1][$Lon] : rand(1);
78 my $Curr = ($Left+$Right+$Over+$Under)/4;
79 $Curr += rand(1) >= 0.5 ? rand(1) : 0-rand(1);
80 # until ($Curr >= $Opt{'min'}) {
81 # D("Curr >= Min");
82 # $Curr += rand(1) * 1.0;
83 # }
84 # until ($Curr <= $Opt{'max'}) {
85 # D("Curr <= Max");
86 # $Curr -= rand(1) * 1.0;
87 # }
88 if ($Lat > 0 && $Lat < $Size && $Lon > 0 && $Lon < $Size) {
89 # print("$Lat\t$Lon\t$Curr\n");
90 # print($Lat . "\t" . $Lon-1 . "\t" . $Left . "\n");
91 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
92 # print("\n");
93 print($Lat+1 . "\t" . $Lon . "\t" . $Over . "\n");
94 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
95 # print("\n");
96 # print($Lat . "\t" . $Lon+1 . "\t" . $Right . "\n");
97 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
98 # print("\n");
99 print($Lat-1 . "\t" . $Lon . "\t" . $Under . "\n");
100 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
101 # print("\n");
103 $Ele[$Lat][$Lon] = $Curr;
104 print("\n");
106 $Lat += 1;
107 last if ($Lat > $Size);
110 sub print_version {
111 # Print program version {{{
112 for (@main::version_array) {
113 print("$_\n");
115 # }}}
116 } # print_version()
118 sub usage {
119 # Send the help message to stdout {{{
120 my $Retval = shift;
122 if ($Opt{'verbose'}) {
123 print("\n");
124 print_version();
126 print(<<END);
128 Usage: $progname [options] [file [files [...]]]
130 Options:
132 -h, --help
133 Show this help.
134 -v, --verbose
135 Increase level of verbosity. Can be repeated.
136 --version
137 Print version information.
138 --debug
139 Print debugging messages.
142 exit($Retval);
143 # }}}
144 } # usage()
146 sub msg {
147 # Print a status message to stderr based on verbosity level {{{
148 my ($verbose_level, $Txt) = @_;
150 if ($Opt{'verbose'} >= $verbose_level) {
151 print(STDERR "$progname: $Txt\n");
153 # }}}
154 } # msg()
156 sub D {
157 # Print a debugging message {{{
158 $Debug || return;
159 my @call_info = caller;
160 chomp(my $Txt = shift);
161 my $File = $call_info[1];
162 $File =~ s#\\#/#g;
163 $File =~ s#^.*/(.*?)$#$1#;
164 print(STDERR "$File:$call_info[2] $$ $Txt\n");
165 return("");
166 # }}}
167 } # D()
169 __END__
171 # Plain Old Documentation (POD) {{{
173 =pod
175 =head1 NAME
179 =head1 REVISION
181 $Id$
183 =head1 SYNOPSIS
185 [options] [file [files [...]]]
187 =head1 DESCRIPTION
191 =head1 OPTIONS
193 =over 4
195 =item B<-h>, B<--help>
197 Print a brief help summary.
199 =item B<-v>, B<--verbose>
201 Increase level of verbosity. Can be repeated.
203 =item B<--version>
205 Print version information.
207 =item B<--debug>
209 Print debugging messages.
211 =back
213 =head1 BUGS
217 =head1 AUTHOR
219 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
221 =head1 COPYRIGHT
223 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
224 This is free software; see the file F<COPYING> for legalese stuff.
226 =head1 LICENCE
228 This program is free software; you can redistribute it and/or modify it
229 under the terms of the GNU General Public License as published by the
230 Free Software Foundation; either version 2 of the License, or (at your
231 option) any later version.
233 This program is distributed in the hope that it will be useful, but
234 WITHOUT ANY WARRANTY; without even the implied warranty of
235 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
236 See the GNU General Public License for more details.
238 You should have received a copy of the GNU General Public License along
239 with this program; if not, write to the Free Software Foundation, Inc.,
240 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
242 =head1 SEE ALSO
244 =cut
246 # }}}
248 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
249 # End of file $Id$