0001 function M = read_netcdf_vars_xy(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 nodeflag = false;
0022 cellflag = false;
0023
0024
0025
0026 freeI = true(1,size(varargin,2));
0027 subsample_num = 0;
0028 for ii=1:1:length(varargin)
0029 keyword = lower(varargin{ii});
0030 vartype = class(keyword);
0031 if vartype(1)~='c' | length(keyword)<10, continue; end
0032 switch(keyword(1:10))
0033 case 'nodevalues'
0034 nodeflag = true;
0035 nodevalues = varargin{ii+1};
0036 freeI([ii ii+1]) = false;
0037 case 'cellvalues'
0038 cellflag = true;
0039 cellvalues = varargin{ii+1};
0040 freeI([ii ii+1]) = false;
0041 end
0042 end
0043
0044
0045 if cellflag & nodeflag
0046 if length(cellvalues) ~= length(nodevalues)
0047 error('The number of elements and nodes are not the same. This functions only works if they are the same :-(');
0048 return
0049 end
0050 end
0051
0052
0053
0054
0055 if nodeflag && cellflag
0056 for count=1:length(nodevalues);
0057
0058 nodes=nodevalues(count);
0059 cells=cellvalues(count);
0060 M1 = read_netcdf_vars(varargin{freeI}, 'dimrange', 'node', nodes+[0 1], 'dimrange', 'nele', cells+[0 1]);
0061
0062 if count==1
0063 M = M1;
0064 elseif count>0
0065
0066 varnames = fieldnames(M1);
0067 for ii=4:2:length(varnames)
0068 dimids = M1.(varnames{ii-1}).dimids;
0069 if size(dimids,1)>0 && dimids(1)<=1;
0070 M.(varnames{ii})(count,:,:) = M1.(varnames{ii});
0071 end
0072 end
0073 end
0074
0075 end
0076 elseif nodeflag
0077 for count=1:length(nodevalues);
0078
0079 nodes=nodevalues(count);
0080 M1 = read_netcdf_vars(varargin{freeI}, 'dimrange', 'node', nodes+[0 1]);
0081
0082 if count==1
0083 M = M1;
0084 elseif count>0
0085
0086 varnames = fieldnames(M1);
0087 for ii=4:2:length(varnames)
0088 dimids = M1.(varnames{ii-1}).dimids;
0089 if dimids(1)==1;
0090 M.(varnames{ii})(count,:,:) = M1.(varnames{ii});
0091 end
0092 end
0093 end
0094
0095 end
0096 elseif cellflag
0097 for count=1:length(cellvalues);
0098
0099 cells=cellvalues(count);
0100 M1 = read_netcdf_vars(varargin{freeI}, 'dimrange', 'nele', cells+[0 1]);
0101
0102 if count==1
0103 M = M1;
0104 elseif count>0
0105
0106 varnames = fieldnames(M1);
0107 for ii=4:2:length(varnames)
0108 dimids = M1.(varnames{ii-1}).dimids;
0109 if dimids(1)==0;
0110 M.(varnames{ii})(count,:,:) = M1.(varnames{ii});
0111 end
0112 end
0113 end
0114
0115 end
0116 end