function WAVE = LCGetWaveform(OBJ, CH, SP, NP)
%
% LCGETWAVEFORM Download a waveform from the oscilloscope.
%
% LCGetWaveform donwloads a waveform from a Lecroy 9450 oscilloscope for
% channel/memory CH using instrument object OBJ. Sparsing, SP, and number
% of points, NP, may be specified or left to the default values 1 and 0 (all
% points).
%
% This function may work with little or no modification on other Lecroy
% scopes that are similar to the 9450.
%
if nargin < 4
NP = 0;
end
if nargin < 3
SP = 1;
end
% Currently we only support one transfer format, valid for GPIB only.
fprintf(OBJ, 'CFMT DEF9,BYTE,BIN');
% Set up the request.
fprintf(OBJ, 'WFSU SP,%d,NP,%d,FP,0,SN,0', [SP NP]);
% Ask for the waveform data values only.
fprintf(OBJ, '%s:WF? DAT1', CH);
% Skip past the header information.
char(fread(OBJ, 13, 'int8'))';
% Obtain the number of points of data.
points = sscanf(char(fread(OBJ, 9, 'int8')'), '%d');
% Read the waveform points.
WAVE = fread(OBJ, points, 'int8');
% Read the end of line character to clear input buffer.
EOL = fread(OBJ, 1);