matlab_ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDhiYTg2NGZjYWVjOGZkZTdkMmVlM2NjNGRmNjMwNzE4MjhmYzFmMQ==
5
+ data.tar.gz: !binary |-
6
+ NGI4Nzg0OTZjMzcyNmZmMTZhZDJjYzA2OGE5ZTBjODQxMTlkZTY2NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2EzZmMxYjNmODkxYzJlMzA1ZDM4NDBlNzQ5NTYyMWRmNWNmOGM1NTgxOGFi
10
+ Mzk5MTllNWI5MDBiYTBiMDc2ZDUyMWMyYWQ1NmViYmNlMzIyZGM0NTZiYTZl
11
+ NWY4NWYwODZjMTVjODU2NTE5MzIwZjRmNTg4YjYyYmFkOWE0MmM=
12
+ data.tar.gz: !binary |-
13
+ NjRlYzA2NzE4ZjNkNDZlYjYyNTI2OTliNDc2NmJkODQ0YTcxNmM4ZGUwM2I3
14
+ YWVmNmEzODFlZjJkYzcyOWU2ZjA5MDdlMWE1ZjY4NjVmOTJmMjA1OGMyY2U5
15
+ NWFjYTdhYTlmZTA5MWZjOTE2YjFjOWY4OGUxYWE4YzQ0ZjA1MTM=
data/.env.test ADDED
@@ -0,0 +1 @@
1
+ MATLAB_RUBY_LIBS_PATH=/usr/local/MATLAB/R2014a/bin/glnxa64
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ examples.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ matlab_ruby
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p547
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in matlab_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Panayotis Matsinopoulos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # MatlabRuby #
2
+
3
+ This is a Ruby interface to the [MATLAB Engine API](http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html)
4
+ and to the [C/C++ Matrix Library API](http://www.mathworks.com/help/matlab/cc-mx-matrix-library.html).
5
+
6
+ MATLAB needs to be installed and you need to know where the dynamically loaded library files are located. For example, in my installation (Ubuntu 14.04)
7
+ MATLAB dlls are installed here: `/usr/local/MATLAB/R2014a/bin/glnxa64`
8
+
9
+ ## Installation ##
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'matlab_ruby'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install matlab_ruby
24
+
25
+ ## Usage ##
26
+
27
+ Open the file `lib/matlab_ruby.rb` to see which functions of the APIs are interfaced via this gem. Not all functions are ready.
28
+
29
+ ### Initialize ###
30
+
31
+ First you need to initialize the interface to the API implementations.
32
+ Call `.initialize` and give the path to the MATLAB libs directory:
33
+
34
+ ```
35
+ MatlabRuby.initialize('/usr/local/MATLAB/R2014a/bin/glnxa64')
36
+ ```
37
+
38
+ ### Start Engine ###
39
+
40
+ Then you need to start the MATLAB engine.
41
+
42
+ ```
43
+ matlab_engine = MatlabRuby.startEngine
44
+ ```
45
+
46
+ ### Call API Functions ###
47
+
48
+ And now you are ready to call API functions.
49
+
50
+ Example:
51
+ ```
52
+ MatlabRuby.engEvalString matlab_engine, "x = 5;"
53
+
54
+ x_var = MatlabRuby.engGetVariable matlab_engine, "x"
55
+
56
+ x_value = MatlabRuby.mxGetScalar(x_var)
57
+
58
+ MatlabRuby.engEvalString(matlab_engine, "clearvars x;")
59
+
60
+ puts "Value of 'x' is #{x_value}" # this should print out 5.0
61
+ ```
62
+
63
+ ## Tests ##
64
+
65
+ In order to run the tests of this gem, you need to have the MATLAB engine installed and you need to have
66
+ MATLAB_RUBY_LIBS_PATH environment variable set to the correct path to the MATLAB libs. You can do that inside the ".env.test" file
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/matlab_ruby. This project is intended to be a safe, welcoming space for collaboration,
71
+ and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
72
+
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
77
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "matlab_ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ require "matlab_ruby/version"
2
+ require "ffi"
3
+
4
+ module MatlabRuby
5
+ extend FFI::Library
6
+
7
+ # This initializes with the directory of the matlab dynamically linked libraries
8
+ # E.g. /usr/local/MATLAB/R2014a/bin/glnxa64
9
+ #
10
+ def self.initialize(matlab_dll_dir = ENV['MATLAB_RUBY_LIBS_PATH'])
11
+ ffi_lib "#{matlab_dll_dir}/libeng.so"
12
+ attach_function :engOpen, [:string], :pointer
13
+ attach_function :engClose, [:pointer], :int
14
+ attach_function :engPutVariable, [:pointer, :string, :pointer ], :int
15
+ attach_function :engGetVariable, [:pointer, :string], :pointer
16
+ attach_function :engEvalString, [:pointer, :string ], :int
17
+
18
+ ffi_lib "#{matlab_dll_dir}/libmx.so"
19
+ attach_function :mxGetNumberOfFields, [:pointer], :int
20
+
21
+ attach_function :mxGetScalar, [:pointer], :double
22
+
23
+ attach_function :mxCreateDoubleMatrix, [:int, :int, :int], :pointer
24
+ attach_function :mxDestroyArray, [:pointer], :void
25
+ attach_function :mxGetClassName, [:pointer], :string
26
+
27
+ ffi_lib FFI::Library::LIBC
28
+ attach_function :malloc, [:size_t], :pointer
29
+ attach_function :free, [:pointer], :void
30
+ end
31
+
32
+ def self.start_engine
33
+ engOpen "matlab -nosplash -nodisplay -nojvm"
34
+ end
35
+
36
+ def self.stop_engine(engine_ref)
37
+ engClose engine_ref
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module MatlabRuby
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'matlab_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "matlab_ruby"
8
+ spec.version = MatlabRuby::VERSION
9
+ spec.authors = ["Panayotis Matsinopoulos"]
10
+ spec.email = ["panayotis@matsinopoulos.gr"]
11
+
12
+ spec.summary = "A Ruby interface to MATLAB Engine API."
13
+ spec.description =<<-SHORT_DESCRIPTION
14
+ This gem allows you to build a MATLAB Engine Application, a.k.a. a Ruby application that embeds a MATLAB Engine. This is all done by interfacing the MATLAB Engine API.
15
+ You can read more about the MATLAB Engine API here: http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html.
16
+ SHORT_DESCRIPTION
17
+ spec.homepage = "https://github.com/pmatsinopoulos"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency "ffi", "1.9.10"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "dotenv", "2.0.2"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matlab_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Panayotis Matsinopoulos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ! 'This gem allows you to build a MATLAB Engine Application, a.k.a. a
84
+ Ruby application that embeds a MATLAB Engine. This is all done by interfacing the
85
+ MATLAB Engine API.
86
+
87
+ You can read more about the MATLAB Engine API here: http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html.
88
+
89
+ '
90
+ email:
91
+ - panayotis@matsinopoulos.gr
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - .env.test
97
+ - .gitignore
98
+ - .rspec
99
+ - .ruby-gemset
100
+ - .ruby-version
101
+ - .travis.yml
102
+ - CODE_OF_CONDUCT.md
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/console
108
+ - bin/setup
109
+ - lib/matlab_ruby.rb
110
+ - lib/matlab_ruby/version.rb
111
+ - matlab_ruby.gemspec
112
+ homepage: https://github.com/pmatsinopoulos
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.2.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: A Ruby interface to MATLAB Engine API.
136
+ test_files: []