General
Geophysics
Links

How do I use Cygwin in Geophysics ?


While there are a lot of nice tools and programs in the Linux/Unix world, to simplify the life of a seismologist, the Windows-world is nice for your daily computer life (see section on Tools).
CYGWIN allows to run a Linux environment within your Windows system. Here, some Tricks and Tips are provided on howto install and compile several standard geophysical utilities under Cygwin.

DISCLAIMER: It did work for me on WindowsXP using CYGWIN 1.5, but I can't guarantee it will be working in your case :-)



Cygwin Installation

You may want to switch off your anti-virus program duriing installation
You may also want to run installation setup program as administrator CYGWIN is a Linux-like environment for Windows, with a collection of tools which provide Linux look and feel. CYGWIN is not a way to run native linux apps on Windows. You have to rebuild your application from source if you want it to run on Windows.

The CYGWIN installation you will need differs from the minimal (default) setup. Most of the programms described here won't work without these additional packages! Luckily, the CYGWIN setup tool provides comfortable means to setup your system...

In addition to the default setup, you will need the following packages:

=====================================================
1) Packages which need to be installed
 Devel:
    - gcc-g++
    - gcc4-fortran
    - libncurses-devel
    - make
    - readline
 Libs:
    - sunrpc
 X11:
    - xorg-server
    - libX11-devel
    - libXt-devel
    - xinit
 Net:
    - inetutils (collection of internet utils, e.g. "ftp")
 System:
    - util-linux (collection of linux utils, e.g. "more", "dos2unix")

=====================================================
2) some nice-to-haves (but not required!!!)
 Editors:
    - nedit
    - nano
 Net:
    - openssh
 Shells:
    - rxvt (terminal with copy-paste function)
=====================================================

If you still encounter problems, you might want to compare your installation with mine. Type

cygcheck -c -d

and compare it with this one (version numbers shouldn't matter).

Page Top

gfortran compiler

gfortran is a compiler for the Fortran95 programming language. However, unlike g95, it is not included in the standard CYGWIN GCC3 collection. There is however a CYGWIN binary on the GCC homepage. Follow the installation instructions provided on that page.
NOTE: The GMP and MPFR packages must be installed for gfortran to work.

Alternatively, you can install GCC4, which works fine in the lates release (1.7.x) of CYGWIN

I encountered an issue with GCC4 that it displayed weired characters in warnings and error. It seems to be an internationalisation issue. You therefor may want to set you LANGUAGE and CODEPAGE:
export LANG=en_US.20127

Page Top

Ready for X

Most of the time you won't need any Xwindows running at all! A basic terminal is enough. However, the default termial used by cygwin is a bit dull, and you can't personalise it as much. A very good alternative to an XTerm is the RXVT terminal. It starts up quickly, doesn't need (but allow) an Xserver in the background, but best of all: RXVT allows a Copy-and-Paste functionality to the middle-mouse button, something MicroSoft should have long adopted for its system! Well...

Personalised Appearance

If the rxvt.exe is launched without arguments it will run like a regular DOS shell without the bash environment. In order to launch in properly you need to create a new shortcut and customize its arguments. Here is how to do it: In Windows Explorer go to C:\cygwin\bin and right-click on rxvt.exe and choose Send To -> Desktop (create shortcut). Now right-click on the shortcut it just created on the desktop and choose Properties.
Select the Shortcut tab and change the entry under Target to:

C:\cygwin\bin\rxvt.exe -sl 1500 -fn "Lucida Console-12" -bg black -fg grey -sr -e ./bash --login -i

This will now launch rxvt correctly with a decent looking font, a black background with white text, and 1500 scrollback lines. You can also play around with the font type and size, for example you could also use:

C:\cygwin\bin\rxvt.exe -sl 1500 -fn "Lucida Console-12" -bg wheat -fg grey -sr -e ./bash --login -i

You get the basic idea...

However, You can set all this (and more) in a file called .Xdefaults, located in your home directory. Here is my version of it! You may notice that I also changed the default colors. You can use the scripts colors.sh to see the different colors available now.

REMEMBER: Whenever you download a text file from the browser for use in CYGWIN, the line-endings are in MS-Dos Format (\r\n) and you need to run a dos2unix -u filename first.
The only thing left, is creating a shortcut on the Desktop, with the follwoing Target (command line):

rxvt.exe -e ./bash --login -i

and Start in:

C:\cygwin\bin\

You may also want to change the icon (there are nice ones in the C:\cygwin\bin\rxvt.exe), but that's only cosmetics...



Page Top

Your .bashrc

The .bashrc is located in your home directory and contains lots of personalised settings: Here is my version of the .bashrc! Be sure you adopt the paths correctly. Some of the settings are specific to several programms and will be discussed below.

Command Prompt

The suggested Command Prompt will look somewhat like:


HOSTNAME: /Current/Directory/Name/
username > echo "something"

this is achieved by setting the PS1 environment variable to

PS1='\n\[\e[01;30m\]\h:\[\e[34m\]\w\n\[\e[00;32m\]\u\[\e[0m\] > '


Alias

Some of the aliases are well established, so I'll point out only a few:
alias open='cygstart'
I just think open is more handy to type and remember... cygstart actually allows to open a Windows Application from CYWING shell

cygstart report.doc (calls word)
cygstart . (Open explorer)
cygstart / (Open explorer)
cygstart http://www.cygwin.com
cygstart --print README.txt
cygstart --maximize ~/projects/whatever/design.doc
cygstart -x . (Open explorer)

alias s='source ~/.bashrc'
If you make lots of changes to your .bashrc this is quite usefull...

alias ..='cd ..'
alias ...='cd ../..'
Go up one or two directories, respectively...

alias X='XWin -multiwindow -clipboard -nowinkill -logverbose 0 &'
This actually starts the X-server in the background, without opening any windows. Type man XWin to learn more about the options...

mount --change-cygdrive-prefix /
Not stricly an alias, but handy anyway. This mounts your Windows Harddrives (C:\ D:\ ) to the root direcectory as /c and /d instead of /cygdrive/c and /cygdrive/d

Note, that there is a nasty bug in nedit in combination with Xorg7.4, but you can get around this by adding the following line to your .bashrc

export XLIB_SKIP_ARGB_VISUALS=1

See for more details http://cygwin.com/ml/cygwin-xfree/2008-11/msg00017.html

Page Top

Interaction with Windows

You do know already the cygstart or open command to open a file with its default Windows application. But in the Linux world you often handle text files without extension or strange extensions unknown to windows. But you still want to edit them in your windows editor:
First we have to determine the Linux-pathname to your programm-directory:

PROG="$(cygpath -u "$(cygpath -m -s "${PROGRAMFILES}")")"

This is necessary to get rid of the anoying space-characters in the english version of WindowsXP ("Program Files"). Now we can define a little function (an alias would not correctly translate the pathname to Windows format):

edit (){
    $PROG/Notepad++/notepad++.exe $2 "`cygpath -w $1`" &
    #second argument, e.g. -n150 opens file at lineNumber 150
    }

Now typing edit ~/.bashrc opens the .bashrc in Notepad++.

Page Top

Connections

This section describes how to connect to other (Linux) computers in the network using ssh whithout having to type the password every time. It is based on James Wookeys Mac Eye for the Geophysics Guy.
"If there are machines you regularly log into / remote copy to it is very handy to be able to do so without a password. This is helpful for example if you want to set up a backup script or similar which copies files to a remote server when you are not present. The simplest way to do this is with a Public-Private key pair with an empty passphrase"
Ah! Yep, allright, so what does that mean?

Assume, you regularily need to login from "HOSTNAME" to "SERVER". In order to do that without typing your password each time, do the following. Note that you need to leave the passphrase empty:


HOSTNAME: /Current/Directory/Name/
username > ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_dsa.
Your public key has been saved in /home/username/.ssh/id_dsa.pub.

HOSTNAME: /Current/Directory/Name/
username > scp ~/.ssh/id_dsa.pub username@SERVER.SOMETHING.EDU:

HOSTNAME: /Current/Directory/Name/
username > ssh username@SERVER.SOMETHING.EDU
password: xxxxx

SERVER: /home/username/
username > cat ~/id_dsa.pub >> ~/.ssh/authorized_keys2

SERVER: /home/username/
username > exit

HOSTNAME: /Current/Directory/Name/
username >

You should now be able to log onto "SERVER" without being prompted for a password.

Page Top

Matlab

Right, this is about how to combine two powerful tools: MatLab and Cygwin. That is correct, you can access your CYGWIN environment from within Matlab, you can for example access a remote computer using scp and ssh or, you can call GMT directly!

Mainly, the only thing you need to do is make the CYGWIN executables available to your Windows PATH variable. In WinXP this can be done in

"System Properties" > "Advanced" > "Environment Variables"

Edit the value of the PATH variable to append the CYGWIN path to the programs you want to use, for example ;C:\CYGWIN\bin;C:\CYGWIN\Soft\GMT4.2.1\bin
You may need to RESTART Windows!

Now, in Matlab, you can launch your programs using the ! command syntax. Try for example (in Matlab)

>> !psxy
>> !man pscoast
>> !pscoast -R-30/30/-40/40 -Jm0.2c -B5 -Gtan -S100/149/237 > africa.ps
>> winopen('africa.ps')

NOTE:For some reason that only seems to work if a CYGIWN window (Xterm, RXVT,...) is open. So you need to have this runnign in the background. As soon as you close that window, Matlab can't access the path definition anymore.

Page Top

Windows Tools

This section presents some native Windows tools (Editors, Reference tools and other freeware software), which work quite well for scientific work!
By the way: To open the Explorer, simply press WindowsKey + e
You can also customise the boot- and logon-screen. But that's another story

Page Top

GMT


GMT is the tool used in geophysics to create maps and graphics. For installation follow the instucions given in the Download Section of the GMT homepage.
You migth also be interested in a magnificent GMT-interface for Matlab: Mirone
  1. Download install_gmt script to your home directory
  2. Create your install_gmt_parameter file using the GMT install form
    The default values will do most of the time, however
    • Part B: select "Please get and install the latest netCDF 3.6.x"
      if automatic installation fails, try manual netCDF installation
    • Part C: 1) select the FTP server nearest to you
    • Part C: 5) select gcc compiler
    • Part C: 7) "Place GMT in subdirectories of:" /usr/local/GMT4.2.1 (or other version name)
  3. press "GET PARAMETERS" button
  4. You can now either copy the output and paste into a newly created file ~./GMTparam.txt
  5. or right-clickThisFrameSave Frame As...~./GMTparam.txt
  6. in the CYGWIN terminal type

username > cd ~
username > dos2unix -u install_gmt GMTparam.txt
username > install_gmt GMTparam.txt

This will start the lengthy download and compiling process. This will fill up your screen and may take a few minutes...
After finishing the installation you can check if everything worked by typing

username > cd /usr/local/GMT4.2.1/examples
username > do_view.sh

Now, set your GMT environment variables in your ./bashrc

#############################################################
#GMT
export GMTHOME=/usr/local/GMT4.2.1
export NETCDFHOME=/usr/local/netcdf-3.6.2
export GMT_DATADIR=$GMTHOME/DATA
export GMT_GRIDDIR=$GMTHOME/DATA/Grids
export PATH=$PATH:$GMTHOME/bin
export MANPATH=$GMTHOME/man:$MANPATH
alias gmtdoc='cygstart "`cygpath -w ${GMTHOME}/www/gmt/doc/html/GMT.html`"'

The last alias is quite handy: if you now type gmtdoc, your browser will open with the GMT function reference



Page Top

GMT data sets

REMEMBER: Whenever you download a text file from the browser for use in CYGWIN, the line-endings are in MS-Dos Format (\r\n) and you need to run a dos2unix -u filename first.
Page Top

SAC

SAC Manual
As described above, you need the following CYGWIN packages installed: gcc-g++, libncurses-devel, make, readline, sunrpc, xorg-x11-devel
Now, you need to obtain the
SAC source code from IRIS. Compile it as suggested in the file "readme.buildsac" of the SAC distribution: Note that sometimes I found that renaming the folder "aux" to "winaux" or vice versa was helpful...

HOSTNAME: /tmp/SACsetup/
username > ./configure

HOSTNAME: /tmp/SACsetup/
username > make

HOSTNAME: /tmp/SACsetup/
username > make install

SAC is now installed under /usr/local/sac. Of course you could change that in the Makefile...

Some instalations have trouble with number precission. That may cause, for example the interpolate command to false round-off and thus inconsistent DELTA. This happens both on 32bit and 64bit computers. You can check this by running

HOSTNAME: /tmp/SACsetup/
username > make check

One possible solution is to use:

HOSTNAME: /tmp/SACsetup/
username > make clean

HOSTNAME: /tmp/SACsetup/
username > env CFLAGS="-ffloat-store" ./configure

HOSTNAME: /tmp/SACsetup/
username > make check

If the make check returns no FAIL than you are good! You can further optimize installation by using the --enable-optim=2 for configure


The only thing left, is to adjust your environment variables in the .bashrc according to the readme-file (Attention: $SACAUX is $SACHOME/winaux under CYGWIN!!)

export SACHOME=/usr/local/sac
export PATH=${PATH}:${SACHOME}/bin
export SACAUX=${SACHOME}/winaux
export SAC_USE_DATABASE=0
export SAC_PPK_LARGE_CROSSHAIRS=1

now reload your .bashrc

HOSTNAME: ~
username > source ~/.bashrc

Now, to run SAC, you need an XWindow server running in the background. This is already installed, you just have to start it. I have set an alias in my .bashrc

alias X='XWin -multiwindow -clipboard -silent-dup-error -logverbose 0 &'

(type XWin --help for more information)
If you are not using the RXVT terminal , be sure you also have the DISPLAY environment varible set in your .bashrc:

export DISPLAY=127.0.0.1:0.0

Now, the first time you start sac in a session, type

HOSTNAME: /Some/Directory/Name
username > X

HOSTNAME: /Some/Directory/Name
username > sac
 SEISMIC ANALYSIS CODE [10/25/2007 (Version 101.0)]
 Copyright 1995 Regents of the University of California

SAC> fg
SAC> plot

You may also want to create an alias to your sac.exe to load a initialisation script sac.ini

alias sac='$SACHOME/bin/sac.exe $HOME/sac.ini'
alias SAC='$SACHOME/sac/bin/sac.exe'

Finally, I prepared some SAC-macro syntax highlighter for some editors:
userDefineLang.xml Notepad++ (Windows)
sac4jedit.xml jedit (platform independent)
sacSyntax_TextWrangler.plist TextWrangler (Macintosh...)

REMEMBER: Whenever you download a text file from the browser for use in CYGWIN, the line-endings are in MS-Dos Format (\r\n) and you need to run a dos2unix -u filename first.

Customisation
One thing I find really anoying on SAC output is the use of exponential number format for header values. I'm not sure if that's intentional or not, but I find
BAZ: 281.19 quicker to understand than
BAZ: 2.8119E+002.
Luckily we can change that with a bit of coding if you have obtained the SAC source:
Open the file ./src/dff/formhv.c and find the line
sprintf(kvalue,"%#16.6e",Fhdr[item]); and change the containig block to:

if( icat == cmlhf.icatf ){
   lok = Fhdr[item] != cmhdr.fundef ;
   if( lok || linc ) {
     if (10e-5 <= fabs(Fhdr[item]) && fabs(Fhdr[item]) <= 10e5 || Fhdr[item] ==0. ) {
       sprintf(kvalue,"%#16.6f",Fhdr[item]);
     }
     else {
       sprintf(kvalue,"%#16.6e",Fhdr[item]);
     }
     ljust( kvalue,41 );
   }
}

Page Top

TauP Toolkit

The TauP-Toolkit provides an interface to obtain theoretic traveltimes for teleseismic events. It is using JAVA, and that causes some problems under CYGWIN, since there is no native java-for-cygwin, but we have to use the Windows version and its path definitions.
Calling java from within CYGWIN actually starts the Windows version. We therefore need the DOS-compatible path names! Anoyingly, the path-separator backslashes have to be escaped, i.e. a single backslash replaced by a double one. Also, the semi-colon in CLASSPATH have to be escaped
I found the following way most useful:
Add to your .bashrc:

####################################################
# taup
# CHANGE PATH AND FILENAMES ACCORDINGLY
#
JAVADIR=/c/Program\ Files\ \(x86\)/Java/jre6/bin
export TAUP_HOME=/usr/local/TauP-1.2beta2
BASE=`cygpath -wp $TAUP_HOME/lib/ | sed 's/\\\\/\\\\\\\\/g'`
export CLASSPATH=`echo -e $BASE'seisFile-1.0.6.jar\;'$BASE'TauP-1.2beta2.jar'`
export PATH=$PATH:${TAUP_HOME}/bin:$JAVADIR

taupEXE='java.exe -cp $CLASSPATH -Xmx512m edu.sc.seis.TauP'
alias taup=${taupEXE}'.TauP "$@" '
alias taup_path=${taupEXE}'.TauP_Path "$@" '
alias taup_time=${taupEXE}'.TauP_Time "$@" '
alias taup_curve=${taupEXE}'.TauP_Curve "$@" '
alias taup_setsac=${taupEXE}'.TauP_SetSac "$@" '
alias taup_create=${taupEXE}'.TauP_Create "$@" '

Now, you can start using TaupToolkit:

HOSTNAME: ~
username > taup_time -ph SKS -ph SKKS -deg 105 -h 600

Model: iasp91
Distance   Depth   Phase   Travel    Ray Param   Purist    Purist
-----------------------------------------------------------------   105.00   600.0   SKS     1365.37     4.422     105.00  = SKS     105.00   600.0   SKKS    1412.97     6.985     105.00  = SKKS    105.00   600.0   SKKS    2107.94     2.561     255.00  = SKKS 

HOSTNAME: ~
username >



Page Top

ttimes

... sorry, still under construction ...



Download Source Code here!

unfortunately, I wasn't able to compile it under CYGWIN 1.5.X ... Some strange errors regardin standart header files... I suspect, that CYGWIN still uses the GNU complier version 3. Perhaps with gcc4.x it will be possible. Keep me informed if you have more success...

Page Top

SOD

This is not about the band S.O.D but the JAVA tool SOD for seismogramm data request and more.

... sorry, still under construction ...





Page Top

rdseed

Unfortunately I wasn't able to compile rdseed under CYGWIN. But you can still use the JAVA version jrdseed

Page Top

RayGui

... sorry, still under construction ...



Page Top

Fun stuff

Watch a geophysicist at work in Southpark, Colorado:

If video is not working, please try this link

Page Top