Fortran: Difference between revisions

Jump to navigation Jump to search
587 bytes added ,  22 March 2014
fix name of fortran file
No edit summary
(fix name of fortran file)
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page describes an example of how to call liboctave functions from a Fortran program.
In the example we will load an Octave array from a file in Octave's native ASCII format,
it consists of two steps:


* write a C++ function with a C compatible interface and C linkage that reads a variable from an Octave ASCII file
* write Fortran code using the "iso_c_binding" intrinsic module to call the C++ function
=== C++ function ===


{{Code|octave_file_io.cc: C++ function to load a matrix from an ASCII file in Octave native format|<syntaxhighlight lang="C" style="font-size:13px">
{{Code|octave_file_io.cc: C++ function to load a matrix from an ASCII file in Octave native format|<syntaxhighlight lang="C" style="font-size:13px">
Line 48: Line 55:
</syntaxhighlight>}}
</syntaxhighlight>}}


=== Header file ===


{{Code|octave_file_io.h: header file with C interface to octave_file_io.cc|<syntaxhighlight lang="C" style="font-size:13px">
{{Code|octave_file_io.h: header file with C interface to octave_file_io.cc|<syntaxhighlight lang="C" style="font-size:13px">
Line 67: Line 76:




Compile the function
=== Fortran Code ===
 
  mkoctfile -I. octave_file_io.cc


{{Code|octave_file_io.cc: C++ function to load a matrix from an ASCII file in Octave native format|<syntaxhighlight lang="C"  
{{Code|octave_file_io_example.f90|<syntaxhighlight lang="fortran" style="font-size:13px">
program octave_file_io_example
program octave_file_io_example
    
    
Line 108: Line 115:
end program octave_file_io_example
end program octave_file_io_example
</syntaxhighlight>}}
</syntaxhighlight>}}
=== Compiling the code ===
  mkoctfile -I. octave_file_io.cc
  mkoctfile -I. --mkoctfile --link-stand-alone octave_file_io_example.f90 octave_file_io.o -o octave_file_io_example
[[Category:Examples]]

Navigation menu