Tuesday 31 March 2009

Bash extract function

Extract function for bash. Put in .bashrc


function extract() # Handy Extract Program.
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}

Friday 27 March 2009

epstopdf

It's epstopdf joe not eps2pdf

Fixing backspace on edred vim

To fix the backspace key on the vim on edred add this to .vimrc

set backspace=indent,eol,start

Thursday 26 March 2009

latex figures

To get rid of strange behaviour in latex where it does weird things with figure numbers its has to be done in a strict order.

\begin{figure}
\begin{center}
\includegraphics{...}
\end{center}
\caption{...}
\label{...}
\end{figure}

I think caption can go above \begin{center} but it must be outside of the centre section

Gnuplot PDF+Latex files

To create a pdf file from gnuplot with latex text do the following:

In the plot use the terminal:
set terminal epslatex


Then convert the eps to a pdf file.

Include the figure using
\input{figure.tex}

Wednesday 25 March 2009

Printing variables from gnuplot to a file

To output variables such as fitting parameters from gnuplot use.
set fit errorvariables # creates a_err type variables for fitting errors
set print "tmp.dat"
print a,a_err,b,b_err

Tuesday 24 March 2009

Labeling figures in Latex

If labeling of figures has gone wrong in latex it's probably because the \label{} must be at the end of the figure block after the includegraphics and caption.

Compiling OpenMPI with Intel Compilers on Ubuntu

Compiling OpenMPI with Intel compilers can be a bit of a nuisance, and so the following seems to work with version 11.074 Intel Compilers, OpenMPI v 2.8.1 and Ubuntu 8.10:

1) Install The Intel Compilers with defaults
2) Put iccvars.sh and ifortvars.sh into /etc/profile.d, and comment out the lines referring to non 64 bit binaries
3) source /etc/profile
4) Unpack the OpenMPI
5) Run ./configure --with-fortran CXX=icc FC=ifort LIBS=-lstdc++
6) type LANG=C
7) make all
8) sudo make all install
9) sudo ldconfig
10) type mpiCC --showme to verify the compiler wrappers are working correctly

Awk Scripting, combining columns

If you have multiple files named filename.< a number > e.g. filename.0, filename.1, filename.2,filename.3 etc then you can take an average of multiple columns using awk as below:

you need to know how many files you have, in this num_files=16, and you need to know the total number of columns per file in this tot_num_cols=13. Here I wanted to average colums 1 and 4. Using the paste command which pastes a number of files to the screen side by side and piping to awk the script will output the average of columns 1 and 4 to a file called anewfile.txt

paste filename.* | awk 'BEGIN{num_col=4;num_files=16;timecol=1;tot_num_cols} {c=0; for (j=0;j < num_files;j++){c+=$(timecol+tot_num_cols*j)}}; s="0;" i="0;i < ="num_files;i++){s+="$(num_col+tot_num_cols*i)};" > | anewfile.txt

Bash number formatting

Use printf as in c. For zero padding add a 0 infront of the field length, eg: %06i

So to delete more files than rm can handle

for i in `seq 0 100`; do file=`printf "%06i" "$i"`; echo $file; done