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

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

Corrected the identification of HFIR trans files

Added new includes for analysis and usans, with higher version numbers. the old ones now simply point to the new one. this provides a mechanism for identifying experiments that were generated and saved with an older version of the macros - the old include file will be present. All three packages now display an alert if the experiment was generated from asn old version of the macros.

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