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:

Finish Lab 04!

Exercise 2: (Commented Solution, Solution archive (zip) including adjusted plotting routine)

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 no documentation, a bunch of columns and many, many rows of data. Here's what the columns mean:

epoch | 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, read in the whole file and write column epoch, lon, lat, and height into a new file FAIR2.dat. If you succeed you should be able to add the site 'FAIR2' to your station definition cell array from the previous lab 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 it, to have you figure out what format strings to use, how to put it together, and to decide which function to use for reading and writing your data.

Summary questions

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

Assume your plotting routine from LAB 04 remains fairly steady, 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?

Solution: You turn plot_station.m into a function that takes a cell array gps_station as input parameter. This way you can call plot_station.m with whatever station names in form of a cell array argument from either the command line or from other scripts while the code of plot_station.m remains untouched.

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.

Solution: There are quite a few solutions possible for this. One would be to turn the function input gps_station into a 2D cell array that contains both path and file name. Or give the full path as a filename. Another option would be to introduce global paths were data is assumed. For this to take effect though, the code between lines 24 and 35 in the plot_station.m would need to be adjusted (where we create the filename).

Helpful Matlab Functions:

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

ronni <at> gi <dot> alaska <dot> edu | last changed: December 27, 2010