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

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

Made preferences a common panel (moved to PlotUtilsMacro?.ipf and globals to root:Packages:NIST:) and added menu items for all packages. Many files had to be modified so that the preferences could be properly accessed

File Open dialog now is set to "All files" so that XML can be selected. I think that all open access that doesn't already have the full path go through this common function.

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