Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/gmt/find_files_grid_first.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
51885b0cf3 Ed H*0001 function [flist] = find_files_grid_first(fpat)
                0002 
                0003 % Function [flist] = find_files_grid_first(fpat)
                0004 %
                0005 % INPUTS
                0006 %   fpat     either a string containing a file pattern
                0007 %              (eg. 'state.*.nc) or a cell array of file patterns
                0008 %
                0009 % OUTPUTS
                0010 %   flist    cell array of file names
                0011 %
                0012 %
                0013 %  Ed Hill
                0014 files = {};
38167c2ffe Ed H*0015 fdirs = {};
51885b0cf3 Ed H*0016 if ischar(fpat)
                0017   tmp = fpat;
                0018   fpat = {};
                0019   fpat = { tmp };
                0020 end
                0021 for ip = 1:length(fpat)
                0022   d = dir(fpat{ip});
38167c2ffe Ed H*0023   r = regexp(fpat{ip},'^(?<dirname>.*/)[^/]+$','names');
51885b0cf3 Ed H*0024   for i = 1:length(d)
38167c2ffe Ed H*0025     if (not(d(i).isdir))
6fad66cf0d Ed H*0026       if (not(isempty(r)))
                0027         fdirs{end+1} = r.dirname;
                0028       else
                0029         fdirs{end+1} = '';
                0030       end
38167c2ffe Ed H*0031       files{end+1} = d(i).name;
                0032     end
51885b0cf3 Ed H*0033   end
                0034 end
38167c2ffe Ed H*0035 [fall,iu] = unique(files);
                0036 dall = {};
                0037 for i = 1:length(iu)
                0038   dall{end+1} = fdirs{iu(i)};
                0039 end
                0040 
51885b0cf3 Ed H*0041 %  Order all the files with any grid files first and the rest
                0042 %  alphabetically
38167c2ffe Ed H*0043 
6802a9bca5 Ed H*0044 fordered = {};
38167c2ffe Ed H*0045 notg = [];
                0046 for i = 1:length(fall)
                0047   if strncmp(fall{i},'grid.',5)
                0048     fordered{end+1} = [ dall{i} fall{i} ];
                0049   else
                0050     notg = [ notg ; i ];
51885b0cf3 Ed H*0051   end
                0052 end
38167c2ffe Ed H*0053 
                0054 for i = 1:length(notg)
                0055   fordered{end+1} = [ dall{notg(i)} fall{notg(i)} ];
51885b0cf3 Ed H*0056 end
38167c2ffe Ed H*0057 
51885b0cf3 Ed H*0058 flist = fordered;
                0059