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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to understand a code 1

Status
Not open for further replies.

Hugo Henris

Programmer
Mar 9, 2019
2
BE
Hello everyone,

I'm a student in Belgium in Mathematics and for my master's thesis, I've to create some Lissajous curves

One of my teachers helps me and send me this code in Fortran! But I don't understand anything, my lesson in Fortran was in a new fortran version and this code is written in an old one.

I have to compile this code with "gfortran Hugo-lissajou.f -o test" in the terminal and generate some figures. But I receive some illegible files like "fort.32" that I can't plot on my laptop


program lissajou
implicit real*8(a-h,m-z)

pi=4.d0*datan(1.d0)
twopi=2.d0*pi

x0=1.d0
y0=1.d0

write(*,*) 'itype, p, q, N, phi0, aphix (*pi = phix) ?'
read(*,*) itype,ip,iq,IN,phi0,aphix

p=ip
q=iq
GN=IN

phix=pi*aphix
phiy=(q*phix-pi*phi0)/p

write(*,*) (q*phix-p*phiy)/pi,phi0

do 800 i=1,IN

IPAS=200
GPAS=IPAS
per=1.0d0
pas = per/GPAS
write(*,*) IPAS,GPAS,Per,pas

do 200 k=0,IPAS
tau=k*pas
if(itype.eq.1) then
t=tau+I/GN
x=x0*dsin(twopi*p*t+phix)
y=y0*dsin(twopi*q*t+phiy)
else
t1=p*tau+I/GN
x=x0*dsin(twopi*t1+phix)
t2=q*tau+I/GN
y=y0*dsin(twopi*t2+phiy)
endif

write(30+i,98) tau,x,y
if(k.eq.0) write(30,98) tau,x,y
98 format(1x,3(f13.9,2x))
200 continue

800 continue

stop
end


Thank you very much and sorry for my English level

Hugo
 
 /Users/Hugo/Desktop/Hugo-lissajou.f
Hi Hugo Henris,

fort.i files are generated in the loops by these write statements
Code:
do 800 i=1,IN
...
...
  do 200 k=0,IPAS
    ...
    ...
    write(30+i,98) tau,x,y
    if(k.eq.0) write(30,98) tau,x,y
    ...
  200 continue

800 continue

So if you enter IN = 10 you will get the files fort.30, fort.31, ..., fort.40
These are normal text files, with 3 columns of numbers.

For example I entered on the input of the program these numbers
Code:
$ ./Hugo-lissajou 
 itype, p, q, N, phi0, aphix (*pi = phix) ?
1 2 3 10 4.5 0 5
and got the files fort.30 ... fort.40, where my last file fort.40 contains these data:
Code:
0.000000000   -0.000000000   -0.707106781
0.005000000    0.062790520   -0.637423990
0.010000000    0.125333234   -0.562083378
0.015000000    0.187381315   -0.481753674
0.020000000    0.248689887   -0.397147891
...
...
0.980000000   -0.248689887   -0.917754626
0.985000000   -0.187381315   -0.876306680
0.990000000   -0.125333234   -0.827080574
0.995000000   -0.062790520   -0.770513243
1.000000000   -0.000000000   -0.707106781

It seems that the columns contain parameter t increased by 0.005 and the computed point coordinates x(t), y(t).

To plot the curve you have to use these text files as an input for a program for plotting curves, e.g. gnuplot.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top