Jump to content

Recommended Posts

Posted

I have recently started FORTRAN to learn Can any body explain, what these lines of code written in FORTRAN are doing...

 

 

!USE MSFLIB
use IFPORT
implicit none
integer nmax,i,m,v,c,j,d
parameter(nmax=50)
real*8 h,x(2),y(2),f(2),r1(2),r2(2),t
real*8 r3(2),r4(2),pi,tmax,ti,lam,k
character*20 data1
real*4 r,rr,z(nmax),p(nmax)
c Initial Values
!k=20
pi=4d0*atan(1d0)
do 200 j=1,nmax
z(j)=28*RAND()
!write(*,*) z(j) !50
p(j)=10*RAND() !10
200 continue
do 100 m=1,nmax
c=0
d=0
x(1)=z(m)
x(2)=p(m)
write(*,*) m, x(1),x(2)
tmax=1000*pi
h=pi/10000
k=0.5d0 !1.00026
v=4.0d0 !15.03
lam=0.90d0
c Oppening the Data File and Writting the Data in:
write(data1, '("a16.dat",i2.2)' )
open(11,file=data1,status='unknown')
close(11)
c**********************************************************************
do 10 ti=0,tmax,h
do 20 i=1,2
y(i)=x(i)
20 continue
t=ti
f(1)=x(2)
f(2)=-1d0+k*v*exp(-k*(x(1)-lam*sin(t)))
do 30 i=1,2
r1(i)=f(i)*h
x(i)=y(i)+r1(i)/2
30 continue
t=ti+h/2
Posted

All those lines?

 

Do you first understand that in Fortran you must 'declare the variables' and it is usual to collect all these together at the start for convenience?

 

So lines up to the starred lines are just declarations.

 

or

 

Are you asking about the subsequent do loops ?

 

If so what do you not understand about them?

Posted

Actually i wana know what are do loops doing..... their dry run is my need???

I am not getting are they nested loops or simple do loops??

please explain what function they are performing??

Posted

Here's a hint:

Start by asking yourself, if you understand the syntax required for an ordinary, non-nested loop?

 

Simple Non-nested loop example:

do 10 i = 1, 5
     i = i + 1
10 continue
If you understand the syntax for a non-nested loop, then you can move on to understanding nested loop syntax. 

Simple nested loop example (loop 20 is nested within loop 10):

do 10 i = 1, 5
     do 20 j = 1, 2
          j = j + 1
    20 continue
    i + i + 1
10 continue

If you understand these syntax, then you should be able to answer your question on your own :)

Posted (edited)
z(j)=28*RAND()
!write(*,*) z(j) !50
please explain these two lines

pi=4d0*atan(1d0)
do 200 j=1,nmax
z(j)=28*RAND()
!write(*,*) z(j) !50
explain please these lines
pi=4d0*atan(1d0)
what is ment by "do"????
Edited by saleha noor
Posted (edited)

what is ment by "do"????

seleha, if you don't know what a do loop is, you don't just need FORTRAN help, but introduction to programming. A do loop is a relatively basic building block that is in most general languages to allow you to repeat execution of lines of code.

 

Answering this question is beyond the scope of what a forum is intended to do.

 

You need to start with an introduction to programming class. Some examples of many: http://www.stat.tamu.edu/~jnewton/604/chap7.pdf http://www.lrsm.upenn.edu/~vitek/courses/f77intro/f77intro.pdf

 

There are many other books and online resources available. Search "introduction to programming" and "introduction to fortran"

Edited by Bignose
Posted

 

z(j)=28*RAND()
!write(*,*) z(j) !50
please explain these two lines

pi=4d0*atan(1d0)
do 200 j=1,nmax
z(j)=28*RAND()
!write(*,*) z(j) !50
explain please these lines
pi=4d0*atan(1d0)
what is ment by "do"????

 

Are you asking about do (as in do loop) or about d0 (which I believe is related to number type)?

Posted (edited)

Are you asking about do (as in do loop) or about d0 (which I believe is related to number type)?

Yeah. In fortran d makes the number a double instead of a single precision number. If you use e in exponential notation, the number is a single.

Edited by Bignose

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.