source: sans/USANSReduction/branches/AJJ-branch1/Put in User Procedures Folder/USANS Procedures v2.00/Main_USANS.ipf @ 28

Last change on this file since 28 was 28, checked in by ajj, 16 years ago

Used flip to convert files to Unix line endings from Mac.

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