如何让gnuplot窗口保持不变并且主程序不冻结 [英] How to let gnuplot window persist and the main program not freeze
问题描述
我在Fortran中有一个程序,用于计算一个名为
wvfunc3d.dat
的文件,我希望在执行程序期间实时使用Gnuplot进行可视化。在创建这个文件的代码之后,我在程序中加入了一个字符串
jret = SYSTEM('gnuplot wf3d.plt')
脚本文件wf3d.plt只有一个字符串,如下所示:
splot'wvfunc3d.dat'wl
所有这一切都绘制出我想看到的情节,但众所周知,它立即消失。我知道,有一个选项可以避免关闭窗口,
jret = SYSTEM('gnuplot -persist wf3d.plt ')
让我的绘图不会消失,但是Fortran程序的执行也会冻结直到我用图表关闭窗口。所以,我希望剧情能够持续到我有新的数据,并在Fortran中重新调用一个命令后自动更新,但我也需要我的程序来运行计算!有没有办法解决这个问题?我认为你可以使用 c>来代替 如果这不起作用,您可以考虑使用多线程策略(fortran中的openMP或mpi)。就我个人而言,我通常只是同时运行gnuplot,并通过按 和 I have a program in Fortran that calculates a file, say, named
wvfunc3d.dat
which I want to visualize with Gnuplot in real time during the execution of my program. After the code that creates this file, I put in my program a string the script file wf3d.plt has the only string and looks like: All of this really draws a plot I want to see, but, as is well known, it immediately disappears. I know, there is an option to avoid the closing of the window, that lets my plot not to disappear, but then the execution of the Fortran program also freezes until I close the window with the graph. So, I want the plot to persist until I have new data, to be automatically updated after a new call of a command in Fortran, but I also need my program to run calculations! Is there a way to solve this problem? I use Windows XP. I think you may be able to use If this doesn't work, you could consider a multi-threaded strategy ( openMP or mpi in fortran). Personally, I usually just run gnuplot at the same time and trigger an update of the plotted data by pressing the and
这篇关于如何让gnuplot窗口保持不变并且主程序不冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! EXECUTE_COMMAND_LINE $ c $我可以使用
EXECUTE_COMMAND_LINE
system
来实现你想要的。这允许您包含一个 wait
选项,当 set 为 .false。
允许fortran代码继续运行。然后,您可以添加睡眠并重新读入您的gnuplot脚本(例如 sleep 1
和 reread
), a href =http://hxcaine.com/blog/2013/02/28/running-gnuplot-as-a-live-graph-with-automatic-updates/ =nofollow> 。
a
键触发绘图数据的更新。我使用Linux所以不能测试它的Windows,但一个最小的例子,这对我来说是,
程序gnuplot
隐式none
logical :: gnuplot_open = .false。
integer :: i,t,N,重绘
real(kind(0.d0)),dimension(:),allocatable :: x,y
real(kind(0.d0 )),parameter :: pi = 4.d0 * atan(1.d0)
N = 1000
allocate(x(N),y(N))
redraw = 100
do t = 1,300000
do i = 1,N
x(i)= 6.d0 * i / N * pi
y(i) =(x(i)+ t * 0.2)
enddo
if(mod(t,redraw).eq。0)then
open(1,FILE ='。/ tempout' ,status ='replace')
do i = 1,N
write(1,*)x(i),y(i)
enddo
close(1,status ='keep')
endif
if(.not。gnuplot_open)然后
调用execute_command_line('gnuplot --persist plot_tempout',wait = .false。)
gnuplot_open =。真正。
endif
enddo
结束程序gnuplot
plot_tempout
是,
plot'tempout'u 1:2 wl
暂停0.1
重读
jret=SYSTEM('gnuplot wf3d.plt')
splot 'wvfunc3d.dat' w l
jret=SYSTEM('gnuplot -persist wf3d.plt')
EXECUTE_COMMAND_LINE
instead of system
to achieve what you want. This allows you to include a wait
option which when set to .false.
allows the fortran code to keep running. You can then add a sleep and reread to your gnuplot script (e.g. sleep 1
and reread
) as suggested in this post.a
key. I use linux so cannot test it for windows but a minimal example which works for me is,program gnuplot
implicit none
logical :: gnuplot_open = .false.
integer :: i,t,N,redraw
real(kind(0.d0)),dimension(:),allocatable :: x,y
real(kind(0.d0)),parameter:: pi=4.d0*atan(1.d0)
N = 1000
allocate(x(N),y(N))
redraw = 100
do t = 1,300000
do i=1,N
x(i) = 6.d0*i/N*pi
y(i) = sin(x(i)+t*0.2)
enddo
if (mod(t,redraw) .eq. 0) then
open(1,FILE='./tempout',status='replace')
do i=1,N
write(1,*) x(i),y(i)
enddo
close(1,status='keep')
endif
if (.not. gnuplot_open) then
call execute_command_line('gnuplot --persist plot_tempout', wait=.false.)
gnuplot_open = .true.
endif
enddo
end program gnuplot
plot_tempout
is,plot 'tempout' u 1:2 w l
pause 0.1
reread