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

Last change on this file since 765 was 765, checked in by ajj, 12 years ago

Date dependent deadtime corrections for main and transmission detectors on USANS

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