Silverfrost Forums

Welcome to our forums

Procedure argument assignment

8 Aug 2009 6:05 #4883

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 ////////

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 :

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,

9 Aug 2009 6:43 #4884

I suspect that you will need to use an INTERFACE for fkdiag in the code where it is called.

9 Aug 2009 8:09 #4885

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,

9 Aug 2009 1:50 #4886

I am suggesting that in your main program should include

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.

10 Aug 2009 1:17 #4888

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)

Please login to reply.