University of Alaska Fairbanks
Geophysical Institute

Beyond the Mouse 2010 - The geoscientist's computational chest.

Lab 5: Matlab I/O 1

"Programming is legitimate and necessary academic endeavor."
Donald E. Knuth

Lab slides

none.

Exercise 1:

Download the file FAIR.pfiles and open it in a text editor (could be Matlab's editor) to have a look at it. It's again a file that contains daily positioning solutions for the continuous GPS site FAIR. This is a more or less typical text file that may or may not cross your path at some point in your future. There's one header line documenting the meaning of the columns, a bunch of columns and many, many rows of data. Here's again what the columns mean:

epoch (decimal year) | GPS Site | Tie Site | Longitude (deg) | Latitude (deg) | Height (m) | Sigma_east (mm) | Sigma_north (mm) | Sigma_vert (mm) | cov_en | cov_eu | cov_nu | path to solution file

Your job is it to write a script that reads the whole file. Skip the one headerline by setting the right parameter-value-pair (read the documentation!) -- you are not allowed to remove it manually from the data file! Then your script will write the columns epoch, lon, lat, and height into a new file FAIR2.dat. Once this works add the site 'FAIR2' to your station definition cell array from the lab 04 and run the script to plot the data. It should be fairly similar to station FAIR (at least the vertical).

The purpose of this exercise is in having you figure out what format strings to use, how to put one together, and to decide which function to use for reading and writing your data. Plus some documentation reading.

Exercise 2:

Take the script you've just written and turn it into a function decimate_data that has two parameters, the name of the input data file and the desired name of the output file. There is no need for a return value here. Adapt your code from the script such that it uses these parameters rather than operating on hardcoded file names. Then write a script that calls decimate_data for FAIR.pfiles and creates FAIR2.dat. I encourage you to use try-catch to make sure your code does not just crash when a file does not exist.

Summary questions

(no need to implement these, think about them and write out your answers)

Assume your plotting routine from LAB 04 remains stable, but the respective station data you want to display will vary. What would be a reasonable step to avoid having to edit the gps_station cell array at the beginning of your script every time the stations you want to display change, AND you don't want to display all available data but a select subset of what ever is in your database?

Now assume your data lives in different directories. How could your change your solution for LAB04 to accomodate such distributed data? Hint: Think back to the part of the solution for the flow chart problem from Lecture 1 and 2 that dealt with lecture number and dates.

Stuff to turn in (I recommend sending in an archive):

Helpful Matlab Functions:

Here is a list of functions that might be of help.

ronni <at> gi <dot> alaska <dot> edu | Last modified: February 01 2013 21:40.