Google
 

Chem 722 Homework


Getting Started with your account

Access to computers

The Chemistry department computer lab is in 2105 Newman-Wolfram. Access to this room is available 24 hours a day via a magnetic stripe reader and your OSU ID. Inside are Macintoshs, PCs, UNIX workstations and the printers. You may use any of these machines to log into your chemistry account on the Sun (UNIX). You may also log into your chemistry account from your home computer. If you do not have a chemistry computer account you may obtain one from the Chemistry department web page. Visit the URL

http://www.chemistry.ohio-state.edu/cgi/campus/acc-request.pl

and fill out the form to obtain your account.

Logging in to your chemistry unix account

From a Macintosh or PC:

Open a telnet session. Telnet to "chemistry". Enter your login name, and password at the prompt. Follow the directions for terminal type and backspace.

From a UNIX workstation in 2105 Newman-Wolfram:

Enter your login name and password at the prompt.

In either case, if this is your first login session you will be prompted to change your password. Please do so, but DO NOT forget your new password. If you forget your password, neither I nor anyone else can find out what it was, and it is a pain to fix. A good suggestion for passwords are the beginning letters of the words to a sentence you will remember, such as:

I will not forget my password. ---> Iwnfmp

or

I will not forget my password again!---> Iwnfmpa!

Notice that the "I" is capitalized, and that there is an exclamation point at the end of the second password. Unix is case sensitive, so Iwnfmp is different from iwnfmp is different from IWNFMP.

When finished, you log out of your account by typing "exit" or "logout" at the prompt.

Working on a UNIX machine

Basic Commands:

There are hundreds of commands available on your account, but you will only need to know about 10 basic comands to complete this course. They include:

ls: List files and subdirectories in this directory
Use ls to list the names of your files
Use ls -l to get a more extensive listing of files, showing size and type

man: List manual page for a command
Use man ls to list the manual page for the command "ls"

pwd: Print working directory (to the screen)
Use pwd to print the directory where you are.

cd: Change directory
Use cd to change to your home directory. Useful when lost.
Use cd .. to change to directory up one level
Use cd Chem722 to change to a subdirectory called Chem722

cp: Copy a file
Use cp hw1 hw1.backup to copy a file called hw1 to a new file called hw1.backup

rm: Remove a file
Use rm core to remove permanently a file called core
Note: there is no undelete in UNIX. Once it's gone, it's gone forever. Be careful with this command.

more: List the contents of a file to the screen
Use more mean.c to list the file mean.c to the screen

lp: Print a file
Use lp mean.c to print the file mean.c to the printer

Programs

There are only a few program you will need to use to complete this course. The following are the simplest, most basic programs available to do the job. They are not the fastest nor the easiest, but they should work on all platforms in the computer lab and at home. If you are familiar enough with computers to use other programs you are free to do so, but you will be on your own.

fse: Starts the "full screen editor" program
Use fse mean.c to edit the file called "mean.c"
Note: very easy to use but brain-damaged text editor.

gcc: gnu C compiler program
Use gcc hw1.c to compile and link a file called "hw1.c"
Note: There are many options. There will be a handout on cc later.

gnuplot: Graphing program
Use gnuplot to start the program "gnuplot"
Note: There will be a handout on gnuplot later.

mail: Mail program
Use mail to start the mail program
Note: described below

Getting the homework assignments

Reading mail on your chemistry unix account

Part of the homework assignments will be handed out in class, but some components (such as C source code and data) may be sent to your chemistry account by e-mail. You will need to save these to individual files, and then edit the files to clean up any excess text attached by the mail program. You will enter the mail program by typing the command

mail

at the prompt. Highlight the e-mail you wish to read by using the arrow keys. Press the space bar. The e-mail will appear on the screen. If the letter is several pages long, press spacebar to scroll down another page. At its end (or at any time) press "q" to quit reading the letter and press "i" to return to the index. When you have finished press "q" to quit the mail program.

Saving mail on your chemistry unix account

Highlight the e-mail you want to save, using the arrow keys. Press "s" to save your e-mail to a file. If the filename begins with "=", the file will appear in your "Mail" directory. If not, it appears in the directory you started the mail program from. If you save your mail and then cannot find it, look in your directories. You may not have been in the directory you thought you were, when you started the mail program.

Do not delete your old data files and source code until you are {\bf sure} they are no longer needed.

Handling the data files

Your data files received by e-mail or downloaded from Netscape may need to be "cleaned up" before forging ahead with your assignment. To open a previously saved data file called "hw1.data" in the text editor "fse", enter

fse hw1.data

Remove the mail header from the file (all those lines that say "From:" or "To:" or "X-Sender:" or whatever) along with anything I might have added (like "1000 point set number 8") so that only the data (the column of numbers) remains. Check both the beginning and the end of the file. When finished, hold down the Control key and briefly press the "x" key. If you have made a mistake answer "N" and your file will not be changed.

Writing the programs

You will downloaded C-language source code from the Chem 722 homework web pages. After you have written the missing parts of the code you must compile and run the file hw1.c with the line

gcc hw1.c -lm

Getting Started with gnuplot

The Program

Gnuplot is a free, readily available all-purpose plotting and fitting routine. Versions are available for most platforms, including Unix, Mac and PC. The only versions that are installed in the computer lab are on the UNIX machines. Use them if they are free. If they are busy, you may login to your account from a Macintosh or PC and run gnuplot remotely.

The FAQ for gnuplot gives much more in-depth information. What is presented here is the bare minimum needed for this course, but the program will do much more.

If you want to install gnuplot on your home computer, click here to download a Macintosh version of gnuplot or click here to download a PC version of gnuplot

Running the UNIX version of gnuplot on a UNIX machine

Login to your account. To begin the program enter "gnuplot" from your prompt. The terminal type is already set to X11.

Running the UNIX version of gnuplot using Telnet on a Macintosh

You will need to configure Telnet so it can display the graphics. Start NCSA Telnet. At the top of the screen under Edit, select "Preferences" and then "Sessions". Click on <chemistry> if present or <default> otherwise and then "Change". The third line from the top says "Tek". Beside it click on 4014 (the type of Tek emulation you need). Click on "OK" twice to get out of configuration section. Telnet to chemistry and login. Start gnuplot by typing "gnuplot" at the prompt.

In either case...

You should see the gnuplot prompt, which is shown below.

gnuplot>

If you started are running the UNIX version of gnuplot using Telnet on a Macintosh the program will say "term type unknown". Enter the command

gnuplot> set term tek40xx

so you can display graphics. Enter "help" for a list of commands with explanations.

Plotting Functions

Let's try a few examples: To plot the function sin(x)

gnuplot>  plot sin(x)

To plot the functions sin(x) and cos(x) together

gnuplot> plot sin(x), cos(x)

To plot the function y(x)=3*x + 5

gnuplot> plot 3*x + 5

Another way to plot the function y(x)=3*x + 5

gnuplot> y(x) = 3 * x + 5

gnuplot> plot y(x)

To make sure y(x) has been defined use

gnuplot> show functions
User-Defined Functions: y(x) =3*x+5

Plotting Data

To plot a data file called "bignums.txt"

gnuplot> plot "bignums.txt"

Note: the double quotes are required! To plot the function y(x) = 3*x**2 - 5 * x + 2 from x= -3 to x= 6.4

gnuplot> y(x) = 3*x**2 - 5 * x + 2

gnuplot> plot [-3:6.4] y(x)

You can use the show functions command to check that the previous definition of y(x) was overwritten.

To plot a previously-made histogram called "my_histo.txt"

gnuplot> plot "my_histo.txt" with boxes

If you were plotting the file "myfile.txt" between limits with impulses.

gnuplot> plot [-5:14][0:6] "myfile.txt" with impulses

gnuplot> show term

Remember your terminal type!

Making Contour Plots

It is a bit tricky to make gnuplot do contour plots. Your data should be in the form

x1  y1  z1

x2  y2  z2

x3  y3  z3

etc...

with no blank lines. To make a contour plot with 10 levels of an (x y z) dataset called chibig.txt, do the following:

gnuplot> set parametric

gnuplot> set dgrid3d

gnuplot> set contour base

gnuplot> set nosurface

gnuplot> set view 0,0

gnuplot> set cntrparam levels auto 10

If you want more or less than 10 levels, change the number in the preceding line to whatever you want.

To plot the contour plot use

gnuplot> splot "chibig.txt" with lines

note that the command is "splot" (for surface plot), not plain old "plot". We've tested this on all 3 platforms and it works identically, so it should work for you. To print, use the method described below.

If you really care, you can enter "help set" to find out more about all those options you typed in.

There is a problem with the memory management in gnufit for the pc, and you may occasionally get "out of memory for isoline surfaces", or something like that, when making a bunch of contour plots under Windows 3.1. if you get this error quit gnufit and try it again, or switch to DOS (instead of a DOS window under Windows), which seems to do better.

Using gnuplot for fitting

Gnuplot has a built-in fitting routine using the Marquardt-Levenberg algorithm. This is quite fast and robust as fitting routines go. It will perform linear and non-linear fits for most any analytical function. To fit your data to a function y(x) first define the function:

gnuplot> y(x) = a*x**2 + m*x + b

Notice the FORTRAN convention of using double asterisks to achieve exponents. Next give some starting values for the parameters. They must include a decimal point!

gnuplot> a = 1.0

gnuplot> m = 5.0

gnuplot> b = 2.0

If you enter anything like

gnuplot> a = 1 ****** wrong *****

the program will blow up (that is, it will not converge and complain about a "Singular Matrix"). Then the command to fit the function y(x) to a datafile called "pair0.txt" is

gnuplot> fit y(x) "pair0.txt" via a, m, b

followed by lots of output. If you have entered "good" initial guesses for the parameters, then the fit should converge in just a few seconds. The results will appear on the screen and will be appended to a file called "fit.log". When reporting results, make sure you are looking at the correct section of "fit.log", as it can get confusing.

Printing from within gnuplot (to a Postscript file)

gnuplot> set term postscript

gnuplot> set output "some_name.ps"

gnuplot> replot 

The plot will be saved to the file "somename.ps".

gnuplot> set output

To reset the output to the screen use

gnuplot> set term X11

or to vttek, tek40xx, or whatever your terminal type was. To send the PostScript file to the printer use

gnuplot> !lp "some_name.ps" 

More about compiling your code

In "Getting started with Homework 1" I said (at one point) to enter the magic phrase "gcc hw1.c -lm" to compile your program. If you wish to know more about what exactly that phrase did, read on. If you don't care, you can stop now and go do something useful.

Of the three parts of the magic phrase, the first was "gcc". This stands for "GNU C compiler", where GNU is a sort of brand name. By typing this command you start the compiler, but you must now tell it what to compile. You can think of the compiler as a sort of translator.

The second part of the phrase was "hw1.c", which is the name of the source code you want to compile. Your source code contains the instructions that tell the computer what to do, but the computer cannot understand them the way they are written (in C language plain ASCII text). C is a "high level" language, meaning that it has a lot of built-in functions incorporated into it. C is relatively easy to use, and but still very powerful. "Low level" languages like assembler are incredibly powerful, but much more difficult to use.

In order to "translate" your C code into something the computer can understand, the code must be compiled and the output turned into an executable (a binary file). The executable it can understand, as long as it was translated (compiled) for that specific type of computer. If you want to make your code run on a Macintosh, then you must compile it on a Macintosh. If you want to run the code on a Sun (like your chemistry account), then you must compile on a Sun. All computers work this way. This is why you cannot just take a Macintosh program and run it on a PC, or the other way around, without first recompiling on that machine.

The third part was "-lm". Not all of the functions used in the file hw1.c are defined there. For instance, if you needed to take the sine of some number, you shouldn't have to program in the definition of sine and how to compute it. Many of those those things have already been done and are in the "math library". Things like sine, arctangent, square root, rounding, and so forth. To tell the compiler to look in the math library for these needed functions, you must add the "-lm" at the end of the command. This is called "linking" to the math library. There are other libraries available if you are programming for graphics, sound, X windows, sockets, and many others.

Options for gcc

If you want to read more about gcc, then enter

man gcc

from the prompt. There are about a million options for gcc. If you were going to use any of them, you would enter the option after the "gcc" and before your filename. The option for linking is different, as it always goes at the end. For example, if you wanted to turn on optimization level 3 (-O3) while linking to the math library it would look like

gcc -O3 hw1.c -lm

Several of the more common options are

-ansi                  turn on strict ANSI C rules
-c                     stop at the compile stage, without linking
-lstuff                link with the library "stuff.a" found in the standard location
-o somename.out        name the executable "somename.out" instead of "a.out"  
-O                     turn on optimization of increasing higher level
-O2
-O3

All of this is completely unnecessary to know for the completion of this course, so don't worry if you didn't understand it.



                                    |