% subroutine to plot the size distribution for a first look
% We plot three days, since sometimes the growth can be followed for more
% than 30 hours
disp('plotting data');
figure(1);clf;
set(gcf,'paperorientation','portrait');
set(gcf,'paperunits','centimeters');
set(gcf,'papertype','a4letter');
set(gcf,'paperposition',[0 0 20.984 25]);
fontsize=14;

% starting with figure 1
subplot(3,1,1);
hold;
colormap(jet(250));
set(gca,'position',[.1 .64 .7 .27]);
yaxis=[3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 200 300 400 500 ...
      600 700 800 900 1000]*1e-9;
set(gca,'ylim',[yaxis(1) yaxis(length(yaxis))])
set(gca,'ytick',[yaxis],'yticklabel',{[],[],[],[],[],[],[], ...
      [10],[],[],[],[],[],[],[],[], ...
      [100],[],[],[],[],[],[],[],[],[1000]})
xti=period(i)+[-.25 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 24.25]/24;
set(gca,'yticklabelmode','manual')
set(gca,'xlim',[xti(1) xti(length(xti))])
set(gca,'xtick',xti,'xticklabel',{[],[],[],[],[],[],[],[],[],[], ...
      [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]})
set(gca,'fontsize',14);
set(gca,'yscale','log');
baraxis=[1 2 3 4 5];
caxis([baraxis(1) baraxis(length(baraxis))]);
text(period(i)+.35,400e-9,datestr(period(i)),'fontsize',fontsize,'color','white');
text(period(i)+1.2,200e-9,'cm^{-3}','fontsize',fontsize);
h=colorbar('vertical');
set(h,'fontsize',14)
set(h,'position',[0.85 0.2 .03 .6])
set(h,'ylim',[baraxis(1) baraxis(length(baraxis))],'ytick',[baraxis])
set(h,'yticklabel',{'10';'100';'1000';'10000';'100000'})

if exist([stationname,datestr(period(i),'YY'),datestr(period(i),'mm'),datestr(period(i),'dd'),'.sum'])>0;
dmpsselect1=dmpsdataday1(:,3:end);
time1=dmpsdataday1(:,1);
% correcting data if below 0
for j=1:size(dmpsselect1,1)
    for k=1:size(dmpsselect1,2)
        if dmpsselect1(j,k)<=0
            dmpsselect1(j,k)=1e-14;
        end
    end
end

%% taking log (to be able to plot correctly)
dmpsselect1=log10(dmpsselect1);

%% plotting spectra one
if size(time1,1)>0 && size(dmpsselect1,1)>0     %test to see if data is OK
    pcolor(time1,sizes1,dmpsselect1')
    shading interp
    
end
end
if exist([stationname,datestr(period(i),'YY'),datestr(period(i),'mm'),datestr(period(i),'dd'),'.fit'])>0;
dmpsfit1=dmpsfitdata(find(floor(dmpsdata(:,1))==period(i)),3:end);
end

%Plotting lines that show when the event starts and ends
if exist([stationname,datestr(period(i),'YY'),datestr(period(i),'mm'),datestr(period(i),'dd'),'.MNC'])>0;
plot([MNCdata(find(MNCdata(:,2)==period(i)),5) MNCdata(find(MNCdata(:,2)==period(i)),5)],[1e-9 2000e-9],'k','linewidth',2);
plot([MNCdata(find(MNCdata(:,2)==period(i)),7) MNCdata(find(MNCdata(:,2)==period(i)),7)],[1e-9 2000e-9],'k','linewidth',2);
end
hold off;

% figure 2
subplot(3,1,2);
hold;
colormap(jet(250));
set(gca,'position',[.1 .37 .7 .27]);
yaxis=[3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 200 300 400 500 ...
      600 700 800 900 1000]*1e-9;
set(gca,'ylim',[yaxis(1) yaxis(length(yaxis))])
set(gca,'ytick',[yaxis],'yticklabel',{[],[],[],[],[],[],[], ...
      [10],[],[],[],[],[],[],[],[], ...
      [100],[],[],[],[],[],[],[],[],[1000]})
xti=period(i)+1+[-.25 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 24.25]/24;
set(gca,'yticklabelmode','manual')
set(gca,'xlim',[xti(1) xti(length(xti))])
set(gca,'xtick',xti,'xticklabel',{[],[],[],[],[],[],[],[],[],[], ...
      [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]})
set(gca,'fontsize',14);
set(gca,'yscale','log');
baraxis=[1 2 3 4 5];
caxis([baraxis(1) baraxis(length(baraxis))]);
text(period(i)+1+.35,400e-9,datestr(period(i)+1),'fontsize',14,'color','white');

if exist([stationname,datestr(period(i)+1,'YY'),datestr(period(i)+1,'mm'),datestr(period(i)+1,'dd'),'.sum'])>0;
dmpsselect2=dmpsdataday2(:,3:end);
time2=dmpsdataday2(:,1);
% correcting data if below 0
for j=1:size(dmpsselect2,1)
    for k=1:size(dmpsselect2,2)
        if dmpsselect2(j,k)<=0
            dmpsselect2(j,k)=1e-14;
        end
    end
end
%% taking log (to be able to plot correctly)
dmpsselect2=log10(dmpsselect2);
%% plotting spectra two
if size(time2,1)>0 && size(dmpsselect2,1)>0     %test to see if data is OK
    pcolor(time2,sizes2,dmpsselect2')
    shading interp
end
end
if exist([stationname,datestr(period(i)+1,'YY'),datestr(period(i)+1,'mm'),datestr(period(i)+1,'dd'),'.fit']);
dmpsfit2=dmpsfitdata(find(floor(dmpsdata(:,1))==period(i)+1),3:end);
end
ylabel('Particle diameter (nm)','fontsize',fontsize);
hold off;



% figure 3
subplot(3,1,3);
hold;
colormap(jet(250));
set(gca,'position',[.1 .10 .7 .27]);
yaxis=[3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 200 300 400 500 ...
      600 700 800 900 1000]*1e-9;
set(gca,'ylim',[yaxis(1) yaxis(length(yaxis))])
set(gca,'ytick',[yaxis],'yticklabel',{[],[],[],[],[],[],[], ...
      [10],[],[],[],[],[],[],[],[], ...
      [100],[],[],[],[],[],[],[],[],[1000]})
xti=period(i)+2+[-.25 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 24.25]/24;
set(gca,'yticklabelmode','manual')
set(gca,'xlim',[xti(1) xti(length(xti))])
set(gca,'xtick',xti,'xticklabel',{[],[0],[],[],[],[4],[],[],[],[8], ...
      [],[],[],[12],[],[],[],[16],[],[],[],[20],[],[],[],[24],[]})
set(gca,'fontsize',14);
set(gca,'yscale','log');
baraxis=[1 2 3 4 5];
caxis([baraxis(1) baraxis(length(baraxis))]);
text(period(i)+2+.35,400e-9,datestr(period(i)+2),'fontsize',14,'color','white');
xlabel('Time','fontsize',fontsize);

if exist([stationname,datestr(period(i)+2,'YY'),datestr(period(i)+2,'mm'),datestr(period(i)+2,'dd'),'.sum'])>0;
dmpsselect3=dmpsdataday3(:,3:end);
time3=dmpsdataday3(:,1);
% correcting data if below 0
for j=1:size(dmpsselect3,1)
    for k=1:size(dmpsselect3,2)
        if dmpsselect3(j,k)<=0
            dmpsselect3(j,k)=1e-14;
        end
    end
end

%% taking log (to be able to plot correctly)

dmpsselect3=log10(dmpsselect3);
%% plotting spectra three

if size(time3,1)>0 && size(dmpsselect3,1)>0     %test to see if data is OK
    pcolor(time3,sizes3,dmpsselect3')
    shading interp
end
end
if exist([stationname,datestr(period(i)+2,'YY'),datestr(period(i)+2,'mm'),datestr(period(i)+2,'dd'),'.fit'])>0;
dmpsfit3=dmpsfitdata(find(floor(dmpsdata(:,1))==period(i)+2),3:end);
end
hold off;
