source: sans/USANSReduction/trunk/Put in User Procedures Folder/USANS Procedures v2.20/Main_USANS.ipf @ 51

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

Fixing prefactor bug. See RT Ticket #742

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