Difference between revisions of "Matlab Bindings"

From LIBISIS
Jump to navigation Jump to search
 
Line 1: Line 1:
<pre>module IXMm_testclass
+
The main binding to the Libisis framework which has been implemented is matlab. Each type defined in the framework has a module which contains type-specific methods for getting objects and variables from the matlab front-end and sending objects and variables back to the matlab front-end. These methods are called using two interfaces which are defined in a module <tt>IXMm_classname</tt>.
 +
 
 +
* <tt>IXBgetFromBinding</tt>
 +
* <tt>IXBsendToBinding</tt>
 +
 
 +
This module is always defined in the file <tt>bindings/matlab/IXMclassname_m.f90</tt>. As a rule this module always contains the line <tt>use IXMclassname</tt> (it is however included automatically and does not need to be explicitly specified in the code)
 +
 
 +
The interfaces and methods of the <tt>IXMm_classname</tt> module are generated automatically using the preprocessor, in the following example for the <tt>IXTtestclass</tt> object in the <tt>IXMtestclass_m.f90</tt> file. These are the '''only''' statements required to define the <tt>IXMm_testclass</tt> module.
 +
 
 +
<pre>
 +
module IXMm_testclass
  
 
#define IXD_TYPE testclass
 
#define IXD_TYPE testclass
Line 10: Line 20:
  
 
end module IXMm_testclass
 
end module IXMm_testclass
 +
</pre>
 +
 +
 +
 +
 +
 +
  
 
#define IXD_TYPE testclass
 
#define IXD_TYPE testclass
Line 17: Line 34:
 
   subroutine IXBplus_Testclass(nlhs, plhs, nrhs, prhs, status)
 
   subroutine IXBplus_Testclass(nlhs, plhs, nrhs, prhs, status)
 
     use IXMm_testclass
 
     use IXMm_testclass
use IXMmatlab_interface
+
    use IXMmatlab_interface
  implicit none
+
    implicit none
integer :: nlhs, nrhs
+
    integer :: nlhs, nrhs
integer(cpointer_t) :: plhs(nlhs), prhs(nrhs)
+
    integer(cpointer_t) :: plhs(nlhs), prhs(nrhs)
type (IXTtestclass) :: wres, w1, w2
+
    type (IXTtestclass) :: wres, w1, w2
type(IXTstatus) :: status
+
    type(IXTstatus) :: status
 
! read in two structures which will be added together
 
! read in two structures which will be added together
 
! wres has been created empty with type statement
 
! wres has been created empty with type statement
Line 28: Line 45:
 
     call IXBgetFromBinding(prhs(3),' ', 1, 0, w2, status)
 
     call IXBgetFromBinding(prhs(3),' ', 1, 0, w2, status)
 
! check read went OK - report errors and return if not
 
! check read went OK - report errors and return if not
if (status == IXCseverity_error) return
+
    if (status == IXCseverity_error) return
 
! do adding operation
 
! do adding operation
call IXFplus_testclass(wres, w1, w2, status)
+
    call IXFplus_testclass(wres, w1, w2, status)
 
! wres has now been filled and needs to be entered into the matlab memory
 
! wres has now been filled and needs to be entered into the matlab memory
 
     if (status == IXCseverity_error) then
 
     if (status == IXCseverity_error) then

Revision as of 12:58, 15 May 2008

The main binding to the Libisis framework which has been implemented is matlab. Each type defined in the framework has a module which contains type-specific methods for getting objects and variables from the matlab front-end and sending objects and variables back to the matlab front-end. These methods are called using two interfaces which are defined in a module IXMm_classname.

  • IXBgetFromBinding
  • IXBsendToBinding

This module is always defined in the file bindings/matlab/IXMclassname_m.f90. As a rule this module always contains the line use IXMclassname (it is however included automatically and does not need to be explicitly specified in the code)

The interfaces and methods of the IXMm_classname module are generated automatically using the preprocessor, in the following example for the IXTtestclass object in the IXMtestclass_m.f90 file. These are the only statements required to define the IXMm_testclass module.

module IXMm_testclass

#define IXD_TYPE testclass
#include "bindings_header.f90"

contains

#define IXD_TYPE testclass
#include "bindings_base.f90"

end module IXMm_testclass




  1. define IXD_TYPE testclass
  2. include "bindings_extra.f90"


 subroutine IXBplus_Testclass(nlhs, plhs, nrhs, prhs, status)
   use IXMm_testclass
   use IXMmatlab_interface
   implicit none
   integer :: nlhs, nrhs
   integer(cpointer_t) :: plhs(nlhs), prhs(nrhs)
   type (IXTtestclass) :: wres, w1, w2
   type(IXTstatus) :: status

! read in two structures which will be added together ! wres has been created empty with type statement

   call IXBgetFromBinding(prhs(2),' ', 1, 0, w1, status)
   call IXBgetFromBinding(prhs(3),' ', 1, 0, w2, status)

! check read went OK - report errors and return if not

   if (status == IXCseverity_error) return

! do adding operation

   call IXFplus_testclass(wres, w1, w2, status)

! wres has now been filled and needs to be entered into the matlab memory

   if (status == IXCseverity_error) then
       plhs(1)=ixDuplicateArray(prhs(1))
   else
       call IXBsendToBinding(plhs(1), prhs(1), ' ', 1, 0, wres, status)
   endif
 end subroutine