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

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
 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)
 Base:
    - coreutils (nice additional tools like "timeout")
 Utils:
    - bc (numeric calculator)
=====================================================

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).

gfortran compiler

gfortran is a compiler for the Fortran95 programming language. However, unlike g95, it is not included in the standard CYGWIN GCC 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.

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 "courier" -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')



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:

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...

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.

Page Top

TauP Toolkit

Download the TauP Toolkit. To make it run under CYGWIN, we require the Windows versions (*.bat) of the functions, since TauP uses JAVA, which is in effect the actual Windows JAVA machine.
So, we have to move the Unix-shell scripts, so that we will not confuse the versions (and TAB-completion works...)

HOSTNAME: /usr/local/TauP-1.1.7/bin
username > mkdir backup

HOSTNAME: /usr/local/TauP-1.1.7/bin
username > mv *[^.bat] backup

and in the .bashrc:

####################################################
# taup
export TAUP_HOME=`cygpath -w /usr/local/TauP-1.1.7`
export PATH=$PATH:/usr/local/TauP-1.1.7/bin



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
Since there is no JAVA runtime environment for CYGWIN, it needs to be run from a DOS shell (not CYGWIN).
Try
C:\User\Yourname> java -jar path/to/jrdseed.jar -d -o 1 -f yourfile.seed

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