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

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

many changes to the VCALC procedures to add in the hard/soft shadowing to the calculation, visualization of the shadowed regions, and the actual q-values. Added a separate panel to view the shadowed regions.

simpe fix to the real time routine to allow easy updating of both the raw 2D data and 1-D average

update to the USANS package to handle the new NICE generated data where the data is collected in terms of q-values rather than angle. On startup asks user which style of data they have. Sets a preference that can be un-checked if you have old-style ICP data. (there is nothing in the data file that I can key on).

  • Property eol-style set to native
File size: 42.0 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
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//
458Function Convert2Countrate(type,doNorm)
459        String type
460        Variable doNorm
461       
462        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
463       
464        String noteStr = note($(USANSFolder+":"+Type+":DetCts"))
465        Variable ctTime
466        ctTime = NumberByKey("TIMEPT",noteStr,":",";")
467//      print ctTime
468        //normalize by counting time
469        Wave detCts = $(USANSFolder+":"+Type+":DetCts")
470        Wave ErrdetCts = $(USANSFolder+":"+Type+":ErrDetCts")
471        Wave MonCts = $(USANSFolder+":"+Type+":MonCts")
472        Wave TransCts = $(USANSFolder+":"+Type+":TransCts")
473       
474        detCts /= ctTime
475        ErrDetCts /= ctTime
476        MonCts /= ctTime
477        TransCts /= ctTime
478       
479        //normalize to monitor countrate [=] counts/monitor
480        //trans countrate does not need to be normalized
481        if(doNorm)
482                NVAR defaultMCR=$(USANSFolder+":Globals:MainPanel:gDefaultMCR")
483                DetCts /= monCts/defaultMCR
484                ErrDetCts /= MonCts/defaultMCR
485        endif
486       
487        //adjust the note (now on basis of 1 second)
488        ctTime = 1
489        noteStr = ReplaceNumberByKey("TIMEPT",noteStr,ctTime,":",";")
490        Note/K detCts
491        Note detCts,noteStr
492       
493        return(0)
494End
495
496
497// copies data from one folder to another
498//
499// used for the first set, simply obliterate the old waves in the folder
500//
501Function NewDataWaves(fromType,toType)
502        String fromType,toType
503       
504        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
505
506        Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle")
507        Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts")
508        Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts")
509        Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts")
510        Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts")
511       
512        //check for qvals wave, move if it's there
513        if(WaveExists($(USANSFolder+":"+fromType+":Qvals")))
514                Duplicate/O $(USANSFolder+":"+fromType+":Qvals"),$(USANSFolder+":"+toType+":Qvals")
515        Endif
516       
517End
518
519//to add additional data to a folder, need to concatenate the data in the waves
520//and need to update the wave note associated with "DetCts" to include the additional file
521//
522Function AppendDataWaves(fromType,toType)
523        String fromType,toType
524
525        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
526       
527        String fromNote="",toNote="",newNote="",fromfile="",toFile=""
528       
529       
530        ConcatenateData( (USANSFolder+":"+toType+":Angle"),(USANSFolder+":"+fromType+":Angle") ) //appends "from" at the end of "to"
531        ConcatenateData( (USANSFolder+":"+toType+":DetCts"),(USANSFolder+":"+fromType+":DetCts") )
532        ConcatenateData( (USANSFolder+":"+toType+":ErrDetCts"),(USANSFolder+":"+fromType+":ErrDetCts") )
533        ConcatenateData( (USANSFolder+":"+toType+":MonCts"),(USANSFolder+":"+fromType+":MonCts") )
534        ConcatenateData( (USANSFolder+":"+toType+":TransCts"),(USANSFolder+":"+fromType+":TransCts") )
535       
536
537        //adjust the wavenote, to account for the new dataset
538        fromNote = note($(USANSFolder+":"+fromType+":DetCts"))
539        fromFile = StringByKey("FILE",fromNote,":",";")
540        toNote = note($(USANSFolder+":"+toType+":DetCts"))
541        toFile = StringByKey("FILE",toNote,":",";")
542        toFile += "," + fromfile
543        toNote = ReplaceStringByKey("FILE",toNote,toFile,":",";")
544        Note/K $(USANSFolder+":"+toType+":DetCts")
545        Note $(USANSFolder+":"+toType+":DetCts"),toNote
546       
547        Return(0)
548End
549
550// action procedure to select the raw data path where the bt5 files are located
551//
552Function PickBT5PathButton(PathButton) : ButtonControl
553        String PathButton
554       
555        //Print "DataPathButton Proc"
556        Variable err = PickBT5Path()            //=1 if error
557
558End
559
560//pick the data folder to save the data to - in general must be a local disk, not the ICP database....
561//
562Function PickSaveButtonProc(ctrlName) : ButtonControl
563        String ctrlName
564       
565        NewPath/O/M="SAVE data to the selected folder" savePathName
566        PathInfo/S savePathName
567        String dum = S_path
568        if (V_flag == 0)
569                return(1)
570        else
571                return(0)               //no error
572        endif
573End
574
575// Show the help file, don't necessarily keep it with the experiment (/K=1)
576Function USANSHelpButtonProc(ctrlName) : ButtonControl
577        String ctrlName
578       
579        DisplayHelpTopic/Z/K=1 "USANS Data Reduction"
580        if(V_flag !=0)
581                DoAlert 0,"The USANS Data Reduction Help file could not be found"
582        endif
583        return(0)
584End
585
586//prompts user to choose the local folder that contains the BT5 Data
587//only one folder can be used, and its path is bt5PathName (and is a NAME, not a string)
588//this will overwrite the path selection
589//returns 1 if no path selected as error condition
590Function PickBT5Path()
591       
592        NVAR isChecked = root:Packages:NIST:USANS:Globals:MainPanel:gUseCurrentData
593       
594        //set the global string to the selected pathname
595        NewPath/O/M="pick the BT5 data folder" bt5PathName
596        PathInfo/S bt5PathName
597        String dum = S_path
598        if (V_flag == 0)
599                //Path does not exist
600                return(1)
601        else
602                if (isChecked == 1)
603                        NewPath/O/M="Select Current Data" bt5CurPathName, getCurrentPath(S_Path)
604                        return(0)               //no error
605                Endif
606        endif
607End
608
609//action procedure to load and plot a raw data file
610// loads the data based on selected file and bt5pathname
611// draws a new graph if necessary
612// otherwise just updates the data
613//
614Function PlotRawButtonProc(ctrlName) : ButtonControl
615        String ctrlName
616
617        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
618
619        String fname=""
620       
621        if (cmpstr(ctrlName,"FileLB") == 0)
622                //Print "PlotRaw Button"
623                //take the selection, and simply plot the counts vs. angle - don't save the data anyplace special
624                //get the selected wave
625                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
626                Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
627                Variable ii=0,num=numpnts(sel),err
628
629               
630                PathInfo bt5PathName
631                fname = S_Path
632                do
633                        if(sel[ii] == 1)
634                                fname+=filewave[ii]
635                                break
636                        endif
637                        ii+=1
638                while(ii<num)
639        elseif (cmpstr(ctrlName,"CurFileBox" )== 0)
640                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:curWave")
641                PathInfo bt5CurPathName
642                fname = S_Path
643                fname+=filewave[0]
644        endif
645        //Print fname
646        if(strlen(fileWave[ii]) > 0 && ii < numpnts(fileWave))          //make sure that this is not a click in blank space
647                err = LoadBT5File(fname,"RAW")
648                if(err)
649                        return(err)
650                endif
651                //if the "Raw Data" Graph exists, do nothing - else draw it
652                //DoWindow/F RawDataWin
653                if(WinType("RawDataWin")!=1)
654                        Execute "GraphRawData()"
655                else
656                        //just update the textbox
657                        //String textStr=StringForRawGraph()
658                        //TextBox/W=RawDataWin/C/N=text1/A=RC/X=0.50/Y=-2 textStr
659                        //TextBox/W=RawDataWin/C/E=2/A=MT/X=0/Y=0/N=text0 textStr
660                        TitleForRawGraph()
661                Endif
662        endif
663        //bring the panel back to the front
664        DoWindow/F USANS_Panel
665End
666
667// action procedure for the raw data listbox
668// responds to selection or (shift)selection events
669// by acting if the "status" button was pressed
670//(note that the status button is obsolete and not drawn on the USANS_Panel, but
671// I kept the nomenclature)
672//
673Function FileListBoxProc(ctrlName,row,col,event)
674        String ctrlName
675        Variable row,col,event
676       
677        if (cmpstr(ctrlName, "fileLB") == 0)
678                //event == 4 is a selection
679                //event == 5 is a selection + shift key
680                if( (event==4) || (event==5) )
681                        StatusButtonProc(ctrlName)              //act as if status button was pressed
682                        PlotRawButtonProc(ctrlName)                                     //automatically plots the raw data
683                Endif
684                return(0)
685        elseif (cmpstr(ctrlName,"CurFileBox") == 0)
686                //print "Selected current data"
687                if  (event == 4)
688                        StatusButtonProc(ctrlName)
689                        PlotRawButtonProc(ctrlName)
690                endif
691                return(0)
692        endif
693        return(1)
694End
695
696// displays the status of the selected file in the raw data file list box
697// - spits the information out to a second listbox
698// - called automatically as an action when there is a selection in the file listbox
699// not used as a button procedure anymore
700//
701Function StatusButtonProc(ctrlName)
702        String ctrlName
703
704        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
705
706        String fname=""
707
708
709        if(cmpstr(ctrlName,"fileLB")==0)
710                //Print "Status Button"
711                //display the (first) selected wave
712                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
713                Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
714                Variable ii=0,num=numpnts(sel)
715               
716                PathInfo bt5PathName
717                fname = S_Path
718                do
719                        if(sel[ii] == 1)
720                                fname+=filewave[ii]
721                                break
722                        endif
723                        ii+=1
724                while(ii<num)
725        elseif(cmpstr(ctrlName,"CurFileBox")==0)
726                Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:curWave")
727                PathInfo bt5CurPathName
728                fname = S_Path
729                fname+=filewave[0]
730        endif           
731        //Print fname
732        if(strlen(fileWave[ii]) > 0 && ii < numpnts(fileWave))          //make sure that this is not a click in blank space
733                ReadBT5Header(fname)
734        endif
735End
736
737// copies the selected files from the raw file list box to the sam file listbox
738//
739// makes sure that any null items are removed from the wave attached to the listbox
740//
741Function toSamListButtonProc(ctrlName) : ButtonControl
742        String ctrlName
743
744        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
745
746        //Print "toSamList button"
747        Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
748        Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave")
749        Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
750        //Wave to indicate Current status
751        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
752
753       
754        Variable num=numpnts(sel),ii=0
755        variable lastPt=numpnts(samWave)
756        do
757                if(sel[ii] == 1)
758                        InsertPoints lastPt,1, samWave
759                        samWave[lastPt]=filewave[ii]
760                        InsertPoints lastPt, 1, isCurrent
761                        isCurrent[lastPt] = 0
762                        lastPt +=1
763                endif
764                ii+=1
765        while(ii<num)
766       
767        //clean out any (null) elements
768        num=numpnts(samwave)
769        for(ii=0;ii<num;ii+=1)
770                if(cmpstr(samWave[ii],"") ==0)
771                        DeletePoints ii,1,samWave
772                        DeletePoints ii,1,isCurrent
773                        num -= 1
774                Endif
775        Endfor
776       
777        return(0)
778End
779
780// copies the selected files from the raw file list box to the sam file listbox
781//
782// makes sure that any null items are removed from the wave attached to the listbox
783//
784Function toEmptyListButtonProc(ctrlName) : ButtonControl
785        String ctrlName
786
787        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
788
789        //Print "toEmptyList button"
790        Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave")
791        Wave/T empWave=$(USANSFolder+":Globals:MainPanel:empWave")
792        Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW")
793        //Wave to indicate Current status
794        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
795
796
797       
798        Variable num=numpnts(sel),ii=0
799        variable lastPt=numpnts(empWave)
800        do
801                if(sel[ii] == 1)
802                        InsertPoints lastPt,1, empWave
803                        empWave[lastPt]=filewave[ii]
804                        InsertPoints lastPt, 1, isCurrent
805                        isCurrent[lastPt] = 0
806                        lastPt +=1
807                endif
808                ii+=1
809        while(ii<num)
810       
811        //clean out any (null) elements
812        num=numpnts(empwave)
813        for(ii=0;ii<num;ii+=1)
814                if(cmpstr(empWave[ii],"") ==0)
815                        DeletePoints ii,1,empWave
816                        DeletePoints ii,1,isCurrent
817                        num -= 1
818                Endif
819        Endfor
820       
821        return(0)
822End
823
824//deletes the selected file from the sam list
825// multiple selections are not allowed
826// the cor_graph is not updated
827//
828Function DelSamButtonProc(ctrlName) : ButtonControl
829        String ctrlName
830
831        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
832
833        ControlInfo SamLB
834        Variable selRow=V_Value
835        Wave lw=$(S_DataFolder + S_Value)
836        DeletePoints selRow,1,lw       
837        //Clear out current flag AJJ Sept O6
838        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
839        DeletePoints selRow, 1, isCurrent       
840End
841
842//deletes the selected file from the emp list
843// multiple selections are not allowed
844// the cor_graph is not updated
845//
846Function DelEmpButtonProc(ctrlName) : ButtonControl
847        String ctrlName
848
849        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
850
851        ControlInfo EmpLB
852        Variable selRow=V_Value
853        Wave lw=$(S_DataFolder + S_Value)
854        DeletePoints selRow,1,lw
855        //Clear out current flag AJJ Sept O6
856        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
857        DeletePoints selRow, 1, isCurrent       
858End
859
860//refreshes the file list presented in the raw data file listbox
861//bt5PathName is hard-wired in, will prompt if none exists
862// reads directly from disk
863//
864// EXCLUDES all files that do not match "*.bt5*" (not case sensitive) (*.ext*)
865//
866// sorts the list to alphabetical order
867//
868// modified to use the correct folder, switching on the control name (AddPanel added)
869//
870Function RefreshListButtonProc(ctrlName) : ButtonControl
871        String ctrlName
872       
873        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
874        SVAR ext = root:Packages:NIST:USANS:Globals:MainPanel:gUExt
875
876        String folderStr=""
877        if(cmpstr(ctrlName,"RefreshButton")==0)
878                //from MainUSANS panel
879                folderStr = "MainPanel"
880        else
881                folderStr = "AddPanel"
882        endif
883       
884        SVAR FilterStr = $(USANSFolder+":Globals:"+folderStr+":FilterStr")
885        print FilterStr
886        String filter
887       
888        //check for path and force user to pick a path
889        do
890                PathInfo bt5PathName
891                if(V_Flag)
892                        break
893                Endif
894                PickBT5Path()
895        while(V_Flag==0)
896       
897        //Get the filter and determine the match string required AJJ Sept06
898        if (stringmatch(FilterStr,"!"))
899                filter = FilterStr+"*"+ext+"*"
900        else
901                filter = "*"+ext+"*"
902        endif
903       
904        //get all the files, then trim the list
905        String list=IndexedFile(bt5PathName,-1,"????")
906        String newList="",item=""
907        Variable num=ItemsInList(list,";"),ii
908        for(ii=0;ii<num;ii+=1)
909                item = StringFromList(ii, list  ,";")
910               
911                if( stringmatch(item,filter) )          //ONLY keep files that match the filter + *.bt5 AJJ Sept 06
912                        newlist += item + ";"
913                endif
914                //print "ii=",ii
915        endfor
916        newList = SortList(newList,";",0)       //get them in order
917        num=ItemsInList(newlist,";")
918        Wave/T fileWave = $(USANSFolder+":Globals:"+folderStr+":fileWave")
919        Wave selFileW = $(USANSFolder+":Globals:"+folderStr+":selFileW")
920        Redimension/N=(num) fileWave
921        Redimension/N=(num) selFileW
922        fileWave=""
923        selFileW = 0
924        fileWave = StringFromList(p,newlist,";")        //  ! quick and easy assignment of the list
925        Sort filewave,filewave
926       
927End
928
929//clears either the sample or empty scan Lists...
930//Also clears the data folders and the COR_Graph
931//
932// very useful to make sure that the data is really what you think it is on the cor_graph
933//
934Function ClearButtonProc(ctrlName) : ButtonControl
935        String ctrlName
936
937        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
938               
939        SetDataFolder $(USANSFolder+":Globals:MainPanel")
940        strswitch(ctrlName)
941                case "ClearSamButton":
942                        Make/O/T/N=1 samWave
943                        samWave=""
944                        //Clear out current flags AJJ Sept O6
945                        Make/O/N=1 SAMisCurrent,EMPisCurrent
946                        SAMisCurrent = 0
947                        EMPisCurrent = 0
948                        //clear the graph, then the data folders as well
949                        CleanOutGraph("SAM")
950                        CleanOutFolder("SAM")
951                        CleanOutGraph("COR")
952                        CleanOutFolder("COR")
953                        break
954                case "ClearEmpButton":
955                        Make/O/T/N=1 empWave
956                        empWave=""
957                        //Clear out current flags AJJ Sept O6
958                        Make/O/N=1 SAMisCurrent,EMPisCurrent
959                        SAMisCurrent = 0
960                        EMPisCurrent = 0
961                        //clear the graph, then the data folders as well
962                        CleanOutGraph("EMP")
963                        CleanOutFolder("EMP")
964                        CleanOutGraph("COR")
965                        CleanOutFolder("COR")
966                        break
967        endswitch
968        // uncheck the cursors
969        UseCrsrCheckProc("",0)
970       
971        DoWindow/F USANS_Panel          //focus back to MainPanel
972        SetDataFolder root:
973End
974
975//reads header information, to display on main panel only
976// called from the action procedure of the raw data listbox
977//
978// puts the pertinent information in the "statusWave" that is associated
979//with the status listbox (which will automatically update)
980//
981Function ReadBT5Header(fname)
982        String fname
983       
984        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
985       
986        Variable err=0,refNum
987        Wave/T statusWave=$(USANSFolder+":Globals:MainPanel:statusWave")
988       
989        Open/R refNum as fname          //READ-ONLY.......if fname is "", a dialog will be presented
990        if(refnum==0)
991                return(1)               //user cancelled
992        endif
993        //read in the ASCII data line-by-line
994        Variable numLinesLoaded = 0,firstchar
995        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead
996        String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10
997       
998        //parse the first line
999        FReadLine refnum,buffer
1000        sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8
1001        statusWave[0] = "FILE: "+s1
1002        statusWave[1] = "DATE: "+s2+" "+s3+" "+s4+" "+s5
1003       
1004        //v1 is the time per point (sec)
1005        //v2  is the monitor prefactor. Let's multiply the time by the prefactor. AJJ 5 March 07
1006        statusWave[2] = "TIME/PT: "+num2istr(v1*v2)+" sec"
1007       
1008        //skip the next line
1009        FReadLine refnum,buffer
1010        //the next line is the title, use it all except the last character - causes formatting oddities in listBox
1011        FReadLine refnum,buffer
1012        statusWave[3] = "TITLE: "+ buffer[0,strlen(buffer)-2]
1013       
1014        //skip the next 3 lines
1015        For(ii=0;ii<3;ii+=1)
1016                FReadLine refnum,buffer
1017        EndFor
1018       
1019        //parse the angular range from the next line
1020        FReadLine refnum,buffer
1021        sscanf buffer,"%g%g%g%g",v1,v2,v3,v4
1022        statusWave[4] = "RANGE: "+num2str(v2)+" to "+num2str(v4)+" step "+num2str(v3)
1023       
1024        Close refNum            // Close the file, read-only, so don't need to move to EOF first
1025        return err                      // Zero signifies no error.     
1026End
1027
1028// given a string that is the wavenote of the just-loaded raw data file
1029// pick out the file and time list items (and values)
1030//and return a string that is to be used for the textbox in the graph of raw data
1031//
1032Function TitleForRawGraph()
1033
1034        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1035
1036        WAVE detCts=$(USANSFolder+":RAW:detCts")
1037        WAVE monCts = $(USANSFolder+":RAW:monCts")
1038        String str=note(detCts)
1039       
1040        String retStr="\\JC"
1041        retStr += StringByKey("FILE",str,":",";")+"\r"
1042        retStr += "Count Time: "+StringByKey("TIMEPT",str,":",";")
1043        retStr += " \tMonitor Rate: "+num2str(mean(monCts)/NumberByKey("TIMEPT",str,":",";"))+"\r"
1044        retStr += "\\s(DetCts) DetCts \\s(TransCts) TransCts \\s(MonCts) MonCts"
1045       
1046        TextBox/W=RawDataWin/C/E=2/A=MT/X=5/Y=0/N=text0 retStr
1047End
1048
1049
1050//concatenates datasets (full names are passed in as a string)
1051//tacks w2 onto the end of w1 (so keep w1)
1052//
1053// copied from a wavemetrics procedure (concatenatewaves?)
1054Function ConcatenateData(w1, w2)
1055        String w1, w2
1056       
1057        Variable numPoints1, numPoints2
1058
1059        if (Exists(w1) == 0)
1060                Duplicate $w2, $w1
1061        else
1062                String wInfo=WaveInfo($w2, 0)
1063                numPoints1 = numpnts($w1)
1064                numPoints2 = numpnts($w2)
1065                Redimension/N=(numPoints1 + numPoints2) $w1
1066                Wave/D ww1=$w1
1067                Wave/D ww2=$w2
1068                ww1[numPoints1, ] = ww2[p-numPoints1]
1069        endif
1070End
1071
1072//takes the given inputs, subtracts EMP and BKG from the SAM data
1073//the user must supply the correct sample thickness, BKGLevel, and EMPLevel for extrapolation
1074Function DoCorrectData()
1075
1076        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1077       
1078        //constants
1079//      NVAR  thetaH = root:Globals:MainPanel:gTheta_H                  //Darwin FWHM
1080//      NVAR  thetaV = root:Globals:MainPanel:gTheta_V                  //Vertical divergence
1081        NVAR dOmega =  $(USANSFolder+":Globals:MainPanel:gDomega")                      //Solid angle of detector
1082        NVAR defaultMCR = $(USANSFolder+":Globals:MainPanel:gDefaultMCR")
1083               
1084        //waves
1085        Wave iqSAM = $(USANSFolder+":SAM:DetCts")
1086        Wave errSAM = $(USANSFolder+":SAM:ErrDetCts")
1087        Wave qvalSAM = $(USANSFolder+":SAM:Qvals")
1088        Wave iqEMP = $(USANSFolder+":EMP:DetCts")
1089        Wave errEMP = $(USANSFolder+":EMP:ErrDetCts")
1090        Wave qvalEMP = $(USANSFolder+":EMP:Qvals")
1091        //BKG,EMP levels,trans,thick
1092        NVAR bkgLevel = $(USANSFolder+":Globals:MainPanel:gBkgCts")
1093        NVAR empLevel =  $(USANSFolder+":Globals:MainPanel:gEmpCts")
1094        NVAR Trock =  $(USANSFolder+":Globals:MainPanel:gTransRock")
1095        NVAR Twide =  $(USANSFolder+":Globals:MainPanel:gTransWide")
1096        NVAR thick =  $(USANSFolder+":Globals:MainPanel:gThick")
1097        //New waves in COR folder, same length as SAM data
1098        Duplicate/O iqSAM,$(USANSFolder+":COR:DetCts")
1099        Duplicate/O errSAM,$(USANSFolder+":COR:ErrDetCts")
1100        Duplicate/O qvalSAM,$(USANSFolder+":COR:Qvals")
1101        Wave iqCOR = $(USANSFolder+":COR:DetCts")
1102        Wave qvalCOR = $(USANSFolder+":COR:Qvals")
1103        Wave errCOR = $(USANSFolder+":COR:ErrDetCts")
1104       
1105        //correction done here
1106        //q-values of EMP must be interpolated to match SAM data
1107        //use the extrapolated value of EMP beyind its measured range
1108        Variable num=numpnts(iqSAM),ii,scale,tempI,temperr,maxq,wq
1109        maxq = qvalEMP[(numpnts(qvalEMP)-1)]            //maximum measure q-value for the empty
1110       
1111        for(ii=0;ii<num;ii+=1)
1112                wq = qvalSAM[ii]        //q-point of the sample
1113                if(wq<maxq)
1114                        tempI = interp(wq,qvalEMP,iqEMP)
1115                        temperr = interp(wq,qvalEMP,errEMP)
1116                else
1117                        tempI = empLevel
1118                        //temperr = sqrt(empLevel)
1119                        temperr = 0             //JGB 5/31/01
1120                endif
1121                iqCOR[ii] = iqSAM[ii] - Trock*tempI - (1-Trock)*bkglevel
1122                errCOR[ii] = sqrt(errSAM[ii]^2 + Trock^2*temperr^2)             //Trock^2; JGB 5/31/01
1123        endfor
1124       
1125        String str=note(iqEMP)
1126        Variable pkHtEMP=NumberByKey("PEAKVAL", str,":",";")
1127        //absolute scaling factor
1128        scale = 1/(Twide*thick*dOmega*pkHtEMP)
1129        iqCOR *= scale
1130        errCOR *= scale
1131       
1132        //copy to Graph directory to plot
1133        Duplicate/O $(USANSFolder+":COR:Qvals"),$(USANSFolder+":Graph:Qvals_COR")
1134        Duplicate/O $(USANSFolder+":COR:DetCts"),$(USANSFolder+":Graph:DetCts_COR")
1135        Duplicate/O $(USANSFolder+":COR:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_COR")
1136       
1137        //now plot the data (or just bring the graph to the front)
1138        DoCORGraph()
1139        return(0)
1140End
1141
1142//cleans out the specified data folder (type)
1143// and clears out the same-named data from the Graph folder
1144// kills what is not in use
1145//
1146Function CleanOutFolder(type)
1147        String type
1148
1149        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder       
1150       
1151        SetDataFolder $(USANSFolder+":"+type)
1152        Killwaves/Z DetCts,Qvals,ErrDetCts,Angle,MonCts,TransCts
1153       
1154        SetDataFolder $(USANSFolder+":Graph")
1155        KillWaves/Z $("DetCts_"+type),$("ErrDetCts_"+type),$("Qvals_"+type)
1156       
1157        SetDataFolder root:
1158End
1159
1160// removes the selected datatype from the COR_Graph
1161//                     
1162Function CleanOutGraph(type)
1163        String type
1164       
1165        DoWindow/F COR_Graph
1166        if(V_flag)
1167                RemoveFromGraph/W=COR_Graph/Z $("DetCts_"+type)
1168        endif
1169End
1170
1171//Edits by AJJ, September 2006
1172//Add functions to get data from Current Folder
1173
1174Function RefreshCurrentButtonProc(ctrlName) : ButtonControl
1175        String ctrlName
1176       
1177        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder       
1178        SVAR ext = root:Packages:NIST:USANS:Globals:MainPanel:gUExt
1179
1180        //Prod the web update page
1181        //This is a horrible kludge that doesn't really work as the
1182        //webscript does not update the current run as of Sept 26 2006
1183        //Will get Nick M to look into it
1184        BrowseURL/Z "http://www-i.ncnr.nist.gov/icpdata/recent.php?action=1&instr=bt5"
1185       
1186        Print "Waiting 20s for update..."
1187        Sleep/S 20
1188        Print "Waited 20s, new file should be there."
1189       
1190        //check for path and force user to pick a path
1191        //assume that if bt5PathName has been assigned, so has bt5CurPathName
1192        do
1193                PathInfo bt5PathName
1194                if(V_Flag)
1195                        break
1196                Endif
1197                PickBT5Path()
1198        while(V_Flag==0)
1199       
1200        PathInfo bt5CurPathName
1201        if(V_flag==0)
1202                NewPath/O/M="Select Current Data" bt5CurPathName, getCurrentPath(S_Path)
1203        endif
1204               
1205        //get all the files, then trim the list
1206        String list=IndexedFile(bt5CurPathName,-1,"????")
1207        String newList="",item=""
1208        Variable num=ItemsInList(list,";"),ii
1209        for(ii=0;ii<num;ii+=1)
1210                item = StringFromList(ii, list  ,";")
1211                if( stringmatch(item,"*"+ext+"*") )             //ONLY keep files with ".bt5" in the name (NOT case-sensitive)
1212                        newlist += item + ";"
1213                endif
1214                //print "ii=",ii
1215        endfor
1216        newList = SortList(newList,";",0)       //get them in order
1217        num=ItemsInList(newlist,";")
1218        Wave/T curWave = $(USANSFolder+":Globals:MainPanel:curWave")
1219        Redimension/N=(num) curWave
1220        curWave=""
1221        curWave = StringFromList(p,newlist,";") //  ! quick and easy assignment of the list
1222        Sort curwave,curwave
1223       
1224End
1225
1226//Reduced version of toSamListButtonProc for putting current data into Sample data
1227Function CurtoSamListButtonProc(ctrlName) : ButtonControl
1228        String ctrlName
1229
1230        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1231
1232        Wave/T curWave=$(USANSFolder+":Globals:MainPanel:curWave")
1233        Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave")
1234        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent")
1235       
1236        Variable num, ii = 0
1237        variable lastPt=numpnts(samWave)
1238       
1239        InsertPoints lastPt,1, samWave
1240        samWave[lastPt]=curwave[ii]
1241        InsertPoints lastPt, 1, isCurrent
1242        isCurrent[lastPt] = 1
1243       
1244        //clean out any (null) elements
1245        num = numpnts(samwave)
1246        for(ii=0;ii<num;ii+=1)
1247                if(cmpstr(samWave[ii],"") ==0)
1248                        DeletePoints ii,1,samWave
1249                        DeletePoints ii,1,isCurrent
1250                        num -= 1
1251                Endif
1252        Endfor
1253       
1254        return(0)
1255End
1256
1257//Reduced version of toEmptyListButtonProc for putting current data into Empty data
1258Function CurtoEmptyListButtonProc(ctrlName) : ButtonControl
1259        String ctrlName
1260
1261        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1262
1263        Wave/T curWave=$(USANSFolder+":Globals:MainPanel:curWave")
1264        Wave/T empWave=$(USANSFolder+":Globals:MainPanel:empWave")
1265        Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent")
1266               
1267        Variable num, ii=0
1268        variable lastPt=numpnts(empWave)
1269
1270        InsertPoints lastPt,1, empWave
1271        empWave[lastPt]=curwave[ii]
1272        InsertPoints lastPt, 1, isCurrent
1273        isCurrent[lastPt] = 1
1274
1275       
1276        //clean out any (null) elements
1277        num=numpnts(empwave)
1278        for(ii=0;ii<num;ii+=1)
1279                if(cmpstr(empWave[ii],"") ==0)
1280                        DeletePoints ii,1,empWave
1281                        DeletePoints ii,1,isCurrent
1282                        num -= 1
1283                Endif
1284        Endfor
1285       
1286       
1287        return(0)
1288End
1289
1290Function UseCurrentDataProc(ctrlName,checked) : CheckBoxControl
1291        String ctrlName
1292        Variable checked
1293
1294        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
1295       
1296        NVAR isChecked = $(USANSFolder+":Globals:MainPanel:gUseCurrentData")
1297       
1298        if (checked == 1)
1299                DoAlert 1, "Enabling Current Data requires access to the NCNR Network.\rDo you wish to continue?"
1300                if(V_flag == 1)
1301                        ModifyControl/Z CurFileBox, disable=0
1302                        ModifyControl/Z AddCurToSAM, disable=0
1303                        ModifyControl/Z AddCurToEMP, disable=0
1304                        ModifyControl/Z RefreshCurrent,disable=0
1305                        isChecked = 1
1306                endif
1307        else
1308                ModifyControl/Z CurFileBox, disable=1
1309                ModifyControl/Z AddCurToSAM, disable=2
1310                ModifyControl/Z AddCurToEMP, disable=2
1311                ModifyControl/Z RefreshCurrent,disable=2       
1312                isChecked = 0
1313        endif
1314
1315End
1316
1317//Function to get path for Current file
1318Function/S getCurrentPath(inPath)
1319        String inPath
1320       
1321        Variable pos=0,mpos = 0
1322        Variable i = 0,j = 0
1323        // The saga continues...
1324        // Originally used ParseFilePath - not in Igor 4
1325        // Switched to strsearch, but useful searching from end of string not in Igor 4
1326        // Now have ugly loops going through the string, but should work.
1327
1328        for( i = 0;i<4; i+=1)   
1329                do
1330                        pos = strsearch(inPath,":",j)
1331                        if (pos != -1)
1332                                mpos = pos
1333                        endif
1334                        j = pos+1
1335                while (pos !=-1)
1336               
1337                inPath = inPath[0,mpos -1]
1338                pos = 0
1339                mpos = 0
1340                j = 0
1341        endfor
1342       
1343        inPath = inPath + ":current:"
1344
1345        return inPath
1346       
1347End
Note: See TracBrowser for help on using the repository browser.