## Copyright (C) 2009, 2010 Thomas Weidenfeller
## 
## This file is part of gds2000tools/gds-octave.
## 
## gds2000tools/gds-octave is free software: you can redistribute it
## and/or modify it under the terms of the GNU General Public License
## version 3 as published by the Free Software Foundation.
## 
## gds2000tools/gds-octave is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with gds2000tools/gds-octave.  If not,
## see <http://www.gnu.org/licenses/>.
##

## usage: [VAL] = gds_struct2val(GDSSTRUCT)
## usage: [VAL] = gds_struct2val(GDSSTRUCT, true)
##
## Returns the Waveform Data samples from GDSSTRUCT as data values.
## The function takes the Vertical Scale information in GDSSTRUCT and
## the GDS-2000 oscilloscope 25 samples/div scaling constant into account.
##
## The second argument, when true, indicates that also the Vertical Position
## information should be taken into account. This offsets all values by the
## Vertical Position value. This is primarily interesting for display. The
## values calculated with the offset in mind are not suitable for calculations.
##
## Note: This function is very similar to the gds_wd2v function.
##       gds_wd2v was a misnomer. The only difference, except the
##	 name is that gds_struct2val doesn't test if the Vertical_Units
##	 are volts. 
##
## Example:
##
## gs = gds_csvread("DS0012.CSV");
## v = gds_struct2val(gs);
##
## See also: gds_csvread, gds_wd2v, gds_wd2val.

## Author: Thomas Weidenfeller
## Created: 2010-07-10
## Version: $Id: gds_struct2val.m,v 1.3 2010/12/31 13:05:40 tw Exp $
## Keywords: Oscilloscope, GDS-2000, gds2000tools, plot

function [v] = gds_struct2val(gs, off_flg)
	if(nargin < 1 || nargin > 2 || !isstruct(gs))
		print_usage();
	endif

	vp = 0;
	if(nargin == 2 && off_flg)
		vp = gs.Vertical_Position;
	endif

	v = gds_wd2val(gs.Waveform_Data, gs.Vertical_Scale, vp);
endfunction

%!demo
%! ##gs = gds_csvread("DS0008.CSV"); ## read waveform from file
%! gs = __gds_demo_gs();      ## for now get a demo gds waveform data structure
%! v = gds_struct2val(gs);
%! subplot(2,1,1);
%! gds_plot(gs);
%! subplot(2,1,2);
%! plot(v);
%! title("Values");
%! ylabel(" ");
