Radiation physics, environmental contamination, and computational science. Researcher working for the Japan Atomic Energy Agency, in Kashiwa, Japan

Spotted an error on this site?
Corrections appreciated, please email alex (at) alexmalins.com or leave a comment.


Updating the version of a port on MacPorts

This post broadly follows the MacPorts howto/Upgrade guide: https://trac.macports.org/wiki/howto/Upgrade

If you come across a piece of software on MacPorts where the version is out of date, here’s how to update it. First open up a terminal window and identify the port’s maintainer:

port info --maintainers <portname>

If the port has a maintainer, easiest is to send them a polite email requesting the port is brought up to date.

If the port has no maintainer (nomaintainer@macports.org), or allows open maintenance (openmaintainer@macports.org), you can upgrade the port manually yourself with the following steps. If successful, you can then submit a new ticket to http://trac.macports.org/ in order for the update to be propagated onto the MacPorts server for the benefit of other users.

First change directory into the port folder:

cd $(port dir <portname>)

Backup the port build file:

sudo cp Portfile Portfile.orig

Use a text editor to edit the software version in the Portfile to the latest version number (e.g. version 1.4.1 to 1.5):

sudo nano Portfile

If the Portfile revision entry is not set to 0, set it to 0 as this is the first revision for the updated version. Now download the source code of the latest version of the port and find its checksums with the following command:

sudo port -d checksum <portname>

Copy the checksums (rmd160 and sha256) that are printed out for the for the latest version and paste them into place over the old checksums in the Portfile. Similarly, if the Portfile contains a livecheck.md5 entry, fetch this for the latest version and propagate it into the Portfile:

sudo port -d livecheck <portname>

You can now compile and install the latest version on your local machine by:

sudo port -d install <portname>

If the compile is successful and the updated software functions correctly, you can then file an update. First create a diff file for the changes to the Portfile:

diff -u Portfile.orig Portfile | sudo tee <portname>.diff

Then file a new ticket at http://trac.macports.org/. Give the ticket a title like:

<portname> @<current_version>: update to <latest_version>

Cc in the email address coupled to the port which you identified at the beginning of this process. Attach the <portname>.diff file. All being well one of the MacPorts team will use your patch and update the port to the latest version on the MacPorts server within the following days.

Compellingly-titled article series on research methods

Image: GMA

Image: GMA

A journal of the German Medical Association, Deutsches Ärzteblatt International, has been running a series of articles on the critical appraisal of scientific papers since 2009.

There is a clear medical focus to the articles. However, many of the topics covered cross over borders into other areas of science. The articles I have read so far have been compelling and well worth recommending to other researchers and curious minds. The coverage of various topics in statistics is particularly interesting.

Here are links to all the articles in the series. Helpfully, they are all open access.


Converting a scanned TIFF document to PDF and creating text searchable PDFs

You can follow these steps to create a text searchable PDF document if your scanner only outputs TIFF files. If your scanner creates PDF files but doesn’t perform OCR to make text searchable, skip to the last step.

Convert TIFF to PDF

ImageMagick comes with a command line tool magick to do this.

magick convert scanned.tiff scanned.pdf

Executing this command creates a PDF file from a TIFF created by a scanner.

Optional: Rotate the PDF Pages

Sometimes the scanned pages will need rotating to the correct orientation. Use PDFtk to rotate the pages. Rotating all the pages in the scanned PDF by 90º anti-clockwise is achieved with the following command:

pdftk scanned.pdf cat 1-endwest output rotated.pdf

Individual pages can be selected and rotated as necessary, see PDFtk examples.

Perform Optical Character Recognition

For this step I resort to a copy of Acrobat Pro.

It would have been nice if I had succeeded in achieving good quality output for this step using open source software. Solutions do exist, mainly using Tesseract to do OCR and then forming a new PDF file with a text searchable layer hidden underneath the scanned images. See e.g. Voelkel’s and OCRmyPDF solutions.

However despite reasonable stabs, for various reasons I couldn’t succeed with either. The quality of the OCR output I was getting from Tesseract was lower than Acrobat. Also Acrobat offers the advantage that it performs small rotations to the pages to make sure the text is horizontal. So eventually I gave up on the open source route and now use Acrobat.

Note Acrobat can perform OCR on any PDF file. This is very useful for making old journal articles text searchable if the download offered by the publisher is not.


[Edit: 24 August 2018 – Updated ImageMagick command “convert” to “magick convert”]

Remove pesky PDF title pages and other PDF tricks


PDFtk command to remove a title page

Taking out pages from PDF files, binding PDFs together, and removing PDF security. Here are a couple of free programmes to perform these tasks.

Taking out pages from a PDF

Sometimes PDFs contain a title page or blank pages that you might want to remove. PDFtk Server is a useful command line tool that can take pages out from a PDF file. To remove the title page from a PDF file, run the following command:

pdftk input.pdf cat 2-end output output.pdf

Set the pages you want to maintain within the document after the cat command, and change input.pdf and output.pdf to suit.

Merging PDF files

You may wish to combine a journal article with its supplementary information, or with comment letters and author responses. Again PDFtk can do this. To combine two pdf files into one:

pdftk input1.pdf input2.pdf cat output combined.pdf

PDFtk can also perform a host of other useful tasks – see its examples page.

Removing PDF Security

Sometimes PDF files come with encryption settings that prevent you from doing the above, or from performing OCR on the document. I find that QPDF works well for removing the security settings, even if you do not know the PDF password. To remove the security settings from a file run:

qpdf --decrypt input.pdf output.pdf

However QPDF does not always succeed. An alternative is to use a PDF printer driver to ‘print’ an unencrypted PDF. Examples of such software for Windows include CutePDF, Bullzip, PDFCreater etc. Preview on Mac will also ‘Export as PDF’. Ghostscript can also perform this task:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf -c 
.setpdfwrite -f input.pdf

More Powerful Manipulation of PDFs

The python package pyPdf can be used to perform PDF file operations with the benefit of easy scripting ability. For instance when merging many hundreds of PDF sections of a larger document, each with a filename describing one part of the document (front matter, initial pages with Roman numerals, main pages…), I wrote a python script to merge the files in the correct order.

Edit 9th June 2015

Added ghostscript command to print to a new PDF file.

Switching from Feedly to Inoreader

Inoreader - nicely reminiscent of Google Reader

Inoreader – nicely reminiscent of Google Reader

It has been over a year now since Google shelved their web RSS aggregator, Google Reader. This was a bit of a blow for those of us who were using Google Reader, as it really was very good. Since Google closed the doors on the service I had been using Feedly.

Feedly never felt quite right however. For a start the interface was like Google Reader, but it also felt different. And different was not an improvement in this case.

Feedly forces you to use their bespoke app when accessing from an iPhone. Switching out from Safari into their app just to read news feeds was cumbersome.

Feedly also require that you login via a Gmail, Facebook account or suchlike to join them. This requirement never sat well with me. I used a Gmail account, but in terms of privacy it is unnerving how Google’s code is slowly pervading every site on the internet. Do not worry, the irony of this for this particular case is not lost on me.

The last straw was Feedly have recently started pushing ads for their $45 Pro service more prominently. Today I switched to another web-RSS reader, Inoreader.

In fact I have been using Inoreader for the past six months. When I joined JAEA I needed a separate RSS reader account for journal new article feeds. To create a second account with Feedly would have required handing over a set of social media account details to them. Therefore I looked elsewhere and found Inoreader. They let you create an account using any email address.

Inoreader is very similar to Feedly using the ‘List View’ setting, but more like the old Google Reader. The interface is definitely better. There is no need to use a separate app on the iPhone – their mobile site on Safari is perfect.

Switching between the Feedly and Inoreader was painless. You just export your RSS subscriptions from Feedly to an OMPL file, then import that file into Inoreader.

If you are looking around at different RSS aggregators, take a gander at Inoreader.