function [neg_on_err] = pb_write_jcamp(fname, num_points, SW, SF, real_data, imag_data)
% FUNCTION NAME:
%   pb_write_jcamp
%
% DESCRIPTION:
%   Write the RAM contents to a JCAMP-DX file.
%
% INPUTS:
%   fname - The filename for the file you want to create
%
%   num_points - Number of points to write to the file
%
%   SW - Spectral width of the baseband data in Hz
%
%   SF - Spectrometer frequency in MHz
%
%   real_data - Integer array containing the real portion of the data points
%
%   imag_data - Integer array containing the imaginary portion of the data points
%
% 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. 
%    
% $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_jcamp',fname, num_points, SW,SF, r_dat, i_dat);

end
