Math::Matlab - An abstract base class for a simple Matlab API.


Math-Matlab documentation Contained in the Math-Matlab distribution.

Index


Code Index:

NAME

Top

Math::Matlab - An abstract base class for a simple Matlab API.

SYNOPSIS

Top

  If MyMatlab is a sub-class of Math::Matlab ...

  use MyMatlab;
  $matlab = MyMatlab->new( { %args } );

  my $code = q/fprintf( 'Hello world!\n' );/
  if ( $matlab->execute($code) ) {
      print $matlab->fetch_result;
  } else {
      print $matlab->err_msg;
  }

DESCRIPTION

Top

Math::Matlab is an abstract class for a simple interface to Matlab, a mathematical computation package from The MathWorks (for more info on Matlab, see http://www.mathworks.com/).

METHODS

Top

Public Object Methods

execute
 $success = $matlab->execute($matlab_code, @args)

An abstract method which executes the Matlab code passed in the first argument and returns true if successful. The handling of any additional arguments are determined by the implementing sub-class. The output of the Matlab code is stored in the object to be retreived by one of the following 4 methods. The Matlab code must print all output to STDOUT.

get_result
 $str = $matlab->get_result
 $str = $matlab->get_result( $str )

Returns the Matlab output after stripping the extra junk.

fetch_result
 $str = $matlab->fetch_result
 $str = $matlab->fetch_result( $str )

Returns the Matlab output after stripping the extra junk, then deletes it from memory.

get_raw_result
 $str = $matlab->get_raw_result
 $str = $matlab->get_raw_result( $str )

Returns the Matlab output in raw form. Can be helpful for debugging errors.

fetch_raw_result
 $str = $matlab->fetch_raw_result
 $str = $matlab->fetch_raw_result( $str )

Returns the Matlab output in raw form, then deletes it from memory. Can be helpful for debugging errors.

err_msg
 $str = $matlab->err_msg
 $str = $matlab->err_msg( $str )

Returns the most recent error message. Or sets the message to be returned.

Private Object Methods

_getset
 $value = $object->_getset($field)          ## get a field's value
 $value = $object->_getset($field, $value)  ## set a field's value

A utility method used to get or set a field in the object.

COPYRIGHT

Top

AUTHOR

Top

  Ray Zimmerman, <rz10@cornell.edu>

SEE ALSO

Top

  perl(1), Math::Matlab::Local, Math::Matlab::Remote, Math::Matlab::Server


Math-Matlab documentation Contained in the Math-Matlab distribution.

package Math::Matlab;

use strict;
use vars qw($VERSION $Revision);

BEGIN {
	$VERSION = '0.08';
	$Revision = sprintf "%d.%03d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/;
}

##-----  Public Class Methods  -----
sub new { die "Unable to create instance of abstract class " . __PACKAGE__; };

##-----  Public Object Methods  -----
sub execute { die "Abstract method execute() must be overridden." };
sub err_msg {	my $self = shift; return $self->_getset('err_msg',	@_); }
sub clear_err_msg { return $_[0]->{err_msg} = undef; }

sub get_result {
	my $self = shift;

	my ($result) = $self->{'result'} =~ /-----MATLAB-BEGIN-----\n-----SUCCESS\n(.*)/s;
# 	$result =~ s/EDU>> //g;		##Êremove edu prompts
# 	$result =~ s/>> //g;		## remove normal prompts

	return $result;
}

sub fetch_result {
	my $self	= shift;
	my $result	= $self->get_result;
	
	$self->{'result'} = '';

	return $result;
}

sub get_raw_result { return $_[0]->{'result'}; }

sub fetch_raw_result {
	my $self	= shift;
	my $result	= $self->get_raw_result;
	
	$self->{'result'} = '';

	return $result;
}

##-----  Private Object Methods  -----
sub _getset {
	my ($self, $field, $val) = @_;
	$self->{$field} = $val	if defined($val);
	return $self->{$field};
}

1;
__END__