UMBC CMSC201, Computer Science I, Spring '97

Project 5: Oil Spill Simulation

Due: Monday, May 12, 1997

Your assignment is to write a program that simulates an oil spill and the movement of the oil over time under certain conditions. This project will give you practice using two-dimensional arrays, passing an array to a function, pointers, getting input from the user using scanf, and reading from a file using ansi C functions, rather than unix redirection.

You are not allowed to use any of the Roberts' libraries for this project


Description of the Oil Spill and Simulation

Your program will simulate an oil spill involving 8,000 gallons of crude oil. You will run the simulation over a 225 square mile area, a 15 mile X 15 mile square.

You must keep track of the number of gallons of oil that are present on the surface of each square mile. The number of gallons in a particular square-mile location will vary over time due to environmental factors, i.e. the tides, wind, etc. For this simulation we will be concerned only with the effects of the wind on the oil spill.

If the wind is from the west, then the oil in a particular location will be pushed primarily to the east, affecting the neighboring areas to the north, north-east, east, south-east and south. Some portion of the oil will stay within the original square-mile area. Obviously the area to the east will get the largest influx of oil. Over time, the spill will shift significantly to the east.

The initial number of gallons of oil per square-mile location are found in the file "oilspill.dat". Basically, the file contains 225 integer values separated by whitespace. This is the contents of the file. You may assume that none of the integers found in the file will be larger than 3 digits. I guarantee that there are 225 integers in the file, so checking for EOF is not necessary.

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

You will be reading the values found in the file into a two dimensional array. This array will then hold the original number of gallons found in each square- mile area at the time of the spill.

You will also be asking the user to say how many time intervals should pass between displaying the values for each square-mile area, and the total amount of time for the entire simulation, as well as the wind direction. We will assume a constant wind velocity so that you do not need to consider it in your calculations.


A Sample Run

retriever[102] a.out Please enter the time interval : 5 Enter the total time : 15 Enter the wind direction : w Time: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 500 500 500 500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Time: 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 6 8 7 4 1 0 0 0 0 0 0 0 1 10 28 43 47 39 20 5 0 0 0 0 0 0 0 9 49 108 149 153 114 56 15 1 0 0 0 0 0 0 28 116 229 303 299 213 100 26 3 0 0 0 0 0 0 36 154 305 402 396 282 130 34 3 0 0 0 0 0 0 36 154 305 402 396 282 130 34 3 0 0 0 0 0 0 28 116 229 303 299 213 100 26 3 0 0 0 0 0 0 9 49 108 149 153 114 56 15 1 0 0 0 0 0 0 1 10 28 43 47 39 20 5 0 0 0 0 0 0 0 0 0 3 6 8 7 4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Time: 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 5 6 5 3 0 0 0 0 0 0 0 0 1 7 15 23 26 21 13 0 0 0 0 0 0 0 1 10 28 51 69 71 57 35 0 0 0 0 0 0 0 6 28 67 114 145 144 113 68 0 0 0 0 0 0 1 13 49 114 186 231 226 173 102 0 0 0 0 0 0 2 17 65 146 235 289 280 213 124 0 0 0 0 0 0 2 17 65 146 235 289 280 213 124 0 0 0 0 0 0 1 13 49 114 186 231 226 173 102 0 0 0 0 0 0 0 6 28 67 114 145 144 113 68 0 0 0 0 0 0 0 1 10 28 51 69 71 57 35 0 0 0 0 0 0 0 0 1 7 15 23 26 21 13 0 0 0 0 0 0 0 0 0 0 2 5 6 5 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Time: 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 1 3 8 11 12 0 0 0 0 0 0 0 0 0 1 6 15 26 34 36 0 0 0 0 0 0 0 0 0 5 18 38 59 74 75 0 0 0 0 0 0 0 0 2 13 37 72 107 129 128 0 0 0 0 0 0 0 0 5 22 57 106 155 185 180 0 0 0 0 0 0 0 0 7 28 71 129 187 220 213 0 0 0 0 0 0 0 0 7 28 71 129 187 220 213 0 0 0 0 0 0 0 0 5 22 57 106 155 185 180 0 0 0 0 0 0 0 0 2 13 37 72 107 129 128 0 0 0 0 0 0 0 0 0 5 18 38 59 74 75 0 0 0 0 0 0 0 0 0 1 6 15 26 34 36 0 0 0 0 0 0 0 0 0 0 1 3 8 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 retriever[103]


More details


The data file

The data file for this project is called oilspill.dat and it is found in my 201 directory. You should copy this file into your own directory. The executable and this data file need to be in the same directory. Here's how:
Change directory until you are in the directory where you will write your code and have the executable, then type the following command at the unix prompt. cp ~sbogar1/201/oilspill.dat oilspill.dat

What to Turn In

You must use separate compilation for this project and should have a file, called proj5.c, that contains only the function main(). You should also have an oilspill.c and oilspill.h, that contain the functions used by proj5.c and the prototypes for those functions, respectively. Submit as follows: submit cs201 proj5 proj5.c oilspill.c oilspill.h The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project are listed.