 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Ronan
Joined: 27 Jun 2007 Posts: 19
|
Posted: Sat Aug 08, 2009 7:05 pm Post subject: Procedure argument assignment |
|
|
Dear community members,
I'm experiencing a difficulty with one-dim array passed in procedure as argument.
Even though I have allocated the memory and set each element in array to zero
, while debugging compiler raises the exception "Error 112, reference to
undefined variable array element or function result". I'm sure that each element in
array is initialzed and nullified properly before passing it, but in passed procedure
the elements of array is still "undefined"? Generally the compiler should deal with it
depending of the prefix of agrument is "IN", "OUT" or "INOUT".
THE BODY OF PROGRAM
////////
Code: | INTEGER,ALLOCATABLE::kdiag(:)
! Code omitted here
ALLOCATE(kdiag(neq),loads(0:neq))
! Code omitted here
kdiag=0.0 ! HERE THE ARRAY ELEMENTS ARE NULLIFIED
elements_1: DO iel=1,nels
num=g_num(:,iel)
CALL num_to_g(num,nf,g)
g_g(:,iel)=g
CALL fkdiag(kdiag,g)
END DO elements_1 |
The implementation of "fkdiag" is :
Code: | SUBROUTINE fkdiag(kdiag,g)
IMPLICIT NONE
INTEGER,INTENT(IN)::g(:)
INTEGER,INTENT(OUT)::kdiag(:)
INTEGER::idof,i,iwp1,j,im,k
kdiag = 0.0
idof=SIZE(g)
DO i=1,idof
iwp1=1
IF(g(i)/=0)THEN
DO j=1,idof
IF(g(j)/=0)THEN
im=g(i)-g(j)+1
IF(im>iwp1)iwp1=im
END IF
END DO
k=g(i)
IF(iwp1>kdiag(k))kdiag(k)=iwp1
END IF
END DO
RETURN
END SUBROUTINE fkdiag |
Any help in advance will be appreciated.
Regards, |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sun Aug 09, 2009 7:43 am Post subject: |
|
|
I suspect that you will need to use an INTERFACE for fkdiag in the code where it is called. |
|
Back to top |
|
 |
Ronan
Joined: 27 Jun 2007 Posts: 19
|
Posted: Sun Aug 09, 2009 9:09 am Post subject: Procedure argument assignment |
|
|
Quote: | I suspect that you will need to use an INTERFACE for fkdiag in the code where it is called. |
I couldn't understand that and sorry for not being clear to express the situtation. Actullay each core-code snippet (e.g. fkdiag, in that case) resides in seperate file and they are bundled together in an interfaced module, which is compiled/build as Fortran library "module.lib" and later added as reference in main program. If that's what you mean with "INTERFACE' I've already used it ?
Regards, |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sun Aug 09, 2009 2:50 pm Post subject: |
|
|
I am suggesting that in your main program should include
Code: | INTERFACE
SUBROUTINE fkdiag(kdiag,g)
INTEGER,INTENT(IN)::g(:)
INTEGER,INTENT(OUT)::kdiag(:)
END SUBROUTINE fkdiag
END INTERFACE |
unless fkdiag is defined in a MODULE and your main program has a corresponding USE statement. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Mon Aug 10, 2009 2:17 am Post subject: |
|
|
From my impression of your code, you have kdiag being updated for each element, but also initialised for each element call.
In subroutine FKDIAG, shouldn't you have
INTEGER,INTENT(INOUT)::kdiag(
and also not initialise kdiag to zero for each call.
(also initialise with "kdiag = 0" rather than 0.0 which is a real) |
|
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
|