fortran和Java学_Fortran模块和全局变量
您可以將模塊假定為PRIVATE或假定為PUBLIC . 我將展示PRIVATE .
module DataTypeModule
implicit none
PRIVATE !
type :: DatCube_Struct
integer :: nGrid
double precision, allocatable, DIMENSION(:) :: tgrid
end type DatCube_Struct
!PUBLIC DatCube_Struct !(Only needs to be public if you want to use it in separate from DataCube)
type(DatCube_Struct), DIMENSION(4) , PUBLIC :: DataCube !
double precision, DIMENSION(:,:), ALLOCATABLE, PUBLIC :: tgrd !
!! PUBLIC DataArraySizes, DataTGrd !
PUBLIC ConstructDataCube !
!%%%%%%%%%%%%%%
contains
!%%%%%%%%%%%%%%
!%%%%%%%%%%%%%%
!! subroutine DataArraySizes(NGrd)
subroutine DataArraySizes
implicit none
!!--> integer, intent(out) :: NGrd(4)
open(unit=15, file='./Data/DataHeader.txt', status='old')
read(15,*) NGrd(1)
read(15,*) NGrd(2)
read(15,*) NGrd(3)
read(15,*) NGrd(4)
close(15)
RETURN
end subroutine DataArraySizes
!%%%%%%%%%%%%%%
subroutine DataTGrd(i)
implicit none
integer, intent(in) :: i !
!! double precision, intent(out) :: tgrd(i) !--> (NGrd(1))
open(unit=16, file='./Data/tgrid.dat', status='old')
read(16,*) DataCube(I)%tgrid(:) !
close(16)
RETURN
end subroutine DataTGrd
!%%%%%%%%%%%%%%
subroutine ConstructDataCube() !--> (DataCube)
implicit none
!!--> type(DatCube) , Intent(out) :: DataCube
!!--> integer , allocatable :: NGrd(:)
!!--> double precision, allocatable :: tgrd(:)
!!--> allocate( NGrd(4) )
call DataArraySizes() !!--> (NGrd)
do I = 1, UBOUND(nGrd,1) !
DataCube(I)%NGrid = NGrd(I)
ENDDO !
AlloTGrd: do I = 1, UBOUND(nGrd,1) !
allocate( tgrd(I ,DataCube(I)%tgrid(NGrd(I)) )
call DataTGrd(I)
!!--> DataCube(I)%tgrid = tgrd(I,:)
ENDDO AlloTGrd
!!deallocate( NGrd,tgrd )
RETURN
END subroutine ConstructDataCube
!%%%%%%%%%%%%%%
end module DataTypeModule
!%%%%%%%%%%%%%%
PROGRAM main
USE DatatypeModule
implicit none
double precision, PARAMETER :: arg1 = 1.0D0
double precision, DIMENSION(4) :: out1
!!--> type(DatCube) :: DataCube
call ConstructDataCube(DataCube)
call subrtn1(arg1,out1)
!Why stop ? stop
end PROGRAM main
!%%%%%%%%%%
subroutine subrtn1(arg1,out1)
use DataTypeModule
implicit none
double precision , Intent(in ) :: arg1
double precision, DIMENSION(4), Intent( out) :: out1
!!--> type(DatCube) :: DataCube
out1 = DataCube(Arg1)%NGrid !!
return
end subroutine subrtn1
這個“答案”更多的是給你一些想法,而不是一個權威的編譯“答案” . 由于數據看起來像是要共享的,我將它們放入標記為PUBLIC的MODULE中 .
總結
以上是生活随笔為你收集整理的fortran和Java学_Fortran模块和全局变量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 持久化线程_java –
- 下一篇: java美元兑换,(Java实现) 美元