Home > . > simparse.m

simparse

PURPOSE ^

SIMPARSE - parse simId string for needed signal information

SYNOPSIS ^

function [id, f, tau, dur] = simparse(simId)

DESCRIPTION ^

 SIMPARSE - parse simId string for needed signal information

 [id, f, tau, dur] = simparse(simId);

 simId         string containing signal information
               N.B. Must be '~' or '_' delimited

 id            string desribing type of signal
 f             frequency of signal
 tau           width of Gaussian
 dur           signal duration in seconds

 SEE ALSO: MAKEH

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [id, f, tau, dur] = simparse(simId)
0002 
0003 % SIMPARSE - parse simId string for needed signal information
0004 %
0005 % [id, f, tau, dur] = simparse(simId);
0006 %
0007 % simId         string containing signal information
0008 %               N.B. Must be '~' or '_' delimited
0009 %
0010 % id            string desribing type of signal
0011 % f             frequency of signal
0012 % tau           width of Gaussian
0013 % dur           signal duration in seconds
0014 %
0015 % SEE ALSO: MAKEH
0016 
0017 % $Id: simparse.m,v 1.6 2004/04/29 21:35:46 stuver Exp $
0018 
0019 % FIND indicies of delimiters in simId
0020 % CHECK to make sure the correct number delimiters where found
0021 % ASSIGN variables by the location of the delimiter
0022 % CHECK variables for errors
0023 
0024 [id, f, tau, dur] = deal([]);
0025 
0026 I = find(simId == '~' | simId == '_');
0027 
0028 errorcheck(simId, I)
0029 
0030 % The simulation type string is the information before the first
0031 % delimiter
0032 id = simId(1:I(1)-1);  
0033 
0034 % The frequency is the information between the first delimiter and the
0035 % second
0036 f = simId(I(1)+1:I(2)-1); % Frequency (string)
0037 f = str2num(f); % Convert string into number
0038 % Check for errors (f must be a positive finite number)
0039 if f < 0 | isinf(f) | isnan(f) | ~isreal(f)
0040     f
0041     error('simparse: f must be a real positive finite number')
0042 end
0043 
0044 % The tau is the information between the second delimiter and the last
0045 tau = simId(I(2)+1:I(3)-1); % tau (string)
0046 tau = str2num(tau); % Convert string into number
0047 % Check for errors (tau must be a positive finite number)
0048 if tau < 0 | isinf(tau) | isnan(tau) | ~isreal(tau)
0049     tau
0050     error('simparse: tau must be a real positive finite number')
0051 end
0052 
0053 % The duration is the information after the last delimiter
0054 dur = simId(I(3)+1:end); % Simulation duration (string)
0055 dur = str2num(dur); % Convert string into number
0056 % Check for errors (dur must be a positive finite number)
0057 if dur <= 0 | isinf(dur) | isnan(dur) | ~isreal(dur)
0058     dur
0059     error('simparse: dur must be a real finite number > 0')
0060 end
0061 
0062 return
0063 
0064 % ~~~ END MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0065 
0066 function errorcheck(simId, I)
0067 
0068 % ERRORCHECK - check simId for errors and errors out if one is found
0069 %
0070 % errorcheck(simId, I)
0071 %
0072 % simId     string containing signal information
0073 %           N.B. Must be '~' or '_' delimited
0074 % I         locations of delimiters
0075 
0076 % Check that delimiters where found
0077 if isempty(I)
0078     simId
0079     error('simparse: simId must be ~ delimited or _ delimited')
0080 elseif length(I) ~= 3
0081     % There must be 3 delimiters
0082     simId
0083     error('simparse: There must be 3 delimiters in simId')
0084 end
0085 
0086 spacing = diff(I);
0087 
0088 % Delimiter 1 and 2 are consecutive
0089 if spacing(1) == 1 
0090     simId
0091     error('simparse: Delimiter 1 and 2 are consecutive')
0092 elseif spacing(2) == 1 
0093     % Delimiter 2 and 3 are consecutive
0094     simId
0095     error('simparse: Delimiter 2 and 3 are consecutive')
0096 end
0097 
0098 if I(1) == 1 
0099     % There is a delimiter at the begining of simId
0100     simId
0101     error('simparse: There is a delimiter at the begining of simId')
0102 elseif I(end) == length(simId) 
0103     % There is a delimiter at the end of simId
0104     simId
0105     error('simparse: There is a delimiter at the end of simId')
0106 end
0107 
0108 return

Generated on Tue 05-Oct-2004 10:40:50 by m2html © 2003