; $Id: dcs_sameness.pro,v 1.8 2005/02/14 17:50:14 azuah Exp $
; Written by J.R.D. Copley.
;************************************************************************************************
;###############################################################################
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;###############################################################################
pro dcs_sameness,dcs_base,files_selected,nfiles_selected,nruns,notsame,davePtr=davePtr
;************************************************************************************************
; This routine reads in each of the files, into "davePtr", and checks that certain
; quantities are the same in all of the files.
;
compile_opt strictarr
;
omithisto=2
printinfo=0
;
; These are the quantities that are required to be identical.
; Quantities removed from this list: "motor_pos","coll_osc"...
;
quantity=["ch_ms","ch_res","ch_srdenom","ch_srmode","ch_wl",$
	"coll_amp","coll_mean","det_dis","tsdmin",$
	"ch_bid","ch_delay","ch_dis","ch_input","ch_phase","ch_slots",$
	"fc_dis","tchanlook","startchoice","highsource"]
;
;	Construct number of files other than background files..
;
nruns_nob=nruns-nfiles_selected[4]
;
ntests=n_elements(quantity)
;
notsame=intarr(ntests,nruns_nob)
;
lines=strarr(2*nruns_nob+2)
;
nline=1
for irun=1,nruns_nob do begin
	irnm1=irun-1
	line=["Examining file"+strcompress(irun)+" of"+strcompress(nruns_nob),files_selected[irnm1]]
	dcs_message_display,line,base,group_leader=dcs_base,alignment=0
	filetype="binary"
	dcs_readdatafile,files_selected[irnm1],omithisto,printinfo,filetype,davePtr=davePtr
	; The next statements have been added to ensure that when ch_srdenom=2 ch_srmode and
	;	ch_input[3] are set to 2 and 2.0 respectively (within the confines of this procedure).
	if ((*(*(*davePtr).dataStrPtr).specificPtr).ch_srdenom eq 2) then begin
		(*(*(*davePtr).dataStrPtr).specificPtr).ch_srmode = 2
		(*(*(*davePtr).dataStrPtr).specificPtr).ch_input[3] = 2.000
	endif
	widget_control,base,/destroy
	if (irun eq 1) then begin ; All files are compared with file 1.
		for k=0,ntests-1 do begin
			com=quantity[k]+"_0=(*(*(*davePtr).dataStrPtr).specificPtr)."+quantity[k]
			res=execute(com)
		endfor
	endif else begin
		for k=0,ntests-1 do begin
			com="tst=where((*(*(*davePtr).dataStrPtr).specificPtr)."+$
				quantity[k]+" ne "+quantity[k]+"_0,count)"
			res=execute(com)
			com="notsame["+strcompress(k,/remove_all)+",irnm1]=count"
			res=execute(com)
		endfor
		if (total(notsame[*,irnm1],1) gt 0) then begin
			nline=nline+2
			lines[nline+1]=files_selected[irnm1]
			lines[nline+2]="   /"
			for k=0,ntests-1 do begin
				if (notsame[k,irnm1] gt 0) then lines[nline+2]=lines[nline+2]+quantity[k]+"/
			endfor
		endif
	endelse
endfor
;
notsame=total(notsame) gt 0
if (notsame) then begin
	lines[0]="THE FIRST RUN IS THE FOLLOWING:"
	lines[1]=files_selected[0]
	lines[2]=""
	lines[3]="QUANTITIES THAT DIFFER FROM THE FIRST RUN:"
	blabel=['I guess you must be right. The program will exit.']
	def_button=0
	lines=lines[0:nline+2]
	dcs_multichoice_modal,lines,decision,blabel,def_button,$
		group_leader=dcs_base,alignment=-1
endif
;
end