


--------------------------------------------------------------------
Copyright (C) J. V. Mansbridge, CSIRO, january 23 1992
Revision $Revision: 1.2 $
CHANGE 1.3 92/04/03
function pos = check_string(name, string, n)
DESCRIPTION:
This function checks whether the character string stored in 'name' is
stored as a row in the matrix named 'string'. It is assumed that
each row in 'string' is completed with blank fill if this is
necessary.
INPUT:
name: is a string of characters that we are searching for in the
array 'string'. It does not have blank fill at the end.
string: is an array where each row is a string which may have blank
fill at the end.
n: is the number of rows in the array 'string'.
OUTPUT:
pos is the index giving the position of name within the string.
pos = -1 if the name is not found within the string.
EXAMPLE:
pos = check_string('fred', string, 4)
where string = [ 'jim ' ; 'john ' ; 'janet ' ; 'fred ' ]
CALLER: getcdf.m, getcdf_batch.m
CALLEE: none
AUTHOR: J. V. Mansbridge, CSIRO
---------------------------------------------------------------------

0001 function pos = check_string(name, string, n) 0002 0003 %-------------------------------------------------------------------- 0004 % Copyright (C) J. V. Mansbridge, CSIRO, january 23 1992 0005 % Revision $Revision: 1.2 $ 0006 % CHANGE 1.3 92/04/03 0007 % 0008 % function pos = check_string(name, string, n) 0009 % 0010 % DESCRIPTION: 0011 % This function checks whether the character string stored in 'name' is 0012 % stored as a row in the matrix named 'string'. It is assumed that 0013 % each row in 'string' is completed with blank fill if this is 0014 % necessary. 0015 % 0016 % INPUT: 0017 % name: is a string of characters that we are searching for in the 0018 % array 'string'. It does not have blank fill at the end. 0019 % string: is an array where each row is a string which may have blank 0020 % fill at the end. 0021 % n: is the number of rows in the array 'string'. 0022 % 0023 % OUTPUT: 0024 % pos is the index giving the position of name within the string. 0025 % pos = -1 if the name is not found within the string. 0026 % 0027 % EXAMPLE: 0028 % pos = check_string('fred', string, 4) 0029 % where string = [ 'jim ' ; 'john ' ; 'janet ' ; 'fred ' ] 0030 % CALLER: getcdf.m, getcdf_batch.m 0031 % CALLEE: none 0032 % 0033 % AUTHOR: J. V. Mansbridge, CSIRO 0034 %--------------------------------------------------------------------- 0035 0036 % @(#)check_string.m 1.3 92/04/03 0037 % Copyright (C), J.V. Mansbridge, 0038 % Commonwealth Scientific and Industrial Research Organisation 0039 % Revision $Revision: 1.2 $ 0040 % Author $Author: mansbrid $ 0041 % Date $Date: 93/06/23 18:33:39 $ 0042 % RCSfile $RCSfile: check_string.m,v $ 0043 % 0044 %-------------------------------------------------------------------- 0045 0046 pos = -1; 0047 le_name = length(name); 0048 [ row_num le_string ] = size(string); 0049 for i = 1:n 0050 temp_name = string(i, :); 0051 limit = le_string; 0052 while ( strcmp(temp_name(limit), ' ') & limit > 1 ) 0053 limit = limit - 1; 0054 end 0055 ans = strcmp(name, temp_name(1:limit)); 0056 if ans == 1 0057 pos = i; 0058 return 0059 end 0060 end