Forandrer alle «sted» i gpstools-systemet til «name». Egentlig utesta,
[gpstools.git] / makemesh
blob4b6f34ee0e4697b3d10be32daad9517ce9732ae1
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 = (
26 'debug' => 0,
27 'help' => 0,
28 'max' => 1000,
29 'min' => 0,
30 'verbose' => 0,
31 'version' => 0,
35 our $progname = $0;
36 $progname =~ s/^.*\/(.*?)$/$1/;
38 my $rcs_id = '$Id$';
39 my $id_date = $rcs_id;
40 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
42 push(@main::version_array, $rcs_id);
44 Getopt::Long::Configure("bundling");
45 GetOptions(
47 "debug" => \$Opt{'debug'},
48 "help|h" => \$Opt{'help'},
49 "max=f" => \$Opt{'max'},
50 "min=f" => \$Opt{'min'},
51 "verbose|v+" => \$Opt{'verbose'},
52 "version" => \$Opt{'version'},
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'debug'} && ($Debug = 1);
57 $Opt{'help'} && usage(0);
58 if ($Opt{'version'}) {
59 print_version();
60 exit(0);
63 my ($Lat, $Lon) =
64 ( 0, 0);
66 my @Ele = ();
68 my $Size = 20;
70 while (1) {
71 D("Lon = '$Lon'");
72 for $Lon (0..$Size) {
73 my $Left = defined($Ele[$Lat][$Lon-1]) ? $Ele[$Lat][$Lon-1] : rand(1);
74 my $Right = defined($Ele[$Lat][$Lon+1]) ? $Ele[$Lat][$Lon+1] : rand(1);
75 my $Over = defined($Ele[$Lat+1][$Lon]) ? $Ele[$Lat+1][$Lon] : rand(1);
76 my $Under = defined($Ele[$Lat-1][$Lon]) ? $Ele[$Lat-1][$Lon] : rand(1);
77 my $Curr = ($Left+$Right+$Over+$Under)/4;
78 $Curr += rand(1) >= 0.5 ? rand(1) : 0-rand(1);
79 # until ($Curr >= $Opt{'min'}) {
80 # D("Curr >= Min");
81 # $Curr += rand(1) * 1.0;
82 # }
83 # until ($Curr <= $Opt{'max'}) {
84 # D("Curr <= Max");
85 # $Curr -= rand(1) * 1.0;
86 # }
87 if ($Lat > 0 && $Lat < $Size && $Lon > 0 && $Lon < $Size) {
88 # print("$Lat\t$Lon\t$Curr\n");
89 # print($Lat . "\t" . $Lon-1 . "\t" . $Left . "\n");
90 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
91 # print("\n");
92 print($Lat+1 . "\t" . $Lon . "\t" . $Over . "\n");
93 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
94 # print("\n");
95 # print($Lat . "\t" . $Lon+1 . "\t" . $Right . "\n");
96 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
97 # print("\n");
98 print($Lat-1 . "\t" . $Lon . "\t" . $Under . "\n");
99 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
100 # print("\n");
102 $Ele[$Lat][$Lon] = $Curr;
103 print("\n");
105 $Lat += 1;
106 last if ($Lat > $Size);
109 sub print_version {
110 # Print program version {{{
111 for (@main::version_array) {
112 print("$_\n");
114 # }}}
115 } # print_version()
117 sub usage {
118 # Send the help message to stdout {{{
119 my $Retval = shift;
121 if ($Opt{'verbose'}) {
122 print("\n");
123 print_version();
125 print(<<END);
127 Usage: $progname [options] [file [files [...]]]
129 Options:
131 -h, --help
132 Show this help.
133 -v, --verbose
134 Increase level of verbosity. Can be repeated.
135 --version
136 Print version information.
137 --debug
138 Print debugging messages.
141 exit($Retval);
142 # }}}
143 } # usage()
145 sub msg {
146 # Print a status message to stderr based on verbosity level {{{
147 my ($verbose_level, $Txt) = @_;
149 if ($Opt{'verbose'} >= $verbose_level) {
150 print(STDERR "$progname: $Txt\n");
152 # }}}
153 } # msg()
155 sub D {
156 # Print a debugging message {{{
157 $Debug || return;
158 my @call_info = caller;
159 chomp(my $Txt = shift);
160 my $File = $call_info[1];
161 $File =~ s#\\#/#g;
162 $File =~ s#^.*/(.*?)$#$1#;
163 print(STDERR "$File:$call_info[2] $$ $Txt\n");
164 return("");
165 # }}}
166 } # D()
168 __END__
170 # Plain Old Documentation (POD) {{{
172 =pod
174 =head1 NAME
178 =head1 REVISION
180 $Id$
182 =head1 SYNOPSIS
184 [options] [file [files [...]]]
186 =head1 DESCRIPTION
190 =head1 OPTIONS
192 =over 4
194 =item B<-h>, B<--help>
196 Print a brief help summary.
198 =item B<-v>, B<--verbose>
200 Increase level of verbosity. Can be repeated.
202 =item B<--version>
204 Print version information.
206 =item B<--debug>
208 Print debugging messages.
210 =back
212 =head1 BUGS
216 =head1 AUTHOR
218 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
220 =head1 COPYRIGHT
222 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
223 This is free software; see the file F<COPYING> for legalese stuff.
225 =head1 LICENCE
227 This program is free software; you can redistribute it and/or modify it
228 under the terms of the GNU General Public License as published by the
229 Free Software Foundation; either version 2 of the License, or (at your
230 option) any later version.
232 This program is distributed in the hope that it will be useful, but
233 WITHOUT ANY WARRANTY; without even the implied warranty of
234 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
235 See the GNU General Public License for more details.
237 You should have received a copy of the GNU General Public License along
238 with this program; if not, write to the Free Software Foundation, Inc.,
239 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
241 =head1 SEE ALSO
243 =cut
245 # }}}
247 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
248 # End of file $Id$