Home > mrg > MRG_MIKE > mrg_is_equidistant.m

mrg_is_equidistant

PURPOSE ^

Checks if an object is has an eqidistant timestep.

SYNOPSIS ^

function tf = mrg_is_equidistant(varargin)

DESCRIPTION ^

 Checks if an object is has an eqidistant timestep.

 INPUT
   ...     Either a MATLAB vector or a MATLAB structure.  See NOTES.

 OUTPUT
   tf      A logical (0 or 1) indicating if the object is equidistant.

 REQUIREMENTS
   Requires the MIKE Matlab toolbox.  Tested with v. 20110304

 NOTES
   If a vector is supplied, then a diff() is performed and the check
   proceeds via testing the uniqueness of this diff.  If a structure is
   provided, it is tested to see if it contains a field 'TimeAxisType'.
   If it is we assume it is a structure returned by one of the core MRG
   functions and we test the values the timeaxis type for known equidstant
   values.

 LICENCE
   Created by Daniel Pritchard (www.pritchard.co)
   Distributed under a creative commons CC BY-SA licence. See here:
   http://creativecommons.org/licenses/by-sa/3.0/

 DEVELOPMENT
   v 1.0   2012
           DP. First version
   v 1.1   14/02/2013
           DP. Documentation

 TODO
   Extend to allow for some flexability in timestep diff (e.g. within 1 sec)...
   Migrate other code to use this function
% Check input

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function tf = mrg_is_equidistant(varargin)
0002 % Checks if an object is has an eqidistant timestep.
0003 %
0004 % INPUT
0005 %   ...     Either a MATLAB vector or a MATLAB structure.  See NOTES.
0006 %
0007 % OUTPUT
0008 %   tf      A logical (0 or 1) indicating if the object is equidistant.
0009 %
0010 % REQUIREMENTS
0011 %   Requires the MIKE Matlab toolbox.  Tested with v. 20110304
0012 %
0013 % NOTES
0014 %   If a vector is supplied, then a diff() is performed and the check
0015 %   proceeds via testing the uniqueness of this diff.  If a structure is
0016 %   provided, it is tested to see if it contains a field 'TimeAxisType'.
0017 %   If it is we assume it is a structure returned by one of the core MRG
0018 %   functions and we test the values the timeaxis type for known equidstant
0019 %   values.
0020 %
0021 % LICENCE
0022 %   Created by Daniel Pritchard (www.pritchard.co)
0023 %   Distributed under a creative commons CC BY-SA licence. See here:
0024 %   http://creativecommons.org/licenses/by-sa/3.0/
0025 %
0026 % DEVELOPMENT
0027 %   v 1.0   2012
0028 %           DP. First version
0029 %   v 1.1   14/02/2013
0030 %           DP. Documentation
0031 %
0032 % TODO
0033 %   Extend to allow for some flexability in timestep diff (e.g. within 1 sec)...
0034 %   Migrate other code to use this function
0035 %% Check input
0036 if isempty(varargin)
0037     error('Input is required.');
0038 end
0039 
0040 if length(varargin)>1
0041     error('This function only takes one input.');
0042 end
0043 
0044 object = varargin{1};
0045 
0046 %% Check if object is a standard MRG output...
0047 if (isstruct(object) && isfield(object, 'TimeAxisType'))
0048     if any(strcmp(object.TimeAxisType, {'CalendarEquidistant', 'TimeEquidistant'}))
0049         tf = 1;
0050         return
0051     else
0052         tf = 0;
0053         return
0054     end
0055 end
0056 
0057 %% Object is not a structure, just do a diff
0058 if ndims(object) > 2
0059     error('Unless the input is a structure, this function can only take a 2D MATLAB matrix.');
0060 end
0061 
0062 if ~any(size(object)==1)
0063     error('Unless the input is a structure, this function can only take a MATLAB matrix with either a single row, or a single column.');
0064 end
0065 
0066 diffs = diff(object);
0067 if length(unique(diffs)) == 1
0068     tf = 1;
0069     return
0070 else
0071     tf = 0;
0072     return
0073 end
0074 end

Generated on Thu 29-May-2014 21:29:53 by m2html © 2005