Menu Close

Plotting Using gnuplot | Fortran

NOTE

Create a test.txt file in the same folder/directory of the program.

File – plotting.f95

PROGRAM IOFUN
IMPLICIT NONE
INTEGER i,ierror

REAL,DIMENSION(100)::ARR

PRINT *, '============================================'
PRINT *, 'PLOTTING USING GNUPLOT [BOTTOMSCIENCE.COM]'
PRINT *, '============================================'

OPEN(UNIT=1,FILE='test.txt', STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror)

DO i=1,10

ARR(i)=0.1*i

WRITE(1,*) ARR(i),ARR(i)**2
END DO
CLOSE(1)
PRINT *,'WRITTEN SUCCESSFULLY'


call system('gnuplot -p plotting.gnu')


END PROGRAM

File – plotting.gnu

set title 'GRAPH'

set xlabel 'X'

set ylabel 'Y'


set key bottom right title 'VALUES OF FUNCTION'

set grid 



plot 'test.txt' with linespoints linewidth 6

OUTPUT

1
WRITTEN SUCCESSFULLY
0

 

test.txt

0.100000001 1.00000007E-02
0.400000006 0.160000011
0.900000036 0.810000062
1.60000002 2.56000018
2.50000000 6.25000000
3.60000014 12.9600010
4.90000010 24.0100002
6.40000010 40.9600029
8.10000038 65.6100082
10.0000000 100.000000

More Related Stuff