问题
I am a Fortran user and a complete newbie to C++ and Eigen. I use modules in Fortran to be able to keep my variables, arrays and matrices in different groups and use them as needed. How to implement the idea of modules in Fortran in C++ so that I am able to pass on the data between different subroutines? I cannot paste the entire Fortran code as it is too large and there will be many new concepts which I would like to write directly in C++. Perhaps, a sample snippet or document showing how to pass on the information between C++ routines could be useful. I want to do something like this (and much more) in C++:
!*************************************************************************
! **** module file: module.f95 ****
module global
save
integer, allocatable :: kod(:,:)
end module
module local
save
integer, allocatable :: kode(:)
real*8, allocatable :: func1(:)
integer pts
end module
module fileunits
save
integer,parameter :: file1 = 11, file2 = 12
end module
!*************************************************************************
! Main program
program main
use global
use local
use fileunits
implicit none
int i,j,k,n
open(unit=file1,file='input.dat')
open(unit=file2,file='output.dat')
read(file1, *) n,pts
allocate(kod(n,pts))
allocate(kode(pts), func1(pts))
do I = 1, n
read(file1, *) (kod(i,j),j=1,pts)
do J=1,pts
kode(j) = kode(i,j)
end do
call proc1
write(file2,*) ((func1(j), j =1, pts)
end do
end program
subroutine proc1
use local
implicit none
int j
do j=1,pts
funct1(j) = kode(j) * kode(j)
...
...
end do
end subroutine
来源:https://stackoverflow.com/questions/28050812/fortran-modules-and-c-with-eigen