Wai Kiat
Wai Kiat

Reputation: 859

Use gnuplot within Fortran code in Windows

I have a fortran code as below

program compute_plot
  integer :: i, n = 10
  real :: x(10), y(10)

  x(1) = 0.0
  y(1) = 0.0

  do i = 2, n 
    x(i) = 0.1*i
    y(i) = x(i)*x(i)
  end do

  open(unit = 5, file = 'data.txt')
  do i = 1, n
    write(5,*) x(i),y(i)
  end do
  close(5)

  call system('gnuplot -p data_plot.gnu')
end program compute_plot

and another gnuplot script as below

reset
set terminal pngcairo dashed enhanced size 480,360 font 'arial,12' fontscale 1.0
set encoding utf8
set output 'plot.png'
set xlabel "x"
set ylabel "y"
m = "./data.txt"
set title 'The parabola'
plot m using 1:2 w l

These two code work well in Linux terminal, but I could not find a way to make them work in Windows command prompt. I also not sure if it is possible to make them work in Windows. Please advise.

Upvotes: 1

Views: 4996

Answers (1)

Wai Kiat
Wai Kiat

Reputation: 859

  1. Download gp503-win32-mingw.zip from gnuplot official webpage;
  2. Extract the zip file in your desired folder, e.g. F:Document;
  3. The gnuplot folder will now have the path of F:\Documents\gnuplot\;
  4. Right click This PC, click on Properties, click on Advanced system settings, click on Advanced tab, click on Environment Variables...;
  5. Choose Path on the top table of Environment Variables windows, then click Edit...;
  6. Now click on New to add in the path of gnuplot.exe, e.g. in my desktop F:\Documents\gnuplot\bin
  7. To check if it is working properly, go to Command prompt and run the command of gnuplot.

Upvotes: 1

Related Questions