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

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

Bug fixes to USANS procedures to clean up changes with new Packages:NIST: subfolder structure.

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