% loads & plots sp files

% WaveSpectra file format:
%{
columns     variable                description
1           Decimal Day-of-Year     timestamp
2:79        F2                      Frequency bin array, Hz
80:157      Df2                     Delta F for F2 bins, Hz
158:235     S2                      Spectral data, m^2.Hz
%}

%% initialize
clear
close all

%% load data
data_path = 'D:\Data\CAPRICORN_2016\Investigator\flux\Processed\riegl_wave_data';
SP = load(fullfile(data_path,'CAPRICORN_2016_WaveSpectra.txt'));
ST = load(fullfile(data_path,'CAPRICORN_2016_WaveStats.txt'));

jd = ST(:,1);
missing = ST(:,2);      % # missing points in 10 min period

%% read  spectra arrays
jj = find(missing<600);     % define filtering criteria
F2 = SP(jj(1),2:79);
Df2 = SP(jj(1),80:157);
S2 = nanmean1(SP(jj,158:235),1);

%% plot mean spectrum

ff = find(F2>0.01,1,'first');
figure; loglog(F2(ff:end)',S2(ff:end),'ro-');
ylim([max(min(S2(ff:end)),10^-6),10^(ceil(max(log10(S2(ff:end)))))]);
xlabel('Frequency (Hz)'); ylabel('S_{hh} (m^2/Hz)'); ;grid;
