#pragma rtGlobals=1 // Use modern global access method. #pragma Version=2.21 #pragma IgorVersion=6.1 //******************** // 101101 Vers. 1 // // Main initialization procedures for USANS reduction // initializes globals and oflders // draws the main panel for user interaction // action procedures for the USANS_Panel // // // // 09 NOV 04 vers 1.1 // - updated dOmega and dQv // - write out dQv to 6-column data sets for analysis compatibility // // //******************** Menu "USANS" "USANS Reduction Panel",ShowUSANSPanel() "Build USANS Notebook" "Desmear USANS Data",Desmear() "Add two raw BT5 files",SelectFilesToAdd() "Add two data sets",ShowUSANSAddPanel() "-" Submenu "1D Utilities" "Load and Plot Manager", Show_Plot_Manager() "Convert to 6 Columns",Convert3ColTo6Col() "ReWrite Experimental Data",MakeDMPanel() //,ReWrite1DData() // SRK SEP10 "1D Arithmetic Panel",MakeDAPanel() "ReBin 1D Data",OpenRebin() end "-" // "Load USANS Data",A_LoadOneDData() // "-" "USANS Simulator",Show_UCALC() "-" "NCNR Preferences",Show_Preferences_Panel() "Feedback or Bug Report",OpenTracTicketPage() "Open Help Movie Page",OpenHelpMoviePage() "Check for Updates",CheckForLatestVersion() End // Bring the USANS_Panel to the front // ALWAYS initializes the folders and variables // then draws the panel if necessary // Proc ShowUSANSPanel() if(itemsinlist(WinList("USANS_Includes.ipf", ";","INCLUDE:6"),";") != 0) //must be opening a v2.2 or earlier template DoAlert 0,"This experiment was created with an old version (v2.2 or earlier) of the macros. I'll try to make this work, but please start new work with a current template" endif //version number Variable/G root:USANS_RED_VERSION=2.3 //distribution as of Jan 2007 Init_MainUSANS() DoWindow/F USANS_Panel if(V_Flag==0) USANS_Panel() Endif DoIgorMenu "Control" "Retrieve All Windows" End // initializes the folders and globals for use with the USANS_Panel // waves for the listboxes must exist before the panel is drawn // "dummy" values for the COR_Graph are set here // instrumental constants are set here as well // Proc Init_MainUSANS() 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:MainPanel if(cmpstr("Macintosh",IgorInfo(2)) == 0) String/G root:Packages:NIST:gAngstStr = num2char(-127) // Variable/G root:myGlobals:gIsMac = 1 else //either Windows or Windows NT String/G root:Packages:NIST:gAngstStr = num2char(-59) // Variable/G root:myGlobals:gIsMac = 0 //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1" endif String/G root:Packages:NIST:USANS:Globals:gUSANSFolder = "root:Packages:NIST:USANS" String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder //NB This is also hardcoded a bit further down - search for "WHY WHY WHY" AJJ Sept 08 Make/O/T/N=1 fileWave,samWave,empWave,curWave //Added curWave Sept 06 A. Jackson fileWave="" samWave="" empWave="" curWave="" //Added Sept 06 A. Jackson //Wave for handling Current Data AJJ Sept 06 Make/O/N=1 SAMisCurrent,EMPisCurrent SAMisCurrent = 0 EMPisCurrent = 0 Make/O/T/N=5 statusWave="" Make/O/B/U/N=1 selFileW Make/O/B/U/N=1 cselFileW //for the graph control bar Variable/G gTransWide = 1 Variable/G gTransRock = 1 Variable/G gEmpCts = 0.76 //default values as of 15 DEC 05 J. Barker Variable/G gBkgCts = 0.62 //default values as of 15 DEC 05 J. Barker Variable/G gThick = 0.1 Variable/G gTypeCheck=1 Variable/G gTransRatio=1 //Text filter for data files AJJ Sept 06 String/G FilterStr Variable/G gUseCurrentData = 0 SetDataFolder root: NewDataFolder/O $(USANSFolder+":RAW") NewDataFolder/O $(USANSFolder+":SAM") NewDataFolder/O $(USANSFolder+":COR") NewDataFolder/O $(USANSFolder+":EMP") NewDataFolder/O $(USANSFolder+":BKG") NewDataFolder/O $(USANSFolder+":SWAP") NewDataFolder/O $(USANSFolder+":Graph") //dummy waves for bkg and emp levels Make/O $(USANSFolder+":EMP:empLevel"),$(USANSFolder+":BKG:bkgLevel") //WHY WHY WHY????? - because dependencies can only involve globals. No locals allowed, since the dependency // must remain in existence after the function is finished //Explicit dependency root:Packages:NIST:USANS:EMP:empLevel := root:Packages:NIST:USANS:Globals:MainPanel:gEmpCts //dependency to connect to SetVariable in panel root:Packages:NIST:USANS:BKG:bkgLevel := root:Packages:NIST:USANS:Globals:MainPanel:gBkgCts // initializes facility specific constants to define the instrument Init_USANS_Facility() //initializes preferences. this includes XML y/n, and SANS Reduction items. // if they already exist, they won't be overwritten Execute "Initialize_Preferences()" End //draws the USANS_Panel, the main control panel for the macros // Window USANS_Panel() PauseUpdate; Silent 1 // building window... NewPanel /W=(600,44,1015,493)/K=1 as "USANS_Panel" 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 // DrawText 293,55,"Current Data" ListBox fileLB,pos={5,55},size={110,230},proc=FileListBoxProc ListBox fileLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:fileWave ListBox fileLB,selWave=root:Packages:NIST:USANS:Globals:MainPanel:selFileW,mode= 4 ListBox samLB,pos={149,55},size={110,90},listWave=root:Packages:NIST:USANS:Globals:MainPanel:samWave ListBox samLB,mode= 1,selRow= -1 Button ClearSamButton,pos={227,148},size={35,20},proc=ClearButtonProc,title="Clr" Button ClearSamButton,help={"Clears the list of sample scans"} Button ClearEmpButton,pos={227,286},size={35,20},proc=ClearButtonProc,title="Clr" Button ClearEmpButton,help={"Clears the list of empty scans"} Button RefreshButton,pos={9,310},size={104,20},proc=RefreshListButtonProc,title="Refresh" Button RefreshButton,help={"Refreshes the list of raw ICP data files"} Button DelSamButton,pos={183,148},size={35,20},proc=DelSamButtonProc,title="Del" Button DelSamButton,help={"Deletes the selected file(s) from the list of sample scans"} Button DelEmpButton,pos={183,286},size={35,20},proc=DelEmpButtonProc,title="Del" Button DelEmpButton,help={"Deletes the selected file(s) from the list of empty scans"} ListBox empLB,pos={151,194},size={110,90} ListBox empLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:empWave,mode= 1,selRow= 0 Button toSamList,pos={120,55},size={25,90},proc=toSamListButtonProc,title="S\r->" Button toSamList,help={"Adds the selected file(s) to the list of sample scans"} Button toEmpList,pos={120,195},size={25,90},proc=toEmptyListButtonProc,title="E\r->" Button toEmpList,help={"Adds the selected file(s) to the list of empty (cell) scans"} ListBox StatusLB,pos={11,358},size={386,77} ListBox StatusLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel: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 PlotSelectedSAMButton,pos={140,148},size={35,20},proc=PlotSelectedSAMButtonProc,title="Plot" Button PlotSelectedSAMButton,help={"Plot the selected sample scattering files in the COR_Graph"} Button PlotSelectedEMPButton,pos={140,286},size={35,20},proc=PlotSelectedEMPButtonProc,title="Plot" Button PlotSelectedEMPButton,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={341,6},size={50,20},proc=USANSHelpButtonProc,title="Help" Button USANSHelpButton,help={"Show the USANS reduction help file"} Button RefreshCurrent,pos={298,310},size={95,20},proc=RefreshCurrentButtonProc,title="Refresh",disable=2 Button RefreshCurrent,help={"Updates data files on Charlotte and gets current data file name"} Button AddCurToSAM,pos={264,55},size={25,90},proc=CurtoSamListButtonProc,title="S\r<-",disable=2 Button AddCurToSAM,help={"Adds the current data file to the list of sample scans"} Button AddCurToEMP,pos={265,194},size={25,90},proc=CurtoEmptyListButtonProc,title="E\r<-",disable=2 Button AddCurToEMP,help={"Adds the current data file to the list of empty scans"} ListBox CurFileBox,pos={295,55},size={100,230},proc=FileListBoxProc,disable=1 ListBox CurFileBox,listWave=root:Packages:NIST:USANS:Globals:MainPanel:curWave,mode=1 SetVariable FilterSetVar,pos={8,289},size={106,18},title="Filter",fSize=12 SetVariable FilterSetVar,value= root:Packages:NIST:USANS:Globals:MainPanel:FilterStr // CheckBox UseCurrentData,pos={298,290},size={10,10},proc=UseCurrentDataProc,title="Enable Current Data" // CheckBox UseCurrentData,value=0 Button USANSFeedback,pos={220,6},size={100,20},proc=OpenTracTicketPage,title="Feedback" EndMacro //draws a simple graph of the monitor counts, transmission counts, and detector counts // plots the selected raw data file when "plot raw" is selected from the USANS_Panel // Proc GraphRawData() PauseUpdate; Silent 1 // building window... String fldrSav= GetDataFolder(1) String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder SetDataFolder $(USANSFolder+":RAW:") //String textStr = StringForRawGraph() //textStr=StringByKey("FILE",textStr,":",";")+" MONRATE:"+num2str(mean(MonCts)/NumberByKey("TIMEPT",textStr,":",";")) Display /W=(600,525,1015,850)/L=left1/B=bottom1 /K=1 DetCts vs Angle as "Raw Data" ModifyGraph margin(top)=50 //Display /W=(600,525,1015,850) /K=1 DetCts vs Angle as "Raw Data" DoWindow/C RawDataWin //AppendToGraph/L=left1 /B=bottom1 DetCts vs Angle AppendToGraph/L=left2/B=bottom1 TransCts vs Angle AppendToGraph/L=left3/B=bottom1 MonCts vs Angle SetAxis/A/N=2 left1 SetAxis/A/N=2 left2 SetAxis/A/N=2 left3 ModifyGraph mode=4, marker=19 ModifyGraph rgb(TransCts)=(1,4,52428),rgb(MonCts)=(1,39321,19939) ModifyGraph msize=1,grid=1,mirror=2,standoff=1,lblPos=50,tickUnit=1,notation=1,freePos={0.1,kwFraction} ModifyGraph nticks(left2)=2 ModifyGraph nticks(left3)=2 ModifyGraph mirror(bottom1)=0 ModifyGraph axisEnab(left1)={0.1,0.5},gridEnab(left1)={0.1,1} ModifyGraph axisEnab(left2)={0.57,0.77},gridEnab(left2)={0.1,1} ModifyGraph axisEnab(left3)={0.8,1},gridEnab={0.1,1} ModifyGraph axisEnab(bottom1)={0.1,1},gridEnab(bottom1)={0.1,1} ErrorBars/T=0 DetCts Y,wave=(ErrDetCts,ErrDetCts) TextBox/F=0/E=2/A=MB/Y=2/N=text1 "Angle" TextBox/F=0/O=90/E=2/A=LC/X=2/N=text2 "Counts" //TextBox/N=text1/A=RC/X=0.50/Y=-2 textStr //Label bottom1 "Angle (degrees)" Label left1 " " Label left2 " " Label left3 " " TitleForRawGraph() SetDataFolder fldrSav End // plots the selected EMP files onto the COR_Graph // Does the following: // - loads raw data // - normalizes counts to time and 1E6 monitor counts // sorts by angle // finds zero angle (and peak height) // converts to q-values // finds T wide // updates the graph // Function PlotSelectedEMPButtonProc(ctrlName) : ButtonControl String ctrlName SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder //get selected files from listbox (everything) //use the listBox wave directly Wave/T listW=$(USANSFolder+":Globals:MainPanel:empWave") //Wave for indication of current data set AJJ Sept 2006 Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") Variable ii,num=numpnts(listW) String fname="",fpath="",curPathStr="" PathInfo bt5PathName fpath = S_Path PathInfo bt5CurPathName curPathStr = S_Path if(cmpstr("",listW[0])==0) return(0) //null item in 1st position, exit Endif //load, normalize, and append //loop over the number of items in the list for(ii=0;ii 0 && ii < numpnts(fileWave)) //make sure that this is not a click in blank space err = LoadBT5File(fname,"RAW") if(err) return(err) endif //if the "Raw Data" Graph exists, do nothing - else draw it //DoWindow/F RawDataWin if(WinType("RawDataWin")!=1) Execute "GraphRawData()" else //just update the textbox //String textStr=StringForRawGraph() //TextBox/W=RawDataWin/C/N=text1/A=RC/X=0.50/Y=-2 textStr //TextBox/W=RawDataWin/C/E=2/A=MT/X=0/Y=0/N=text0 textStr TitleForRawGraph() Endif endif //bring the panel back to the front DoWindow/F USANS_Panel End // action procedure for the raw data listbox // responds to selection or (shift)selection events // by acting if the "status" button was pressed //(note that the status button is obsolete and not drawn on the USANS_Panel, but // I kept the nomenclature) // Function FileListBoxProc(ctrlName,row,col,event) String ctrlName Variable row,col,event if (cmpstr(ctrlName, "fileLB") == 0) //event == 4 is a selection //event == 5 is a selection + shift key if( (event==4) || (event==5) ) StatusButtonProc(ctrlName) //act as if status button was pressed PlotRawButtonProc(ctrlName) //automatically plots the raw data Endif return(0) elseif (cmpstr(ctrlName,"CurFileBox") == 0) //print "Selected current data" if (event == 4) StatusButtonProc(ctrlName) PlotRawButtonProc(ctrlName) endif return(0) endif return(1) End // displays the status of the selected file in the raw data file list box // - spits the information out to a second listbox // - called automatically as an action when there is a selection in the file listbox // not used as a button procedure anymore // Function StatusButtonProc(ctrlName) String ctrlName SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder String fname="" if(cmpstr(ctrlName,"fileLB")==0) //Print "Status Button" //display the (first) selected wave Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave") Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW") Variable ii=0,num=numpnts(sel) PathInfo bt5PathName fname = S_Path do if(sel[ii] == 1) fname+=filewave[ii] break endif ii+=1 while(ii 0 && ii < numpnts(fileWave)) //make sure that this is not a click in blank space ReadBT5Header(fname) endif End // copies the selected files from the raw file list box to the sam file listbox // // makes sure that any null items are removed from the wave attached to the listbox // Function toSamListButtonProc(ctrlName) : ButtonControl String ctrlName SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder //Print "toSamList button" Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave") Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave") Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW") //Wave to indicate Current status Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") Variable num=numpnts(sel),ii=0 variable lastPt=numpnts(samWave) do if(sel[ii] == 1) InsertPoints lastPt,1, samWave samWave[lastPt]=filewave[ii] InsertPoints lastPt, 1, isCurrent isCurrent[lastPt] = 0 lastPt +=1 endif ii+=1 while(ii