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

Last change on this file since 1103 was 807, checked in by srkline, 11 years ago

Initial separation of facility-specific initialization from the USANS reduction procedures. This is being done to enable the KIST-USANS instrument to use the NCNR reduction scheme. KIST will duplicate the .bt5 file structure but use a different extension.

For this, files for KIST have been created for USANS-specifc, and for some SANS-specific procedures that are entangled with the XML writing and with the USANS simulator.

Corresponding changes (new U_NCNR_Utils) have been added for NCNR-specific USANS initialization.

More will need to be done to disentangle the U_CALC, but at a later date. See ticket #334.

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