Silverfrost Forums

Welcome to our forums

Problem calling a subroutine

27 May 2006 8:06 #692

Hi

Me again. Sorry.

Thanks for the advice thus far. Based on your last reply, I have provided interfaces for my subroutines which are passing 'assumed shape' arrays and also routines with 'optional' statements. These routines are being called successfully but now I've run into another problem.

I am trying to call the following subroutine:

SUBROUTINE fkdiag(kdiag,g)

IMPLICIT NONE INTEGER,INTENT(IN)::g(:) INTEGER,INTENT(OUT)kdiag(:) INTEGERidof,i,iwp1,j,im,k 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

I have provided the following interface for FKDIAG:

INTERFACE FEDOR subroutine fkdiag(kdiag,g) INTEGER,INTENT(IN)::g(:) INTEGER,INTENT(OUT)::kdiag(:) end subroutine END INTERFACE

...and the arguments I'm trying to pass are as follows:

g = (0,1,2,3,0,6) kdiag : This has been allocated for 12 integer entries.

When FKDIAG is called, the following error message appears:

'*** Error 112, Reference to undefined variable, array element or function result (/UNDEF)'

The problematic line in the FKDIAG subroutine is identified as the following:

IF(iwp1>kdiag(k))kdiag(k)=iwp1

This being the case, it seems to be having difficulty with the integer array kdiag(12), even though it has already been declared and allocated.

Can anyone let me know if they know the solution to this problem?

Thanks very much in advance.

Mikhail Kalashnikov

28 May 2006 11:26 #695

Mikhail

I have not tested your code but as well as declaring the array and allocating memory for it, you must provide a value for every element of the array that you use.

29 May 2006 3:21 #696

Yes, I forgot to mention that after the array KDIAG was declared and allocated, and before it was passed into the routine FKDIAG, all entries were set to zero with the following line:

kdiag=0

In light of this, is there any other possible reason why I'm getting this error message?

Mikhail Kalashnikov

29 May 2006 3:33 #697

Maybe kdiag should be INTENT(INOUT).

29 May 2006 3:40 #698

Of course! I should have spotted this.

Thank you very much again!

Mikhail Kalashnikov

Please login to reply.