- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, Im trying to improve SW by modules. However, there are some issues which I dont understand well.
It says an error like in the topic.
Question: is it really necessary to define inside a module an interface while using assumed shape arrays (passing as an argument into subroutine/function)?
the code (there are some errors, but here is important just that arrays passing and solving is also substituted just by copying):
program main
use variables
use routines
implicit none
integer :: tellme, input
input= 2
allocate(A(input,input),x(input),b(input))
A= fillMatrixA(input)
b= fillVectorb(input)
tellme= solveLinSystem(input)
write(*,*) 'tellme ',tellme
end program main
module routines
use variables
implicit none
contains
c Function for filling matrix A
function fillMatrixA(n)
integer (kind=4) n, i, j
real (kind=8) fillMatrixA(:,:)
allocate(fillMatrixA(n,n))
do i=1,n
do j=1,n
if (i.eq.j) then
fillMatrixA(i,j)=1.d0
else
fillMatrixA(i,j)=0.d0
endif
end do
end do
end function fillMatrixA
c Function for filling vector b
function fillVectorb(n)
integer (kind=4) n, i
real (kind=8) fillVectorb(:)
allocate(fillMatrixA(n,n))
do i=1,n
fillVectorb(i)=1.d0
end do
end function fillVectorb
c Function for solving linear system of equations
function solveLinSystem(A,b,n)
real (kind=8) :: A(:,:), b(:)
integer (kind=4) n
real (kind=8), allocatable :: solveLinSystem(:)
allocate(solveLinSystem(n))
solveLinSystem= b
end function solveLinSystem
end module routines
And to finish this - error from compiler:
-bash-4.1$ make -f run.mk newrun
ifort -c variables.for
ifort -c routines.for
routines.for(12): error #6689: An assumed-shape array must be declared as a dummy argument. [FILLMATRIXA]
real (kind=8) fillMatrixA(:,:)
--------------------^
routines.for(33): error #6689: An assumed-shape array must be declared as a dummy argument. [FILLVECTORB]
real (kind=8) fillVectorb(:)
--------------------^
routines.for(14): error #6724: An allocate/deallocate object must have the ALLOCATABLE or POINTER attribute. [FILLMATRIXA]
allocate(fillMatrixA(n,n))
---------------^
routines.for(10): error #6688: The array-spec for a function name with no POINTER attribute must be an explicit shape array (R505.9). [FILLMATRIXA]
function fillMatrixA(n)
---------------^
routines.for(35): error #6423: This name has already been used as an external function name. [FILLMATRIXA]
allocate(fillMatrixA(n,n))
---------------^
routines.for(31): error #6688: The array-spec for a function name with no POINTER attribute must be an explicit shape array (R505.9). [FILLVECTORB]
function fillVectorb(n)
---------------^
compilation aborted for routines.for (code 1)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For example, replace
[fortran]real (kind=8) fillMatrixA(:,:) [/fortran] by
[bash]real (kind=8), allocatable :: fillMatrixA(:,:) [/bash]

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page