Tuesday, 26 July 2011

Null/special characters

Like my LaTeX post, this is just going to be a home for scripting tricks...I'll start it off with one that's taken me the whole day to figure out.

awk and grep don't like 'binary files', by which I mean files with null characters in. I didn't even realise I had binary characters in the file until I used grep... it wasn't my file.

There are ways to continue to use grep and diff on binary files:
grep --binary-files=text
diff --text

In awk, any null/special characters are treated as the end of a line. Two ways to get around this are:
  1. rev - for example, if you want the last four columns of a file, but they're after a special character, just use rev twice: rev ${file} | awk '{print $1, $2, $3, $4}' | rev
  2. perl - you can do anything in perl, apparently. I just hate the language; it looks like the kind of poetry hard drive pixies would write after way too much whisky. Neither tr nor sed work, but the perl syntax is almost identical to that of sed: perl -pe 's/\000//g' ${file}

Thursday, 16 June 2011

Not-quite-bugs in LaTeX

I'll use the comments box below to post more LaTeX oddities over the coming months, but here's the first:

The Error:
! Undefined control sequence. \captionlabelfont@default ->\cph@font

The Issue:
The class file containing the \includepackage{caption} command was given the same base name as the .tex file

The Solution:
Rename the class and associated file.

Sunday, 29 May 2011

Naïveté?

Having been told that Numerical Recipes was a must-have for all scientists, coming across the following web page was a bit of a shock:
http://amath.colorado.edu/computing/Fortran/numrec.html

I haven't had time to check out their claims, but certainly some of the routines I've used appeared somewhat unstable... I still assume that this is my ignorance rather than theirs, but maybe I should delve a little deeper.

Either way, I'm happy that I've found http://www.netlib.org/. Even if most of the code relevant to me appears to be written in Fortran (a.k.a. Ancient Aramaic).

Sunday, 22 May 2011

Before submitting a paper...

I've overheard confessions from senior academics who admit that they knowingly submit before their work is ready. As a result, they find it mentally difficult to critically assess their own work after publishing a paper. This can't be a good sign.

The following are guidelines for me. I've broken several of these in the last couple of years, and regretted it.
  1. Have you finished the work? In other words, are you being pressured to publish before you're happy? Supervisor pressure, the risk of being scooped, money or time issues... these are all indicators that you might want to think carefully about submitting.
  2. When did you finish doing this work? If less than 3 months ago, don't submit.
  3. Have you discussed this with other people in your field? This is strongly recommended, since the easiest person to fool is ourselves.
  4. Have you written any part of your submission in such a way that it could be seen as an affront to another academic? However illogical their research might seem, this is a bad idea. Perhaps think about writing a reply to their paper instead.
  5. Have you had the paper proofread by someone else? More than one person?
  6. When did you finish writing the submission? If less than 1 month (and preferably 3 months) ago, don't submit. Check it, make sure you would be happy with submitting it, then put it in a drawer somewhere, and do something else.
  7. Once bringing the submission back out of its hiding place, have you checked it over thoroughly again? Do you still agree with what you've written?!
  8. If you've passed all the above points, here's a difficult one. Try to question/disprove as much of your submission as possible. Take some time to do this thoroughly. If you succeed in finding holes in your work, you can still submit, but you may need to rewrite and add caveats. Pride should have no place in a scientific establishment. This step should be repeated a year after the paper has been published - it encourages personal reflection, which is probably not a bad thing for a scientist.
Everything checks out? You probably have a scientific paper. You've got it past yourself, so the journal editors and reviewers should be easy, right?

Probably easier, but not easy - you still need to think carefully about where to submit. The minimum three months between finishing the work and submitting should help tone down the "this is so exciting, like, the most exciting thing in the world, man!" and the "Nature have to accept this, otherwise they're just being small minded" thought-processes. If it hasn't, either you haven't waited long enough, you're deluded, or you really do have a piece of ground-breaking work.

Good luck!

Wednesday, 18 May 2011

GPlates on Ubuntu

Ever wanted to watch plate evolution through time? Yes, of course you have.

GPlates on Ubuntu is great, but installing it at the moment takes a bit of know-how. Here's how I did it.

  • Visit http://www.gplates.org/
  • Download the .deb file
  • Attempt to install it, and find that the libicu42 dependency is 'unsatisfiable'.
  • Get annoyed, since libicu44 is already installed.

Here comes the hack to solve many of these dependency problems:
dpkg-deb -x ${debfile} tmpdir
dpkg-deb --control ${debfile} tmpdir/DEBIAN
sed 's/libicu42/libicu44/g' tmpdir/DEBIAN/control > tmp # Change this depending on the dependency issue you want to resolve.
mv tmp tmpdir/DEBIAN/control
dpkg -b tmpdir ${newdeb}

After this, run package manager with the new .deb file. You'll get a warning appearing telling you that the creator of the package (i.e. you) is not the same as the user who originally built the package. This warning is not usually to be taken lightly, and I take no responsibility for anyone screwing up their computer.

Anyway, the install should work fine. When you try to open gplates, it'll bring up an error:
gplates: error while loading shared libraries: libicuuc.so.42: cannot open shared object file: No such file or directory

There are a lot more icu libraries required too. Luckily, there's a quick way to solve this (though it is a horrible hack):
for file in /usr/lib/libicu*44*; do name=`echo ${file} | sed 's/44/42/g'`; sudo cp ${file} ${name}; done

Everything now works. If anyone can suggest a better way of doing this (by actually changing the hardwired libicu paths, for example), it would be great to hear from you!

Friday, 6 May 2011

My settings: Ubuntu 16.04

Ok, so I'm using Ubuntu 11.04. A geophysicist would be nowhere without his programs, so I've compiled a list of those installed on top of the basic Ubuntu packages. This is essentially a list of the things I've done to my computer after running a clean install. The install went something like this:
  • Back up files to two separate external hard drives
  • Create Ubuntu 11.04 Live CD and place in driver
  • Restart
  • Run through instructions, selecting 'other' when it comes to formatting
  • Delete the old Ubuntu partitions, leaving the Windows 7 one untouched
  • Create three new partitions, one as swap space (2*RAM), one as / (20GB) and one as /home (the rest, 60 GB).
  • Press Go
I needed to repeat this, since my laptop internet connection in college (wireless) was lousy and caused the installation to fail.

After that, it just remained for me to scream in horror at the ugliness and unergonomic monstrosity that was Ubuntu Unity, and run a quick search on Gnome 3. You can just select other options at login (bottom middle of screen), but I wanted a change.

And so began the week of updates, installs, reinstalls and a steep patch learning curve. The below is a summary of the packages I've installed since then.

DISCLAIMER: Some of these packages are still under development. I needed to tweak the Gnome-3 themes significantly, and there were a few bugs to iron out, but updates seem to be making this process easier.

# I dislike Unity (and am growing fond of Gnome 3)
sudo apt-get install gnome-shell gnome-themes-standard gnome-themes-selected gnome-themes-extra gnome-tweak-tool

sudo apt-get install ttf-mscorefonts-installer # Microsoft font package
# I love Python
sudo apt-get install python ipython mayavi2 python-matplotlib python-pip
pip install --upgrade

# Python packages numpy, scipy, pysparse, using
pip install numpy
pip install scipy
pip install pysparse
pip install mayavi # Yes, I know I'm installing mayavi twice. Shush.
pip install obspy

# Subversion and git
sudo apt-get install subversion git
 
# Octave (Matlab clone)
sudo apt-get install octave
# FEniCS (Finite element python package)
# NB The location of the FeniCS demos directory is not mentioned in the documentation. A quick 'locate' reveals them to be hiding in /usr/share/dolfin
sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt-get update
sudo apt-get install --no-install-recommends fenics
sudo apt-get dist-upgrade

#Gmsh (Creates FEniCS readable meshes for finite elements)
sudo apt-get install gmsh

# FiPy (Finite Volume python package)
svn checkout http://matforge.org/svn/fipy/tags/version-2_1_2 # Check for current version
# Text editing
sudo apt-get install emacs24 # Check for current version
# The full Texlive set
sudo apt-get install texlive-full
sudo apt-get install texworks # Tex environment
sudo apt-get install latex2html

# Postscripts and PDFs
sudo apt-get install gv # you'll need 3.7.2 or above (brand new and manual install as of 29th April 2011) to avoid warnings (at least with Gnome 3)
sudo apt-get install evince okular
sudo apt-get appmenu-gtk # removes icon warnings when using evince
sudo apt-get install acroread

# Image editing
sudo apt-get install gimp g3data
# Video
sudo apt-get install vlc
# Google Earth
sudo apt-get install lsb-core
http://www.google.com/earth/download/ge/agree.html
# For those long dark nights
sudo apt-get install fortune # Quotations (for my .bashrc)
sudo apt-get install gnubg # Backgammon

# 'New' additions
sudo apt-get install paraview
sudo apt-get install hugin
sudo apt-get install audacious
sudo apt-get install inkscape
sudo apt-get install prey

Thursday, 9 September 2010

My DVDs (for borrowing purposes)

In case anyone wants to borrow a DVD or 20 from me, here's a list. Films are first, series second. Please don't judge me too harshly! Just let me know if you'd like to watch any, and I'll bring it/them along the next time we meet.

FILMS
*******************
Hitchcock Films:
Strangers on a Train
Dial M for Murder
The Wrong Man
Stage Fright
I Confess
North by Northwest
Rear Window

Classic Films:
Harvey
Mr Smith Goes to Washington
It's a Wonderful Life
Some Like it Hot
To Kill a Mockingbird
Singin in the Rain
The Godfather Trilogy
Dr Strangelove
Schindler's List
The Shawshank Redemption
Pan's Labyrinth

Bond Films:
Casino Royale
Quantum of Solace

Bourne Films:
The Bourne Ultimatum
The Bourne Supremacy

Drama:
The Constant Gardener
Blood Diamond
The Last King of Scotland
Catch me if you can
Body of Lies

Action/adventure:
The Lord of the Rings Trilogy
The Indiana Jones Quartet
Mission Impossible: III

Sci-Fi:
I, Robot (from TV)
Stargate
Unbreakable
The Matrix: Reloaded
Serenity

Fantasy:
Stardust
Batman Begins
The Prestige
Interview with a Vampire
The Hitchhiker's Guide to the Galaxy
Constantine

Comedy:
Life of Brian

Disaster:
The Day After Tomorrow


SERIES
*******************
Comedy:
Red Dwarf (I-VIII)
Scrubs (I-VI)
'Allo 'allo (I-II)
Yes Minister (I-III)
The Goodies (I-II)
Fawlty Towers (Complete)
The Day Today (I)
Blackadder (I-IV)
Father Ted (III)
One Foot in the Grave (Best of)
Monty Python's Flying Circus (Best of)
The Beiderbecke Trilogy (plus Get Lost!)
Michael Macintyre's Hello Wembley

Tongue-in-cheek:
The Avengers ('65-'67)
The Champions (Complete)

Drama:
Randall and Hopkirk (Remake; I-II)
Jonathan Creek (I-IV)
House (I-III)
Dexter (I-III)

Sci-Fi/Fantasy:
Stargate SG-1 (I)
Battlestar Galactica (Remake; 0-I)
Fringe (I-II)