This is the website of Andy Carter a Textpattern and Drupal web developer living in the Steel city.

Automating Gnuplot with scripting

I have recently found myself with a large number of data files that all wanted to be fed through Gnuplot to produce a number of figures. Not wanting to spend ages manually feeding them in to Gnuplot I decided to have a go at scripting something to save myself a lot of time. I hope that sharing this here is of use to somebody out there.

The script, script.sh:-

#! /bin/bash
ls *.data | sed "s/.data//" > list
for i in `cat list` ; do
   sed -e "s/INPUTFILE/$i/" -e "s/OUTPUTFILE/$i/" \
    plot.gnu | gnuplot
done
rm list

The script, written in Bash, creates a file called list in which all the data files matching the condition *.data are listed (stripped of their file extension .data). It then reads through this file invoking sed to replace INPUTFILE and OUTPUTFILE in the Gnuplot script plot.gnu (see below) with the name of the data file and passes this to Gnuplot. Finally, the temporary file list is removed. Simple!

Remember the script needs to be executable: chmod +x script.sh

The Gnuplot file, plot.gnu:-

set term postscript enhanced color
set output 'OUTPUTFILE.eps'
set title 'OUTPUTFILE'
p 'INPUTFILE.data' u 1:2 w l

Obviously you can make the Gnuplot file as advanced as you like to produce the sort of figures you desire with your data.

You might be interested in the following


Comment

Want to comment?

To comment you'll need to provide an e-mail address. Don't worry all e-mail addresses are kept private and will never be shown on this site or distributed to others.

Don't forget the http:// part

You'll need to preview your comment before it can be submitted; this is to help prevent spam and to give you a chance to review your comment before it gets posted on the site.

Comment formatting:

_emphasis_
*strong*
??citation??
-deleted text-
+inserted text+
^superscript^

Hyperlink:
"link text":http://link.com/

To define an acronym:
ABC(Always Be Closing)

Note: All (X)HTML tags will be escaped.