Editing Fortran

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 90: Line 90:
=== Fortran Code ===
=== Fortran Code ===


Fortran main program to read the plain ASCII matrix with the help of the Octave-C++ function.  The read in matrix is printed to the screen.
{{Code|octave_file_io_example.f90|<syntaxhighlight lang="fortran" style="font-size:13px">
 
{{File|octave_file_io_example.f90|<syntaxhighlight lang="fortran">
program octave_file_io_example
program octave_file_io_example
 
 
   use iso_c_binding
   use iso_c_binding
 
   
   implicit none
   implicit none


   interface
   interface  
     function octave_load (filename, data, numel) bind(c, name="octave_load")
     function octave_load (filename, varname, data, numel) bind(c, name="octave_load")
 
     
       use iso_c_binding
       use iso_c_binding
       implicit none
       implicit none


       integer(c_int) :: octave_load
       integer(c_int) :: octave_load
 
     
       character(kind=c_char), intent(in) :: filename(*)
       character(kind=c_char), intent(in) :: filename(*)
 
      character(kind=c_char), intent(in) :: varname(*)
     
       type(c_ptr), intent(out) :: data
       type(c_ptr), intent(out) :: data
       integer(c_int), intent(out) :: numel
       integer(c_int), intent(out) :: numel
 
     
     end function octave_load
     end function octave_load
   end interface
   end interface
 
 
   integer(c_int) :: res
   integer(c_int) :: res  
   type(c_ptr) :: data
   type(c_ptr) :: data
   real(c_double), pointer :: fdata(:)
   real(c_double), pointer :: fdata(:)
   integer(c_int) :: numel
   integer(c_int) :: numel


   res = octave_load (c_char_'data.txt' // c_null_char, data, numel)
   res = octave_load (c_char_'pippo.octxt' // c_null_char, c_char_'A' // c_null_char, data, numel)
 
 
   call c_f_pointer (data, fdata, (/numel/))
   call c_f_pointer (data, fdata, (/numel/))
 
 
   write (*,*) fdata
   write (*,*) fdata


end program octave_file_io_example
end program octave_file_io_example
</syntaxhighlight>}}
</syntaxhighlight>}}


=== Compiling the code ===
=== Compiling the code ===
Please note that all contributions to Octave may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Octave:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: