Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/Graphix/GraphixUtility/ReadVariables.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit c578fd6b on 2005-10-20 18:14:57 UTC
c578fd6b1e Dani*0001 function varcell = ReadVariables(filename)
                0002 
                0003 % Function: ReadVariables
                0004 % Author:   Daniel Enderton
                0005 %
                0006 % Input Fields:
                0007 %
                0008 %   Field        Type        (Brief) Description
                0009 %   -----------------------------------------------------------------------
                0010 %   filename     string      File name to parse for variables.
                0011 %
                0012 % Output Fields:
                0013 %
                0014 %   Field        Type        (Brief) Description
                0015 %   -----------------------------------------------------------------------
                0016 %   varcell      cell array  List of variables in file.
                0017 %
                0018 % Descripton:
                0019 %   This function takes a text file (likely Matlab .m file) and parses it,
                0020 %   returning a cell array of all variables in the file where variables are
                0021 %   defined by <variable_name> = <variable_data>.  If a line has no equal
                0022 %   signs in it, it will be ignored.
                0023 
                0024 varcell = {};
                0025 ivar = 1;
                0026 fid = fopen(filename,'r');
                0027 EndFile = 0;
                0028 while ~EndFile
                0029     line = fgetl(fid);
                0030     if ~ischar(line)
                0031         EndFile = 1;
                0032     else
                0033         line = strrep(line,' ','');
                0034         if length(line) ~= 0
                0035             if ~isequal(line(1),'%')
                0036                 variablename = line(1:find(line == '=')-1);
                0037                 if length(variablename) > 0
                0038                     varcell{ivar} = variablename;
                0039                     ivar = ivar+1;
                0040                 end
                0041             end    
                0042         end
                0043     end
                0044 end
                0045 fclose(fid);