%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
%    Workbook: \\cabin\CCHRC\Building Science Research\Projects\CRREL
%    Permafrost Fdn 4008-001\Robbin RTF Foundation Stuff\Old RTF\South
%    Lab\south lab baseline for Matlab.xlsx Worksheet: West of bay
%
% To extend the code for use with different selected data or a different
% spreadsheet, generate a function instead of a script.

% Auto-generated by MATLAB on 2014/11/13 10:37:50

%% Import the data, extracting spreadsheet dates in Excel serial date format
[~, ~, raw, dates] = xlsread('\\cabin\CCHRC\Building Science Research\Projects\CRREL Permafrost Fdn 4008-001\Robbin RTF Foundation Stuff\Old RTF\South Lab\south lab baseline for Matlab.xlsx','West of bay','A4:M1999','',@convertSpreadsheetExcelDates);
raw = raw(:,[2,3,4,5,6,7,8,9,10,11,12,13]);
dates = dates(:,1);

%% Create output variable
data = reshape([raw{:}],size(raw));

%% Create table
south = table;

%% Allocate imported array to column variable names
south.TIMESTAMP = datetime([dates{:,1}].', 'ConvertFrom', 'Excel', 'Format', 'MM/dd/yyyy');
south.halfdeep = data(:,1);
south.onedeep = data(:,2);
south.onepoint5deep = data(:,3);
south.threedeep = data(:,4);
south.threepoint5deep = data(:,5);
south.fourdeep = data(:,6);
south.fivedeep = data(:,7);
south.tendeep = data(:,8);
south.fifteendeep = data(:,9);
south.twentydeep = data(:,10);
south.twentyfivedeep = data(:,11);
south.thirtydeep = data(:,12);

% For code requiring serial dates (datenum) instead of datetime, uncomment
% the following line(s) below to return the imported dates as datenum(s).

% south.TIMESTAMP=datenum(south.TIMESTAMP);

%% Clear temporary variables
clearvars data raw dates;
%convert timestamp to date vector
[year, month,~,~,~,~]=datevec(south.TIMESTAMP)
%insert month column into the table
month=table(month)
south=[month,south]
year=table(year)
south=[year,south]
%remove timestamp 
south(:,'TIMESTAMP') = [];
%average data based on month and year
foundationmonthly=varfun(@mean,south,'groupingvariables',{'year','month'})
%transpose to monthly columns for whiplash curves
foundationarray=table2array(foundationmonthly)
South2=array2table(foundationarray.')
%remove first rows of monthly, year and count numbers
South2(1,:) = [];
South2(1,:) = [];
South2(1,:) = [];

%convert Celcius to F
func=@(x) (x.*1.8)+32
South2=varfun(func, South2)
%name column variables
South2.Properties.VariableNames{1} = 'November2006';
South2.Properties.VariableNames{2} = 'December2006';
South2.Properties.VariableNames{3} = 'January2007';
South2.Properties.VariableNames{4} = 'February2007';
South2.Properties.VariableNames{5} = 'March2007';
South2.Properties.VariableNames{6} = 'April2007';
South2.Properties.VariableNames{7} = 'May2007';
South2.Properties.VariableNames{8} = 'June2007';
South2.Properties.VariableNames{9} = 'July2007';
South2.Properties.VariableNames{10} = 'August2007';
South2.Properties.VariableNames{11} = 'September2007';
South2.Properties.VariableNames{12} = 'October2007';
South2.Properties.VariableNames{13} = 'November2007';
South2.Properties.VariableNames{14} = 'December2007';
South2.Properties.VariableNames{15} = 'January2008';
South2.Properties.VariableNames{16} = 'February2008';
South2.Properties.VariableNames{17} = 'March2008';
South2.Properties.VariableNames{18} = 'April2008';
South2.Properties.VariableNames{19} = 'May2008';
South2.Properties.VariableNames{20} = 'June2008';
South2.Properties.VariableNames{21} = 'July2008';
South2.Properties.VariableNames{22} = 'August2008';
South2.Properties.VariableNames{23} = 'September2008';
South2.Properties.VariableNames{24} = 'October2008';
South2.Properties.VariableNames{25} = 'November2008';
South2.Properties.VariableNames{26} = 'December2008';
South2.Properties.VariableNames{27} = 'January2009';
South2.Properties.VariableNames{28} = 'February2009';
South2.Properties.VariableNames{29} = 'March2009';
South2.Properties.VariableNames{30} = 'April2009';
South2.Properties.VariableNames{31} = 'May2009';
South2.Properties.VariableNames{32} = 'June2009';
South2.Properties.VariableNames{33} = 'July2009';
South2.Properties.VariableNames{34} = 'August2009';
South2.Properties.VariableNames{35} = 'September2009';
South2.Properties.VariableNames{36} = 'October2009';
South2.Properties.VariableNames{37} = 'November2009';
South2.Properties.VariableNames{38} = 'December2009';
South2.Properties.VariableNames{39} = 'January2010';
South2.Properties.VariableNames{40} = 'February2010';
South2.Properties.VariableNames{41} = 'March2010';
South2.Properties.VariableNames{42} = 'April2010';
South2.Properties.VariableNames{43} = 'May2010';
South2.Properties.VariableNames{44} = 'June2010';
South2.Properties.VariableNames{45} = 'July2010';
South2.Properties.VariableNames{46} = 'August2010';
South2.Properties.VariableNames{47} = 'September2010';
South2.Properties.VariableNames{48} = 'October2010';
South2.Properties.VariableNames{49} = 'November2010';
South2.Properties.VariableNames{50} = 'December2010';
South2.Properties.VariableNames{51} = 'January2011';
South2.Properties.VariableNames{52} = 'February2011';
South2.Properties.VariableNames{53} = 'March2011';
South2.Properties.VariableNames{54} = 'April2011';
South2.Properties.VariableNames{55} = 'May2011';
South2.Properties.VariableNames{56} = 'June2011';
South2.Properties.VariableNames{57} = 'July2011';
South2.Properties.VariableNames{58} = 'August2011';
South2.Properties.VariableNames{59} = 'September2011';
South2.Properties.VariableNames{60} = 'October2011';
South2.Properties.VariableNames{61} = 'November2011';
South2.Properties.VariableNames{62} = 'December2011';
South2.Properties.VariableNames{63} = 'January2012';
South2.Properties.VariableNames{64} = 'February2012';
South2.Properties.VariableNames{65} = 'March2012';

%make depth vector
Depthft=[-0.5
    -1
    -1.5
     -3
    -3.5
    -4
    -5
    -10
    -15	
    -20
    -25
    -30]

%% 
%whiplash plot
%axes1 = axes('Parent',figure,'ColorOrderIndex',3)
%'Position',[0.13 0.583837209302326 0.775 0.341162790697675]);
%hold(axes1,'on');
figure
%subplot(2,1,1);
plot (South2.January2007, Depthft,'LineWidth',.5,'Color','m','DisplayName','January 2007')
hold 
plot (South2.February2007, Depthft,'LineWidth',.5,'Color','g','DisplayName','February 2007')
 plot (South2.March2007, Depthft,'LineWidth',.5,'Color','k','DisplayName','March 2007')
 plot (South2.April2007, Depthft,'LineWidth',.5,'Color','c','DisplayName','April 2007')
 plot (South2.May2007, Depthft, 'LineWidth',.5,'Color','r','DisplayName','May 2007')
 plot (South2.June2007, Depthft,'LineWidth',.5,'Color','b','DisplayName','June 2007')
 plot (South2.July2007, Depthft,'LineWidth',.5,'Color',[.1133,.7015,.6859],'DisplayName','July 2007')
 plot (South2.August2007, Depthft,'LineWidth',.5,'Color',[.8185,0.7327,0.3498],'DisplayName','August 2007')
 plot (South2.September2007, Depthft,'LineWidth',.5,'Color',[0,.25,0],'DisplayName','September 2007')
 plot (South2.October2007, Depthft,'LineWidth',.5,'Color',[.85,.325,.098],'DisplayName','October 2007')
 plot (South2.November2007, Depthft,'LineWidth',.5,'Color',[1,.75,0],'DisplayName','November 2007')
 plot (South2.December2007, Depthft,'LineWidth',.5,'Color',[0,.447,.7410],'DisplayName','December 2007')
legend('show','location','southeast')
     xlabel('Temperature (F)')
   xlim ([30,42])
    grid on
     ylabel('Depth (ft)')
     title ('South of old RTF 2007')
 
     figure
%subplot(2,1,1);
plot (South2.January2008, Depthft,'LineWidth',.5,'Color','m','DisplayName','January 2008')
hold 
plot (South2.February2008, Depthft,'LineWidth',.5,'Color','g','DisplayName','February 2008')
 plot (South2.March2008, Depthft,'LineWidth',.5,'Color','k','DisplayName','March 2008')
 plot (South2.April2008, Depthft,'LineWidth',.5,'Color','c','DisplayName','April 2008')
 plot (South2.May2008, Depthft, 'LineWidth',.5,'Color','r','DisplayName','May 2008')
 plot (South2.June2008, Depthft,'LineWidth',.5,'Color','b','DisplayName','June 2008')
 plot (South2.July2008, Depthft,'LineWidth',.5,'Color',[.1133,.7015,.6859],'DisplayName','July 2008')
 plot (South2.August2008, Depthft,'LineWidth',.5,'Color',[.8185,0.7327,0.3498],'DisplayName','August 2008')
 plot (South2.September2008, Depthft,'LineWidth',.5,'Color',[0,.25,0],'DisplayName','September 2008')
 plot (South2.October2008, Depthft,'LineWidth',.5,'Color',[.85,.325,.098],'DisplayName','October 2008')
 plot (South2.November2008, Depthft,'LineWidth',.5,'Color',[1,.75,0],'DisplayName','November 2008')
 plot (South2.December2008, Depthft,'LineWidth',.5,'Color',[0,.447,.7410],'DisplayName','December 2008')
legend('show','location','southeast')
     xlabel('Temperature (F)')
   xlim ([30,42])
    grid on
     ylabel('Depth (ft)')
     title ('South of old RTF 2008')
     
          figure
%subplot(2,1,1);
plot (South2.January2009, Depthft,'LineWidth',.5,'Color','m','DisplayName','January 2009')
hold 
plot (South2.February2009, Depthft,'LineWidth',.5,'Color','g','DisplayName','February 2009')
 plot (South2.March2009, Depthft,'LineWidth',.5,'Color','k','DisplayName','March 2009')
 plot (South2.April2009, Depthft,'LineWidth',.5,'Color','c','DisplayName','April 2009')
 plot (South2.May2009, Depthft, 'LineWidth',.5,'Color','r','DisplayName','May 2009')
 plot (South2.June2009, Depthft,'LineWidth',.5,'Color','b','DisplayName','June 2009')
 plot (South2.July2009, Depthft,'LineWidth',.5,'Color',[.1133,.7015,.6859],'DisplayName','July 2009')
 plot (South2.August2009, Depthft,'LineWidth',.5,'Color',[.8185,0.7327,0.3498],'DisplayName','August 2009')
 plot (South2.September2009, Depthft,'LineWidth',.5,'Color',[0,.25,0],'DisplayName','September 2009')
 plot (South2.October2009, Depthft,'LineWidth',.5,'Color',[.85,.325,.098],'DisplayName','October 2009')
 plot (South2.November2009, Depthft,'LineWidth',.5,'Color',[1,.75,0],'DisplayName','November 2009')
 plot (South2.December2009, Depthft,'LineWidth',.5,'Color',[0,.447,.7410],'DisplayName','December 2009')
legend('show','location','southeast')
     xlabel('Temperature (F)')
    xlim ([30,42])
    grid on
     ylabel('Depth (ft)')
     title ('South of old RTF 2009')
 
               figure
%subplot(2,1,1);
plot (South2.January2010, Depthft,'LineWidth',.5,'Color','m','DisplayName','January 2010')
hold 
plot (South2.February2010, Depthft,'LineWidth',.5,'Color','g','DisplayName','February 2010')
 plot (South2.March2010, Depthft,'LineWidth',.5,'Color','k','DisplayName','March 2010')
 plot (South2.April2010, Depthft,'LineWidth',.5,'Color','c','DisplayName','April 2010')
 plot (South2.May2010, Depthft, 'LineWidth',.5,'Color','r','DisplayName','May 2010')
 plot (South2.June2010, Depthft,'LineWidth',.5,'Color','b','DisplayName','June 2010')
 plot (South2.July2010, Depthft,'LineWidth',.5,'Color',[.1133,.7015,.6859],'DisplayName','July 2010')
 plot (South2.August2010, Depthft,'LineWidth',.5,'Color',[.8185,0.7327,0.3498],'DisplayName','August 2010')
 plot (South2.September2010, Depthft,'LineWidth',.5,'Color',[0,.25,0],'DisplayName','September 2010')
 plot (South2.October2010, Depthft,'LineWidth',.5,'Color',[.85,.325,.098],'DisplayName','October 2010')
 plot (South2.November2010, Depthft,'LineWidth',.5,'Color',[1,.75,0],'DisplayName','November 2010')
 plot (South2.December2010, Depthft,'LineWidth',.5,'Color',[0,.447,.7410],'DisplayName','December 2010')
legend('show','location','southeast')
     xlabel('Temperature (F)')
xlim ([30,42])
    grid on
     ylabel('Depth (ft)')
     title ('South of old RTF 2010')
     
      
               figure
%subplot(2,1,1);
plot (South2.January2011, Depthft,'LineWidth',.5,'Color','m','DisplayName','January 2011')
hold 
plot (South2.February2011, Depthft,'LineWidth',.5,'Color','g','DisplayName','February 2011')
 plot (South2.March2011, Depthft,'LineWidth',.5,'Color','k','DisplayName','March 2011')
 plot (South2.April2011, Depthft,'LineWidth',.5,'Color','c','DisplayName','April 2011')
 plot (South2.May2011, Depthft, 'LineWidth',.5,'Color','r','DisplayName','May 2011')
 plot (South2.June2011, Depthft,'LineWidth',.5,'Color','b','DisplayName','June 2011')
 plot (South2.July2011, Depthft,'LineWidth',.5,'Color',[.1133,.7015,.6859],'DisplayName','July 2011')
 plot (South2.August2011, Depthft,'LineWidth',.5,'Color',[.8185,0.7327,0.3498],'DisplayName','August 2011')
 plot (South2.September2011, Depthft,'LineWidth',.5,'Color',[0,.25,0],'DisplayName','September 2011')
   plot (South2.October2011, Depthft,'LineWidth',.5,'Color',[.85,.325,.098],'DisplayName','October 2011')
 plot (South2.November2011, Depthft,'LineWidth',.5,'Color',[1,.75,0],'DisplayName','November 2011')
 plot (South2.December2011, Depthft,'LineWidth',.5,'Color',[0,.447,.7410],'DisplayName','December 2011')
legend('show','location','southeast')
     xlabel('Temperature (F)')
   xlim ([30,42])
    grid on
     ylabel('Depth (ft)')
     title ('South of old RTF 2011')
     
           
               figure
%subplot(2,1,1);
plot (South2.January2012, Depthft,'LineWidth',.5,'Color','m','DisplayName','January 2012')
hold 
plot (South2.February2012, Depthft,'LineWidth',.5,'Color','g','DisplayName','February 2012')
 plot (South2.March2012, Depthft,'LineWidth',.5,'Color','k','DisplayName','March 2012')
     xlabel('Temperature (F)')
    xlim ([30,42])
    grid on
      %xlim ([-1,6])
     ylabel('Depth (ft)')
     title ('South of old RTF 2012')
          legend('show','location','southeast')
     
     %% plot over time
     months=[
    39022
    39052
   39083.00
39114.00
39142.00
39173.00
39203.00
39234.00
39264.00
39295.00
39326.00
39356.00
39387.00
39417.00
39448.00
39479.00
39508.00
39539.00
39569.00
39600.00
39630.00
39661.00
39692.00
39722.00
39753.00
39783.00
39814.00
39845.00
39873.00
39904.00
39934.00
39965.00
39995.00
40026.00
40057.00
40087.00
40118.00
40148.00
40179.00
40210.00
40238.00
40269.00
40299.00
40330.00
40360.00
40391.00
40422.00
40452.00
40483.00
40513.00
40544.00
40575.00
40603.00
40634.00
40664.00
40695.00
40725.00
40756.00
40787.00
40817.00
40848.00
40878.00
40909.00
40940.00
40969.00]

south=foundationmonthly
south(:,1)=[];
south(:,1)=[];
south(:,1)=[];
%convert Celcius to F
func=@(x) (x.*1.8)+32
south=varfun(func, south)


south.Properties.VariableNames{1} = 'one';
south.Properties.VariableNames{2} = 'two';
south.Properties.VariableNames{3} = 'three';
south.Properties.VariableNames{4} = 'four';
south.Properties.VariableNames{5} = 'five';
south.Properties.VariableNames{6} = 'six';
south.Properties.VariableNames{7} = 'seven';
south.Properties.VariableNames{8} = 'eight';
south.Properties.VariableNames{9} = 'nine';
south.Properties.VariableNames{10} = 'ten';
south.Properties.VariableNames{11} = 'eleven';
south.Properties.VariableNames{12} = 'twelve';


figure 
plot(months,south.one,'DisplayName','-0.5 ft');
hold on;
plot(months,south.two,'DisplayName','-1 ft');
plot(months,south.three,'DisplayName','-1.5 ft');
plot(months, south.four,'DisplayName','-3 ft');
plot(months,south.five,'DisplayName','-3.5 ft');
plot(months,south.six,'DisplayName','-4 ft');
plot(months,south.seven,'DisplayName','-5 ft');
plot(months,south.eight,'DisplayName','-10 ft');
plot(months,south.nine,'DisplayName','-15 ft');
plot(months, south.ten,'DisplayName','-20 ft');
plot(months,south.eleven,'DisplayName','-25 ft');
plot(months,south.twelve,'DisplayName','-30 ft');

hold off;
%format plot
datetick('x','mmmyy')
legend('show','Orientation','horizontal','Location','southoutside')
     ylabel('Temperature (F)')
     ylim([30,42])
     grid on
      title ('South of Original RTF')

     
     
  