source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/USANS/Main_USANS.ipf @ 540

Last change on this file since 540 was 540, checked in by srkline, 13 years ago

Changed T-Wide calculation to be normalized to the monitor counts, hopefully to avoid oddities of MCR fluctuations.

Also handle the case where data greater than 2 degrees is not present. in this case, a warning is presented, and the last 4 points are used, whatever the angles are.

  • Property eol-style set to native
File size: 40.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.21
3#pragma IgorVersion=6.0
4
5//********************
6// 101101 Vers. 1
7//
8// Main initialization procedures for USANS reduction
9// initializes globals and oflders
10// draws the main panel for user interaction
11// action procedures for the USANS_Panel
12//
13//
14//
15// 09 NOV 04 vers 1.1
16// - updated dOmega and dQv
17// - write out dQv to 6-column data sets for analysis compatibility
18//
19//
20//********************
21
22Menu "USANS"
23        "USANS Reduction Panel",ShowUSANSPanel()
24        "Build USANS Notebook"
25        "Desmear USANS Data",Desmear()
26        "-"
27        "Load USANS Data",A_LoadOneDData()
28        "Convert to 6 Columns",Convert3ColTo6Col()
29        "-"
30        "Feedback or Bug Report",U_OpenTracTicketPage("")
31        "Check for Updates",CheckForLatestVersion()
32End
33
34// Bring the USANS_Panel to the front
35// ALWAYS initializes the folders and variables
36// then draws the panel if necessary
37//
38Proc ShowUSANSPanel()
39        //version number
40        Variable/G root:USANS_RED_VERSION=2.21                  //distribution as of Jan 2007
41       
42        Init_MainUSANS()
43        DoWindow/F USANS_Panel
44        if(V_Flag==0)
45                USANS_Panel()
46        Endif
47End
48
49// initializes the folders and globals for use with the USANS_Panel
50// waves for the listboxes must exist before the panel is drawn
51// "dummy" values for the COR_Graph are set here
52// instrumental constants are set here as well
53//
54Proc Init_MainUSANS()
55        NewDataFolder/O root:Packages
56        NewDataFolder/O root:Packages:NIST
57        NewDataFolder/O root:Packages:NIST:USANS
58        NewDataFolder/O root:Packages:NIST:USANS:Globals
59        NewDataFolder/O/S root:Packages:NIST:USANS:Globals:MainPanel
60       
61        String/G root:Packages:NIST:USANS:Globals:gUSANSFolder  = "root:Packages:NIST:USANS"
62        String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
63        //NB This is also hardcoded a bit further down - search for "WHY WHY WHY" AJJ Sept 08
64       
65        //Preference value to determine if we are outputting XML
66        Variable/G root:Packages:NIST:USANS:Globals:gUseXMLOutput = 0
67       
68        Make/O/T/N=1 fileWave,samWave,empWave,curWave //Added curWave Sept 06 A. Jackson
69        fileWave=""
70        samWave=""
71        empWave=""
72        curWave="" //Added Sept 06 A. Jackson
73        //Wave for handling Current Data AJJ Sept 06
74        Make/O/N=1 SAMisCurrent,EMPisCurrent
75        SAMisCurrent = 0
76        EMPisCurrent = 0
77        Make/O/T/N=5 statusWave=""
78        Make/O/B/U/N=1 selFileW
79        Make/O/B/U/N=1 cselFileW
80        //for the graph control bar
81        Variable/G gTransWide = 1
82        Variable/G gTransRock = 1
83        Variable/G gEmpCts = 0.76                       //default values as of 15 DEC 05 J. Barker
84        Variable/G gBkgCts = 0.62                       //default values as of 15 DEC 05 J. Barker
85        Variable/G gThick = 0.1
86        Variable/G gTypeCheck=1
87        Variable/G gTransRatio=1
88        //Text filter for data files AJJ Sept 06
89        String/G FilterStr
90        Variable/G gUseCurrentData = 0
91       
92        SetDataFolder root:
93       
94        NewDataFolder/O $(USANSFolder+":RAW")
95        NewDataFolder/O $(USANSFolder+":SAM")
96        NewDataFolder/O $(USANSFolder+":COR")
97        NewDataFolder/O $(USANSFolder+":EMP")
98        NewDataFolder/O $(USANSFolder+":BKG")
99        NewDataFolder/O $(USANSFolder+":SWAP")
100        NewDataFolder/O $(USANSFolder+":Graph")
101       
102        //dummy waves for bkg and emp levels
103        Make/O $(USANSFolder+":EMP:empLevel"),$(USANSFolder+":BKG:bkgLevel")
104        //WHY WHY WHY????? - because dependencies can only involve globals. No locals allowed, since the dependency
105        // must remain in existence after the function is finished
106        //Explicit dependency
107        root:Packages:NIST:USANS:EMP:empLevel := root:Packages:NIST:USANS:Globals:MainPanel:gEmpCts //dependency to connect to SetVariable in panel
108        root:Packages:NIST:USANS:BKG:bkgLevel := root:Packages:NIST:USANS:Globals:MainPanel:gBkgCts
109
110       
111        //INSTRUMENTAL CONSTANTS
112        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gTheta_H = 3.9e-6            //Darwin FWHM   (pre- NOV 2004)
113        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gTheta_V = 0.014             //Vertical divergence   (pre- NOV 2004)
114        //Variable/G  root:Globals:MainPanel:gDomega = 2.7e-7           //Solid angle of detector (pre- NOV 2004)
115        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gDomega = 7.1e-7             //Solid angle of detector (NOV 2004)
116        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gDefaultMCR= 1e6             //factor for normalization
117       
118        //Variable/G  root:Globals:MainPanel:gDQv = 0.037               //divergence, in terms of Q (1/A) (pre- NOV 2004)
119        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gDQv = 0.117         //divergence, in terms of Q (1/A)  (NOV 2004)
120
121       
122
123End
124
125//draws the USANS_Panel, the main control panel for the macros
126//
127
128Window USANS_Panel() : Panel
129        PauseUpdate; Silent 1           // building window...
130        NewPanel /W=(600,44,1015,493)/K=1 as "USANS_Panel"
131        SetDrawLayer UserBack
132        SetDrawEnv fstyle= 1
133        DrawText 12,53,"Data Files"
134        SetDrawEnv fstyle= 1
135        DrawText 157,192,"Empty Scans"
136        SetDrawEnv fstyle= 1
137        DrawText 154,54,"Sample Scans"
138        DrawLine 6,337,398,337
139        DrawLine 5,33,393,33
140        SetDrawEnv fstyle= 1
141        DrawText 140,357,"Raw Data Header"
142        SetDrawEnv fstyle= 1
143//      DrawText 293,55,"Current Data"
144        ListBox fileLB,pos={5,55},size={110,230},proc=FileListBoxProc
145        ListBox fileLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:fileWave
146        ListBox fileLB,selWave=root:Packages:NIST:USANS:Globals:MainPanel:selFileW,mode= 4
147        ListBox samLB,pos={149,55},size={110,90},listWave=root:Packages:NIST:USANS:Globals:MainPanel:samWave
148        ListBox samLB,mode= 1,selRow= -1
149        Button ClearSamButton,pos={224,148},size={35,21},proc=ClearButtonProc,title="Clr"
150        Button ClearSamButton,help={"Clears the list of sample scans"}
151        Button ClearEmpButton,pos={227,286},size={35,20},proc=ClearButtonProc,title="Clr"
152        Button ClearEmpButton,help={"Clears the list of empty scans"}
153        Button RefreshButton,pos={9,310},size={104,20},proc=RefreshListButtonProc,title="Refresh"
154        Button RefreshButton,help={"Refreshes the list of raw ICP data files"}
155        Button DelSamButton,pos={186,148},size={35,20},proc=DelSamButtonProc,title="Del"
156        Button DelSamButton,help={"Deletes the selected file(s) from the list of sample scans"}
157        Button DelEmpButton,pos={190,286},size={35,20},proc=DelEmpButtonProc,title="Del"
158        Button DelEmpButton,help={"Deletes the selected file(s) from the list of empty scans"}
159        ListBox empLB,pos={151,194},size={110,90}
160        ListBox empLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:empWave,mode= 1,selRow= 0
161        Button toSamList,pos={118,55},size={25,90},proc=toSamListButtonProc,title="S->"
162        Button toSamList,help={"Adds the selected file(s) to the list of sample scans"}
163        Button toEmpList,pos={120,195},size={25,90},proc=toEmptyListButtonProc,title="E->"
164        Button toEmpList,help={"Adds the selected file(s) to the list of empty (cell) scans"}
165        ListBox StatusLB,pos={11,358},size={386,77}
166        ListBox StatusLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:statusWave
167        Button pickPathButton,pos={6,8},size={80,20},proc=PickBT5PathButton,title="DataPath..."
168        Button pickPathButton,help={"Select the data folder where the raw ICP data files are located"}
169        Button PlotSelectedSAMButton,pos={148,148},size={35,20},proc=PlotSelectedSAMButtonProc,title="Plot"
170        Button PlotSelectedSAMButton,help={"Plot the selected sample scattering files in the COR_Graph"}
171        Button PlotSelectedEMPButton,pos={152,286},size={35,20},proc=PlotSelectedEMPButtonProc,title="Plot"
172        Button PlotSelectedEMPButton,help={"Plot the selected empty cell scattering files in the COR_Graph"}
173        Button pickSavePathButton,pos={97,8},size={80,20},proc=PickSaveButtonProc,title="SavePath..."
174        Button pickSavePathButton,help={"Select the data folder where data is to be saved to disk"}
175        Button USANSHelpButton,pos={341,6},size={50,20},proc=USANSHelpButtonProc,title="Help"
176        Button USANSHelpButton,help={"Show the USANS reduction help file"}
177        Button RefreshCurrent,pos={298,310},size={95,20},proc=RefreshCurrentButtonProc,title="Refresh",disable=2
178        Button RefreshCurrent,help={"Updates data files on Charlotte and gets current data file name"}
179        Button AddCurToSAM,pos={264,55},size={25,90},proc=CurtoSamListButtonProc,title="<-S",disable=2
180        Button AddCurToSAM,help={"Adds the current data file to the list of sample scans"}
181        Button AddCurToEMP,pos={265,194},size={25,90},proc=CurtoEmptyListButtonProc,title="<-E",disable=2
182        Button AddCurToEMP,help={"Adds the current data file to the list of empty scans"}
183        ListBox CurFileBox,pos={295,55},size={100,230},proc=FileListBoxProc,disable=1
184        ListBox CurFileBox,listWave=root:Packages:NIST:USANS:Globals:MainPanel:curWave,mode=1
185        SetVariable FilterSetVar,pos={8,289},size={106,18},title="Filter",fSize=12
186        SetVariable FilterSetVar,value= root:Packages:NIST:USANS:Globals:MainPanel:FilterStr
187//      CheckBox UseCurrentData,pos={298,290},size={10,10},proc=UseCurrentDataProc,title="Enable Current Data"
188//      CheckBox UseCurrentData,value=0
189        Button USANSFeedback,pos={220,6},size={100,20},proc=U_OpenTracTicketPage,title="Feedback"
190       
191EndMacro
192
193
194
195//draws a simple graph of the monitor counts, transmission counts, and detector counts
196// plots the selected raw data file when "plot raw" is selected from the USANS_Panel
197//
198Proc GraphRawData()
199        PauseUpdate; Silent 1           // building window...
200        String fldrSav= GetDataFolder(1)
201        String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
202        SetDataFolder $(USANSFolder+":RAW:")
203        //String textStr = StringForRawGraph()
204        //textStr=StringByKey("FILE",textStr,":",";")+" MONRATE:"+num2str(mean(MonCts)/NumberByKey("TIMEPT",textStr,":",";"))
205        Display /W=(600,525,1015,850)/L=left1/B=bottom1 /K=1 DetCts vs Angle as "Raw Data"
206        ModifyGraph margin(top)=50
207        //Display /W=(600,525,1015,850) /K=1 DetCts vs Angle as "Raw Data"
208        DoWindow/C RawDataWin
209        //AppendToGraph/L=left1 /B=bottom1 DetCts vs Angle
210        AppendToGraph/L=left2/B=bottom1 TransCts vs Angle
211        AppendToGraph/L=left3/B=bottom1 MonCts vs Angle
212        SetAxis/A/N=2 left1
213        SetAxis/A/N=2 left2
214        SetAxis/A/N=2 left3
215        ModifyGraph mode=4, marker=19
216        ModifyGraph rgb(TransCts)=(1,4,52428),rgb(MonCts)=(1,39321,19939)
217        ModifyGraph msize=1,grid=1,mirror=2,standoff=1,lblPos=50,tickUnit=1,notation=1,freePos={0.1,kwFraction}
218        ModifyGraph nticks(left2)=2
219        ModifyGraph nticks(left3)=2
220        ModifyGraph mirror(bottom1)=0
221        ModifyGraph axisEnab(left1)={0.1,0.5},gridEnab(left1)={0.1,1}
222        ModifyGraph axisEnab(left2)={0.57,0.77},gridEnab(left2)={0.1,1}
223        ModifyGraph axisEnab(left3)={0.8,1},gridEnab={0.1,1}
224        ModifyGraph axisEnab(bottom1)={0.1,1},gridEnab(bottom1)={0.1,1}
225        ErrorBars/T=0 DetCts Y,wave=(ErrDetCts,ErrDetCts)
226        TextBox/F=0/E=2/A=MB/Y=2/N=text1 "Angle"
227        TextBox/F=0/O=90/E=2/A=LC/X=2/N=text2 "Counts"
228        //TextBox/N=text1/A=RC/X=0.50/Y=-2 textStr
229        //Label bottom1 "Angle (degrees)"
230        Label left1 " "
231        Label left2 " "
232        Label left3 " "
233        TitleForRawGraph()
234        SetDataFolder fldrSav
235End
236
237// plots the selected EMP files onto the COR_Graph
238// Does the following:
239// - loads raw data
240// - normalizes counts to time and 1E6 monitor counts
241// sorts by angle
242// finds zero angle (and peak height)
243// converts to q-values
244// finds T wide
245// updates the graph
246//
247Function PlotSelectedEMPButtonProc(ctrlName) : ButtonControl
248        String ctrlName
249
250        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
251
252        //get selected files from listbox (everything)
253        //use the listBox wave directly
254        Wave/T listW=$(USANSFolder+":Globals:MainPanel:empWave")
255        //Wave for indication of current data set AJJ Sept 2006
256        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
257        Variable ii,num=numpnts(listW)
258        String fname="",fpath="",curPathStr=""
259        PathInfo bt5PathName
260        fpath = S_Path
261        PathInfo bt5CurPathName
262        curPathStr = S_Path
263               
264        if(cmpstr("",listW[0])==0)
265                return(0)               //null item in 1st position, exit
266        Endif
267       
268        //load, normalize, and append
269        //loop over the number of items in the list
270        for(ii=0;ii<num;ii+=1)
271               
272                //Check to see if file is current data set AJJ Sept 06
273                if (isCurrent[ii] ==  1)
274                        fname = curPathStr + listw[ii]
275                else
276                        fname = fpath + listw[ii]
277                endif
278
279               
280                LoadBT5File(fname,"SWAP")       //overwrite what's in the SWAP folder
281                Convert2Countrate("SWAP")
282                if(ii==0)       //first time, overwrite
283                        NewDataWaves("SWAP","EMP")
284                else            //append to waves in "EMP"
285                        AppendDataWaves("SWAP","EMP")
286                endif
287        endfor
288        //sort after all loaded
289        DoAngleSort("EMP")
290       
291        //find the peak and convert to Q-values
292        Variable zeroAngle = FindZeroAngle("EMP")
293        if(zeroAngle == -9999)
294                DoAlert 0,"Couldn't find a peak - using zero as zero angle"
295                zeroAngle = 0
296        Endif
297        ConvertAngle2Qvals("EMP",zeroAngle)
298       
299        //find the Trans Cts for T_Wide
300        FindTWideCts("EMP")
301       
302        //copy the data to plot to the root:Graph directory, and give clear names
303        if(WaveExists($(USANSFolder+":EMP:Qvals")))
304                Duplicate/O $(USANSFolder+":EMP:Qvals"),$(USANSFolder+":Graph:Qvals_EMP")
305        Endif
306        Duplicate/O $(USANSFolder+":EMP:Angle"),$(USANSFolder+":Graph:Angle_EMP")
307        Duplicate/O $(USANSFolder+":EMP:DetCts"),$(USANSFolder+":Graph:DetCts_EMP")
308        Duplicate/O $(USANSFolder+":EMP:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_EMP")
309       
310        //now plot the data (or just bring the graph to the front)
311        DoCORGraph()
312End
313
314// plots the selected SAM files onto the COR_Graph
315// Does the following:
316// - loads raw data
317// - normalizes counts to time and 1E6 monitor counts
318// sorts by angle
319// finds zero angle (and peak height)
320// converts to q-values
321// finds T wide
322// updates the graph
323//
324Function PlotSelectedSAMButtonProc(ctrlName) : ButtonControl
325        String ctrlName
326
327        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
328
329        //get selected files from listbox (everything)
330        //use the listBox wave directly
331        Wave/T listW=$(USANSFolder+":Globals:MainPanel:samWave")
332        //Wave for indication of current data set AJJ Sept 2006
333        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
334        Variable ii,num=numpnts(listW)
335        String fname="",fpath="",curPathStr=""
336        PathInfo bt5PathName
337        fpath = S_Path
338        PathInfo bt5CurPathName
339        curPathStr = S_Path
340       
341//      print fpath
342       
343        if(cmpstr("",listW[0])==0)
344                return(0)               //null item in 1st position, exit
345        Endif
346       
347        //load, normalize, and append
348        //loop over the number of items in the list
349        for(ii=0;ii<num;ii+=1)
350                fname = fpath + listw[ii]
351               
352                //Check to see if file is current data set AJJ Sept 06
353                if (isCurrent[ii] ==  1)
354                        fname = curPathStr + listw[ii]
355                else
356                        fname = fpath + listw[ii]
357                endif
358                               
359                LoadBT5File(fname,"SWAP")       //overwrite what's in the SWAP folder
360                Convert2Countrate("SWAP")
361                if(ii==0)       //first time, overwrite
362                        NewDataWaves("SWAP","SAM")
363                else            //append to waves in "SAM"
364                        AppendDataWaves("SWAP","SAM")
365                endif
366        endfor
367        //sort after all loaded
368        DoAngleSort("SAM")
369       
370        //find the peak and convert to Q-values
371        Variable zeroAngle = FindZeroAngle("SAM")
372        if(zeroAngle == -9999)
373                DoAlert 0,"Couldn't find a peak - using zero as zero angle"
374                zeroAngle = 0
375        Endif
376        ConvertAngle2Qvals("SAM",zeroAngle)
377        //find the Trans Cts for T_Wide
378        FindTWideCts("SAM")
379        //
380        //copy the data to plot to the root:Graph directory, and give clear names
381        if(WaveExists($(USANSFolder+":SAM:Qvals")))
382                Duplicate/O $(USANSFolder+":SAM:Qvals"),$(USANSFolder+":Graph:Qvals_SAM")
383        Endif
384        Duplicate/O $(USANSFolder+":SAM:Angle"),$(USANSFolder+":Graph:Angle_SAM")
385        Duplicate/O $(USANSFolder+":SAM:DetCts"),$(USANSFolder+":Graph:DetCts_SAM")
386        Duplicate/O $(USANSFolder+":SAM:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_SAM")
387       
388        //now plot the data (or just bring the graph to the front)
389        DoCORGraph()
390End
391
392//sort the data in the "type"folder, based on angle
393//carry along all associated waves
394//
395Function DoAngleSort(type)
396        String type
397       
398        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
399       
400        Wave angle = $(USANSFolder+":"+Type+":Angle")
401        Wave detCts = $(USANSFolder+":"+Type+":DetCts")
402        Wave ErrdetCts = $(USANSFolder+":"+Type+":ErrDetCts")
403        Wave MonCts = $(USANSFolder+":"+Type+":MonCts")
404        Wave TransCts = $(USANSFolder+":"+Type+":TransCts")
405       
406        Sort Angle DetCts,ErrDetCts,MonCts,TransCts,Angle
407        return(0)
408End
409
410// converts to countrate per 1E6 monitor counts (default value)
411// by dividing by the counting time (reported in header in seconds per point)
412// and the globally defined monitor count
413//
414// works on data in "type" folder
415//
416// note that trans detector counts are NOT normalized to 1E6 mon cts (not necessary)
417//
418Function Convert2Countrate(type)
419        String type
420       
421        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
422       
423        String noteStr = note($(USANSFolder+":"+Type+":DetCts"))
424        Variable ctTime
425        ctTime = NumberByKey("TIMEPT",noteStr,":",";")
426//      print ctTime
427        //normalize by counting time
428        Wave detCts = $(USANSFolder+":"+Type+":DetCts")
429        Wave ErrdetCts = $(USANSFolder+":"+Type+":ErrDetCts")
430        Wave MonCts = $(USANSFolder+":"+Type+":MonCts")
431        Wave TransCts = $(USANSFolder+":"+Type+":TransCts")
432       
433        detCts /= ctTime
434        ErrDetCts /= ctTime
435        MonCts /= ctTime
436        TransCts /= ctTime
437       
438        //normalize to monitor countrate [=] counts/monitor
439        //trans countrate does not need to be normalized
440        NVAR defaultMCR=$(USANSFolder+":Globals:MainPanel:gDefaultMCR")
441        DetCts /= monCts/defaultMCR
442        ErrDetCts /= MonCts/defaultMCR
443       
444        //adjust the note (now on basis of 1 second)
445        ctTime = 1
446        noteStr = ReplaceNumberByKey("TIMEPT",noteStr,ctTime,":",";")
447        Note/K detCts
448        Note detCts,noteStr
449       
450        return(0)
451End
452
453
454// copies data from one folder to another
455//
456// used for the first set, simply obliterate the old waves in the folder
457//
458Function NewDataWaves(fromType,toType)
459        String fromType,toType
460       
461        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
462
463        Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle")
464        Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts")
465        Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts")
466        Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts")
467        Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts")
468       
469        //check for qvals wave, move if it's there
470        if(WaveExists($(USANSFolder+":"+fromType+":Qvals")))
471                Duplicate/O $(USANSFolder+":"+fromType+":Qvals"),$(USANSFolder+":"+toType+":Qvals")
472        Endif
473       
474End
475
476//to add additional data to a folder, need to concatenate the data in the waves
477//and need to update the wave note associated with "DetCts" to include the additional file
478//
479Function AppendDataWaves(fromType,toType)
480        String fromType,toType
481
482        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
483       
484        String fromNote="",toNote="",newNote="",fromfile="",toFile=""
485       
486       
487        ConcatenateData( (USANSFolder+":"+toType+":Angle"),(USANSFolder+":"+fromType+":Angle") ) //appends "from" at the end of "to"
488        ConcatenateData( (USANSFolder+":"+toType+":DetCts"),(USANSFolder+":"+fromType+":DetCts") )
489        ConcatenateData( (USANSFolder+":"+toType+":ErrDetCts"),(USANSFolder+":"+fromType+":ErrDetCts") )
490        ConcatenateData( (USANSFolder+":"+toType+":MonCts"),(USANSFolder+":"+fromType+":MonCts") )
491        ConcatenateData( (USANSFolder+":"+toType+":TransCts"),(USANSFolder+":"+fromType+":TransCts") )
492       
493
494        //adjust the wavenote, to account for the new dataset
495        fromNote = note($(USANSFolder+":"+fromType+":DetCts"))
496        fromFile = StringByKey("FILE",fromNote,":",";")
497        toNote = note($(USANSFolder+":"+toType+":DetCts"))
498        toFile = StringByKey("FILE",toNote,":",";")
499        toFile += "," + fromfile
500        toNote = ReplaceStringByKey("FILE",toNote,toFile,":",";")
501        Note/K $(USANSFolder+":"+toType+":DetCts")
502        Note $(USANSFolder+":"+toType+":DetCts"),toNote
503       
504        Return(0)
505End
506
507// action procedure to select the raw data path where the bt5 files are located
508//
509Function PickBT5PathButton(PathButton) : ButtonControl
510        String PathButton
511       
512        //Print "DataPathButton Proc"
513        Variable err = PickBT5Path()            //=1 if error
514
515End
516
517//pick the data folder to save the data to - in general must be a local disk, not the ICP database....
518//
519Function PickSaveButtonProc(ctrlName) : ButtonControl
520        String ctrlName
521       
522        NewPath/O/M="SAVE data to the selected folder" savePathName
523        PathInfo/S savePathName
524        String dum = S_path
525        if (V_flag == 0)
526                return(1)
527        else
528                return(0)               //no error
529        endif
530End
531
532// Show the help file, don't necessarily keep it with the experiment (/K=1)
533Function USANSHelpButtonProc(ctrlName) : ButtonControl
534        String ctrlName
535       
536        DisplayHelpTopic/Z/K=1 "USANS Data Reduction"
537        if(V_flag !=0)
538                DoAlert 0,"The USANS Data Reduction Help file could not be found"
539        endif
540        return(0)
541End
542
543//prompts user to choose the local folder that contains the BT5 Data
544//only one folder can be used, and its path is bt5PathName (and is a NAME, not a string)
545//this will overwrite the path selection
546//returns 1 if no path selected as error condition
547Function PickBT5Path()
548       
549        NVAR isChecked = root:Packages:NIST:USANS:Globals:MainPanel:gUseCurrentData
550       
551        //set the global string to the selected pathname
552        NewPath/O/M="pick the BT5 data folder" bt5PathName
553        PathInfo/S bt5PathName
554        String dum = S_path
555        if (V_flag == 0)
556                //Path does not exist
557                return(1)
558        else
559                if (isChecked == 1)
560                        NewPath/O/M="Select Current Data" bt5CurPathName, getCurrentPath(S_Path)
561                        return(0)               //no error
562                Endif
563        endif
564End
565
566//action procedure to load and plot a raw data file
567// loads the data based on selected file and bt5pathname
568// draws a new graph if necessary
569// otherwise just updates the data
570//
571Function PlotRawButtonProc(ctrlName) : ButtonControl
572        String ctrlName
573
574        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
575
576        String fname=""
577       
578        if (cmpstr(ctrlName,"FileLB") == 0)
579                //Print "PlotRaw Button"
580                //take the selection, and simply plot the counts vs. angle - don't save the data anyplace special
581                //get the selected wave
582                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
583                Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
584                Variable ii=0,num=numpnts(sel),err
585
586               
587                PathInfo bt5PathName
588                fname = S_Path
589                do
590                        if(sel[ii] == 1)
591                                fname+=filewave[ii]
592                                break
593                        endif
594                        ii+=1
595                while(ii<num)
596        elseif (cmpstr(ctrlName,"CurFileBox" )== 0)
597                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:curWave")
598                PathInfo bt5CurPathName
599                fname = S_Path
600                fname+=filewave[0]
601        endif
602        //Print fname
603        err = LoadBT5File(fname,"RAW")
604        if(err)
605                return(err)
606        endif
607        //if the "Raw Data" Graph exists, do nothing - else draw it
608        //DoWindow/F RawDataWin
609        if(WinType("RawDataWin")!=1)
610                Execute "GraphRawData()"
611        else
612                //just update the textbox
613                //String textStr=StringForRawGraph()
614                //TextBox/W=RawDataWin/C/N=text1/A=RC/X=0.50/Y=-2 textStr
615                //TextBox/W=RawDataWin/C/E=2/A=MT/X=0/Y=0/N=text0 textStr
616                TitleForRawGraph()
617        Endif
618        //bring the panel back to the front
619        DoWindow/F USANS_Panel
620End
621
622// action procedure for the raw data listbox
623// responds to selection or (shift)selection events
624// by acting if the "status" button was pressed
625//(note that the status button is obsolete and not drawn on the USANS_Panel, but
626// I kept the nomenclature)
627//
628Function FileListBoxProc(ctrlName,row,col,event)
629        String ctrlName
630        Variable row,col,event
631       
632        if (cmpstr(ctrlName, "fileLB") == 0)
633                //event == 4 is a selection
634                //event == 5 is a selection + shift key
635                if( (event==4) || (event==5) )
636                        StatusButtonProc(ctrlName)              //act as if status button was pressed
637                        PlotRawButtonProc(ctrlName)                                     //automatically plots the raw data
638                Endif
639                return(0)
640        elseif (cmpstr(ctrlName,"CurFileBox") == 0)
641                //print "Selected current data"
642                if  (event == 4)
643                        StatusButtonProc(ctrlName)
644                        PlotRawButtonProc(ctrlName)
645                endif
646                return(0)
647        endif
648        return(1)
649End
650
651// displays the status of the selected file in the raw data file list box
652// - spits the information out to a second listbox
653// - called automatically as an action when there is a selection in the file listbox
654// not used as a button procedure anymore
655//
656Function StatusButtonProc(ctrlName)
657        String ctrlName
658
659        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
660
661        String fname=""
662
663
664        if(cmpstr(ctrlName,"fileLB")==0)
665                //Print "Status Button"
666                //display the (first) selected wave
667                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
668                Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
669                Variable ii=0,num=numpnts(sel)
670               
671                PathInfo bt5PathName
672                fname = S_Path
673                do
674                        if(sel[ii] == 1)
675                                fname+=filewave[ii]
676                                break
677                        endif
678                        ii+=1
679                while(ii<num)
680        elseif(cmpstr(ctrlName,"CurFileBox")==0)
681                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:curWave")
682                PathInfo bt5CurPathName
683                fname = S_Path
684                fname+=filewave[0]
685        endif           
686        //Print fname
687        ReadBT5Header(fname)
688End
689
690// copies the selected files from the raw file list box to the sam file listbox
691//
692// makes sure that any null items are removed from the wave attached to the listbox
693//
694Function toSamListButtonProc(ctrlName) : ButtonControl
695        String ctrlName
696
697        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
698
699        //Print "toSamList button"
700        Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
701        Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave")
702        Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
703        //Wave to indicate Current status
704        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
705
706       
707        Variable num=numpnts(sel),ii=0
708        variable lastPt=numpnts(samWave)
709        do
710                if(sel[ii] == 1)
711                        InsertPoints lastPt,1, samWave
712                        samWave[lastPt]=filewave[ii]
713                        InsertPoints lastPt, 1, isCurrent
714                        isCurrent[lastPt] = 0
715                        lastPt +=1
716                endif
717                ii+=1
718        while(ii<num)
719       
720        //clean out any (null) elements
721        num=numpnts(samwave)
722        for(ii=0;ii<num;ii+=1)
723                if(cmpstr(samWave[ii],"") ==0)
724                        DeletePoints ii,1,samWave
725                        DeletePoints ii,1,isCurrent
726                        num -= 1
727                Endif
728        Endfor
729       
730        return(0)
731End
732
733// copies the selected files from the raw file list box to the sam file listbox
734//
735// makes sure that any null items are removed from the wave attached to the listbox
736//
737Function toEmptyListButtonProc(ctrlName) : ButtonControl
738        String ctrlName
739
740        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
741
742        //Print "toEmptyList button"
743        Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
744        Wave/T empWave=$(USANSFolder+":Globals:MainPanel:empWave")
745        Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
746        //Wave to indicate Current status
747        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
748
749
750       
751        Variable num=numpnts(sel),ii=0
752        variable lastPt=numpnts(empWave)
753        do
754                if(sel[ii] == 1)
755                        InsertPoints lastPt,1, empWave
756                        empWave[lastPt]=filewave[ii]
757                        InsertPoints lastPt, 1, isCurrent
758                        isCurrent[lastPt] = 0
759                        lastPt +=1
760                endif
761                ii+=1
762        while(ii<num)
763       
764        //clean out any (null) elements
765        num=numpnts(empwave)
766        for(ii=0;ii<num;ii+=1)
767                if(cmpstr(empWave[ii],"") ==0)
768                        DeletePoints ii,1,empWave
769                        DeletePoints ii,1,isCurrent
770                        num -= 1
771                Endif
772        Endfor
773       
774        return(0)
775End
776
777//deletes the selected file from the sam list
778// multiple selections are not allowed
779// the cor_graph is not updated
780//
781Function DelSamButtonProc(ctrlName) : ButtonControl
782        String ctrlName
783
784        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
785
786        ControlInfo SamLB
787        Variable selRow=V_Value
788        Wave lw=$(S_DataFolder + S_Value)
789        DeletePoints selRow,1,lw       
790        //Clear out current flag AJJ Sept O6
791        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
792        DeletePoints selRow, 1, isCurrent       
793End
794
795//deletes the selected file from the emp list
796// multiple selections are not allowed
797// the cor_graph is not updated
798//
799Function DelEmpButtonProc(ctrlName) : ButtonControl
800        String ctrlName
801
802        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
803
804        ControlInfo EmpLB
805        Variable selRow=V_Value
806        Wave lw=$(S_DataFolder + S_Value)
807        DeletePoints selRow,1,lw
808        //Clear out current flag AJJ Sept O6
809        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
810        DeletePoints selRow, 1, isCurrent       
811End
812
813//refreshes the file list presented in the raw data file listbox
814//bt5PathName is hard-wired in, will prompt if none exists
815// reads directly from disk
816//
817// EXCLUDES all files that do not match "*.bt5*" (not case sensitive)
818//
819// sorts the list to alphabetical order
820//
821Function RefreshListButtonProc(ctrlName) : ButtonControl
822        String ctrlName
823       
824        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
825
826        SVAR FilterStr = $(USANSFolder+":Globals:MainPanel:FilterStr")
827        print FilterStr
828        String filter
829       
830        //check for path and force user to pick a path
831        do
832                PathInfo bt5PathName
833                if(V_Flag)
834                        break
835                Endif
836                PickBT5Path()
837        while(V_Flag==0)
838       
839        //Get the filter and determine the match string required AJJ Sept06
840        if (stringmatch(FilterStr,"!"))
841                filter = FilterStr+"*.bt5*"
842        else
843                filter = "*.bt5*"
844        endif
845       
846        //get all the files, then trim the list
847        String list=IndexedFile(bt5PathName,-1,"????")
848        String newList="",item=""
849        Variable num=ItemsInList(list,";"),ii
850        for(ii=0;ii<num;ii+=1)
851                item = StringFromList(ii, list  ,";")
852               
853                if( stringmatch(item,filter) )          //ONLY keep files that match the filter + *.bt5 AJJ Sept 06
854                        newlist += item + ";"
855                endif
856                //print "ii=",ii
857        endfor
858        newList = SortList(newList,";",0)       //get them in order
859        num=ItemsInList(newlist,";")
860        Wave/T fileWave = $(USANSFolder+":Globals:MainPanel:fileWave")
861        Wave selFileW = $(USANSFolder+":Globals:MainPanel:selFileW")
862        Redimension/N=(num) fileWave
863        Redimension/N=(num) selFileW
864        fileWave=""
865        selFileW = 0
866        fileWave = StringFromList(p,newlist,";")        //  ! quick and easy assignment of the list
867        Sort filewave,filewave
868       
869End
870
871//clears either the sample or empty scan Lists...
872//Also clears the data folders and the COR_Graph
873//
874// very useful to make sure that the data is really what you think it is on the cor_graph
875//
876Function ClearButtonProc(ctrlName) : ButtonControl
877        String ctrlName
878
879        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
880               
881        SetDataFolder $(USANSFolder+":Globals:MainPanel")
882        strswitch(ctrlName)
883                case "ClearSamButton":
884                        Make/O/T/N=1 samWave
885                        samWave=""
886                        //Clear out current flags AJJ Sept O6
887                        Make/O/N=1 SAMisCurrent,EMPisCurrent
888                        SAMisCurrent = 0
889                        EMPisCurrent = 0
890                        //clear the graph, then the data folders as well
891                        CleanOutGraph("SAM")
892                        CleanOutFolder("SAM")
893                        CleanOutGraph("COR")
894                        CleanOutFolder("COR")
895                        break
896                case "ClearEmpButton":
897                        Make/O/T/N=1 empWave
898                        empWave=""
899                        //Clear out current flags AJJ Sept O6
900                        Make/O/N=1 SAMisCurrent,EMPisCurrent
901                        SAMisCurrent = 0
902                        EMPisCurrent = 0
903                        //clear the graph, then the data folders as well
904                        CleanOutGraph("EMP")
905                        CleanOutFolder("EMP")
906                        CleanOutGraph("COR")
907                        CleanOutFolder("COR")
908                        break
909        endswitch
910        // uncheck the cursors
911        UseCrsrCheckProc("",0)
912       
913        DoWindow/F USANS_Panel          //focus back to MainPanel
914        SetDataFolder root:
915End
916
917//reads header information, to display on main panel only
918// called from the action procedure of the raw data listbox
919//
920// puts the pertinent information in the "statusWave" that is associated
921//with the status listbox (which will automatically update)
922//
923Function ReadBT5Header(fname)
924        String fname
925       
926        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
927       
928        Variable err=0,refNum
929        Wave/T statusWave=$(USANSFolder+":Globals:MainPanel:statusWave")
930       
931        Open/R refNum as fname          //READ-ONLY.......if fname is "", a dialog will be presented
932        if(refnum==0)
933                return(1)               //user cancelled
934        endif
935        //read in the ASCII data line-by-line
936        Variable numLinesLoaded = 0,firstchar
937        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead
938        String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10
939       
940        //parse the first line
941        FReadLine refnum,buffer
942        sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8
943        statusWave[0] = "FILE: "+s1
944        statusWave[1] = "DATE: "+s2+" "+s3+" "+s4+" "+s5
945       
946        //v1 is the time per point (sec)
947        //v2  is the monitor prefactor. Let's multiply the time by the prefactor. AJJ 5 March 07
948        statusWave[2] = "TIME/PT: "+num2istr(v1*v2)+" sec"
949       
950        //skip the next line
951        FReadLine refnum,buffer
952        //the next line is the title, use it all except the last character - causes formatting oddities in listBox
953        FReadLine refnum,buffer
954        statusWave[3] = "TITLE: "+ buffer[0,strlen(buffer)-2]
955       
956        //skip the next 3 lines
957        For(ii=0;ii<3;ii+=1)
958                FReadLine refnum,buffer
959        EndFor
960       
961        //parse the angular range from the next line
962        FReadLine refnum,buffer
963        sscanf buffer,"%g%g%g%g",v1,v2,v3,v4
964        statusWave[4] = "RANGE: "+num2str(v2)+" to "+num2str(v4)+" step "+num2str(v3)
965       
966        Close refNum            // Close the file, read-only, so don't need to move to EOF first
967        return err                      // Zero signifies no error.     
968End
969
970// given a string that is the wavenote of the just-loaded raw data file
971// pick out the file and time list items (and values)
972//and return a string that is to be used for the textbox in the graph of raw data
973//
974Function TitleForRawGraph()
975
976        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
977
978        WAVE detCts=$(USANSFolder+":RAW:detCts")
979        WAVE monCts = $(USANSFolder+":RAW:monCts")
980        String str=note(detCts)
981       
982        String retStr="\\JC"
983        retStr += StringByKey("FILE",str,":",";")+"\r"
984        retStr += "Count Time: "+StringByKey("TIMEPT",str,":",";")
985        retStr += " \tMonitor Rate: "+num2str(mean(monCts)/NumberByKey("TIMEPT",str,":",";"))+"\r"
986        retStr += "\\s(DetCts) DetCts \\s(TransCts) TransCts \\s(MonCts) MonCts"
987       
988        TextBox/W=RawDataWin/C/E=2/A=MT/X=5/Y=0/N=text0 retStr
989End
990
991
992//concatenates datasets (full names are passed in as a string)
993//tacks w2 onto the end of w1 (so keep w1)
994//
995// copied from a wavemetrics procedure (concatenatewaves?)
996Function ConcatenateData(w1, w2)
997        String w1, w2
998       
999        Variable numPoints1, numPoints2
1000
1001        if (Exists(w1) == 0)
1002                Duplicate $w2, $w1
1003        else
1004                String wInfo=WaveInfo($w2, 0)
1005                numPoints1 = numpnts($w1)
1006                numPoints2 = numpnts($w2)
1007                Redimension/N=(numPoints1 + numPoints2) $w1
1008                Wave/D ww1=$w1
1009                Wave/D ww2=$w2
1010                ww1[numPoints1, ] = ww2[p-numPoints1]
1011        endif
1012End
1013
1014//takes the given inputs, subtracts EMP and BKG from the SAM data
1015//the user must supply the correct sample thickness, BKGLevel, and EMPLevel for extrapolation
1016Function DoCorrectData()
1017
1018        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1019       
1020        //constants
1021//      NVAR  thetaH = root:Globals:MainPanel:gTheta_H                  //Darwin FWHM
1022//      NVAR  thetaV = root:Globals:MainPanel:gTheta_V                  //Vertical divergence
1023        NVAR dOmega =  $(USANSFolder+":Globals:MainPanel:gDomega")                      //Solid angle of detector
1024        NVAR defaultMCR = $(USANSFolder+":Globals:MainPanel:gDefaultMCR")
1025               
1026        //waves
1027        Wave iqSAM = $(USANSFolder+":SAM:DetCts")
1028        Wave errSAM = $(USANSFolder+":SAM:ErrDetCts")
1029        Wave qvalSAM = $(USANSFolder+":SAM:Qvals")
1030        Wave iqEMP = $(USANSFolder+":EMP:DetCts")
1031        Wave errEMP = $(USANSFolder+":EMP:ErrDetCts")
1032        Wave qvalEMP = $(USANSFolder+":EMP:Qvals")
1033        //BKG,EMP levels,trans,thick
1034        NVAR bkgLevel = $(USANSFolder+":Globals:MainPanel:gBkgCts")
1035        NVAR empLevel =  $(USANSFolder+":Globals:MainPanel:gEmpCts")
1036        NVAR Trock =  $(USANSFolder+":Globals:MainPanel:gTransRock")
1037        NVAR Twide =  $(USANSFolder+":Globals:MainPanel:gTransWide")
1038        NVAR thick =  $(USANSFolder+":Globals:MainPanel:gThick")
1039        //New waves in COR folder, same length as SAM data
1040        Duplicate/O iqSAM,$(USANSFolder+":COR:DetCts")
1041        Duplicate/O errSAM,$(USANSFolder+":COR:ErrDetCts")
1042        Duplicate/O qvalSAM,$(USANSFolder+":COR:Qvals")
1043        Wave iqCOR = $(USANSFolder+":COR:DetCts")
1044        Wave qvalCOR = $(USANSFolder+":COR:Qvals")
1045        Wave errCOR = $(USANSFolder+":COR:ErrDetCts")
1046       
1047        //correction done here
1048        //q-values of EMP must be interpolated to match SAM data
1049        //use the extrapolated value of EMP beyind its measured range
1050        Variable num=numpnts(iqSAM),ii,scale,tempI,temperr,maxq,wq
1051        maxq = qvalEMP[(numpnts(qvalEMP)-1)]            //maximum measure q-value for the empty
1052       
1053        for(ii=0;ii<num;ii+=1)
1054                wq = qvalSAM[ii]        //q-point of the sample
1055                if(wq<maxq)
1056                        tempI = interp(wq,qvalEMP,iqEMP)
1057                        temperr = interp(wq,qvalEMP,errEMP)
1058                else
1059                        tempI = empLevel
1060                        //temperr = sqrt(empLevel)
1061                        temperr = 0             //JGB 5/31/01
1062                endif
1063                iqCOR[ii] = iqSAM[ii] - Trock*tempI - (1-Trock)*bkglevel
1064                errCOR[ii] = sqrt(errSAM[ii]^2 + Trock^2*temperr^2)             //Trock^2; JGB 5/31/01
1065        endfor
1066       
1067        String str=note(iqEMP)
1068        Variable pkHtEMP=NumberByKey("PEAKVAL", str,":",";")
1069        //absolute scaling factor
1070        scale = 1/(Twide*thick*dOmega*pkHtEMP)
1071        iqCOR *= scale
1072        errCOR *= scale
1073       
1074        //copy to Graph directory to plot
1075        Duplicate/O $(USANSFolder+":COR:Qvals"),$(USANSFolder+":Graph:Qvals_COR")
1076        Duplicate/O $(USANSFolder+":COR:DetCts"),$(USANSFolder+":Graph:DetCts_COR")
1077        Duplicate/O $(USANSFolder+":COR:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_COR")
1078       
1079        //now plot the data (or just bring the graph to the front)
1080        DoCORGraph()
1081        return(0)
1082End
1083
1084//cleans out the specified data folder (type)
1085// and clears out the same-named data from the Graph folder
1086// kills what is not in use
1087//
1088Function CleanOutFolder(type)
1089        String type
1090
1091        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder       
1092       
1093        SetDataFolder $(USANSFolder+":"+type)
1094        Killwaves/Z DetCts,Qvals,ErrDetCts,Angle,MonCts,TransCts
1095       
1096        SetDataFolder $(USANSFolder+":Graph")
1097        KillWaves/Z $("DetCts_"+type),$("ErrDetCts_"+type),$("Qvals_"+type)
1098       
1099        SetDataFolder root:
1100End
1101
1102// removes the selected datatype from the COR_Graph
1103//                     
1104Function CleanOutGraph(type)
1105        String type
1106       
1107        DoWindow/F COR_Graph
1108        if(V_flag)
1109                RemoveFromGraph/W=COR_Graph/Z $("DetCts_"+type)
1110        endif
1111End
1112
1113//Edits by AJJ, September 2006
1114//Add functions to get data from Current Folder
1115
1116Function RefreshCurrentButtonProc(ctrlName) : ButtonControl
1117        String ctrlName
1118       
1119        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder       
1120       
1121        //Prod the web update page
1122        //This is a horrible kludge that doesn't really work as the
1123        //webscript does not update the current run as of Sept 26 2006
1124        //Will get Nick M to look into it
1125        BrowseURL/Z "http://www-i.ncnr.nist.gov/icpdata/recent.php?action=1&instr=bt5"
1126       
1127        Print "Waiting 20s for update..."
1128        Sleep/S 20
1129        Print "Waited 20s, new file should be there."
1130       
1131        //check for path and force user to pick a path
1132        //assume that if bt5PathName has been assigned, so has bt5CurPathName
1133        do
1134                PathInfo bt5PathName
1135                if(V_Flag)
1136                        break
1137                Endif
1138                PickBT5Path()
1139        while(V_Flag==0)
1140       
1141        PathInfo bt5CurPathName
1142        if(V_flag==0)
1143                NewPath/O/M="Select Current Data" bt5CurPathName, getCurrentPath(S_Path)
1144        endif
1145               
1146        //get all the files, then trim the list
1147        String list=IndexedFile(bt5CurPathName,-1,"????")
1148        String newList="",item=""
1149        Variable num=ItemsInList(list,";"),ii
1150        for(ii=0;ii<num;ii+=1)
1151                item = StringFromList(ii, list  ,";")
1152                if( stringmatch(item,"*.bt5*") )                //ONLY keep files with ".bt5" in the name (NOT case-sensitive)
1153                        newlist += item + ";"
1154                endif
1155                //print "ii=",ii
1156        endfor
1157        newList = SortList(newList,";",0)       //get them in order
1158        num=ItemsInList(newlist,";")
1159        Wave/T curWave = $(USANSFolder+":Globals:MainPanel:curWave")
1160        Redimension/N=(num) curWave
1161        curWave=""
1162        curWave = StringFromList(p,newlist,";") //  ! quick and easy assignment of the list
1163        Sort curwave,curwave
1164       
1165End
1166
1167//Reduced version of toSamListButtonProc for putting current data into Sample data
1168Function CurtoSamListButtonProc(ctrlName) : ButtonControl
1169        String ctrlName
1170
1171        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1172
1173        Wave/T curWave=$(USANSFolder+":Globals:MainPanel:curWave")
1174        Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave")
1175        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
1176       
1177        Variable num, ii = 0
1178        variable lastPt=numpnts(samWave)
1179       
1180        InsertPoints lastPt,1, samWave
1181        samWave[lastPt]=curwave[ii]
1182        InsertPoints lastPt, 1, isCurrent
1183        isCurrent[lastPt] = 1
1184       
1185        //clean out any (null) elements
1186        num = numpnts(samwave)
1187        for(ii=0;ii<num;ii+=1)
1188                if(cmpstr(samWave[ii],"") ==0)
1189                        DeletePoints ii,1,samWave
1190                        DeletePoints ii,1,isCurrent
1191                        num -= 1
1192                Endif
1193        Endfor
1194       
1195        return(0)
1196End
1197
1198//Reduced version of toEmptyListButtonProc for putting current data into Empty data
1199Function CurtoEmptyListButtonProc(ctrlName) : ButtonControl
1200        String ctrlName
1201
1202        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1203
1204        Wave/T curWave=$(USANSFolder+":Globals:MainPanel:curWave")
1205        Wave/T empWave=$(USANSFolder+":Globals:MainPanel:empWave")
1206        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
1207               
1208        Variable num, ii=0
1209        variable lastPt=numpnts(empWave)
1210
1211        InsertPoints lastPt,1, empWave
1212        empWave[lastPt]=curwave[ii]
1213        InsertPoints lastPt, 1, isCurrent
1214        isCurrent[lastPt] = 1
1215
1216       
1217        //clean out any (null) elements
1218        num=numpnts(empwave)
1219        for(ii=0;ii<num;ii+=1)
1220                if(cmpstr(empWave[ii],"") ==0)
1221                        DeletePoints ii,1,empWave
1222                        DeletePoints ii,1,isCurrent
1223                        num -= 1
1224                Endif
1225        Endfor
1226       
1227       
1228        return(0)
1229End
1230
1231Function UseCurrentDataProc(ctrlName,checked) : CheckBoxControl
1232        String ctrlName
1233        Variable checked
1234
1235        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1236       
1237        NVAR isChecked = $(USANSFolder+":Globals:MainPanel:gUseCurrentData")
1238       
1239        if (checked == 1)
1240                DoAlert 1, "Enabling Current Data requires access to the NCNR Network.\rDo you wish to continue?"
1241                if(V_flag == 1)
1242                        ModifyControl/Z CurFileBox, disable=0
1243                        ModifyControl/Z AddCurToSAM, disable=0
1244                        ModifyControl/Z AddCurToEMP, disable=0
1245                        ModifyControl/Z RefreshCurrent,disable=0
1246                        isChecked = 1
1247                endif
1248        else
1249                ModifyControl/Z CurFileBox, disable=1
1250                ModifyControl/Z AddCurToSAM, disable=2
1251                ModifyControl/Z AddCurToEMP, disable=2
1252                ModifyControl/Z RefreshCurrent,disable=2       
1253                isChecked = 0
1254        endif
1255
1256End
1257
1258//Function to get path for Current file
1259Function/S getCurrentPath(inPath)
1260        String inPath
1261       
1262        Variable pos=0,mpos = 0
1263        Variable i = 0,j = 0
1264        // The saga continues...
1265        // Originally used ParseFilePath - not in Igor 4
1266        // Switched to strsearch, but useful searching from end of string not in Igor 4
1267        // Now have ugly loops going through the string, but should work.
1268
1269        for( i = 0;i<4; i+=1)   
1270                do
1271                        pos = strsearch(inPath,":",j)
1272                        if (pos != -1)
1273                                mpos = pos
1274                        endif
1275                        j = pos+1
1276                while (pos !=-1)
1277               
1278                inPath = inPath[0,mpos -1]
1279                pos = 0
1280                mpos = 0
1281                j = 0
1282        endfor
1283       
1284        inPath = inPath + ":current:"
1285
1286        return inPath
1287       
1288End
1289
1290//
1291Function U_OpenTracTicketPage(ctrlName)
1292        String ctrlName
1293        DoAlert 1,"Your web browser will open to a page where you can submit your bug report or feature request. OK?"
1294        if(V_flag==1)
1295                BrowseURL "http://danse.chem.utk.edu/trac/newticket"
1296        endif
1297End
Note: See TracBrowser for help on using the repository browser.