A Different Type of Lab
We've been writing a lot of programs and creating files. Now, it's time to kick things up a notch and use C to generate data files for another application, gnuplot.
~/public_html
. Any and all files that you put into
this directory become available on your web page. (If your user id
is foobar, your web page is http://udel.edu/~foobar).
To see if you have this directory, change your working directory
to your home directory and then see if the directory
"public_html" is listed. If you don't have the
directory already, create the public_html
directory.
public_html
directory and create a
cisc105 directory. The public_html/cisc105
directory
will store your CISC105 web page. In a later step in this lab, you
will create a personal web page (if you don't already have one) and a
web page specifically for this course.
The files for your personal web page go into the directory "~/public_html", and will be accessed via the URL http://udel.edu/~userid (where userid is your UDelNet ID).
The "CISC105 web page" goes into the folder "~/public_html/cisc105", and will be accessed with the URL http://udel.edu/~userid/cisc105. You can use this same technique to create as many web pages as you like under your main web page, just by creating new subdirectories to store the content.
<html> <head> <title>Joe Sample's Web page</title> </head> <body> <h1>Joe Sample's Web page</h1> I had to do this <b>web page</b> for my <a href="http://udel.edu/~pconrad/cisc105">CISC105 class</a>. Right now it is pretty lame, but I hope to make it better later. </body> </html> |
Here's what that looks like once it is formatted by a web browser:
Joe Sample's web pageI had to do this web page for my CISC105 class. Right now it is pretty lame, but I hope to make it better later. |
chmod a+rx ~/public_html/*
More details:The asterisk in the above command matches every file name in the public_html directory. You can also use chmod on individual files and directories as shown in class. You need to repeat this command each time you add new files under public_html that you want users of the Web to be able to access.
http://copland.udel.edu/~userid
If it
doesn't come up, make sure you set all your file permissions
correctly. The most common problem is not doing the "chmod
a+rx ~/public_html/*" command. If you did that, and it still
doesn't work, check with your TA or with a classmate for help.
<img src="imagename.jpg">
, where
"imagename.jpg" is the (case-sensitive) name of your file.
chmod a+r [filename]
command to get the web page to come up when you use the URL http://udel.edu/~jsample/cisc105.In this exercise, you will use a program called gnuplot to draw bar graphs. This exercise illustrates how you can use C with other applications.
You will first use a text editor to create a file that contains the size of the bars to draw. You will then use gnuplot to plot the bars and store the resulting graphic in an output file. The output file has the extension .png, which stands for "Portable Network Graphics". Files ending in .png are similar to files ending in .gif, .jpg, or .jpeg except they use a different format for representing the pixels in the image and for compressing those pixels.
This exercise also assumes you know how to put files on the web
under your public_html directory, use the chmod
command
to make those files readable, and point your web browser at those
files.
The link where you must put the files you create with this exercise is
http://copland.udel.edu/~userid/cisc105/lab08where userid is your strauss userid. Hence, the directory name is
~/public_html/cisc105/lab05
A typical gnuplot data file consists of lines of text, where on each line there are two numbers, representing an x-value and a y-value. Here is a gnuplot data file called "bars.dat", followed by an explanation of its contents:
# number of days in each month of 2005 1 31 2 28 3 31 4 30 5 31 6 30 7 31 8 31 9 30 10 31 11 30 12 31 |
Explanation:
set terminal png color large set output "bars.png" set data style boxes set boxwidth 0.4 set xtics nomirror set border 11 set xrange [0:13] set yrange [0:32] set xlabel "Months" set ylabel "Days in Month" plot 'bars.dat' using 1:2 title "Num Days" |
Create an array that maintains the number of times each number is generated by rand(), i.e., an array that maintains the frequency count of each number. Generate 10 random numbers between 0 and 9. Count how many times each number is generated and store it in the array. Print out the contents of the array.
Repeat the process for 100, 1000, and 10000 random numbers and print out the results. (Does the array size need to change?)
Start by generating the file for 10 generated random numbers. After you have worked the bugs out, generate the data files for 100, 1000, and 10000 random numbers as well.
bars.gnuplot
to plot the frequency counts. Label
the axes appropriately. Generate 4 graphs, one for each of the four
data files that you generated.
In your C files, comment on how random "rand()" is. How does randomness change with more iterations?
Submit your two C programs, four gnuplot, four data, and four png files to WebCT. Submit a printed script file of your C programs, compiled and executed to your TA. Then, cat each data file. Your TA will also grade your web pages and the generated graphs.
Parts of this lab were borrowed from Phill Conrad's Fall 04 Lab01 and Lab05 labs.