function [time,amp] = hpread(varargin);

%HPREAD: Read and plot data from scope channels.
%
%This routine plots and returns individual-channel scope data
%taken from the oscilloscope. It accepts as parameters a scope 
%data member, a selected channel, and any style information 
%regarding the plotting capabilities of the routine.  
%A routine call follows the format:
%
%[time,amp] = HPREAD(scope_data_member, 'selected_channel', 'style');
%
%The parameter, 'scope_data_member', is a subscripted set of
%data created by the HPIMPORT routine, which downloads scope
%data from the .prn file (saved by the HP Benchlink Software).
%The data MUST first be downloaded into this data member
%before a call to HPREAD may be made.
%
%The parameter, 'selected_channel', is a string that is entered
%by the user, contained in single quotes, selecting which
%channel is to be plotted/returned.  The options are as follows:
%
%     'chan1', 'chan2', 'chan3', chan4'
%
%Keep in mind that not all of the channels will contain data,
%as not all of them might not be turned on for use at one time.
%
%The parameter 'style' selects the style of graphing used in
%the plot.  The options are the same as defined in PLOT.
%There is also a new twist: Giving the style, 'noplot', causes
%the routine to skip the plot of the channel and only returns
%the channel data.
%
%The returned parameters [time,amp] contain the time(x) axis
%and the amplitude(y) axis data for the selected channel.
%They are returned in horizontal vectors of equal length.
%The routine call may be made without the return parameters:
%
%HPREAD(scope_data_member, 'selected_channel', 'style')
%
%To supress the return parameters from being displayed to
%the screen, place a semicolon after the routine call.
%
%SEE ALSO: HPIMPORT, PLOT

%Author: J.P. Van't Hof
%Date of Creation: 6/11/98

data = varargin{1}.data;
format = varargin{1}.format;
num = varargin{1}.num;
select = varargin{2};

%if the user inputted a style parameter
if(nargin == 3)
   style = varargin{3};
else
   style = '-';
end;

found = 0;
select = upper(select);

%find which channel was selected, extract the data
%and plot if the user did not use the noplot parameter
%--plot using the style selected by user
for(i = 1:num)
   if(strcmp(format(1,i),select))
      if(~strcmp(style,'noplot'));
      	plot(data(:,(2*i-1)),data(:,(2*i)),style);
      	xlabel(char(format(2,i)));
      	ylabel(char(format(3,i)));
      	title(strcat('Scope Data:  ',format(1,i)));
      end;
      time = data(:,(2*i-1))';
      amp  = data(:,(2*i))';
      found = 1;
   end
end

%if the select parameter is invalid, let the user know
if(~found)
   disp(strcat('WARNING: ',select,' is an invalid entry or does not contain any data.'));
end
