function s = readMKL2012(path)
%

% MKL
OPT.ncpath1      = path; % local
OPT.Filename1    = 'MKL2012.xls';

% jarkus database for transect info
OPT.ncpath      = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/';
OPT.Filename   = 'transect.nc';

% general settings
OPT.refdatenum   = datenum(1970,1,1);

%% Read data form jarkus transect.nc
id       = ncread([OPT.ncpath OPT.Filename],'id');
along    = ncread([OPT.ncpath OPT.Filename],'alongshore');
cross    = ncread([OPT.ncpath OPT.Filename],'cross_shore');
areaname = ncread([OPT.ncpath OPT.Filename],'areaname');
x        = ncread([OPT.ncpath OPT.Filename],'x');
y        = ncread([OPT.ncpath OPT.Filename],'y');

year_MKL    = 2012;
time = datenum(num2str(year_MKL),'yyyy') - OPT.refdatenum;

jarkusyear = str2num(datestr(OPT.refdatenum+ncread([OPT.ncpath OPT.Filename],'time'),'yyyy')); %#ok<ST2NM>

% now read the .xls file for 2012
disp('reading MKL 2012 ')
MKL2012  = xls2struct(fullfile(OPT.ncpath1, OPT.Filename1),'units',0);

% define vars in MKL2012.xls and remove the nans
%refdatenumXls = datenum('30-Dec-1899'); % weird enough...
%----------- Correction 
%xlsdatenum    = cellfun(@(x) (x+refdatenumXls),MKL2012.Year(5:end)); % 5 is header
%xlsdatenum    = cellfun(@(x) (x+refdatenumXls),MKL2012.Year,'UniformOutput',0); % 5 is header
xlsdatenum    = cellfun(@(x) datenum(x,'dd-mm-yyyy'),MKL2012.Year,'UniformOutput',0); % 5 is header
xlsdatenum = cell2mat(xlsdatenum);
%-----------


% xlsdate = MKL2012.Year;
% NotNans = [false(4,1); ~isnan(xlsdatenum)]; % 5 is header
% xlscode = cell2mat(MKL2012.Kv(NotNans));
% xlsraai = cell2mat(MKL2012.Nr(NotNans));
% xlsMaxS = cell2mat(MKL2012.XMaxSea(NotNans));
% xlsZup  = cell2mat(MKL2012.ZUpperBeachVolume(NotNans));
% xlsZlo  = cell2mat(MKL2012.ZLowerBeachVolume(NotNans));
% xlsxMKL = cell2mat(MKL2012.XMkl(NotNans));
% xlsVol  = cell2mat(MKL2012.Volume(NotNans));
% xlsID   = xlscode*1e6 + xlsraai;

NotNans =  sum(~isnan(xlsdatenum),2)==size(xlsdatenum,2);
xlscode = MKL2012.Kv(NotNans);
xlsraai = MKL2012.Nr(NotNans);
xlsMaxS = MKL2012.XMaxSea(NotNans);
xlsZup  = MKL2012.ZUpperBeachVolume(NotNans);
xlsZlo  = MKL2012.ZLowerBeachVolume(NotNans);
xlsxMKL = MKL2012.XMkl(NotNans);
xlsVol  = MKL2012.Volume(NotNans);
xlsID   = xlscode*1e6 + xlsraai;


datenum_MKL = xlsdatenum(~isnan(xlsdatenum));
date_MKL    = datenum_MKL - OPT.refdatenum;


%% convert Xmkl in RD coordinates and in WGS84 and follow the alongshore def
% MKL2012 in RD coordinates
MKL2012_x    = NaN(length(id),1); MKL2012_y   = NaN(length(id),1);
MKL2012MaxS  = NaN(length(id),1); MKL2012date = NaN(length(id),1);
MKL2012_Zup  = NaN(length(id),1); MKL2012_Zlo = NaN(length(id),1);
MKL2012_Xmkl = NaN(length(id),1); MKL2012_Vol = NaN(length(id),1);

[ids, xlsids] = ismember(id, xlsID);
for i = 1:length(id)
    if ids(i)
        
        MKL2012_Xmkl(i) = xlsxMKL(xlsids(i));
        MKL2012MaxS(i)  = xlsMaxS(xlsids(i)); 
        MKL2012date(i)  = date_MKL(xlsids(i));
        MKL2012_Zup(i)  = xlsZup(xlsids(i)); 
        MKL2012_Zlo(i)  = xlsZlo(xlsids(i));
        MKL2012_Vol(i)  = xlsVol(xlsids(i));
        
        MKL2012_x(i) = interp1(cross', x(:,i), xlsxMKL(xlsids(i)));
        MKL2012_y(i) = interp1(cross', y(:,i), xlsxMKL(xlsids(i)));
    end
end
% MKL in WGS84 coordinates
[MKL2012_lon, MKL2012_lat] = convertCoordinates(MKL2012_x,MKL2012_y,'CS1.code',28992,'CS2.code',4326);

s.id = id;
s.areaname = areaname;
s.time     = time;

s.MKL_lat = MKL2012_lat;
s.MKL_lon = MKL2012_lon;
s.MKL_x   = MKL2012_x;
s.MKL_y   = MKL2012_y;

s.Xmkl    = MKL2012_Xmkl;
s.Volume  = MKL2012_Vol;

s.timeMKL = MKL2012date;
s.hoog    = MKL2012_Zup;
s.laag    = MKL2012_Zlo;
s.XzeeMKL = MKL2012MaxS;

