function ms_fitcut

% function ms_fitcut
% construct MSlice : Fit Cut window 
% to use with MFit to fit cuts from MSlice including binning and resolution effects  
% Radu Coldea 22-September-1999

% === define colours in RGB format
colordef white;
white=[1 1 1];
black=[0 0 0];
grey=[0.752941 0.752941 0.752941];

% === close previous MSlice Control Windows
h=findobj('Tag','ms_fitcut');
if ~isempty(h),
   disp(['Closing previous Mslice: Fit Cut Window'])
   delete(h);
end

% === draw Control Window and establish positions and dimensions of menu items
fig=figure;
set(fig,'Name','MSlice : Fit Cut',...
   'NumberTitle','off',...
   'Tag','ms_fitcut',...
   'MenuBar','none','Resize','off');
h=uicontrol(fig,'Style','text','String','Spectrometer',...
   'BackgroundColor',grey);
pos=get(h,'Extent');
lineheight=pos(4);
interlines=ceil(lineheight/5);
nlines=15.2;
width=8*pos(3);
bottomx=6;
bottomy=414;

set(fig,'Position',[bottomx bottomy width lineheight*nlines+interlines*(nlines-1)]);
pos=[0 lineheight*(nlines-1)+interlines*(nlines-1) pos(3) pos(4)];
set(h,'Position',pos); 
oneline=[0 lineheight+0*interlines 0 0];
pos=pos-[0 interlines 0 0];

%========== Top Menu : Exit ===========================
hmenu=uimenu(fig,'Label','Exit');
uimenu(hmenu,'Label','Exit','Callback','close(gcf);');

%========== Top Menu : Help ===========================
%hmenu=uimenu(fig,'Label','Help');
%uimenu(hmenu,'Label','Display help file','Callback','type dv_help.txt ');

%========== Top Menu : About ==========================
hmenu=uimenu(fig,'Label','About FitCut...');
hmenu1=uimenu(hmenu,'Label','MSlice FitCut version 1.0, 22-September-1999');
hmenu1=uimenu(hmenu,'Label','written by Radu Coldea (ORNL/ISIS)');
hmenu1=uimenu(hmenu,'Label','radu@isise.rl.ac.uk');

%========= efixed emode and spectrometer =========
set(h,'String','efixed');
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_efixed',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
	'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','geometry',...
   'Position',pos+[2*pos(3) 0 0 0]);   
h=uicontrol('Parent',fig,'Style','popupmenu','String',{'direct','indirect'},...
   'Tag','ms_fitcut_emode','BackgroundColor',white,...
	'Position',pos+[3*pos(3) interlines/2 0 interlines],'Value',2);
h=uicontrol('Parent',fig,'Style','text','String','spectrometer',...
   'Position',pos+[4*pos(3) 0 0 0]);   
h=uicontrol('Parent',fig,'Style','popupmenu','String',{'IRIS','HET','MARI'},...
   'Tag','ms_fitcut_spectrometer','BackgroundColor',white,...
	'Position',pos+[5*pos(3) interlines/2 0 interlines],'Value',1);

%========= CutFile ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String',[pwd '\'],...
   'Position',pos,'Visible','off','Tag','ms_fitcut_CutDir');
h=uicontrol('Parent',fig,'Style','text','String','CutFile(.cut)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_CutFile',...
   'Position',pos+[pos(3) 0 2*pos(3) interlines],...
   'HorizontalAlignment','left',...
	'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','pushbutton','String','Browse',...
   'Callback',...
   'ms_getfile(findobj(''Tag'',''ms_fitcut_CutDir''),findobj(''Tag'',''ms_fitcut_CutFile''),''*.cut'',''Choose Cut File'');',...
   'Position',pos+[4*pos(3) interlines/2 0 0]);   

%========= DetFile and Load Cut pushbuttons ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','DetFile(.par)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','text','String',[pwd '\'],...
   'Position',pos,'Visible','off','Tag','ms_fitcut_ParDir');
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_ParFile',...
   'Position',pos+[pos(3) 0 2*pos(3) interlines],...
   'HorizontalAlignment','left',...
	'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','pushbutton','String','Browse',...
   'Callback',...
   'ms_getfile(findobj(''Tag'',''ms_fitcut_ParDir''),findobj(''Tag'',''ms_fitcut_ParFile''),''*.par'',''Choose Detector File'');',...
   'Position',pos+[4*pos(3) interlines/2 0 0]);   
h=uicontrol('Parent',fig,'Style','pushbutton','String','Save Cut',...
   'Callback','ms_fitcut_save_data;',...
   'Position',pos+[6*pos(3) interlines 0 0]);   
h=uicontrol('Parent',fig,'Style','pushbutton','String','Load Cut',...
   'Callback','ms_fitcut_load_data;',...
   'Position',pos+[7*pos(3) interlines 0 0]);   

%========= Fit parameters ==================
pos=pos-1.5*oneline;
h=uicontrol('Parent',fig,'Style','text','String','Fit parameters',...
   'Position',pos,'BackgroundColor','White');

%========= NMC and icross ==================
pos=pos-1.5*oneline;
h=uicontrol('Parent',fig,'Style','text','String','NMC points',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_nmc',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,'String','1');
h=uicontrol('Parent',fig,'Style','text','String','icross',...
   'Position',pos+[2*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_icross',...
   'Position',pos+[3*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,...
   'Callback','ms_fitcut_updatepar',...
   'String','9');

%========= Sample :Single Crystal/Powder ==================

pos=pos-1.5*oneline;
h=uicontrol('Parent',fig,'Style','text','String','Sample',...
   'Position',pos,'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','popupmenu','String',{'single crystal','powder'},...
   'Tag','ms_fitcut_sample','BackgroundColor',white,...
   'Position',pos+[pos(3) 0 0.5*pos(3) interlines],...
   'Callback','ms_fitcut_sample','Value',1);

%========= Lattice parameters ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','Unit cell lattice parameters ',...
   'Position',pos+[0 0 1.5*pos(3) 0]);

%========= as bs cs (Angs)==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','a (Å)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_as',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','b (Å)',...
   'Position',pos+[2*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_bs',...
   'Position',pos+[3*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','c (Å)',...
   'Position',pos+[4*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_cs',...
   'Position',pos+[5*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);

%========= aa bb cc (deg)==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','aa (deg)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_aa',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','bb (deg)',...
   'Position',pos+[2*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_bb',...
   'Position',pos+[3*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','cc (deg)',...
   'Position',pos+[4*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_cc',...
   'Position',pos+[5*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);

%========= Crystal orientation ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text',...
   'String',...
   'Crystal orientation:(u,v) reciprocal space axes in principal scattering plane (Qx || ki,Qy), i.e. u=[100]=a*,v=[010]=b*',...
   'Position',pos+[0 0 7*pos(3) 0]);

%========= ux uy uz ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','ux',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_ux',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','uy',...
   'Position',pos+[2*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_uy',...
   'Position',pos+[3*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','uz',...
   'Position',pos+[4*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_uz',...
   'Position',pos+[5*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);

%========= vx vy vz ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','vx',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_vx',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','vy',...
   'Position',pos+[2*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_vy',...
   'Position',pos+[3*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text','String','vz',...
   'Position',pos+[4*pos(3) 0 0 0]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_vz',...
   'Position',pos+[5*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);

%========= psi_samp (deg) ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','Psi(deg)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_psi_samp',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white);
h=uicontrol('Parent',fig,'Style','text',...
   'String',' angle between ki and u, +ve if (ki x u) || Q_z',...
   'HorizontalAlignment','left','Position',pos+[2*pos(3) 0 6*pos(3) 0]);

%========= Angular divergencies and energy resolution ==================
pos=pos-1.5*oneline;
h=uicontrol('Parent',fig,'Style','text',...
   'String',...
   'Spectrometer angular divergencies and time resolutions (fwhm) ',...
   'BackgroundColor',white,...
   'HorizontalAlignment','left',...
   'Position',pos+[0 0 4*pos(3) 0]);

%========= horizontal and vertical beam divergencies for IRIS ==================
pos=pos-1.5*oneline;
h=uicontrol('Parent',fig,'Style','text','String','theta_h(deg)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_theta_h',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,'String','2.3');
h=uicontrol('Parent',fig,'Style','text','String','theta_v(deg)',...
   'Position',pos+[2*pos(3) 0 0 interlines]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_theta_v',...
   'Position',pos+[3*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,'String','2.3');
h=uicontrol('Parent',fig,'Style','text','String','psi_h(deg)',...
   'Position',pos+[4*pos(3) 0 0 interlines]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_psi_h',...
   'Position',pos+[5*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,'String','6.4');
h=uicontrol('Parent',fig,'Style','text','String','psi_v(deg)',...
   'Position',pos+[6*pos(3) 0 0 interlines]);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_psi_v',...
   'Position',pos+[7*pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,'String','6.4');

%========= time resolution ==================
pos=pos-oneline;
h=uicontrol('Parent',fig,'Style','text','String','dt (us)',...
   'Position',pos);
h=uicontrol('Parent',fig,'Style','edit','Enable','on','Tag','ms_fitcut_dt',...
   'Position',pos+[pos(3) 0 0 interlines],...
   'HorizontalAlignment','left',...
   'BackgroundColor',white,'String','212');

% === start Mfit 
hmf_ctrl=mf_figs;
if isempty(hmf_ctrl)|(hmf_ctrl==0),
	mfit;   
end











  