Fortran modules and C++ with Eigen

天大地大妈咪最大 提交于 2020-01-06 23:46:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!