% Script g3 (not a function)
%
% This is going to load some magnetic data and try to find a daily cycle
% in it.

% Load the file
mags=load('HargravesMag_A_F.txt');

% Take inspiration from CONVERTDATES.m to convert "dates" to days.
magt=datenum(mags(:,7)+2000,mags(:,5),mags(:,6),mags(:,2),mags(:,3),mags(:,4));
magt=[magt-magt(1)]*24;

% Quick plot
plot(magt,mags(:,1),'+')

% Now use g2 to see if there might be a 24 hour cycle??
g2(magt,mags(:,1),24);

% Remove outliers to improve the analysis
magx=mags(:,1);
strip=[magx<prctile(magx,05) | magx>prctile(magx,95)];
magx(strip)=NaN;
magxt=magt(~isnan(magx));
magx=magx(~isnan(magx));

% Quick plot
plot(magxt,magx,'+')

% Now use g2 to see if there might be a 24 hour cycle??
g2(magxt,magx,24);
 amplitudes A  8.39  
 periods    P 24.00  
 offset term  49630.93  
 variance rd   4.82%

 amplitudes A  6.03  
 periods    P 24.00  
 offset term  49633.84  
 variance rd   5.85%