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

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