⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getnc.m

📁 matlacb程序包
💻 M
📖 第 1 页 / 共 2 页
字号:
%%   5) A strange 'feature' of matlab 5 is that it will not tolerate a singleton% dimension as the final dimension of a multidimensional array.  Thus, if% you chose to have only one element in the final dimension this dimension% will be 'squeezed' whether you want it to be or not - this seems to be% unavoidable.%%   6) Some earlier versions of this function the argument "order" to be an% array. This option has been removed because it was so confusing - the% matlab function "permute" can be used to do the same thing.%% EXAMPLES:% 1) Get all the elements of the variable, note the order of the dimensions:% >> airtemp = getnc('oberhuber.nc', 'airtemp');% >> size(airtemp)% ans =%     12    90   180%% 2) Get a subsample of the variable, note the stride:% >> airtemp = getnc('oberhuber.nc', 'airtemp', [-1 1 3], [-1 46 6], [1 5 1]);% >> size(airtemp)% ans =%     12    10     4%% 3) Get all the elements of the variable, but with missing values%    replaced with 1000.  Note that the bl_corner, tr_corner, stride and%    order vectors have been replaced by -1 to choose the defaults:% >> airtemp = getnc('oberhuber.nc', 'airtemp', -1, -1, -1, -1, 3, 1000); % >> size(airtemp)% ans =%     12    90   180%% 4) Get a subsample of the variable, a singleton dimension is squeezed:% >> airtemp = getnc('oberhuber.nc', 'airtemp', [-1 7 -1], [-1 7 -1]);   % >> size(airtemp)                                                         % ans =%     12   180% % 5) Get a subsample of the variable, a singleton dimension is not squeezed:% >> airtemp = getnc('oberhuber.nc','airtemp',[-1 7 -1],[-1 7 -1],-1,-1,-1,-1,0);% >> size(airtemp)                                                            % ans =%     12     1   180%%% AUTHOR:   J. V. Mansbridge, CSIRO%---------------------------------------------------------------------% This function calls: check_nc.m, check_st.m, fill_att.m, fill_var.m,%                      getnc_s.m, inqnc.m, menu_old.m, mexnc, pos_cds.m,%                      return_v.m, uncmp_nc.m, y_rescal.m%     Copyright (C), J.V. Mansbridge, 1992%     Commonwealth Scientific and Industrial Research Organisation%     $Id: getnc.m Mon, 03 Jul 2006 17:16:40 $% %--------------------------------------------------------------------% In November 1998 some code was added to deal better with byte type data in a% netcdf file. Note that any values greater than 127 will have 256 subtracted% from them. This is because on some machines (an SGI running irix6.2 is an% example) values are returned in the range 0 to 255. Note that in the fix the% values less than 128 are unaltered and so we do not have to know whether the% particular problem has occurred or not; for machines where there is no problem% no values will be altered. This is applied to byte type attributes (like% _FillValue) as well as the variable values.% Check the number of arguments.  If there are no arguments then return% the help message.  If there is more than one argument then call% getnc_s which reads the netcdf file in a non-interactive way.% If there is only one argument then drop through and find the values% interactively.num_args = length(varargin);if num_args == 0  % No input argument  help getnc  disp('You must pass an input argument to getnc')  returnelseif num_args == 1  if isstruct(varargin{1})    % Send on to getnc_s    values = getnc_s(varargin);    return  else    % Carry on with the interactive version of getnc    file = varargin{1};  endelse  % Send on to getnc_s  values = getnc_s(varargin);  returnend% Find the full path name of the file.[cdf, file_status] = CSIRO_get_more_file_info(file);% Find out whether values should be automatically rescaled or not.[rescale_var, rescale_att] = y_rescal;% Get the dds for the file.desc = ddsnc(cdf);% varstring = fill_var(cdfid, nvars);% Prompt the user for the name of the variable containing the hyperslab.nvars = length(desc.variable);list_variable_name = cell(nvars, 1);for ii = 1:nvars  list_variable_name{ii} = desc.variable(ii).name;endi_var = menu('Choose a variable', list_variable_name);% Get attribute and dimension information for the chosen variable.var_name = list_variable_name{i_var};[att_val, att_name_list] = attnc(cdf, var_name);dim_idents = desc.variable(i_var).dim_idents;num_dims_of_var = length(dim_idents);list_dim_name = cell(num_dims_of_var, 1);list_dim_length = zeros(num_dims_of_var, 1);is_dim_a_variable = zeros(num_dims_of_var, 1);for ii = 1:num_dims_of_var  list_dim_name{ii} = desc.dimension(dim_idents(ii)).name;  list_dim_length(ii) = desc.dimension(dim_idents(ii)).length;  for jj = 1:nvars    if strcmp(list_dim_name{ii}, list_variable_name{jj})      is_dim_a_variable(ii) = 1;      break    end  endend% Call simple input dialog so user can select the features they need. Note% that this is in a loop in case the user messes up the answer.dlg_title = [var_name ': input details'];num_lines = 1;for ii = 1:num_dims_of_var  prompt{ii} = [list_dim_name{ii} ...		': [starting index, finishing index, stride]'];  defAns{ii} = ['[1, ' num2str(list_dim_length(ii)) ', 1]'];endndvp = num_dims_of_var + 1;prompt{ndvp} = 'replace missing values with NaN? (y or n)';defAns{ndvp} = 'y';Resize = 'on';repeat_loop = 1;while repeat_loop    % Get user respnse    answer = inputdlg(prompt, dlg_title, num_lines, defAns, Resize);  % Now parse the reply to see if it is o.k.    repeat_loop = 0;  for ii = 1:num_dims_of_var    try      xx = str2num(answer{ii});      bl_corner(ii) = xx(1);      tr_corner(ii) = xx(2);      stride(ii) = xx(3);    catch      repeat_loop = repeat_loop + 1;      err_msg{repeat_loop} = ['Dimension ' list_dim_name{ii} ...		    ': specify [starting index, finishing index, stride]'];    end    switch lower(answer{ndvp})     case 'y'      change_miss = 2;     case 'n'      change_miss = 1;     otherwise      repeat_loop = repeat_loop + 1;      err_msg{repeat_loop} = 'Replacement of missing values specified wrongly';    end  end    % Deal with any errors that the user made in the dialog box.    if repeat_loop == 1    errordlg(err_msg{1}, 'Error specifying array')  elseif repeat_loop > 1    clear err_list    err_list{1} = ['There were ' num2str(repeat_loop) ' errors in the input' ...		   ' dialog box'];    for ii = 1:repeat_loop      err_list{ii + 1} = err_msg{ii};    end    errordlg(err_list, 'Error specifying array')  endendvalues = getnc(cdf, var_name, bl_corner, tr_corner, stride, -1, change_miss, ...		    0, 1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -