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

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

Made the preference panel fancier, with a tab control. this makes it much easier to add more things in the future. Added two more SANS items to turn off some detector corrections. good for testing, but maybe a bit dangerous.

removed the SANSPreferences procedure file from the general includes list for reduction. kept it in the very old versions of the includes (510 and older) for backwards comaptibility. new experiments start with 520 or higher.

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