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

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

Removed code for old panel - only new panel with current data is now used.

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