%% Pointers
% When your handwritten code allocates memory for signal, state, or parameter 
% data, you can generate code that accesses that data through a pointer. 
% Apply a storage class such as |ImportedExternPointer| to a data item in 
% the model. Your handwritten code provides the pointer definition.

% Copyright 2020 The MathWorks, Inc.

%% C Construct
% |extern double *myIn;|  

%% Procedure
% 1. Open example model <matlab:ex_pointer |ex_pointer|>. 
open_system('ex_pointer');
%%
% 2. Open the *Embedded Coder* app.
%
% 3. In the *C Code* tab, select *Code Interface* > *Individual Element
%    Code Mappings*.
%
% 4. In the Code Mappings editor, on the *Inports* tab, set *Storage Class*
%    for the Inport block to |ImportedExternPointer|.
%
% 5. Generate code from the model.
evalc('rtwbuild(''ex_pointer'')');

%% Results
% The generated header file |ex_pointer.h| declares the pointer.
file = fullfile('ex_pointer_ert_rtw','ex_pointer.h');
rtwdemodbtype(file,'/* Imported (extern) pointer block signals */', ...
    'extern real_T *In1;',1,1);

%%
% In the generated source file |ex_pointer.c|, in the model step function, 
% the algorithm dereferences the pointer, |In1|.
file = fullfile('ex_pointer_ert_rtw','ex_pointer.c');
rtwdemodbtype(file,'/* Model step function */', ...
    '/* Model initialize function */',1,0);







