function [neg_on_err, r_dat, i_dat] = pb_get_data(num_points, real, imag)
% FUNCTION NAME:
%   pb_get_data
%
% DESCRIPTION:
%   Retrieve the captured data from the board's memory. Data is returned as a 
%   signed 32 bit integer. Data can be accessed at any time, even while the data 
%   from a scan is being captured. However, this is not recommended since there 
%   is no way to tell what data is part of the current scan and what is part of 
%   the previous scan. No post processing of the data is done; it is read directly 
%   from memory into the output arrays. pb_read_status() can be used to determine
%   whether or not a scan is currently in progress. It takes approximately 160ms
%   to transfer all 16k complex points.
%
% INPUTS:
%   num_points - Number of complex points to read from RAM
%
%   real - Array to store the real data read from RAM
%
%   imag - Array to store the imag data read from RAM
%
% OUTPUTS:
%   neg_on_err - A negative number is returned on failure, and spinerr is set to a 
%                description of the error. 0 is returned on success.
%
%   r_dat - Real data from RAM is stored into this array
%
%   i_dat - Imag data from RAM is stored into this array
%
% $Revision: R2017a$ 
% $Author: SpinCore Technologies, Inc.$
% $Date: November 17, 2023$
% ------------------------------------------------------------------------------

global SPINAPI_DLL_NAME;

% Assign the memory address of the c_data array to the pointer argument
real_pointer = libpointer('int16Ptr', real);
imag_pointer = libpointer('int16Ptr', imag);

% Retrieve the data from the pointer
r_dat = real_pointer.Value;
i_dat = imag_pointer.Value;

[neg_on_err, r_dat, i_dat] = calllib(SPINAPI_DLL_NAME, 'pb_get_data', num_points, r_dat, i_dat);

end

