Programming tidbits

Mendeley script for abbreviating journal names

I needed to make a few modifications to brainstorm’s script to make it run on my Mac OSX. The new version is here:

#!/bin/bash
db="/Users/rcusack/Library/Application Support/Mendeley Desktop/rhodricusack@gmail.com@www.mendeley.com.sqlite" # set the db-file here. The location depends on the OS you use.
limit="WHERE confirmed='true' AND type='JournalArticle'"
sqlite3 "$db" "SELECT id FROM Documents $limit" > temp_ids.txt
cat temp_ids.txt | while read line
do
long=$(sqlite3 "$db" "SELECT publication FROM Documents WHERE id=$line")
echo "long = $long"
echo "The id is $line"
line_pubm=$(grep -i -n -m 1 "$long" J_Medline.txt | cut -f1 -d:)
echo "linenumber in pubm= $line_pubm"
abbr_linen=$(( $line_pubm + 1 ))
short=$(sed -n ${abbr_linen}p J_Medline.txt | sed 's/MedAbbr: //' | tr -cd '[:alnum:]')
echo “short= $short”
LEN=$(echo ${#short})
echo $LEN
if [ "$short" ]; then
echo $short
echo $line
sqlite3 "$db" "UPDATE Documents SET publication='${short}' WHERE id=${line}"
# sqlite3 $db
# make a security update of your sqlite-file and replace the echo from above with sqlite3 $db
else
echo "no or short shortname (<3 chars) - not changed"
fi
done

Computing blog

This blog describes the latest updates to our computer systems

Getting to grips with complex Matlab structures

When dealing with (other people’s) complex Matlab structures that have layers of branching, it can be hard to find the field you need. I find it convenient to dump the structure as XML and then look or search it in a text editor. Download xml_write to somewhere it your Matlab path and type

xml_write('dumphdr.xml',mystructure);

Accurate timing in Matlab

Matlab’s tic and toc commands have high accuracy on many platforms and can be used for precise timing. You can check for your platform with feature(‘timing’,'resolution_tictoc’). You might also want to use the syntax tstart=tic; which gets the 64-bit timer value.