Anders Andreasen Blog

Just another WordPress.com weblog

Archive for the ‘Python’ Category

gfortran headaque reading from piped input

leave a comment »

UPDATE: I have investigated further and it seems that it is somehow related to differences between stdin when read from a redirected file and a pipe stream. I tested with Sun Studio and received a similar error, so it seems that this is not compiler specific. Btw. the code I am testing/wrapping fails when trying to “BACKSPACE”  (previous record) in the read input. Found some info that might relate somehow to the difficulties I am facing at the Intel Forum.

My current  hobby project is trying to wrap a NASA legacy program for chemical equilibrium calculations (NASA CEA) in python. The first step has been tweaking the program to read input from stdin (unit 5 in fortran)  and write output to stdout (unit 6 in fortran). In its current state it reads from an input file and writes to another file. This was faily easy to accomplish by changing the unit numbers. So far so good. It works fine if a run the program with stdin and stdout redirected like

cea2 < input > output

However, things go wrong if i use piped stdin like

cat input | cea2 > output

I really need this, since I would like to use the subprocess.Popen in python in order to communicate with the program through piped input.

I am not a fortran programmer, and it is likely that I have done something wrong. This has been my working hypothesis so far. The program fails with a message saying somthing like “Illegal seek” and the IOSTAT exit code is 29 (STATUS= specifier on an OPEN statement is invalid. According to this site), and it happens when the program tries to “backspace” in the read input. Somehow it may be stock at the end of file or something like that. A lot of googling didn’t bring up much, except this bug report for gfortran. According to the mail archive it should be fixed in versions 4.4, 4.5, and 4.6. I am running Linux Mint 11 with gcc 4.5.2. However, the upstream bug fix may not have surfaced in the downstream gcc package installed on Mint 11. I will try a live distro with gcc 4.6 one of these days, likely Mint 12, to see if it helps.

I have set up a google code site in order to maintain the work done, I have called the python wrap for cea2py.

Advertisements

Written by aandreasen

January 17, 2012 at 11:21 am

pydb not working properly on Ubuntu 9.10

with 7 comments

I was trying to use pydb with ddd in order to debug a python script. However when invoking ddd with e.g.
ddd script.py
ddd clamied that it could not find pydb. I tried running pydb from the command line and I was left with a message like
The program 'pydb' is currently not installed. You can install it by typing:
sudo apt-get install pydb
pydb: command not found

Ok, so I tried to install it
sudo apt-get install pydb
Reading package lists... Done
Building dependency tree
Reading state information... Done
pydb is already the newest version.

Hmmm, strange. Google, google, google……….
It turned out that some else had experienced the same problem as me and provided a fix. Apparently the link to pydb in /usr/bin is broken. The fix is
sudo rm /usr/bin/pydb
sudo ln -s /usr/lib/python2.4/site-packages/pydb/pydb.py /usr/bin/pydb

Written by aandreasen

March 18, 2010 at 8:46 pm

Posted in GNU/Linux, Programming, Python, Ubuntu

Tagged with , , ,

Installing cantera 1.8 on Ubuntu 9.10 (32 bit)

with 35 comments

Note: I just checked that the procedure (svn) given below also works for Ubuntu 10.10, and it does.

Here’s a brief description on how I managed to compile and install cantera 1.8 on Ubuntu 9.10 (32 bit), with the full python interface. However, first a little description of what cantera is (taken from the website):

Cantera is a suite of object-oriented software tools for problems involving chemical kinetics, thermodynamics, and/or transport processes.

Cantera is written in C++, and can be interfaced also from python, matlab and Fortran.

  1. First step is to install any dependencies. This is handled by apt-get:
    sudo apt-get install subversion g++ gfortran python2.6-dev python-numpy libsundials* graphviz
  2. Next step is to get the source for cantera. This can be done by either downloading the cantera-1.8.0-beta-tar.gz from the cantera site our checking the latest version from svn
    svn checkout http://cantera.googlecode.com/svn/cantera18/trunk/ cantera
  3. change to the cantera directory (either the svn checkout or the untarred/gunzipped cantera-1.8.0)
  4. Edit the file named preconfig and make sure the following lines are included by uncommenting/editing
    PYTHON_PACKAGE=${PYTHON_PACKAGE:="full"}
    USE_NUMPY=${USE_NUMPY:="y"}
    SUNDIALS_VERSION=${SUNDIALS_VERSION:='2.3'}
  5. The entire preconfig file can be viewed here
  6. then in a terminal run the following commands
    ./preconfig
    make
    sudo make install
    source ~/setup_cantera
  7. If everything went well you should be able to import the Cantera module in python:
    python
    >>>from Cantera import *

Written by aandreasen

January 28, 2010 at 11:06 pm

Fedora 12. Probably the best GNU/Linux distro in the world?

leave a comment »


I have recently installed Fedora 12 on my computer (laptop). I have used Linux for many years, and my best experience has been with Debian derived systems like Debian itself, Ubuntu and Mint, so far. However, when I started out using Linux it was on RedHat 6.2, although I jumped the RedHat wagon after 8.0. Nevertheless, I thought it was a good time now to see the current state of the RedHat upstream development.
To jump to the conclusion rigth away, I really like Fedora 12. To be more specific:

  1. Installation was very easy just as easy as Ubuntu, in my opinion
  2. Very good and professional documentation
  3. The amount of scientific packages is very good. Numpy, Scipy and Matplotlib is included. Other useful apps: Xmgrace/Grace, Octave, DX, R, hdf5, maxima, paraview
  4. The Gnome NetworkManager comes with good stuff preinstalled e.g. vpnc (Cisco VPN client) and for some reason it seems to connect to my home router faster than on Ubuntu/Mint. Although this is only a subjective impression.
  5. Eclipse comes with many useful plugins e.g. pydev, valgrind. Unfortunately the eclipse sql explorer plugin is not one of them. However, installation is easy,
  6. Compiz works very well. It has caused me some trouble to make it work on OpenSUSE 11
  7. Gnote instead of Tomboy. I have never been a fan of .Net/Mono. Again this is my personal opinion
  8. The default configuration of Gnome is good, and pleasant
  9. YUM is very easy to use. Very much like APT. The yum history command is very useful

In order to get a full installation, even with applications such as Adobe Reader, VLC, Google Earth, Google Picasa, Skype, RealPlayer, I can recommend to go through the step-by-step guide on HowtoForge. It is extremely useful. Cadeau!

However, I have found a few things I do not like so much about Fedora 12, which has pushed me towards CentOS 5.4 instead

  • For some reason when resuming from suspend/hibernate Xorg crashed leaving me with a new gdm login screen leading to a blank desktop with all my apps gone (Intel MobileGMA 965). I haven’t found a fix, according to the mailinglists/bugzilla the issue should have been resolved (but obviously its not). Works out of the box in CentOS.
  • Couldn’t find a way to get CPU throttling to work i.e. the “On demand” mode. Whenever trying to force this mode I was always reverted to “Performance” i.e. full speed. No problem for workstation doing heavy calculations all the time, but for a laptop it’s really a nive feature. This works out of the box in CentOS.

The post is brought to you by lekhonee v0.7

Written by aandreasen

December 5, 2009 at 8:35 pm

Posted in Computers, GNU/Linux, Python