My first program written in fortran is below
!================================================
PROGRAM Grafik
IMPLICIT NONE
!declare variable
REAL :: gaya,ygaya,k,ky,a,ay,m,v,vy,t,x,y,z
REAL :: sbx,sby,sbz,g,fx,fy,fz
REAL :: r,dt,dx,dy,dz,dv,dvy,theta,phi
INTEGER :: i,j,n
!initial value
r =100
g =10
n =10000
k =10000
ky =1000
t=0
dt=0.001
!dx=0.01
m=10
v=0
x=10
y=10
vy=0
!create new file named data.dat (you may change the extension. I used that as I think .dat is cool extension )
OPEN (80, FILE = 'data.dat', STATUS = 'NEW', FORM = 'FORMATTED')
WRITE(80,*) ' i t x y'
CLOSE(80)
OPEN(80, ACCESS = 'APPEND', FILE = 'data.dat', FORM = 'FORMATTED')
!the algorithm
DO i=1,n
gaya=-k*x
a=gaya/m
dv=a*dt
v=v+dv
dx=v*dt
x=x+dx
ygaya=-ky*y
ay=ygaya/m
dvy=ay*dt
vy=vy+dvy
dy=vy*dt
y=y+dy
t=t+dt
!write the result of calclation to data.dat
WRITE(80,81) i, t, x, y
81 FORMAT(i7,' 'e14.7,' ',e14.7,' ',e14.7)
END DO
CLOSE(80)
END PROGRAM Grafik
!===========================================
save to grafik.f90 then compile using this syntax
$gfortran grafik.f90
that'll produce file named a.out
run using
$./a.out
and data.dat will appear
to plot the graphic using value in data.dat I use kst
$kst -x 2 -y 3 data dat
mean kst will use 2nd column as x-axis n 3rd as y-axis
Yeah, I know that the steps look boring, so I used sh script below to generate it automatically.
using kwrite, create text file like below:
rm *.dat
gfortran grafik.f90
./a.out
kst -x 2 -y 3 data.dat
save as run.sh, make it executable then run:
$./run.sh
!I also used script below to generate x, y, z in text file and plot it using kst
!
!DO i=1 ,100
! dt=i
! dt=dt/100
! sbx=r*sin(dt)
! sby=r*cos(dt)
! sbz=dt
! WRITE(80,81) sbx, sby, sbz
! 81 FORMAT(F10.2,' ',e14.7,' ',e14.7)
!END DO
!DO i=1, n
!DO j=1, n
! theta=i
! phi=j
! sbx=r*sin(theta)*cos(phi)
! sby=r*sin(theta)*sin(phi)
! sbz=r*cos(theta)
! !sbz=2
! WRITE(80,81) i, j, sbx, sby, sbz
! 81 FORMAT(i7,' ',i7,' 'e14.7,' ',e14.7,' ',e14.7)
! PRINT*, 'theta: ',i,' -------------'
! PRINT*, 'phi: ',j,' -------------'
! PRINT*, 'sb-x :', sbx
! PRINT*, 'sb-y :', sby
! PRINT*, 'sb-z :', sbz
!END DO
!END DO
There is something strange in two script above. The result is x, y, z (THREE variable) but why the plot is just in TWO axis? Err..., that the weakness of kst.
At prior time :), I used gnuplot to generate "3D" picture--of course, it just projection of z-axis (or x-axis if you using left-handed coordinate)--but I have'nt yet found to automating it using .sh script.
If you like to using gnuplot:
$gnuplot
>plot "data.dat" using 2:3 (oops, that still 2D. Plotting data.dat using 2nd and 3rd column)
>splot "data.dat" using 2:3:4 (that is.)
I've skimmed "man gnuplot" but did'nt found how to do it automatically
anybody can help me automating it using gnuplot?
oh yeah, almost forget, I use Linux.
Subscribe to:
Post Comments (Atom)
My sky is high, blue, bright and silent.
Nugroho's (almost like junk) blog
By: Nugroho Adi Pramono
323f
(5)
amp
(1)
android
(12)
apple
(7)
arduino
(18)
art
(1)
assembler
(21)
astina
(4)
ATTiny
(23)
blackberry
(4)
camera
(3)
canon
(2)
cerita
(2)
computer
(106)
crazyness
(11)
debian
(1)
delphi
(39)
diary
(286)
flash
(8)
fortran
(6)
freebsd
(6)
google apps script
(8)
guitar
(2)
HTML5
(10)
IFTTT
(7)
Instagram
(7)
internet
(12)
iOS
(5)
iPad
(6)
iPhone
(5)
java
(1)
javascript
(1)
keynote
(2)
LaTeX
(6)
lazarus
(1)
linux
(29)
lion
(15)
mac
(28)
macbook air
(8)
macbook pro
(3)
macOS
(1)
Math
(3)
mathematica
(1)
maverick
(6)
mazda
(4)
microcontroler
(35)
mountain lion
(2)
music
(37)
netbook
(1)
nugnux
(6)
os x
(36)
php
(1)
Physicist
(29)
Picture
(3)
programming
(189)
Python
(109)
S2
(13)
software
(7)
Soliloquy
(125)
Ubuntu
(5)
unix
(4)
Video
(8)
wayang
(3)
yosemite
(3)
No comments:
Post a Comment