Sha256: 0eb021723d36c3a1630aac6b6c4c609d8cf076df55f615a156ed02f65e736713

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

require 'global_additions'
require 'default_logger'

# Maintain and run matlab commands and paths.
class MatlabQueue
  include DefaultLogger
  
  attr_accessor :paths, :commands, :ml_command
  attr_reader :success
  
  def initialize
    @paths = []
    @commands = []
    @ml_command = "matlab -nosplash -nodesktop"
    setup_logger unless defined?($Log)
  end
  
  def to_s
    @commands.flatten.join(', ')
  end
  
  def run!
    set_matlabpath
    cmd = @ml_command + " -r \"#{ escape_error(to_s) }, exit\" "
    @success = run(cmd)
  end
  
  def method_missing(m, *args, &block)
    @commands.send(m, *args, &block)
  end
  
  # Add paths that should be available for Matlab scripts.
  def add_to_path(*args)
    args.each { |arg| @paths << arg }
  end
  
  private 
  
  # Ensure all the paths from #MatlabQueue @paths instance var are present. 
  def set_matlabpath
    mlpath = ENV['MATLABPATH'].split(":")
    @paths.flatten.collect { |path| mlpath << path }
    $Log.debug ENV['MATLABPATH'] = mlpath.uniq.join(":")
  end
  
  def escape_error(command)
    "try; #{command}; catch exception; display(getReport(exception)); pause(1); end"
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rpipe-0.1.7 lib/matlab_helpers/matlab_queue.rb
rpipe-0.1.6 lib/matlab_helpers/matlab_queue.rb
rpipe-0.1.4 lib/matlab_helpers/matlab_queue.rb
rpipe-0.1.3 lib/matlab_helpers/matlab_queue.rb
rpipe-0.1.2 lib/matlab_helpers/matlab_queue.rb
rpipe-0.1.1 lib/matlab_helpers/matlab_queue.rb