Re: some confusing in subroutine
From: David Ham (D.A.Ham_at_CiTG.TUDelft.nl)
Date: 10/27/03
- Next message: Dr Ivan D. Reid: "Re: some confusing in subroutine"
- Previous message: Gordon Sande: "Re: some confusing in subroutine"
- In reply to: Zhang yunfeng: "some confusing in subroutine"
- Next in thread: Ron Shepard: "Re: some confusing in subroutine"
- Reply: Ron Shepard: "Re: some confusing in subroutine"
- Reply: Richard Maine: "Re: some confusing in subroutine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Oct 2003 15:30:45 +0100
"Zhang yunfeng" <zyf_sz@hit.edu.cn> writes:
> hi, all.
> here's a subroutine, although "goto" is used, but the structure is clear.
> what i confused is the array "A,B,C" is declared only one element. why in
> the next, the array A,B,C is used like they has more than one element?
> it 's said that the code is written in FORTRAN IV. and could compiled with
> NDP-FORTRAN. is the code correct in Fortran IV?
> appreciate for your advice
>
>
> SUBROUTINE SHTADV (A,B,C,AA,NN,IIND)
> IMPLICIT REAL*8 (A-H,O-Z)
> DIMENSION A(1),B(1),C(1)
> GO TO (5,15,25),IIND
>
> 5 DO 10 I=1,NN
> 10 A(I)=B(I) - C(I)
> RETURN
>
> 15 DO 20 I=1,NN
> 20 A(I)=B(I) + C(I)
> RETURN
>
> 25 DO 30 I=1,NN
> 30 A(I)=A(I) - B(I)*C(I)*AA
> RETURN
> END
This is an ancient and truly hairy kludge to get around the fact that
pre-f77 dialects of Fortran did not allow for variable sized
arguments. The idea, I believe, is that you hope and pray that the
compiler generates a program which passes A by passing the location in
memory of the first entry in A. This is how C does arrays. It's not
remotely legal in any Fortran standard after 1977 (since I was one in
1977 I'll defer to the more ancient denizens of clf as to whether it
was ever legal) and it tends to cause modern compilers with even
primitive bound checking to barf at compile time.
There are (at least) three ways of fixing this:
1. Find a way to switch off bounds checking on your compiler. This is
the easiest if the program is big but it's obviously not portable.
2. Replace the declarations with assumed size arrays:
DIMENSION A(*),B(*),C(*)
This makes the declaration legal f77 (and f90/f95).
3. Replace the declarations with assumed shape arrays:
DIMENSION A(:),B(:),C(:)
This makes the definition legal f90/f95 (but not f77).
Regards,
David
- Next message: Dr Ivan D. Reid: "Re: some confusing in subroutine"
- Previous message: Gordon Sande: "Re: some confusing in subroutine"
- In reply to: Zhang yunfeng: "some confusing in subroutine"
- Next in thread: Ron Shepard: "Re: some confusing in subroutine"
- Reply: Ron Shepard: "Re: some confusing in subroutine"
- Reply: Richard Maine: "Re: some confusing in subroutine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|