filepath = 'Z:\Aarne\Keskeneraiset\Raspberry_LAI_2013\optical_properties\data\';

%% Process raspberry samples, 20.7.2013

raspberry_spectra = zeros(16*4, 2151);

%% Raspberry stray light 1

straylight_r_1 = dlmread(strcat(filepath, 'raspberry00059.asd.txt'), '\t', 1, 0);
straylight_r_2 = dlmread(strcat(filepath, 'raspberry00060.asd.txt'), '\t', 1, 0);
straylight_r_3 = dlmread(strcat(filepath, 'raspberry00061.asd.txt'), '\t', 1, 0);
straylight_r_4 = dlmread(strcat(filepath, 'raspberry00062.asd.txt'), '\t', 1, 0);
% plot(straylight_r_1(:,1), straylight_r_1(:,2));
% hold on;
% plot(straylight_r_1(:,1), straylight_r_2(:,2));
% plot(straylight_r_1(:,1), straylight_r_3(:,2));
% plot(straylight_r_1(:,1), straylight_r_4(:,2));
sl_r = (straylight_r_1(:,2) + straylight_r_2(:,2) + straylight_r_3(:,2) + straylight_r_4(:,2)) / 4;
% plot(straylight_r_1(:,1), sl_r, 'r');
% hold off;

straylight_t_1 = dlmread(strcat(filepath, 'raspberry00075.asd.txt'), '\t', 1, 0);
straylight_t_2 = dlmread(strcat(filepath, 'raspberry00076.asd.txt'), '\t', 1, 0);
straylight_t_3 = dlmread(strcat(filepath, 'raspberry00077.asd.txt'), '\t', 1, 0);
straylight_t_4 = dlmread(strcat(filepath, 'raspberry00078.asd.txt'), '\t', 1, 0);
% plot(straylight_t_1(:,1), straylight_t_1(:,2));
% hold on;
% plot(straylight_t_1(:,1), straylight_t_2(:,2));
% plot(straylight_t_1(:,1), straylight_t_3(:,2));
% plot(straylight_t_1(:,1), straylight_t_4(:,2));
sl_t = (straylight_t_1(:,2) + straylight_t_2(:,2) + straylight_t_3(:,2) + straylight_t_4(:,2)) / 4;
% plot(straylight_t_1(:,1), sl_t, 'r');
% hold off;

%% Raspberry 1.1.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00055.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00057.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(1,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00056.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00058.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(2,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00063.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00065.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00066.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00067.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00068.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00069.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(3,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00064.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00070.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00071.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00072.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00073.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00074.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(4,:) = spectrum;

%% Raspberry 2.1.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00055.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00090.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(17,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00056.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00091.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(18,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00063.asd.txt'), '\t', 1, 0);
% 6 samples!
measurement1 = dlmread(strcat(filepath, 'raspberry00079.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00080.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00081.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00082.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00083.asd.txt'), '\t', 1, 0);
measurement6 = dlmread(strcat(filepath, 'raspberry00084.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
% plot(wr(:,1), measurement6(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5 + measurement6) / 6;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(19,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00064.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00085.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00086.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00087.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00088.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00089.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(20,:) = spectrum;

%% Raspberry 1.1.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00092.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00094.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(5,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00093.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00095.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(6,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00096.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00098.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00099.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00100.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00101.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00102.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(7,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00097.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00103.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00104.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00105.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00106.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00107.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(8,:) = spectrum;

%% Raspberry 2.1.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00092.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00118.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(21,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00093.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00119.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(22,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00096.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00108.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00109.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00110.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00111.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00112.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(23,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00097.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00113.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00114.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00115.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00116.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00117.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(24,:) = spectrum;

%% Raspberry 1.2.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00120.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00122.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(9,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00121.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00123.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(10,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00124.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00126.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00127.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00128.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00129.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00130.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(11,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00125.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00131.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00132.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00133.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00134.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00135.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(12,:) = spectrum;


%% Raspberry stray light 2

straylight_r_1 = dlmread(strcat(filepath, 'raspberry00142.asd.txt'), '\t', 1, 0);
straylight_r_2 = dlmread(strcat(filepath, 'raspberry00143.asd.txt'), '\t', 1, 0);
straylight_r_3 = dlmread(strcat(filepath, 'raspberry00144.asd.txt'), '\t', 1, 0);
straylight_r_4 = dlmread(strcat(filepath, 'raspberry00145.asd.txt'), '\t', 1, 0);
% plot(straylight_r_1(:,1), straylight_r_1(:,2));
% hold on;
% plot(straylight_r_1(:,1), straylight_r_2(:,2));
% plot(straylight_r_1(:,1), straylight_r_3(:,2));
% plot(straylight_r_1(:,1), straylight_r_4(:,2));
sl_r = (straylight_r_1(:,2) + straylight_r_2(:,2) + straylight_r_3(:,2) + straylight_r_4(:,2)) / 4;
% plot(straylight_r_1(:,1), sl_r, 'r');
% hold off;

straylight_t_1 = dlmread(strcat(filepath, 'raspberry00158.asd.txt'), '\t', 1, 0);
straylight_t_2 = dlmread(strcat(filepath, 'raspberry00159.asd.txt'), '\t', 1, 0);
straylight_t_3 = dlmread(strcat(filepath, 'raspberry00160.asd.txt'), '\t', 1, 0);
straylight_t_4 = dlmread(strcat(filepath, 'raspberry00161.asd.txt'), '\t', 1, 0);
% plot(straylight_t_1(:,1), straylight_t_1(:,2));
% hold on;
% plot(straylight_t_1(:,1), straylight_t_2(:,2));
% plot(straylight_t_1(:,1), straylight_t_3(:,2));
% plot(straylight_t_1(:,1), straylight_t_4(:,2));
sl_t = (straylight_t_1(:,2) + straylight_t_2(:,2) + straylight_t_3(:,2) + straylight_t_4(:,2)) / 4;
% plot(straylight_t_1(:,1), sl_t, 'r');
% hold off;


%% Raspberry 2.2.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00139.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00140.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(25,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00138.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00141.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(26,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00146.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00148.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00149.asd.txt'), '\t', 1, 0);
% measurement3 = dlmread(strcat(filepath, 'raspberry00150.asd.txt'), '\t', 1, 0); % Removed as outlier
measurement4 = dlmread(strcat(filepath, 'raspberry00151.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00152.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% % plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement4 + measurement5) / 4;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(27,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00147.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00153.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00154.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00155.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00156.asd.txt'), '\t', 1, 0);
% measurement5 = dlmread(strcat(filepath, 'raspberry00157.asd.txt'), '\t', 1, 0); % Error, removed as outlier
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% % plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4) / 4;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(28,:) = spectrum;

%% Raspberry 1.2.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00162.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00164.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(13,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00163.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00165.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(14,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00166.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00168.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00169.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00170.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00171.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00172.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(15,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00167.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00173.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00174.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00175.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00176.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00177.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(16,:) = spectrum;

%% Raspberry 2.2.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00162.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00188.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(29,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00163.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00189.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(30,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00166.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00178.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00179.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00180.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00181.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00182.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(31,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00167.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00183.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00184.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00185.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00186.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00187.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(32,:) = spectrum;

%% Raspberry 3.1.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00190.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00192.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(33,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00191.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00193.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(34,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00194.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00196.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00197.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00198.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00199.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00200.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(35,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00195.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00201.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00202.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00203.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00204.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00205.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(36,:) = spectrum;

%% Raspberry 4.1.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00190.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00221.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(49,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00191.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00222.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(50,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00194.asd.txt'), '\t', 1, 0);
% 10 measurements!!!
% measurement1 = dlmread(strcat(filepath, 'raspberry00206.asd.txt'), '\t', 1, 0); % Removed as outlier
measurement2 = dlmread(strcat(filepath, 'raspberry00207.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00208.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00209.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00210.asd.txt'), '\t', 1, 0);
measurement6 = dlmread(strcat(filepath, 'raspberry00211.asd.txt'), '\t', 1, 0);
measurement7 = dlmread(strcat(filepath, 'raspberry00212.asd.txt'), '\t', 1, 0);
measurement8 = dlmread(strcat(filepath, 'raspberry00213.asd.txt'), '\t', 1, 0);
measurement9 = dlmread(strcat(filepath, 'raspberry00214.asd.txt'), '\t', 1, 0);
measurement10 = dlmread(strcat(filepath, 'raspberry00215.asd.txt'), '\t', 1, 0);
% % plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
% plot(wr(:,1), measurement6(:,2));
% plot(wr(:,1), measurement7(:,2)); 
% plot(wr(:,1), measurement8(:,2));
% plot(wr(:,1), measurement9(:,2));
% plot(wr(:,1), measurement10(:,2));
measurement = (measurement2 + measurement3 + measurement4 + measurement5 + measurement6 + measurement7 + measurement8 + measurement9 + measurement10) / 9;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(51,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00195.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00216.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00217.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00218.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00219.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00220.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(52,:) = spectrum;

%% Raspberry 3.1.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00223.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00225.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(37,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00224.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00226.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(38,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00227.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00229.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00230.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00231.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00232.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00233.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(39,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00228.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00234.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00235.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00236.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00237.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00238.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(40,:) = spectrum;

%% Raspberry 4.1.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00223.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00249.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(53,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00224.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00250.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(54,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00227.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00239.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00240.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00241.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00242.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00243.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(55,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00228.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00244.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00245.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00246.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00247.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00248.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(56,:) = spectrum;

%% Raspberry 3.2.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00251.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00253.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(41,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00252.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00254.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(42,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00255.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00257.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00258.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00259.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00260.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00261.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(43,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00256.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00262.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00263.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00264.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00265.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00266.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(44,:) = spectrum;

%% Raspberry stray light 3

straylight_r_1 = dlmread(strcat(filepath, 'raspberry00311.asd.txt'), '\t', 1, 0);
straylight_r_2 = dlmread(strcat(filepath, 'raspberry00312.asd.txt'), '\t', 1, 0);
straylight_r_3 = dlmread(strcat(filepath, 'raspberry00313.asd.txt'), '\t', 1, 0);
straylight_r_4 = dlmread(strcat(filepath, 'raspberry00314.asd.txt'), '\t', 1, 0);
% plot(straylight_r_1(:,1), straylight_r_1(:,2));
% hold on;
% plot(straylight_r_1(:,1), straylight_r_2(:,2));
% plot(straylight_r_1(:,1), straylight_r_3(:,2));
% plot(straylight_r_1(:,1), straylight_r_4(:,2));
sl_r = (straylight_r_1(:,2) + straylight_r_2(:,2) + straylight_r_3(:,2) + straylight_r_4(:,2)) / 4;
% plot(straylight_r_1(:,1), sl_r, 'r');
% hold off;

straylight_t_1 = dlmread(strcat(filepath, 'raspberry00315.asd.txt'), '\t', 1, 0);
straylight_t_2 = dlmread(strcat(filepath, 'raspberry00316.asd.txt'), '\t', 1, 0);
straylight_t_3 = dlmread(strcat(filepath, 'raspberry00317.asd.txt'), '\t', 1, 0);
straylight_t_4 = dlmread(strcat(filepath, 'raspberry00318.asd.txt'), '\t', 1, 0);
% plot(straylight_t_1(:,1), straylight_t_1(:,2));
% hold on;
% plot(straylight_t_1(:,1), straylight_t_2(:,2));
% plot(straylight_t_1(:,1), straylight_t_3(:,2));
% plot(straylight_t_1(:,1), straylight_t_4(:,2));
sl_t = (straylight_t_1(:,2) + straylight_t_2(:,2) + straylight_t_3(:,2) + straylight_t_4(:,2)) / 4;
% plot(straylight_t_1(:,1), sl_t, 'r');
% hold off;


%% Raspberry 4.2.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00267.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00269.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(57,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00268.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00270.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(58,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00271.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00273.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00274.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00275.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00276.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00277.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(59,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00272.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00278.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00279.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00280.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00281.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00282.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(60,:) = spectrum;

%% Raspberry 3.2.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00283.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00285.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(45,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00284.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00286.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(46,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00287.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00289.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00290.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00291.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00292.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00293.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(47,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00288.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00294.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00295.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00296.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00297.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00298.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(48,:) = spectrum;

%% Raspberry 4.2.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'raspberry00283.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00309.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(61,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'raspberry00284.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'raspberry00310.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
raspberry_spectra(62,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'raspberry00287.asd.txt'), '\t', 1, 0);
% measurement1 = dlmread(strcat(filepath, 'raspberry00299.asd.txt'), '\t', 1, 0); % Removed as outlier
measurement2 = dlmread(strcat(filepath, 'raspberry00300.asd.txt'), '\t', 1, 0); 
measurement3 = dlmread(strcat(filepath, 'raspberry00301.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00302.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00303.asd.txt'), '\t', 1, 0);
% % plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2)); 
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement2 + measurement3 + measurement4 + measurement5) / 4;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(63,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'raspberry00288.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'raspberry00304.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'raspberry00305.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'raspberry00306.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'raspberry00307.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'raspberry00308.asd.txt'), '\t', 1, 0); 
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
raspberry_spectra(64,:) = spectrum;


%% Process fireweed samples, 21.7.2013

fireweed_spectra = zeros(6*4, 2151);

%% Fireweed stray light 1

straylight_r_1 = dlmread(strcat(filepath, 'fireweed00008.asd.txt'), '\t', 1, 0);
straylight_r_2 = dlmread(strcat(filepath, 'fireweed00009.asd.txt'), '\t', 1, 0);
straylight_r_3 = dlmread(strcat(filepath, 'fireweed00010.asd.txt'), '\t', 1, 0);
straylight_r_4 = dlmread(strcat(filepath, 'fireweed00011.asd.txt'), '\t', 1, 0);
% plot(straylight_r_1(:,1), straylight_r_1(:,2));
% hold on;
% plot(straylight_r_1(:,1), straylight_r_2(:,2));
% plot(straylight_r_1(:,1), straylight_r_3(:,2));
% plot(straylight_r_1(:,1), straylight_r_4(:,2));
sl_r = (straylight_r_1(:,2) + straylight_r_2(:,2) + straylight_r_3(:,2) + straylight_r_4(:,2)) / 4;
% plot(straylight_r_1(:,1), sl_r, 'r');
% hold off;

straylight_t_1 = dlmread(strcat(filepath, 'fireweed00024.asd.txt'), '\t', 1, 0);
straylight_t_2 = dlmread(strcat(filepath, 'fireweed00025.asd.txt'), '\t', 1, 0);
straylight_t_3 = dlmread(strcat(filepath, 'fireweed00026.asd.txt'), '\t', 1, 0);
straylight_t_4 = dlmread(strcat(filepath, 'fireweed00027.asd.txt'), '\t', 1, 0);
% plot(straylight_t_1(:,1), straylight_t_1(:,2));
% hold on;
% plot(straylight_t_1(:,1), straylight_t_2(:,2));
% plot(straylight_t_1(:,1), straylight_t_3(:,2));
% plot(straylight_t_1(:,1), straylight_t_4(:,2));
sl_t = (straylight_t_1(:,2) + straylight_t_2(:,2) + straylight_t_3(:,2) + straylight_t_4(:,2)) / 4;
% plot(straylight_t_1(:,1), sl_t, 'r');
% hold off;

%% Fireweed 1.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'fireweed00004.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00006.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(1,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'fireweed00005.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00007.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(2,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'fireweed00012.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00014.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00015.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00016.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00017.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00018.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(3,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'fireweed00013.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00019.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00020.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00021.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00022.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00023.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(4,:) = spectrum;

%% Fireweed 3.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'fireweed00028.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00030.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(17,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'fireweed00029.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00031.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(18,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'fireweed00032.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00034.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00035.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00036.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00037.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00038.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(19,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'fireweed00033.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00039.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00040.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00041.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00042.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00043.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(20,:) = spectrum;

%% Fireweed 2.E

% Reflectance, side A
wr = dlmread(strcat(filepath, 'fireweed00028.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00054.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(9,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'fireweed00029.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00055.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(10,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'fireweed00032.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00044.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00045.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00046.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00047.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00048.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(11,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'fireweed00033.asd.txt'), '\t', 1, 0);
% measurement1 = dlmread(strcat(filepath, 'fireweed00049.asd.txt'), '\t', 1, 0); % Removed as outlier
measurement2 = dlmread(strcat(filepath, 'fireweed00050.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00051.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00052.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00053.asd.txt'), '\t', 1, 0);
% % plot(wr(:,1), measurement1(:,2));
% plot(wr(:,1), measurement2(:,2));
% hold on;
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement2 + measurement3 + measurement4 + measurement5) / 4;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(12,:) = spectrum;


%% Fireweed 1.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'fireweed00056.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00058.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(5,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'fireweed00057.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00059.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(6,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'fireweed00060.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00062.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00063.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00064.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00065.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00066.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(7,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'fireweed00061.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00067.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00068.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00069.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00070.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00071.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% plot(wr(:,1), measurement2(:,2));
% hold on;
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(8,:) = spectrum;

%% Fireweed 2.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'fireweed00056.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00082.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(13,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'fireweed00057.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00083.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(14,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'fireweed00060.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00072.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00073.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00074.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00075.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00076.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(15,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'fireweed00061.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00077.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00078.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00079.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00080.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00081.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% plot(wr(:,1), measurement2(:,2));
% hold on;
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(16,:) = spectrum;

%% Fireweed 3.S

% Reflectance, side A
wr = dlmread(strcat(filepath, 'fireweed00084.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00086.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(21,:) = spectrum;

% Reflectance, side B
wr = dlmread(strcat(filepath, 'fireweed00085.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'fireweed00087.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
% plot(wr(:,1), spectrum);
fireweed_spectra(22,:) = spectrum;

% Transmittance, side A
wr = dlmread(strcat(filepath, 'fireweed00088.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00090.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00091.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00092.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00093.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00094.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% hold on;
% plot(wr(:,1), measurement2(:,2));
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(23,:) = spectrum;

% Transmittance, side B
wr = dlmread(strcat(filepath, 'fireweed00089.asd.txt'), '\t', 1, 0);
measurement1 = dlmread(strcat(filepath, 'fireweed00095.asd.txt'), '\t', 1, 0);
measurement2 = dlmread(strcat(filepath, 'fireweed00096.asd.txt'), '\t', 1, 0);
measurement3 = dlmread(strcat(filepath, 'fireweed00097.asd.txt'), '\t', 1, 0);
measurement4 = dlmread(strcat(filepath, 'fireweed00098.asd.txt'), '\t', 1, 0);
measurement5 = dlmread(strcat(filepath, 'fireweed00099.asd.txt'), '\t', 1, 0);
% plot(wr(:,1), measurement1(:,2));
% plot(wr(:,1), measurement2(:,2));
% hold on;
% plot(wr(:,1), measurement3(:,2));
% plot(wr(:,1), measurement4(:,2));
% plot(wr(:,1), measurement5(:,2));
measurement = (measurement1 + measurement2 + measurement3 + measurement4 + measurement5) / 5;
% plot(wr(:,1), measurement(:,2), 'r');
% hold off;
spectrum = (measurement(:,2) - sl_t) ./ (wr(:,2) - sl_t);
% plot(wr(:,1), spectrum);
fireweed_spectra(24,:) = spectrum;

%% Write spectra into file

dlmwrite('C:/tyo/raspberry_OP.csv', raspberry_spectra);
dlmwrite('C:/tyo/fireweed_OP.csv', fireweed_spectra);


%% Process moisture samples, 20-21.7.2013

%% Moisture stray light 1

straylight_r_1 = dlmread(strcat(filepath, 'moisture00177.asd.txt'), '\t', 1, 0);
straylight_r_2 = dlmread(strcat(filepath, 'moisture00178.asd.txt'), '\t', 1, 0);
straylight_r_3 = dlmread(strcat(filepath, 'moisture00179.asd.txt'), '\t', 1, 0);
straylight_r_4 = dlmread(strcat(filepath, 'moisture00180.asd.txt'), '\t', 1, 0);
% plot(straylight_r_1(:,1), straylight_r_1(:,2));
% hold on;
% plot(straylight_r_1(:,1), straylight_r_2(:,2));
% plot(straylight_r_1(:,1), straylight_r_3(:,2));
% plot(straylight_r_1(:,1), straylight_r_4(:,2));
sl_r = (straylight_r_1(:,2) + straylight_r_2(:,2) + straylight_r_3(:,2) + straylight_r_4(:,2)) / 4;
% plot(straylight_r_1(:,1), sl_r, 'r');
% hold off;

straylight_t_1 = dlmread(strcat(filepath, 'moisture00181.asd.txt'), '\t', 1, 0);
straylight_t_2 = dlmread(strcat(filepath, 'moisture00182.asd.txt'), '\t', 1, 0);
straylight_t_3 = dlmread(strcat(filepath, 'moisture00183.asd.txt'), '\t', 1, 0);
straylight_t_4 = dlmread(strcat(filepath, 'moisture00184.asd.txt'), '\t', 1, 0);
% plot(straylight_t_1(:,1), straylight_t_1(:,2));
% hold on;
% plot(straylight_t_1(:,1), straylight_t_2(:,2));
% plot(straylight_t_1(:,1), straylight_t_3(:,2));
% plot(straylight_t_1(:,1), straylight_t_4(:,2));
sl_t = (straylight_t_1(:,2) + straylight_t_2(:,2) + straylight_t_3(:,2) + straylight_t_4(:,2)) / 4;
% plot(straylight_t_1(:,1), sl_t, 'r');
% hold off;

%% Moisture samples

subplot(3,2,1);
wr = dlmread(strcat(filepath, 'moisture00162.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00163.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum);
hold on;
wr = dlmread(strcat(filepath, 'moisture00166.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00164.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'r');
measurement = dlmread(strcat(filepath, 'moisture00165.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'g');
ylim([0 1]);
legend('Dry leaf', 'Wet leaf, drops', 'Wet leaf, continuous layer');
ylabel('DHRF');
xlabel('Wavelength, nm');
title('Sample 9');

subplot(3,2,2);
wr = dlmread(strcat(filepath, 'moisture00167.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00168.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum);
hold on;
wr = dlmread(strcat(filepath, 'moisture00171.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00169.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'r');
measurement = dlmread(strcat(filepath, 'moisture00170.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'g');
ylim([0 1]);
ylabel('DHRF');
xlabel('Wavelength, nm');
title('Sample 10');

subplot(3,2,3);
wr = dlmread(strcat(filepath, 'moisture00172.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00173.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum);
hold on;
wr = dlmread(strcat(filepath, 'moisture00176.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00174.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'r');
measurement = dlmread(strcat(filepath, 'moisture00175.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'g');
ylim([0 1]);
ylabel('DHRF');
xlabel('Wavelength, nm');
title('Sample 11');

%% Moisture stray light 2

straylight_r_1 = dlmread(strcat(filepath, 'raspberry00040.asd.txt'), '\t', 1, 0);
straylight_r_2 = dlmread(strcat(filepath, 'raspberry00041.asd.txt'), '\t', 1, 0);
straylight_r_3 = dlmread(strcat(filepath, 'raspberry00042.asd.txt'), '\t', 1, 0);
straylight_r_4 = dlmread(strcat(filepath, 'raspberry00043.asd.txt'), '\t', 1, 0);
% plot(straylight_r_1(:,1), straylight_r_1(:,2));
% hold on;
% plot(straylight_r_1(:,1), straylight_r_2(:,2));
% plot(straylight_r_1(:,1), straylight_r_3(:,2));
% plot(straylight_r_1(:,1), straylight_r_4(:,2));
sl_r = (straylight_r_1(:,2) + straylight_r_2(:,2) + straylight_r_3(:,2) + straylight_r_4(:,2)) / 4;
% plot(straylight_r_1(:,1), sl_r, 'r');
% hold off;

% straylight_t_1 = dlmread(strcat(filepath, 'raspberry00044.asd.txt'), '\t', 1, 0);
straylight_t_2 = dlmread(strcat(filepath, 'raspberry00045.asd.txt'), '\t', 1, 0);
straylight_t_3 = dlmread(strcat(filepath, 'raspberry00046.asd.txt'), '\t', 1, 0);
straylight_t_4 = dlmread(strcat(filepath, 'raspberry00047.asd.txt'), '\t', 1, 0);
% plot(straylight_t_1(:,1), straylight_t_1(:,2)); % Do not use 1
hold on;
plot(straylight_t_1(:,1), straylight_t_2(:,2)); 
plot(straylight_t_1(:,1), straylight_t_3(:,2));
plot(straylight_t_1(:,1), straylight_t_4(:,2));
sl_t = (straylight_t_2(:,2) + straylight_t_3(:,2) + straylight_t_4(:,2)) / 3;
plot(straylight_t_1(:,1), sl_t, 'r');
hold off;

%% More moisture samples

subplot(3,2,4);
wr = dlmread(strcat(filepath, 'moisture00015.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00020.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum);
hold on;
wr = dlmread(strcat(filepath, 'moisture00030.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00025.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'r');
ylim([0 1]);
ylabel('DHRF');
xlabel('Wavelength, nm');
title('Sample 2');

subplot(3,2,5);
wr = dlmread(strcat(filepath, 'moisture00035.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00040.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum);
hold on;
wr = dlmread(strcat(filepath, 'moisture00050.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00045.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'r');
ylim([0 1]);
ylabel('DHRF');
xlabel('Wavelength, nm');
title('Sample 3');

subplot(3,2,6);
wr = dlmread(strcat(filepath, 'moisture00055.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00060.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum);
hold on;
wr = dlmread(strcat(filepath, 'moisture00070.asd.txt'), '\t', 1, 0);
measurement = dlmread(strcat(filepath, 'moisture00065.asd.txt'), '\t', 1, 0);
spectrum = (measurement(:,2) - sl_r) ./ (wr(:,2) - sl_r);
plot(wr(:,1), spectrum, 'r');
ylim([0 1]);
ylabel('DHRF');
xlabel('Wavelength, nm');
title('Sample 4');


%% Figures

% Raspberry, 1st yr, sun exposed, reflectance
subplot(2, 2, 1);
plot(wr(:,1), raspberry_spectra(1,:));
hold on;
plot(wr(:,1), raspberry_spectra(2,:), 'r');
legend('Upper side', 'Lower side');
plot(wr(:,1), raspberry_spectra(17,:));
plot(wr(:,1), raspberry_spectra(18,:), 'r');
plot(wr(:,1), raspberry_spectra(33,:));
plot(wr(:,1), raspberry_spectra(34,:), 'r');
plot(wr(:,1), raspberry_spectra(49,:));
plot(wr(:,1), raspberry_spectra(50,:), 'r');
hold off;
title('Raspberry, 1st yr, sun exposed, reflectance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHRF');

% Raspberry, 2nd yr, sun exposed, reflectance
subplot(2, 2, 3);
plot(wr(:,1), raspberry_spectra(9,:));
hold on;
plot(wr(:,1), raspberry_spectra(25,:));
plot(wr(:,1), raspberry_spectra(41,:));
plot(wr(:,1), raspberry_spectra(57,:));
plot(wr(:,1), raspberry_spectra(10,:), 'r');
plot(wr(:,1), raspberry_spectra(26,:), 'r');
plot(wr(:,1), raspberry_spectra(42,:), 'r');
plot(wr(:,1), raspberry_spectra(58,:), 'r');
hold off;
title('Raspberry, 2nd yr, sun exposed, reflectance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHRF');

% Raspberry, 1st yr, shaded, reflectance
subplot(2, 2, 2);
plot(wr(:,1), raspberry_spectra(5,:));
hold on;
plot(wr(:,1), raspberry_spectra(21,:));
plot(wr(:,1), raspberry_spectra(37,:));
plot(wr(:,1), raspberry_spectra(53,:));
plot(wr(:,1), raspberry_spectra(6,:), 'r');
plot(wr(:,1), raspberry_spectra(22,:), 'r');
plot(wr(:,1), raspberry_spectra(38,:), 'r');
plot(wr(:,1), raspberry_spectra(54,:), 'r');
hold off;
title('Raspberry, 1st yr, shaded, reflectance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHRF');

% Raspberry, 2nd yr, shaded, reflectance
subplot(2, 2, 4);
plot(wr(:,1), raspberry_spectra(13,:));
hold on;
plot(wr(:,1), raspberry_spectra(29,:));
plot(wr(:,1), raspberry_spectra(45,:));
plot(wr(:,1), raspberry_spectra(61,:));
plot(wr(:,1), raspberry_spectra(14,:), 'r');
plot(wr(:,1), raspberry_spectra(30,:), 'r');
plot(wr(:,1), raspberry_spectra(46,:), 'r');
plot(wr(:,1), raspberry_spectra(62,:), 'r');
hold off;
title('Raspberry, 2nd yr, shaded, reflectance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHRF');

% Raspberry, 1st yr, sun exposed, transmittance
subplot(2, 2, 1);
plot(wr(:,1), raspberry_spectra(3,:));
hold on;
plot(wr(:,1), raspberry_spectra(4,:), 'r');
legend('Upper side', 'Lower side');
plot(wr(:,1), raspberry_spectra(19,:));
plot(wr(:,1), raspberry_spectra(35,:));
plot(wr(:,1), raspberry_spectra(51,:));
plot(wr(:,1), raspberry_spectra(20,:), 'r');
plot(wr(:,1), raspberry_spectra(36,:), 'r');
plot(wr(:,1), raspberry_spectra(52,:), 'r');
hold off;
title('Raspberry, 1st yr, sun exposed, transmittance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHTF');

% Raspberry, 2nd yr, sun exposed, transmittance
subplot(2, 2, 3);
plot(wr(:,1), raspberry_spectra(11,:));
hold on;
plot(wr(:,1), raspberry_spectra(27,:));
plot(wr(:,1), raspberry_spectra(43,:));
plot(wr(:,1), raspberry_spectra(59,:));
plot(wr(:,1), raspberry_spectra(12,:), 'r');
plot(wr(:,1), raspberry_spectra(28,:), 'r');
plot(wr(:,1), raspberry_spectra(44,:), 'r');
plot(wr(:,1), raspberry_spectra(60,:), 'r');
hold off;
title('Raspberry, 2nd yr, sun exposed, transmittance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHTF');

% Raspberry, 1st yr, shaded, transmittance
subplot(2, 2, 2);
plot(wr(:,1), raspberry_spectra(7,:));
hold on;
plot(wr(:,1), raspberry_spectra(23,:));
plot(wr(:,1), raspberry_spectra(39,:));
plot(wr(:,1), raspberry_spectra(55,:));
plot(wr(:,1), raspberry_spectra(8,:), 'r');
plot(wr(:,1), raspberry_spectra(24,:), 'r');
plot(wr(:,1), raspberry_spectra(40,:), 'r');
plot(wr(:,1), raspberry_spectra(56,:), 'r');
hold off;
title('Raspberry, 1st yr, shaded, transmittance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHTF');

% Raspberry, 2nd yr, shaded, transmittance
subplot(2, 2, 4);
plot(wr(:,1), raspberry_spectra(15,:));
hold on;
plot(wr(:,1), raspberry_spectra(31,:));
plot(wr(:,1), raspberry_spectra(47,:));
plot(wr(:,1), raspberry_spectra(63,:));
plot(wr(:,1), raspberry_spectra(16,:), 'r');
plot(wr(:,1), raspberry_spectra(32,:), 'r');
plot(wr(:,1), raspberry_spectra(48,:), 'r');
plot(wr(:,1), raspberry_spectra(64,:), 'r');
hold off;
title('Raspberry, 2nd yr, shaded, transmittance');
ylim([0 1]);
xlabel('Wavelength, nm');
ylabel('DHTF');


% Fireweed, sun exposed, reflectance
subplot(2,2,1);
plot(wr(:,1), fireweed_spectra(1,:));
hold on;
plot(wr(:,1), fireweed_spectra(2,:), 'r');
legend('Upper side', 'Lower side');
plot(wr(:,1), fireweed_spectra(9,:));
plot(wr(:,1), fireweed_spectra(17,:));
plot(wr(:,1), fireweed_spectra(10,:), 'r');
plot(wr(:,1), fireweed_spectra(18,:), 'r');
hold off;
ylim([0 1]);
title('Fireweed, sun exposed, reflectance');
xlabel('Wavelength, nm');
ylabel('DHRF');

% Fireweed, shaded, reflectance
subplot(2,2,2);
plot(wr(:,1), fireweed_spectra(5,:));
hold on;
plot(wr(:,1), fireweed_spectra(13,:));
plot(wr(:,1), fireweed_spectra(21,:));
plot(wr(:,1), fireweed_spectra(6,:), 'r');
plot(wr(:,1), fireweed_spectra(14,:), 'r');
plot(wr(:,1), fireweed_spectra(22,:), 'r');
hold off;
ylim([0 1]);
title('Fireweed, shaded, reflectance');
xlabel('Wavelength, nm');
ylabel('DHRF');

% Fireweed, sun exposed, transmittance
subplot(2,2,3);
plot(wr(:,1), fireweed_spectra(3,:));
hold on;
plot(wr(:,1), fireweed_spectra(11,:));
plot(wr(:,1), fireweed_spectra(19,:));
plot(wr(:,1), fireweed_spectra(4,:), 'r');
plot(wr(:,1), fireweed_spectra(12,:), 'r');
plot(wr(:,1), fireweed_spectra(20,:), 'r');
hold off;
ylim([0 1])
title('Fireweed, sun exposed, transmittance');
xlabel('Wavelength, nm');
ylabel('DHTF');

% Fireweed, shaded, transmittance
subplot(2,2,4);
plot(wr(:,1), fireweed_spectra(7,:));
hold on;
plot(wr(:,1), fireweed_spectra(15,:));
plot(wr(:,1), fireweed_spectra(23,:));
plot(wr(:,1), fireweed_spectra(8,:), 'r');
plot(wr(:,1), fireweed_spectra(16,:), 'r');
plot(wr(:,1), fireweed_spectra(24,:), 'r');
hold off;
ylim([0 1])
title('Fireweed, shaded, transmittance');
xlabel('Wavelength, nm');
ylabel('DHTF');


%% Analyse the specific leaf area data

filepath = 'Z:\Aarne\Keskeneraiset\Raspberry_LAI_2013\optical_properties\scan_images\';

file_list = {
    strcat(filepath, '1_1_E.jpg'),
    strcat(filepath, '1_1_S.jpg'),
    strcat(filepath, '1_2_E.jpg'),
    strcat(filepath, '1_2_S.jpg'),
    strcat(filepath, '2_1_E.jpg'),
    strcat(filepath, '2_1_S.jpg'),
    strcat(filepath, '2_2_E.jpg'),
    strcat(filepath, '2_2_S.jpg'),
    strcat(filepath, '3_1_E.jpg'),
    strcat(filepath, '3_1_S.jpg'),
    strcat(filepath, '3_2_E.jpg'),
    strcat(filepath, '3_2_S.jpg'),
    strcat(filepath, '4_1_E.jpg'),
    strcat(filepath, '4_1_S.jpg'),
    strcat(filepath, '4_2_E.jpg'),
    strcat(filepath, '4_2_S.jpg'),
    strcat(filepath, 'firew_1_E.jpg'),
    strcat(filepath, 'firew_1_S.jpg'),
    strcat(filepath, 'firew_2_E.jpg'),
    strcat(filepath, 'firew_2_S.jpg'),
    strcat(filepath, 'firew_3_E.jpg'),
    strcat(filepath, 'firew_3_S.jpg')
    };


% Tables to store graylevel threshold and leaf area
area = zeros(22,1);
threshold = zeros(22,1);

% Image width and height in millimeters
width = 215.9;
height = 297.2;

for i = 1:22
    A = imread(file_list{i}, 'jpg');
    imshow(A(:,:,1));
    level = graythresh(A(:,:,1));
    BW = im2bw(A(:,:,1), level);
    imshow(BW);
    area(i) = (1 - sum(sum(BW))/(length(BW(1,:))*length(BW(:,1)))) * width * height;
    threshold(i) = level;
    pause(2);
end








