Home > vbmeg > external > iso2mesh > jsonopt.m

jsonopt

PURPOSE ^

SYNOPSIS ^

function val=jsonopt(key,default,varargin)

DESCRIPTION ^

 val=jsonopt(key,default,optstruct)

 setting options based on a struct. The struct can be produced
 by varargin2struct from a list of 'param','value' pairs

 authors:Qianqian Fang (q.fang <at> neu.edu)

 $Id: loadjson.m 371 2012-06-20 12:43:06Z fangq $

 input:
      key: a string with which one look up a value from a struct
      default: if the key does not exist, return default
      optstruct: a struct where each sub-field is a key 

 output:
      val: if key exists, val=optstruct.key; otherwise val=default

 license:
     BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

 -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function val=jsonopt(key,default,varargin)
0002 %
0003 % val=jsonopt(key,default,optstruct)
0004 %
0005 % setting options based on a struct. The struct can be produced
0006 % by varargin2struct from a list of 'param','value' pairs
0007 %
0008 % authors:Qianqian Fang (q.fang <at> neu.edu)
0009 %
0010 % $Id: loadjson.m 371 2012-06-20 12:43:06Z fangq $
0011 %
0012 % input:
0013 %      key: a string with which one look up a value from a struct
0014 %      default: if the key does not exist, return default
0015 %      optstruct: a struct where each sub-field is a key
0016 %
0017 % output:
0018 %      val: if key exists, val=optstruct.key; otherwise val=default
0019 %
0020 % license:
0021 %     BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
0022 %
0023 % -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
0024 %
0025 
0026 val=default;
0027 if(nargin<=2) return; end
0028 opt=varargin{1};
0029 if(isstruct(opt))
0030     if(isfield(opt,key))
0031        val=getfield(opt,key);
0032     elseif(isfield(opt,lower(key)))
0033        val=getfield(opt,lower(key));
0034     end
0035 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005