Silverfrost Forums

Welcome to our forums

help! problem calling a subroutine

17 Jun 2010 9:58 #6541

I am a relative novice, I am using FTN95 with PLATO. I have a code with multiple subroutines in the same file, but outside the main program. ie, for illustration

PROGRAM

CALL SUBROUTINE A
CALL SUBROUTINE D
CALL SUBROUTINE E
CALL SUBROUTINE C

END PROGRAM

SUBROUTINE A
...
END SUBROUTINE A

SUBROUTINE B
...
END SUBROUTINE B

SUBROUTINE C
...
END SUBROUTINE C

SUBROUTINE D
...
END SUBROUTINE D

SUBROUTINE E
...
END SUBROUTINE E

When I run the code it runs fine for most calls to subroutines (i.e. A, D and E), but on C it returns 'error 426, CHARACTER dummy argument defined to be larger than actual argument'. when i look at the line that the error came up on, it is actually the END SUBROUTINE B, the end statement of another subroutine just before the one that is meant to be called. Furthermore, if I remove the subroutine whose END statement it is reading (as it isn't being used yet) then the error occurs on the END statement of the subroutine preceding that one!

The program is buggy, and was modified just before this happened, but i reverted back to an older version (which didn't have this problem last time it was run) and it now has the same problem.[/code]

18 Jun 2010 12:50 #6542

Post a small example program that will demonstrate the errors that you encountered.

The 'code' that you posted cannot be compiled into a running program, nor does it show the types of subroutine arguments that you described.

18 Jun 2010 11:43 #6544

If you are doing something like:

character*80 a
call sub1(a)
end

subroutine sub1(dummy)
character*100 dummy
len_dummy = 100
end

That would leave the last 20 characters of 'dummy' unfilled by the data in the main program 'a' variable, and would probably be filled by data from any main program data which was defined immediately after the definition of 'a'.

Try using:

character*80 a
call sub1(a)
end

subroutine sub1(dummy)
character*(*) dummy
len_dummy = len(dummy)
end

Regards Ian

21 Jun 2010 1:44 #6552

thanks guys,

mecej4, the code is too long to post here, and the problem doesn't seem to happen on some smaller codes with subroutines I've used.

Ian, thanks for the comment, I will look through to see if i'm doing anything like that.

There are two big things that are confusing me;

  1. the subroutine is called 3 times prior to the error, and runs fine. But if the error is something like that Ian described then that would make sense.

  2. the line that the error report points to in the code is the END SUBROUTINE line of a different subroutine , i.e. not at all to do with the subroutine it claims is causing the error! and the subroutine to which this END statement applies is in no way linked to thesubroutine that is apparently causing the error. Furthermore, in the sourcecode the END statement in question is directly above the subroutine being called, so if i change the order of subroutines in the sourcecode, the error comes up for whichever END statement directly precedes the problem subroutine (even if it is the END PROGRAM statement)

In other possibly related matter, I thought I'd go back to the original version of the code to see if I could retrace my steps and now PLATO gives an 'access violation error' when I try to build! this was not happening previously and i don't see how my code could be causing such a problem during building. Is FTN95 particularly buggy? in other words could it be my compiler? is it worth reinstalling?

Please login to reply.