diff --git a/matlab/TCV_IMAS/tcv2ids.m b/matlab/TCV_IMAS/tcv2ids.m
index 83662207267327b831b59dafa8fcb1c4cbcb589f..c94bea2bbefe53e7306ba693ec9ec9e9756914f7 100644
--- a/matlab/TCV_IMAS/tcv2ids.m
+++ b/matlab/TCV_IMAS/tcv2ids.m
@@ -54,6 +54,9 @@ p.addOptional('nverbose', 1, @(x) isempty(x) || isnumeric(x) );
 p.addOptional('time_out', [], @(x) isempty(x) || isnumeric(x) );
 p.addOptional('trialindx', [], @(x) isempty(x) || isnumeric(x) );
 p.addOptional('liuqe', [], @(x) isempty(x) || isnumeric(x) );
+p.addOptional('cxrs_source_ti', [], @(x) isempty(x) || isnumeric(x) );
+p.addOptional('cxrs_source_ni', [], @(x) isempty(x) || isnumeric(x) );
+p.addOptional('ignore_dependencies', [], @(x) isempty(x) || isnumeric(x) );
 
 params_not_for_gdat_params = {'shot','ids_names'};
 
@@ -121,6 +124,15 @@ for i=1:length(gdat_params_fields)
   end
 end
 gdat_params.data_request = 'ids';
+
+%Check that the shot did not disrupt very early.
+if shot ~= -1
+  t_disrupted = gdat(shot,'time_disrupted()');
+  if t_disrupted.data <= 0.04 || t_disrupted.data > 128
+    error('the shot disrupted')
+  end
+end
+
 for i=1:length(params_tcv2ids.ids_names)
   ids_to_get = params_tcv2ids.ids_names{i};
   gdat_params.source = ids_to_get;
diff --git a/matlab/TCV_IMAS/tcv2ids2database.m b/matlab/TCV_IMAS/tcv2ids2database.m
index 916ec4384ddd538d5eb34659677ffbafba2a5204..57a1e6f05f6759e3f987035149c6df414658204e 100644
--- a/matlab/TCV_IMAS/tcv2ids2database.m
+++ b/matlab/TCV_IMAS/tcv2ids2database.m
@@ -24,6 +24,9 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin);
 %           'time_out': if 2 values provided: get all time data within that time interval
 %                       otherwise get values at these times provided in time_out (with linear interpolation and cst extrapolation)
 %           'trialindx': trial_indx for relevant nodes, in particular CONF kinetic profiles nodes
+%           'cxrs_source_ti': specify which sources to use for the charge exchange data and fits of ion temperature. Default all (1,2,3)
+%	    'cxrs_source_ni': specify which sources to use for the charge exchange data and fits of impurity density. Default all (1,2,3)
+%           'ignore_dependencies': ignore unfulfilled dependencies in extracting cxrs data
 %
 % example:
 %   ids_from_tcv = tcv2ids2database(62745,9999,'ids_names',{'pf_active'},'error_bar','added'); % to test only one ids
@@ -63,6 +66,10 @@ p.addOptional('b0sign_out', 0, @(x) isempty(x) || (isscalar(x) && (x==0 || x==-1
 p.addOptional('nverbose', 1, @(x) isempty(x) || isnumeric(x) );
 p.addOptional('time_out', [], @(x) isempty(x) || isnumeric(x) );
 p.addOptional('trialindx', [], @(x) isempty(x) || isnumeric(x) );
+p.addOptional('cxrs_source_ti', [], @(x) isempty(x) || isnumeric(x) );
+p.addOptional('cxrs_source_ni', [], @(x) isempty(x) || isnumeric(x) );
+p.addOptional('ignore_dependencies', [], @(x) isempty(x) || isnumeric(x) );
+
 
 p.parse;
 defaults_tcv2ids2database = p.Results; % to keep track of defaults
diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index e31c6fad1d3c8ebd29c07cfbd71aebcc8fbef9a0..23c36b372bbf7423626dfa2e76d1660bdbd06023 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -23,6 +23,16 @@ machine = 'tcv';
 tens_time = -1;
 tens_rho = -0.1;
 
+% Extract imas version
+imas_version_path = which('ids_gen');
+tokens = regexp(imas_version_path, 'IMAS/(\d+)', 'tokens');
+
+if ~isempty(tokens)
+    imas_major_version = str2double(tokens{1}{1});
+else
+    error('Problems loading IMAS');
+end
+
 if exist('gdat_params','var')
   [ids_core_profiles, params_cores_profiles] = ...
     tcv_ids_headpart(shot,ids_equil_empty,'cores_profiles','gdat_params',gdat_params,varargin{:});
@@ -35,6 +45,23 @@ end
 params_eff_ref = gdat_params; params_eff_ref.doplot=0;
 try params_eff_ref=rmfield(params_eff_ref,'source');catch;end % make sure no source (from ids def)
 
+
+% Find the times for cxrs integration for the various cxrs systems
+system_ref = '\\ATLAS::CXRS_%03d.ACQ:TIMING'; %or '\tcv_shot::top.atlas.acquired.cxrs.system_001.acq:timing'
+times_cxrs_integration = [];
+for ii = 1:12
+  system_names = sprintf(system_ref, ii);
+  warning('off');
+  timings_cxrs = gdat(params_cores_profiles.shot,system_names);
+  warning('off');
+  if timings_cxrs.data
+    period_name = regexp(timings_cxrs.data, 'PeriodName=''([^'']*)''', 'tokens', 'once');
+    time = gdat(params_cores_profiles.shot, period_name);
+    times_cxrs_integration = [times_cxrs_integration,time.data*1e-6];
+  end
+end
+
+
 % initialize description
 ids_core_profiles_description = [];
 
@@ -162,6 +189,32 @@ for ir=1:length(temp_1d.area.x) % map tmp_1d.area to core_profiles.time
   area_cpt(ir,:) = interpos(temp_1d.area.t,temp_1d.area.data(ir,:),ids_core_profiles.time,tens_time);
 end
 
+%% Extracting info about Thomson data
+% Need to check if the temperature is local or averaged. Best way is to check the data themselves
+te_local_time = gdat(params_cores_profiles.shot, '\proffit:local_time:teft');
+te_avg_time = gdat(params_cores_profiles.shot, '\proffit:avg_time:teft');
+te_conf = gdat(params_cores_profiles.shot, '\results::conf:te');
+
+if isequal(te_local_time.t, te_conf.t) || isequal(te_local_time.t, te_avg_time.t)
+  thomson_description = 'using Thomson scattering measurement at the given time';
+elseif isequal(te_avg_time.t, te_conf.t)
+  thomson_description = 'using Thomson scattering measurement averaged over respective width';
+else
+  thomson_description = 'unrecongnized';
+  warning('Time series for Thomson not recognized. Check CONF nodes')
+end
+
+% Dimension is larger but times are the same, data exists after the end of the shot till end of acquisition.
+% This is for now not used anywhere. The IDS chi_squared is for each datapoint, this is for the whole profile
+% To calculate individual chi_squared the weights are needed. Where are they stored?
+params_eff.data_request = '\tcv_shot::top.results.proffit.avg_time:teft_chi2';
+temp_1d.te_rho.chi_squared = gdat(params_cores_profiles.shot, params_eff);
+temp_1d_desc.te_rho_chi_squared = params_eff.data_request;
+
+
+time_measurement_width_all = gdat(params_cores_profiles.shot,'\tcv_shot::top.results.proffit.avg_time:time_avg');
+time_measurement_width_thomson = time_measurement_width_all.data(1) - time_measurement_width_all.data(2);
+
 it_thom = iround_os(temp_1d.te_rho.t,ids_core_profiles.time);
 for it=1:length(ids_core_profiles.time)
   % fill grid
@@ -185,6 +238,13 @@ for it=1:length(ids_core_profiles.time)
       size(ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.measured));
   ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.rho_tor_norm = temp_1d.te_rho.grids_1d.rhotornorm(:,it_thom(it));
   ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.source = {'Thomson, interpos fit'};
+  ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.time_measurement_slice_method.name='local';
+  ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.time_measurement_slice_method.index=0;
+  ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.time_measurement_slice_method.description= thomson_description;
+  ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.local = 1;
+  %ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.chi_squared = 
+  ids_core_profiles.profiles_1d{it}.electrons.temperature_fit.time_measurement_width = time_measurement_width_thomson;
+
   ids_core_profiles.profiles_1d{it}.electrons.density = temp_1d.fit.ne_rho.data(:,it);
   ids_core_profiles.profiles_1d{it}.electrons.density_thermal = ids_core_profiles.profiles_1d{it}.electrons.density;
   ids_core_profiles.profiles_1d{it}.electrons.density_fit.measured = temp_1d.ne_rho.data(:,it_thom(it));
@@ -192,6 +252,14 @@ for it=1:length(ids_core_profiles.time)
       size(ids_core_profiles.profiles_1d{it}.electrons.density_fit.measured));
   ids_core_profiles.profiles_1d{it}.electrons.density_fit.rho_tor_norm = temp_1d.ne_rho.grids_1d.rhotornorm(:,it_thom(it));
   ids_core_profiles.profiles_1d{it}.electrons.density_fit.source = {'Thomson, interpos fit'};
+  ids_core_profiles.profiles_1d{it}.electrons.density_fit.time_measurement_slice_method.name='local';
+  ids_core_profiles.profiles_1d{it}.electrons.density_fit.time_measurement_slice_method.index=0;
+  ids_core_profiles.profiles_1d{it}.electrons.density_fit.time_measurement_slice_method.description= thomson_description;
+  ids_core_profiles.profiles_1d{it}.electrons.density_fit.local = 1;
+  %ids_core_profiles.profiles_1d{it}.electrons.density_fit.chi_squared = 
+  ids_core_profiles.profiles_1d{it}.electrons.density_fit.time_measurement_width = time_measurement_width_thomson;
+
+
   ids_core_profiles.profiles_1d{it}.electrons.pressure_thermal = 1.6022e-19.*ids_core_profiles.profiles_1d{it}.electrons.density_thermal ...
       .* ids_core_profiles.profiles_1d{it}.electrons.temperature;
   % fill zeff
@@ -199,6 +267,7 @@ for it=1:length(ids_core_profiles.time)
       ones(size(ids_core_profiles.profiles_1d{it}.electrons.density));
 end
 
+if imas_major_version > 2
 zeff_error = 0.5;
 switch error_bar
  case 'delta'
@@ -240,25 +309,58 @@ switch error_bar
  otherwise
   error(['tcv_ids_bpol_loop: error_bar option not known: ' error_bar])
 end
+end
 
 %% ion struct
 % assume only D if no CXRS (need to ask how to check if H...)
 params_eff_fit1.data_request = 'cxrs';
+
+% Check that CXRS exists and that the fits are updated. Stop the generation if action should be taken.
+[index_hldsi, info_hldsi] = hldsi(params_cores_profiles.shot);
+
+if isfield(info_hldsi.CXRS, 'timefilled')
+  date_CXRS = datetime(info_hldsi.CXRS.timefilled, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss.SS');
+  date_CONF = datetime(info_hldsi.CONF.timefilled, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss.SS');
+
+  if date_CXRS > date_CONF
+    if (info_hldsi.CONF.trialindex{2}.index == 1) &&  strcmpi(info_hldsi.CONF.trialindex{2}.user{1}, 'ANANOCD_ANASRV ')
+      warning('Fits in conf nodes are not up to date with CXRS analysis.')
+      disp('Please run [status, info] = anaprofs_standard_no_currentdrive(shot,username,global_option);')
+    else
+      warning('Fits in conf nodes are not up to date with CXRS analysis.')
+      disp(strjoin({'The analysis was not automatic. Contact', info_hldsi.CONF.trialindex{2}.user{1}, 'for more info'}, ' '))
+    end
+    if ~isfield(gdat_params, 'ignore_dependencies')
+      error('Use the ignore_dependencies flag to extract the data anyway');
+    end
+  end
+else
+  warning('CXRS analysis was not performed. Please rerun if data is available')
+end
+
+% Extract ti here
+all_sources = [1,2,3,4,7];
+
+if isfield(gdat_params, 'cxrs_source_ti')
+  params_eff_fit1.source = gdat_params.cxrs_source_ti;
+else
+  params_eff_fit1.source = all_sources;
+end
+
 try
   temp_1d.cxrs_rho = gdat(params_cores_profiles.shot,params_eff_fit1);
   temp_1d_desc.cxrs_rho = params_eff_fit1.data_request;
 catch
   temp_1d.cxrs_rho.data = [];
+  temp_1d.cxrs_rho.error_bar = [];
   temp_1d_desc.cxrs_rho = ['Problem with gdat ' params_eff_fit1.data_request ' ; no data'];
 end
+
 params_eff_fit1.data_request = 'results.conf:ti';
 temp_1d.ti_conf_rho = gdat(params_cores_profiles.shot,params_eff_fit1);
-temp_1d_desc.ti_conf_rho = params_eff_fit1.data_request;
-params_eff_fit1.data_request = 'results.conf:ni';
-temp_1d.ni_conf_rho = gdat(params_cores_profiles.shot,params_eff_fit1);
-temp_1d_desc.ni_conf_rho = params_eff_fit1.data_request;
+temp_1d_desc.ti_conf_rho = [params_eff_fit1.data_request, ' which took data from ', temp_1d.ti_conf_rho.help];
 if ~isempty(temp_1d.cxrs_rho.data)
-  data_fullpath_raw = 'Ti(C sometimes B) from cxrs system 1 to 3';
+  data_fullpath_raw = ['Ti(C sometimes B) from cxrs system(s) ', char(strjoin(string(params_eff_fit1.source), ', '))];
   temp_1d.ti.raw = temp_1d.cxrs_rho.ti.raw;
   temp_1d.ti.raw.shot = temp_1d.cxrs_rho.shot;temp_1d.ti.raw.gdat_params = temp_1d.cxrs_rho.gdat_params;
   temp_1d.ti.raw.x =temp_1d.cxrs_rho.ti.raw.rho; temp_1d.ti.raw.t =temp_1d.cxrs_rho.t;
@@ -266,18 +368,100 @@ if ~isempty(temp_1d.cxrs_rho.data)
     data_fullpath_fit = 'Ti from fit from cxrs thus Ti(C)';
     temp_1d.ti.raw =get_grids_1d(temp_1d.ti.raw,2,1);
   else
-    data_fullpath_fit = 'Ti from fit in CONF node';
+    data_fullpath_fit = ['Ti from fit in CONF node, from call ', temp_1d_desc.ti_conf_rho];
   end
 else
-  data_fullpath_fit = 'Ti from fit in CONF node';
+  data_fullpath_fit = ['Ti from fit in CONF node, from call ', temp_1d_desc.ti_conf_rho];
 end
-temp_1d_desc.ti.raw = data_fullpath_fit;
+
 temp_1d.ti.fit = temp_1d.ti_conf_rho;
 temp_1d.ti.fit =get_grids_1d(temp_1d.ti.fit,1,1);
-temp_1d_desc.ti.fit = temp_1d_desc.ti_conf_rho;
+temp_1d_desc.ti.raw = data_fullpath_raw;
+temp_1d_desc.ti.fit = data_fullpath_fit;
+temp_1d_desc.ti.tot = ['Raw data taken from ', data_fullpath_raw, ' and fits taken from ', data_fullpath_fit];
+
+% Extract ni here
+params_eff_fit1.data_request = 'cxrs';
+if  isfield(gdat_params, 'cxrs_source_ni')
+  params_eff_fit1.source = gdat_params.cxrs_source_ni;
+else
+  params_eff_fit1.source = all_sources;
+end
+
+try
+  temp_1d.cxrs_rho = gdat(params_cores_profiles.shot,params_eff_fit1);
+  temp_1d_desc.cxrs_rho = params_eff_fit1.data_request;
+catch
+  temp_1d.cxrs_rho.data = [];
+  temp_1d.cxrs_rho.error_bar = [];
+  temp_1d_desc.cxrs_rho = ['Problem with gdat ' params_eff_fit1.data_request ' ; no data'];
+end
+
+% Extract sources to find integration time for each data
+mask_sources = zeros(size(temp_1d.cxrs_rho.ti.raw.data));
+
+% Retrive the source for each datapoint
+for isource = all_sources
+  try
+    params_eff_fit1.source = [isource];
+    temp_1d.cxrs_rho_partial = gdat(params_cores_profiles.shot,params_eff_fit1);
+    [isCommon, idxA] = ismember(temp_1d.cxrs_rho.ti.raw.data, temp_1d.cxrs_rho_partial.ti.raw.data);
+    isCommon = isource*isCommon;
+    mask_sources(isCommon ~= 0) = isCommon(isCommon ~= 0);
+  end
+end
+
+% Find the times for cxrs integration for the various cxrs systems
+system_ref = '\\ATLAS::CXRS_%03d.ACQ:TIMING'; %or '\tcv_shot::top.atlas.acquired.cxrs.system_001.acq:timing'
+times_cxrs_integration = [];
+for ii = 1:12
+  system_names = sprintf(system_ref, ii);
+  warning('off');
+  timings_cxrs = gdat(params_cores_profiles.shot,system_names);
+  warning('off');
+  if timings_cxrs.data
+    period_name = regexp(timings_cxrs.data, 'PeriodName=''([^'']*)''', 'tokens', 'once');
+    bursts_name = regexp(timings_cxrs.data, 'BurstsName=''([^'']*)''', 'tokens', 'once');
+
+    %period = gdat(params_cores_profiles.shot, period_name);
+    %bursts = gdat(params_cores_profiles.shot, bursts_name);
+    %time_aquisition = period.data * bursts.data;  %This is the total acquisition time in a shot.
+    time_acquisition = gdat(params_cores_profiles.shot, period_name);
+    times_cxrs_integration = [times_cxrs_integration,time_acquisition.data.*1e-6];
+  else
+    times_cxrs_integration = [times_cxrs_integration,0];
+  end
+end
+
+% Assign widths of integration time 
+widths = zeros(size(temp_1d.cxrs_rho.ti.raw.data));
+for isource = all_sources
+  widths(mask_sources == isource) = times_cxrs_integration(isource);
+end
+
+params_eff_fit1.data_request = 'results.conf:ni';
+temp_1d.ni_conf_rho = gdat(params_cores_profiles.shot,params_eff_fit1);
+temp_1d_desc.ni_conf_rho = [params_eff_fit1.data_request, ' which took data from ', temp_1d.ni_conf_rho.help];
+if ~isempty(temp_1d.cxrs_rho.data)
+  data_fullpath_raw = ['ni(C sometimes B) from cxrs system(s) ', char(strjoin(string(params_eff_fit1.source), ', '))];
+  temp_1d.ni.raw = temp_1d.cxrs_rho.ni.raw;
+  temp_1d.ni.raw.shot = temp_1d.cxrs_rho.shot;temp_1d.ni.raw.gdat_params = temp_1d.cxrs_rho.gdat_params;
+  temp_1d.ni.raw.x =temp_1d.cxrs_rho.ni.raw.rho; temp_1d.ni.raw.t =temp_1d.cxrs_rho.t;
+  if ~isempty(temp_1d.cxrs_rho.ni.raw.data)
+    data_fullpath_fit = 'ni from fit from cxrs thus ni(C)';
+    temp_1d.ni.raw =get_grids_1d(temp_1d.ni.raw,2,1);
+  else
+    data_fullpath_fit = ['ni from fit in CONF node, from call ', temp_1d_desc.ni_conf_rho];
+  end
+else
+  data_fullpath_fit = ['ni from fit in CONF node, from call ', temp_1d_desc.ni_conf_rho];
+end
+temp_1d_desc.ni.raw = data_fullpath_fit;
 temp_1d.ni.fit = temp_1d.ni_conf_rho;
 temp_1d.ni.fit =get_grids_1d(temp_1d.ni.fit,1,1);
 temp_1d_desc.ni.fit = temp_1d_desc.ni_conf_rho;
+temp_1d_desc.ni.tot = ['Raw data taken from ', data_fullpath_raw, ' and fits taken from ', data_fullpath_fit];
+
 it_ti = iround_os(temp_1d.ti.fit.t,ids_core_profiles.time);
 % assumed 1 impurity with Zp=6
 Zp = 6.;
@@ -312,6 +496,7 @@ for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.ion{2}.z_ion = 6.;
   ids_core_profiles.profiles_1d{it}.ion{2}.multiple_states_flag = 0;
   ids_core_profiles.profiles_1d{it}.ion{2}.temperature = ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
+
   ids_core_profiles.profiles_1d{it}.ion{2}.density = (ids_core_profiles.profiles_1d{it}.electrons.density - ids_core_profiles.profiles_1d{it}.ion{1}.density) ./ ids_core_profiles.profiles_1d{it}.ion{2}.z_ion;
   ids_core_profiles.profiles_1d{it}.ion{2}.density_thermal = ids_core_profiles.profiles_1d{it}.ion{2}.density;
   ids_core_profiles.profiles_1d{it}.ion{2}.pressure_thermal = 1.6022e-19.*ids_core_profiles.profiles_1d{it}.ion{2}.density_thermal ...
@@ -329,13 +514,90 @@ end
 if ~isempty(temp_1d.cxrs_rho.data) && ~isempty(temp_1d.cxrs_rho.ti.fit.data)
   it_raw = iround_os(temp_1d.ti.raw.t,ids_core_profiles.time);
   for it=1:length(ids_core_profiles.time)
-    % ids_core_profiles.profiles_1d{it}.ion{1}.temperature_fit = temp_1d.ti.fit(:,it_ti(it));
-    ids_core_profiles.profiles_1d{it}.ion{1}.density_fit.source = {'from Zeff and ne profile'};
-    ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured = temp_1d.ti.raw.data(:,it_raw(it));
-    ids_core_profiles.profiles_1d{it}.t_i_average_fit.source = {'from CXRS on C usually'};
+    ids_core_profiles.profiles_1d{it}.ion{2}.temperature_fit.measured = temp_1d.ti.raw.data(:,it_raw(it));
+    ids_core_profiles.profiles_1d{it}.ion{2}.temperature_fit.source = temp_1d_desc.ti.tot;
+    ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured = temp_1d.ni.raw.data(:,it_raw(it));
+    ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.source = temp_1d_desc.ni.tot;
+    ids_core_profiles.profiles_1d{it}.ion{2}.rho_tor_norm = temp_1d.cxrs_rho.ti.raw.rho(:,it_raw(it));
+    ids_core_profiles.profiles_1d{it}.ion{2}.time_measurement = temp_1d.ti.raw.t(it_raw(it));
+    ids_core_profiles.profiles_1d{it}.ion{2}.time_measurement_slice_method.name = 'local';
+    ids_core_profiles.profiles_1d{it}.ion{2}.time_measurement_slice_method.index = 0;
+    ids_core_profiles.profiles_1d{it}.ion{2}.time_measurement_slice_method.description = 'Using cxrs at given time';
+    ids_core_profiles.profiles_1d{it}.ion{2}.time_measurement_width = widths(:,it_raw(it));
+
+    ids_core_profiles.profiles_1d{it}.ion{1}.temperature_fit = ids_core_profiles.profiles_1d{it}.ion{2}.temperature_fit;
+    ids_core_profiles.profiles_1d{it}.ion{1}.density_fit.source = {'Same as C temperature'};
+
+    ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured = ids_core_profiles.profiles_1d{it}.ion{2}.temperature_fit;
+    ids_core_profiles.profiles_1d{it}.t_i_average_fit.source = {'Same as C temperature'};
+    ids_core_profiles.profiles_1d{it}.t_i_average_fit.rho_tor_norm = ids_core_profiles.profiles_1d{it}.ion{2}.rho_tor_norm;
+    ids_core_profiles.profiles_1d{it}.t_i_average_fit.time_measurement = ids_core_profiles.profiles_1d{it}.ion{2}.time_measurement;
+
   end
 end
 
+if ~isempty(temp_1d.cxrs_rho.error_bar) && imas_major_version > 2
+  switch error_bar
+   case 'delta'
+     for it=1:length(ids_core_profiles.time)
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_upper = temp_1d.cxrs_rho.ti.raw.error_bar(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_upper = temp_1d.cxrs_rho.ti.raw.error_bar(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.rho_tor_norm = temp_1d.cxrs_rho.ti.raw.rho(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.rho_tor_norm_error_upper = temp_1d.cxrs_rho.ti.raw.error_bar_rho(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.time_measurement = temp_1d.ti.raw.t(it_raw(it));
+     end
+   case 'delta_with_lower'
+     for it=1:length(ids_core_profiles.time)
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_upper = temp_1d.cxrs_rho.error_bar(:,it_thom(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_lower = ...
+           ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_upper;
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.time_measurement = temp_1d.ti.raw.t(it_raw(it));
+     end
+   case 'added'
+     for it=1:length(ids_core_profiles.time)
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_upper = ...
+           ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured ...
+           + temp_1d.cxrs_rho.error_bar(:,it_thom(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured_error_lower = ...
+           ids_core_profiles.profiles_1d{it}.t_i_average_fit.measured ...
+           - temp_1d.cxrs_rho.error_bar(:,it_thom(it));
+       ids_core_profiles.profiles_1d{it}.t_i_average_fit.time_measurement = temp_1d.ti.raw.t(it_raw(it));
+     end
+   otherwise
+     error(['tcv_ids_cxrs_extraction: error_bar option not known: ' error_bar])
+  end
+  switch error_bar
+   case 'delta'
+     for it=1:length(ids_core_profiles.time)
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_upper = temp_1d.cxrs_rho.ni.raw.error_bar(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_upper = temp_1d.cxrs_rho.ni.raw.error_bar(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.rho_tor_norm = temp_1d.cxrs_rho.ni.raw.rho(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.rho_tor_norm_error_upper = temp_1d.cxrs_rho.ni.raw.error_bar_rho(:,it_raw(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.time_measurement = temp_1d.ni.raw.t(it_raw(it));
+     end
+   case 'delta_with_lower'
+     for it=1:length(ids_core_profiles.time)
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_upper = temp_1d.cxrs_rho.error_bar(:,it_thom(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_lower = ...
+           ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_upper;
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.time_measurement = temp_1d.ni.raw.t(it_raw(it));
+     end
+   case 'added'
+     for it=1:length(ids_core_profiles.time)
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_upper = ...
+           ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured ...
+           + temp_1d.cxrs_rho.error_bar(:,it_thom(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured_error_lower = ...
+           ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.measured ...
+           - temp_1d.cxrs_rho.error_bar(:,it_thom(it));
+       ids_core_profiles.profiles_1d{it}.ion{2}.density_fit.time_measurement = temp_1d.ni.raw.t(it_raw(it));
+     end
+   otherwise
+     error(['tcv_ids_cxrs_extraction: error_bar option not known: ' error_bar])
+  end
+end
+
+
 %% q profile and magnetic shear
 params_eff.data_request = 'q_rho';
 temp_1d.q = gdat(params_cores_profiles.shot,params_eff);