Skip to content
Snippets Groups Projects
gdat.m 7.58 KiB
Newer Older
function [trace,error,varargout] = gdat(shot,data_type,varargin)
%
% function [trace,error,varargout] = gdat(shot,data_type,varargin)
%
% new:  no args or with shot=-9 to get keywords relevant for the related experiment
%       keywordlist=gdat; (for the default machine)
%       keywordlist=gdat(-9,[],'machine'); (for the specific machine)
Olivier Sauter's avatar
Olivier Sauter committed
% varargin{1}:  0 => no plot (default), 1 => plot  (see special case for old JET style below)
% varargin{2}:  machine name 'AUG', 'JET' , 'TCV' (default: depending on where implemented)
%
% list of data_type currently available:
%
% (almost) All machines
% 'Ip'   =  current
% 'zmag' =  vertical position of the center of the plasma (magnetic axis)
% 'rmag' =  radial position of the center of the plasma 
% 'rcont' =  R of plama boundary vs time
% 'zcont' =  Z of plama boundary vs time
% 'vol' =  volume of flux surfaces vs rho=sqrt(psi)
% 'qrho' =  q profile on rho mesh
% 'q95' =  q95 vs time
% 'kappa', 'elon' =  edge elongation vs time
% 'delta', 'triang' =  edge averaged triangularity vs time
% 'deltatop', 'triangtop' =  edge upper (top) triangularity vs time
% 'deltabot', 'triangbot' =  edge lower (bottom) triangularity vs time
% 'neint' =  line-integrated electron density [m/m^3]
% 'ne'= ne raw profile on (z,t). ADD error bars in .std
% 'te'= Te raw profile on (z,t). ADD error bars in .std
% 'nerho'= ne profile on (rho=sqrt(psi),time) mesh.Note rho is a 2D array as depends on time. ADD error bars in .std
% 'terho'= Te profile on (rho=sqrt(psi),time) mesh.Note rho is a 2D array as depends on time. ADD error bars in .std
% 'ece'  =  electron cyclotron emission
% 'sxr'  =  soft x-ray emission 
% 'sxR'  =  soft x-ray emission with varargout{1} option (requires varargin{5}!)
Olivier Sauter's avatar
Olivier Sauter committed
% 'Halpha' = H(D)-alpha trace
%
% specific to TCV (see help loadTCVdata for more information)
% 'xx_2 or xx_3' for Liuqe2 or 3: same as above for xx related to equilibrium
% 'vol' =  volume of flux surfaces
% 'profnerho' =  ne smoothed or fitted , vs (rho,t) (from Thomson fit)
% 'profterho' =  te smoothed or fitted , vs (rho,t) (from Thomson fit)
% 'neft' =  ne fitted from data on rho mesh (from proffit.local_time:neft)
% 'teft' =  te fitted from data on rho mesh (from proffit.local_time:teft)
% 'neftav' =  ne fitted from averaged over time data on rho mesh (from proffit.avg_time:neft)
% 'teftav' =  te fitted from averaged over time data on rho mesh (from proffit.avg_time:teft)
% 'ece'  =  electron cyclotron emission
% 'sxr'  =  soft x-ray emission
% 'sxR'  =  soft x-ray emission with varargout{1} option (requires varargin{4}!)
% 'MPX'  =  soft x-ray from wire chambers
% 'vtor' = toroidal rotation, raw data and arror bars
% 'vtorfit' = fitted toroidal rotation profiles (and error bars)
% 'vpol' = poloidal rotation, raw data and arror bars
% 'vpolfit' = fitted poloidal rotation profiles (and error bars)
Olivier Sauter's avatar
Olivier Sauter committed
% 'Ti' (or Tc), 'Tifit', 'ni' (or nC), 'nifit', 'zeffcxrs', 'zeffcxrsfit': similar to 'vtor' from CXRS
% Special case compatible with old gdat.m allows (JET related): gdat(51994,'ppf','efit/xip',1)
% data_type: type of the required data.( see above)
% optional arguments valid for all values of data_type (not passed on to loadMACHINEdata function):
% Additional input arguments for specific traces (passed on to loadMACHINEdata function)
%                  varargin{3}:  [i1 i2] : if not empty, assumes need many chords from i1 to i2
%                  varargin{4}:  channel status 1= unread yet, 0= read
%                                (for traces with many channel, enables to load additional channels,
%                                 like SXR, ECE, etc.)
%                  varargin{5}:  zmag for varargout{1} computation
%
% OUTPUT:
% trace: structure containing data and meshes (compatible with tdi main structure)
% trace.data:   data
% trace.t:      time of reference 
% trace.x:      space of reference 
% trace.dim:    cell array of grids, trace.dim{1}, {2}, ...
% trace.dimunits: units of dimensions
% trace.std: if error bars are available
Olivier Sauter's avatar
Olivier Sauter committed
% error:        error in loading signal (0=> OK, >=1 => error)
%
% Additional Output arguments depending on data_type
%
% data_type=sxR:
%                varargout{1}: intersection of the view lines with magnetic axis
% data_type=MPX: (specific to TCV) 
%                varargout{1}: see help loadTCVdata
% functions needed: loadAUGdata, loadJETdata, loadTCVdata
%                  
%
% Examples:
%         [zmag,error]=gdat(shot,'zmag',1);  % gets zmag from TCV and plot
%         [zmag,error]=gdat(shot,'zmag',1,'JET'); % idem but from JET
%         [zmag,error]=gdat(shot,'ppf','efit/zmag',1); as above for JET 
%
%   keywordlist=gdat(-9,[],[],machine); % to get examples and the keywords defined for the relevant machine
%   keywordlist=gdat; % to get examples and the keywords defined for the local machine
Olivier Sauter's avatar
Olivier Sauter committed
gdatpaths

nargineff=nargin;
if nargineff>=3 & ischar(varargin{1})
Olivier Sauter's avatar
Olivier Sauter committed
% $$$   if isempty(strmatch(upper(varargin{1}),[{'TCV'} {'JET'} {'AUG'}]))
  % old JET way with second part of data structure in varagin{1}
  data_type={data_type ; varargin{1}};
  if nargineff>=4; 
    varargin{1}=varargin{2};
  else
    varargin{1}=0;
    nargineff=4;
  end
  varargin{2}='JET';
Olivier Sauter's avatar
Olivier Sauter committed
% $$$ end
end  

% SETTING MACHINE
doplot=0;
if (nargineff>=3 & ~isempty(varargin{1})); doplot=varargin{1}; end
Olivier Sauter's avatar
Olivier Sauter committed
a=which('gdat');
if ~isempty(findstr('ipp',a)) | ~isempty(findstr('/u/osauter',a));
  machine='AUG';
  global usemdsplus; % so far from AUG, do not use mdsplus
  usemdsplus=0;
elseif ~isempty(findstr('/home/osauter',a));
  machine='JET';
elseif ~isempty(findstr('/home/sauter',a));
  machine='TCV';
Olivier Sauter's avatar
Olivier Sauter committed
elseif ~isempty(findstr('/u/sauter',a));
  machine='D3D';
if ~exist('machine')
Olivier Sauter's avatar
Olivier Sauter committed
 % disp('did not find machine, set it to TCV')
if (nargineff>=4 & ~isempty(varargin{2})); machine=varargin{2}; end
Olivier Sauter's avatar
Olivier Sauter committed
machine
% load data from specified machine
if ~exist('data_type'); data_type=[]; end
if ~exist('shot') || isempty(shot); shot=-9; end
if nargineff<=4
  eval(['[trace,error,varargout] = load' machine 'data(shot,data_type);']);
else
  eval(['[trace,error,varargout] = load' machine 'data(shot,data_type,varargin{3:end});']);
Olivier Sauter's avatar
Olivier Sauter committed
if doplot~=0; set_defaults_matlab; end
if doplot==1 && isfield(trace,'data') && length(trace.data)>1 && ~ischar(trace.data)
  try
    figure;zoom on
    if length(size(trace.data))<=2
Olivier Sauter's avatar
Olivier Sauter committed
      hhh=plot(trace.t,trace.data);
      ylabel(data_type)
    else
      for idim=1:length(trace.dim)
        if length(trace.t)==length(trace.dim{idim}); idim_t=idim; end
      end
      if idim_t<=2
Olivier Sauter's avatar
Olivier Sauter committed
        hhh=plot(trace.t,trace.data(:,:,floor(end/2)));
        ylabel([data_type '(:,:,floor(end/2))'])
      elseif idim_t==3;
Olivier Sauter's avatar
Olivier Sauter committed
        hhh=plot(trace.t,reshape(trace.data(:,floor(end/2),:),length(trace.dim{1}),length(trace.t)));
        ylabel([data_type '(:,floor(end/2),:)'])
      end
    xlabel('time [s]')
    title([machine ' '  num2str(shot)])
    grid on
  catch
    disp(' error in plotting part, most probably because could not guess time dimension correctly. To check')
Olivier Sauter's avatar
Olivier Sauter committed
  end
  try
    hold on
Olivier Sauter's avatar
Olivier Sauter committed
    child_h=get(gca,'child');
    nbplot=length(child_h);
    if length(size(trace.data))<=2
Olivier Sauter's avatar
Olivier Sauter committed
      hhh=plotos(trace.t,trace.data,'-',[],[],colos(mod(nbplot,12)+1,:));
Olivier Sauter's avatar
Olivier Sauter committed
      hhh=plot(trace.t,trace.data(:,:,1),'--');
    end
  catch
    disp(' error in plotting part, most probably because could not guess time dimension correctly. To check')
Olivier Sauter's avatar
Olivier Sauter committed
  end
Olivier Sauter's avatar
Olivier Sauter committed

try
  if exist('hhh') && ishandle(hhh(end)); set(hhh(end),'Tag',['gdat: ' num2str(shot)]); end
catch
end

Olivier Sauter's avatar
Olivier Sauter committed
if doplot~=0
  h2=findobj(gca,'-regexp','Tag','gdat:*');
  if ~isempty(h2);
    legend(get(sort(h2),'Tag'));
  end
Olivier Sauter's avatar
Olivier Sauter committed
end