Home > RPSstuff > fill_attnames.m

fill_attnames

PURPOSE ^

--------------------------------------------------------------------

SYNOPSIS ^

function str = fill_attnames(cdfid, varid, nvatts)

DESCRIPTION ^

--------------------------------------------------------------------
     Copyright (C) J. V. Mansbridge, CSIRO, january 23 1992
     Revision $Revision: 1.3 $
 CHANGE   1.2 92/03/10
  function str = fill_attnames(cdfid, varid, nvatts)

 DESCRIPTION:
  This function fills the ith row of an array named 'str', with the
  the name of the ith attribute of the variable having id number
  varid in the netcdf file with id number cdfid.  nvatts is the
  number of attributes.  Each attribute 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.
  varid: the id number of the variable under consideration.
  nvatts: the number of attributes of the variable under consideration.

 OUTPUT:
  str: the array that receives each attribute name as one of its rows.

 EXAMPLE:


 CALLER:   getcdf.m, getcdf_batch.m
 CALLEE:   mexcdf.mex

 AUTHOR:   J. V. Mansbridge, CSIRO
---------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Wed 30-Nov-2005 14:45:02 by m2html © 2003