[Fortran] 纯文本查看 复制代码
Module MeshDistribution_Mod
Implicit None
contains
Function MeshDistribution( r )
Real , Intent( IN ) :: r(:,:)
Real :: MeshDistribution(size(r,dim=1)+1,size(r,dim=2)+1)
Integer :: n , m , i , j
MeshDistribution = 0.0
n = size(r,dim=1)+1
m = size(r,dim=2)+1
MeshDistribution( 1 , 1 ) = r(1,1)
MeshDistribution( 1 , m ) = r(1,m-1)
MeshDistribution( n , 1 ) = r(n-1,1)
MeshDistribution( n , m ) = r(n-1,m-1)
Do i = 2 , n-1
MeshDistribution( i , 1 ) = sum(r(i-1:i,1))/2.0
Do j = 2 , m-1
MeshDistribution( i , j ) = sum(r(i-1:i,j-1:j))/4.0
End Do
MeshDistribution( i , m ) = sum(r(i-1:i,m-1))/2.0
End Do
Do j = 2 , m-1
MeshDistribution( 1 , j ) = sum(r(1,j-1:j))/2.0
MeshDistribution( n , j ) = sum(r(n-1,j-1:j))/2.0
End Do
End Function MeshDistribution
End Module MeshDistribution_Mod
Program www_fcode_cn
Use MeshDistribution_Mod
Implicit None
real :: v(4,3) = reshape( (/ &
3,5,6,0, &
8,3,5,4, &
8,6,8,1 /) , (/4,3/) )
write(*,'(4(5f5.2,/))') MeshDistribution( v )
End Program www_fcode_cn