-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspectrumcalc
executable file
·136 lines (89 loc) · 3.06 KB
/
spectrumcalc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl
use strict;
use warnings;
use 5.010; # For the \R generalized newline
use Getopt::Std;
use Pod::Usage;
local $Getopt::Std::STANDARD_HELP_VERSION = 1;
my %Opts;
getopts('HLhmv', \%Opts);
$Opts{h} and &HELP_MESSAGE;
$Opts{m} and pod2usage(VERBOSE=>2);
$Opts{v} and &VERSION_MESSAGE;
my $pntsfile = pop;
my $specfile = pop;
if ($Opts{H} and $Opts{L}) { die "You can't have it both ways--pick H or L. "};
unless ($Opts{H} or $Opts{L}) { die "You must pick either H or L. "};
open(my $specin, $specfile) || die "Couldn't read $specfile: $!";
open(my $ptsin, $pntsfile) || die "Couldn't read $pntsfile: $!";
my @spec;
while (<$specin>)
{ push @spec, [split];
}
my @pts;
while (<$ptsin>)
{ s/\R//;
push @pts, (split)[0];
}
if ($Opts{H})
{ foreach my $point (@pts)
{ my ($Gp,$Gpp) = 0;
for my $i (0..$#spec)
{ my $Gi = $spec[$i][1];
my $li = $spec[$i][0];
$Gp += $Gi*($point*$li)**2/(1+($point*$li)**2);
$Gpp += $Gi*($point*$li)/(1+($point*$li)**2);
}
print "$point\t$Gp\t$Gpp\n"
}
}
if ($Opts{L})
{ foreach my $point (@pts)
{ my $J = 0;
for my $i (0..$#spec)
{ my $Ji = $spec[$i][1];
my $ti = $spec[$i][0];
$J += $Ji*(1-exp(-$point/$ti));
}
print "$point\t$J\n"
}
}
sub HELP_MESSAGE { pod2usage(VERBOSE=>1) };
sub VERSION_MESSAGE { say "spectrumcalc.pl 0.1\nWritten Summer 2012, by Ian McDougall." };
__END__
=head1 NAME
spectrumcalc.pl - calculates rheological functions at arbitrary points from a discrete rheological spectrum.
=head1 SYNOPSIS
B<spectrumcalc.pl> I<-H> I<-L> I<-h> I<-m> I<-v> F<spectrum> F<points>
=head1 DESCRIPTION
B<spectrumcalc.pl> takes a discrete spectrum and a list of points, calculates associated material functions at those points, and prints them to STDOUT. It assumes that all input files are tab- or whitespace-separated and that the first column is the independent variable. Either one of the I<-H> (relaxation) or I<-L> (retardation) options is required to specify what kind of spectrum is given.
=head1 OPTIONS
=over 4
=item I<-H>
The input is a relaxation spectrum. The points will be interpreted as frequencies, and dynamic moduli will be calculated.
item I<-L>
The input is a retardation spectrum. The points will be interpreted as times, and creep compliances will be calculated.
=item I<-h>, I<--help>
Show this help message.
=item I<-m>
Show the manpage (full documentation).
=item I<-v>, I<--version>
Show version information.
=back
=head1 DIAGNOSTICS
=over 4
=item Couldn't read F<filename>!
(F) The given F<filename> was invalid for some reason.
=item You can't have it both ways--pick H or L.
(F) Either option I<-H> or I<-L> is required, but you can't use both.
=item You must pick either H ot L.
(F) Unless you specify the type of spectrum given with the I<-H> or I<-L> option, B<spectrumcalc.pl> won't know what to do with it.
=back
=TODO
I need to find the papers I got the formulas from, check them one last time, and reference them in the documentation.
=head1 REQUIRES
Perl 5.010, Getopt::Std, Pod::Usage
=head1 SEE ALSO
perl(1)
=head1 AUTHOR
Ian McDougall, [email protected]