Skip to content
Snippets Groups Projects
gdat_plot.m 3.95 KiB
Newer Older
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)
%

fighandle = NaN;
gdat_plot_params.dummy=NaN;
if mod(nargin-1,2)==0
  for i=1:2:nargin-1
    if ischar(varargin{i})
      % enforce lower case for any character driven input
      gdat_plot_params.(lower(varargin{i})) = varargin{i+1};
    else
      warning(['input argument nb: ' num2str(i) ' is incorrect, expects a character string'])
      error_status=101;
      return
    end
  end
else
  warning('number of input arguments incorrect, cannot make pairs of parameters')
  error_status=102;
doplot=0;
if isfield(gdat_plot_params,'doplot') && ~isempty(gdat_plot_params.doplot)
  doplot = gdat_plot_params.doplot;
elseif isfield(gdat_data.gdat_params,'doplot') || ~isempty(gdat_data.gdat_params.doplot)
  doplot = gdat_data.gdat_params.doplot;
end
if doplot==0; return; end

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
  if strcmp(gdat_data.gdat_request,'eqdsk')
    % special case, plot contours of first equil
    endstr = '';
    if iscell(gdat_data.eqdsk); endstr = '{1}'; end
    eval(['contour(gdat_data.eqdsk' endstr '.rmesh,gdat_data.eqdsk' endstr '.zmesh,gdat_data.eqdsk' endstr '.psi'',100);'])
    hold on
    eval(['plot(gdat_data.eqdsk' endstr '.rplas,gdat_data.eqdsk' endstr '.zplas,''k'');'])
    eval(['plot(gdat_data.eqdsk' endstr '.rlim,gdat_data.eqdsk' endstr '.zlim,''k'');'])
    axis equal;
    title(eval(['gdat_data.eqdsk' endstr '.stitle']));
  elseif any(find(size(gdat_data.data)==length(gdat_data.t)))
    plot(gdat_data.t,gdat_data.data);
    title([gdat_data.gdat_params.machine ' #' num2str(gdat_data.shot)]);
    if isfield(gdat_data,'mapping_for')
      xlabel(['time [' gdat_data.dimunits{gdat_data.mapping_for.(gdat_data.gdat_params.machine).gdat_timedim} ']']);
    else
      xlabel(['time']);
    end
    ylabel_eff = gdat_data.label;
    if iscell(gdat_data.label) && length(gdat_data.label)>=2; ylabel_eff = gdat_data.label{2}; end
    if ~isempty(gdat_data.units)
      hylabel=ylabel([ylabel_eff '[' gdat_data.units ']']);
      hylabel=ylabel(ylabel_eff);
    zoom on;
  end
  if strcmp(gdat_data.gdat_request,'mhd')
    % special case, add legend instead of ylabel
    delete(hylabel);
    legend(gdat_data.label,2);
    % add spectrogram per signal
    mhd_sum_data = 0.;
    nfft=1024;
    tmhdm=mean(reshape(gdat_data.t(1:nfft*fix(length(gdat_data.t)/nfft)),nfft,fix(length(gdat_data.t)/nfft)));
    for i=1:size(gdat_data.data,2)
      [B,F,T]=specgram(gdat_data.data(:,i),nfft,1/mean(diff(gdat_data.t)),hanning(nfft),nfft/2);
      figure
      imagesc(T+tmhdm(1),F/1e3,20*log10(abs(B)));axis xy;colormap jet;
      ylabel('freq')
      xlabel(gdat_data.dimunits{1})
      title([upper(gdat_data.gdat_params.machine) '#' num2str(gdat_data.shot) ' ' gdat_data.label{i}])
      mhd_sum_data = mhd_sum_data + gdat_data.data(:,i);
    [B,F,T]=specgram(mhd_sum_data./size(gdat_data.data,2),nfft,1/mean(diff(gdat_data.t)),hanning(nfft),nfft/2);
    figure
    imagesc(T+tmhdm(1),F/1e3,20*log10(abs(B)));axis xy;colormap jet;
    ylabel('freq')
    xlabel(gdat_data.dimunits{1})
    title([upper(gdat_data.gdat_params.machine) '#' num2str(gdat_data.shot) ' sum of ' gdat_data.label{:}])
else
  disp('cannot plot gdat_data, has empty data or t field')
end