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

Last change on this file since 764 was 754, checked in by srkline, 12 years ago

added fDoBinning_QxQy2D(folderStr) that takes the QxQyQz? data and bins it to I(Q) (PlotUtils2D)

added comments to Sphere_2D describing how the 2D smearing calculation is different than the 1D calculation

the trac ticket page button on the USANS panel now points to the correct function

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