9 Text Files

9.1 I/O Redirection
9.2 Packages and import Statements
9.3 Reading from Files (Video)
    9.3.1 Iterators
    9.3.2 String Split Method
    9.3.3 Reading from Other Things
    9.3.4 Other Options (Java Based)
9.4 Writing to File
    9.4.1 Appending to File
9.5 Use Case: Simple Encryption
    9.5.1 Command Line Arguments
    9.5.2 Mapping a File
    9.5.3 Character Offset
    9.5.4 Alphabet Flip
    9.5.5 Key Word
    9.5.6 Putting it Together
    9.5.7 Primes and Real Cryptography

Exercises:

Projects:

W1. The web site http://cdiac.ornl.gov/epubs/ndp/ushcn/access.html has historical weather data for sites across the United States. For this project you should download some monthly files and you will do linear fits to the data in those files. Two files are present at the bottom of this page for San Antonio, TX and Boulder, CO. The idea is that you can see if there has been a general change in temperature over the length of data collection by finding the values of c and d such that temp = c*date+d is as close as possible to all the data point. To determine the best fit it is standard to minimize the sum of the squares of the offsets.

You can find the values of c and d by solving the linear equation, ATAx = ATy. The vector x is c and d, what you want to solve for. The vector y is simply all the temperatures. The matrix A has one row for each data row in the file and two columns for the coefficients of c and d. The coefficient of c is the date. To get this as s single number, instead of a year and month, you can use year+month/12.0. The coefficient of d is 1.

If you plug in all the values and do the matrix multiplication, you get ATA is a 2x2 matrix and ATy is a 2x1 matrix. Say the first matrix has elements a00, a01, a10, a11 while the second matrix has elements b0 and b1. You have add a multiple of the first row to the second such that the sum has a zero in the first column. This then gives you a linear equation with one variable and one unknown. You can solve that for d, then plug that into the first row to find c. This is a very small example of using Gaussian elimination to solve a linear equation. Do this for a few locations, including those for the files below, to see how the temperature has changed over the time span of these records.
ċ
CO050848_5142.csv
(50k)
Mark Lewis,
Oct 11, 2012, 8:31 PM
ċ
TX417945_1654.csv
(50k)
Mark Lewis,
Oct 11, 2012, 8:31 PM
Comments