diff --git a/matlab/TCV_IMAS/README b/matlab/TCV_IMAS/README
index 9dd6086ce2ce67e712e1a1497b3f2f751e6632f5..4051c6b05a5e475fada194fc9dff1584f05b4533 100644
--- a/matlab/TCV_IMAS/README
+++ b/matlab/TCV_IMAS/README
@@ -2,7 +2,7 @@
 %
 % generate empty ids structures, from gateway in imasenv, get list and then generate present known ids
 %
-ids_list_all=ids_list;
+ids_list_all=IDS_list;
 
 % ids_list_to_generate = tcv_available_ids;
 ids_list_to_generate = ids_list_all;
@@ -12,3 +12,6 @@ for i=1:length(ids_list_to_generate)
 end
 
 % save ids_structures_IMAS326.mat ids_structures ids_list_to_generate ids_list_all
+% then use ids_structures_mat_to_m to save all the structures as ids_empty_xx.m files
+% [empty_dir_out] = ids_structures_mat_to_m('/tmp/sautero/ids_structures_IMAS331.mat','/tmp/sautero/ids_empty')
+%
diff --git a/matlab/TCV_IMAS/ids2database.m b/matlab/TCV_IMAS/ids2database.m
index f2b887ba90b8d714455d434603a56fdc641a0e99..c7d4a061a3a0e3c32f20f8b260a5da99fe771805 100644
--- a/matlab/TCV_IMAS/ids2database.m
+++ b/matlab/TCV_IMAS/ids2database.m
@@ -82,10 +82,10 @@ params_ids2database = params;
 % check ids_names
 ids_names=fieldnames(ids2put);
 try
-  if exist('ids_list')
-    ids_full_list = ids_list;
-  else
+  if exist('IDS_list')
     ids_full_list = IDS_list;
+  else
+    ids_full_list = ids_list;
   end
 catch
   ids_full_list = tcv_available_ids;
diff --git a/matlab/TCV_IMAS/ids_structures_mat_to_m.m b/matlab/TCV_IMAS/ids_structures_mat_to_m.m
index 0aae46806bdf07f4ee7fd7ddac6bccc17df8e761..88f29ac2daa36dc47e2980fddd2e010455b30b70 100644
--- a/matlab/TCV_IMAS/ids_structures_mat_to_m.m
+++ b/matlab/TCV_IMAS/ids_structures_mat_to_m.m
@@ -1,13 +1,24 @@
+function [empty_dir_out] = ids_structures_mat_to_m(mat_filename,emptydirname)
 %%
 % auxiliary script to write .mat containing empty IDS to separate .m files
 % in ids_empty_folder
+%
+% Example:
+% [empty_dir_out] = ids_structures_mat_to_m('/tmp/sautero/ids_structures_IMAS331.mat','/tmp/sautero/ids_empty')
+%
+if nargin < 1 || isempty(mat_filename)
+  error('requires mat filename');
+  return
+end
+if nargin < 2 || isempty(emptydirname)
+  target_folder = 'ids_empty';
+else
+  target_folder = emptydirname;
+end
+empty_dir_out = target_folder;
 
-clear;
-cd(fileparts(mfilename('fullpath')));
-ids_struct_saved = '/home/sauter/matlab/gdat_develop/matlab/TCV_IMAS/ids_structures_20190312.mat';
-ids_struct_saved = '/home/sauter/matlab/gdat_develop/matlab/TCV_IMAS/ids_structures_IMAS326.mat';
-target_folder = 'ids_empty';
-ffolder = fullfile(fileparts(mfilename('fullpath')),target_folder);
+ids_struct_saved = mat_filename;
+ffolder = fullfile(target_folder);
 assert(~~exist(ffolder,'dir'),'target folder does not exist')
 
 load(ids_struct_saved);
@@ -19,7 +30,7 @@ okflag = writecell(fields,fullfile(ffolder,'ids_list_all'),15);
 assert(okflag,'problem writing cell array');
 assert(isequaln(fields,eval('ids_list_all'))); % check
 %% write individual files per ids template
-
+addpath(ffolder)
 for ii=1:numel(fields)
   myfield = fields{ii};
   fieldval = ids_structures.(myfield);
@@ -33,13 +44,10 @@ for ii=1:numel(fields)
   assert(okflag,'failed writing %s',fpath);
 
   try
-    cd ids_empty
     S_out = eval(fname);
     assert(isequaln(fieldval,S_out),'fields not equal %s',myfield);
-    cd ..
   catch ME
-    cd ..
-keyboard
+    keyboard
     rethrow(ME)
   end
 end
diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index b0f5f54ca8966b116ec1f01683618b5d92f1cc74..2891e6dd8eb526d7740d301ba93a1edcc597bd27 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -268,13 +268,13 @@ for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.ion{1}.element{1}.a = 2.;
   ids_core_profiles.profiles_1d{it}.ion{1}.element{1}.z_n = 1;
   ids_core_profiles.profiles_1d{it}.ion{1}.element{1}.atoms_n = 1;
+  ids_core_profiles.profiles_1d{it}.ion{1}.z_ion = 1;
   ids_core_profiles.profiles_1d{it}.ion{1}.multiple_states_flag = 0;
   ids_core_profiles.profiles_1d{it}.ion{1}.temperature = temp_1d.ti.fit.data(:,it_ti(it));
   ids_core_profiles.profiles_1d{it}.ion{1}.density = (temp_1d.ni.fit.data(:,it_ti(it)).*Zp-ids_core_profiles.profiles_1d{it}.electrons.density)./(Zp-1.);
   ids_core_profiles.profiles_1d{it}.ion{1}.density_thermal = ids_core_profiles.profiles_1d{it}.ion{1}.density;
   ids_core_profiles.profiles_1d{it}.ion{1}.pressure_thermal = 1.6022e-19.*ids_core_profiles.profiles_1d{it}.ion{1}.density_thermal ...
       .* ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
-  ids_core_profiles.profiles_1d{it}.ion{1}.z_ion = 1;
   ids_core_profiles.profiles_1d{it}.ion{1}.label = 'D+';
   %
   ids_core_profiles.profiles_1d{it}.t_i_average = ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
@@ -289,13 +289,13 @@ for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.ion{2}.element{1}.a = 12.;
   ids_core_profiles.profiles_1d{it}.ion{2}.element{1}.z_n = 6.;
   ids_core_profiles.profiles_1d{it}.ion{2}.element{1}.atoms_n = 1.;
+  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}.element{1}.z_ion;
+  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 ...
       .* ids_core_profiles.profiles_1d{it}.ion{2}.temperature;
-  ids_core_profiles.profiles_1d{it}.ion{2}.z_ion = 6.;
   ids_core_profiles.profiles_1d{it}.ion{2}.label = 'C6+';
   % average/sums
   ids_core_profiles.profiles_1d{it}.t_i_average = ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
diff --git a/matlab/TCV_IMAS/tcv_get_ids_nbi.m b/matlab/TCV_IMAS/tcv_get_ids_nbi.m
index 1c2ca51b57f56a17482edbc9279390d8d140279d..b9d20aea7c5c587c4208252cfdd09b66502b0f4a 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_nbi.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_nbi.m
@@ -120,13 +120,27 @@ for iunit=1:nb_units
   %     ids_nbi.unit{iunit}.beamlets_group{1}.width_vertical_error_index: -999999999
   %     ids_nbi.unit{iunit}.beamlets_group{1}.width_vertical_error_lower: -9.0000e+40
   %     ids_nbi.unit{iunit}.beamlets_group{1}.width_vertical_error_upper: -9.0000e+40
-  ids_nbi.unit{iunit}.beamlets_group{1}.focus = beamlets_group.focus(iunit);
+
+  % Should always copy "leaves" only to avoid deleting non-filled in values like error_bars
+  fields_to_copy = fieldnames(beamlets_group.focus(iunit));
+  for i=1:numel(fields_to_copy)
+    ids_nbi.unit{iunit}.beamlets_group{1}.focus.(fields_to_copy{i}) = beamlets_group.focus(iunit).(fields_to_copy{i});
+  end
   %% divergence component struct
-  ids_nbi.unit{iunit}.beamlets_group{1}.divergence_component{1} = beamlets_group.divergence(iunit);
+  fields_to_copy = fieldnames(beamlets_group.divergence(iunit));
+  for i=1:numel(fields_to_copy)
+    ids_nbi.unit{iunit}.beamlets_group{1}.divergence_component{1}.(fields_to_copy{i}) = beamlets_group.divergence(iunit).(fields_to_copy{i});
+  end
   %% tilting
   % it is fixed in time. what should we do about it?
+  % At this stage empty, so need empty cell, otherwise provide 2 time points with same values
+  ids_nbi.unit{iunit}.beamlets_group{1}.tilting = {};
+
   %% position
-  ids_nbi.unit{iunit}.beamlets_group{1}.position = beamlets_group.position(iunit);
+  fields_to_copy = fieldnames(beamlets_group.position(iunit));
+  for i=1:numel(fields_to_copy)
+    ids_nbi.unit{iunit}.beamlets_group{1}.position.(fields_to_copy{i}) = beamlets_group.position(iunit).(fields_to_copy{i});
+  end
 
   %% beamlets
   % M. Vallar thinks it is useless now