


--------------------------------------------------------------------
Copyright (C) J. V. Mansbridge, CSIRO, january 24 1992
Revision $Revision: 1.3 $
CHANGE 1.2 92/03/10
function str = fill_dimnames(cdfid, ndims)
DESCRIPTION:
This function fills the ith row of an array named 'str', with the
the name of the ith dimension in the netcdf file with id number
cdfid. ndims is the number of dimensions. Each dimension name is
initially allowed up to max_le 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 dimensions of the netCDF file under consideration.
OUTPUT:
str: the array that receives each dimension name as one of its rows.
EXAMPLE:
CALLER: general purpose
CALLEE: none
AUTHOR: J. V. Mansbridge, CSIRO
---------------------------------------------------------------------

0001 function str = fill_dimnames(cdfid, ndims) 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_dimnames(cdfid, ndims) 0007 % 0008 % DESCRIPTION: 0009 % This function fills the ith row of an array named 'str', with the 0010 % the name of the ith dimension in the netcdf file with id number 0011 % cdfid. ndims is the number of dimensions. Each dimension name is 0012 % initially allowed up to max_le letters but the number of columns in 0013 % 'str' will be expanded if necessary. 0014 % 0015 % INPUT: 0016 % cdfid: the id number of the netCDF file under consideration. 0017 % ndims: the number of dimensions of the netCDF file under consideration. 0018 % 0019 % OUTPUT: 0020 % str: the array that receives each dimension name as one of its rows. 0021 % 0022 % EXAMPLE: 0023 % 0024 % 0025 % CALLER: general purpose 0026 % CALLEE: none 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_dimnames.m,v $ 0037 % @(#)fill_dimnames.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 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 = 25; 0048 new_max = 25; 0049 for i = 0:ndims - 1 0050 [dimnam, dimsiz, rcode] = mexcdf('ncdiminq', cdfid, i); 0051 if rcode == -1 0052 error(['** ERROR ** ncdiminq: rcode = ' num2str(rcode)]) 0053 end 0054 le = length(dimnam); 0055 0056 if le > max_le | new_max > max_le 0057 new_max = max ([ le new_max ]); 0058 else 0059 str_tmp = [ dimnam ]; 0060 while le < max_le 0061 str_tmp = [ str_tmp ' ' ]; 0062 le = le + 1; 0063 end 0064 str = [ str ; str_tmp ]; 0065 end 0066 end 0067 0068 % If any name is more than max_le characters long then store the names 0069 % correctly in str now that we know the length of the longest name. 0070 0071 if new_max > max_le 0072 str = []; 0073 max_le = new_max; 0074 for i = 0:ndims - 1 0075 [dimnam, dimsiz, rcode] = mexcdf('ncdiminq', cdfid, i); 0076 if rcode == -1 0077 error(['** ERROR ** ncdiminq: rcode = ' num2str(rcode)]) 0078 end 0079 le = length(dimnam); 0080 0081 str_tmp = [ dimnam ]; 0082 while le < max_le 0083 str_tmp = [ str_tmp ' ' ]; 0084 le = le + 1; 0085 end 0086 str = [ str ; str_tmp ]; 0087 end 0088 end 0089