Skip to content
Snippets Groups Projects
simulshift.m 2.50 KiB
function [toa_date,toa]=simulshift(toa_date,toa,sampl_int,windowstart,sosoreftime,FloatReferenceTime);

% 10-NOV-2000, HFurey.  
% Written for ARTOA2 input, based on code from ARTOA_ARTRK.
% INPUT:    toa_date    - truncated julian date of each toa (a non-continuous time vector)
%			toa         - toas of a source that fall on toa_date
%			sampl_int   - the sample interval: need this so can tell if diff(toa_date) 
%                         greater than one cycle
%			windowstart - the start times of every window within a float cycle (e.g., 30 60 90)
%			sosoreftime - the time the source ponged, in hour minute (e.g., 01 30)
% OUTPUT:   toa         - toa string adjusted for simultaneity
%			toa_date    - sorted toa date string (innocuous? relevant? necessary?  keeping cuz
%				          was in the doppler shift code from Olaf/ARTOA2


%------------------------------------------------------------------------------

% this seems OK.  innocuous.
[toa_date,ix]=sort(toa_date);
toa=toa(ix);

% I really need to know sampling interval to correctly apply the time.
sstoa = toa;   % simultaneity shifted toa
diffdate = diff(toa_date); % n-1 long, in days
difftoa = diff(toa);
sampl_int = sampl_int./24;

FloatReferenceTime = FloatReferenceTime(1)*60 + FloatReferenceTime(2);  % OB 2017 03 05 convert [hh mm] to [minutes]
shifttime = sum(windowstart)./length(windowstart) + FloatReferenceTime; % in minutes  % OB 2017 03 05 added last summand
sosoreftime = sosoreftime(1)*60 + sosoreftime(2); % in minutes
timeshift = (shifttime - sosoreftime); % positive if soso ponged before reftime, 
									   % negative if soso ponged after reftime.
adjfraction = timeshift./1440; % timeshift/num minutes perday

% simulshiftTOA = toa + adjfraction*(d(toa)/d(t)), provided d(t) is sampling interval
% I want to avoid calculating the correction over a period of time > samplerate.
if timeshift ~= 0 % if shift necessary, then proceed ...
	for m = 1:(length(toa_date)-1) % forward differencing method - no shift to end points.
        %next line changed by G. Roudaut 04/08/2005 to get ride of roundoff errors
		%if diffdate(m)==sampl_int % else a single or segment end point; leave TOA unchanged
		if abs(diffdate(m)-sampl_int) < (sampl_int/10) % else a single or segment end point; leave TOA unchanged
            sstoa(m) = toa(m) + adjfraction*(difftoa(m)/sampl_int);
		end
		% if point does not qualify for date restrictions then a stand-alone point,
		% and should remain unchanged.
    
    end
end

toa=sstoa;