Blog

Thursday 28 August 2008

Bad Science

If you haven’t discovered Ben Goldacre’s Bad Science website yet then it is well worth a look. He writes about the misrepresentation of science in the media and has a book coming out in the UK next Monday (1st September), also called Bad Science.

— Andy

Posted in:

Comment

Monday 18 August 2008

Combine PDFs from the Linux command line

Here's a useful little trick for merging PDF files at the Linux command line using Ghostscript:-

> gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH file1.pdf file2.pdf

— Andy

Posted in:

Comment

Tuesday 05 August 2008

Using awk to calculate averages

Here's a simple little awk script, averages.awk that takes a datafile and returns the average value of each column in that file:-

{ for (i = 1; i <= NF; i++) x[i]+=$i ; j++ }
END { for ( i=1 ; i<= NF ; i++ ) print x[i]/j }

The first line of the script goes through the datafile keeping a tally of each column in the array x; the number of iterations is stored in the variable j. The variable NF contains the number of columns read in from the file by awk. The second line is executed at the end and returns the mean average of each column.

The script is simply called from the command line with the last parameter being the name of the datafile from which the averages are to be calculated:-

> awk -f 'averages.awk' datafile.dat

— Andy

Posted in:

Comment

Wednesday 30 July 2008

Heavy Electricity

Classic Brass Eye getting celebrities to discuss the dangers of heavy electricity (apparently ‘caused by sodomised electrons’)…

(More4 is currently repeating Brass Eye late on Sundays.)

— Andy

Posted in:

Comment

Wednesday 23 July 2008

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.

— Andy

Posted in:

Comment

Saturday 19 July 2008

TV scientists

Top 10 TV scientists blog post on the Guardian website.

— Andy

Posted in:

Comment

Tuesday 08 July 2008

Uesful Gnuplot websites

Gnuplot is an incredibly useful free program for plotting functions and data that I use a lot. Some day I intend putting together a guide to making the most out of it, but in the meantime here are a collection of useful websites for using this surprisingly powerful piece of software.

The official Gnuplot website is the place to go to download a copy of Gnuplot as well as a useful resource for detailed documentation on what the program can do and how, including a number of examples. However, for newcomers the documentation can be a bit bewildering; a number of sites have good introductions to using Gnuplot, one of the better of them is the Math Blog’s Getting started with Gnuplot. Another good tutorial is this Duke University Gnuplot 4.0 tutorial page. IBM have a good article on visualising 2D data with Gnuplot.

If you’ve got to grips with the basics and want quick answers an excellent resource is the Gnuplot: Not so frequently asked questions website, an invaluable site that I’ve made a great deal of use of over the years (and still do).

If I find more I’ll add them. If you want to suggest a good Gnuplot site then please leave a comment below.

— Andy

Posted in:

Comment

Tuesday 01 July 2008

andy-carter.com version 1

I’ve just changed the look of the site for the first time since I launched it a couple of years ago. I still like the look and feel I gave the original site, but it was time for a change and I needed something a little more spacious to accommodate the growing information I want to put on here. So, for the sake of nostalgia I am posting a picture of the original site design here.

site design version 1

— Andy

Posted in:

Comment

Saturday 31 May 2008

The World of Chemistry

An attempt by the European commission to make science ‘cool’…

— Andy

Posted in:

Comment

Recent blog posts

Links