CPF_REGISTER_EVENT Register event functions= CPF_EVENTS = CPF_REGISTER_EVENT(CPF_EVENTS, NAME, FCN, TOL, LOCATE) Registers a CPF event function to be called by RUNCPF. Inputs: CPF_EVENTS : struct containing info about registered CPF event fcns NAME : string containing event name FCN : string containing name of event function, returning numerical scalar or vector value that changes sign at location of the event TOL : scalar or vector of same dimension as event function return value of tolerance for detecting the event, i.e. abs(val) <= tol LOCATE : flag indicating whether the event requests a rollback step to locate the event function zero Outputs: CPF_EVENTS : updated struct containing info about registered CPF event fcns
0001 function cpf_events = cpf_register_event(cpf_events, name, fcn, tol, locate) 0002 %CPF_REGISTER_EVENT Register event functions= 0003 % CPF_EVENTS = CPF_REGISTER_EVENT(CPF_EVENTS, NAME, FCN, TOL, LOCATE) 0004 % 0005 % Registers a CPF event function to be called by RUNCPF. 0006 % 0007 % Inputs: 0008 % CPF_EVENTS : struct containing info about registered CPF event fcns 0009 % NAME : string containing event name 0010 % FCN : string containing name of event function, returning numerical 0011 % scalar or vector value that changes sign at location of the event 0012 % TOL : scalar or vector of same dimension as event function return value 0013 % of tolerance for detecting the event, i.e. abs(val) <= tol 0014 % LOCATE : flag indicating whether the event requests a rollback step 0015 % to locate the event function zero 0016 % 0017 % Outputs: 0018 % CPF_EVENTS : updated struct containing info about registered CPF event fcns 0019 0020 % MATPOWER 0021 % Copyright (c) 2016, Power Systems Engineering Research Center (PSERC) 0022 % by Ray Zimmerman, PSERC Cornell 0023 % and Shrirang Abhyankar, Argonne National Laboratory 0024 % 0025 % This file is part of MATPOWER. 0026 % Covered by the 3-clause BSD License (see LICENSE file for details). 0027 % See http://www.pserc.cornell.edu/matpower/ for more info. 0028 0029 %% the event function data to be registered 0030 e = struct( ... 0031 'name', name, ... 0032 'fcn', fcn, ... 0033 'tol', tol, ... 0034 'locate', locate ... 0035 ); 0036 0037 %% convert function names to function handles, as necessary 0038 if ~isa(e.fcn, 'function_handle') 0039 e.fcn = str2func(e.fcn); 0040 end 0041 0042 %% register to list of event functions 0043 if isempty(cpf_events) 0044 cpf_events = e; 0045 else 0046 nef = length(cpf_events); 0047 for k = 1:nef 0048 if strcmp(cpf_events(k).name, name) 0049 error('cpf_register_event: duplicate event name: ''%s''', name); 0050 end 0051 end 0052 cpf_events(nef+1) = e; 0053 end