function [sub_ids_struct_out,sub_ids_struct_out_description, varargout] =  tcv_ids_bpol_probe(shot, ids_structures, gdat_params, varargin)
%
% [sub_ids_struct_out,sub_ids_struct_out_description, varargout] =  tcv_ids_bpol_probe(shot, ids_structures, gdat_params, varargin)
%
% Get magnetics.bpol_probe
%
% error_bar: from gdat_params.error_bar
%            'relative' (default): value to be added
%            'added': value already added to data: data +- error_bar
%

error_bar = 'relative';
if exist('gdat_params') && isfield(gdat_params,'error_bar') && ~isempty(gdat_params.error_bar)
  error_bar = gdat_params.error_bar;
end

% Get data 
tmp = gdat_tcv( shot, '\MAGNETICS::BPOL_003');
names = tmp.dim{2};
time = tmp.dim{1};
data = tmp.data;
ang_m = gdat_tcv( shot, 'static("ANG_M")');

% Preallocate output structure
Nprobes = size(tmp.data,2);
sub_ids_struct_out(1:Nprobes) = ids_structures;

for ii=1:Nprobes
    sub_ids_struct_out{ii}.name  = [names{ii}];  
    sub_ids_struct_out_description{ii}.name  = [names{ii}];
    sub_ids_struct_out{ii}.position.r  = mdsvalue('STATIC("R_M"  )[$1]',sub_ids_struct_out{ii}.name);
    sub_ids_struct_out_description{ii}.position_r  = ['from ''STATIC("R_M"  )[' sub_ids_struct_out{ii}.name ']'''];
    sub_ids_struct_out{ii}.position.z  = mdsvalue('STATIC("Z_M"  )[$1]',sub_ids_struct_out{ii}.name); 
    sub_ids_struct_out_description{ii}.position_z  = ['from ''STATIC("Z_M"  )[' sub_ids_struct_out{ii}.name ']'''];
    sub_ids_struct_out{ii}.field.data  =  data(:,ii);
    sub_ids_struct_out_description{ii}.field_data  =  'from ''\MAGNETICS::BPOL_003''';
    sub_ids_struct_out{ii}.field.time  =  time; 
    
    sub_ids_struct_out{ii}.toroidal_angle  =  0.; % to see if should match sector 3 (bpol003)
    aa =  gdat_tcv( shot, ['static("ANG_M")[$1]'',''' sub_ids_struct_out{ii}.name '']); 
    sub_ids_struct_out{ii}.poloidal_angle  = aa.data;
    sub_ids_struct_out_description{ii}.poloidal_angle  = ['from ' aa.data_fullpath];
    sub_ids_struct_out_description{ii}.toroidal_angle = 'set to 0 although BPOL_003 means sector 3';
end

fixed_error = 0.009999999776483;
switch error_bar
 case 'relative'
  for ii=1:Nprobes
    sub_ids_struct_out{ii}.field.data_error_upper = fixed_error.*ones(size(sub_ids_struct_out{ii}.field.data));% TO BE FOUND;   
  sub_ids_struct_out_description{ii}.field_data_error_upper = ['from fixed error value in case ' error_bar];
  sub_ids_struct_out_description{ii}.field_data_error_lower = ['not provided since symmetric'];
  end
 case 'added'
  for ii=1:Nprobes 
    sub_ids_struct_out{ii}.field.data_error_upper = sub_ids_struct_out{ii}.field.data + fixed_error.*ones(size(sub_ids_struct_out{ii}.field.data));
    sub_ids_struct_out{ii}.field.data_error_lower = sub_ids_struct_out{ii}.field.data - fixed_error.*ones(size(sub_ids_struct_out{ii}.field.data));
    sub_ids_struct_out_description{ii}.field_data_error_upper = ['from data + fixed error value in case ' error_bar];
    sub_ids_struct_out_description{ii}.field_data_error_lower = ['from data - fixed error value in case ' error_bar];
  end
 otherwise
  error(['tcv_ids_bpol_loop: error_bar option not known: ' error_bar])
end


  

