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)

 OTPUTS:      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', 'time', ...
                             'time',        [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')

 VERSION:     $Id: split.m,v 1.22 2007/11/02 12:26:24 ingo 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 % OTPUTS:      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', 'time', ...
0060 %                             'time',        [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 %
0102 % VERSION:     $Id: split.m,v 1.22 2007/11/02 12:26:24 ingo Exp $
0103 %
0104 % HISTORY: 02-03-07 M Hewitson
0105 %            Creation.
0106 %
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 
0109 ALGONAME = 'split';
0110 VERSION  = '$Id: split.m,v 1.22 2007/11/02 12:26:24 ingo Exp $';
0111 
0112 % Check if this is a call for parameters
0113 if nargin == 2
0114   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0115     in = char(varargin{2});
0116     if strcmp(in, 'Params')
0117       bo = getDefaultPL();
0118       return
0119     elseif strcmp(in, 'Version')
0120       bo = VERSION;
0121       return
0122     end
0123   end
0124 end
0125 
0126 % Initialise input/output
0127 bo = [];
0128 as = [];
0129 pl = [];
0130 
0131 for i=1:nargin
0132   a = varargin{i};
0133   if isa(a, 'ao')
0134     as  = [as a];
0135   elseif isa(varargin{i}, 'plist')
0136     pl = [pl varargin{i}];
0137   end
0138 end
0139 
0140 if ~isempty (pl)
0141   pl = combine(pl);
0142 end
0143 
0144 % capture input variable names
0145 invars = {};
0146 for j=1:nargin
0147   if isa(varargin{j}, 'ao')
0148     invars = [invars cellstr(inputname(j))];
0149   end
0150 end
0151 
0152 %% go through analysis objects
0153 for j=1:numel(as)
0154 
0155   % Unpack parameter list
0156   split_type = find(pl, 'split_type');
0157 
0158   % check old version without the key 'split_type'
0159   if ~isempty(find(pl, 'samples'))
0160     split_type = 'samples';
0161   elseif ~isempty(find(pl, 'times')) || ...
0162       ~isempty(find(pl, 'frequencies'))
0163     split_type = 'times';  % times is the same to frequencies
0164   end
0165 
0166   if isempty(split_type)
0167     error('### please specify the key ''split_type'' in the parameter list');
0168   end
0169 
0170   % look at input data
0171   d = as(j).data;
0172   % name for this object
0173   if isempty(invars{1})
0174     n1 = as(j).name;
0175   else
0176     n1 = invars{1};
0177   end
0178 
0179   [x,y] = get_xy_values(as(j).data);
0180 
0181   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0182   %                       splitting by time or frequency                        %
0183   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0184   if strcmpi(split_type, 'times') || strcmpi(split_type, 'frequencies')
0185 
0186     times       = find(pl, 'times');
0187     frequencies = find(pl, 'frequencies');
0188 
0189     if ~isempty(times)
0190       disp('* splitting by time...');
0191       split_x_axis.type  = 'times';
0192       split_x_axis.value =  times;
0193     else
0194       disp('* splitting by frequency...');
0195       split_x_axis.type  = 'frequencies';
0196       split_x_axis.value =  frequencies;
0197     end
0198 
0199     % examine time list
0200     ntimes = length(split_x_axis.value);
0201     if mod(ntimes, 2) ~= 0
0202       error('### please specify a start and stop for each interval.')
0203     end
0204 
0205     % go over each interval now
0206     for i=1:2:ntimes
0207 
0208       is = split_x_axis.value(i);
0209       ie = split_x_axis.value(i+1);
0210 
0211       idx = find(x>=is & x <ie);
0212 
0213       % Make output analysis object
0214       nameStr = sprintf('split(%s)', d.name);
0215 
0216       % create new output data
0217       d = set_xy_axis(d, x(idx), y(idx));
0218       d = set(d, 'name', nameStr);
0219 
0220       % create new output history
0221       h = history(ALGONAME, VERSION, plist(param(split_x_axis.type, [is ie])), as(j).hist);
0222       h = set(h, 'invars', invars);
0223 
0224       % Set nsecs for tsdata
0225       if isa(d, 'tsdata')
0226         if ~isempty(d.t)
0227           d.nsecs = d.t(end) - d.t(1) + 1/d.fs;
0228         else
0229           d.nsecs = 0;
0230         end
0231       end
0232 
0233       % make output analysis object
0234       b = ao(d, h);
0235 
0236       % set name
0237       b = setnh(b, 'name', sprintf('split(%s)', n1));
0238 
0239       % Add to output array
0240       bo = [bo b];
0241 
0242     end
0243 
0244     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0245     %                            splitting by samples                             %
0246     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0247   elseif strcmpi(split_type, 'samples')
0248 
0249     disp('* splitting by samples...');
0250 
0251     samples = find(pl, 'samples');
0252 
0253     % examine time list
0254     npairs = length(samples);
0255     if mod(npairs, 2) ~= 0
0256       error('### please specify a start and stop for each interval.')
0257     end
0258 
0259     % go over each interval now
0260     for i=1:2:npairs
0261 
0262       is = samples(i);
0263       ie = samples(i+1);
0264 
0265       % Make output analysis object
0266       nameStr = sprintf('split(%s)', d.name);
0267 
0268       % create new output data
0269       x1 = x(is:ie);
0270       y1 = y(is:ie);
0271       d = set_xy_axis(d, x1, y1);
0272       d = set(d, 'name', nameStr);
0273 
0274       % create new output history
0275       h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as(j).hist);
0276       h = set(h, 'invars', invars);
0277 
0278       % make output analysis object
0279       b = ao(d, h);
0280 
0281       % set name
0282       b = setnh(b, 'name', sprintf('split(%s)', n1));
0283 
0284       % Add to output array
0285       bo = [bo b];
0286 
0287     end
0288 
0289     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0290     %                            splitting into chunks                            %
0291     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0292   elseif strcmpi(split_type, 'chunks')
0293 
0294     N = find(pl, 'N');
0295 
0296     disp(sprintf('* splitting into %d chunks', N));
0297     error('### I have not been written yet. Please code me up.');
0298 
0299     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0300     %                           splitting into interval                           %
0301     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0302   elseif strcmpi(split_type, 'interval')
0303 
0304     %% get values from the parameter list
0305     duration   = find(pl, 'duration');
0306     start_time = find(pl, 'start_time');
0307     end_time   = find(pl, 'end_time');
0308     format_str = find(pl, 'format_str');
0309     timespan   = find(pl, 'timespan');
0310 
0311     %%%%%%%%%%%%%%%%%%%%%%%%   Convert the time object   %%%%%%%%%%%%%%%%%%%%%%%%
0312     if ~isempty(start_time) && isa(start_time, 'time')
0313       if ~isempty(format_str)
0314         start_time = set(start_time, 'timeformat', format_str);
0315       else
0316         format_str = char(start_time.timeformat);
0317       end
0318       %     format_str = char(start_time.timeformat);
0319       start_time = char(start_time);
0320     end
0321 
0322     if ~isempty(end_time) && isa(end_time, 'time')
0323       if ~isempty(format_str)
0324         end_time = set(end_time, 'timeformat', format_str);
0325       else
0326         format_str = char(end_time.timeformat);
0327       end
0328       %     format_str = char(end_time.timeformat);
0329       end_time   = char(end_time);
0330     end
0331 
0332     if ~isempty(duration) && isa(duration, 'time')
0333       if ~isempty(format_str)
0334         duration = set(duration, 'timeformat', format_str);
0335       else
0336         format_str = char(duration.timeformat);
0337       end
0338       %     format_str = char(end_time.timeformat);
0339       duration   = char(duration);
0340     end
0341 
0342     %%%%%%%%%%%%%%%%%%%%%   Convert the time span object   %%%%%%%%%%%%%%%%%%%%%%
0343     if ~isempty(timespan)
0344       start_time = char(timespan.start);
0345       end_time   = char(timespan.end);
0346       format_str = char(timespan.timeformat);
0347       duration   = '';
0348     end
0349 
0350     UTC = false;
0351 
0352     %% check the input values
0353     if ~isa(as(j).data, 'tsdata')
0354       error ('### the split type: ''duration'' only works with tsdata.')
0355     end
0356 
0357     if (isempty(start_time) && ...
0358         (isempty(duration) || isempty(end_time)))
0359       error ('### please specify the key ''start_time'' AND ''end_stime'' OR ''duration'' in the parameter list')
0360     end
0361 
0362     if (ischar(start_time) ||     ...
0363         ischar(end_time)   ||     ...
0364         ischar(duration)     ) && ...
0365         isempty(format_str)
0366       %% are the time strings in UTC (yyy-mm-dd HH:MM:SS)
0367       %% then set the format string to the UTC format.
0368       if isUTCformat(start_time) || ...
0369           isUTCformat(end_time)   || ...
0370           isUTCformat(duration)
0371         format_str = 'yyyy-mm-dd HH:MM:SS';
0372       else
0373         error ([char (10) '### please specify the key ''format_str'' for the keys ' ...
0374           '''start_time'', ''end_time'' OR/AND ''duration'''])
0375       end
0376     end
0377 
0378     disp('* splitting by interval ...');
0379 
0380     %% convert the start time
0381     if isUTCformat(start_time)
0382       UTC = true;
0383       start_time = time(start_time);
0384       start_time = start_time.utc_epoch_milli/1000;
0385     elseif ischar (start_time)
0386       start_time = getSeconds(start_time, format_str);
0387     end
0388 
0389     %% convert the end time
0390     if isUTCformat(end_time)
0391       UTC = true;
0392       end_time = time(end_time);
0393       end_time = end_time.utc_epoch_milli/1000;
0394     elseif ischar (end_time)
0395       end_time = getSeconds(end_time, format_str);
0396     end
0397 
0398     %% convert the duration
0399     if ~isempty(end_time) && ~isempty(duration)
0400       warning (['### in the parameter list are both parameter '...
0401         '''end_time'' and ''duration''. Using the parameter ''end_time'''])
0402     elseif ischar(duration) && ~isempty(duration)
0403       duration = getSeconds(duration, format_str);
0404     end
0405 
0406     %% get/convert the t0
0407     t0 = as(j).data.t0;
0408     t_unix_time = t0.utc_epoch_milli/1000;
0409     t1 = x(1);
0410 
0411     if UTC == true
0412       ts = start_time-t_unix_time+t1;
0413       if ~isempty(end_time)
0414         te = end_time-t_unix_time+t1;
0415       else
0416         te = ts+duration;
0417       end
0418     else
0419 
0420       t0_offset = format(t0, format_str);
0421       t0_offset = getSeconds(t0_offset, format_str);
0422 
0423       ts = start_time+t1-t0_offset;
0424       if ~isempty(end_time)
0425         te = end_time+t1-t0_offset;
0426       else
0427         te = start_time+duration+t1-t0_offset;
0428       end
0429     end
0430 
0431     idx = find(x>=ts & x <te);
0432 
0433     % Make output analysis object
0434     nameStr = sprintf('split(%s)', d.name);
0435 
0436     % create new output data
0437     d = set_xy_axis(d, x(idx), y(idx));
0438     d = set(d, 'name', nameStr);
0439 
0440     % Set nsecs for tsdata
0441     if isa(d, 'tsdata')
0442       if ~isempty(d.t)
0443         d.nsecs = d.t(end) - d.t(1) + 1/d.fs;
0444       else
0445         d.nsecs = 0;
0446       end
0447     end
0448 
0449     % create new output history
0450     h = history(ALGONAME, VERSION, pl, as(j).hist);
0451     h = set(h, 'invars', invars);
0452 
0453     % make output analysis object
0454     b = ao(d, h);
0455 
0456     % set name
0457     b = setnh(b, 'name', sprintf('split(%s)', n1));
0458 
0459     % Add to output array
0460     bo = [bo b];
0461 
0462 
0463   else
0464     error('### do not know how to split.')
0465   end
0466 
0467 end % for j = 1:numel(as)
0468 
0469 % Reshape the ouput to the same size of the input
0470 if numel(bo) == numel(as)
0471   bo = reshape(bo, size(as));
0472 end
0473 
0474 end % split
0475 
0476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0477 %
0478 % FUNCTION:    getDefaultPL
0479 %
0480 % DESCRIPTION: Returns the default parameter list
0481 %
0482 % HISTORY:     02-03-07 M Hewitson
0483 %                Creation.
0484 %
0485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0486 
0487 function plo = getDefaultPL()
0488 
0489   disp('* creating default plist...');
0490   plo = plist();
0491   plo = append(plo, param('split_type',  ''));
0492   plo = append(plo, param('times',       []));
0493   plo = append(plo, param('frequencies', []));
0494   plo = append(plo, param('samples',     []));
0495   plo = append(plo, param('N',           []));
0496   plo = append(plo, param('duration',    ''));
0497   plo = append(plo, param('start_time',  ''));
0498   plo = append(plo, param('end_time',    ''));
0499   plo = append(plo, param('format_str',  ''));
0500   disp('* done.');
0501 
0502 end % getDefaultPL
0503 
0504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0505 %
0506 % FUNCTION:    isUTCformat
0507 %
0508 % DESCRIPTION: Check the input to the UTC time format (yyyy-mm-dd- HH:MM:SS)
0509 %
0510 % HISTORY:     11-07-07 Diepholz
0511 %                Creation.
0512 %
0513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0514 
0515 function bool = isUTCformat(time_string)
0516 
0517   bool = false;
0518 
0519   if ischar(time_string)
0520     if regexp(time_string, '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}')
0521       bool = true;
0522     end
0523   end
0524 
0525 end % isUTCformat
0526 
0527 
0528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0529 %
0530 % FUNCTION:    getSeconds
0531 %
0532 % DESCRIPTION: Returns the seconds for any time format with hours minutes
0533 %              ans seconds.
0534 %
0535 % HISTORY:     11-07-07 Diepholz
0536 %                Creation.
0537 %
0538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0539 
0540 function sec = getSeconds(time_str, format_str)
0541 
0542   % The customer use year, month or day to specify the time_str
0543   if regexp(format_str, '[ymd]')
0544     if ~strcmp('yyyy-mm-dd HH:MM:SS', format_str)
0545       error (['### if you want to specify the time without using the UTC time '...
0546         'use only hours(HH) minutes(MM) and seconds(SS)'])
0547     end
0548   end
0549 
0550   try
0551     sec = ( datenum(time_str, format_str) - fix(datenum(time_str, format_str)) ) * 86400;
0552     sec = round(sec*1000)/1000;
0553   catch
0554     last_error = lasterror;
0555     if strfind(last_error.identifier, 'datenum')
0556       error ([last_error.message char(10) char(10) ...
0557         'time_str = ''' time_str ''' format string = ''' format_str ''''])
0558     else
0559       error (last_error.message)
0560     end
0561   end
0562 
0563 end % getSeconds

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003