function [fighandle]=gdat_plot(gdat_data,varargin);
%
% choices from doplot in gdat_data.gdat_params.doplot:
%     doplot = 0: no plot
%            = 1: new figure created
%            = -1: add to current figure (with hold all)
%            > 1: create new figure with this number, adding clf
%            <-1: add to figure number abs(doplot) (with hold all)
%
if ~isfield(gdat_data.gdat_params,'doplot') || gdat_data.gdat_params.doplot ==0
  return
end

fighandle = get(0,'CurrentFigure');

if prod(isfield(gdat_data,{'data','t'})) && ~isempty(gdat_data.data) && ~isempty(gdat_data.t)
  if gdat_data.gdat_params.doplot == 1
    fighandle = figure;
  elseif gdat_data.gdat_params.doplot > 1
    fighandle = figure(gdat_data.gdat_params.doplot);
    clf;
  elseif gdat_data.gdat_params.doplot == -1
    hold all
  elseif gdat_data.gdat_params.doplot < -1
    fighandle = figure(abs(gdat_data.gdat_params.doplot));
    hold all
  end
  plot(gdat_data.t,gdat_data.data);
  title([gdat_data.gdat_params.machine ' #' num2str(gdat_data.shot)]);
  ylabel(gdat_data.label);
  zoom on;
else
  disp('cannot plot gdat_data, has empty data or t field')
end
