function mapping = tcv_requests_mapping(data_request)
%
% Information pre-defined for gdat_tcv, you can add cases here to match official cases in gdat_tcv, allowing backward compatibility
%

% Defaults
mapping = struct(...
    'label', '', ...
    'method', '', ...
    'expression','', ...
    'timedim', -1, ...     % dim which is the time is the database, to copy in .t, the other dims are in .x (-1 means last dimension)
    'gdat_timedim',[], ...  % if need to reshape data and dim orders to have timedim as gdat_timedim (shifting time to gdat_timedim)
    'min', -inf, ...
    'max', inf);
% Note that gdat_timedim is set to timedim at end of this function if empty
% gdat_timedim should have effective index of the time dimension in gdat

if ~exist('data_request') || isempty(data_request)
  return
end

% default label: data_request keyword itself
mapping.label = data_request;

% for TCV, following choices are set so far:
% method = 'tdi' and then expression is the string within tdi (usual case when there is a direct link to an existing signal)
%                with tdi, if expression cell array, call tdi(cell{1},cell{2},...)
% method = 'tdiliuqe': same as tdi but adds "_2" or "_3" if 'liuqe',2 or 3 is asked for in options
% method = 'expression', then expression is executed and it should provide the structure gdat_tmp, which fields are copied to gdat_data
% method = 'switchcase', then there will be a specific case within gdat_tcv (usual case when not directly a signal)
%
% label is used for plotting
switch lower(data_request)
 case 'a_minor'
  mapping.timedim = 1;
  mapping.label = 'a(LCFS)';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'b0'
  mapping.timedim = 1;
  mapping.label = 'B_0';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'beta'
  mapping.timedim = 1;
  mapping.label = '\beta';
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::beta_tor';
 case 'betan'
  mapping.timedim = 1;
  mapping.label = '\beta_N';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'betap'
  mapping.timedim = 1;
  mapping.label = '\beta_p';
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::beta_pol';
 case 'cxrs'
  mapping.timedim = 2;
  mapping.label = 'cxrs';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'cxrs_rho'
  mapping.timedim = 2;
  mapping.label = 'cxrs';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'delta'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::delta_edge';
  % mapping.method = 'expression';
  % mapping.expression = ['tdi(''\results::q_psi'');']; % for tests
 case 'delta_bottom'
  mapping.timedim = 1;
  mapping.label = 'delta\_bottom';
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::delta_ed_bot';
 case 'delta_top'
  mapping.timedim = 1;
  mapping.label = 'delta\_top';
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::delta_ed_top';
 case 'ece'
  mapping.timedim = 2;
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'eqdsk'
  mapping.timedim = 0;
  mapping.method = 'switchcase'; % could use function make_eqdsk directly?
  mapping.expression = '';
 case 'halpha'
  mapping.timedim = 1;
  mapping.label = 'Halpha';
  mapping.method = 'tdi';
  mapping.expression = '\base::pd:pd_001';
 case 'halphas'
  mapping.timedim = 1;
  mapping.label = 'Halpha';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'ioh'
  mapping.timedim = 1;
  mapping.label = 'I ohmic transformer';
  mapping.method = 'tdi';
  mapping.expression = [{'\magnetics::ipol[*,$1]'} {'OH_001'}];
 case 'ip'
  mapping.timedim = 1;
  mapping.label = 'Plasma current';
  mapping.method = 'tdi';
  mapping.expression = '\magnetics::iplasma:trapeze';
 case 'kappa'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::kappa_edge';
 case 'li'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::l_i';
 case 'mhd'
  mapping.timedim = 1;
  mapping.label = 'n=1,2, etc';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'ne'
  mapping.timedim = 2;
  mapping.method = 'switchcase';
 case 'neint'
  mapping.timedim = 1;
  mapping.label = 'line integrated el. density';
  mapping.method = 'tdi';
  mapping.expression = '\results::fir:lin_int_dens';
 case 'nel'
  mapping.timedim = 1;
  mapping.label = 'line-averaged el. density';
  mapping.method = 'tdi';
  mapping.expression = '\results::fir:n_average';
 case 'ne_rho'
  mapping.timedim = 2;
  mapping.label = 'ne';
  mapping.method = 'switchcase';
 case 'neft'
  mapping.timedim = 2;
  mapping.label = 'ne';
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''ne_rho''; ' ...
                    'params_eff.fit=1;params_eff.fit_type=''avg'';gdat_tmp=gdat_tcv([],params_eff);'];
 case 'nete_rho'
  mapping.timedim = 2;
  mapping.label = 'ne and Te';
  mapping.method = 'switchcase';
 case 'ni'
  mapping.timedim = 2;
  mapping.method = 'switchcase'; % especially since might have option fit, etc
 case 'powers'
  mapping.timedim = 1;
  mapping.label = 'various powers';
  mapping.method = 'switchcase';
 case 'psi_axis'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::psi_axis';
 case 'psi_edge'
  mapping.timedim = 1;
  mapping.method = 'switchcase'; % is set to zero, so not in tree nodes
  mapping.label = 'psi\_edge';
 case 'q0'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::q_zero';
 case 'q95'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::q_95';
 case 'qedge'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::q_edge';
 case 'q_rho'
  mapping.timedim = 2;
  mapping.label = 'q';
  mapping.method = 'switchcase';
 case 'r_contour'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::r_contour';
 case 'rgeom'
  mapping.timedim = 1;
  mapping.label = 'Rgeom';
  mapping.method = 'switchcase';
 case 'rhotor_edge'
  mapping.timedim = 1;
  mapping.label = 'rhotor\_edge=sqrt(Phi/pi/B0)';
  mapping.method = 'switchcase'; % from conf if exist otherwise computes it
 case 'rhotor'
  mapping.timedim = 2;
  mapping.label = 'rhotor\_norm';
  mapping.method = 'switchcase'; % from conf if exist otherwise computes it
 case 'rhovol'
  mapping.timedim = 2;
  mapping.label = 'rhovol\_norm';
  mapping.method = 'switchcase'; % from conf if exist otherwise computes it
 case 'rmag'
  mapping.timedim = 1;
  mapping.label = 'R\_magaxis';
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::r_axis';
 case 'rtc'
  mapping.timedim = 1;
  mapping.label = 'rtc\_signals';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'sxr'
  mapping.timedim = 1;
  mapping.gdat_timedim = 2;
  mapping.method = 'switchcase';
 case 'te'
  mapping.timedim = 2;
  mapping.label = 'Te';
  mapping.method = 'switchcase';
 case 'te_rho'
  mapping.timedim = 2;
  mapping.label = 'Te';
  mapping.method = 'switchcase';
 case 'teft'
  mapping.timedim = 2;
  mapping.label = 'ne';
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''te_rho''; ' ...
                    'params_eff.fit=1;params_eff.fit_type=''avg'';gdat_tmp=gdat_tcv([],params_eff);'];
 case 'ti'
  mapping.timedim = 2;
  mapping.label = 'Ti';
  mapping.method = 'switchcase';
 case 'transp'
  mapping.label = 'transp output';
  mapping.method = 'switchcase';
 case 'vloop'
  mapping.timedim = 1;
  mapping.label = 'Vloop';
  mapping.method = 'tdi';
  mapping.expression = [{'\magnetics::vloop[*,$1]'} {'001'}];
 case 'volume'
  mapping.timedim = 1;
  mapping.label = 'Volume\_LCFS';
  mapping.method = 'switchcase';
 case 'volume_rho'
  mapping.timedim = 2;
  mapping.label = 'Volume(\rho)';
  mapping.method = 'switchcase';
  % mapping.expression = '\results::psitbx:vol'; (if exists for liuqe2 and 3 as well)
 case 'wmhd'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::total_energy';
 case 'z_contour'
  mapping.timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::z_contour';
 case 'zeff'
  mapping.timedim = 1;
  mapping.label = 'zeff from Ip-Ibs';
  mapping.method = 'tdi';
  mapping.expression = '\results::ibs:z_eff';
 case 'zgeom'
  mapping.timedim = 1;
  mapping.label = 'Zgeom';
  mapping.method = 'switchcase';
 case 'zmag'
  mapping.timedim = 1;
  mapping.label = 'Zmagaxis';
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::z_axis';
  %
  % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % extra TCV cases (not necessarily in official data_request name list)
  % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
 case '\results::total_energy'
  mapping.timedim = 1;
  mapping.gdat_timedim = 1;
  mapping.method = 'tdiliuqe';
  % mapping.expression = '\results::total_energy:foo';
  mapping.expression = '\results::total_energy';
 case '\results::thomson:psiscatvol'
  mapping.timedim = 1;
  mapping.gdat_timedim = 1;
  mapping.method = 'tdiliuqe';
  % mapping.expression = '\results::thomson:psiscatvol:foo';
  mapping.expression = '\results::thomson:psiscatvol';
 case 'mpx'
  mapping.timedim = 1;
  mapping.gdat_timedim = 2;
  mapping.method = 'switchcase';
 case {'profnerho','profterho'}
  mapping.timedim = 1;
  mapping.label = data_request;
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'xte'
  mapping.timedim = 1;
  mapping.gdat_timedim = 1;
  mapping.method = 'tdiliuqe';
  mapping.expression = '\results::te_x_a[*,12]';
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''\results::te_x_a[*,12]''; ' ...
                    'gdat_tmp=gdat_tcv([],params_eff); ' ...
                    'params_eff = gdat_data.gdat_params;params_eff.data_request=''\magnetics::iplasma:trapeze''; ' ...
                    'aa=gdat_tcv([],params_eff);it=find(abs(aa.data)<10e3);it2=iround_os(gdat_tmp.t,aa.t(it));gdat_tmp.data(it2)=NaN;'];
  
% $$$  case ''
% $$$   mapping.timedim = 1;
% $$$   mapping.label = data_request;
% $$$   mapping.method = 'tdi';
% $$$   mapping.expression = '';
 otherwise
  mapping.label = data_request;
  mapping.method = 'tdi'; % assume a full tracename is given, so just try with tdi (could check there are some ":", etc...)
  mapping.expression = data_request;
  
end

if isempty(mapping.gdat_timedim)
  mapping.gdat_timedim = mapping.timedim;
end
