gpst: Use my $curr_file in for loop
[gpstools.git] / makemesh
blobd5bbcb4fc23dd27b06d181027ffb6db0366b38ba
1 #!/usr/bin/perl
3 #=======================================================================
4 # makemesh
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 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'help' => 0,
26 'max' => 1000,
27 'min' => 0,
28 'verbose' => 0,
29 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = "0.00";
37 Getopt::Long::Configure("bundling");
38 GetOptions(
40 "debug" => \$Opt{'debug'},
41 "help|h" => \$Opt{'help'},
42 "max=f" => \$Opt{'max'},
43 "min=f" => \$Opt{'min'},
44 "verbose|v+" => \$Opt{'verbose'},
45 "version" => \$Opt{'version'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'debug'} && ($Debug = 1);
50 $Opt{'help'} && usage(0);
51 if ($Opt{'version'}) {
52 print_version();
53 exit(0);
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 print("$progname v$VERSION\n");
105 # }}}
106 } # print_version()
108 sub usage {
109 # Send the help message to stdout {{{
110 my $Retval = shift;
112 if ($Opt{'verbose'}) {
113 print("\n");
114 print_version();
116 print(<<END);
118 Usage: $progname [options] [file [files [...]]]
120 Options:
122 -h, --help
123 Show this help.
124 -v, --verbose
125 Increase level of verbosity. Can be repeated.
126 --version
127 Print version information.
128 --debug
129 Print debugging messages.
132 exit($Retval);
133 # }}}
134 } # usage()
136 sub msg {
137 # Print a status message to stderr based on verbosity level {{{
138 my ($verbose_level, $Txt) = @_;
140 if ($Opt{'verbose'} >= $verbose_level) {
141 print(STDERR "$progname: $Txt\n");
143 # }}}
144 } # msg()
146 sub D {
147 # Print a debugging message {{{
148 $Debug || return;
149 my @call_info = caller;
150 chomp(my $Txt = shift);
151 my $File = $call_info[1];
152 $File =~ s#\\#/#g;
153 $File =~ s#^.*/(.*?)$#$1#;
154 print(STDERR "$File:$call_info[2] $$ $Txt\n");
155 return("");
156 # }}}
157 } # D()
159 __END__
161 # Plain Old Documentation (POD) {{{
163 =pod
165 =head1 NAME
169 =head1 SYNOPSIS
171 [options] [file [files [...]]]
173 =head1 DESCRIPTION
177 =head1 OPTIONS
179 =over 4
181 =item B<-h>, B<--help>
183 Print a brief help summary.
185 =item B<-v>, B<--verbose>
187 Increase level of verbosity. Can be repeated.
189 =item B<--version>
191 Print version information.
193 =item B<--debug>
195 Print debugging messages.
197 =back
199 =head1 BUGS
203 =head1 AUTHOR
205 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
207 =head1 COPYRIGHT
209 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
210 This is free software; see the file F<COPYING> for legalese stuff.
212 =head1 LICENCE
214 This program is free software: you can redistribute it and/or modify it
215 under the terms of the GNU General Public License as published by the
216 Free Software Foundation, either version 3 of the License, or (at your
217 option) any later version.
219 This program is distributed in the hope that it will be useful, but
220 WITHOUT ANY WARRANTY; without even the implied warranty of
221 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
222 See the GNU General Public License for more details.
224 You should have received a copy of the GNU General Public License along
225 with this program.
226 If not, see L<http://www.gnu.org/licenses/>.
228 =head1 SEE ALSO
230 =cut
232 # }}}
234 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :