% BLRMS analysis
% cd ~/Documents/LIGO/LHO/
gwd = GWData;
gwd.use_backup_server(1)

tStart = GWData.gps_convert('1 Sep 2015 00:00:00');

load blrms_61to100

blrms5 = blrms_total(5, :);
ok_blrms_total = blrms5 > 1e-20 & blrms5 < 1e-18;
blrms5(~ok_blrms_total) = NaN;

tBLRMS = (0:(numel(ok_blrms_total) - 1)) * 60 * 12;

plot(tBLRMS, blrms5)

tStartMin = 60 * floor(tStart / 60);
nGo = find(tBLRMS > 7e6);
tGoStride = tBLRMS(nGo(1:30:end)) + tStartMin;
for n = 1:200
  fprintf('\n=== FETCH %d of %d\n', n, numel(tGoStride))
  [d_n, t_n] = gwd.fetch(tGoStride(n), tGoStride(n + 1), ...
    'H0:FMC-LVEA_AVTEMP_DEGC.mean,m-trend');
  if n == 1
    dtemp = d_n;
  else
    dtemp = [dtemp; d_n];
  end
end

ttemp0 = tGoStride(1);
ttemp = (0:(numel(dtemp) - 1)) * 60;
plot(tBLRMS, blrms5, ttemp + (ttemp0 - tStart), dtemp * 1e-20)

nBT = find(tBLRMS + tStart > ttemp0 & ...
  tBLRMS + tStart < ttemp(end) + ttemp0);
tBT = tBLRMS(nBT)+ tStart - ttemp0;
blrmsBT = blrms5(nBT);

plot(tBT, (blrmsBT * 1e20 - 6) / 2, ttemp, (dtemp - mean(dtemp)));

