-
Notifications
You must be signed in to change notification settings - Fork 46
/
EpochTT.m
96 lines (92 loc) · 3.35 KB
/
EpochTT.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
classdef EpochTT < GenericTimeArray
%EpochTT Class representing TT epoch (CDF TT2000), nanoseconds since 2000.
%
% EpochTT(t) - initialize class, where t can be:
% - vector of number (double) of seconds since TT2000 epoch
% - vector of integer number (int64) of nanoseconds as TT2000
% - UTC string array
% ----------------------------------------------------------------------------
% SPDX-License-Identifier: Beerware
% "THE BEER-WARE LICENSE" (Revision 42):
% <[email protected]> wrote this file. As long as you retain this notice you
% can do whatever you want with this stuff. If we meet some day, and you think
% this stuff is worth it, you can buy me a beer in return. Yuri Khotyaintsev
% ----------------------------------------------------------------------------
methods
function obj = EpochTT(inp)
if nargin==0, return, end
if isa(inp,'double')
if min(size(inp))>1
error('irf:EpochTT:EpochTT:badInputs',...
'input must be a column or row vector')
end
obj.epoch = int64(inp(:)*1e9); % column vector
elseif isa(inp,'int64')
if min(size(inp))>1
error('irf:EpochTT:EpochTT:badInputs',...
'int64 input (nanoseconds since 2000) must be a column or row vector')
end
obj.epoch = inp(:); % column vector
elseif isa(inp,'char')
if ~GenericTimeArray.validate_utc(inp)
error('irf:EpochUnix:EpochUnix:badInputs',...
'UTC string input (char) must be in the form yyyy-mm-ddThh:mm:ss.mmmuuunnnZ')
end
obj.epoch = GenericTimeArray.utc2ttns(inp);
elseif isa(inp,'string')
if ~GenericTimeArray.validate_utc(inp)
error('irf:EpochUnix:EpochUnix:badInputs',...
'UTC string input (string) must be in the form yyyy-mm-ddThh:mm:ss.mmmuuunnnZ')
end
obj.epoch = GenericTimeArray.utc2ttns(inp);
elseif isa(inp,'GenericTimeArray')
if isa(inp,'EpochTT')
obj = inp;
else
obj = EpochTT(inp.ttns);
end
else
error('irf:EpochUnix:EpochUnix:badInputs',...
'Expected inputs: int64 (nanoseconds since 2000), double (seconds since 1970) or char (yyyy-mm-ddThh:mm:ss.mmmuuunnnZ)')
end
end
function objOut = plus(obj,arg)
if isnumeric(arg)
if isa(arg,'double')
inp = int64(arg*1e9);
elseif isa(arg,'int64')
inp = arg;
else
error('Input type not defined');
end
objOut = obj;
objOut.epoch = obj.epoch + inp(:);
end
end
function outObj = colon(obj,varargin)
if nargin == 2 && isa(varargin{1},'EpochTT')
tns = obj.start.ttns:int64(1e9):varargin{1}.stop.ttns;
outObj = EpochTT(tns);
elseif nargin == 3 && isa(varargin{2},'EpochTT') && isnumeric(varargin{1})
tns = obj.start.ttns:int64(varargin{1}*1e9):varargin{2}.stop.ttns;
outObj = EpochTT(tns);
end
end
end
methods (Static)
function output = from_ttns(input,index) % for consistency with other GenericTimeArray routines
if nargin == 1
output = input;
else
output = input(index);
end
end
function output = to_ttns(input,index)
if nargin == 1
output = input;
else
output = input(index);
end
end
end
end