/[MITgcm]/MITgcm_contrib/enderton/Diagnostics/ReadVariables.m
ViewVC logotype

Contents of /MITgcm_contrib/enderton/Diagnostics/ReadVariables.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Mon Jan 31 15:43:27 2005 UTC (20 years, 5 months ago) by enderton
Branch: MAIN
CVS Tags: HEAD
 o Initial check in.

1 function varcell = ReadVariables(filename)
2
3 % Function: ReadVariables
4 % Author: Daniel Enderton
5 %
6 % Input Fields:
7 %
8 % Field Type (Brief) Description
9 % -----------------------------------------------------------------------
10 % filename string File name to parse for variables.
11 %
12 % Output Fields:
13 %
14 % Field Type (Brief) Description
15 % -----------------------------------------------------------------------
16 % varcell cell array List of variables in file.
17 %
18 % Descripton:
19 % This function takes a text file (likely Matlab .m file) and parses it,
20 % returning a cell array of all variables in the file where variables are
21 % defined by <variable_name> = <variable_data>. If a line has no equal
22 % signs in it, it will be ignored.
23
24 varcell = {};
25 ivar = 1;
26 fid = fopen(filename,'r');
27 EndFile = 0;
28 while ~EndFile
29 line = fgetl(fid);
30 if ~ischar(line)
31 EndFile = 1;
32 else
33 line = strrep(line,' ','');
34 if length(line) ~= 0
35 if ~isequal(line(1),'%')
36 variablename = line(1:find(line == '=')-1);
37 if length(variablename) > 0
38 varcell{ivar} = variablename;
39 ivar = ivar+1;
40 end
41 end
42 end
43 end
44 end
45 fclose(fid);

  ViewVC Help
Powered by ViewVC 1.1.22