Monday, June 11, 2007

Mac for scientific computation: Part2

In this blog I continue from where I left. In the last post, I wrote a lot about terminal customization. Today I talk about a few programs on Mac, I found indispensable with. To make life easy, first install two applications 1) x11 and 2) darwin ports.
X11 is present in the Mac installation CD and can be found in optional software folder. X11 is required for X-Windows under ssh, matlab or any application which expects Linux environment. Darwin ports is available at darwinports.com and with the help of it, one can install lot of free software generally found in linux.

  • For Programming
For programming, we need compilers, editors and/or IDE's. The native IDE for mac is XCode, which is free and can be found in the mac os installation disk. Along with XCode, comes gcc compiler set. The path of gcc after installation is /usr/bin/gcc
For fortran 90 compiler, two free options are available. One is gfortran, which is developed by GNU and another is g95, a GPL compatible Fortran 95 compiler. I mostly use gfortran and it is available as a binary package at http://hpc.sourceforge.net. g95 is available with darwin parts. To install it, use the command
sudo port install g95
The above command installs g95 from darwinports repositories. Replace g95 with any application you want. If you want to look at all the available packages with darwinports, browse darwinports.com under the section "port categories". Since apple uses intel processors now, intel compilers are also available for intel macs. Intel compilers are available free of cost for personal use on linux. But on mac, they cost money. I bought intel fortran compiler (IFC) and use it mainly instead of gfortran. IFC can be integrated with XCode and actually I used XCode+IFC for writing and running a couple of programs. But I didn't like XCode, so I stopped using it. I don't say its bad, but for the small programs I write, it is too much. Also for fortran, there is another IDE called Photron based on Eclipse, but it is still not feature rich for me. So I settled with command line compiling. But I still feel the lack of GUI debugging. There is command line debugging option of using gdb, but I never tried to learn it, after getting spoiled by MS-Visual Studio.
Since I settled for command line compilation, I needed a good editor. On linux, I used to use gedit and at first I was looking for similar type of editor. In fact I installed full blow gnome from darwinports just for gedit. For some reason (I forgot now) I didn't like gedit on mac, and started looking for alternative. And I found jedit. Oh boy, what an editor it is! It has lot of features and lot of customization, its like finding a gold mine. It has fortran 90 syntax support, keyword case conversion, anti-aliased fonts, different set of options (like fonts, size..etc ) for printing and viewing, tons of plugins.... Just install and explore its features.
  • Document Creation
By document creation, I mean latex files and data plotting tools. For latex install MacTex package. Its huge and is approximately 700MB in size. It has TexShop as frontend and TexLive as backend. From my understanding, TexLive is now replacing tetex everywhere. On linux, I use kile as frontend for latex, texshop is very similar to it.
For dataplotting, gnuplot is available with aquaterm. You will see the results in aquaterm window, which has options to save the window to a file. One main advanteage with aquaterm is, it has the native aqua look. Install gnuplot from darwinports.
sudo port install gnuplot
All the dependencies are automatically resolved and all the required packages are installed. One word of caution, don't install aquaterm.app which is available separately. Install aquaterm from darwinports only. For cutting images, I use xv, which is also available from darwinports.

  • Fun stuff and others
Mac is already an excellent entertainment center. This section is only for enhancing it further. Most of the following things might be done by you already. Install Flip4Mac for wmv support in quicktime, divx, x264. Or you can install just install VLC. I found FrontRow support under VLC a little quirky. Handbrake is good for ripping DVDs and its free. Use UnrarX for .rar support. StuffitExpander supports rar but UnrarX is faster. Try Speed Download 4 (30 day trial period if I am correct) if you always download something like me. In my opinion its damn worth its cost.

This concludes the topic: mac for scientific computation. Most of the info given here is gathered from google. All credit goes to original posters. Also what I wrote here is my way of doing things. There may be better alternatives. If you think there exists better way, please reply.

Sunday, June 10, 2007

Mac for scientific computation: Part1




Last semester I got a sexy white Macbook with my adviser's money. I got it mainly because it looked cool. I knew very little about the OS other than its an unix variant. Over the period I configured, tweaked it, installed some software and it became a very productive tool for me. In this and next few blogs I will explain how I configured my Mac to suit my needs. Remember my needs are 1) programming, scientific computation and related stuff 2) presentations and document creation 3) fun stuff (movies, songs... etc.) 4) and all other.
  • Quicksilver
The first thing that comes to my mind w.r.t productivity is Quicksilver. Its a free tool and allows you type one or two letters and get the application you want. Its use is similar to Alt+F2 on KDE or gnome. Sure you can get all the important apps on Dock or look in Applications folder, but the programming guys know the importance of keyboard shortcuts. Some might say use Spotlight, but its slow for me.
  • Terminal
Terminal is important for all programmers using nix'es. Mac offers an application called Terminal.app and I found its better than other terminals like xterm because it has nice anti-aliased fonts. For anti-alias fonts explore window settings. But its text is monochrome. In linux, you find terminals displaying folders, files, executables, symbolic links in different colors. It helps in finding things quickly. To get colors for terminal you have to tweak it. After extensive googling, I was able to manage this. I am presenting all the info needed here. For getting colors, a variable called LSCOLORS has to defined. My .bash_profile file contains these lines
export CLICOLOR=1
#export LSCOLORS=ExFxCxDxBxegedabagacad
export LSCOLORS=gxexcxdxbxegedabagdcdx
Let me explain what the string means. The capital letters in the string display things in bold and small letters correspond to normal display. Each pair of characters corresponds to a file attribute. The first char corresponds to foreground and the second char of the pair corresponds to background. Here are the attributes in the order.

Directory
Symlink
Socket
Pipe
Executable
Block
Character
Exec. w/ SUID
Exec. w/ SGID
Dir, o+w, sticky
Dir, o+w, unsticky

As you see, there are too many attributes and if you specify different color for each attribute, you will get lost. I don't care if the executable has suid/sgid bits set or not (if you are a sysadmin in a big company, you may care). So I give identical colors to all executables and similarly for directories. Also you hardly encounter things like pipes and sockets in work folders. So don't worry about them. So the things we have to look at are 1st, 2nd, 5th and last two pair of chars. So in the string gxexcxdxbxegedabagdcdx I care only about things highlighted with color. Now how do we set the colors. Just look at the table below
a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background

Now you should be able to see colors in the terminal. Look at the picture to see how terminal displays files on my mac. But if you ssh to a linux machine, terminal again displays files in monochrome. To get colors when using ssh you have to do couple of extra things. If you open terminal preferences you will see an option saying how to define $TERM. This is the variable passed to the remote machine telling which (kind of) terminal you are using. For my machine, I defined it as xterm-color. In the linux machine, create a .dir_colors file in your home directory. Just copy /etc/DIR_COLORS and rename it. Go through that file and configure how colors should be displayed on the linux machine terminals. If you look into that file you will find lot of lines starting with TERM. There should be a line which corresponds to $TERM defined on your mac. I added the line
TERM xterm-color
Then add the following lines in .bashrc file on the linux machine.
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b ~/.dir_colors`"
alias ls='ls --color=auto'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
fi

This should help you to get colors with ssh also. Look at the picture to see how colors appear after sshing to a linux machine.

Saturday, June 9, 2007

My first blog

This is my first blog. From a long time, I was thinking of starting a blog, but putting off. May be I am lazy or not interested sub-consciously, I am not sure.
My blog's title is Physics, Computers and Programming. I choose this title for couple of reasons. First, I am doing my PhD in Physics. To be specific, my work is on theoretical calculations of properties of nanomaterials. And to be productive in theoretical physics, these days one needs to be proficient in programming. Also I am good at things related to computers: assembling, OS installation, programming..... I spend lot of time programming (now mainly in Fortran 90). I also used to waste my time installing all the major linux distros. Now I cut down that and settled with Suse. I also install linux for my friends. In the last one week I installed linux for two of my friends and installed Solaris 10(this became my new favorite) on my desktop. Plus I had 1+years work experience as a C/assembly programmer (but the title was DSP Engineer). As a matter of fact, when I first met my PhD adviser, I knew very little of Physics.
For this blog I am thinking of writing about things which come up in scientific computation. I won't be writing on interesting stuff in Physics; my knowledge in Physics is still deficient. I may blog about numerical techniques, Fortran 90/95(I hardly use C now), MPI-2,experiences with Linux and Solaris installations, and anything which interests me.