function mapping = aug_requests_mapping(data_request)
%
% Information pre-defined for gdat_aug, you can add cases here to match official cases in gdat_aug, 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 AUG, following choices are set so far:
% method = 'signal' then expression contains the shotfile, diagnostic and if needed the experiment
%                expression is a cell array
% method = 'expression', then expression is the expression to return gdat_tmp...
% method = 'switchcase', then there will be a specific case within gdat_aug (usual case when not directly a signal)
%
% label is used for plotting
if iscell(data_request) % || (~ischar(data_request) && length(data_request)>1)
  mapping.label = data_request;
  mapping.method = 'signal'; % assume a full tracename is given, so just try with tdi (could check there are some ":", etc...)
  mapping.expression = data_request;
  mapping.gdat_timedim = mapping.timedim;
  return
end

switch lower(data_request)
 case 'a_minor'
  mapping.timedim = 1;
  mapping.label = 'a\_minor';
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''r_inboard'';' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);gdat_tmp.r_inboard=gdat_tmp.data;' ...
		    'params_eff.data_request=''r_outboard'';' ...
		   'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.r_outboard=gdat_tmp2.data;' ...
		    'gdat_tmp.data = 0.5.*(gdat_tmp2.data-gdat_tmp.data);gdat_tmp.label=''' mapping.label ''';' ...
		   'gdat_tmp.gdat_request=''' data_request ''';'];
 case 'b0'
  mapping.timedim = 1;
  mapping.label = 'B_0';
  mapping.method = 'signal';
  mapping.expression = [{'FPC'},{'BTF'}];
 case 'beta'
  mapping.timedim = 1;
  mapping.label = '\beta';
  mapping.method = 'signal';
  mapping.expression = [{'TOT'},{'beta'}];
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''betan'';' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);' ...
		    'params_eff.data_request=''ip'';gdat_tmp2=gdat_aug(shot,params_eff);' ...
		    'params_eff.data_request=''b0'';gdat_tmp3=gdat_aug(shot,params_eff);' ...
		    'params_eff.data_request=''a_minor'';gdat_tmp4=gdat_aug(shot,params_eff);' ...
		    'tmp_data_ip=interp1(gdat_tmp2.t,gdat_tmp2.data,gdat_tmp.t,[],NaN);' ...
		    'tmp_data_b0=interp1(gdat_tmp3.t,gdat_tmp3.data,gdat_tmp.t,[],NaN);' ...
		    'tmp_data_a=interp1(gdat_tmp4.t,gdat_tmp4.data,gdat_tmp.t,[],NaN);' ...
		    'gdat_tmp.data = 0.01.*abs(gdat_tmp.data.*tmp_data_ip./1e6./tmp_data_a./tmp_data_b0);' ...
		    'gdat_tmp.label=''' mapping.label ''';gdat_tmp.gdat_request=''' data_request ''';'];
 case 'betan'
  mapping.timedim = 1;
  mapping.label = '\beta_N';
  mapping.method = 'signal';
  mapping.expression = [{'TOT'},{'beta_N'}];
 case 'betap'
  mapping.timedim = 1;
  mapping.label = '\beta_p';
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'betpol'}];
 case 'cxrs'
  mapping.timedim = 2;
  mapping.label = 'cxrs';
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'delta'
  mapping.timedim = 1;
  mapping.label = 'delta';
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''delta_bottom''; ' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);params_eff.data_request=''delta_top'';' ...
		   'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.data = 0.5.*(gdat_tmp.data+gdat_tmp2.data);'];
 case 'delta_top'
  mapping.label = 'delta\_top';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'delRoben'}];
 case 'delta_bottom'
  mapping.label = 'delta\_bottom';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'delRuntn'}];
 case {'ece', 'eced', 'ece_rho', 'eced_rho'}
  mapping.timedim = 2;
  mapping.method = 'switchcase';
  mapping.expression = '';
 case 'eqdsk'
  mapping.timedim = 2;
  mapping.method = 'switchcase'; % could use function make_eqdsk directly?
  mapping.expression = '';
 case 'equil'
  mapping.gdat_timedim = 2;
  mapping.method = 'switchcase'; % could use function make_eqdsk directly?
  mapping.expression = '';
 case 'halpha'
  mapping.timedim = 1;
  mapping.label = 'Halpha';
  mapping.method = 'signal';
  mapping.expression = [{'POT'},{'ELMa-Han'}];
 case 'ioh'
  mapping.timedim = 1;
  mapping.label = 'I ohmic transformer';
  mapping.method = 'signal';
  mapping.expression = [{'MBI'},{'IOH'}];
 case 'ip'
  mapping.timedim = 1;
  mapping.label = 'Plasma current';
  mapping.method = 'signal';
  mapping.expression = [{'MAG'},{'Ipa'}];
 case 'kappa'
  mapping.timedim = 1;
  mapping.label = '\kappa';
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'k'}];
 case 'mhd'
  mapping.timedim = 1;
  mapping.label = 'Odd and Even n';
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request={''MOD'',''OddN''}; ' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);gdat_tmp.data=reshape(gdat_tmp.data,length(gdat_tmp.data),1 );' ...
		    'gdat_tmp.dim{1}=gdat_tmp.t;gdat_tmp.dim{2}=[1 2];gdat_tmp.x=gdat_tmp.dim{2};' ...
		    'gdat_tmp.n_odd.data = gdat_tmp.data;gdat_tmp.n_odd.data_request=params_eff.data_request;' ...
		    'params_eff.data_request={''MOD'',''EvenN''};' ...
		    'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.data(:,2)=reshape(gdat_tmp2.data,length(gdat_tmp2.data),1);' ...
		    'gdat_tmp.n_even.data = gdat_tmp2.data;gdat_tmp.n_even.data_request=params_eff.data_request;gdat_tmp.label={''n\_odd'',''n\_even''};' ...
		    'params_eff.data_request={''MOD'',''OddNAmp''};' ...
		    'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.n_odd.amp=reshape(gdat_tmp2.data,length(gdat_tmp2.data),1);' ...
		    'gdat_tmp.n_odd.amp_t=gdat_tmp2.t;' ...
		    'params_eff.data_request={''MOD'',''EvenNAmp''};' ...
		    'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.n_even.amp=reshape(gdat_tmp2.data,length(gdat_tmp2.data),1);' ...
		    'gdat_tmp.n_even.amp_t=gdat_tmp2.t;' ...
		    'gdat_tmp.full_path=''MOD/Odd in data and .n_odd; .n_even'';' ...
		    'gdat_tmp.gdat_request=''mhd'';gdat_tmp.gdat_params.data_request=gdat_tmp.gdat_request;'];
 case 'ne'
  mapping.timedim = 2;
  mapping.method = 'switchcase';
 case 'neint'
  mapping.timedim = 1;
  mapping.label = 'line integrated el. density';
  mapping.method = 'signal';
  mapping.expression = [{'DCN'},{'H-1'},{'AUGD'}];
 case 'nel'
  mapping.timedim = 1;
  mapping.label = 'line-averaged el. density';
  mapping.expression = [{'FPG'},{'lenH-1'},{'AUGD'}];
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''neint'';' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);params_eff.data_request=[{''FPG''},{''lenH-1''},{''AUGD''}];' ...
		   'gdat_tmp2=gdat_aug(shot,params_eff);ij=find(gdat_tmp2.data==0);gdat_tmp2.data(ij)=NaN;' ...
		    'tmp_data=interp1(gdat_tmp2.t,gdat_tmp2.data,gdat_tmp.t,[],NaN);' ...
		    'gdat_tmp.data = gdat_tmp.data./(tmp_data+1e-5);'];
 case 'ne_rho'
  mapping.timedim = 2;
  mapping.label = 'ne';
  mapping.method = 'switchcase';
 case 'nete_rho'
  mapping.timedim = 2;
  mapping.label = 'ne and Te';
  mapping.method = 'switchcase';
 case 'ni'
  mapping.method = 'switchcase'; % especially since might have option fit, etc
 case 'pgyro'
  mapping.timedim = 1;
  mapping.label = 'EC gyros';
  mapping.method = 'switchcase';
 case 'powers'
  mapping.timedim = 1;
  mapping.label = 'various powers';
  mapping.method = 'switchcase';
 case 'psi_axis'
  mapping.timedim = 1;
  mapping.method = 'switchcase'; % there is psi_axis-psi_edge in FPG but otherwise complicated to get from equil, thus needs swticth case
  mapping.label ='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.label = 'q_0';
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'q0'},{'AUGD'}];
 case 'q95'
  mapping.timedim = 1;
  mapping.label = 'q_{95}';
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'q95'},{'AUGD'}];
 case 'q_edge'
  mapping.timedim = 1;
  mapping.label = 'q_{edge}}';
  mapping.method = 'expression';
  mapping.method = 'switchcase';
  mapping.expression = [{'FPG'},{'q95'},{'AUGD'}];
  mapping.expression = [];
 case 'q_rho'
  mapping.timedim = 2;
  mapping.gdat_timedim = 2;
  mapping.label = 'q';
  mapping.method = 'switchcase';
 case 'rgeom'
  mapping.label = 'Rgeom';
  mapping.timedim = 1;
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=''r_inboard'';' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);gdat_tmp.r_inboard=gdat_tmp.data;' ...
		    'params_eff.data_request=''r_outboard'';' ...
		   'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.r_outboard=gdat_tmp2.data;' ...
		    'gdat_tmp.data = 0.5.*(gdat_tmp2.data+gdat_tmp.data);gdat_tmp.label=''' mapping.label ''';' ...
		   'gdat_tmp.gdat_request=''' data_request ''';'];
 case 'r_inboard'
  mapping.label = 'R\_inboard';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'Rin'},{'AUGD'}];
 case 'r_outboard'
  mapping.label = 'R\_outboard';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'Raus'},{'AUGD'}];
 case 'rhotor'
  mapping.timedim = 2;
  mapping.method = 'switchcase';
  mapping.label = 'rhotor\_norm';
 case 'rhotor_edge'
  mapping.timedim = 1;
  mapping.method = 'switchcase';
  mapping.label = 'rhotor\_edge';
 case 'rhovol'
  mapping.timedim = 2;
  mapping.label = 'rhovol\_norm';
  mapping.method = 'switchcase';
 case 'rmag'
  mapping.label = 'R\_magaxis';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'Rmag'},{'AUGD'}];
 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 'ti'
  mapping.label = 'Ti';
  mapping.method = 'switchcase';
 case 'vloop'
  mapping.label = 'Vloop';
  mapping.timedim = 1;
  % mapping.method = 'signal';
  % mapping.expression = [{'MAG'},{'ULid12'},{'AUGD'}];
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=[{''MAG''},{''ULid12''},{''AUGD''}];' ...
		   'gdat_tmp=gdat_aug(shot,params_eff);ij=find(~isnan(gdat_tmp.data));' ...
		    'tmp_data=interpos(gdat_tmp.t,gdat_tmp.data,-3e4);' ...
		    'gdat_tmp.data_smooth = tmp_data;gdat_tmp.gdat_request=''vloop'';gdat_tmp.gdat_params.data_request=gdat_tmp.gdat_request;'];
 case 'volume'
  mapping.label = 'Volume';
  mapping.timedim = 1;
  mapping.method = 'switchcase';
  mapping.expression = [{'FPG'},{'Vol'},{'AUGD'}];
 case 'volume_rho'
  mapping.timedim = 2;
  mapping.label = 'volume\_norm';
  mapping.method = 'switchcase';
 case 'zeff'
  mapping.label = 'zeff from cxrs';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'ZES'},{'Zeff'},{'AUGD'}];
 case 'zgeom'
  mapping.label = 'Zgeom';
  mapping.timedim = 1;
  mapping.method = 'expression';
  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request=[{''FPG''},{''Zoben''},{''AUGD''}];' ...
                    'gdat_tmp=gdat_aug(shot,params_eff);gdat_tmp.z_top=gdat_tmp.data;' ...
		    'params_eff.data_request=[{''FPG''},{''Zunt''},{''AUGD''}];' ...
		   'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.z_bottom=gdat_tmp2.data;' ...
		    'gdat_tmp.data = 0.5.*(gdat_tmp2.data+gdat_tmp.data);gdat_tmp.label=''' mapping.label ''';' ...
		   'gdat_tmp.gdat_request=''' data_request ''';'];

 case 'zmag'
  mapping.label = 'Z\_magaxis';
  mapping.timedim = 1;
  mapping.method = 'signal';
  mapping.expression = [{'FPG'},{'Zmag'},{'AUGD'}];
  %
  % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % extra AUG cases (not necessarily in official data_request name list)
  % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
 case 'transp'
  mapping.label = 'transp output';
  mapping.method = 'switchcase';


 otherwise
  mapping.label = data_request;
  mapping.method = 'signal'; % 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
