%concaténation des spectrogrammes (FFTBrest_XXXXXXX.mat) pour un affichage
%global

clear all
directory='C:\Users\augereau\Documents\manu\ricochet\traitement\sismo\FFTBrest*.mat';
List=dir(directory)

spectro_out=struct('FFTspectrum',{0},'FFTfrequencies',{0},'Time0',{0});

for ii=1:length(List)
   
    % Load des données
    spectro_in=load(List(ii).name);
    
    if ii==1
    spectro_out.FFTspectrum=[spectro_in.FFTspectrum];
    spectro_out.FFTfrequencies=[spectro_in.FFTfrequencies];
    spectro_out.Time0=[spectro_in.Time0];
    else
    
    spectro_out.FFTspectrum=[spectro_out.FFTspectrum,spectro_in.FFTspectrum];
    spectro_out.FFTfrequencies=[spectro_out.FFTfrequencies,spectro_in.FFTfrequencies];
    spectro_out.Time0=[spectro_out.Time0,spectro_in.Time0];
    
    end
end

FFTspectrum=spectro_out.FFTspectrum;
FFTfrequencies= spectro_out.FFTfrequencies;
Time0= spectro_out.Time0;

save(strcat('FFTBrest_',List(1).name(10:17),'_full.mat'),'FFTspectrum','FFTfrequencies','Time0')

%%PLOT

CSCALE=jet(length(spectro_out.FFTspectrum));
PSpectro=zeros(length(spectro_out.FFTspectrum),length(spectro_out.FFTfrequencies{1}));

figure;
subplot 211
loglog(spectro_out.FFTfrequencies{1},spectro_out.FFTspectrum{1},'color',CSCALE(1,:),'linewidth',1.5)
PSpectro(1,:)=spectro_out.FFTspectrum{1};
hold on;grid on;box on;
set(gca,'fontname','arial','fontsize',14)
ylabel('Amplitude','fontname','arial','fontsize',14)
xlabel('Frequency','fontname','arial','fontsize',14)

for ll=2:length(spectro_out.FFTspectrum)
    loglog(spectro_out.FFTfrequencies{ll},spectro_out.FFTspectrum{ll},'color',CSCALE(ll,:))
    PSpectro(ll,:)=spectro_out.FFTspectrum{ll};

end
axis([1/100 50 1E-12 1E-5])

subplot 212
load CMAPBREST.mat
pcolor(spectro_out.Time0,spectro_out.FFTfrequencies{1},PSpectro')
set(gca,'Yscale','log')
shading interp
colorbar;
caxis([1E-13 5E-8]);
colormap (CMAP);
datetick('x','dd-mmm','keepticks')
axis([spectro_out.Time0(1) spectro_out.Time0(end) 2E-2 50])
set(gca,'fontname','arial','fontsize',14)
xlabel('Date','fontname','arial','fontsize',14)
ylabel('Frequency','fontname','arial','fontsize',14)
