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

Last change on this file since 477 was 477, checked in by srkline, 14 years ago

Added save/restore buttons to SimpleGlobal? fit to be able to restore the state of the checkboxes if possible. Checkboxes are reset when new data sets are selected.

Typos in SANSRedn help file have been corrected.

Error bar styles have been changed to /T=0, a vertical line with no horizontal bar. My preference - I got tired of seeing more of the horizontal bar than the actual data.

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