Friday, November 28, 2008

Find matching bracket in Vim

Just position cursor on a bracket and press % to go to the matching bracket!

Friday, November 14, 2008

Linux shell I/O redirecting

./my_script > file <-- Redirect standard output
./my_script 2> file <-- Redirect error output
./my_script &> file <-- Redirect all output
./my_script > file 2>&1 <-- Combined error and standard output

Friday, July 11, 2008

gnuplot + PlotDrop - plotting the data for high quality IEEE publications

gnuplot is a command-driven interactive function and data plotting program. PlotDrop is its simple and user friendly frontend. PlotDrop can be used with latex/pdflatex for generatating high quality figures for IEEE publications, theses, etc. Beside the limited number of gnuplot commands that are available through the GUI, PlotDrop enables specifying arbitrary commands through the Extra tab (command line style). The following gnuplot commands are more or less what I use when generating figures for IEEE publications:

  • set terminal postscript eps enhanced solid monochrome "NimbusSanL-Regu" fontfile "/usr/share/texmf-texlive/fonts/type1/urw/helvetic/uhvr8a.pfb"
1. enhanced flag enables enhanced text features (subscript/superscript)
2. solid flag makes all the lines non-dashed
3. monochrome flag makes all the lines black
4. "NimbusSanL-Regu" fontfile "/usr/share/texmf-texlive/fonts/type1/urw/helvetic/uhvr8a.pfb" - construct sets the default font to NimbusSanL-Regu instead of Helvetica and enables font embedding in the pdf (useful for IEEE papers produced with latex/pdflatex).
  • set size 0.75,0.75 - Scales the graph and not the fonts, so the fonts are bigger at the output.
  • set key bottom right - Puts the "legend" at the bottom right corner. Valid flags are: top, center, bottom, right, left, above, below, outside and inside. Also, you can specify absolute coordinates of the top-right box corner within the plot coordinate system, as follows: set key at 4.2,0.2.
  • set key spacing 2 - Increases the vertical spacing between labels in the "legend".
  • set key box - Draws the box around the "legend".
  • set key width 1 - Increases the key box width by the width of 1 character.
  • set pointsize 1.5 - Sets the point (marker) size at 1.5 (default is 1).
  • set bar 1.5 - Sets the bar size at 1.5.
  • set ytics nomirror - Remove tics on the right (vertical) border line.
  • set xtics nomirror - Remove tics on the top (horizontal) border line.
  • set tics out - X and Y tics point outside instead of inside of the axes.
  • set title font "NimbusSanL-Regu,20"
  • set ylabel font "NimbusSanL-Regu,20"
  • set xlabel font "NimbusSanL-Regu,20"
  • set label font "NimbusSanL-Regu,20"
The previous four commands set title, y-axis and x-axis label and other labels fonts to NimbusSanL-Regu, size 20.

With this setup you can generate very good figures in ps/eps/fig/latex/etc. formats (Plot->Plot to file). To import figures in pdflatex you have to convert ps to pdf. For this conversion use epstopdf and not ps2pdf!

Check if fonts are embedded and subset in a pdf file

In GNU/Linux you can check if a pdf file has embedded and subset fonts with the following command:
pdffonts mypaper.pdf

Monday, June 23, 2008

Using Vim + ctags for easy locating of "#define" variables

If you want to find where some variable is defined in C code, you can use:
Ctrl-]


in Vim editor. However, this does not work for "#define" variables until you execute:
ctags *.h *.c


on all .c and .h files that you want to tag. After that you can search for "#define" variable using Vim's Ctrl-] command. In order to return at the original position (before the search) press Ctrl-T.

Executing shell commands through Vim

If you don't want to terminate Vim to execute a shell command just type: :! shell_command. How cool is that?

Wednesday, February 27, 2008

Nice code printing with a2ps

a2ps --line-numbers=1 --columns=1 -R -T4 -f5 -o output.ps input.c







SwitchMeaning
line-numbersturn on/off line numbers
columnsnumber of columns on the page
Rportrait mode
T4TAB size is 4 spaces
f5font size
o stringoutput file name