clear all
close all
warning off all
clc

%MCTools behoevend
zw_dir = 'D:\werf_je\Werk\1.201.819-Proefsuppletie_Galgeplaat_2e_evaluatie\Data\Waterstand\';
lof = 53000;%grootte van het bestand (ongeveer)
i = 0;

for file = dir(fullfile(zw_dir,'*.data'))',
    clear tijdstip t zw hwb
    hwb = waitbar(0,[strrep(file.name,'.data',''),'...']);
    jj = 0;
    i = i + 1;
    
    fid = fopen(fullfile(zw_dir,file.name));
    
    fgetl(fid);
    fgetl(fid);
    fgetl(fid);
    for j = 1:lof
        waitbar(j/lof);
        clear dum
        try dum = fscanf(fid,'%s',1);
            dum = strrep(dum,'mrt','mar');
            dum = strrep(dum,'mei','may');
            dum = strrep(dum,'okt','oct');
            try datestr(dum);                    
                clear dum2
                jj = jj+1;
                tijdstip{jj} = fscanf(fid,'%s',1);
                t(jj) = datenum([dum,' ',tijdstip{jj}],'dd-mmm-yyyy HH:MM');        	
                dum2 = fscanf(fid,'%f',1);
                if ~isempty(dum2)
                    zw(jj) = 0.01*dum2;
                else
                    zw(jj) = NaN;
                    fgetl(fid);
                end
            catch
                fgetl(fid);
                fgetl(fid);
                fgetl(fid);
            end
        catch
        end
    end
    fclose(fid);
    close(hwb);
    zw_data.naam(i) = {strrep(file.name,'.data','')};
    zw_data.t(i) = {t};
    zw_data.zw(i) = {zw};

    h = figure;
    plot(zw_data.t{i},zw_data.zw{i},'b-')
    hold on
    xlabel('datum')
    ylabel('z_w (m NAP)')
    title(zw_data.naam(i))
    xData = linspace(min(zw_data.t{i}),max(zw_data.t{i}),12);
    set(gca,'XTick',xData);
    datetick('x','mm','keepticks')    
    grid on
    pause
    close(h);
end

save zw_data zw_data