* /branches/gpst.spread/
[gpstools.git] / makemesh
blob4327463f182e4b2063daca0b1d8aebc57d97491c
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 use strict;
14 use Getopt::Long;
16 $| = 1;
18 our $Debug = 0;
20 our %Opt = (
21 'debug' => 0,
22 'help' => 0,
23 'max' => 1000,
24 'min' => 0,
25 'verbose' => 0,
26 'version' => 0,
29 our $progname = $0;
30 $progname =~ s#^.*/(.*?)$#$1#;
32 my $rcs_id = '$Id$';
33 my $id_date = $rcs_id;
34 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
36 Getopt::Long::Configure("bundling");
37 GetOptions(
38 "debug" => \$Opt{'debug'},
39 "help|h" => \$Opt{'help'},
40 "max=f" => \$Opt{'max'},
41 "min=f" => \$Opt{'min'},
42 "verbose|v+" => \$Opt{'verbose'},
43 "version" => \$Opt{'version'},
44 ) || die("$progname: Option error. Use -h for help.\n");
46 $Opt{'debug'} && ($Debug = 1);
47 $Opt{'help'} && usage(0);
48 $Opt{'version'} && print_version();
50 my ($Lat, $Lon) =
51 ( 0, 0);
53 my @Ele = ();
55 my $Size = 20;
57 while (1) {
58 D("Lon = '$Lon'");
59 for $Lon (0..$Size) {
60 my $Left = defined($Ele[$Lat][$Lon-1]) ? $Ele[$Lat][$Lon-1] : rand(1);
61 my $Right = defined($Ele[$Lat][$Lon+1]) ? $Ele[$Lat][$Lon+1] : rand(1);
62 my $Over = defined($Ele[$Lat+1][$Lon]) ? $Ele[$Lat+1][$Lon] : rand(1);
63 my $Under = defined($Ele[$Lat-1][$Lon]) ? $Ele[$Lat-1][$Lon] : rand(1);
64 my $Curr = ($Left+$Right+$Over+$Under)/4;
65 $Curr += rand(1) >= 0.5 ? rand(1) : 0-rand(1);
66 # until ($Curr >= $Opt{'min'}) {
67 # D("Curr >= Min");
68 # $Curr += rand(1) * 1.0;
69 # }
70 # until ($Curr <= $Opt{'max'}) {
71 # D("Curr <= Max");
72 # $Curr -= rand(1) * 1.0;
73 # }
74 if ($Lat > 0 && $Lat < $Size && $Lon > 0 && $Lon < $Size) {
75 # print("$Lat\t$Lon\t$Curr\n");
76 # print($Lat . "\t" . $Lon-1 . "\t" . $Left . "\n");
77 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
78 # print("\n");
79 print($Lat+1 . "\t" . $Lon . "\t" . $Over . "\n");
80 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
81 # print("\n");
82 # print($Lat . "\t" . $Lon+1 . "\t" . $Right . "\n");
83 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
84 # print("\n");
85 print($Lat-1 . "\t" . $Lon . "\t" . $Under . "\n");
86 print($Lat . "\t" . $Lon . "\t" . $Curr . "\n");
87 # print("\n");
89 $Ele[$Lat][$Lon] = $Curr;
90 print("\n");
92 $Lat += 1;
93 last if ($Lat > $Size);
96 sub print_version {
97 # Print program version {{{
98 print("$rcs_id\n");
99 exit(0);
100 # }}}
101 } # print_version()
103 sub usage {
104 # Send the help message to stdout {{{
105 my $Retval = shift;
107 print(<<END);
109 $rcs_id
111 Usage: $progname [options] [file [files [...]]]
113 Options:
115 -h, --help
116 Show this help.
117 -v, --verbose
118 Increase level of verbosity. Can be repeated.
119 --version
120 Print version information.
121 --debug
122 Print debugging messages.
125 exit($Retval);
126 # }}}
127 } # usage()
129 sub msg {
130 # Print a status message to stderr based on verbosity level {{{
131 my ($verbose_level, $Txt) = @_;
133 if ($Opt{'verbose'} >= $verbose_level) {
134 print(STDERR "$progname: $Txt\n");
136 # }}}
137 } # msg()
139 sub D {
140 # Print a debugging message {{{
141 $Debug || return;
142 my @call_info = caller;
143 chomp(my $Txt = shift);
144 my $File = $call_info[1];
145 $File =~ s#\\#/#g;
146 $File =~ s#^.*/(.*?)$#$1#;
147 print(STDERR "$File:$call_info[2] $$ $Txt\n");
148 return("");
149 # }}}
150 } # D()
152 __END__
154 # Plain Old Documentation (POD) {{{
156 =pod
158 =head1 NAME
162 =head1 REVISION
164 $Id$
166 =head1 SYNOPSIS
168 [options] [file [files [...]]]
170 =head1 DESCRIPTION
174 =head1 OPTIONS
176 =over 4
178 =item B<-h>, B<--help>
180 Print a brief help summary.
182 =item B<-v>, B<--verbose>
184 Increase level of verbosity. Can be repeated.
186 =item B<--version>
188 Print version information.
190 =item B<--debug>
192 Print debugging messages.
194 =back
196 =head1 BUGS
200 =head1 AUTHOR
202 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
204 =head1 COPYRIGHT
206 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
207 This is free software; see the file F<COPYING> for legalese stuff.
209 =head1 LICENCE
211 This program is free software; you can redistribute it and/or modify it
212 under the terms of the GNU General Public License as published by the
213 Free Software Foundation; either version 2 of the License, or (at your
214 option) any later version.
216 This program is distributed in the hope that it will be useful, but
217 WITHOUT ANY WARRANTY; without even the implied warranty of
218 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
219 See the GNU General Public License for more details.
221 You should have received a copy of the GNU General Public License along
222 with this program; if not, write to the Free Software Foundation, Inc.,
223 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
225 =head1 SEE ALSO
227 =cut
229 # }}}
231 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
232 # End of file $Id$