Search code examples
if-statementfortrando-loops

Using a simple code in Fortran structure ( DO & IF)


I want to use the if (....) then and elseif (....) then in a Do loop. However, I am not sure about the structure and its possibilities. Could anyone please help me with this simple code?

      Do i=0,1000,1
          T(i)=t-(i*TI)
          if (z(i) .EQ. 0.00) then
              z(i+1)=v*T(i)
          elseif (z(i) .EQ. A) then
              z(i+1)=A-v*T(i)
          endif   
          r1=sqrt(x**2+(z-z(i))**2)
          flux(1)=((alpha*p)/(d*pi*r0**2))*exp(-(r1**2/r0**2))
          flux(2)=0 
      end do

Solution

  • You are indexing z and T as arrays like this:

    T(i) z(i)

    but you did not define them as arrays. You must declare their dimension somehow.

    The compiler should complain in some way, saying that you use them as functions in a improper way or some similar related error message.

    After fixing that try to follow the logic of the loop checking that you properly defined the initial values and the other values are computed using the preceding values.


    You should also definitely add IMPLICIT NONE at the top of your subroutine.