function [neg_on_err] = pb_write_ascii_verbose(fname, num_points, SW, SF, real_data, imag_data)
% FUNCTION NAME:
%   pb_write_ascii_verbose
%
% DESCRIPTION:
%   Write the data captured from RAM to an ascii file. The file format produced 
%   is: The first three lines are comments containing information about the 
%   RadioProcessor and SpinAPI. The fourth line contains the number of complex 
%   points, the fifth line contains the spectrometer frequency (in MHz), the 
%   sixth line contains the spectral width of the data (in Hz), and the 
%   remaining lines contain the complex points themselves. Real and Imaginary 
%   compoents of the complex points are given on alternate lines. Thus, the 
%   real and imaginary components of the first point are given on lines 7 and 8 
%   respectively. The second point is given on lines9 and 10, etc.
%
% INPUTS:
%   fname - Filename to write the data to
%
%   num_points - Number of complex data points to write
%
%   SW - Spectral width in Hz. This should be set to the spectral width of the 
%        stored baseband data.
%
%   SF	- Spectrometer frequency in MHz
%
%   real_data - Array holding the real portion of the complex data points
%
%   imag_data - Array holding the imaginary portion of the complex data points
%
% $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_data);
imag_pointer = libpointer('int16Ptr', imag_data);

r_dat = real_pointer.Value;
i_dat = imag_pointer.Value;

fname = char(fname);

neg_on_err = calllib(SPINAPI_DLL_NAME, 'pb_write_ascii_verbose', fname, num_points, SW, SF, r_dat, i_dat);

end


