Archive for August, 2008

Fortran: can’t get no leading zero


Perhaps someone who eats Fortran for breakfast can help me.

Is it really the case that there’s no way (in (portable) Fortran) to format a floating point number so that it has as many leading zeros as are necessary to fill the field?

Imagine I wanted to output something like ISO 6709 and have the location of Sheffield displayed as:


In Python (using C’s syntax) this is just '%+06.2f%+07.2f' % (lat,lon).

Can I really not do this in Fortran? Surely I have just missed something.


gives me:

+53.40 -1.50

which is not what I wanted at all. I (half humourously) tried F06.2,F07.2 but that doesn’t work.

If true, it’s absolutely unforgivable.

Quality Improvement Agency, improving the 404


I know I shouldn’t. It’s silly to mock quangoes. But I just couldn’t resist.

Check out the Quality Improvement Agency’s 404:

Quality. Got to have that 404 displayed in Rockwell Bold. Outline. What the heck is «http://404» anyway?

I was going to mock them for the hilarious graphic, amongst other things, in this press release. Most excellent.

BBC: remove errors bars for better headline


In this article from the BBC Richard Black claims “This year appears set to be the coolest globally this century”. There is no basis for this claim, and moreover the very notion of picking warmest and coolest years amounts to bickering about global warming.

Black appears to be making this claim on the basis of looking at column 2 of the HadCRUT data. Here’s a graph, freshly minted from the Google Chart API:

The data is taken from HadCRUT, here’s a relevant extract:

2000  0.238  0.249  0.227  0.333  0.144  0.238  0.233  0.334  0.143  0.334  0.143
2001  0.400  0.411  0.388  0.495  0.304  0.400  0.394  0.495  0.304  0.495  0.303
2002  0.455  0.466  0.445  0.553  0.358  0.455  0.450  0.553  0.358  0.553  0.357
2003  0.457  0.468  0.447  0.556  0.359  0.457  0.452  0.556  0.358  0.556  0.358
2004  0.432  0.444  0.421  0.530  0.335  0.432  0.426  0.530  0.334  0.530  0.334
2005  0.479  0.490  0.469  0.580  0.378  0.479  0.473  0.581  0.378  0.581  0.378
2006  0.422  0.432  0.412  0.517  0.327  0.422  0.416  0.518  0.326  0.518  0.326
2007  0.404  0.414  0.394  0.501  0.307  0.404  0.398  0.502  0.307  0.502  0.307
2008  0.281  0.292  0.270  0.428  0.134  0.281  0.275  0.429  0.134  0.429  0.134

The format of the data is described here, by Hadley.

In the graph the red line is the best estimate, the pink lines shows the combined 95% uncertainty from all sources. You can get more, or possibly just different, graphs from Hadley.

The first thing to notice is that Black’s claim is false if you include the year 2000. Okay so technically I know that “this century” starts in XX01 but I also know we all celebrated the beginning of the millennium in 2000 and we accepted then that although 2001 was technically the beginning of the millennium (and hence the century) it was much hipper to celebrate 2000. So that deserves a mention at least.

But really my gripe is about not observing the error bars. The uncertainty in the data is such that the error bars all overlap! The data does not support the claim that 2008 is warmer than 2005 for example; if we take as our null hypothesis that these two years are the same temperature then we cannot reject it with any confidence. The same is true about any other pair of years (except possibly for 2005 versus 2000; we might be able to claim that 2005 was warmer than 2000).

Neglecting 2000, as Black obviously does, the data are consistent with a constant anomaly of +0.4°C. That’s just an example, many other temperature series would be consistent with the data, including ones which make 2005 the coolest year.

And that’s the problem with trying to “rank” years. The uncertainties in the data are all so large compared to the yearly changes that it’s totally meaningless to talk about the warmest year or the coolest year. We just don’t know.

Of course, if Richard Black had thought about the uncertainties in the data then he would’ve had to say “latest HadCRUT data shows 2008 about as warm as any other year this century”, and that’s not a very controversial thing to say. All this dramatic concentration on the yearly, monthly, daily ups and downs of global temperatures, greenhouse gas levels, what-have-you is nonsense. It’s just talking about the weather while the planet burns.

Python: short range xrange


Pathetic Python:

>>> range(1e10,1e10)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: range() integer start argument expected, got float.
>>> xrange(1e10,1e10)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: long int too large to convert to int

In the first case range‘s error message is misleading. range is quite happy to take float arguments that are integers:

>>> range(1e1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

I suspect that range‘s actual problem is what xrange is complaining about a little lower down: it can’t squeeze 1e10 into an int. It should say so.

xrange however should not be barfing on this input. Well, for one thing the resulting sequence has no elements in it. But even xrange(1e300) is reasonable and should give a reasonable result. There’s no reason that xrange should be constrained by being implemented with int (which in Python is bounded) rather than long (or bignum, as we would say).

Browsing the bug tracker, looks like it might be being fixed.

Hiragana practice grid


Whilst looking for something else on my hard disk I found this ancient thing I did that might be of use to other people. It’s a design of practice paper for writing hiragana and katakana. So if you’re learning to write Japanese do print out lots.

kanagrid (PDF, 3807 octets)

Share and Enjoy!

Much to my amusement the “source” is a short PostScript program that I now find mysterious. Despite the comments:

% Kanagrid v1
% Copyright 1998 drj - copying in whole permitted

% draws a box of the specified dimensions at 0,0
% bx by -
/box {
  0 0 moveto
  dup 0 exch rlineto
  exch 0 rlineto
  neg 0 exch rlineto
  closepath } def

% draws the interior divisions of a rectangle divided into n
% boxes, the boxes being arranged horizontally
% bx by n - bx by n
/oxgrid {
  1 1 2 index 1 sub
  { 3 index mul 1 index div
    0 moveto 0 2 index rlineto }
  for } def

% draws the interior divisions of a rectangle divided into n
% boxes, the boxes being arranged vertically
% bx by n - bx by n
/oygrid {
  1 1 2 index 1 sub
  { 2 index mul 1 index div
    0 exch moveto 2 index 0 rlineto }
  for } def

% draws the interior division of a rectangle divided
% horixontally and vertically into a grid of boxes.
% there are nx boxes horizontally, and ny vertically.
% at 0,0
% bx by nx ny -
/ogrid {
  4 1 roll oxgrid
  pop 3 -1 roll oygrid
  pop pop pop
} def

% draw a rectangle divided into nx boxes horizontally and
% ny vertically, at 0,0
% bx by nx ny -
/cgrid {
  3 index 3 index
  box ogrid
} def


% put user space in mm
72 25.4 div
dup scale

% { nicked from 5.6.1 of PSRM2
/Helvetica findfont
dup length dict begin
  {1 index /FID ne {def} {pop pop} ifelse} forall
  /Encoding ISOLatin1Encoding def
/Helvetica-ISOLatin1 exch definefont pop
% }
9 25.4 mul 72 div selectfont

40 36 translate
0 0 moveto (kanagrid - \251 1997 drj - copying in whole permitted) show

0.25 setlinewidth
0 4 translate
133 200 box
3 0 translate

0 1 9 {pop 10 200 1 20 cgrid 13 0 translate} for



DEFRA promotes bovine TB in herds


Farming Link is a magazine published by DEFRA. I assume it is sent to all DEFRA registered farmers (in the UK in order to receive money under the Single Payment Scheme you must be the registered owner of entitled land; DEFRA probably uses this list or something similar).

August’s edition is hot off the press and contains an article that introduces the gamma interferon test (for bovine tuberculosis). This article correctly identifies the major benefit of the gamma interferon test, namely higher sensitivity compared to the skin test. Sensitivity is the proportion of infections that are identified as positive according to the test. So the gamma interferon test correctly identifies more infections than the skin test. The appendices of Specificity Trial of the BOVIGAM® IFN-Gamma Test in GB Cattle give a sampling of figures for sensitivity: around 77% for skin test; around 88% for gamma interferon.

Currently in some situations it is up to the farmer whether a herd should be tested using the more sensitive gamma interferon test or the traditional skin test. Carl Padgett, president of the British Cattle Veterinary Association, is quoted as saying “If you have a herd with a brand new infection, you want to get rid of that infection as quickly as possible before it spills over to neighbouring farms or into the local wildlife population. So you want to take out as many animals as possible that might be infected rather than keeping them in the herd”. Sounds like jolly good advice to me.

But then the article goes on to say that in some herds with recurrent TB problems “the [gamma interferon] test may pick out more infected cattle than the standard skin test”. Well yeah, it’s more sensitive, that’s what it’s supposed to do. The articles says that in these circumstances the gamma interferon “might not be in the farmer’s interests”. In other words DEFRA is saying that because the skin test leaves more infected animals in the herd it could be better for the farmer; the farmer will have to replace fewer heifers (expense) and therefore should opt for skin test. In any case I don’t really buy the expense argument. Animals that test positive are compensated for at the market rates, isn’t there an equivalence between money and heifers? Isn’t this what economics is about?

What is DEFRA’s agenda here? Reducing bovine TB, or minimising the number of positive animals it has to purchase?

The glorious twelfth


Ah, the open country, the heather in bloom. Load up the number 5 shot Henry, and make sure both my guns are clean. Open season on grouse.

We can all see how the management of the common resource, large grouse in this case, is improved by the government imposing controls on its use. Preventing people from shooting until a certain date means that everyone gets a better experience.

Surely this is a killer argument for state managed resources that even right-wingers can understand?


Get every new post delivered to your Inbox.