The Developer Tools and Developer
Kits may already be
installed but if you have later problems with
compiling and
linking, it's probably because some of the Developer
Kits (SDKs) weren't installed. The packages to
install them are on the install disk (and the correct
version 10.3, 10.4 etc. should be installed
to match your OS). Alternatively, the packages can usually
be found on your hard drive if your mac was
shipped:
You may have to install Applications/Installers/Xcode
Tools/Developer.mpkg and you'll probably have
to install the three SDK packages (BSDSDK.pkg,
DevSDK.pkg, X11SDK.pkg) in
Applications/Installers/Xcode Tools/Packages/ (see a
screenshot of where to find Xcode Tools).
Now get X11. If you can't find it in the
Applications/Utilities folder of your hard drive,
I recommend installing the version at Apple's website. If you couldn't find all three of the SDK packages on your hard drive (BSDSDK, DevSDK, X11SDK), you should also download and install them from Apple. I prefer the version of X11 from Apple (rather than the Fink version - we'll discuss Fink below) as it installs quickly and easily.
Shells
|
An Introduction
for Those Uninitiated
in the Arcane Ways of Unix |
This is an IMPORTANT ASIDE FOR GRAD STUDENTS AND ANYONE WHO ISN'T
USED TO USING UNIX. Unix is
based on a system based on a system
that was based on a system, and,
consequently, it's a bit like an
onion. Historically, there have been
many layers, and
different people are comfortable
working with a different layer. In
UNIX speak, these layers are called
SHELLS. A Mac OS X Terminal will open in the
bash shell, BUT I USE THE tc-shell
and EVERYTHING
WRITTEN BELOW WILL ASSUME
THIS. Thus, if you're
entirely new to UNIX you're now a
tc-shell user. Welcome.
To make sure you're ALWAYS IN THE tc-shell you
can do several things. You could
type "tcsh" every time you open a
terminal but this is laborious
and you're bound to forget at
some point, so I suggest, when you
double-click on the X11 icon, to
go to Applications on the X11 Toolbar, and under
the Customize option create a Name,
say, "xterm" that contains the
following command (see a screenshot of this):
xterm -e tcsh &
Now, when you run this command from the toolbar, you'll
automatically be in the
tc-shell rather than
bash. If you want a
snazzier feel to your
xterms create a Name,
say, "small xterm" that contains the
following command:
xterm -fg white -bg black -sb -sl 500 -geometry 78x24+528-48 -n main -e tcsh &
Try it! Particularly useful is the -sb flag, which creates a
scrollbar. The command
options, or flags, are
described in detail in the
manual (type "man xterm" at
any prompt).
If you tend to run stuff from the Mac OS Terminal, rather than the x11
application,
please don't,
as any
x-application
won't
display. If
you INSIST on
using
Terminal, go
to
Terminal then
Preferences
on the
Terminal
Toolbar and
click the
radio button
that states
"Execute this
command
(specify
complete
path)" and
change
"/bin/bash"
to
"/bin/tcsh" (see a screenshot of this).
Xapplications
still won't
display but
hey, you
wanted to use
Terminal.
Initialization Files
|
Start As You Mean
To Go On |
OK, now you're constantly in the tc-shell when you run X11, you'll need to have a variety of initialisation files in your home
directory (i.e. ~/.xinitrc, ~/.tcshrc). There
are handy examples on your hard drive at
/usr/share/tcsh/examples/, or you can have a
look at mine. At the minimum, I recommend
making a copy of my .xinitrc file and
sourcing the .login, .logout and .tcshrc
files in /usr/share/tcsh/examples. By
"at the minimum sourcing", I mean creating a file
called ".tcshrc" IN
YOUR HOME DIRECTORY that contains only the
line "source
/usr/share/tcsh/examples/rc", creating
a second file called ".login" that
contains only the line "source
/usr/share/tcsh/examples/login" etc. (see
/usr/share/tcsh/examples/README). You can
"create" these files using a simple
editor such as pico (type "pico" in a
Terminal or Xterm). Or by typing,
e.g:
prompt>echo "source /usr/share/tcsh/examples/rc" >> ~/.tcshrc
at the prompt. (~ is a UNIX abbreviation for your home
directory). Once these .files
are setup, X11 should work fairly well.
NOTE: DO NOT try to create text files for UNIX using the Macintosh clipboard/notepad/copy-paste function or a Mac-based editor such as Simpletext or *shudder* MSWord as these create files that have rich-text-style Meta-formatting that is gibberish to UNIX.
|
Fink
|
Fink is a useful way of installing
Mac OS X software |
The builders of Fink maintain
their own excellent documentation. First you
should visit the Fink home page to check you know which version you need to install, then you can download it and follow the installation instructions.
I find it very simple to use Fink from the command line, although it
currently ships with a GUI called Fink Commander. As an example of using Fink at the command line, once you've installed it, try the following at the prompt of a (new) shell:
prompt> sudo fink list scra
prompt> sudo fink install xscrabble
Now open a new shell and
prompt> xscrabble
Now quit out, 'cos you're at work. Note that you had to type "sudo" to
get root privileges (and were probably
asked for your user
password), which will
be a recurring theme below.
Some handy software you might want to use Fink to install:
"g77" - the fortran compiler
"xemacs" or "emacs21" - your favourite text editor
"gimp" - the image manipulation software
"abiword" - looks a lot like Microsoft Word but it's free
Note that these can take a long time to install and it's probably worth
setting the Fink installation going
overnight, or when you
don't need your machine.
NOTE: Once fink is installed you need a line in your .tcshrc file that sources all of the fink setup info, so add a line somewhere in your .tcshrc file (using an editor such as pico) that states "source /sw/bin/init.csh". My example file already contains this line.
|
Python,
Numerical Python and IRAF
|
IRAF, Numerical Python,
SLALIB, PGPLOT; Scisoft covers all
the bases |
Although Mac OS X ships with
Python, (as
of v10.3) it doesn't ship with
Numerical Python. Astronomers will
probably also need IRAF at some point, and this
can be a pain to install. FORTRAN programmers
will probably also want the SLALIB
libraries. ESO's Scisoft neatly solves all of these
problems and more.
Download the latest version of Scisoft
for Mac OS X. The syntactic stress is
because one version (I think
2004.1.5) overwrote some key
directories on my system! Once it
unbundles, it's an
easy point-and-double-click install.
It should install everything in a
directory at the root level called
/scisoft, which you may need to source
by adding
source /scisoft/bin/Setup.csh
to your ~/.tcshrc file. If you nicked my example .tcshrc file, it's
already in there.
You'll find after the
installation that (important things like)
python and IRAF will now run from the scisoft
binary:
prompt> which python
/scisoft/bin/python
prompt> which xiraf
/scisoft/bin/xiraf
USEFUL NOTE: Linking. If you have code
that
requires a
link to the
(e.g.)
SLALIB library, you should
compile it something like this:
prompt> g77 test.f -o test.exe -L/scisoft/star/lib/ -lsla -fno-second-underscore
If you get "restFP" or "saveFP" or "symbols undefined" errors, then you
probably also need
to link to /usr/lib
(add a -L/usr/lib
flag), where the
gcc compiler
library is kept. See below for more on this.
NOTE that the latest versions of
Scisoft have been installing without SciPy, a useful module for scientific techniques. Instead, I recommend installing the Open Source module Scientific from here. Their install worked first time for me, just read the README that comes in the tar bundle. If you need some more sophisticated scientific functions (e.g. Bessel functions or gamma functions) try the transcendental package, which I found to be an easy install. Of course you could also install SciPy itself but note that SciPy can have problems compiling if Scisoft is installed on your machine (see below).
|
Scisoft vs SciPy
|
SciPy compilers
don't always get along with Scisoft |
After many problems trying to install SciPy for Python 2.4 on my Mac,
even after specifying version 3.3 of gcc as the compiler and checking I had numarray, fftpack and, in fact, every conceivably necessary package (all of these, for example), I noticed that the compile problems were usually caused by crosstalk between the SciPy install script and Scisoft libraries. After I hid Scisoft everything compiled perfectly. So, if trying to install SciPy, I recommend, at the minimum, unsourcing scisoft in your .tcshrc file (i.e., comment out the command "source /scisoft/bin/Setup.csh") and opening a new xterm in which to build SciPy. If this still doesn't work, hide the /scisoft directory. Failing this, you might have to delete Scisoft (sudo remove the /scisoft directory entirely), install SciPy, then reinstall Scisoft.
I should point out that I usually install Python from the binaries, so
maybe people who let Scisoft install Python too won't encounter the problems installing SciPy that I did.
|
saveFP/restFP Compiling Errors
|
The g77 and gcc
compilers have trouble making friends, at least up until Tiger (Mac OS X 10.4)
|
From time to time, you may find that you get errors when compiling
Fortran or C code. This most commonly occurs when compiling mixed C code using the Fortran g77 compiler. Basically, the problem is that when different versions of gcc link to a library, they make slightly different calls, which can then be missed by subsequent compilations that make different default links. The reason this arises with Fortran/C cross-linking is that it is not uncommon to have gcc installed from a developer kit, say in
prompt> which gcc
/usr/bin/gcc
but to have g77 installed from fink, say in
prompt> which g77
/sw/bin/g77
So, when Apple (Darwin) gcc calls g77 which implements Fink's
gcc defaults, it finds that certain expected links are not made.
So, how to circumvent this? Well, my version of Tiger has the Darwin
gcc libraries installed in /usr/lib/gcc and statically linking to it has always solved restFP/saveFP errors. So, for instance, when compiling with (Fink's) g77, I explicitly link via, e.g.,
prompt> g77 out.o -o executable.exe -L/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/ -lgcc
Presumably this works the opposite way too (i.e., if for some reason you're
using Apple's FORTRAN compiler and Fink's C compiler, then try statically linking to libraries in /sw/lib/gcc)
(Perhaps the best discussion of this problem is here)
|
SuperMongo
|
SM is a handy
plotting package but it is not
freely available. If you don't have a license
(Illinois astronomy does), you can
buy it here
|
Graduate students (etc.) in
Robert's group can ask me for
SuperMongo and I'll supply
them with the tarball. I
recommend installing it in
/usr/local as this is the
default for many other
installations.
Assuming the SM tarball is on your Desktop (and that
you've already got a
directory /usr/local and
don't have to make it first), start
by unbundling the tarball in
a /usr/local/sm directory:
prompt> sudo mkdir /usr/local/sm
prompt> cd /usr/local/sm
prompt> sudo mv ~/Desktop/sm2_4_20* .
If the tarball hasn't already been unbundled by StuffIt Expander, unbundle
it.
prompt> sudo tar -zxvf sm2_4_20.tar.gz
A directory with the latest SM version number will be created and we're
ready to configure the install.
prompt> cd sm2_4_20
prompt> sudo set_opts
You will now be asked some questions. Just hit "return" for the
default in all cases, except when asked what device to use - you should type "X11" and then hit "return". When set_opts has (successfully) exited, edit the src/options.h file as prompted to remove the first seven lines of comments, accepting that you're licensed to use SuperMongo. Now everything should make without a hitch.
prompt> make
prompt> sudo make install
Leopard Update: Cedric Grenon, a grad student at Queen's
University in Kingston, Ontario points out that on his MacBook Pro running 10.5 (Leopard) he encountered a "/usr/bin/ld: cannot find -lX11" error, which he solved by changing the following line in the Makefile (src/Makefile):
substitute XLIB11 = -lX11 for XLIB11 = -L/USR/X11R6/lib -lX11
(First you should mv up to the /src directory, ADM)
You will need a .sm file in your home directory (see my examples). Supermongo will still run without a .sm file but only with certain annoying font and key-mapping problems, so create a .sm file. Unless it's already there, /usr/local/bin will need to be added to your path in your .tcshrc file (see my examples). Now, typing "sm" in a (new) shell should take you to the sm prompt and bring up an X11 interface.
If you've never used SM before there's a tutorial. If you've used it before and still have problems, it's always a good idea to RTFM.
|
Pysmongo
|
Use SM plotting
techniques from
within Python
|
If you've already installed SM
and Numerical
Python, why not
let Python talk to SM?
First download pysmongo-1.0.tar.gz (or whatever version they're currently up to....)
Assuming the Pysmongo tarball is on your Desktop (and that
you've already got a
directory /usr/local and
don't have to make it first), start
by unbundling the tarball in
a /usr/local/pysmongo directory:
prompt> sudo mkdir /usr/local/pysmongo
prompt> cd /usr/local/pysmongo
prompt> sudo mv ~/Desktop/pysmongo* .
If the tarball hasn't already been unbundled by StuffIt Expander, unbundle
it.
prompt> sudo gunzip pysmongo-1.0.tar.gz ; sudo tar -xvf pysmongo-1.0.tar
A pysmongo directory with the latest version number will be created and we're
ready to configure the install.
prompt> cd pysmongo-1.0
prompt> configure
prompt> make
prompt> sudo make install
If a problem is going to arise at this stage, it will probably be that
the Pysmongo MakeFile incorrectly guessed where your Python site-packages folder resided, and made its own version of the Pysmongo class executable in /python/Darwin/python-2.3/site-packages/SM. To (neatly) solve this problem, determine where the site-packages folder that your Python binary reads is by, say, looking for the /lib directory near to you default Python binary, which can be found with:
prompt> which python | awk '{print "ls -al",$1}' | csh
In my case the site-packages folder read by the scisoft python
binary is /scisoft/Library/Frameworks/Python.framework/Versions/Current/lib/python2.3/site-packages. You should ensure that the Pysmongo class executable is in the correct site-packages folder by moving it from the created site-packages folder to your default, i.e.:
prompt> sudo mv /python/Darwin/python-2.3/site-packages/SM /scisoft/Library/Frameworks/Python.framework/Versions/Current/lib/python2.3/site-packages/
And, if you haven't previously put anything
important in a /python folder at the root level!!!!
prompt> sudo \rm -r /python
Now, to test that Pysmongo works (you should still be in
/usr/local/pysmongo/pysmongo-1.0, by the way) typing
prompt> python test/tstsm.py
should generate a colour plot in an X11 window. You can now invoke pysmongo in a Python
shell (or in Python code) by using the command "import SM". The .py files in /usr/local/pysmongo/pysmongo-1.0/test provide some handy examples for using pysmongo.
IMPORTANT: As of posting, pysmongo appears to miscalculate
plotting geometry on our macs, meaning that it's essentially useless. Biggles is a neat alternative. Or there's John Lucey's cunning trick (also available here) for using supermongo in a shell script. You could then work the command line from inside python by importing system from the os module and using the os.system() command.
|
TeXShop
|
Native TeX for Mac
OS X
|
The best version of TeX that we've come across for Mac OS X is TeXShop. It's quite a complicated installation but it's very well documented. One splendid feature of TeXShop is the ease with which you can typeset a document in real time as you code it. I think it installed first time on my Mac (and it should, 'cos it's written in Cocoa) but if anyone in the group has installation problems, mail me and we'll make a note here.
Being native to Mac OS X TeXShop always uses pdf rather than
postscript. You can still include encapsulated postscript figures, though, if you add to or modify the documentstyle command to resemble
\documentstyle[epsfig,epstopdf]{mn}
Or, if you don't have a documentstyle command Adam Rengstorf suggests this alternative
\documentclass[12pt,preprint]{aastex}
\usepackage{graphicx}
\usepackage{epstopdf}
The {mn} and {aastex} commands here are, of course, examples of style
files used by two popular astronomy journals.
|
Desktop Manager
|
Split your screen
into multiple desktops
|
Currently (v10.3), Mac OS X doesn't ship with a straightforward way of
splitting
your
screen
across
multiple
desktops.
Fortunately, Desktop Manager provides for this quite superbly.
Once you download Desktop Manager it's easy to install and use - if it doesn't automatically install, pointing-and-clicking will do it.
Click the Desktop Manager icon to start. You can modify options by either clicking the menu icon in the status bar or the blue haze beneath the pager.
|
Hosting Web
Pages
|
Publish documents
on
the
WWW
|
To turn on Apache on your Mac, click on the Apple icon and then "System
Preferences" and select "Sharing" under "Internet and Network". Now click the box marked "Personal Web Sharing". Your Mac will inform you of two possible websites; the computer website and your personal website.
To publish a user home page hosted on your Mac, modify the index.html
file in ~/Sites. To publish a home page at your Mac's website, modify the index.html file in /Library/WebServer/Documents. If you're comfortable with your knowledge of web security, you could also publish CGI scripts in /Library/WebServer/CGI-Executables.
|
CVS/Kerberos
|
Kerberos and the LCDM common
user repository
|
Robert has written a pdf document on how members of the Laboratory for Cosmological Data Mining can use CVS to back up files to the LCDM common user space. This is particularly useful for keeping track of pieces of software that one of us has written but that we all might want to use and for keeping tabs on which version of a piece of software we've written works.....
NOTE that the first section of
Robert's document
also contains a
useful tutorial concerning setting up the network authentication protocol Kerberos on Mac OS X. Basically, Kerberos is a protocol to create authentication tickets that enable you to securely move between networked machines. I've put the edu.mit.Kerberos protocol file that worked for me in my examples.
To extend Robert's instructions on setting up the CVSROOT environment variable: If your ncsa username differs to that on your local machine, you could set CVSROOT in the following manner (this, of course, is the c-shell example - Robert tends to give bash shell examples):
prompt> setenv CVSROOT ":ext:username@cvs.ncsa.illinois.edu:/CVS/lcdm"
NOTE that before setting up
CVS, you will need to mail the ncsa helpdesk and ask for access to the CVS repository.
|
Public/Private Key Encryption
|
Access remote
accounts without typing a password
|
Adam Rengstorf supplied me
with a way of setting up public/private key encryption so that you can access a remote machine without having to type your password. First you need to generate an access key....type
prompt> ssh-keygen -t dsa
and accept the default directory for storing the key. Enter an empty
pass-phrase, too. Note that typing "sudo" before "ssh-keygen" will generate a pass-key for root.
Now, ftp into the remote machine and transfer the file generated by
keygen ("id_dsa.pub" - keygen will echo which directory it stored the file in) to your (remote) home directory.
Finally, log into the remote machine that you want free access to and
append the information in the key-file to your .ssh/authorized_keys file (or create it if it doesn't exist)
REMOTE MACHINE prompt> cat id_dsa.pub >> .ssh/authorized_keys
Now, to see if it works, open a window on your machine and ssh to the
remote machine
prompt> ssh remoteusername@remotemachinename
Access should now be granted without inputting a password. Of course, if
"remoteusername" is the same as your username on your machine, there's no need to enter it. If you typed "sudo" before "ssh-keygen", then it's root whom has free access and you will have to type
prompt> sudo ssh remoteusername@remotemachinename
unless, of course, you're powerful enough that you could store the key in root's home directory on the remote machine.
|
Backing Up Directories
|
Using rsync to
copy files between machines
|
Adam Rengstorf has written a
script that uses rsync to mirror a directory on a remote machine. This is very useful for backing up directories in the absence of a RAID disk.
First you'll need to use Fink to install rsync in
/sw/bin/
prompt> sudo fink install rsync
and you'll have to set up a key encryption so that
root can access the remote machine (the machine that you wish to back up you home directory to) as you, without needing to enter a password.
Now, obtain both of Adam Rengstorf's example files from this directory. You can put these directories anywhere on your local machine but I'll assume for ease of expression that they're in /Users/myusername/cronscripts. The file excludefile should contain a list of any directories you don't feel you need to back up (i.e. trash, internet caches etc.). You need to change the 6 customisable parameters in the file backup_user.sh so that they reflect the local directories you wish to have backed up and the remote machine and directories you want to back up to (there are guiding comments in the file itself). Note that the remote directory that you wish to back up to must exist on the machine you wish to back up to - backup_user.sh does not, as provided, make this directory for you.
You'll have to change the permissions of backup_user.sh so that
the script is executable
prompt> chmod +x /Users/myusername/cronscripts/backup_user.csh
and it's worth (at least briefly) testing that it runs faultlessly with the parameters you
have customised
prompt> /Users/myusername/cronscripts/backup_user.csh
and that you've set up the key encryption for root
correctly. Now, edit your crontab as root
prompt> sudo pico /etc/crontab
and add something like
00 3 * * * root /Users/myusername/cronscripts/backup_user.sh
To regularly run the backup script as root (in this case every morning
at 3am). Now check the logfile tomorrow morning and see if it worked!
|
Customising arXiv
|
Why waste time
trawling new arXiv listings that don't interest you?
|
NOTE: I updated astroph.py to
version 1.03 on April 30th, 2008 to reflect a change in arXiv's primary url for astrophysics abstracts. If you have an earlier version you may want to grab the newer version.
Obviously, we don't always have time to read every entry on
arXiv. Further, it's a known effect that being listed higher on arXiv increases your exposure, hence biasing citation rates.
I've written a handy little Python script that will grab the new
arXiv listings page, select only those abstracts that interest you, and open a browser window to display the results (kind of an Arxivsorter that you can control yourself). It should be reasonably functional on any platform that runs Python but has certain features that are geared specifically to Mac OS X. It runs from the command line. You can get it here (on Mac OS X; place your cursor over astrophApr2008.py, the most recent version, hold down the alt/option key and click the mouse-button once).
By the way, if you found this code useful, consider linking to my website
as a courtesy, rather than just passing the source code around.
If you downloaded it to the desktop, you can check it works by
double-clicking the astrophApr2008.py icon, then double-clicking the generated applescript bundle. It should return today's arXiv new listings with the default search parameters. The easiest way to run astroph.py with customised parameters is to run it under UNIX (from the Terminal or an Xterm). So put it in a directory that's in your path (such as '/usr/local' or '.'). Here are some of the most common example uses:
prompt>python astroph.py -help
Print a help message and usage options
prompt>python astroph.py QSO supernova -v star
A basic search that will reject all occurences of star and
then return today's arXiv abstracts that contain
QSO or supernova
prompt>python astroph.py QSO supernova -v star -ho
The same search with -ho, the highlight option, flagged. This will
return arXiv with all occurences of star highlighted
in red, all occurences of QSO or supernova
highlighted in green and the abstracts ordered so that matches with
QSO and supernova are at the top of the returned page
and matches with star are at the bottom of the returned
page
prompt>python astroph.py cluster group quasar
QSO lens supernova ' AGN' correl -v star magnet globular branch
As a cosmologist interested in lensing, this is my typical search. The quote
marks around AGN force a space before the word, meaning that words
like 'mAGNitude' will not be searched for. Alternatively, the -cs
flag could be used to make the search case-sensitive.
If you want your typical arXiv new listings to pop up daily without prompting, why not
set up a cron job? To do this on Mac OS X, assuming astroph.py is in a directory that is in your pythonpath (if you don't know how to set the pythonpath environment variable, look in my example .tcshrc file), create a simple script that contains your default search in, say, the (existing?) directory ~/cronscripts
prompt> echo "python astroph.py cluster group
quasar QSO lens supernova ' AGN' correl -v star magnet globular branch" >! ~/cronscripts/astroph.csh
prompt> chmod +x ~/cronscripts/astroph.csh
Now edit your /etc/crontab file (you have to be logged in as root to
write to the crontab file)
prompt> sudo pico /etc/crontab
and add something like
00 6 * * 1-5 myuserame python /Users/myusername/cronscripts/astroph.csh
To regularly run the astroph.csh script as myusername (in this
case every weekday morning
at 6am). Now, each weekday morning, your edited arXiv new listings page should be displayed.
Note that it is inadvisable to run astroph.py as
root as it will write to directories as root rather than as myusername and subsequently running it as myusername will fail to overwrite these directories. From the command line, astroph.py will halt with a warning message if you run it as root. You can force it to run as root by adding a -root flag, if this is what you really intend to do.
|
Some Miscellaneous Other Software
|
And who in
Robert's Group to Contact for More Help Should You Want the Software and Have Problems Finding or Installing it
|
Adobe Reader copes with sideways pages, unlike Preview - see Nick Ball
Mozilla Firefox browser - see Nick Ball
Emacs Python mode can be set up for writing Python code - see Nick Ball
Fugu FTP GUI - see Nick Ball
Partiview 3D visualization - see Nick Ball
Office 2000 (for e.g. Powerpoint; note that we have the most recent version of MS Office for Mac, which you should be able to get off Robert) - see Nick Ball
OSX VNC and Chicken of the VNC Virtual Network Computing for working from home - see Nick Ball
NASA's myADS webpage will do similar things to customizing arXiv, but only returns articles once they are published in a journal or updated in the SLAC database. After setting up search terms you will be regularly emailed new publications - see Nick Ball
IDL coding language and library - see Nick Ball
D2K NCSA Automated Learning Group's Data-to-Knowledge toolkit - see Nick Ball
Department of Physics & Astronomy, University of Wyoming,
1000 E. University, Dept. 3905,
Laramie, WY 82071, USA |
|
|
| Page maintained (and updated)
|
| | |