Home > atmlab > handy > rqre_field.m

rqre_field

PURPOSE ^

RQRE_FIELD Require that a structure has a particular field

SYNOPSIS ^

function rqre_field( Q, fieldname, nonstdname )

DESCRIPTION ^

 RQRE_FIELD   Require that a structure has a particular field

    Issues an error if criterion not fulfilled.

 FORMAT   rqre_field( Q, fieldname [, nonstdname ] )
        
 IN    Q             The structure.
       fieldname     Name of field.
 OPT   nonstdname    Name of variable to use in error message. Default is
                     to use the function *inputname* to determine the
                     variable name.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rqre_field.m

SOURCE CODE ^

0001 % RQRE_FIELD   Require that a structure has a particular field
0002 %
0003 %    Issues an error if criterion not fulfilled.
0004 %
0005 % FORMAT   rqre_field( Q, fieldname [, nonstdname ] )
0006 %
0007 % IN    Q             The structure.
0008 %       fieldname     Name of field.
0009 % OPT   nonstdname    Name of variable to use in error message. Default is
0010 %                     to use the function *inputname* to determine the
0011 %                     variable name.
0012 
0013 % 2005-03-15   Created by Patrick Eriksson.
0014 
0015 
0016 function rqre_field( Q, fieldname, nonstdname )
0017 %
0018 if nargin < 3, nonstdname = []; end
0019  
0020 %- Handle the cellstr case in recursive manner
0021 if iscellstr( fieldname )
0022   for i = 1 : length(fieldname)
0023     rqre_field( Q, fieldname{1}, nonstdname );
0024   end
0025   return
0026 end
0027                                                                            %&%
0028 assert( ischar( fieldname ) );                                             %&%
0029 assert( ischar( nonstdname )  ||  isempty( nonstdname ) );                 %&%
0030   
0031 
0032 if isempty(nonstdname)
0033   vname = sprintf( 'The variable *%s*', inputname(1) );
0034 else
0035   assert( ischar( nonstdname ) );                                          %&%
0036   vname = sprintf( '%s', nonstdname );
0037 end
0038 
0039 if ~isfield( Q, fieldname )
0040   error(['atmlab:' mfilename ':missingfield'], ...
0041       '%s is required to have the field *%s*.', vname, fieldname);
0042 end
0043 
0044 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005