Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive in Fortran 77 1

Status
Not open for further replies.

miki2012

Programmer
Oct 10, 2012
3
CA
Hello Guys,

Actually, I am not a Fortran ceder, but, since in our group there was code that I have to work on it, I switched to Fortran 77.
In part of my coding I tried to use a very simple recursive task that Fortran did not let me. This part of code is as follows and I do not know how to solve it.0

Code:
do j=n,1,-1
    cc(j)=p(j)*cc(j+1)+q(j)
enddo

The variables p and q are previously calculated and cc has n+1 members. Could anyone help me to get rid of this headache.
Any suggestion will really be appreciated.
Thanks in advance
Miki
 
What error do you get? Doesn't it compile? Or doesn't it give the desired result?
Did you initialise cc(n+1)?
Check you bounds on c when you allocate the array REAL :: cc(n+1) and not REAL :: cc(n) for example
 
Hello,
Thank you for your reply. In fact, it does not even get compiled. I use gfortran 7 in code block and cc variable is initialized before and its size is also much larger than n.
Best,
Miki
 
Well, the error doesn't seem to be caused by this loop. I would isolate it and test it in a separate code.
 
No, the code looks perfectly okay to me. As long as n > 1 before the loop starts, that is.

If gfrotran fails to compile it should issue an errormessage. Let us have this together with your code - enclosed in code-tags - and we will see what can be done.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
I appreciate you for your replies.

The code is very large and has many different subroutines. The only problem seems to be related to this subroutine, because without calling this subroutine every thing works fine. The whole subroutine is as:

Code:
      subroutine TDMA()
      implicit real*8(a-h,o-z)
      common /vdc/ aa(150),bb(150),cc(150),dd(150),gg(150)
     1hha,hhc,cssold(220,150),css(220,150),utz(221),
     &dsold(220,150),ds(220,150),time,nnj,lims
      dimension p(0:150),q(0:150)
c
c     Forward Elimination
c
      do j=1,nnj
         denom=bb(j)+aa(j)*p(j-1)
         p(j)=-dd(j)/denom
         q(j)=(gg(j)-aa(j)*q(j-1))/denom
      enddo
c
c     Back Substitution
c
      do j=nnj,1,-1
         cc(j)=p(j)*cc(j+1)+q(j)
      enddo
c
      return
      end

and the generated error is

code::blocks said:
Compiling: TDMA.for
C:\Users\inst\Desktop\Code\VSDC_TDMA\TDMA.for:20.72:
common /vdc/ aa(150),bb(150),cc(150),dd(150),gg(150)
1
Error: Syntax error in COMMON statement at (1)
C:\Users\inst\Desktop\Code\VSDC_TDMA\TDMA.for:36.15:
cc(j)=p(j)*cc(j+1)+q(j)
1
Error: Statement function at (1) is recursive
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
 
Hi miki2012

There is a missing comma after gg(150) in the first line of the common statement. It should be:

common /vdc/ aa(150),bb(150),cc(150),dd(150),gg(150),

That explains the syntax error.
The code compiles fine in my Microsoft Fortran Optimizing Compiler Version 5.10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top