Fortran77/90 code integration

Calling Fortran source code

The C++ - Fortran interface is defined in the openfluid/tools/FortranCPP.hpp file. In order to execute Fortran code from a simulation function, this Fortran source code have to be wrapped into a subroutine that will be called from the C++ code of the simulation function. To help programmers to achieve this wrapping operation, the FortranCPP.h file defines macros. These macros allows calls of Fortran77 and Fortran90 source code. You are invited to browse the FortranCPP.h file to get more information about these macros.


Fortran source code (FSubr.f90):

subroutine displayvector(Fsize,vect)

implicit none

integer Fsize,ifrom
real*8 vect(Fsize)

write(*,*) 'size',Fsize
write(*,*) (Vect(i),i=1,Fsize)

return
end


Declaration block int the .cpp file, located just after the function signature (MyFunc.cpp):


Call of the fortran subroutine from the initializeRun method (MyFunc.cpp):

#include <openfluid/tools/FortranCPP.hpp>

bool MyFunction::initializeRun(const openfluid::base::SimulationInfo* SimInfo)
{
  openfluid::core::VectorValue MyVect;
  
  MyVect = openfluid::core::VectorValue(15,9);
  int Size = MyVect->getSize();

  CALL_FSUBROUTINE(toto)(&Size,(MyVect.getData()));

  return true;
}


The compilation and link of fortran source code is automatically done when adding fortran source files to the FUNC_FORTRAN variable in the CMake.in.config file (See Complete example).


Generated using Doxygen 1.7.3
Creative Commons License Creative Commons By-NC-ND license