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

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

Added routines to enforce short enough names to keep the Igor-generated object names to less than 31 characters (once I add extensions). Changed the ExecuteProtocol? to automatically trim text from the HFIR data file names, since they are ridiculously long.

Added routines in 1D Data loader (and XML loader) to enforce 25 characters, in the case that a long file name was generated by another program.

If XML files are generated, "x" is tagged at the end of the suffix, as in ".ABSx".
Added menu items to each package menu for feedback, movies, and updates

Made sure that new table entry of SamplePosition? did not cause compile errors with other facility templates. right now, this is NCNR-specific, but easity added to other facilities if they provide the stub. then the bits of the table could be added.

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