#pragma rtGlobals=1 // Use modern global access method. #pragma IgorVersion=6.1 // Version 1.0 // SRK 7 OCT 2009 // // Adding two raw .bt5 files: // - only files with the same angle range and the same number of points can be added. // - NO shifting is done - these are raw data files, and the angular shift is not known // - it can be repeated multiple times to add more than two files together // - the two added files are listed in the title of the summed file. // Adding two data sets: // - here, two entire data sets (inlcluding the main beam) are added together after // loading and normalizing and coverting to Q. The data file is NOT saved out, because // it is not a format that can be re-read in for reduction. // - to use the summed data set, it is first summed in a separate panel, and then transferred // to either the active "SAM" or "EMP" data // - since the zero offset can make the point values not exactly the same, only those within a // certain tolerance are actually added. Points that cannot be added are still kept in the final // data set. // // issues // - are the errors calculated correctly? I think so... // - if there is a direct 1:1 correspondence of the data points, saving is easy // -- if not, then some points will have a different counting time // -- this is always the case if I do a "full" data set. // // - convert to countrate seems like a good idea, then 1+1=2 and I can propagate errors // -- but how to save the data? At this point, errCR != sqrt(CR) // -> answer is -- don't save the full data sets that have been summed... // // - Why can't I just use the whole set of files from the main USANS panel, and add what needs // to be added? Because if there is an angle shift, I have no way of knowing which files to apply // the shift to... // // - do I have anything hard-wired in the code that needs to be generalized before release? // // simple stuff to do: // - allow user to input Qpeak (maybe of no use?) If so, do it right away with a dialog // if no peak was found. Proc ShowUSANSAddPanel() DoWindow/F USANS_Add_Panel if(V_Flag==0) Init_AddUSANS() USANS_Add_Panel() Endif End // initializes the folders and globals for use with the USANS_Add_Panel // // there is some overlap of the controls from the Main_USANS panel // separate waves are created for the lists in :AddPanel // Proc Init_AddUSANS() NewDataFolder/O root:Packages NewDataFolder/O root:Packages:NIST NewDataFolder/O root:Packages:NIST:USANS NewDataFolder/O root:Packages:NIST:USANS:Globals NewDataFolder/O/S root:Packages:NIST:USANS:Globals:AddPanel String/G root:Packages:NIST:USANS:Globals:gUSANSFolder = "root:Packages:NIST:USANS" String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder //Preference value to determine if we are outputting XML // Variable/G root:Packages:NIST:USANS:Globals:gUseXMLOutput = 0 String/G FilterStr Variable/G gAddUSANSTolerance = 0.01 // add points if x is within 1% (an arbitrary choice!) Make/O/T/N=1 fileWave,AWave,BWave fileWave="" AWave="" BWave="" // Make/O/T/N=5 statusWave="" Make/O/B/U/N=1 selFileW SetDataFolder root: NewDataFolder/O $(USANSFolder+":TMP_A") NewDataFolder/O $(USANSFolder+":TMP_B") NewDataFolder/O $(USANSFolder+":SUM_AB") End //draws the USANS_Add_Panel, somewhat similar to the Main panel // // but used exclusively for adding files, and is a graph/control bar // Proc USANS_Add_Panel() PauseUpdate; Silent 1 // building window... Display /W=(100,44,900,493)/K=1 as "USANS_Add_Panel" DoWindow/C USANS_Add_Panel DoWindow/T USANS_Add_Panel, "Add Raw USANS Files" ControlBar/L 300 // ModifyGraph cbRGB=(36929,50412,31845) ModifyGraph cbRGB=(65535,60076,49151) // (I don't know where these end up anyhow...) // SetDrawLayer UserBack // SetDrawEnv fstyle= 1 // DrawText 12,53,"Data Files" // SetDrawEnv fstyle= 1 // DrawText 157,192,"Empty Scans" // SetDrawEnv fstyle= 1 // DrawText 154,54,"Sample Scans" // DrawLine 6,337,398,337 // DrawLine 5,33,393,33 // SetDrawEnv fstyle= 1 // DrawText 140,357,"Raw Data Header" // SetDrawEnv fstyle= 1 ListBox AfileLB,pos={5,55},size={110,230}//,proc=AddFileListBoxProc ListBox AfileLB,listWave=root:Packages:NIST:USANS:Globals:AddPanel:fileWave ListBox AfileLB,selWave=root:Packages:NIST:USANS:Globals:AddPanel:selFileW,mode= 4 ListBox A_LB,pos={149,55},size={110,90},listWave=root:Packages:NIST:USANS:Globals:AddPanel:AWave ListBox A_LB,mode= 1,selRow= -1 Button Clear_A_Button,pos={227,148},size={35,20},proc=ClearABButtonProc,title="Clr" Button Clear_A_Button,help={"Clears the list of sample scans"} Button Clear_B_Button,pos={227,286},size={35,20},proc=ClearABButtonProc,title="Clr" Button Clear_B_Button,help={"Clears the list of empty scans"} Button ARefreshButton,pos={9,310},size={104,20},proc=RefreshListButtonProc,title="Refresh" Button ARefreshButton,help={"Refreshes the list of raw ICP data files"} Button Del_A_Button,pos={183,148},size={35,20},proc=DelAButtonProc,title="Del" Button Del_A_Button,help={"Deletes the selected file(s) from the list of SET A scans"} Button Del_B_Button,pos={183,286},size={35,20},proc=DelBButtonProc,title="Del" Button Del_B_Button,help={"Deletes the selected file(s) from the list of SET B scans"} ListBox B_LB,pos={151,194},size={110,90} ListBox B_LB,listWave=root:Packages:NIST:USANS:Globals:AddPanel:BWave,mode= 1,selRow= 0 Button to_A_List,pos={118,55},size={25,90},proc=to_A_ListButtonProc,title="A\r->" Button to_A_List,help={"Adds the selected file(s) to the list of SET A scans"} Button to_B_List,pos={120,195},size={25,90},proc=to_B_ListButtonProc,title="B\r->" Button to_B_List,help={"Adds the selected file(s) to the list of SET B scans"} // ListBox StatusLB,pos={11,358},size={386,77} // ListBox StatusLB,listWave=root:Packages:NIST:USANS:Globals:AddPanel:statusWave Button pickPathButton,pos={6,8},size={80,20},proc=PickBT5PathButton,title="DataPath..." Button pickPathButton,help={"Select the data folder where the raw ICP data files are located"} Button PlotSelected_A_Button,pos={140,148},size={35,20},proc=PlotSelected_AB_ButtonProc,title="Plot" Button PlotSelected_A_Button,help={"Plot the selected sample scattering files in the COR_Graph"} Button PlotSelected_B_Button,pos={140,286},size={35,20},proc=PlotSelected_AB_ButtonProc,title="Plot" Button PlotSelected_B_Button,help={"Plot the selected empty cell scattering files in the COR_Graph"} Button pickSavePathButton,pos={97,8},size={80,20},proc=PickSaveButtonProc,title="SavePath..." Button pickSavePathButton,help={"Select the data folder where data is to be saved to disk"} Button USANSHelpButton,pos={220,6},size={50,20},proc=USANSAddFilesHelpButton,title="Help" Button USANSHelpButton,help={"Show the USANS reduction help file"} SetVariable FilterSetVar,pos={8,289},size={106,18},title="Filter",fSize=12 SetVariable FilterSetVar,value= root:Packages:NIST:USANS:Globals:AddPanel:FilterStr Button A_AddDone,pos={231,414},size={50,20},proc=AddUSANSDone,title="Done" Button A_AddDone,help={"Closes the panel"} Button AddUSANSButton,pos={12,368},size={80,20},proc=AddUSANSFilesButtonProc,title="Add Files" Button AddUSANSButton,help={"Adds the A and B files together"} Button AddUSANSButton,fColor=(16386,65535,16385) Button ClearSumButton,pos={159,322},size={80,20},proc=ClearSumButtonProc,title="Clear Sum" Button ClearSumButton,help={"Clears the summed data from the graph and clears the data in memory"} Button SaveSumButton,pos={13,405},size={80,20},proc=SaveSumButtonProc,title="Move Sum" Button SaveSumButton,help={"Saves the summed data as a fake bt5 file"} Button SaveSumButton,fColor=(16385,28398,65535) EndMacro // Show the help file, don't necessarily keep it with the experiment (/K=1) Function USANSAddFilesHelpButton(ctrlName) : ButtonControl String ctrlName DisplayHelpTopic/Z/K=1 "Adding Two Data Sets" if(V_flag !=0) DoAlert 0,"The USANS Data Reduction Help file could not be found" endif return(0) End Function AddUSANSDone(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here DoWindow/K USANS_Add_Panel break endswitch return 0 End Function AddUSANSFilesButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here Add_AB("") break endswitch return 0 End Function ClearSumButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here RemoveFromGraph/W=USANS_Add_Panel/Z $("DetCts_"+"SUM_AB") CleanOutFolder("SUM_AB") break endswitch return 0 End // really a "move" since I'm not sure about how to poroperly save... // Function SaveSumButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here String type="" Prompt type,"Move the sumed data to:", popup, "EMP;SAM;" DoPrompt "Move Summed Data",type if(V_flag) return(0) endif MoveSummedData(type) break endswitch return 0 End Function Add_AB(ctrlName) : ButtonControl String ctrlName SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder // copy waves over to the SUM_AB folder String fromType = "TMP_A",toType="SUM_AB" Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle_A") Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts_A") Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts_A") Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts_A") Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts_A") fromType = "TMP_B" Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle_B") Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts_B") Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts_B") Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts_B") Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts_B") SetDataFolder $(USANSFolder+":"+toType) Wave Angle_A = Angle_A Wave DetCts_A = DetCts_A Wave MonCts_A = MonCts_A Wave TransCts_A = TransCts_A Wave ErrDetCts_A = ErrDetCts_A Wave Angle_B = Angle_B Wave DetCts_B = DetCts_B Wave MonCts_B = MonCts_B Wave TransCts_B = TransCts_B Wave ErrDetCts_B = ErrDetCts_B Make/O/D/N=0 Angle,DetCts,MonCts,TransCts,ErrDetCts //do something with the wave note on each DetCts wave so it's not lost // String/G note_A = note(DetCts_A) // String/G note_B = note(DetCts_B) Variable minPt,minDelta Variable ii,jj,nA,nB,sumPt=0 nA = numpnts(Angle_A) nB = numpnts(Angle_B) Make/O/D/N=(nB) tmp_delta NVAR tol = root:Packages:NIST:USANS:Globals:AddPanel:gAddUSANSTolerance //1% error allowed as default for(ii=0;ii