Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/gmt/rdnctiles.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
4e7bfad2e0 Ed H*0001 function [res,att] = rdnctiles(fpat,vnames,tlev, flag,dblev)
8d3b8abaa0 Ed H*0002 
4e7bfad2e0 Ed H*0003 % Function [res,att] = rdnctiles(fpat,vnames,tlev, flag,dblev)
8d3b8abaa0 Ed H*0004 %
                0005 % INPUTS
                0006 %   fpat     either a string containing a file pattern
                0007 %              (eg. 'state.*.nc) or a cell array of file patterns
                0008 %   vnames   either a single variable name as a string or a
                0009 %              cell array of variable names
6802a9bca5 Ed H*0010 %   tlev     empty or a struct specifying:
                0011 %              tdname :  name of the "time" dimension
                0012 %              tvname :  name of the "time" coord variable
                0013 %              tvals  :  vector of "time" values 
8d3b8abaa0 Ed H*0014 %
b2dac0a6c3 Ed H*0015 %   flag     one of:  'oldflat' [def]
                0016 %                     'compact' 'bytile' 'byface'
8d3b8abaa0 Ed H*0017 %   dblev    debug level [def: 0]
                0018 %
                0019 % OUTPUTS
b2dac0a6c3 Ed H*0020 %   res      results
                0021 %   att      attribute values
8d3b8abaa0 Ed H*0022 %
                0023 % EXAMPLES
                0024 %   tlist = rdnctiles('state.*',[1000:100:2000]);
                0025 %   tlist = rdnctiles('state.*.nc','Temp','S',[1000:100:2000]);
6802a9bca5 Ed H*0026 %
8d3b8abaa0 Ed H*0027 %   tlist = rdnctiles('state.*.nc','Temp','S',[1000:100:2000]);
15db930790 Ed H*0028 %
                0029 %   tl = rdnctiles({'state.*.nc' 'grid*'},[],[],[],20)
b2dac0a6c3 Ed H*0030 %   tl = rdnctiles({'state.*.nc' 'grid*'},[],[],'bytile',20)
15db930790 Ed H*0031 %   tl = rdnctiles({'state.*.nc' 'grid*'},[],[24 72],[],20)
                0032 %   tl = rdnctiles({'state.*.nc' 'grid*'},[],[24 72],'bytile',20)
4e7bfad2e0 Ed H*0033 %
                0034 %
8d3b8abaa0 Ed H*0035 %  Ed Hill
b2dac0a6c3 Ed H*0036 %  Set defaults
8d3b8abaa0 Ed H*0037 dlev = 0;
                0038 if nargin < 1
                0039   error('There must be at least one argument!');
                0040 end
                0041 if nargin < 2
                0042   vnames = {};
                0043 end
                0044 if nargin < 3
4e7bfad2e0 Ed H*0045   tlev = {};
8d3b8abaa0 Ed H*0046 end
b2dac0a6c3 Ed H*0047 if nargin < 4 || isempty(flag)
5e40d2151d Ed H*0048   flag = 'oldflat';
b2dac0a6c3 Ed H*0049 end
                0050 if nargin > 4
8d3b8abaa0 Ed H*0051   dlev = dblev;
                0052 end
                0053 
b2dac0a6c3 Ed H*0054 switch lower(flag)
                0055  case 'oldflat'
5e40d2151d Ed H*0056   % error(['the ''oldflat'' format is not yet implemented.']);
b2dac0a6c3 Ed H*0057  case 'compact'
                0058   error(['the ''compact'' format is not yet implemented.']);
                0059  case 'bytile'
                0060  case 'byface'
                0061   error(['the ''byface'' format is not yet implemented.']);
                0062  otherwise
                0063   error(['the flag ''' flag ''' is unknown']);
                0064 end
                0065 
6802a9bca5 Ed H*0066 % Get all the files
51885b0cf3 Ed H*0067 fall = find_files_grid_first(fpat);
8d3b8abaa0 Ed H*0068 if isempty(fall)
                0069   error(['No files matching could be found!']);
                0070 end
                0071 if dlev > 2
                0072   disp(sprintf('Total files found:  %d',length(fall)));
                0073   for i = 1:length(fall)
                0074     disp(['  ' fall{i}]);
                0075   end
                0076 end
                0077 
6802a9bca5 Ed H*0078 %  Set defaults and do basic sanity checks for vnames
8d3b8abaa0 Ed H*0079 if isempty(vnames)
                0080   vnames = {};
                0081 elseif ischar(vnames)
                0082   tmp = vnames;
                0083   vnames = { tmp };
6802a9bca5 Ed H*0084 elseif iscell(vnames)
8d3b8abaa0 Ed H*0085 else
51885b0cf3 Ed H*0086   error(['"vnames" must be a cell array or a string!']);
8d3b8abaa0 Ed H*0087 end
                0088 
6802a9bca5 Ed H*0089 %  Set defaults and do basic sanity checks for tlev
15db930790 Ed H*0090 if isvector(tlev)
                0091   tmp = tlev;
                0092   clear tlev;
                0093   tlev.tvals = tmp;
                0094 end
4e7bfad2e0 Ed H*0095 if isempty(tlev)
6802a9bca5 Ed H*0096   vit = find_all_iters_per_var(fall,vnames,[]);
                0097 elseif isstruct(tlev)
                0098   if isfield(tlev,'tdname')
                0099     vit.tdname = tlev.tdname;
8d3b8abaa0 Ed H*0100   end
6802a9bca5 Ed H*0101   if isfield(tlev,'tvname')
                0102     vit.tvname = tlev.tvname;
8d3b8abaa0 Ed H*0103   end
6802a9bca5 Ed H*0104   if isfield(tlev,'tvals')
                0105     if isvector(tlev.tvals)
15db930790 Ed H*0106       vit = find_all_iters_per_var(fall,vnames,tlev);
                0107       allvars = fieldnames(vit.vars);
                0108       insufft = {};
                0109       for i = 1:length(allvars)
                0110         if isempty(vit.vars.(allvars{i}))
                0111           continue
                0112         end
                0113         v = intersect(vit.vars.(allvars{i}),tlev.tvals);
                0114         if length(v) < length(tlev.tvals)
                0115           insufft{end+1} = allvars{i};
                0116         end
                0117         vit.vars.(allvars{i}) = tlev.tvals;
                0118       end
                0119       if not(isempty(insufft))
                0120         disp(['WARNING: some of the specified times are not ' ...
                0121               'available for the following variables :']);
                0122         fprintf(1,['   ']);
                0123         for i = 1:length(insufft)
                0124           fprintf(1,[' ' insufft{i} ]);
                0125         end
                0126       end
6802a9bca5 Ed H*0127     else
                0128       error(['if tlev.tvals is defined, it *must* be a vector ' ...
                0129              'of time values']);
                0130     end
                0131   else
15db930790 Ed H*0132       vit = find_all_iters_per_var(fall,vnames,[]);
8d3b8abaa0 Ed H*0133   end
6802a9bca5 Ed H*0134 else
                0135   error(['the "tlev" input is not in the right format']);
8d3b8abaa0 Ed H*0136 end
                0137 
b2dac0a6c3 Ed H*0138 res = [];
7b05d035df Ed H*0139 att = [];
b2dac0a6c3 Ed H*0140 switch lower(flag)
                0141  case 'oldflat'
5e40d2151d Ed H*0142   res = rdnctiles_oldflat(fall,vit,dlev);
b2dac0a6c3 Ed H*0143  
                0144  case 'compact'
8d3b8abaa0 Ed H*0145   
b2dac0a6c3 Ed H*0146  case 'bytile'
6802a9bca5 Ed H*0147   res = rdnctiles_bytile(fall,vit,dlev);
b2dac0a6c3 Ed H*0148  
                0149  case 'byface'
8d3b8abaa0 Ed H*0150   
                0151 end
                0152