[haskell-gnuplot] temporary files, asynchronous execution of gnuplot

Henning Thielemann lemming at henning-thielemann.de
Fri Dec 14 14:45:16 GMT 2012


Hi all,

I may change the behaviour of the Haskell gnuplot wrapper and want to know 
your opinion on that topic.

Handling of the curve data files was always a problem in the Haskell 
gnuplot wrapper. Thus I ended up writing all curve.csv files into the 
current directory. Not nice, but the most portable implementation at the 
time of writing. A portable way to access the system's temporary directory 
was not available then.

This has changed, we have now the 'temporary' and 'filepath' packages and 
'directory' got a getTemporaryDirectory function. But these do not simply 
solve the problem. We have the following options and corresponding 
problems:

1. Preserve temporary files, such that they persist after gnuplot 
terminates. With this option everything would work as in the past but the 
allocated space in the temporary directory would grow with every call to 
gnuplot.

2. Delete temporary files after gnuplot quits. That's difficult because 
currently I run gnuplot with the --persist option and this means that 
gnuplot starts a background process to handle the open window while the 
main gnuplot executable terminates. That is, if I delete the curve files 
after the main gnuplot executable terminates then the window shows data 
that is no longer available on disk. Gnuplot does not need access to the 
curve files if you resize the window BUT if you use the zoom feature of 
the WX terminal then it tries to load the temporary files that I already 
deleted.
  That is, in order to do that properly I would have to block main gnuplot 
until the user closes the window. I can achieve this by adding a 'pause 
mouse close' as the last gnuplot command. But then, calling a gnuplot 
command from GHCi would block the GHCi prompt which is different from the 
current behavior. I can add a forkIO to the gnuplot call, but this would 
be wrong for file generating gnuplot terminals.


I think option 2 is the right thing. Now my question to you is:
Are you keen on preserving the current asynchronous start of gnuplot for 
interactive terminals and synchronous start of gnuplot for file terminals?
Possible answers may be:

a) Make plot always synchronous (i.e. block until gnuplot terminates),
    I can run it asynchronously with forkIO myself.

b) Make plot always synchronous and add plotAsync.

c) Emulate current behaviour of plot
    (async for terminals X11, WX; sync for PNG, PDF, PS)
    and add plotSync and plotAsync.

I prefer answer a or b. Answer c is fragile because I do not know how to 
find out whether a terminal is interactive or not. I can hardcode it for 
the currently supported terminals but what about the default terminal? Is 
it always interactive? For me it is true, but it is always true?


One last issue: I have learned that some users want to read the content of 
curve.csv and curve.gp. But relying on certain file names and locations in 
an external script would be rather fragile. Thus I offer to add a function 
that converts a gnuplot object into (String, [(FilePath, String)]), where 
the first String is the content of the gnuplot script and the list 
contains file names and contents of the curve files.


Best,
Henning



More information about the Gnuplot mailing list