clear all
close all
clc
warning off all

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

for file = dir(fullfile(wind_dir,'*.data'))',
    clear tijdstip t V theta hwb
    hwb = waitbar(0,[strrep(file.name,'.data',''),'...']);
    jj = 0;
    i = i + 1;
    
    fid = fopen(fullfile(wind_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 dum3
                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)
                    V(jj) = 0.1*dum2;
                else
                    V(jj) = NaN;                    
                end
                dum3 = fscanf(fid,'%f',1);
                if ~isempty(dum3)
                    theta(jj) = dum3;
                else
                    theta(jj) = NaN;                    
                end
                fgetl(fid);
            catch
                fgetl(fid);
                fgetl(fid);
                fgetl(fid);
            end
        catch
            break
        end
    end
    fclose(fid);
    close(hwb);
    wind_data.naam(i) = {strrep(file.name,'.data','')};
    wind_data.t(i) = {t};
    wind_data.V(i) = {V};
    wind_data.theta(i) = {theta};

    h = figure;
    subplot(2,1,1)
    plot(wind_data.t{i},wind_data.V{i},'b-')
    hold on
    ylabel('V (m/s)')
    title(wind_data.naam(i))
    xData = linspace(min(wind_data.t{i}),max(wind_data.t{i}),12);
    set(gca,'XTick',xData);
    datetick('x','mm','keepticks')    
    grid on
    
    subplot(2,1,2)
    plot(wind_data.t{i},wind_data.theta{i},'b-')
    hold on
    xlabel('datum')
    ylabel('\theta (^oN)')
    title(wind_data.naam(i))
    xData = linspace(min(wind_data.t{i}),max(wind_data.t{i}),12);
    set(gca,'XTick',xData);
    datetick('x','mm','keepticks')    
    grid on
    pause
    close(h);
end

save wind_data wind_data