Skip to content

Commit

Permalink
new importer merged with trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkacigler committed Sep 9, 2011
0 parents commit 964d8cb
Show file tree
Hide file tree
Showing 58 changed files with 2,673 additions and 0 deletions.
233 changes: 233 additions & 0 deletions DateTime.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
classdef DateTime
% This class enclapsulates date time value but behaves in a very
% similar way as typical array of timestamps in datenum format
%======================================================================
%{
Copyright (c) 2011
This program is a result of a joined cooperation of Energocentrum
PLUS, s.r.o. and Czech Technical University (CTU) in Prague.
The program is maintained by Energocentrum PLUS, s.r.o. and
licensed under the terms of MIT license. Full text of the license
is included in the program release.
Author(s):
Jiri Cigler, Dept. of Control Engineering, CTU Prague & Automatic Control Laboratory, ETH Zurich
Jan Siroky, Energocentrum PLUS s.r.o.
Implementation and Revisions:
Auth Date Description of change
---- --------- -------------------------------------------------
jc 01-Mar-11 First implementation
%}
%======================================================================

properties
serialDate
end
methods
function this = DateTime(varargin)
if numel(varargin)==1 && isa(varargin{1},'java.util.Date')
this.serialDate=-java.util.Date().getTimezoneOffset()/(60*24)+datenum(char(varargin{1}.toGMTString));
else
this.serialDate=datenum(varargin{:});
end
end
function this = plus(this,val)
o =@plus;
this = doFun(this,o,val);
end
function this = minus(this,val)
o =@minus;
this = doFun(this,o,val);
end
function this = times(this,val)
o =@times;
this = doFun(this,o,val);
end

function this = mtimes(this,val)
o =@mtimes;
this = doFun(this,o,val);
end

function this = mrdivide(this,val)
o =@mrdivide;
this = doFun(this,o,val);
end

function this = rdivide(this,val)
o =@rdivide;
this = doFun(this,o,val);
end



function this = horzcat(this,varargin)
%this.serialDate = [this.serialDate, n.serialDate];
for i=1:numel(varargin)
this.serialDate = [this.serialDate, varargin{i}.serialDate];
end
end

function this = vertcat(this,varargin)
for i=1:numel(varargin)
this.serialDate = [this.serialDate; varargin{i}.serialDate];
end
end


function this = ctranspose(this)
this.serialDate = this.serialDate';
end

function this = transpose(this)
this.serialDate = this.serialDate';
end
function disp(this)
disp([this.serialDate])
end
function out = double(this)
out = this.serialDate;
end
function out = length(this)
out = length(this.serialDate);
end

function out = size(this,varargin)
out = size(this.serialDate,varargin{:});
end

function out = numel(this)
out = numel(this.serialDate);
end
function out = isreal(this)
out = isreal(this.serialDate);
end
function out = isnan(this)
out = isnan(this.serialDate);
end
function out = isfinite(this)
out = isfinite(this.serialDate);
end

function out = le(this,B)
if isa(B,'DateTime')
out = le(this.serialDate,B.serialDate);
else
out = le(this.serialDate,B);
end
end

function out = lt(this,B)
fun=@lt;
if isa(B,'DateTime')
out = fun(this.serialDate,B.serialDate);
else
out = fun(this.serialDate,B);
end
end
function out = gt(this,B)
fun=@gt;
if isa(B,'DateTime')
out = fun(this.serialDate,B.serialDate);
else
out = fun(this.serialDate,B);
end
end
function out = eq(this,B)
fun=@eq;
if isa(B,'DateTime')
out = fun(this.serialDate,B.serialDate);
else
out = fun(this.serialDate,B);
end
end
function out = diff(this)
out = diff(this.serialDate);
end

function out = norm(this,varargin)
out = norm(this.serialDate,varargin{:});
end

function [this k] = sort(this,varargin)
[this.serialDate k] = sort(this.serialDate,varargin{:});
end

function this = subsref(this,S)
if isa(S.subs{1},'DateTime')
S.subs{1}=double(S.subs{1});
end

this.serialDate = subsref(this.serialDate,S);
end

function idx = subsindex(this)
idx = double(this)-1;
end

function endidx = end(this,k,n)
if size(this.serialDate,1)==1 || size(this.serialDate,2)==1
endidx=numel(this.serialDate);
else
endidx = size(this.serialDate,k);
end
end

function this = subsasgn(this, S, B)
if not(isa(B,'DateTime'))
B=DateTime(B);
end

this.serialDate =subsasgn(this.serialDate, S, B);
end

function res = bsxfun(fun,A,B)
res = fun(A,B);
end

function out =superiorfloat (x,y,xi)
if isa(x,'DateTime') && isa(xi,'DateTime')
out = superiorfloat(x.serialDate,y,xi.serialDate);
elseif isa(x,'DateTime') && not(isa(xi,'DateTime'))
out = superiorfloat(x.serialDate,y,xi);
elseif not(isa(x,'DateTime')) && isa(xi,'DateTime')
out = superiorfloat(x,y,xi.serialDate);
else
out = superiorfloat(x,y,xi);
end
end

function this = floor(this)
this.serialDate = floor(this.serialDate);
end
function this = max(this,varargin)
this.serialDate = max(this.serialDate,varargin{:});
end
function this = min(this,varargin)
this.serialDate = min(this.serialDate,varargin{:});
end
function out = datestr(this)
out = datestr(this.serialDate);
end
end

methods (Access = private)
function this = doFun (this,o, val)
if isa(val,'DateTime') && isa(this,'DateTime')
this.serialDate=o(this.serialDate, val.serialDate);
elseif isa(val,'DateTime') && not(isa(this,'DateTime'))
val.serialDate=o(this, val.serialDate);
this = val;
elseif not(isa(val,'DateTime')) && (isa(this,'DateTime'))
this.serialDate=o(this.serialDate, val);
else
this.serialDate=DateTime(o(this, val));
end
end


end

end
22 changes: 22 additions & 0 deletions MIT-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2011 CTU in Prague and Energocentrum PLUS s.r.o.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
30 changes: 30 additions & 0 deletions ReadYaml.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%==========================================================================
% Actually reads YAML file and transforms it using several mechanisms:
%
% - Transforms mappings and lists into Matlab structs and cell arrays,
% for timestamps uses DateTime class, performs all imports (when it
% finds a struct field named 'import' it opens file(s) named in the
% field content and substitutes the filename by their content.
% - Deflates outer imports into inner imports - see deflateimports(...)
% for details.
% - Merges imported structures with the structure from where the import
% was performed. This is actually the same process as inheritance with
% the difference that parent is located in a different file.
% - Does inheritance - see doinheritance(...) for details.
% - Makes matrices from cell vectors - see makematrices(...) for details.
%
function result = ReadYaml(filename)
ry = ReadYamlRaw(filename, 0);
ry = deflateimports(ry);
if iscell(ry) && ...
length(ry) == 1 && ...
isstruct(ry{1}) && ...
length(fields(ry{1})) == 1 && ...
isfield(ry{1},'import')
ry = ry{1};
end;
ry = mergeimports(ry);
ry = doinheritance(ry);
ry = makematrices(ry);
result = ry;
end
Loading

0 comments on commit 964d8cb

Please sign in to comment.