RUN_USERFCN Runs the userfcn callbacks for a given stage. RV = RUN_USERFCN(USERFCN, STAGE, VARARGIN) USERFCN : the 'userfcn' field of mpc, populated by ADD_USERFCN STAGE : the name of the callback stage begin executed (additional arguments) some stages require additional arguments. Example: mpc = get_mpc(om); om = run_userfcn(mpc.userfcn, 'formulation', om); See also ADD_USERFCN, REMOVE_USERFCN, TOGGLE_RESERVES, TOGGLE_IFLIMS, RUNOPF_W_RES.
0001 function rv = run_userfcn(userfcn, stage, varargin) 0002 %RUN_USERFCN Runs the userfcn callbacks for a given stage. 0003 % RV = RUN_USERFCN(USERFCN, STAGE, VARARGIN) 0004 % 0005 % USERFCN : the 'userfcn' field of mpc, populated by ADD_USERFCN 0006 % STAGE : the name of the callback stage begin executed 0007 % (additional arguments) some stages require additional arguments. 0008 % 0009 % Example: 0010 % mpc = get_mpc(om); 0011 % om = run_userfcn(mpc.userfcn, 'formulation', om); 0012 % 0013 % See also ADD_USERFCN, REMOVE_USERFCN, TOGGLE_RESERVES, TOGGLE_IFLIMS, 0014 % RUNOPF_W_RES. 0015 0016 % MATPOWER 0017 % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 0018 % by Ray Zimmerman, PSERC Cornell 0019 % 0020 % $Id: run_userfcn.m 2644 2015-03-11 19:34:22Z ray $ 0021 % 0022 % This file is part of MATPOWER. 0023 % Covered by the 3-clause BSD License (see LICENSE file for details). 0024 % See http://www.pserc.cornell.edu/matpower/ for more info. 0025 0026 rv = varargin{1}; 0027 if ~isempty(userfcn) && isfield(userfcn, stage) 0028 for k = 1:length(userfcn.(stage)) 0029 if isfield(userfcn.(stage)(k), 'args') 0030 args = userfcn.(stage)(k).args; 0031 else 0032 args = []; 0033 end 0034 switch stage 0035 case {'ext2int', 'formulation', 'int2ext'} 0036 % mpc = userfcn_*_ext2int(mpc, args); 0037 % om = userfcn_*_formulation(om, args); 0038 % results = userfcn_*_int2ext(results, args); 0039 rv = feval(userfcn.(stage)(k).fcn, rv, args); 0040 case {'printpf', 'savecase'} 0041 % results = userfcn_*_printpf(results, fd, mpopt, args); 0042 % mpc = userfcn_*_savecase(mpc, fd, prefix, args); 0043 rv = feval(userfcn.(stage)(k).fcn, rv, varargin{2}, varargin{3}, args); 0044 end 0045 end 0046 end