Fortran: Difference between revisions

Jump to navigation Jump to search
447 bytes added ,  13 July 2020
Add description about the data file.
(Add description about the data file.)
 
Line 1: Line 1:
This page describes an example of how to call liboctave functions from a Fortran program.
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,
In the example we will load a single matrix, stored in ASCII format, from a data file.
it consists of two steps:
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 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
# write Fortran code using the "iso_c_binding" intrinsic module to call the C++ function
 
=== Data file ===
 
{{File|data.txt|<syntaxhighlight lang="text">
1.59797350e-01 5.41307474e-01 1.12127655e-01 2.09249248e-01
3.22564589e-01 7.94307947e-01 8.25924316e-01 5.38352076e-01
3.63990736e-01 1.90371212e-02 2.89370865e-01 1.30131246e-01
6.28360462e-01 1.98831330e-01 6.89539723e-01 6.91062597e-01
</syntaxhighlight>}}
 
The file was generated with
 
<syntaxhighlight lang="octave">
A = rand (4);
save -ascii data.txt A
</syntaxhighlight>


=== C++ function ===
=== C++ function ===

Navigation menu