clear all;
close all;

load precip_sno.txt;

  % first three values are year,month, and day
  % datenum in this instance converts time into a single 
  % numerical value so that we know
  % that consecutive days are separated by a value of 1
  dates = datenum(precip_sno(:,1:3));
  data(:,1:7) = precip_sno(:,4:10);
  %data(:,1)=ben lomond peak
  %data(:,2)=ben lomond trail
  %data(:,3)=tony grove lake
  %data(:,4)=snowbird
  %data(:,5)=thaynes canyon
  %data(:,6)=timpanogos
  %data(:,7)=payson
  
  [nd,nn] = size(dates);

  %for convenience and to match notes, define x
  % columns are locations and rows are years

x = data(:,1:7);

figure(1)
hold on;
bar(dates,x(:,1));
datetick('x',25)
xlim([726742 733194]);

xm = mean(x);
xs = std(x,1);

% anomalies
xp = x - ones(nd,1) * xm ;

% standardized anomalies

xstar = xp ./ (ones(nd,1) * xs);

figure(2)
hold on;
bar(dates,xstar(:,1));
datetick('x',25)
xlim([726742 733194]);

% linear algebra way to compute cross correlations

rho_1 = transpose(xstar)*xstar / nd;

figure(3)
hold on
[C,hc]=contour(rho_1);
clabel(C,hc);
