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

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

Change (1):
In preparation for release, updated pragma IgorVersion?=6.1 in all procedures

Change (2):
As a side benefit of requiring 6.1, we can use the MultiThread? keyword to thread any model function we like. The speed benefit is only noticeable on functions that require at least one integration and at least 100 points (resolution smearing is NOT threaded, too many threadSafe issues, too little benefit). I have chosen to use the MultiThread? only on the XOP assignment. In the Igor code there are too many functions that are not explicitly declared threadsafe, making for a mess.

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