Documentation for  xaid_mu2chi.pro

----- Documentation for xaid_mu2chi.pro -----
 =================================  xaid_mu2chi ===============================



   xaid_mu2chi is a widget based graphical interface to perform the
   XAFS background substraction. Among several different  operations 
   xaid_mu2chi may extract the Eo value from the maximum of the derivative, 
   get automatically or manually the Jump value, perform polynomial 
   and multispline fits, and allows three methods of normalization.
   
   The main window contains the following controls

	FILE Menu:
	  EXPORT TO SPEC FILE: wites an ASCII file with all the calculated
		data in SPEC format. Columns are: 
		E [eV]  E-Eo [eV]  k [A^-1]  Mu  Mu-PreEdge  Mu Norm
		PreEdge  PostEdge  Chi  Chi*k  Chi*k^2  Chi*k^3
	  INPUT PARAMETERS: These options permit to load/write a 
		file with the parameters of the XAID_MU2CHI application. 
		It can also be used for defining user's defaults. 
	  PRINT:  Send a copy of the current plot to the printer.
	  PREFERENCES...:  Allows to customize some parameters relevant
		for the display and Fourier Transform. 
	  QUIT:	Exit or Quit the program

	RAW_DATA Menu:
	  These operations apply ONLY to RAW data:
	  CUT: Permits to reduce the horizontal limits of the data
	  DERIVATIVES: Shows at the same plot the signal and
		its two first derivatives
	  INTERPOLATION: Allows Linear or Spline interpolation for
		reducing or adding points. 
	  GENERIC OPERATION: Permits to modify the x and y raw data. 
		Useful to change units (eV-keV), prenormalization, etc. 

	Tools Menu:
	  XAID_MU2CHI: Opens a new application window
	  XAID: Starts main XAID window
	  XPLOT: Opens an empty XPLOT window.
	  XOP: Starts main XOP window

       HELP Menu:   Shows documentation to several related XAFS routines.

	Main Left Panel: Input parameters 

	  RAW DATA FILE: To Load a File with Data. The file must contain 
		the data in ascii formatted in two columns. It
		may content comments becoming by a non-numeric (nor + - .)
		character. The program stores the data and reads 
		automatically all the points and columns
	  1) PreEdge Linear Fit: Selects the limits in E for the preEdge
		linear fit
	  2) Eo and Jump: Gets the Eo from the maximum of the derivative, and 
		allows the user to change it or input another one.
	        It also gets an initial Jump value and allows the user to 
		change it.
	  3) Post-edge Multi-Spline: allows multi-spline polynomial fits.
	  4) EXAFS extraction: Selects the extraction algorithm:
		
	Main Right Panel: Plot parameters. 


		
 ======== Non-interactive use of XAID_Mu2CHI ====================

	NAME:
		XAID_MU2CHI
	PURPOSE:
		 EXAFS extraction
 	CATEGORY:
		XAID: XOP XAFS data analysis.
	CALLING SEQUENCE:
		XAID_MU2CHI [,filename] 
	OPTIONAL INPUT PARAMETERS:
		filename: a string containing the file name to be
		plotted or an idl variable [fltarr(2,n_points)]
		with data. The file must be ascii data arranged in 
		columns. Lines starting with characters [except . + -]
		are comments and not considered for the plot.

	KEYWORD PARAMETERS:
		GROUP = The widget ID of the widget that calls Xplot.
		When this ID is specified, a death of the caller results 
		in a death of XAID_Mu2Chi.
		NO_BLOCK = If set, starts Xmanager with the No_Block keyword.
		WSIZE = The initial size of the graphical display in pixels
		DELIAID = The widget id for DELIA panel (for internal
			use of DELIA)

	OUTPUT KEYWORD PARAMETERS:
		PARENT = The widget id for the main window (see later)
	OUTPUTS:
		Open a widget utility and present a graphic.
	COMMON BLOCKS:
		COMMON xaid_mu2chi, strOper
		to keep memory from operation window
	PROCEDURE:
		Uses XAID data analysis IDL library.
	MODIFICATION HISTORY:
		Written by  Manuel Sanchez del Rio. ESRF. 11 October 1994
		96-08-22 MSR creates a new version from the old xcnpick.
		97-01-14 MSR fixes for Windows.
		97-09-08 MSR adds NO_BLOCK keyword
		97-09-30 srio@esrf.fr READ_ASCII renamed to RASCII
		97-10-25 srio@esrf.fr small fixed in main window.
		98-10-01 srio@esrf.fr adapts for delia. Use of catch.
		99-02-18 srio@esrf.fr adapts XOP 2.0
		00-02-15 srio@esrf.fr adapts for Exodus. Centers 
			the screens. Adds *1000 and :1000 operations.
			Allows to load a spline.
		03-12-09 srio@esrf.fr adds linear fit (LINFIT) and
			normalization to jump.
		06-03-13 srio@esrf.fr Almost completely rewritten. v 2.0Beta1
		06-07-20 srio@esrf.fr Avoid loading file name when loading 
			input files. 
		2009-05-13 srio@esrf.eu version 2.0Beta3. Implementation of
			some ideas from C. Prestipino: 
			Weight in spline, kev->eV conversion, etc.
			Multiple input files. Other small improvements.
		2009-06-10 srio@esrf.eu makes some improvements after
                       feedback of Carmelo Prestipino:
                       Possibility to use Extra windows (old "Zoom")
                       Fix a bug related to applied weighting window 
                       Plot knots


   Example of using of xaid_mu2chi from external programs: 
	The Parent keyword permits to store the application id and 
	reuse it from other applications. Some routines allow the
	data manipulation:
		xaid_mu2chi_loadfile,parent,set
		xaid_mu2chi_plot,parent
               ; get input parameters
		str=xaid_mu2chi_getstr(parent)
               ; set input parameters
		xaid_mu2chi_putstr,parent,str
		;   (or xaid_mu2chi_putstr,parent,str,/NoFile to avoid 
		;    changing the input file name)

               perform calculations
		xaid_mu2chi_calc,p
               ; or  (for any set)
		xaid_mu2chi_calc,set=set,str=str

	Examples: 

	1) Start and quit:
		IDL> xaid_mu2chi,parent=p
		IDL> xaid_mu2chi_quit,p
	2) Start and load data
		IDL> xaid_mu2chi,parent=p
		IDL> xaid_mu2chi_loadfile,p,'CuFoilRef.txt',/plot
		or
		xaid_mu2chi_loadfile,p,rascii('CuFoilRef.txt'),plot=0

	3) Load data, modify parameters of left panel, update the plot
		
		IDL> xaid_mu2chi,parent=p,'CuFoilRef.txt'
		IDL> str=xaid_mu2chi_getstr(p)
		IDL> str.e0=8979
		IDL> str.jump=1
		IDL> xaid_mu2chi_putstr,p,str
		IDL> xaid_mu2chi_plot,p,ix=2,iy=8
	
	4) Export data
		
           4.1)
		IDL> xaid_mu2chi_calc, p, out=out, coltitles=coltitles
               IDL> xplot,out,coltitles=coltitles

           4.2) 
               IDL> xaid_mu2chi_write,p, file= 'tmp.spec'


  HELP FOR THE USE OF NON-INTERACTIVE ROUTINES: 




 PRO xaid_mu2chi_quit,id

 destroys main window



 PRO xaid_mu2chi_updatexwindow,wid

 If there are Extra (additional) xwwindows, update them



 PRO xaid_mu2chi_putstr,id,str,noFile=noFile

 stores a xaid_mu2chi data structure




  PRO xaid_mu2chi_plot,id,Print=Print,_Extra=extra, $
    ix=ix,iy=iy,resetzoom=resetzoom, xplot=xplot,$
    xx=xx1,yy=yy1,xtitle=xtitle,ytitle=ytitle ; output keywords

  ResetZoom: redefines default limits (recommended)
  ix: 0 E [eV]
      1 E-Eo [eV]
      2 K [A^-1]
      3 R [A]   (if set, the Fourier transform is displayed vs R)

  iy: 0  Mu
      1  Mu & PreEdge
      2  Mu - PreEdge
      3  Mu Normalized
      4  Mu - PreEdge & Postedge
      5  Mu - PreEdge & Postedge k
      6  Mu - PreEdge & Postedge k^2
      7  Mu - PreEdge & Postedge k^3
      8  Chi
      9  Chi*k
     10  Chi*k^2
     11  Chi*k^3


 TODO: Rewrite it using xaid_mu2chi_calc.




 PRO xaid_mu2chi_loadfile,id,file,Dialog_Parent=dialog_parent, plot=iplot,$
 message=message,defaultFile=defaultFile,path=path

  plot = 0  No plot (default)
  plot = 1  Plot 
  plot = 2  Plot (force Mu vs E)
  plot = 2  Plot (force Chi vs k)

 DefaultFile and Path are passed to Dialog_Pickfile()
 DefaultParms compute default parameters (E Min, E Max Eo, Jump,
               knots in k).




 PRO xaid_mu2chi_write, parent , $
   scannumber=scannumber, xplot=xplot, file=file, $
   out=out, coltitles=coltitles ; output from xaid_mu2chi_calc

 xplot=0 no xplot window
 xplot=1 start xplot
 xplot=2 ask for confirmation 

 scannumber: passed to spec_save()

 output: out, coltitles

 2009-05-15 srio@esrf.eu written


