function [ids_bolometer,ids_bolometer_description] =  ...
    tcv_get_ids_bolometer(shot, ids_bolometer_empty, gdat_params,varargin)
%
% [ids_bolometer,ids_bolometer_description] = ...
%   tcv_get_ids_bolometer(shot, ids_bolometer_empty,varargin);
%
% Get the bolometer diagnostics data
%
% ids_bolometer_empty should at least be the empty bolometer ids structure 
% in input
%
% gdat_params: gdat_data.gdat_params to get all params passed from original
% call, in particular error_bar options
%
% Date: 20/09/24
% Author: L. Simons

% Initialise structure with default ids_properties
% shot=70777; gdat_params=[]; varargin={};
% aa=gdat([],'ids','source','bolometer'); ids_bolometer_empty=aa.bolometer;
if exist('gdat_params')
  [ids_bolometer, ~] = tcv_ids_headpart(shot, ids_bolometer_empty, ...
    'bolometer','homogeneous_time',1,'gdat_params',gdat_params, ...
     varargin{:});
else
  [ids_bolometer, ~] = tcv_ids_headpart(shot,ids_bolometer_empty,'bolometer','homogeneous_time',0,varargin{:});
end

ids_bolometer_description = struct();

% Load the bolometer geometry
bolo_geom=bolou_load_geometry();


params_eff.data_request='\tcv_shot::top.results.bolo_u.intensity';
params_eff.trialindx=1;
params_eff.machine='tcv';
params_eff.doplot=0;
bolo_u_intensity = gdat(shot,params_eff);
params_eff.data_request='\tcv_shot::top.results.bolo_u.prad';
bolo_u_prad = gdat(shot,params_eff);
params_eff.data_request='\tcv_shot::top.results.bolo_u.prad_core';
bolo_u_prad_core = gdat(shot,params_eff);
params_eff.data_request='\tcv_shot::top.results.bolo_u.confidence';
bolo_u_confidence = gdat(shot,params_eff);

status = ~ischar(bolo_u_intensity.data) & ~ischar(bolo_u_prad_core.data);
imas_version_number=getenv('IMAS_VERSION')
if status
  nchannel = numel(bolo_u_intensity.x);
  ids_bolometer.channel(1:nchannel) = ids_bolometer.channel(1);
  for ii = 1:nchannel
    
    ids_bolometer.channel{ii}.name = bolo_geom.channel{ii}.name;

    if strcmp(aa(1),'3')
        ids_bolometer.channel{ii}.identifier = bolo_geom.channel{ii}.identifier;
    elseif strcmp(aa(1),'4')
        ids_bolometer.channel{ii}.description = bolo_geom.channel{ii}.identifier;
    end

    ids_bolometer.channel{ii}.detector.geometry_type= bolo_geom.channel{ii}.detector.geometry_type;
    ids_bolometer.channel{ii}.detector.centre.phi= bolo_geom.channel{ii}.detector.centre.phi;
    ids_bolometer.channel{ii}.detector.centre.r= bolo_geom.channel{ii}.detector.centre.r;
    ids_bolometer.channel{ii}.detector.centre.z= bolo_geom.channel{ii}.detector.centre.z;
    ids_bolometer.channel{ii}.detector.x1_unit_vector.x= bolo_geom.channel{ii}.detector.x1_unit_vector.x;
    ids_bolometer.channel{ii}.detector.x1_unit_vector.y= bolo_geom.channel{ii}.detector.x1_unit_vector.y;
    ids_bolometer.channel{ii}.detector.x1_unit_vector.z= bolo_geom.channel{ii}.detector.x1_unit_vector.z;
    ids_bolometer.channel{ii}.detector.x2_unit_vector.x= bolo_geom.channel{ii}.detector.x2_unit_vector.x;
    ids_bolometer.channel{ii}.detector.x2_unit_vector.y= bolo_geom.channel{ii}.detector.x2_unit_vector.y;
    ids_bolometer.channel{ii}.detector.x2_unit_vector.z= bolo_geom.channel{ii}.detector.x2_unit_vector.z;
    ids_bolometer.channel{ii}.detector.x3_unit_vector.x= bolo_geom.channel{ii}.detector.x3_unit_vector.x;
    ids_bolometer.channel{ii}.detector.x3_unit_vector.y= bolo_geom.channel{ii}.detector.x3_unit_vector.y;
    ids_bolometer.channel{ii}.detector.x3_unit_vector.z= bolo_geom.channel{ii}.detector.x3_unit_vector.z;
    ids_bolometer.channel{ii}.detector.x1_width= bolo_geom.channel{ii}.detector.x1_width;
    ids_bolometer.channel{ii}.detector.x2_width= bolo_geom.channel{ii}.detector.x2_width;
    ids_bolometer.channel{ii}.detector.surface= bolo_geom.channel{ii}.detector.surface;
    
    ids_bolometer.channel{ii}.aperture{1}.geometry_type= bolo_geom.channel{ii}.aperture{1}.geometry_type;
    ids_bolometer.channel{ii}.aperture{1}.centre.r= bolo_geom.channel{ii}.aperture{1}.centre.r;
    ids_bolometer.channel{ii}.aperture{1}.centre.z= bolo_geom.channel{ii}.aperture{1}.centre.z;
    ids_bolometer.channel{ii}.aperture{1}.x1_unit_vector.x= bolo_geom.channel{ii}.aperture{1}.x1_unit_vector.x;
    ids_bolometer.channel{ii}.aperture{1}.x1_unit_vector.y= bolo_geom.channel{ii}.aperture{1}.x1_unit_vector.y;
    ids_bolometer.channel{ii}.aperture{1}.x1_unit_vector.z= bolo_geom.channel{ii}.aperture{1}.x1_unit_vector.z;
    ids_bolometer.channel{ii}.aperture{1}.x2_unit_vector.x= bolo_geom.channel{ii}.aperture{1}.x2_unit_vector.x;
    ids_bolometer.channel{ii}.aperture{1}.x2_unit_vector.y= bolo_geom.channel{ii}.aperture{1}.x2_unit_vector.y;
    ids_bolometer.channel{ii}.aperture{1}.x2_unit_vector.z= bolo_geom.channel{ii}.aperture{1}.x2_unit_vector.z;
    ids_bolometer.channel{ii}.aperture{1}.x3_unit_vector.x= bolo_geom.channel{ii}.aperture{1}.x3_unit_vector.x;
    ids_bolometer.channel{ii}.aperture{1}.x3_unit_vector.y= bolo_geom.channel{ii}.aperture{1}.x3_unit_vector.y;
    ids_bolometer.channel{ii}.aperture{1}.x3_unit_vector.z= bolo_geom.channel{ii}.aperture{1}.x3_unit_vector.z;
    ids_bolometer.channel{ii}.aperture{1}.x1_width= bolo_geom.channel{ii}.aperture{1}.x1_width;
    ids_bolometer.channel{ii}.aperture{1}.x2_width= bolo_geom.channel{ii}.aperture{1}.x2_width;
    ids_bolometer.channel{ii}.aperture{1}.surface= bolo_geom.channel{ii}.aperture{1}.surface;
    
    ids_bolometer.channel{ii}.etendue = bolo_geom.channel{ii}.etendue;
    ids_bolometer.channel{ii}.etendue_method.name = bolo_geom.channel{ii}.etendue_method.name;
    ids_bolometer.channel{ii}.etendue_method.description = bolo_geom.channel{ii}.etendue_method.description;
    
    ids_bolometer.channel{ii}.line_of_sight.first_point.phi = bolo_geom.channel{ii}.line_of_sight.first_point.phi;
    ids_bolometer.channel{ii}.line_of_sight.first_point.r = bolo_geom.channel{ii}.line_of_sight.first_point.r;
    ids_bolometer.channel{ii}.line_of_sight.first_point.z = bolo_geom.channel{ii}.line_of_sight.first_point.z;
    
    ids_bolometer.channel{ii}.line_of_sight.second_point.phi = bolo_geom.channel{ii}.line_of_sight.second_point.phi;
    ids_bolometer.channel{ii}.line_of_sight.second_point.r = bolo_geom.channel{ii}.line_of_sight.second_point.r;
    ids_bolometer.channel{ii}.line_of_sight.second_point.z = bolo_geom.channel{ii}.line_of_sight.second_point.z;
    
    ids_bolometer.channel{ii}.power.data = bolo_u_intensity.data(ii,:);
    ids_bolometer_description.channel{ii}.power.data = ...
        ['From results.bolo_u.intensity data, Radiance measured by ' ...
        'each bolometer foil in units of [W/m^{2}sr]'];
    ids_bolometer.channel{ii}.power.t = bolo_u_intensity.t;
    ids_bolometer_description.channel{ii}.power.data = ...
        ['From results.bolo_u.intensity dim{1}, time basis of radiance'];
    ids_bolometer.channel{ii}.validity = 0; % FIXME: Always valid data
    ids_bolometer.channel{ii}.power_radiated_total = bolo_u_prad.data;
    ids_bolometer_description.channel{ii}.power_radiated_total = ...
        ['From results.bolo_u.prad data, Total radiated power measured by ' ...
        'the bolometer system in units of [kW]'];
%     ids_bolometer.channel{ii}.power_radiated_total_error_upper = ...
%         0.*bolo_u_prad.data; % FIXME: Zero error
%     ids_bolometer.channel{ii}.power_radiated_total_error_lower = ...
%         0.*bolo_u_prad.data; % FIXME: Zero error
    ids_bolometer.channel{ii}.power_radiated_inside_lcfs =  ...
        bolo_u_prad_core.data;
    ids_bolometer_description.channel{ii}.power_radiated_inside_lcfs.data = ...
        ['From results.bolo_u.prad_core data, Total radiated power ' ...
        'radiated from inside the last closed flux surface in units of [kW]'];
%     ids_bolometer.channel{ii}.power_radiated_inside_lcfs_error_upper =  ...
%         0.*bolo_u_prad_core.data;
%     ids_bolometer.channel{ii}.power_radiated_inside_lcfs_error_lower =  ...
%         0.*bolo_u_prad_core.data;
    ids_bolometer.channel{ii}.power_radiated_validity = 0*bolo_u_prad.data;
    
    ids_bolometer.power_radiated_inside_lcfs = bolo_u_prad_core.data;
    ids_bolometer.power_radiated_total = bolo_u_prad.data;
    ids_bolometer.power_radiated_validity = 0*bolo_u_prad.data;
  end
  ids_bolometer.code.name = 'rc_gti_prep';
  ids_bolometer.code.description = ...
    ['rc_gti_prep, RADCAM gitlab repo, calls GTI to generate emissivity profiles with liuqe.']
%    '/usr/local/bin/matlab960 -nojvm -nosplash -nodisplay -r ' ...
%    '"anasrvmat(''rc_gti_prep'',$2,[0 2.2],''bolo'', 10, 1, 0.04, 30,' ...
%    'false, false,false, [], ''automated'', 1)"'];
  ids_bolometer.code.commit='';
  ids_bolometer.code.version='';
  ids_bolometer.code.repository= ...
      'https://gitlab.epfl.ch/spc/tcv/diag/radcam/';
  ids_bolometer.code.parameters='';
  ids_bolometer.code.library{1}.name = 'meq';
  ids_bolometer.code.library{1}.description = 'Magnetic equilibrium';
  ids_bolometer.code.library{1}.commit = '';
  ids_bolometer.code.library{1}.version = '';
  ids_bolometer.code.library{1}.repository = ...
      'https://gitlab.epfl.ch/spc/tcv/tbx/meq';
  ids_bolometer.code.library{1}.parameters = '';
  ids_bolometer.code.library{2}.name = 'GTI';
  ids_bolometer.code.library{2}.description = ...
      'General Tomographic Inversion';
  ids_bolometer.code.library{2}.commit = '';
  [a1,a2]=unix('git rev-parse --verify HEAD');
  [b1,b2]=unix('git rev-parse --abbrev-ref HEAD');
  ids_bolometer.code.library{2}.version = sprintf('%s_branch_%s',strtrim(a2),strtrim(b2));
  ids_bolometer.code.library{2}.repository = ...
      'https://gitlab.epfl.ch/spc/tcv/analysis/gti';
  ids_bolometer.code.library{2}.parameters = '';
  
  
  % FIXME: Values of bolo_u_confidence don't match output_flag
  ids_bolometer.code.output_flag=bolo_u_confidence; 
  ids_bolometer.time = bolo_u_intensity.t;
else
  warning('Failed to load data for shot %d',shot);
end

end
