Elegance in Computer Science

June 7, 2010

Converting Pictures and merging pdf files

Filed under: ghostscript, pdf-merge — abdullah @ 09:42

I was working on a problem in graph theory sometime back and I had to work with images in png format generated by pigale. Instead of manually converting png into pdf files by printing. I decided to use shell scripts to do the same. There is a program called sam2p to convert a png file to pdf via the command line and this is how you do it.

for png in $(ls *.png)
do
	sam2p $png $png.pdf
done

So, now that I had converted every png file to a pdf file, I wanted to merge all the generated pdf files into a single pdf file so that I can peruse the pictures more easily. Thus, in order to merge the pdf files I used a program called Ghostscript which is invoked by calling gs.

rm all.pdf
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=all.pdf -dBATCH *.pdf

The output obtained after combining all pdf files is here. It is a trace of an algorithm that I was trying to develop on a sample planar graph. I tried to develop an algorithm to partition a planar graph into two outer planar graphs but I have not (yet) been able to do it.

In order to view more information regarding sam2p or gs, view their respective man pages by typing

$ man sam2p      #For sam2p man page
$ man gs            #For Ghostscript man page



May 22, 2010

My Latex Guide

Filed under: latex Intro — abdullah @ 12:38

I have been pretty busy for the past couple of months forming the ideas for my thesis and then creating presentations and the like using latex. More specifically, I created a presentation, and am in the process of creating a report for my thesis. Most of the content is available online here.

In the process, I have come to learn a lot about latex. Unfortunately, most of the documentation out there is not exactly the way I would have liked to have it explained to me. Hence as I was working on my presentation, I had intended to provide my own very quick introduction to how things work. I could not go ahead with it, however, and am still hampered with a lot of pending work with respect to the thesis report. But a few days back, someone requested me for some help to get started with latex and this spurred me to create a small page here explaining things in my way.

I have tried to give a very quick and easy hands-on way of getting going with latex. The spirit in which I would like to convey things is there. However, there will be lots of scope for improvement and in case you have any feedback please do comment here and let me know. Hopefully, the page will be of some help to beginners to latex.

Once again the page is http://linuxandlisp.com/blog/latex-for-absolute-beginners/, hopefully, a sign of more things to come.




April 12, 2010

Installing and Running jpf source code (on the command line)

Filed under: Formal Methods, Verification, jpf — abdullah @ 06:47

In this post we shall investigate how to obtain and install the jpf source code.

Obtaining the Source code

In order to obtain the jpf source code we must follow the steps listed below:-

  1. The source code of Java Path Finder is currently maintained as mercurial repositories. As I already mentioned here, for debian-based distributions, all we have to do is
    sudo apt-get install mercurial

    On other operating systems, you have to follow the general installation procedure that is used in your systems after obtaining the software from mercurial’s website.

    In the following steps, you will be using mercurial to obtain and install the jpf source code. You may want to read the tutorial on how to use mercurial, here, before we proceed.

  2. The command used to obtain the source code from the jpf web site is
     hg clone

    As the name suggests, we are actually cloning the complete folder as it is on the repository online. You will definitely need the jpf-core component and it is also sufficient to have this module to get started. As suggested on the jpf web site, I created a default folder called ‘projects’ and cloned the jpf-core component inside this folder. Thus the commands that I entered, were as follows,

    $mkdir projects
    $cd projects
    $hg clone http://babelfish.arc.nasa.gov/trac/jpf/wiki/projects/jpf-core jpf-core
    
  3. Having obtained the source code, we now verify if the code was obtained correctly by typing in
    $cd jpf-core
    $hg verify
    

    If you get an output similar to what is given below, without any error reported, then the clone was successful, else there was some problem while downloading and you may have to clone the repository again.

    checking changesets
    checking manifests
    crosschecking files in changesets and manifests
    checking files
    1727 files, 157 changesets, 2369 total revisions
    abdullah@abdullah-desktop:~/projects/jpf-core$
    

Upon successful completion of the above three steps, we would have obtained a copy of the jpf-core component. In order to obtain the source code of other components we have to follow the same above procedure but change the site name appropriately while cloning (step 2).

Building the source code

Now, that we have the source code for a particular component, in order to build the source code and create the executables, all we have to do is enter the following command,

$cd ~/projects/jpf-core
$bin/ant test

The above code will create all executables in the appropriate sub folders of the source directory.

Updating the site.properties file

Lastly, in order to configure the jpf-core component we need to create and update a site.properties file. In order to do that, type in the following commands,

$cd $HOME
$mkdir .jpf
$gedit site.properties

The text editor will open up and you have to enter the following

jpf-core=~/projects/jpf-core

The above line indicates the location of the source code for the jpf-core folder in your system. So, make appropriate changes to the location address if needed.

Running jpf

To run jpf on a sample program check the previous post, the only change that has to be made is that, instead of,

$~/binaries/jpf-core/bin/jpf +classpath=.  Rand

we have to type in the following,

$~/projects/jpf-core/bin/jpf +classpath=.  Rand



Older Posts »

Powered by WordPress