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

Last change on this file since 740 was 740, checked in by srkline, 12 years ago

Added 1D data processing routines to the USANS package.

Added the Data Management panel to all menus - "ReWrite? Experimental Data". This mainly adds the functionality to convert data back and forth between XML and 6-column. Still needs debugging.

Added menu item for Rebinning of 1D data. Brings up a separate panel, since I couldn't figure out where it really belonged. It's small enough that it could be added to most any panel. Routines are at the end of the DataSetHandling?.ipf file.

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