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.

7
  • 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? Commented Feb 6, 2017 at 14:55
  • Did you get any error message in Windows? Commented Feb 6, 2017 at 14:55
  • @d_1999 Yes, I did get 'gnuplot' is not recognized as an internal or external command, operable program or batch file. Commented Feb 6, 2017 at 15:38
  • 2
    You'll possibly want to add the path to the executable to your PATH environment variable (for example see here for how to do this on windows 7). You may want to use the command wgnuplot instead, if so you may find this helpful (which basically says don't as you may get some problems!). Commented Feb 6, 2017 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. Commented Feb 7, 2017 at 10:26

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.