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

Last change on this file since 1140 was 1140, checked in by srkline, 4 years ago

updating the USANS documentation to reflect the new changes in the data format of the column swap and q-values rather than angle.

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