meplib / binaries / bin / printTCPointsList.pl @ master
Historique | Voir | Annoter | Télécharger (5,56 ko)
1 |
#! /usr/bin/perl |
---|---|
2 |
|
3 |
# printTCPointsList.pl - ST - 2005-07-18 |
4 |
|
5 |
# COMMAND LINE SYNTAX: |
6 |
# printPointsList.pl lowerbBound upperBound numPoints |
7 |
|
8 |
# NOTE(S): |
9 |
# |
10 |
|
11 |
############################################################################## |
12 |
# PROGRAM DECLARATIONS |
13 |
############################################################################## |
14 |
|
15 |
BEGIN |
16 |
{ |
17 |
# Modify @INC here if necessary |
18 |
push(@INC,"../utils"); |
19 |
push(@INC,"../utils/tchebychev"); |
20 |
$ENV{PATH} .= ":../utils/tchebychev"; |
21 |
}; |
22 |
|
23 |
# core modules |
24 |
use strict; # must be first to force strict in all others |
25 |
use Carp; |
26 |
use Getopt::Long; |
27 |
use Math::BigFloat; |
28 |
use Math::BigRat; |
29 |
|
30 |
# custom modules |
31 |
# Uncomment if you want to use standard exit error codes. |
32 |
# the stdExitErrors.pm file must be available around. |
33 |
use stdExitErrors; |
34 |
use Tchebychev qw(:BASIC); |
35 |
#use Matrix qw(:BASIC); |
36 |
|
37 |
############################################################################## |
38 |
# PROGRAM CONSTANT DECLARATIONS |
39 |
############################################################################## |
40 |
my @test = (1,2,10); |
41 |
my $maxErrContFrac = Math::BigFloat->new("0.001"); |
42 |
############################################################################## |
43 |
# PROGRAM VARIABLE DECLARATIONS |
44 |
############################################################################## |
45 |
my $lowerBoundAsBigRat; |
46 |
my $upperBoundAsBigRat; |
47 |
my $numPoints; |
48 |
my $refPoints; |
49 |
############################################################################## |
50 |
# TEST ENVIRONMENT AND CONFIGURATION VARIABLES |
51 |
############################################################################## |
52 |
|
53 |
############################################################################## |
54 |
# INITIALIZE DEBUG FILE |
55 |
############################################################################## |
56 |
|
57 |
############################################################################## |
58 |
# INITIALIZE LOG FILE |
59 |
############################################################################## |
60 |
|
61 |
############################################################################## |
62 |
# GET COMMAND LINE ARGUMENTS |
63 |
############################################################################## |
64 |
|
65 |
############################################################################## |
66 |
# PROGRAM MAIN |
67 |
############################################################################## |
68 |
&usage(); |
69 |
# Use $numPoints -2 because we add the lower and the upper bounds. |
70 |
$refPoints = &tchebychevPointsForInterval($lowerBoundAsBigRat, |
71 |
$upperBoundAsBigRat, |
72 |
$numPoints - 2, |
73 |
$maxErrContFrac); |
74 |
# Add the lower bound (at the tail) and the upper bound (at the front) |
75 |
# of the list |
76 |
unshift(@$refPoints, $upperBoundAsBigRat); |
77 |
push(@$refPoints, $lowerBoundAsBigRat); |
78 |
for (my $i = (@$refPoints - 1) ; $i >= 0 ; $i--) |
79 |
{ |
80 |
print STDOUT "$$refPoints[$i] "; |
81 |
} |
82 |
print STDOUT "\n"; |
83 |
# Uncomment this line and remove the next one if using stdExitErrors. |
84 |
exit($EX_OK); |
85 |
|
86 |
############################################################################## |
87 |
# PROGRAM SUBS |
88 |
############################################################################## |
89 |
############################################################################## |
90 |
# sub mySub |
91 |
############################################################################## |
92 |
# Performed task: |
93 |
# |
94 |
# input : |
95 |
# output : |
96 |
# globals : |
97 |
# |
98 |
sub mySub { |
99 |
my ($someParameter) = @_; |
100 |
if (! defined($someParameter)) |
101 |
{ |
102 |
my @call_info = caller(0); |
103 |
print "\n\n", $call_info[3], " missing parameter. Aborting program!\n\n"; |
104 |
# Uncomment this line and remove the next one if using stdExitErrors. |
105 |
#exit($EX_SOFTWARE); |
106 |
exit(1); |
107 |
} |
108 |
} # End mySub |
109 |
############################################################################## |
110 |
# sub $retv = _privateSubName($argv) |
111 |
############################################################################## |
112 |
|
113 |
sub _privateSubName |
114 |
{ |
115 |
my $argv = shift(); |
116 |
my $retv = undef; |
117 |
return($retv); |
118 |
}; |
119 |
# |
120 |
############################################################################## |
121 |
# sub usage |
122 |
############################################################################## |
123 |
# Performed task: checks the command line parameters |
124 |
# |
125 |
# input : none |
126 |
# output : none |
127 |
# globals : $ARGV,others... |
128 |
# |
129 |
sub usage { |
130 |
if (! defined($ARGV[2])) |
131 |
{ |
132 |
my $scriptName = `basename $0`; |
133 |
chomp $scriptName; |
134 |
print STDERR "\n\nUsage : $scriptName lowerBound upperBound num_points\n\n"; |
135 |
print STDERR " - lowerBound: the lower bound of the interval;\n"; |
136 |
print STDERR " - upperBound: the upper bound of the interval;\n"; |
137 |
print STDERR " - num_points: the number of points.\n\n"; |
138 |
# Uncomment this line and remove the next one if using stdExitErrors. |
139 |
exit($EX_USAGE); |
140 |
} # End if |
141 |
# Some initializations |
142 |
$ARGV[0] =~ s/"//g; |
143 |
$lowerBoundAsBigRat = Math::BigRat->new($ARGV[0]); |
144 |
if ($lowerBoundAsBigRat->is_nan()) |
145 |
{ |
146 |
print STDERR "\n\n"; |
147 |
print STDERR "The lower bound \"$ARGV[0]\" could not be converted into a "; |
148 |
print STDERR "Math::BigRat. Aborting the program!\n\n"; |
149 |
exit ($EX_DATAERR); |
150 |
} |
151 |
$ARGV[1] =~ s/"//g; |
152 |
$upperBoundAsBigRat = Math::BigRat->new($ARGV[1]); |
153 |
if ($upperBoundAsBigRat->is_nan()) |
154 |
{ |
155 |
print STDERR "\n\n"; |
156 |
print STDERR "The upper bound \"$ARGV[1]\" could not be converted into a "; |
157 |
print STDERR "Math::BigRat. Aborting the program!\n\n"; |
158 |
exit ($EX_DATAERR); |
159 |
} |
160 |
$ARGV[2] =~ s/"//g; |
161 |
$numPoints = $ARGV[2]; |
162 |
if (Math::BigInt->new($numPoints)->is_nan()) |
163 |
{ |
164 |
print STDERR "\n\n"; |
165 |
print STDERR "The number of points \"$ARGV[3]\" is not a valid integer. "; |
166 |
print STDERR "Aborting the program!\n\n"; |
167 |
exit ($EX_DATAERR); |
168 |
} |
169 |
|
170 |
} # End usage |
171 |
|
172 |
|
173 |
__END__ |
174 |
|