1

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.

Wai Kiat
  • 789
  • 1
  • 8
  • 13
  • If you open a command prompt on windows and type `gnuplot` do you start the gnuplot program or do you get something like a `'gnuplot is not recognized....` error? – d_1999 Feb 06 '17 at 14:55
  • Did you get any error message in Windows? – Vladimir F Героям слава Feb 06 '17 at 14:55
  • @d_1999 Yes, I did get `'gnuplot' is not recognized as an internal or external command, operable program or batch file`. – Wai Kiat Feb 06 '17 at 15:38
  • 2
    You'll possibly want to add the path to the executable to your `PATH` environment variable (for example see [here](http://stackoverflow.com/a/28545224) for how to do this on windows 7). You may want to use the command `wgnuplot` instead, if so you may find [this](http://stackoverflow.com/q/24203126) helpful (which basically says don't as you may get some problems!). – d_1999 Feb 06 '17 at 16:28
  • @d_1999 Thank you so much. I added the directory of the executable `gnuplot.exe` to the `PATH` environment variables and the code work perfectly now. – Wai Kiat Feb 07 '17 at 10:26
  • @Kiat no problem. You might want to write a short answer explaining what you did to solve the problem so future visitors know how to fix this. – d_1999 Feb 07 '17 at 15:09
  • @d_1999 Certainly. Thank you again. – Wai Kiat Feb 11 '17 at 07:36

1 Answers1

1
  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.
Wai Kiat
  • 789
  • 1
  • 8
  • 13