function Transform(s)

%% parameters

% load input data
% ------DONAR----------------
D = getDONARdata(s);

% ------MATROOS--------------

urlChar = '..\WaveTable\'; %'p:/webtools/tools/WaveTable/';
E.YM6a  = fileread([urlChar 'YM6_matroos.asc']); id1 = regexp(E.YM6a,'\n');
E.YM6a  = str2num(reshape(E.YM6a,id1(1),(length(E.YM6a)/id1(1)))');
E.EURa  = fileread([urlChar 'EUR_matroos.asc']); id2 = regexp(E.EURa,'\n');
E.EURa  = str2num(reshape(E.EURa,id2(1),(length(E.EURa)/id2(1)))');
E.ELDa  = fileread([urlChar 'ELD_matroos.asc']); id3 = regexp(E.ELDa,'\n');
E.ELDa  = str2num(reshape(E.ELDa,id3(1),(length(E.ELDa)/id3(1)))');

% load input matrix for conversion
load('TransMatrix_InputParameters.mat');

%% input

% DATAFILES
% IJMUIDEN
id(1).hm0           = find(E.YM6a(:,1) > D(1).hm0.time(end));
id(1).th0           = find(E.YM6a(:,1) > D(1).th0.time(end));
id(1).tm02          = find(E.YM6a(:,1) > D(1).tm02.time(end));

ym6.time(1).datenum = (round(24*6*[D(1).hm0.time(:); E.YM6a(id(1).hm0,1)]))/24/6;
ym6.time(2).datenum = (round(24*6*[D(1).th0.time(:); E.YM6a(id(1).th0,1)]))/24/6;
ym6.time(3).datenum = (round(24*6*[D(1).tm02.time(:);E.YM6a(id(1).tm02,1)]))/24/6;
ym6.Hm0.data        = [D(1).hm0.val(:);  E.YM6a(id(1).hm0,2)];
ym6.Th0.data        = [D(1).th0.val(:);  E.YM6a(id(1).th0,3)];
ym6.Tm02.data       = [D(1).tm02.val(:); E.YM6a(id(1).tm02,4)];

% EUROPLATFORM
id(2).hm0           = find(E.EURa(:,1) > D(2).hm0.time(end));
id(2).th0           = find(E.EURa(:,1) > D(2).th0.time(end));
id(2).tm02          = find(E.EURa(:,1) > D(2).tm02.time(end));

eur.time(1).datenum = (round(24*6*[D(2).hm0.time(:); E.EURa(id(2).hm0,1)]))/24/6;
eur.time(2).datenum = (round(24*6*[D(2).th0.time(:); E.EURa(id(2).th0,1)]))/24/6;
eur.time(3).datenum = (round(24*6*[D(2).tm02.time(:);E.EURa(id(2).tm02,1)]))/24/6;
eur.Hm0.data        = [D(2).hm0.val(:);  E.EURa(id(2).hm0,2)];
eur.Th0.data        = [D(2).th0.val(:);  E.EURa(id(2).th0,3)];
eur.Tm02.data       = [D(2).tm02.val(:); E.EURa(id(2).tm02,4)];

% EIERLANDSE GAT
id(3).hm0           = find(E.ELDa(:,1) > D(3).hm0.time(end));
id(3).th0           = find(E.ELDa(:,1) > D(3).th0.time(end));
id(3).tm02          = find(E.ELDa(:,1) > D(3).tm02.time(end));

eld.time(1).datenum = (round(24*6*[D(3).hm0.time(:); E.ELDa(id(3).hm0,1)]))/24/6;
eld.time(2).datenum = (round(24*6*[D(3).th0.time(:); E.ELDa(id(3).th0,1)]))/24/6;
eld.time(3).datenum = (round(24*6*[D(3).tm02.time(:);E.ELDa(id(3).tm02,1)]))/24/6;
eld.Hm0.data        = [D(3).hm0.val(:);  E.ELDa(id(3).hm0,2)];
eld.Th0.data        = [D(3).th0.val(:);  E.ELDa(id(3).th0,3)];
eld.Tm02.data       = [D(3).tm02.val(:); E.ELDa(id(3).tm02,4)];

clear D E id

% waveconditions from SWAN simulations
WC.eur              = Input.data(3:8:length(Input.data),:);
WC.ym6              = Input.data(4:8:length(Input.data),:);
WC.eld              = Input.data(5:8:length(Input.data),:);

% XY-coordinates (using least square technique)
aa                  = sqrt(((Grid.X - s.Loc.X).^2 + (Grid.Y - s.Loc.Y).^2));
[s.Loc.M s.Loc.N]   = find(aa==min(min(aa)));

%% convert timeseries
tstart =  ([ym6.time(1).datenum(1),ym6.time(2).datenum(1),ym6.time(3).datenum(1),...
            eur.time(1).datenum(1),eur.time(2).datenum(1),eur.time(3).datenum(1),...
            eld.time(1).datenum(1),eld.time(2).datenum(1),eld.time(3).datenum(1)]);
        
% make new timeline and fill the data to this timeline
%   3-hourly date up to 01-Jan-1987
%   hourly data up to 01-Jul-2007
%   10 minutes interval up to now
Tnew     = unique([min(tstart):3/24:datenum(1987,01,01), datenum(1987,01,01):1/24:datenum(2007,07,01), datenum(2007,07,01):1/(24*6):ym6.time(1).datenum(end)]');

for i=1:length(ym6.time)
        % IJMUIDEN
        % remove doubles
        [dum,idt]           = unique(ym6.time(i).datenum);
        ym6.time(i).datenum = ym6.time(i).datenum(idt);
        if i==1;     ym6.Hm0.data  = ym6.Hm0.data(idt);
        elseif i==2; ym6.Th0.data  = ym6.Th0.data(idt);
        elseif i==3; ym6.Tm02.data = ym6.Tm02.data(idt);
        end
        % line up timeseries to Tnew
        dumT                = nan(length(Tnew),1);
        dumV                = nan(length(Tnew),1);
        a                   = ismember(round(24*6*Tnew),round(24*6*ym6.time(i).datenum));
        b                   = ismember(round(24*6*ym6.time(i).datenum),round(24*6*Tnew));
        dumT(a)             = ym6.time(i).datenum(b); 
        ym6.time(i).datenum = dumT;
        if     i==1; dumV(a)= ym6.Hm0.data(b);  ym6.Hm0.data = dumV;
        elseif i==2; dumV(a)= ym6.Th0.data(b);  ym6.Th0.data = dumV;
        elseif i==3; dumV(a)= ym6.Tm02.data(b); ym6.Tm02.data= dumV;
        end; clear dumT dumV a b dum idt;

        % EUROPLATFORM
        % remove doubles
        [dum,idt]           = unique(eur.time(i).datenum);
        eur.time(i).datenum = eur.time(i).datenum(idt);
        if i==1;     eur.Hm0.data  = eur.Hm0.data(idt);
        elseif i==2; eur.Th0.data  = eur.Th0.data(idt);
        elseif i==3; eur.Tm02.data = eur.Tm02.data(idt);
        end
        % line up timeseries to Tnew
        dumT                = nan(length(Tnew),1);
        dumV                = nan(length(Tnew),1);
        a                   = ismember(round(24*6*Tnew),round(24*6*eur.time(i).datenum));
        b                   = ismember(round(24*6*eur.time(i).datenum),round(24*6*Tnew));
        dumT(a)             = eur.time(i).datenum(b); 
        eur.time(i).datenum = dumT;
        if     i==1; dumV(a)= eur.Hm0.data(b);  eur.Hm0.data = dumV;
        elseif i==2; dumV(a)= eur.Th0.data(b);  eur.Th0.data = dumV;
        elseif i==3; dumV(a)= eur.Tm02.data(b); eur.Tm02.data= dumV;
        end; clear dumT dumV a b dum idt;

        % EIERLANDSE GAT
        % remove doubles
        [dum,idt]           = unique(eld.time(i).datenum);
        eld.time(i).datenum = eld.time(i).datenum(idt);
        if i==1;     eld.Hm0.data  = eld.Hm0.data(idt);
        elseif i==2; eld.Th0.data  = eld.Th0.data(idt);
        elseif i==3; eld.Tm02.data = eld.Tm02.data(idt);
        end
        % line up timeseries to Tnew
        dumT                = nan(length(Tnew),1);
        dumV                = nan(length(Tnew),1);
        a                   = ismember(round(24*6*Tnew),round(24*6*eld.time(i).datenum));
        b                   = ismember(round(24*6*eld.time(i).datenum),round(24*6*Tnew));
        dumT(a)             = eld.time(i).datenum(b); 
        eld.time(i).datenum = dumT;
        if     i==1; dumV(a)= eld.Hm0.data(b);  eld.Hm0.data = dumV;
        elseif i==2; dumV(a)= eld.Th0.data(b);  eld.Th0.data = dumV;
        elseif i==3; dumV(a)= eld.Tm02.data(b); eld.Tm02.data= dumV;
        end; clear dumT dumV a b dum idt;
end

% if offshore direction 30 < dir < 200, then no transformation
% because these data are not classified in the matrix
nid                 = find(ym6.Th0.data >= 30 & ym6.Th0.data <= 200);
ym6.Hm0.data(nid)   = NaN;      ym6.Th0.data(nid)   = NaN;      ym6.Tm02.data(nid)  = NaN;      % ym6.surge.data(nid) = NaN;
eur.Hm0.data(nid)   = NaN;      eur.Th0.data(nid)   = NaN;      eur.Tm02.data(nid)  = NaN;      % eur.surge.data(nid) = NaN;
eld.Hm0.data(nid)   = NaN;      eld.Th0.data(nid)   = NaN;      eld.Tm02.data(nid)  = NaN;      % eld.surge.data(nid) = NaN;

% transformation of Tm02 to Tp (because no realible results for Tm, only for Tp)
ym6.Tp              = ym6.Tm02;
ym6.Tp.data         = ym6.Tp.data * 1.28; 
eur.Tp              = eur.Tm02;
eur.Tp.data         = eur.Tp.data * 1.28; 
eld.Tp              = eld.Tm02;
eld.Tp.data         = eld.Tp.data * 1.28; 

% find right transformation factor from the matrix
% step 1: classify data
% step 2: classify SWAN runs
% step 3: find right factor
vid                 = find(Tnew>=s.StartDate & Tnew<s.EndDate);
output.Hm0.data     = repmat(NaN,size(vid)); 
output.Hdir.data    = repmat(NaN,size(vid)); 
output.Tp.data      = repmat(NaN,size(vid)); 

hh = waitbar(0,'Transforming offshore data to nearshore, Please wait .......');
for n=1:length(vid)
    waitbar(n/length(vid),hh)
    % classify values, so that the transformation matrix can be used
    for i=1:length(classes{1})
        for j=1:length(classes{2})
            did  = find(ym6.Hm0.data(vid(n)) >  classes{1}(i,1) & ...
                        ym6.Hm0.data(vid(n)) <= classes{1}(i,2) & ....
                        ym6.Th0.data(vid(n)) >  classes{2}(j,1) & ...
                        ym6.Th0.data(vid(n)) <= classes{2}(j,2));
            if did ==1; ii=i; jj=j; break; end
        end
    end

    if exist('ii')
        % check between which offshore stations, the point is located
        if s.Loc.N < 105
            % now check for directions, locations below N=40, get directional information from EUR, locations above N=40 from YM6
            if s.Loc.N < 40
                if (~isnan(ym6.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & eur.Th0.data(vid(n))>280);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * ym6.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + eur.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * ym6.Tp.data(vid(n));
                elseif (~isnan(eur.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & eur.Th0.data(vid(n))<=280);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * eur.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + eur.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * eur.Tp.data(vid(n));
                else; end;
            else
                if (~isnan(ym6.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & ym6.Th0.data(vid(n))>280);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * ym6.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + ym6.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * ym6.Tp.data(vid(n));
                elseif (~isnan(eur.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & ym6.Th0.data(vid(n))<=280);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * eur.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + ym6.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * eur.Tp.data(vid(n));
                else; end;
            end;
        
        elseif s.Loc.N >= 105 & s.Loc.N <205
            % now check for directions, locations below N=185, get directional information from YM6, locations above N=185 from ELD
            if s.Loc.N < 185
                if (~isnan(eld.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & ym6.Th0.data(vid(n))>300);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * eld.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + ym6.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * eld.Tp.data(vid(n));
                elseif (~isnan(ym6.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & ym6.Th0.data(vid(n))<=300);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * ym6.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + ym6.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * ym6.Tp.data(vid(n));
                else; end;
            else
                if (~isnan(eld.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & eld.Th0.data(vid(n))>300);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * eld.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + eld.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * eld.Tp.data(vid(n));
                elseif (~isnan(ym6.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)) & eld.Th0.data(vid(n))<=300);
                    output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * ym6.Hm0.data(vid(n));
                    output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + eld.Th0.data(vid(n));   % directions, so summation
                    output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * ym6.Tp.data(vid(n));
                else; end;
            end
        % locations above ELD always get information from ELD
        elseif s.Loc.N >= 205;

            if (~isnan(eld.Hm0.data(vid(n))) & ~isnan(WCmat(ii,jj)));
                output.Hm0.data(n)     = Trans(WCmat(ii,jj)).Hs(s.Loc.M,s.Loc.N)   * eld.Hm0.data(vid(n));
                output.Hdir.data(n)    = Trans(WCmat(ii,jj)).Hdir(s.Loc.M,s.Loc.N) + eld.Th0.data(vid(n));   % directions, so summation
                output.Tp.data(n)      = Trans(WCmat(ii,jj)).Tp(s.Loc.M,s.Loc.N)   * eld.Tp.data(vid(n));
            else; end;
        end
    else; end
    clear ii jj;
end
close(hh)

idHm0_0                     = find(output.Hm0.data==0);
output.Hm0.data(idHm0_0)    = NaN; 
output.Hdir.data(idHm0_0)   = NaN; 
output.Tp.data(idHm0_0)     = NaN; 

% make directions from 0-360 deg.
idTh0_0                     = find(output.Hdir.data<0);
idTh0_360                   = find(output.Hdir.data>360);
output.Hdir.data(idTh0_0)   = output.Hdir.data(idTh0_0)   + 360;
output.Hdir.data(idTh0_360) = output.Hdir.data(idTh0_360) - 360;

%% export data
Output.Data  = [output.Hm0.data output.Hdir.data output.Tp.data];
Output.Time  = {datestr(Tnew(vid),'yyyymmdd') datestr(Tnew(vid),'HHMMSS')};

if s.Loc.N > 205;
    k=warndlg(sprintf('Note: The results of the wave transformation at this location \n           may be not very accurate! \n The wave transformation matrix is build for the area between ELD and EUR'), '!! Warning !!')
else; end

fid = fopen(s.OutputFile,'w');
fprintf(fid,'%s\n','Transformed wave data from the offshore platforms ELD, YM6 and EUR to nearshore');
fprintf(fid,'%s\n','NaN values mean that the wave direction is between 30-200 deg, so no transformation is done');
fprintf(fid,'%s\n',['* Output Location X: ' num2str(s.Loc.X) ' [m; RD]']);
fprintf(fid,'%s\n',['* Output Location Y: ' num2str(s.Loc.Y) ' [m; RD]']);
fprintf(fid,'%s\n','* column 1 = Date');
fprintf(fid,'%s\n','* column 2 = Time');
fprintf(fid,'%s\n','* column 3 = Hm0   (m)');
fprintf(fid,'%s\n','* column 4 = Hdir  (deg N)');
fprintf(fid,'%s\n','* column 5 = Tp  (s)');
%fprintf(fid,'%s\n','* column 6 = Surge (m)');
for i=1:size(vid,1)
    fprintf(fid,'%s',[Output.Time{1}(i,:) '  ' Output.Time{2}(i,:)]);
    fprintf(fid,[repmat('%8.3f   ',1,size(Output.Data,2)) '\n'],Output.Data(i,:)');
end
fclose(fid);

%% figure
time = Tnew(vid);
xx   = (time(end)-time(1))/5;
if xx > 0.8 
    xx   = round((time(end)-time(1))/5);
    xxx  = time(1):xx:time(end);
    xxxx = datestr(xxx,1);
    xl   = 'date [dd-mmm-yyyy]';
elseif xx <= 0.8
    xx   = round(24*((time(end)-time(1))/5))/24;
    xxx  = time(1):xx:time(end);
    xxxx = datestr(xxx,16);  
    xl   = 'date [HH:MM]';
end

% -------------------------------------------------------------------------
% get large nan sections (larger than 5)
id_nan = [find(~isnan(Output.Data(:,1))) ; size(Output.Data,1)]; 

k=0;
if length(id_nan)>1;
    for i=1:length(id_nan)
        if i==1
            t_diff(i,:) = [1 id_nan(i)-1];
        else
            t_diff(i,:) = [id_nan(i-1)+1 id_nan(i)-1];
        end
    end
    for i=1:length(t_diff)
        if t_diff(i,2)-t_diff(i,1) > 5;
            k=k+1;
            tt_diff(k,:) = t_diff(i,:);
        end
    end
end
% -------------------------------------------------------------------------
 
ColorNaN = [1 1 0.88];

figure('PaperType','A4','PaperOrientation','landscape','PaperPositionMode','manual',...
    'PaperUnits','centimeters','Paperposition',[0.5 0.5 28.7 20],'Position',[100 100 1124 768]);
as_1(1) = axes('Position',[.005 .005 .99 .99],'Xtick',[],'Ytick',[],'box','on','handlevisibility','off');

as_1(2) = axes('Position',[0.25 0.68 0.72 0.24]);
if exist('tt_diff')
    for i=1:size(tt_diff,1)
        t = [[time(tt_diff(i,1));time(tt_diff(i,2))]]; t=[t;flipud(t)];
        v = [0; 0; max(Output.Data(:,1)); max(Output.Data(:,1))];
        fill(t,v,ColorNaN,'EdgeColor',ColorNaN); hold on;
    end
end
ll = legend('Wave Direction between 30-200°');
set(ll,'Position',[0.83 0.93 0.1 0.05]);
plot(time,Output.Data(:,1),'b');
set(gca,'XTick',xxx,'XTickLabel',[])
xlim([time(1) time(end)])
yy = [0:0.5:max(Output.Data(:,1))];
set(gca,'YTick',yy,'YTickLabel',yy,'FontSize',8)
ylim([yy(1) yy(end)])
ylabel('Hm0 [m]')
title('Hm0 [m]','FontWeight','bold');
grid on; set(gca,'Layer','top');
box on;

as_1(3) = axes('Position',[0.25 0.38 0.72 0.24]);
if exist('tt_diff')
    for i=1:size(tt_diff,1)
        t = [[time(tt_diff(i,1));time(tt_diff(i,2))]]; t=[t;flipud(t)];
        v = [0; 0; 360; 360];
        fill(t,v,ColorNaN,'EdgeColor',ColorNaN); hold on;
    end
end
plot(time,Output.Data(:,2),'b')
set(gca,'XTick',xxx,'XTickLabel',[])
xlim([time(1) time(end)])
yy = [0:30:360];
set(gca,'YTick',yy,'YTickLabel',yy,'FontSize',8)
ylabel('direction [°N]')
ylim([yy(1) yy(end)])
title('Wave direction [°N]','FontWeight','bold');
grid on; set(gca,'Layer','top');
box on;

as_1(4) = axes('Position',[0.25 0.08 0.72 0.24]);
if exist('tt_diff')
    for i=1:size(tt_diff,1)
        t = [[time(tt_diff(i,1));time(tt_diff(i,2))]]; t=[t;flipud(t)];
        v = [0; 0; 10; 10];
        fill(t,v,ColorNaN,'EdgeColor',ColorNaN); hold on;
    end
end
plot(time,Output.Data(:,3),'b')
set(gca,'XTick',xxx,'XTickLabel',xxxx,'FontSize',8)
xlim([time(1) time(end)])
yy = [0:1:10];
set(gca,'YTick',yy,'YTickLabel',yy,'FontSize',8)
ylim([yy(1) yy(end)])
xlabel(xl);
ylabel('Tp [s]')
title('Tp [s]','FontWeight','bold');
grid on; set(gca,'Layer','top');
box on;

as_1(5) = axes('Position',[0.02 0.02 0.15 0.95]);
textline{1} = ['Computed wave conditions using the Wave Transformation Table'];
textline{2} = ['at location X:' num2str([s.Loc.X]) ' Y:' num2str([s.Loc.Y])]; 
textline{3} = ['from ' datestr(time(1)) ' to ' datestr(time(end))];
textline{4} = ['developed for Building with Nature HK 3.2'];
for j=1:length(textline)
    k=length(textline)+1-j;
    text(j/5,0.99,textline{k},'rotation',270,'FontSize',10)
end
set(gca,'XTick',[],'YTick',[])
text(0.09,0.01,'© Anton de Fockert; Deltares','rotation',0,'FontSize',6)
box on;

PapSize = get(gcf,'PaperSize');             % dimension figure * dimension A4 to get the [width/length] correct
as_1(6) = axes('Position',[0.03 0.04 (0.25*(746/1033)*(PapSize(2)/PapSize(1))) 0.25]);
image(LogoEco);
set(gca,'XTick',[],'YTick',[]); 
box on; set(gca,'Layer','top');

%%
%print(gcf,'-dpng','-painters',[s.OutputFile(1:end-4)]);
print(gcf,'-dpdf','-painters',[s.OutputFile(1:end-4)]);
close all; 