Tuesday, 3 May 2011

Spell checking LaTeX documents

Spell checking a LaTeX document is different from spell checking a plain text document, since the LaTeX document contains commands that should be ignored by the spell checker. For example, consider this command for including a figure with a caption:

\begin{figure}
\centering
\includegraphics[width = 7cm]{image1}
\caption{Focused image of piont scatterer.}
\end{figure}

Here, a spell checker should not suggest changing "\includegraphics" to "include graphics", but it should suggest changing the misspelled "piont" in the caption to "point". Luckily, there are spell checkers that interpret LaTeX commands, and I am currently using one of them, Aspell. In Linux, Aspell is easily installed by the following commands:

apt-get install aspell
apt-get install aspell-en

which installs both the program and the english dictionary. To spell check a LaTeX file called paper.tex on the command line, type

aspell -c paper.tex

Note that Aspell (and its relative Ispell) can also be used at runtime by text processing programs like Kile.

Thursday, 28 April 2011

Concatenating binary raw data files

At my company, Breivoll Inspection Technologies, we perform inline ultrasound scans of water pipelines, and the resulting raw data is stored in a number of binary files for postprocessing. I was looking for a simple way to combine these files, and found out that the familiar cat command (on Linux) does the trick:

cat *.dat > mergedFile.dat

This concatenates all the .dat files in the current directory and outputs them into mergedFile.dat. Note that although cat is often used for text files, it works just as well for binary files.

Another note: In some cases, a raw data file may contain headers or footers that should not be included when the files are concatenated. I found a simple solution in this forum post. For binary files, a number of bytes can easily be stripped away from the beginning and the end of the file by using the dd command, for example:

dd if=input.dat of=output.dat bs=1 skip=X count=Y

This skips the X first bytes of the input file, and writes the following Y bytes to the output file. See the help section on the dd command for more options.

Sunday, 3 April 2011

The Acoustic Ghost in the Machine

I came across this awesome article when doing research on another topic. Haunting "supernatural" events can be explained by simple acoustics - infrasonic waves are the Ghost In The Machine! :D

Abstract: In this paper we outline an as yet undocumented natural cause for some cases of ostensible haunting. Using the first author’s own experience as an example, we show how a 19hz standing air wave may under certain conditions create sensory phenomena suggestive of a ghost. The mechanics and physiology of this "ghost in the machine" effect is outlined. Spontaneous case researchers are encouraged to rule out this potential natural explanation for paranormal experience in future cases of the haunting or poltergeistic type.

Wednesday, 19 January 2011

Inline comments in LaTeX

I recently got some feedback on an article that I've submitted, and when I started including the reviewer's comments in the revised version, I started wondering if there is a way to make an "in-line" comment in LaTeX documents. I often use the percent sign, %, to comment out everything after a line, like this:

... and thus we see that these methods are equvivalent. % Or are they?

After some searching I found an interesting post on Eric Rasmussen's blog, and it seems that the easiest way to do this is to define a "macro" that doesn't do anything, in the document preamble:

\newcommand{\comment}[1]{}

and then I can make an inline comment using the \comment{} command, like this:

... these methods are equvalent. \comment{Or are they?} Luckily, it doesn't matter...

Thursday, 13 January 2011

Compressing Matlab AVI videos in Linux

Recently I've started making a few movies in Matlab. This is actually quite easy - for an example see this description from the Matlab documentation. Unfortunately, the movie2avi() function does not apply any compression when writing the movie to file (not in Linux, anyway), and this results in very large movies (on the order of 100 MB for a few seconds).

However, I found a solution. I originally posted it as a reply in the MATLAB Newsreader, but I thought I'd share it here as well:

You can transcode Matlabs AVI movies using FFmpeg (www.ffmpeg.org). If you don't have the package, you can install it using the terminal:

sudo apt-get install ffmpeg

If you have only one file, let's call it inputFile, you can transcode it using something like this:

ffmpeg -i inputFile.avi -sameq outputFile.avi

The "-sameq" option is used to preserve video quality. I tested this on a 80 MB file produced by Matlab, and got a 5 MB file without any visible loss in quality. If you want to do it within your matlab script, use the system() command:

system('ffmpeg -i file1.avi -sameq outputFile.avi')

If you have a problem with the Matlab AVI file growing too big, you can split it into several smaller files and compress them as you go, and finally combine them after your iteration has finished. A way of doing this is described here in the FFmpeg FAQ. Note that you will have to transcode your intermediate files to MPEG format. .

Thursday, 11 November 2010

Printing to pdf from Matlab via eps

I use pdflatex for my publications, both because it is convenient to have PDF as the output format, and also because it accepts many kinds of graphic files, like JPG and PNG. If you want to use a vector graphics format, then you can save your graphics as PDFs. This is quite easy to do in Matlab, but I have found that it often leads to rasterization artifacts in the graphics. Exporting to EPS seems to work a lot better in this regard. The solution: Exporting from Matlab in EPS format, and postconverting to PDF using the esptopdf function (part of the texlive-extra-utils). I have made a Matlab function to automate the process:

function printpdfviaeps(filename, varargin)
%PRINTPDFVIAEPS Print current figure to pdf via eps
%
% printpdfviaeps(filename) will save the current figure to filename.pdf,
% using a default paper size of width = 12 cm, height = 9 cm.
%
% printpdfviaeps(filename, width, height) lets you specify the width and
% height yourself.
%
% Martin Skjelvareid, 2010-11-11

width = 12; % Default width in centimeters
height = 9; % Default height in centimeters

if nargin > 1
width = varargin{1};
end
if nargin > 2
height = varargin{2};
end

set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperSize', [width height]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 width height]);

print('-deps2','-r150', filename)
system(['epstopdf ' filename '.eps']);
delete([filename '.eps'])

Monday, 8 November 2010

Resetting ssh server host key

Today I tried logging on to a server that was recently down due to a brute force attack. Using the SSH command resulted in the following warning:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.

[...]

In this case, the problem was that the RSA host key had changed. After searching the net for a while, I found that some people routinely delete their known_hosts file because of this. However, there is a proper solution to the problem, as presemted by *ccm* in this blog post:

ssh-keygen -R

where is replaced with the name of the server that you're trying to connect to.