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();
bolo_geom_gitinfo= ...
    tcv_get_deploymentinfo(fullfile(fileparts(which('bolou_load_geometry')), ...
    '.this-deployment.info'));

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
    
    %% Fill geometry information
    % Fill information from bolo_geom=bolou_load_geometry();
    ids_bolometer.channel{ii}.name = bolo_geom.channel{ii}.name;
    if strcmp(imas_version_number(1),'3')
        ids_bolometer.channel{ii}.identifier = bolo_geom.channel{ii}.identifier;
    elseif strcmp(imas_version_number(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;
    
    
    %% Fill measurement information
%     '\tcv_shot::top.results.bolo_u.prad';
%     '\tcv_shot::top.results.bolo_u.prad_core';
%     '\tcv_shot::top.results.bolo_u.confidence';

    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
  
  %% Code legacy for rc_gti_prep
  ids_bolometer.code.name = 'rc_gti_prep';
  rc_gti_prep_gitinfo= ...
    tcv_get_deploymentinfo(fullfile(fileparts(which(ids_bolometer.code.name)),'.this-deployment.info'));
  ids_bolometer.code.description = ...
    'rc_gti_prep, RADCAM gitlab repo, calls GTI to generate emissivity profiles with liuqe.';
  ids_bolometer.code.commit=rc_gti_prep_gitinfo.git_commit;
  ids_bolometer.code.version=rc_gti_prep_gitinfo.git_tag;
  ids_bolometer.code.repository= rc_gti_prep_gitinfo.repository;
  ids_bolometer.code.parameters= ...
      ['rc_gti_prep(shot,[0 2.2],''bolo'', 10, 1, 0.04, 30,' ...
    'false, false,false, [], ''automated'', 1)'];

  %% Code legacy for TCV_EQ; FBTE
  % Call to gti: gti_get_disc
  % Call to TCV_eq: temp=tdi('TCV_EQ("psi")',disc.s.equilsrc);
  % https://spcwiki.epfl.ch/wiki/Tcv_eq
  % a=gdat(shot,'TCV_EQ("psi")');
  ids_bolometer.code.library{1}.name = 'fbte';
  ids_bolometer.code.library{1}.description = 'Magnetic equilibrium';
  ids_bolometer.code.library{1}.parameters = 'TCV_EQ("psi")';
  
  %% Code legacy for GTI
  ids_bolometer.code.library{2}.name = 'gti';
  ids_bolometer.code.library{2}.description = ...
      'General Tomographic Inversion';
  for ii = 1:numel(ids_bolometer.code.library)
      
      library_gitinfo= ...
        tcv_get_deploymentinfo(fullfile(fileparts(which('gti_do_inversion')),'.this-deployment.info'));
      ids_bolometer.code.library{ii}.commit = library_gitinfo.git_commit;
      ids_bolometer.code.library{ii}.version = library_gitinfo.git_tag;
      ids_bolometer.code.library{ii}.repository = library_gitinfo.gitlab_project_url;
  end
  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