saleha noor Posted September 19, 2014 Posted September 19, 2014 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
studiot Posted September 19, 2014 Posted September 19, 2014 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?
saleha noor Posted September 19, 2014 Author Posted September 19, 2014 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??
Curiatron Posted September 19, 2014 Posted September 19, 2014 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
saleha noor Posted September 19, 2014 Author Posted September 19, 2014 (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 September 19, 2014 by saleha noor
Bignose Posted September 20, 2014 Posted September 20, 2014 (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 September 20, 2014 by Bignose
mathematic Posted September 20, 2014 Posted September 20, 2014 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)?
Bignose Posted September 21, 2014 Posted September 21, 2014 (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 September 21, 2014 by Bignose
saleha noor Posted September 24, 2014 Author Posted September 24, 2014 pi=4d0*atan(1d0) i am asking about this "1d0"??? i am not asking about do loop ..
Strange Posted September 24, 2014 Posted September 24, 2014 pi=4d0*atan(1d0) i am asking about this "1d0"??? i am not asking about do loop .. From: http://math.hawaii.edu/wordpress/fortran-3/#double Double precision numbers are written in scientific notation but with D usurping the role of E. And: http://stackoverflow.com/questions/8434820/what-does-mean-10-d00-in-fortran
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now