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 % $Id: run_userfcn.m,v 1.5 2010/04/26 19:45:25 ray Exp $ 0018 % by Ray Zimmerman, PSERC Cornell 0019 % Copyright (c) 2009-2010 by Power System Engineering Research Center (PSERC) 0020 % 0021 % This file is part of MATPOWER. 0022 % See http://www.pserc.cornell.edu/matpower/ for more info. 0023 % 0024 % MATPOWER is free software: you can redistribute it and/or modify 0025 % it under the terms of the GNU General Public License as published 0026 % by the Free Software Foundation, either version 3 of the License, 0027 % or (at your option) any later version. 0028 % 0029 % MATPOWER is distributed in the hope that it will be useful, 0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0032 % GNU General Public License for more details. 0033 % 0034 % You should have received a copy of the GNU General Public License 0035 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0036 % 0037 % Additional permission under GNU GPL version 3 section 7 0038 % 0039 % If you modify MATPOWER, or any covered work, to interface with 0040 % other modules (such as MATLAB code and MEX-files) available in a 0041 % MATLAB(R) or comparable environment containing parts covered 0042 % under other licensing terms, the licensors of MATPOWER grant 0043 % you additional permission to convey the resulting work. 0044 0045 rv = varargin{1}; 0046 if ~isempty(userfcn) && isfield(userfcn, stage) 0047 for k = 1:length(userfcn.(stage)) 0048 if isfield(userfcn.(stage)(k), 'args') 0049 args = userfcn.(stage)(k).args; 0050 else 0051 args = []; 0052 end 0053 switch stage 0054 case {'ext2int', 'formulation', 'int2ext'} 0055 % mpc = userfcn_*_ext2int(mpc, args); 0056 % om = userfcn_*_formulation(om, args); 0057 % results = userfcn_*_int2ext(results, args); 0058 rv = feval(userfcn.(stage)(k).fcn, rv, args); 0059 case {'printpf', 'savecase'} 0060 % results = userfcn_*_printpf(results, fd, mpopt, args); 0061 % mpc = userfcn_*_savecase(mpc, fd, prefix, args); 0062 rv = feval(userfcn.(stage)(k).fcn, rv, varargin{2}, varargin{3}, args); 0063 end 0064 end 0065 end