Fortran77/90 code integration

Calling Fortran source code

The C++ - Fortran interface is defined in the FortranCPP.h file, located in the tool part of the SDK. 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. Youa re 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):

BEGIN_EXTERN_FORTRAN
  EXTERN_FSUBROUTINE(toto)(FINT *Size, FREAL8 *Vect);
END_EXTERN_FORTRAN


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

bool MyFunction::initializeRun(const openfluid::base::SimulationInfo* SimInfo)
{
  openfluid::core::VectorValue* MyVect;
  
  MyVect = new 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.6.3
Creative Commons License Creative Commons By-NC-ND license