
Page 1 of 1
CSCD 309: Scientific Programming
HW #6: I/O, Interpolation, Curve Fitting
Due: Wed May 20
Put your work in a script file as previously.
1) On the course website there is a text file called “molecule.txt”. This is a file from some
program that is describing the structure of a molecule. In this case the molecule being described
is a hydrocarbon called benzene (until I changed one of the atoms, that is). Write a function
called parse_molecule() that takes the filename as an input string, and returns 3 items, parsed
from the section of the file marked as @ATOM: a 2xn matrix with two characters per entry for
the atomic symbol (second column of entries), and corresponding vectors containing the x and
y coordinates of the atom (third and fourth columns). You should ignore the first and fifth
columns in this section of the file, and the other portions of the file. There are a few things to
note about this case: (a) when parsing both numbers and characters (or strings), all items will
be returned as numbers. Thus you will have to call the char function on the atomic symbol
characters to convert them from ASCII code numbers to characters. (b) this case is a bit tricky
in that the atomic symbol can be 1 or 2 characters. See the lecture notes for the difficulty this
causes. You are required, however, to process all of the desired data lines in the file with a
single call to fscanf. The secret in this case is to make use of %c. (c) as noted in the lecture,
Octave does not currently perform early exit of the evaluation of the logical OR of multiple
conditionals. Thus you will have to modify the example code where it searches for a key line in
the file in order to avoid a runtime error. Once you have the file parsed, plot the x,y locations of
the molecules, using a diamond symbol for the carbon atoms (C), a square symbol for the
Hydrogen atoms (H), and an asterisk for the Helium atoms (He).
7.17ab. Depending on whether you’ve updated lately, Octave / Windows either has a broken
ginput, or no ginput at all. Thus you can skip parts c and d. Note that you should still be able to
read the crossover point with a cursor though, there’s just no way to throw an interactive
determination from the plot back into a variable in your script.
12.1, 12.4, 12.6, 12.8a, 12.10bcd
Turn in your homework by emailing your script and any function files to me by the due date.