%I used this to import Rrs from the P files
%Modify as needed....
% Created by Tom
% Modified by Javier

for k = 1:2 %cycles through 10 files
    % path name to the files
    fid=fopen(['/Users/javier/Desktop/Javier/PHD_RIT/DMCcourse/HLLab1/Ecolight/printout/Pex3_run' num2str(k) '.txt']);
    c = textscan(fid,'%s','delimiter','\n');
    fclose all;
    idx1= [];
    idx2= [];
    for n = 1:length(c{1})
        % find Rrs
%         a = [];
        a = strfind(c{1}{n},'Rrs'); %finds Rrs header
        
        if ~isempty(a)
            idx1 = [idx1;n];
        end
        % find wavelength
        b = strfind(c{1}{n},'wavelength =');
        if ~isempty(b)
            idx2 = [idx2;n];
        end
    end
    
    % get Rrs values
    idx_value = idx1+3; %number of wavelengths used in run)
    
    for j = 1:length(idx_value)
        C = textscan(c{1}{idx_value(j)},'%s');
        % take last column
        Rrs(j,k) = str2double(C{1}(end));
    end
    
        % get wavelength values

    
    for j = 1:length(idx2)
        D = textscan(c{1}{idx2(j)},'%s');
        % take last column
        wavelength(j,k) = str2double(D{1}(18));
    end 
end