FSTD.m 3.9 KB
function FSTD
evalin('base','clear all')
evalin('base','close all')

[filename,filepath]= uigetfile('*.*','All files');
path=[filepath,'/',filename];

x=ncread(path,'x_axis');
t=ncread(path,'time');
om=ncread(path,'omega');
spectre=ncread(path,'Spectrum');
Dave=ncread(path,'Dave');
FSD=ncread(path,'Floe size distribution');
Fsize=ncread(path,'floe size');
thick=ncread(path,'Ice thickness');
conc=ncread(path,'Ice concentration');
Hs=ncread(path,'significant height');
IDT=ncread(path,'Ice Thickness Distribution');
hcat=ncread(path,'thickness categories');
dx=(x(2)-x(1))*1000;
assignin('base','x',x)
assignin('base','FSD',FSD)
assignin('base','IDT',IDT)
assignin('base','Fsize',Fsize)
assignin('base','hcat',hcat)
assignin('base','dx',dx)

fig=figure('Name','Floe size and Thickness distribution','position',[200 200 1200 1000],'Numbertitle','off');
set(fig,'color',[0.2 0.2 0.2])
cmap=coolcolor;
assignin('base','cmap',cmap)

plot1=subplot(2,2,3:4);

[hAx,hLine1,hLine2] =plotyy(x,thick,x,Dave);
set(hAx,'color','none')
set(hAx(1),'ycolor','b')
set(hAx(2),'ycolor','g')
set(hLine1,'linewidth',2,'color','b')
set(hLine2,'linewidth',2,'color','g')
h2=gca;
assignin('base','h2',h2)
axesPosition=get(h2,'Position');
ylabel(hAx(2),'Mean Floe size [m]','interpreter','latex');
ylabel(hAx(1),'Mean Ice thickness [m]','interpreter','latex');
xlabel('Distance [km]','interpreter','latex');
hold on
xLimit = [min(x) max(x)];
yWidth = 0.05;
xOffset = -yWidth*diff(xLimit)/axesPosition(3);
h1 = axes('Position',axesPosition+yWidth.*[-1 0 1 0],...
    'Color','none','XColor','k','YColor','r',...
    'XLim',xLimit+[xOffset 0],...
    'XTick',[],'XTickLabel',[],'NextPlot','add');
plot(h1,x,Hs(find(Hs>0)),'r','linewidth',2);
assignin('base','h1',h1)
ylabel('Significant height [m]','interpreter','latex');
hold on
curs=datacursormode(fig);
set(curs,'enable','on');
set(curs,'UpdateFcn', @plotother)

    function txt = plotother(~,event)
        
        x=evalin('base','x');
        dx=evalin('base','dx');
        h1=evalin('base','h1');
        IDT=evalin('base','IDT');
        FSD=evalin('base','FSD');
        Fsize=evalin('base','Fsize');
        hcat=evalin('base','hcat');
        cmap=evalin('base','cmap');
        
        pos = get(event,'Position');
        txt = {['',num2str(pos(1))]};
        [~,posx]=min(abs(x-pos(1)));
        
        if (gca==h1)
            
            ise = evalin( 'base', 'exist(''linex'') == 1' );
            
            if ise
                evalin('base', 'set(linex,''visible'',''off'')')
            end
            
            FSD1=reshape(FSD(posx,posx,:,:),length(Fsize),length(hcat));
            IDT1=IDT(posx,:);
            for i=1:length(hcat)
                FSD1(:,i)=FSD1(:,i)*IDT1(i);
                nfloe(:,i)=((FSD1(:,i)*(dx)^2)./Fsize.^2) ;
            end
            nfloe=nfloe/sum(sum(nfloe));
            
            
            subplot(2,2,1)
            title('FSTD')
            colormap(cmap)
            pcolor(hcat,Fsize,nfloe);
            shading interp
            c=colorbar;
            xlabel('Floe thickness [m]','interpreter','latex')
            ylabel('Floe size','interpreter','latex')
            ylabel(c,'normalized number of floes','interpreter','latex')
            
            
            subplot(2,2,2)
            title('FSD')
            FSD2(posx,:)=sum(FSD1,2);
            nfloe2=((sum(FSD1,2)*dx^2)./Fsize.^2)/sum((sum(FSD1,2)*dx^2)./Fsize.^2);
            plot(Fsize,nfloe2,'linewidth',2,'color','m')
            set(gca,'color','none')
            xlabel('Floe size [m]','interpreter','latex')
            ylabel('normalized number of floes','interpreter','latex')
            grid on
            
            get(h1,'ylim')
            linex=plot(h1,[pos(1) pos(1)],get(h1,'ylim'),'linewidth',1.5,'color',[0.2 0.2 0.6],'linestyle','--');
            assignin('base','linex',linex)
            
        end
        
    end

end