function [time,B_H,B_D,Qual,siteData] = importCARISMAICMFolder(folder)
%IMPORTFILE Import numeric data from a text file as column vectors.
% Example:
%   [t,H,D,Q] = importCARISMAICM('20090824DAWS.ICM20',1, 1728000);

ICMFiles = dir(strcat(folder,'/*ICM*'));
numICMFiles = numel(ICMFiles);

fprintf('Found %d files in %s\n',numICMFiles,folder);



for i = 1:numICMFiles
   fprintf('Parsing: %s\n',ICMFiles(i).name);
   [timeTemp, B_HTemp, B_DTemp, QualTemp, siteDataTemp] = importCARISMAICM(strcat(folder,'/', ICMFiles(i).name));
   
   if (i == 1)
        time = timeTemp;
        B_H = B_HTemp;
        B_D = B_DTemp;
        Qual = QualTemp;
        siteData = siteDataTemp;
        fprintf('Parsed Site: %s (%7.3f geoLat and %7.4f geoLon) at %d sps.\n', siteData.siteID, siteData.geoLat, siteData.geoLon, siteData.Fs);
   else
       if isequal(siteData,siteDataTemp)
        time    = [time; timeTemp];
        B_H     = [B_H; B_HTemp];
        B_D     = [B_D; B_DTemp];
        Qual    = [Qual; QualTemp];
       else
        fprintf('ERROR: Site information does not match. Ignoring File!.\n');
       end
   end
end

deltaTime = time(2:end)-time(1:end-1);
timeSkips = (abs(seconds(deltaTime) - 1/siteData.Fs) > 1e-6);

if (sum(timeSkips) > 0)
    fprintf('ERROR: Time skipped. Look near %s.\n', datestr(time(find(timeSkips,1))));
end

end