Math-Spline-0.02000755000000000000 012145176425 14112 5ustar00unknownunknown000000000000Makefile.PL000644000000000000 423412145173043 16140 0ustar00unknownunknown000000000000Math-Spline-0.02use ExtUtils::MakeMaker; use Config; WriteMakefile1( 'NAME' => 'Math::Spline', 'VERSION_FROM' => 'Spline.pm', PREREQ_PM => { 'Math::Derivative' => 0, 'Carp' => 0, 'Exporter' => 5.57, }, TEST_REQUIRES => { 'Test::More' => 0, }, LICENSE => 'perl', MIN_PERL_VERSION => '5.006', META_MERGE => { resources => { repository => 'git://github.com/chorny/Math-Spline.git', }, }, 'clean' => {'FILES' => '*~'}, $^O =~/win/i ? ( dist => { TAR => 'ptar', TARFLAGS => '-c -C -f', }, ) : (), ); sub WriteMakefile1 { #Compatibility code for old versions of EU::MM. Written by Alexandr Ciornii, version 0.23. Added by eumm-upgrade. my %params=@_; my $eumm_version=$ExtUtils::MakeMaker::VERSION; $eumm_version=eval $eumm_version; die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; die "License not specified" if not exists $params{LICENSE}; if ($params{AUTHOR} and ref($params{AUTHOR}) eq 'ARRAY' and $eumm_version < 6.5705) { $params{META_ADD}->{author}=$params{AUTHOR}; $params{AUTHOR}=join(', ',@{$params{AUTHOR}}); } if ($params{TEST_REQUIRES} and $eumm_version < 6.64) { $params{BUILD_REQUIRES}={ %{$params{BUILD_REQUIRES} || {}} , %{$params{TEST_REQUIRES}} }; delete $params{TEST_REQUIRES}; } if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; delete $params{BUILD_REQUIRES}; } delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; delete $params{META_MERGE} if $eumm_version < 6.46; delete $params{META_ADD} if $eumm_version < 6.46; delete $params{LICENSE} if $eumm_version < 6.31; delete $params{AUTHOR} if $] < 5.005; delete $params{ABSTRACT_FROM} if $] < 5.005; delete $params{BINARY_LOCATION} if $] < 5.005; WriteMakefile(%params); } MANIFEST000644000000000000 36012145176425 15302 0ustar00unknownunknown000000000000Math-Spline-0.02MANIFEST README Release Makefile.PL Spline.pm t/00-load.t t/01-work.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) META.json000644000000000000 212712145176425 15615 0ustar00unknownunknown000000000000Math-Spline-0.02{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.112621", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Math-Spline", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : 0, "Test::More" : 0 } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "runtime" : { "requires" : { "Carp" : 0, "Exporter" : "5.57", "Math::Derivative" : 0, "perl" : "5.006" } } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "git://github.com/chorny/Math-Spline.git" } }, "version" : "0.02" } META.yml000644000000000000 112112145176423 15434 0ustar00unknownunknown000000000000Math-Spline-0.02--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: 0 Test::More: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.112621' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Math-Spline no_index: directory: - t - inc requires: Carp: 0 Exporter: 5.57 Math::Derivative: 0 perl: 5.006 resources: repository: git://github.com/chorny/Math-Spline.git version: 0.02 README000644000000000000 101512145176310 15040 0ustar00unknownunknown000000000000Math-Spline-0.02Perl Module Math::Spline - 0.02 Copyright (c) 1995 John A.R. Williams. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. To install, unzip and untar the archive. In the directory created type perl Makefile.pl make install Documentation is in the module file and will be added onto perllocal.pod as usual. The perl package Math::Derivative is required by this module. I can be contacted at Release000644000000000000 132212145176321 15466 0ustar00unknownunknown000000000000Math-Spline-0.02Announcing the release of Perl Module Math::Spline Version 0.02 Math::Spline - Cubic Spline Interpolation of data This package provides cubic spline interpolation of numeric data. The data is passed as references to two arrays containing the x and y ordinates. It may be used as an exporter of the the numerical functions or, more easily as a class module. Module Entry 6) Data Types and Data Type Utilities (see also Database Interfaces) Name DSLI Description Info ----------- ---- -------------------------------------------- ----- Math:: ::Spline RdpO Cubic Spline Interpolation of data JARW JARW John A.R. Williams Spline.pm000644000000000000 733012145176161 15762 0ustar00unknownunknown000000000000Math-Spline-0.02package Math::Spline; use 5.006; use strict; use warnings; use Exporter 'import'; #require Exporter; #@ISA=qw(Exporter); our @EXPORT_OK=qw(linsearch binsearch spline); our $VERSION = 0.02; use Carp; use Math::Derivative qw(Derivative2); sub new { my $type=shift; my $self=[]; push @{$self},shift; # x push @{$self},shift; # y my $y2=[Derivative2($self->[0],$self->[1])]; push @{$self},$y2; bless $self,$type; } sub evaluate { my ($self,$v)=@_; my $idx=binsearch($self->[0],$v); spline($self->[0],$self->[1],$self->[2],$idx,$v); } sub spline { my ($x,$y,$y2,$i,$v)=@_; my ($klo,$khi)=($i,$i+1); my $h=$x->[$khi]-$x->[$klo]; if ($h==0) { croak "Zero interval in spline data.\n"; } my $a=($x->[$khi]-$v)/$h; my $b=($v-$x->[$klo])/$h; return $a*$y->[$klo] + $b*$y->[$khi] +(($a*$a*$a-$a)*$y2->[$klo] +($b*$b*$b-$b)*$y2->[$khi])*($h*$h)/6.0; } sub binsearch { # binary search routine finds index just below value my ($x,$v)=@_; my ($klo,$khi)=(0,$#{$x}); my $k; while (($khi-$klo)>1) { $k=int(($khi+$klo)/2); if ($x->[$k]>$v) { $khi=$k; } else { $klo=$k; } } return $klo; } sub linsearch { # more efficient if repetatively doint it my ($x,$v,$khi)=@_; $khi+=1; my $n=$#{$x}; while($v>$x->[$khi] and $khi<$n) { $khi++; } $_[2]=$khi-1; } 1; __END__ =head1 NAME Math::Spline - Cubic Spline Interpolation of data =head1 SYNOPSIS use Math::Spline; $spline = Math::Spline->new(\@x,\@y) $y_interp=$spline->evaluate($x); use Math::Spline qw(spline linsearch binsearch); use Math::Derivative qw(Derivative2); @y2=Derivative2(\@x,\@y); $index=binsearch(\@x,$x); $index=linsearch(\@x,$x,$index); $y_interp=spline(\@x,\@y,\@y2,$index,$x); =head1 DESCRIPTION This package provides cubic spline interpolation of numeric data. The data is passed as references to two arrays containing the x and y ordinates. It may be used as an exporter of the numerical functions or, more easily as a class module. The B class constructor B takes references to the arrays of x and y ordinates of the data. An interpolation is performed using the B method, which, when given an x ordinate returns the interpolate y ordinate at that value. The B function takes as arguments references to the x and y ordinate array, a reference to the 2nd derivatives (calculated using B, the low index of the interval in which to interpolate and the x ordinate in that interval. Returned is the interpolated y ordinate. Two functions are provided to look up the appropriate index in the array of x data. For random calls B can be used - give a reference to the x ordinates and the x loopup value it returns the low index of the interval in the data in which the value lies. Where the lookups are strictly in ascending sequence (e.g. if interpolating to produce a higher resolution data set to draw a curve) the B function may more efficiently be used. It performs like B, but requires a third argument being the previous index value, which is incremented if necessary. =head1 NOTE requires Math::Derivative module =head1 EXAMPLE require Math::Spline; my @x=(1,3,8,10); my @y=(1,2,3,4); $spline = Math::Spline->new(\@x,\@y); print $spline->evaluate(5)."\n"; produces the output 2.44 =head1 HISTORY $Log: Spline.pm,v $ Revision 1.1 1995/12/26 17:28:17 willijar Initial revision =head1 BUGS Bug reports or constructive comments are welcome. =head1 AUTHOR John A.R. Williams =head1 SEE ALSO "Numerical Recipies: The Art of Scientific Computing" W.H. Press, B.P. Flannery, S.A. Teukolsky, W.T. Vetterling. Cambridge University Press. ISBN 0 521 30811 9. =cut t000755000000000000 012145176423 14274 5ustar00unknownunknown000000000000Math-Spline-0.0200-load.t000644000000000000 23012145122724 15722 0ustar00unknownunknown000000000000Math-Spline-0.02/t#!perl use Test::More tests => 1; BEGIN { use_ok( 'Math::Spline' ); } diag( "Testing Math::Spline $Math::Spline::VERSION, Perl $], $^X" ); 01-work.t000644000000000000 32312145173467 16003 0ustar00unknownunknown000000000000Math-Spline-0.02/t#!perl use Test::More tests => 1; use Math::Spline; my @x = (1,2,3); my @y = (1,2,3); my $x = 1.5; my $spline = Math::Spline->new(\@x,\@y); my $y_interp=$spline->evaluate($x); ok(defined($y_interp));