% ComputeClimateTren.m
%
% Josh Thompson, 4.22.13
%
% This is the top-level control of the NOAA - climate example


% 

% Choose a file to load below
% CleanUpClimateData
	S = importdata('ushcn-v2.5-stations.txt',',')
	load(['~/Teaching/MA211/ClimateData/MaxTempsStation_187.mat']);


% Plotting Settings
	set(0,'DefaultFigureWindowStyle','docked')
	figure; hold on;
	S = {'Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'};


% Months/Avg
	J = 2:13;

% For each column of data, compute a Least Squares Estimate & Plot
for j = J 

	% Plotting
	title(S{j-1});
	xlabel('Year');
	ylabel('Temperature in Farenheit');

	% Compute Least Squares
	[v,xd,yd] = LeastSq(1,F(:,j)');

	% Years are in the first column, but at end of timestamp	
	Year = num2str(F(:,1));
	Year = str2num(Year(:,end-3:end));

	% Plot the raw data
	hb = plot(Year,F(:,j),'.')

	% Compute the approximating line
	x = 1:length(Year); 
	y = v(1) + v(2)*x; % + v(3)*x.^2;

	% In case you want to try en exponential model
	%x = 1:length(F(K,j)); y = v(1) *exp( v(2)*x); % + v(3)*x.^2;

	% Plot the approximating line
	hr = plot(Year,y,'r-','LineWidth',10)

	% Display Info
	disp(['Slope is ', num2str(v(2))])
	pause

	% Remove previous plots, unless last	
	if j ~= J(end)
		set(hb,'Visible','Off')
		set(hr,'Visible','Off')
	end
end

