Jim Emery is a member of Kansas City’s STEM2 society. He has started a Scientific Programming Study Group recently at the CCCKC hackerspace. STEM2 is a group that promotes Science, Technology, Engineering and Mathematics. The topic is based on his document titled “Scientific Calculating, Programming and Writing” which can be found at the Stem2 web site.

Using Python

Jim chose the Python language for these sessions. It is a powerful language with many features that make scientific computing easier.

Getting Started in Linux

Since I’m using Ubuntu Linux, Python is already installed. To work through Jim’s examples I need to create the following new directories in my home folder “/vthompson“.

/bin

/tmp

/src

The next step is to open a command window and adjust the $PATH variable so any programs placed in the /bin folder can be found. First, keyin the command echo $PATH to see how this environment variable is already defined.

PATH Environment Variable

From the picture above, we see the /bin directory shows up in in several places. Surprisingly, the directory I just created in my home directory already shows up. How did this happen? The answer can be found in the hidden shell script also found in my home directory, vthompson/.profile. It contains the following code segment that automatically places a home directory’s /bin path as the first one in the PATH list.

# set PATH so it includes user’s private bin if it exists
if [ -d “$HOME/bin” ] ; then
PATH=”$HOME/bin:$PATH”
fi

Purpose of the /bin Directory

Linux is designed as a multi user operating system. While your desktop or laptop computer may not be used by other people logging into different accounts, using the home directory’s /bin folder prevents our special programs from interfering with someone else’s computer usage habits.

Now, its time to populate the /bin directory with files from the STEM2 software listing. The files we need are linux.zip and py.zip. Download and unzip the contents into /bin.

Trying a Sample Program

From Jim’s book, Chapter 6 on Graphing and Programmable Calculators, I’m trying the square root sample. I’ve created a /src directory to place my program source code into. Here is the sample program written using the gedit editor: