function buttonexport2libCAA(hObject, eventdata, Empty_Button, lcs, basichi, basicfsz, sty, calclib, version)
data = get(Empty_Button,'UserData');

sfixA = size(data.fixA,1);

s = 0;
datsol = [];
if (sfixA >= 1) && (data.choosen(1) == 1)
    if s == 0
        dat = {'blue (first) spectrum'};
    else
        dat = {dat{:}, 'blue (first) spectrum'};
    end
    a = [1 data.fixA(1,:)]*data.V(:,1:3)';
    datsol = [datsol; a/max(a)];
    s = s+1;
end
if (sfixA >= 2) && (data.choosen(2) == 1)
    if s == 0
        dat = {'red (second) spectrum'};
    else
        dat = {dat{:}, 'red (second) spectrum'};
    end
    a = [1 data.fixA(2,:)]*data.V(:,1:3)';
    datsol = [datsol; a/max(a)];
    s = s+1;
end
if (sfixA >= 3) && (data.choosen(3) == 1)
    if s == 0
        dat = {'dark yellow (third) spectrum'};
    else
        dat = {dat{:}, 'dark yellow (third) spectrum'};
    end
    a = [1 data.fixA(3,:)]*data.V(:,1:3)';
    datsol = [datsol; a/max(a)];
    s = s+1;
end

if s == 0
    return
end

fig = figure;
pause(.1);

scrsz = get(0,'ScreenSize');

set(fig,'Position',[scrsz(3)/2 scrsz(4)/2 600 200]);
pause(.1);

set(fig,'Name','Export a certain spectrum to the library','NumberTitle','off','MenuBar','none','Toolbar','none','color','white');

Textfield(1) = uicontrol('Style','text','String','Select spectrum:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.76, 0.45, 0.2]);

Textfield(2) = uicontrol('Style','text','String','Name:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.52, 0.45, 0.2]);

Textfield(3) = uicontrol('Style','edit','String','','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.48, 0.52, 0.51, 0.2]);

Textfield(4) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'FontWeight','bold','Position',[0, 0.25, 1, 0.2]);

popup(1) = uicontrol('Style','popupmenu','String',dat,'HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.48, 0.775, 0.51, 0.2], 'Value',1);

Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Add to library','HorizontalAlignment','center','Fontsize',1.5*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.51, 0.04, 0.48, 0.2],...
    'Callback',{@innerbuttonadd, Empty_Button, popup, Textfield, fig, calclib, version, datsol});

Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Cancel','HorizontalAlignment','center','Fontsize',1.5*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.04, 0.48, 0.2],...
    'Callback',{@innerbuttoncancel, fig});



function innerbuttonadd(hobject, eventdata, Empty_Button, popup, Textfield, parentfig, calclib, version, datsol)
data = get(Empty_Button,'UserData');
name = get(Textfield(3), 'String');
if strcmp(name,'') == 1
    set(Textfield(4), 'String' ,'Export not successful: Please enter a NAME','Foregroundcolor','red');
    return
end

load([calclib,'/FACPACKlibrary.mat']);
no = length(lib);
for i=1:no
    if strcmp(lib(i).name, name) == 1
        set(Textfield(4), 'String' ,'Export not successful: NAME exists already in the library','Foregroundcolor','red');
        return
    end
end

cln = clock;
cln = [num2str(cln(4),'%2.2d'), ':', num2str(cln(5),'%2.2d'), ':', num2str(round(cln(6)),'%2.2d')];

lib(no+1).name = name;
lib(no+1).x = data.x;
lib(no+1).a = datsol(get(popup(1),'Value'),:);
lib(no+1).date = date;
lib(no+1).clock = cln;
lib(no+1).module = 'CAA';
lib(no+1).dataset = [data.PathName, data.FileName];
lib(no+1).version = version;

set(Textfield(4), 'String' ,'Export successful','Foregroundcolor','black');

save([calclib,'/FACPACKlibrary.mat'],'lib');
close(parentfig);


function innerbuttoncancel(hobject, eventdata, parentfig)
close(parentfig);
