-------------------------------------------------------------------- Copyright (C) J. V. Mansbridge, CSIRO, january 24 1992 Revision $Revision: 1.3 $ CHANGE 1.2 92/03/10 function str = fill_varnames(cdfid, nvars) DESCRIPTION: This function fills the ith row of an array named 'str', with the the name of the ith variable in the netcdf file with id number cdfid. nvars is the number of variables. Each name is initially allowed up to 25 letters but the number of columns in 'str' will be expanded if necessary. INPUT: cdfid: the id number of the netCDF file under consideration. ndims: the number of variables of the netCDF file under consideration. OUTPUT: str: the array that receives each variable name as one of its rows. EXAMPLE: CALLER: getcdf.m CALLEE: mexcdf.mex AUTHOR: J. V. Mansbridge, CSIRO ---------------------------------------------------------------------
0001 function str = fill_varnames(cdfid, nvars) 0002 %-------------------------------------------------------------------- 0003 % Copyright (C) J. V. Mansbridge, CSIRO, january 24 1992 0004 % Revision $Revision: 1.3 $ 0005 % CHANGE 1.2 92/03/10 0006 % function str = fill_varnames(cdfid, nvars) 0007 % 0008 % DESCRIPTION: 0009 % This function fills the ith row of an array named 'str', with the 0010 % the name of the ith variable in the netcdf file with id number 0011 % cdfid. nvars is the number of variables. Each name is initially 0012 % allowed up to 25 letters but the number of columns in 'str' will 0013 % be expanded if necessary. 0014 % 0015 % INPUT: 0016 % cdfid: the id number of the netCDF file under consideration. 0017 % ndims: the number of variables of the netCDF file under consideration. 0018 % 0019 % OUTPUT: 0020 % str: the array that receives each variable name as one of its rows. 0021 % 0022 % EXAMPLE: 0023 % 0024 % 0025 % CALLER: getcdf.m 0026 % CALLEE: mexcdf.mex 0027 % 0028 % AUTHOR: J. V. Mansbridge, CSIRO 0029 %--------------------------------------------------------------------- 0030 0031 % Copyright (C), J.V. Mansbridge, 0032 % Commonwealth Scientific and Industrial Research Organisation 0033 % Revision $Revision: 1.3 $ 0034 % Author $Author: mansbrid $ 0035 % Date $Date: 1994/02/16 00:17:31 $ 0036 % RCSfile $RCSfile: fill_varnames.m,v $ 0037 % @(#)fill_varnames.m 1.2 92/03/10 0038 % 0039 %-------------------------------------------------------------------- 0040 0041 % First try to fill each row of str with the relevant name. If any 0042 % name has more than max_le characters then the number of characters 0043 % in the longest name will be stores and become the number of columns 0044 % when the operation is done correctly. 0045 0046 str = []; 0047 max_le = 30; 0048 new_max = 25; 0049 for i = 0:nvars - 1 0050 [varnam, vartyp, nvdims, vdims, nvatts, rcode] = ... 0051 mexcdf('ncvarinq', cdfid, i); 0052 if rcode == -1 0053 error(['** ERROR ** ncvarinq: rcode = ' num2str(rcode)]) 0054 end 0055 le = length(varnam); 0056 0057 if le > max_le | new_max > max_le 0058 new_max = max ([ le new_max ]); 0059 else 0060 str_tmp = [ varnam ]; 0061 while le < max_le 0062 str_tmp = [ str_tmp ' ' ]; 0063 le = le + 1; 0064 end 0065 str = [ str ; str_tmp ]; 0066 end 0067 end 0068 0069 % If any name is more than max_le characters long then store the names 0070 % correctly in str now that we know the length of the longest name. 0071 0072 if new_max > max_le 0073 str = []; 0074 max_le = new_max; 0075 for i = 1:nvars 0076 [varnam, vartyp, nvdims, vdims, nvatts, rcode] = ... 0077 mexcdf('ncvarinq', cdfid, i); 0078 if rcode == -1 0079 error(['** ERROR ** ncvarinq: rcode = ' num2str(rcode)]) 0080 end 0081 le = length(varnam); 0082 0083 str_tmp = [ varnam ]; 0084 while le < max_le 0085 str_tmp = [ str_tmp ' ' ]; 0086 le = le + 1; 0087 end 0088 str = [ str ; str_tmp ]; 0089 end 0090 end