|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
liuzhe1213
Joined: 05 Sep 2007 Posts: 1
|
Posted: Fri Sep 07, 2007 4:04 pm Post subject: a problem about subroutine |
|
|
I have the subroutine
SUBROUTINE linmul_sky_vc(cv,disps,svc,kdiag)
!
! This subroutine forms the product of symmetric matrix stored as
! a skyline and a vector.
!
IMPLICIT NONE
INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)
REAL(iwp),INTENT(IN)::cv(,disps(0
REAL(iwp),INTENT(OUT)::svc(0
INTEGER,INTENT(IN)::kdiag(
INTEGER::n,i,j,low,lup,k
REAL(iwp):,zero=0.0_iwp
n=UBOUND(disps,1)
DO i=1,n
x=zero
lup=kdiag(i)
IF(i==1)low=lup
IF(i/=1)low=kdiag(i-1)+1
DO j=low,lup
x=x+cv(j)*disps(i+j-lup)
END DO
svc(i)=x
IF(i==1)CYCLE
lup=lup-1
DO j=low,lup
k=i+j-lup-1
svc(k)=svc(k)+cv(j)*disps(i)
END DO
END DO
WRITE(11,'(2(A,I5))')(" vc matrix")
WRITE(11,'(6E12.4)')svc
RETURN
END SUBROUTINE linmul_sky_vc
but when I call this subroutine, there are some error information, the error is the following:
Run-time Error
*** Error 112, Reference to undefined variable, array element or function result (/UNDEF)
but I define the variables, arrary in the main programme and subroutine. someone can help me to explain how to call the subroutine, the dummy argument and real argument, thanks a lot |
|
Back to top |
|
|
DrTip
Joined: 01 Aug 2006 Posts: 74 Location: Manchester
|
Posted: Sun Sep 09, 2007 8:59 pm Post subject: |
|
|
Hi there
I think your probelm is that you are using automatic arrays in the subroutine arguments
to get this to work you will either need to define the size if the arrays in the subroutine ie expicityly state the size of the arrays
or use a an interface in the calling program
simple example would be
subroutine sub1(cv)
real cv(:)
write (*,*) cv
cv = cv + 1.0
end subroutine
program test
interface
subroutine sub1(cv)
real cv(:)
end subroutine
end interface
real cv(4)
cv = 6.9
call sub1(cv)
write (*,*) cv
end program
writing interfaces is a bit tedious if you are doing it every time you call a subroutine I would suggest that you put the interface in a module and then have a use use the module but this is just my preference.
Carl
ps when submitting code I suggest you disable smilies |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Mon Sep 10, 2007 4:34 am Post subject: |
|
|
I am familiar with the skyline equation solver and I would recommend the first place you look is to check the contents of the index array KDIAG.
Why not first create a simplified routine which lists out the index value for each equation and the value of the diagonal for this equation, to check you have correctly constructed the skyline index.
This is an old fortran style routine, so defining arrays as :-
real*8 disps(*)
integer*4 kdiag(*)
I'm sure the original version had "n" as a subroutine argument. Shouldn't it be the size of svc. ubound(disps) does not look correct. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Mon Sep 10, 2007 8:26 am Post subject: |
|
|
The quick way to find out exactly what is undefined is to step through the code using the integrated debugger. In fact all you need to do is to run the code using the debugger and it will stop at the point of failure and the variables window will show you what is undefined. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|