TOPIC 1: UNIX STUFF Very basic things you should know about *nix: You live in a "shell": an interface to the operating system. Shells allow you to move around the computer, look at files, manipulate files and directories, and run programs. A GUI, such as Windows, OS-X, or Gnome provides mostly the same functionality in visual form. Depending on what you are doing, a GUI can be more efficient than a shell, and vice versa. For our type of work, shells are the way to go. The operating system is an interface for the kernel, which is, in turn, an interface for the system hardware. The kernel knows how to read a harddrive, access RAM, tell the video card how to display something on a monitor, etc. Just like there are many operating systems and many kernels, there are many shells. I use bash (the "Bourne Again SHell"), but IDL is set up to use a cshell, either csh or tcsh. It doesn't really matter, they all provide the same basic functionality. Let us investigate. Open a shell. You should see something like tarrl@GodofGords-desk ~$ which follows a format like USER @ COMPUTER to find out where you are, use the "print working directory" utility: tarrl@GodofGords-desk ~$ pwd [ENTER] /home/tarrl This tells me I am in the directory. This is my personal "home directory" on this computer. We can find out what this directory holds by using the "list" utility: tarrl@GodofGords-desk ~$ ls [ENTER] Next commands to run. I've put all my comments between angle brackets, like so < a comment > : tarrl@slab ~$ cd .. [ENTER] <"change directory" up one level, to /home/> ls cd / ls cd no[TAB] pwd cd <"change directory" with no argument takes you back home> ls cd /bin ls The /bin/ directory holds a bunch of standard system utilities. Peruse the list. Some of these we've already encoutered: "ls", "pwd"... Below I've listed the most used commands: ls : list contents of a directory (current directory, by default) cp {I1} {I2}: copy something from item 1 to item 2. mv {I1} {I2}: mv something from item 1 to item 2. This is how you rename a file or directory, or overwrite a file or directory. rm {I} : remove (delete) an file or directory mkdir {name} : make a directory called "name" more {file} : display contents of a text file less {file} : display contents of a text file, but do it better (less is more) And finally... man {command} : display the manual for "command", so you can learn how to use it For example: tarrl@GodofGords-desk bin$ man mkdir [enter] [q] ++++++++++++++++++++++++++++++++++++++++++++++++++++ TOPIC 2: STAYING CONNECTED You will be working in IDL on remote computers that you connect to via SSH. At some point, you may wish to leave something running overnight on the remote computer, but disconnect your laptop and take it with you. How do you do this? The answer is the 'screen' program. Screen creates a virtual session on a computer that may be detached and reattached. Example session: tarrl@compy1 ~$ ssh -X tarrl@compy2 [enter] tarrl@compy2 ~$ screen -ls [enter] There is a screen on: 21613.pts-1.helios (01/10/2011 12:10:10 PM) (Detached) 1 Socket in /var/run/screen/S-tarrl. This tells me that I currently have session currently running, and it is detached. Let's start a new session: tarrl@compy2 ~$ screen [enter] It looks like nothing really happened, but it did. We are inside the virtual command line. All of screen's functionality is accessible by typing [Ctrl-a]. For instance, to read screen's help file, go like so: tarrl@compy2 ~$ [Ctrl-a ?] For instance, we see that we may title our session by typing [Ctrl-a A], we may open a new window within the session by typing [Ctrl-a c], and we may list all the windows (and select one to focus on) in a current session by typing [Ctrl-a "]. Most important, we may detach a session by typing [Ctrl-a d]... tarrl@compy2 ~$ [Ctrl-a d] Screen tells us we have [detached], and we are now sitting again at a prompt. tarrl@compy2 ~$ screen -ls There are screens on: 8353.pts-9.helios (05/16/2011 01:43:52 PM) (Detached) 21613.pts-1.helios (01/10/2011 12:10:10 PM) (Detached) 2 Sockets in /var/run/screen/S-tarrl. Now we see that they're are two sessions open, and what the timestamps mean. Apparently, I opened screen session 21613 in January of this year. That's why screen is awesome. If my connection drops, or I wish to detach and switch workstations, screen just keeps happily chugging away on the remote server, and I don't lose any of my work. We can reattach to a detached session by specifying it's session number: tarrl@compy2 ~$ screen -r 21613 tarrl@compy2 ~$ [Ctrl-a d] Occasionally, our X display (graphical stuff) may be messed up. To fix, we can figure out what our current display is: tarrl@compy2 ~$ echo $DISPLAY localhost:13.0 connect to screen session: tarrl@compy2 ~$ screen -r 21613 and set the display correctly: tarrl@compy2 ~$ export DISPLAY=localhost:13.0 tarrl@compy2 ~$ setenv DISPLAY localhost:13.0 This may or may not be necessary. ++++++++++++++++++++++++++++++++++++++++++++++++++++ TOPIC 3: WRITING STUFF Programmers edit text in a text editor, of all things. There are many editors: nano, gedit, textedit, notepad, scite. MS Word is not a text editor. The editors above are all fine for simple things like writing letters, but for more complex activities (like programming) they have their drawbacks. Because of this, most programmers use one of two editors: VI (pronounced "vee-eye") or EMACS. Both are fully featured editors packed with all sorts of goodies to make your life easier. Fools care which one you use, but just ignore them. Pick one and don't look back. NOTES: EMACS is almost always in write-mode: you press a button, it shows up in your text. The exception is when you hold Ctrl or Alt while pressing a button, in which case you issue a command. In VI you switch into insert-mode by typing 'i', and out by pressing 'esc'. You inter command mode by typing ':'. Get help by typing ':help' http://www.cs.colostate.edu/helpdocs/emacs.html and http://www.cs.colostate.edu/helpdocs/vi.html appear to have useful basic commands for each. If you decide to use vi, consider buying http://www.thinkgeek.com/homeoffice/mugs/7bbe/ ++++++++++++++++++++++++++++++++++++++++++++++++++++ TOPIC 4: IDL STUFF Finally, we reach the *real* purpose of these beginning sessions: an introduction to IDL. Variable types: integers, floats, doubles, strings, structures...there are more, but those are the main ones. Compare: IDL> a = 1 IDL> b = 2 IDL> c = 1. IDL> d = 2. IDL> print, a 1 IDL> help, a A INT = 1 IDL> help, b B INT = 2 IDL> help, c,d C FLOAT = 1.00000 D FLOAT = 2.00000 IDL> print, a/b 0 IDL> print, a/d 0.500000 IDL> print, 5/4 1 IDL> print, 5./4 1.25000 IDL> print, 5.0/4 1.25000 IDL> print, a+b+c+d ; IDL ignores everything after a semicolon 6.00000 IDL> e = double(a) IDL> print, c, e 1.00000 1.0000000 So there you have integers, floats, and doubles. doubles are "double precision": higher accuracy, and take up more memory than, floats. We can also make arrays of numbers: IDL> a = intarr(5) & print, a ; Use the '&' to issue two commands on one line 0 0 0 0 0 IDL> b = indgen(5) & print, b 0 1 2 3 4 IDL> print, a + $ ; Use the '$' to split a single command between two lines IDL> 2*b 0 2 4 6 8 IDL> c = fltarr(10) & print, c 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 IDL> d = findgen(10) & print, d 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 Things get weird when you try to add arrays of different lengths: IDL> help, a, d A INT = Array[5] D FLOAT = Array[10] IDL> print, n_elements(a), n_elements(d) 5 10 IDL> e = a+d IDL> print, e 0.00000 1.00000 2.00000 3.00000 4.00000 IDL> print, d 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 IDL> f = d+a IDL> print, f 0.00000 1.00000 2.00000 3.00000 4.00000 We can concatenate arrays, and also overwrite previously used variables: IDL> f = [a,d] IDL> print, f 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 Now, strings: IDL> a = 'This is a string' IDL> b = 'This is a more different string' IDL> print, a+b This is a stringThis is a more different string IDL> help, a A STRING = 'This is a string' IDL> c = 'What if I want's an apostrophy, eh?' ; this doesn't work c = 'What if I want's an apostrophy, eh?' ; this doesn't work ^ % Syntax error. IDL> c = "What if I want's an apostrophy, eh?" ; this does! IDL> print, c What if I want's an apostrophy, eh? We can sometimes force type of a variable to change: IDL> a = '5' & help, a ; a is a variable of type String containing the character '5' A STRING = '5' IDL> print, a+2 & help, a+2 7 INT = 7 IDL> print, a+'2' & help, a+'2' 52 STRING = '52' IDL> b = float(a) & help, b B FLOAT = 5.00000 IDL> print, b+'some string'; it doesn't like this! % Type conversion error: Unable to convert given STRING to Float. % Detected at: $MAIN$ 5.00000 We can also have arrays of strings: IDL> c = 'c' IDL> d = replicate(c,10) IDL> print, d c c c c c c c c c c IDL> help, d D STRING = Array[10] ...but not arrays of strings and numbers: c = ['Lucas wishes he found a',50,'dollar bill yesterday'] % Type conversion error: Unable to convert given STRING to Integer. % Detected at: $MAIN$ % Type conversion error: Unable to convert given STRING to Integer. % Detected at: $MAIN$ That is often a useful thing to do, and we get around this using things called structures, which are variables that hold other variables. Structures are defined using braces, { and }, and giving each variable in a structure a name: IDL> c = {name:'Lucas', units:'Dollars', amount:randomu(2,7), days:['Mon','Tue','Wed','Ths','Fri','Sat','Sun']} IDL> help, c C STRUCT = -> Array[1] IDL> help, c,/structures ** Structure <8c77864>, 4 tags, length=136, data length=136, refs=1: NAME STRING 'Lucas' UNITS STRING 'Dollars' AMOUNT FLOAT Array[7] DAYS STRING Array[7] IDL> print, c.name Lucas IDL> print, c.amount 0.342299 0.402381 0.307838 0.820642 0.0691442 0.512821 0.860873 We could also give the structure a name: IDL> c = {Money_Struct,name:'Lucas', units:'Dollars', amount:randomu(2,7), days:['Mon','Tue','Wed','Ths','Fri','Sat','Sun']} IDL> help, c C STRUCT = -> MONEY_STRUCT Array[1] IDL> help, c,/str ** Structure MONEY_STRUCT, 4 tags, length=136, data length=136: NAME STRING 'Lucas' UNITS STRING 'Dollars' AMOUNT FLOAT Array[7] DAYS STRING Array[7] But no one actually does that. Finally, we can make arrays of structures: d = replicate(c,3) & help, d D STRUCT = -> MONEY_STRUCT Array[3] IDL> print, d.name Lucas Lucas Lucas IDL> d[2].name = 'Lucilia' IDL> print, d.name Lucas Lucas Lucilia IDL> d[2].amount +=100. ; Lucilia found way more money than I did IDL> print, d[0].amount 0.342299 0.402381 0.307838 0.820642 0.0691442 0.512821 0.860873 IDL> print, d[2].amount 100.342 100.402 100.308 100.821 100.069 100.513 100.861