Home > classes > @ao > split.m

split

PURPOSE ^

SPLIT split an analysis object into the specified segments.

SYNOPSIS ^

function bo = split(varargin)

DESCRIPTION ^

 SPLIT split an analysis object into the specified segments.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SPLIT split an analysis object into the specified segments.

 CALL:        b = split(a, pl)

 INPUTS:      a  - input analysis object
              pl - input parameter list (see below for parameters)

 OUTPUTS:      b  - array of analysis objects

 PARAMETERS: <key>         <value>        <description>
             'split_type'  'times'        split the ao into time segments
                           'frequencies'  split the ao into frequencies segments
                           'samples'      split the ao into sample segments
                           'chunks'       split the ao into chunks
                           'duration'     select a duration of a tsdata

 Necessary for the individual split types:
             <split type>  <key>         <description>
             'times'       'times'       an array of start/stop times to split by
             'frequencies' 'frequencies' an array of start/stop frequencies to split by
             'samples'     'samples'     an array of start/stop samples to split by
             'chunks'      'N'           split into N contiguous pieces
             'interval'    'start_time', 'stop_time'
                           - start/stop time can be either a string or a time
                             object (if a string, 'format_str' must be
                             specified or specify the strings in UTC time format)
             'interval'    'start_time', 'duration'
                           - start time and the duration can be either a string
                             or a time object (if a string, 'format_str' must be
                             specified or specify the strings in UTC time format)
             'interval'    'timespan'
                           - the start/end time are specified in the time span
                             object.

              The UTC time format is: 'yyyy-mm-dd HH:MM:SS'

              If more than one splitting method is specified, the priority
              goes like the list above.

              The time vector in the output AO retains the original
              time values (i.e. it doesn't start from zero).

              The splitting is done as  s<=t<e.

              Arrays of start/stop values should be like: [s1 e1 s2 e2 ....]

 EXAMPLES:    1.) Split method by frequency. Get the values from 10-100 Hz
                  pl = plist('split_type', 'frequencies', ...
                             'frequencies', [10 100]);
                  ao_new = split(a1, pl);

              2.) Split method by time.
                  Get the values from 0.0 to 1.0 Seconds AND from 1.0 to 2.5 seconds
                  pl = plist('split_type', 'times', ...
                             'times',        [0.0 1.0 1.0 2.5]);
                  ao_new = split(a1, pl);

              3.) Split method by samples.
                  Get the samples from 0 to 50 AND from 150 to 200.
                  pl = plist('split_type', 'samples', ...
                             'samples',     [0 50 150 200]);
                  ao_new = split(a1, pl);

              4.1) Select an interval with strings
                   pl = plist('split_type', 'interval', ...
                              'start_time', '14:00:01', ...
                              'end_time',   '14:00:02', ...
                              'format_str', 'HH:MM:SS');
                   ao_new = split(a1, pl);

                   pl = plist('split_type', 'interval', ...
                              'start_time', '14:00:01', ...
                              'duration',   '00:00:02', ...
                              'format_str', 'HH:MM:SS');
                   ao_new = split(a1, pl);

              4.2) Select an interval with time objects
                   pl = plist('split_type', 'interval', ...
                              'start_time', time('14:00:01', 'HH:MM:SS'), ...
                              'end_time',   time('2007-10-10 14:00:03'));
                   ao_new = split(a1, pl);

                   pl = plist('split_type', 'interval', ...
                              'start_time', time('14:00:01', 'HH:MM:SS'), ...
                              'duration',   time('00:00:05', 'HH:MM:SS'));
                   ao_new = split(a1, pl);

              4.3) Select an interval with a time span object
                   pl = plist('split_type', 'interval', ...
                              'timespan', timespan('14:00:00', '14:00:05', 'HH:MM:SS'));
                   ao_new = split(a1, pl);

              The following call returns a parameter list object that
              contains the default parameter values:
              >> pl = split(ao, 'Params')
              The following call returns a string that contains the routine
              CVS version:
              >> version = foo(ao,'Version')

              The following call returns a string that contains the
              routine category:
              >> category = foo(ao,'Category')

 VERSION:     $Id: split.html,v 1.14 2008/03/31 10:27:34 hewitson Exp $

 HISTORY: 02-03-07 M Hewitson
            Creation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function bo = split(varargin)
0002 % SPLIT split an analysis object into the specified segments.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SPLIT split an analysis object into the specified segments.
0007 %
0008 % CALL:        b = split(a, pl)
0009 %
0010 % INPUTS:      a  - input analysis object
0011 %              pl - input parameter list (see below for parameters)
0012 %
0013 % OUTPUTS:      b  - array of analysis objects
0014 %
0015 % PARAMETERS: <key>         <value>        <description>
0016 %             'split_type'  'times'        split the ao into time segments
0017 %                           'frequencies'  split the ao into frequencies segments
0018 %                           'samples'      split the ao into sample segments
0019 %                           'chunks'       split the ao into chunks
0020 %                           'duration'     select a duration of a tsdata
0021 %
0022 % Necessary for the individual split types:
0023 %             <split type>  <key>         <description>
0024 %             'times'       'times'       an array of start/stop times to split by
0025 %             'frequencies' 'frequencies' an array of start/stop frequencies to split by
0026 %             'samples'     'samples'     an array of start/stop samples to split by
0027 %             'chunks'      'N'           split into N contiguous pieces
0028 %             'interval'    'start_time', 'stop_time'
0029 %                           - start/stop time can be either a string or a time
0030 %                             object (if a string, 'format_str' must be
0031 %                             specified or specify the strings in UTC time format)
0032 %             'interval'    'start_time', 'duration'
0033 %                           - start time and the duration can be either a string
0034 %                             or a time object (if a string, 'format_str' must be
0035 %                             specified or specify the strings in UTC time format)
0036 %             'interval'    'timespan'
0037 %                           - the start/end time are specified in the time span
0038 %                             object.
0039 %
0040 %              The UTC time format is: 'yyyy-mm-dd HH:MM:SS'
0041 %
0042 %              If more than one splitting method is specified, the priority
0043 %              goes like the list above.
0044 %
0045 %              The time vector in the output AO retains the original
0046 %              time values (i.e. it doesn't start from zero).
0047 %
0048 %              The splitting is done as  s<=t<e.
0049 %
0050 %              Arrays of start/stop values should be like: [s1 e1 s2 e2 ....]
0051 %
0052 % EXAMPLES:    1.) Split method by frequency. Get the values from 10-100 Hz
0053 %                  pl = plist('split_type', 'frequencies', ...
0054 %                             'frequencies', [10 100]);
0055 %                  ao_new = split(a1, pl);
0056 %
0057 %              2.) Split method by time.
0058 %                  Get the values from 0.0 to 1.0 Seconds AND from 1.0 to 2.5 seconds
0059 %                  pl = plist('split_type', 'times', ...
0060 %                             'times',        [0.0 1.0 1.0 2.5]);
0061 %                  ao_new = split(a1, pl);
0062 %
0063 %              3.) Split method by samples.
0064 %                  Get the samples from 0 to 50 AND from 150 to 200.
0065 %                  pl = plist('split_type', 'samples', ...
0066 %                             'samples',     [0 50 150 200]);
0067 %                  ao_new = split(a1, pl);
0068 %
0069 %              4.1) Select an interval with strings
0070 %                   pl = plist('split_type', 'interval', ...
0071 %                              'start_time', '14:00:01', ...
0072 %                              'end_time',   '14:00:02', ...
0073 %                              'format_str', 'HH:MM:SS');
0074 %                   ao_new = split(a1, pl);
0075 %
0076 %                   pl = plist('split_type', 'interval', ...
0077 %                              'start_time', '14:00:01', ...
0078 %                              'duration',   '00:00:02', ...
0079 %                              'format_str', 'HH:MM:SS');
0080 %                   ao_new = split(a1, pl);
0081 %
0082 %              4.2) Select an interval with time objects
0083 %                   pl = plist('split_type', 'interval', ...
0084 %                              'start_time', time('14:00:01', 'HH:MM:SS'), ...
0085 %                              'end_time',   time('2007-10-10 14:00:03'));
0086 %                   ao_new = split(a1, pl);
0087 %
0088 %                   pl = plist('split_type', 'interval', ...
0089 %                              'start_time', time('14:00:01', 'HH:MM:SS'), ...
0090 %                              'duration',   time('00:00:05', 'HH:MM:SS'));
0091 %                   ao_new = split(a1, pl);
0092 %
0093 %              4.3) Select an interval with a time span object
0094 %                   pl = plist('split_type', 'interval', ...
0095 %                              'timespan', timespan('14:00:00', '14:00:05', 'HH:MM:SS'));
0096 %                   ao_new = split(a1, pl);
0097 %
0098 %              The following call returns a parameter list object that
0099 %              contains the default parameter values:
0100 %              >> pl = split(ao, 'Params')
0101 %              The following call returns a string that contains the routine
0102 %              CVS version:
0103 %              >> version = foo(ao,'Version')
0104 %
0105 %              The following call returns a string that contains the
0106 %              routine category:
0107 %              >> category = foo(ao,'Category')
0108 %
0109 % VERSION:     $Id: split.html,v 1.14 2008/03/31 10:27:34 hewitson Exp $
0110 %
0111 % HISTORY: 02-03-07 M Hewitson
0112 %            Creation.
0113 
0114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0115 
0116 ALGONAME = 'split';
0117 VERSION  = '$Id: split.html,v 1.14 2008/03/31 10:27:34 hewitson Exp $';
0118 CATEGORY = 'Signal Processing';
0119 
0120 bo       = [];
0121 
0122 % Check if this is a call for parameters
0123 if nargin == 2
0124   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0125     in = char(varargin{2});
0126     if strcmp(in, 'Params')
0127       bo = getDefaultPL();
0128       return
0129     elseif strcmp(in, 'Version')
0130       bo = VERSION;
0131       return
0132     elseif strcmp(in, 'Category')
0133       bo = CATEGORY;
0134       return
0135     end
0136   end
0137 end
0138 
0139 %% Collect input ao's, plist's and ao variable names
0140 in_names = {};
0141 for ii = 1:nargin
0142   in_names{end+1} = inputname(ii);
0143 
0144   if isnumeric(varargin{ii})
0145     samples = [samples varargin{ii}];
0146   end
0147 end
0148 
0149 [as, pl, invars] = collect_inputs(varargin, in_names);
0150 
0151 if ~isempty (pl)
0152   pl = combine(pl);
0153 end
0154 
0155 %% go through analysis objects
0156 for j=1:numel(as)
0157 
0158   % Unpack parameter list
0159   split_type = find(pl, 'split_type');
0160 
0161   % check old version without the key 'split_type'
0162   if ~isempty(find(pl, 'samples'))
0163     split_type = 'samples';
0164   elseif ~isempty(find(pl, 'times')) || ...
0165       ~isempty(find(pl, 'frequencies'))
0166     split_type = 'times';  % times is the same to frequencies
0167   end
0168 
0169   if isempty(split_type)
0170     error('### please specify the key ''split_type'' in the parameter list');
0171   end
0172 
0173   % look at input data
0174   d = as(j).data;
0175 
0176   [x,y] = get_xy_values(as(j).data);
0177 
0178   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0179   %                       splitting by time or frequency                        %
0180   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0181   if strcmpi(split_type, 'times') || strcmpi(split_type, 'frequencies')
0182 
0183     times       = find(pl, 'times');
0184     frequencies = find(pl, 'frequencies');
0185 
0186     if ~isempty(times)
0187       disp('* splitting by time...');
0188       split_x_axis.type  = 'times';
0189       split_x_axis.value =  times;
0190     else
0191       disp('* splitting by frequency...');
0192       split_x_axis.type  = 'frequencies';
0193       split_x_axis.value =  frequencies;
0194     end
0195 
0196     % examine time list
0197     ntimes = length(split_x_axis.value);
0198     if mod(ntimes, 2) ~= 0
0199       error('### please specify a start and stop for each interval.')
0200     end
0201 
0202     % go over each interval now
0203     for i=1:2:ntimes
0204 
0205       is = split_x_axis.value(i);
0206       ie = split_x_axis.value(i+1);
0207       idx = find(x>=is & x <ie);
0208 
0209       % create new output data
0210       d.x = x(idx);
0211       d.y = y(idx);
0212       d.name = sprintf('split(%s)', d.name);
0213 
0214       % create new output history
0215       h = history(ALGONAME, VERSION, plist(param(split_x_axis.type, [is ie])), as(j).hist);
0216       h.invars = invars(j);
0217 
0218       % Set nsecs for tsdata
0219       if isa(d, 'tsdata')
0220         if ~isempty(d.x)
0221           d.nsecs = d.x(end) - d.x(1) + 1/d.fs;
0222         else
0223           d.nsecs = 0;
0224         end
0225       end
0226 
0227       % make output analysis object
0228       b = ao(d, h);
0229 
0230       % set name
0231       b.name = sprintf('split(%s)', invars{j});
0232 
0233       % Add to output array
0234       bo = [bo b];
0235 
0236     end
0237 
0238     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0239     %                            splitting by samples                             %
0240     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0241   elseif strcmpi(split_type, 'samples')
0242 
0243     disp('* splitting by samples...');
0244 
0245     samples = find(pl, 'samples');
0246 
0247     % examine time list
0248     npairs = length(samples);
0249     if mod(npairs, 2) ~= 0
0250       error('### please specify a start and stop for each interval.')
0251     end
0252 
0253     % check data
0254     if length(x) ~= length(y) && ~isempty(x)
0255       error('### Something is wrong with the x/y vectors. I can''t split this data.');
0256     end
0257 
0258     % go over each interval now
0259     disp(sprintf('Split: \f'));
0260     c = 1;
0261     dtmp = d;
0262     dtmp.x = [];
0263     dtmp.y = [];
0264     for i=1:2:npairs
0265 
0266       disp(sprintf('\b%03d  ', round(c)));
0267       if mod(c,11) == 0 && c < npairs
0268         disp(sprintf('Chunk: \f'));
0269       end
0270       is = samples(i);
0271       ie = samples(i+1);
0272 
0273       % create new output data
0274       if ~isempty(x)
0275         x1 = x(is:ie);
0276       else
0277         x1 = [];
0278       end
0279       y1 = y(is:ie);
0280       % subtract offset of x for tsdata
0281       % - we record this info by chaging t0
0282       if isa(d, 'tsdata')
0283         d.x = x1-x1(1);
0284       else
0285         d.x = x1;
0286       end
0287       d.y = y1;
0288       d.name = sprintf('split(%s)[%d]', dtmp.name, c);
0289 
0290       % set t0,nsecs if this is tsdata
0291       if isa(d, 'tsdata')
0292         t0 = dtmp.t0 + x1(1);
0293         d.t0  = t0;
0294         d.nsecs = length(y1) ./ dtmp.fs;
0295       end
0296 
0297       % create new output history
0298       h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as(j).hist);
0299       h.invars = invars;
0300 
0301       % make output analysis object
0302       b = ao(d, h);
0303 
0304       % set name
0305       b.name = sprintf('split(%s)[%d]', invars{j}, c);
0306 
0307       % Add to output array
0308       bo = [bo b];
0309       c = c + 1;
0310     end
0311 
0312     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0313     %                            splitting into chunks                            %
0314     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0315   elseif strcmpi(split_type, 'chunks')
0316 
0317     N = find(pl, 'N');
0318 
0319     disp(sprintf('* splitting into %d chunks', N));
0320 
0321     % chunk size
0322     csize = floor(length(y)/N);
0323 
0324     % generate list of indices
0325     idx = [];
0326     for kk=1:N
0327       is = 1+(kk-1)*csize;
0328       ie = csize*kk;
0329       idx = [idx is ie];
0330     end
0331 
0332     % one call to split with these samples
0333     b = split(as, plist('split_type', 'samples', 'samples', idx));
0334     bo = [bo b];
0335     return
0336 
0337     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0338     %                           splitting into interval                           %
0339     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0340   elseif strcmpi(split_type, 'interval')
0341 
0342     %% get values from the parameter list
0343     duration   = find(pl, 'duration');
0344     start_time = find(pl, 'start_time');
0345     end_time   = find(pl, 'end_time');
0346     format_str = find(pl, 'format_str');
0347     timespan   = find(pl, 'timespan');
0348 
0349     %%%%%%%%%%%%%%%%%%%%%%%%   Convert the time object   %%%%%%%%%%%%%%%%%%%%%%%%
0350     if ~isempty(start_time) && isa(start_time, 'time')
0351       if ~isempty(format_str)
0352         start_time = set(start_time, 'timeformat', format_str);
0353       else
0354         format_str = char(start_time.timeformat);
0355       end
0356       %     format_str = char(start_time.timeformat);
0357       start_time = char(start_time);
0358     end
0359 
0360     if ~isempty(end_time) && isa(end_time, 'time')
0361       if ~isempty(format_str)
0362         end_time = set(end_time, 'timeformat', format_str);
0363       else
0364         format_str = char(end_time.timeformat);
0365       end
0366       %     format_str = char(end_time.timeformat);
0367       end_time   = char(end_time);
0368     end
0369 
0370     if ~isempty(duration) && isa(duration, 'time')
0371       if ~isempty(format_str)
0372         duration = set(duration, 'timeformat', format_str);
0373       else
0374         format_str = char(duration.timeformat);
0375       end
0376       %     format_str = char(end_time.timeformat);
0377       duration   = char(duration);
0378     end
0379 
0380     %%%%%%%%%%%%%%%%%%%%%   Convert the time span object   %%%%%%%%%%%%%%%%%%%%%%
0381     if ~isempty(timespan)
0382       start_time = char(timespan.start);
0383       end_time   = char(timespan.end);
0384       format_str = char(timespan.timeformat);
0385       duration   = '';
0386     end
0387 
0388     UTC = false;
0389 
0390     %% check the input values
0391     if ~isa(as(j).data, 'tsdata')
0392       error ('### the split type: ''duration'' only works with tsdata.')
0393     end
0394 
0395     if (isempty(start_time) && ...
0396         (isempty(duration) || isempty(end_time)))
0397       error ('### please specify the key ''start_time'' AND ''end_stime'' OR ''duration'' in the parameter list')
0398     end
0399 
0400     if (ischar(start_time) ||     ...
0401         ischar(end_time)   ||     ...
0402         ischar(duration)     ) && ...
0403         isempty(format_str)
0404       %% are the time strings in UTC (yyy-mm-dd HH:MM:SS)
0405       %% then set the format string to the UTC format.
0406       if isUTCformat(start_time) || ...
0407           isUTCformat(end_time)   || ...
0408           isUTCformat(duration)
0409         format_str = 'yyyy-mm-dd HH:MM:SS';
0410       else
0411         error ([char (10) '### please specify the key ''format_str'' for the keys ' ...
0412           '''start_time'', ''end_time'' OR/AND ''duration'''])
0413       end
0414     end
0415 
0416     disp('* splitting by interval ...');
0417 
0418     %% convert the start time
0419     if isUTCformat(start_time)
0420       UTC = true;
0421       start_time = time(start_time);
0422       start_time = start_time.utc_epoch_milli/1000;
0423     elseif ischar (start_time)
0424       start_time = getSeconds(start_time, format_str);
0425     end
0426 
0427     %% convert the end time
0428     if isUTCformat(end_time)
0429       UTC = true;
0430       end_time = time(end_time);
0431       end_time = end_time.utc_epoch_milli/1000;
0432     elseif ischar (end_time)
0433       end_time = getSeconds(end_time, format_str);
0434     end
0435 
0436     %% convert the duration
0437     if ~isempty(end_time) && ~isempty(duration)
0438       warning (['### in the parameter list are both parameter '...
0439         '''end_time'' and ''duration''. Using the parameter ''end_time'''])
0440     elseif ischar(duration) && ~isempty(duration)
0441       duration = getSeconds(duration, format_str);
0442     end
0443 
0444     %% get/convert the t0
0445     t0 = as(j).data.t0;
0446     t_unix_time = t0.utc_epoch_milli/1000;
0447     t1 = x(1);
0448 
0449     if UTC == true
0450       ts = start_time-t_unix_time+t1;
0451       if ~isempty(end_time)
0452         te = end_time-t_unix_time+t1;
0453       else
0454         te = ts+duration;
0455       end
0456     else
0457 
0458       t0_offset = format(t0, format_str);
0459       t0_offset = getSeconds(t0_offset, format_str);
0460 
0461       ts = start_time+t1-t0_offset;
0462       if ~isempty(end_time)
0463         te = end_time+t1-t0_offset;
0464       else
0465         te = start_time+duration+t1-t0_offset;
0466       end
0467     end
0468 
0469     idx = find(x>=ts & x <te);
0470 
0471     % create new output data
0472     d.x = x(idx);
0473     d.y = y(idx);
0474     d.name = sprintf('split(%s)', d.name);
0475 
0476     % Set nsecs for tsdata
0477     if isa(d, 'tsdata')
0478       if ~isempty(d.x)
0479         d.nsecs = d.x(end) - d.x(1) + 1/d.fs;
0480       else
0481         d.nsecs = 0;
0482       end
0483     end
0484 
0485     % create new output history
0486     h = history(ALGONAME, VERSION, pl, as(j).hist);
0487     h.invars = invars;
0488 
0489     % make output analysis object
0490     b = ao(d, h);
0491 
0492     % set name
0493     b.name = sprintf('split(%s)', invars{j});
0494 
0495     % set the t0 to the value (t0 + b.data.x(1)) and
0496     % the time of first data sample to zero.
0497     if isempty(duration)
0498       duration = end_time - start_time;
0499     end
0500     start_time = find(pl, 'start_time');
0501     b.data.t0 = b.data.t0+b.data.x(1);
0502     b.data.x = b.data.x - b.data.x(1);
0503 
0504     % Add to output array
0505     bo = [bo b];
0506 
0507 
0508   else
0509     error('### do not know how to split.')
0510   end
0511 
0512 end % for j = 1:numel(as)
0513 
0514 % Reshape the ouput to the same size of the input
0515 if numel(bo) == numel(as)
0516   bo = reshape(bo, size(as));
0517 end
0518 
0519 end % split
0520 
0521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0522 %
0523 % FUNCTION:    getDefaultPL
0524 %
0525 % DESCRIPTION: Returns the default parameter list
0526 %
0527 % HISTORY:     02-03-07 M Hewitson
0528 %                Creation.
0529 %
0530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0531 
0532 function plo = getDefaultPL()
0533 
0534   plo = plist();
0535   plo = append(plo, param('split_type',  ''));
0536   plo = append(plo, param('times',       []));
0537   plo = append(plo, param('frequencies', []));
0538   plo = append(plo, param('samples',     []));
0539   plo = append(plo, param('N',           []));
0540   plo = append(plo, param('duration',    ''));
0541   plo = append(plo, param('start_time',  ''));
0542   plo = append(plo, param('end_time',    ''));
0543   plo = append(plo, param('format_str',  ''));
0544 
0545 end % getDefaultPL
0546 
0547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0548 %
0549 % FUNCTION:    isUTCformat
0550 %
0551 % DESCRIPTION: Check the input to the UTC time format (yyyy-mm-dd- HH:MM:SS)
0552 %
0553 % HISTORY:     11-07-07 Diepholz
0554 %                Creation.
0555 %
0556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0557 
0558 function bool = isUTCformat(time_string)
0559 
0560   bool = false;
0561 
0562   if ischar(time_string)
0563     if regexp(time_string, '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}')
0564       bool = true;
0565     end
0566   end
0567 
0568 end % isUTCformat
0569 
0570 
0571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0572 %
0573 % FUNCTION:    getSeconds
0574 %
0575 % DESCRIPTION: Returns the seconds for any time format with hours minutes
0576 %              ans seconds.
0577 %
0578 % HISTORY:     11-07-07 Diepholz
0579 %                Creation.
0580 %
0581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0582 
0583 function sec = getSeconds(time_str, format_str)
0584 
0585   % The customer use year, month or day to specify the time_str
0586   if regexp(format_str, '[ymd]')
0587     if ~strcmp('yyyy-mm-dd HH:MM:SS', format_str)
0588       error (['### if you want to specify the time without using the UTC time '...
0589         'use only hours(HH) minutes(MM) and seconds(SS)'])
0590     end
0591   end
0592 
0593   try
0594     sec = ( datenum(time_str, format_str) - fix(datenum(time_str, format_str)) ) * 86400;
0595     sec = round(sec*1000)/1000;
0596   catch
0597     last_error = lasterror;
0598     if strfind(last_error.identifier, 'datenum')
0599       error ([last_error.message char(10) char(10) ...
0600         'time_str = ''' time_str ''' format string = ''' format_str ''''])
0601     else
0602       error (last_error.message)
0603     end
0604   end
0605 
0606 end % getSeconds

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003