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

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

Lots of changes to add the first version of a USANS simulator, like SASCALC

(!) first issue is with the entanglement of dependencies - need to load SANS macros first!

otherwise, worth a first test for interface and accuracy. behavior is similar to the 1D SASCALC

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