function [libera_RF_offset,block_offset,BBA_offset,survey_offset]=get_bpm_offsets(dev)

X_offset_BBA=0;
Z_offset_BBA=0;
libera_RF_offset=0;
block_offset=0;
survey_offset=0;
increment=1;
Correspondance=tango_get_db_property('BPM','DeviceParameters');
block_table=tango_get_db_property('BPM','BlockParameters');
libera_table=tango_get_db_property('BPM','HwParameters');
       for i=1:1:size(Correspondance,2)
            index=regexpi(Correspondance{i},dev);     
            if isempty(index)==0
                separator=regexpi(Correspondance{i},':');  
                BPM_name=Correspondance{i}(1:separator(1)-1);
                block_name=Correspondance{i}(separator(1)+1:separator(2)-1);
                libera_name=Correspondance{i}(separator(2)+1:size(Correspondance{i},2));
               for j=1:1:size(block_table,2)
                    index_block=regexpi(block_table{j},[block_name,':']);
                    if isempty(index_block)==0
                        separator=regexpi(block_table{j},':');  
                        Block_Ka=str2num(block_table{j}(separator(3)+1:separator(4)-1));
                        Block_Kb=str2num(block_table{j}(separator(4)+1:separator(5)-1));
                        Block_Kc=str2num(block_table{j}(separator(5)+1:separator(6)-1));
                        Block_Kd=str2num(block_table{j}(separator(6)+1:separator(7)-1));
                       
                        X_survey_offset=str2num(block_table{j}(separator(7)+1:separator(8)-1));
                        Z_survey_offset=str2num(block_table{j}(separator(9)+1:separator(10)-1));
                        X_offset_BBA=str2num(block_table{j}(separator(8)+1:separator(9)-1));
                        Z_offset_BBA=str2num(block_table{j}(separator(10)+1:separator(11)-1));
                        BPM=BPM_name;
                    end
                end
                for j=1:1:size(libera_table,2)
                    index_libera=regexpi(libera_table{j},[libera_name,':']);
                    if isempty(index_libera)==0
                        separator=regexpi(libera_table{j},':');  
                        libera_Ka=str2num(libera_table{j}(separator(2)+1:separator(3)-1));
                        libera_Kb=str2num(libera_table{j}(separator(3)+1:separator(4)-1));
                        libera_Kc=str2num(libera_table{j}(separator(4)+1:separator(5)-1));
                        libera_Kd=str2num(libera_table{j}(separator(5)+1:separator(6)-1));
                       
                     end
                end
            end
       end
K=11.4;
BBA_offset(1)=X_offset_BBA;
BBA_offset(2)=Z_offset_BBA;
survey_offset(1)=X_survey_offset;
survey_offset(2)=Z_survey_offset;
block_offset(1)=K*(1/Block_Ka+1/Block_Kd-1/Block_Kb-1/Block_Kc)/(1/Block_Ka+1/Block_Kb+1/Block_Kc+1/Block_Kd);
block_offset(2)=K*(1/Block_Ka+1/Block_Kb-1/Block_Kc-1/Block_Kd)/(1/Block_Ka+1/Block_Kb+1/Block_Kc+1/Block_Kd);
block_offset(3)=Block_Ka;
block_offset(4)=Block_Kb;
block_offset(5)=Block_Kc;
block_offset(6)=Block_Kd;
libera_RF_offset(1)=K*(1/libera_Ka+1/libera_Kd-1/libera_Kb-1/libera_Kc)/(1/libera_Ka+1/libera_Kb+1/libera_Kc+1/libera_Kd);
libera_RF_offset(2)=K*(1/libera_Ka+1/libera_Kb-1/libera_Kc-1/libera_Kd)/(1/libera_Ka+1/libera_Kb+1/libera_Kc+1/libera_Kd);
libera_RF_offset(3)=libera_Ka;
libera_RF_offset(4)=libera_Kb;
libera_RF_offset(5)=libera_Kc;
libera_RF_offset(6)=libera_Kd;
% block_offset(1)=K*(Block_Ka+Block_Kc-Block_Kb-Block_Kd)/(Block_Ka+Block_Kb+Block_Kc+Block_Kd);
% block_offset(2)=K*(Block_Ka+Block_Kb-Block_Kc-Block_Kd)/(Block_Ka+Block_Kb+Block_Kc+Block_Kd);
% libera_RF_offset(1)=K*(libera_Ka+libera_Kc-libera_Kb-libera_Kd)/(libera_Ka+libera_Kb+libera_Kc+libera_Kd);
% libera_RF_offset(2)=K*(libera_Ka+libera_Kb-libera_Kc-libera_Kd)/(libera_Ka+libera_Kb+libera_Kc+libera_Kd);
      %end
% switch dev
%     case 'all'
%  for i=1:1:size(Correspondance,2)
%      index=regexpi(Correspondance{i},'ANS-C');     
%     if isempty(index)==0
%         BPM_name=Correspondance{i}(index:index+15);
%         block_name=Correspondance{i}(index+17:index+24);
%   for j=1:1:size(block_table,2)
%    index=regexpi(block_table{j},[block_name,':']);
%    if isempty(index)==0
%         separator=regexpi(block_table{j},':');             
%         X_offset_BBA(increment)=str2num(block_table{j}(separator(8)+1:separator(9)-1));
%         Z_offset_BBA(increment)=str2num(block_table{j}(separator(10)+1:separator(11)-1));
%         BPM(increment,:)=BPM_name;
%         increment=increment+1; 
%    end 
%   end
% 
%   otherwise        
 
offsets_X = [X_offset_BBA(2:end) X_offset_BBA(1)]';
offsets_Z = [Z_offset_BBA(2:end) Z_offset_BBA(1)]';


X_offset=block_offset(1)+BBA_offset(1)+survey_offset(1);
Z_offset=block_offset(2)+BBA_offset(2)+survey_offset(2);
