AST 443: Notes on Computing
Now that you should all have accounts at the
Math sinc site,
and have logged in
succesfully, here are some notes that may help you.
Navigation
When you log in, you are in your home directory /home/username where
username is the name you used to log in with. You may have
subdirectories in your home directory. Create them with mkdir. Use
subdirectories to organize your files.
Use the cd command to change directories.
Don't know where you are? Type pwd.
UNIX is case-sensitive. ls and LS are two different
commands.
There are many variants of UNIX. I use the C-shell. Type tcsh
to use this shell. If you want to use the bash shell, or any other shell, you
are on your own!
You can run any UNIX command in the background by adding an ampersand (&) to
then end of the command line. For example, to run netscape in the background,
so you can use the terminal window for other things, type netscape &.
Useful commands:
- pwd - print current directory
- cd - change directories. cd with no arguments moves to your
home directory.
- man - Manual. Type man cmd to get the help page
for the cmd command
- mkdir - Make a directory. Type mkdir name to create
a subdirectory named name
- rmdir - Remove (delete) a directory. It should be empty first.
- mv - Renames a file. mv file1 file2
- cp - Copy a file. cp file1 file2
- scp - Secure copy. Use to copy files over the network, from the
ast443 account on osiris. To copy one of the data files in that
account, you would type
scp ast443@osiris.ess.sunysb.edu:filename .
You will be asked to enter the ast443 password. If you enter it
successfully, you will find filename in your directory. If you
wish to rename it to something else, replade the dot (.) in the scp command
with the new filename, or use the mv command later.
- ssh - You can log into the mathlab computers remotely
using ssh. This is more secure than telnet or rlogin, which are disabled
on most modern systems. ssh is available on most UNIX platforms.
the syntax is ssh yourname@computername.mathlab.sunysb.edu.
where yourname is your user name on the mathlab computer
computername. If you can ssh in, but cannot generate a
graphics windoiwm try using the -Y option in ssh
(ssh -Y yourname@computername.mathlab.sunysb.edu).
To log in securely from a Windows platform, you will need to install
Putty,
a free SSH client. Putty emulates ssh; PSCP emulates scp.
You can also use CYGWIN to connect from a Windows platform.
See here for
installation instructions. Thanks to Josh Schleider for the writeup.
- rm - Remove (delete) a file. rm filename
- ls - Lists the files your directory. ls -a also list the
files that begin with a dot (.). ls -l provides a long listing,
including file sizes and creation dates.
- cat - catenate a file. Type cat name to print the
file to the terminal screen. May also be used to concatenate files
cat file1 file2 > file3 appends
file2 to file1 and write the result as file3.
- more - more: prints out a (presumably text) file, one screen at a
time.
UNIX Mail
UNIX mail is neither intuitive or user friendly. In order to send mail,
you would type: mail addressee,
where addressee is the e-mail address of the intended recipient.
You then type your mesage. End the message with a line that contains a single
period. You will get a CC: prompt; you may enter other addresses here.
To send a subject line, add -s "subject line" to the mail
command.
To send a file, append <filename to the mail command.
For example, to send your mock HST proposal, a file named
hst_proposal.tex, to me, you would type the following:
mail -s"my HST proposal" fwalter@astro.sunysb.edu <hst_proposal.tex
Logging Out
When you are done, you must log out. Generally this is done by moving the
mouse to a blank part of the window, and right-clicking. Look for a "logout"
option. You will need to confirm the logout.
IDL should be in your path. If the command
which idl returns the string /usr/local/bin/rsi, or
something similar, you are in business. Otherwise, you will have to find the
location of the IDL executable and add it to your path.
Start by typing idl.
Need help? Type a question mark (followed by a return). This brings up the
help manual (a pdf file). Read this at your leisure.
A better manual is Fanning's "IDL Programming Techniques". You may read this
as a pdf file on the
Blackboard
page for this course (go to Course Documents)
There are a number of good web sites devoted to IDL programming. Among these
are:
But before you go to any of the above-mentioned sites, read the
following primer first.
IDL is a powerful language,
with many intrinsic capabilities. It can be run
interactively, line by line, from the terminal, or you can create programs
(called procedures) which you can then run. The syntax is very similar to
FORTRAN, so a user familiar with FORTRAN should have little difficulty coming
up to speed in IDL (however, it takes years to become expert).
Unlike Fortran or C, IDL code
need not be compiled and linked. You can stop a procedure anywhere in the code,
and examine intermediate results, change values, or do whatever you might
think of doing.
The best advice is, as often, to read the online
manuals before you begin.
To run IDL, type idl.
Note that, unlike UNIX, IDL is not case-sensitive. However, file
names are, because IDL must interesct with the operating system to find files.
The IDL commands that follow are capitalized to distinguish them from the
text; they need not be.
On some systems (including the Math sync site), the default "backing-store"
is turned off. This means that the contents of a graphics window can be lost
when the window is pushed into the background. To overcome this nuisance, type
the command device, retain=2 upon starting IDL. If you will need to do
this often, you might consider puting it in an IDL startup file.
IDL recognizes a lot of variable types, including
- short (16 bit) two's complement integers (-32768 to +32767). Example: 16
- long (32 bit) integers (up to +/- 232-1). Example: 66000L
- floating point (32 bits). Example: 2.3, 7.0E7
- double precision (64 bits). Example: 2.3D0, 7.0D7
- bytes (8 bit) (0-255). Example: 32b
- strings. list of bits that are interpreted as text.
Example: 'This is a string'. Strings are delimited by single or double
quotes. IDL has a lot of string processing routines, all of which start
with the letters str.
Once you start IDL, you should check your default directory. One way to
find where you are is to type
CD,CUR=CUR & PRINT,CUR.
If you are not where you want to be, you can use the
CD command. CD is like the UNIX cd command, but it needs
a string argument, as in CD,'new_dir'.
In addition to the intrinsic capabilities
there exists a large and growing library of user-supplied routines. The most
useful for our purposes is the
Astronomy Users
Library. These routines are
in /home/fwalter/pro, and should be in your IDL_PATH.
A brief description of the contents
is in /home/fwalter/contents.txt.
For the most part, you will only need primitive IDL commands for displaying
and measuring your data. The data files are generally in
FITS
format, which you can easily read in IDL
by
following these instructions. The data will then consist of a header
H (a string array) and a data array
D, which may be multi-dimensional.
- The index of the first element of an array is 0, not 1.
- IDL is vector-oriented. Many operations which require a loop in FORTRAN
can be done in one line, without loops, in IDL.
- IDL is not case-sensitive.
- IDL features dynamic typing. For example, you can change a floating point
variable (a=3.14159) into an integer (a=3) with the command
A=FIX(A). Beware: you can change an array
(A(512,512))
into a scalar by simply redefining it (A=0).
Note that there are times you want to do this, such as to minimize
memory use.
- Note that the default integer in IDL is 16 bits long, and so cannot
32767. If you expect to use larger integers, make sure to define them
as LONG (i.e., 50000L) by appending the "L" to the integer.
- If you plan to work with large floating point numbers (like Julian days),
you should work in double precision. If you set JD=2455555.789, and then
print it out, you will find that JD=2455555.75. You have lost 0.39 days
because single precision numbers only store 6-7 significant figures.
However, by declaring JD=2455555.789D0, you preserve about 14 significant
figures, and millisecond accuracy.
Acquaint yourself with the PLOT and
TV commands. Use PLOT for
line plots; use TV to display images.
The simplest graphics/display software in idl is written for single-plane,
256 color graphics. I don't know whether of not the Suns can deal with
24-bit color (true colors).
If your plots come up black, or you can't get color
tables to work, try DEVICE,DECOMPOSED=0. Feel free
to experiment with colors.
- The default window size 640x512 pixels.
You can create a window in real time of size (X,Y) with the command
WINDOW,xsize=X,ysize=Y.
- If changing the color tables does not
affect the existing windows, you will need to create a new window.
Either delete
the current window with WDELETE, or create
a new window using WINDOW
- The system variable !d.name (HELP,/ST,!D) contains
the name of the current graphics device. The default is
'X'. To change the plot device, use the
SET_PLOT,dev command. dev is the name of the
plot device. Use PS to generate a postscript file on disk.
Note that dev is a string.
Check the HELP
file on DEVICE for the many other options. Then do your plot (you won't
see anything on the terminal). After plotting to the
device, you need to type DEVICE,/close and
SET_PLOT,'X' to reset to
plot on the terminal screen.
It is easy to extract M-dimensional data from N-dimensional data. For example,
given a 2-dimensional array of spectra D (as you get from the IUE high
dispersion data), you can extract the nth row with the command
S=D(n,*), or the nth column with the command
S=D(*,n)
Read FITS files with READFITS. READFITS, a function,
returns a parameter (the data array). To read a file, type
data = readfits("my_fits_file.fits",header)
Data is an array containg the data; header is a string array containing the
FITS header. The fits file name is a string, and must be enclosed in quotes
(unless it is a string variable). Use SXPAR to extract values from
the fits header.
READFITS can read gzipped file (those with .fits.gz extensions):
there is no need to uncompress the file first with gunzip.
More information about FITS files and reading FITS extensions is
here.
For one-dimensional data (e.g., spectra), use the PLOT
command. Set the plot scale and range with SET_XY.
Two-dimensional data can be displayed using the TV.
Note that the window displays byte values, and PLOT does
not do any byte-scaling. Use TVSCL,data or
TV,BYTSCL(data) to scale your data appropriately. Note that,
if you have a few pixels that are very much brighter than the others, you may
not see much. This is because the full range is compressed into about 256
intensity levels. Use the < operator to truncate the image
(e.g., TVSCL,data<500 will plot all pixels with values
>500 as 500. Used in
this manner, the operator does not overwrite the data.).
The basic way to measure a value on the screen is with the
CURSOR command. Type CURSOR,X,Y.
Click the left mouse button at the point of interest, and then
PRINT,X,Y to get the values back. On a 2-dimensional
image, X and Y will be the pixel number, and the value at that point is
IMAGE(X,Y).
In order to use the CURSOR command for images, you need to set up
the plot limits properly (there may be more elegant methods, but this works!).
s=size(image) ;this returns a vector containing the size
;of the image. s(0) is the number of dimensions,
;which should be 2 for an image array
sx=s(1) ;size of X dimension
sy=s(2) ;size of Y dimension
window,xsize=sx,ysize=sy ;create window the size of the image
!p.position=[0,0,1,1] ;plot boundaries are window boundaries - there
; are no margins
set_xy,0,sx-1,0,sy-1 ;set plot limits
!x.style=1 & !y.style=1 ; force exact plot boundaries
plot,indgen(10) ;this dummy plot will define the plot limits
tvscl,image ; display image
x=sx/2 & y=sy/2 ; initialize to center of plot
cursor,x,y ; use cursor command to get position
On occasion, a procedure will encounter an error and stop. You will know this
has happened when you see an error message followed by a traceback like
% Attempt to subscript K with is out of range.
% Execution halted at: DBHELP 192
/data/gremlin/fwalter/astrolib/pro/database/dbhelp.pro
% $MAIN$
When this happens, you can either try to fix the problem, or bail out. The
latter is generally recommended unless you know what you are doing. To bail
out, type RETALL. This will close the procedure and
return to the main level.
- To start up the NETSCAPE browser: netscape &
- To edit a file: use emacs
- Runing the latex type setting program is a two step process.
Assuming you have a tex file named filename.tex, you would
first type latex filename. Note that you do not include
the .tex in the file name. The latex program produces a
file filename.dvi.
To generate a postscript file, you will need to type
dvips -o filename.ps filename
This creates the postscriopt (.ps) file, which you can then print or
mail.
- To uncompress gzip compressed data (file name ends in .gz), use
gunzip.
Your SMARTS data are on the mathlab computer, in
/mt/cootie/home/fwalter/data and its subdirectories.
You can read these files directly, as in
data=readfits('mt/cootie/home/fwalter/data/XXX.fits',header). Note that you need to type the full path (including any other
subdirectories) every time.
Use cp to copy the data to your own directory, or scp to
copy to another computer.
Back to top