source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Buttons.ipf @ 890

Last change on this file since 890 was 800, checked in by srkline, 11 years ago

Changed the 2D resolution calculation to include gravity. This seems to work, but will still require some testing. It requires no modifications to the smearing calculation, still using parallel and perpendicular directions.

Added a Fake Update feature to the RealTime? update. There are specific, separate instructions for how to set this up. Usef (possibly) for summer schools or demos.

Adjusted the 2D MonteCarlo? simulation to a corrected beam center. The Gauss Peak was not symmetric around the old beam center.

Corrected the AAO resolution smearing functions to work with cursors.

File size: 9.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//************
6//Vers 1.2 083101
7//
8// Button procedures for control bar on the SANS_Data graph window
9// some additional procedures that are called are in WorkFileUtils
10//******************
11
12//toggles the display from linear to log-scale, changing all waves and global
13//in the currently displayed folder
14Function Log_Lin(ctrlName) : ButtonControl
15        String ctrlName
16       
17        //get the current displayed data (so the correct folder is used)
18        SVAR cur_folder=root:myGlobals:gDataDisplayType
19        Variable err=0
20       
21        if (cmpstr(ctrlName,"bisLog") == 0)
22                //      MakeLinear
23                err = ConvertFolderToLinearScale(cur_folder)            //will abort if there is an error
24                if( !err )
25                        //update the button
26                        Button $ctrlName,title="isLin",rename=bisLin,win=SANS_Data
27                Endif
28        else
29                //make log-scale
30                err = ConvertFolderToLogScale(cur_folder)       //checks for negative values, and will abort if there is an error
31                if( !err )
32                        //update the button
33                        Button $ctrlName,title="isLog",rename=bisLog,win=SANS_Data
34                Endif
35        endif
36       
37        //back to root folder (redundant)
38        SetDataFolder root:
39End
40
41//prints out information about the currently displayed file to the history window
42//
43Function StatusButton(ctrlName) : ButtonControl
44        String ctrlName
45       
46        //get the current displayed data (so the correct folder is used)
47        SVAR cur_folder=root:myGlobals:gDataDisplayType
48        String cur = "root:Packages:NIST:"+cur_folder
49       
50        WAVE reals=$(cur + ":realsread")
51        WAVE ints = $(cur + ":integersRead")
52        WAVE/T text=$(cur + ":textread")
53        SVAR fileList = $(cur +":fileList")
54        String toPrint
55       
56        Print "\r***Current file status***"
57        Print "FILE(S) : " + fileList
58        Print "LABEL:  "+ text[6]
59        sprintf toPrint, "Counting time = %g seconds",ints[2]
60        Print toPrint
61        sprintf toPrint,"Detector counts = %g for %g monitor counts",reals[2],reals[0]
62        Print toPrint
63        sprintf toPrint,"Trans = %g , thick = %g cm,  Xcenter = %g, Ycenter = %g",reals[4],reals[5],reals[16],reals[17]
64        Print toPrint
65        sprintf toPrint,"%g attenuators used",reals[3]
66        Print toPrint
67       
68        //back to root folder (redundant)
69        SetDataFolder root:
70End
71
72
73//Updates the color map used for the SANS data based on the values of the slider bars
74// checks to see which (name) slider was moved and its value. event is ignored
75//
76// procedure is attached to the sliders, but is also called to reset the color map
77// using MapSliderProc("junk",0,0) to skip to default map values
78// MapSliderProc("both",0,0) will produce behavior as if either slider was hit
79// but will poll for values
80//
81// when called by a moving slider, all is OK
82// when called manually to force a reset, SANS_Data window must be the target
83Function MapSliderProc(name, value, event)
84        String name     // name of this slider control
85        Variable value  // value of slider
86        Variable event  // bit field: bit 0: value set; 1: mouse down, 2: mouse up, 3: mouse moved
87       
88        WAVE NIHColors = $"root:myGlobals:NIHColors"
89        Variable loscale,hiScale,maxData,minData,loRange,hiRange
90       
91//      DoWindow/F SANS_Data
92        if(WinType("SANS_Data")==0)             //check for existence without explicity bringing it to the front
93                return(1)               //no data window, don't do anything
94        Endif
95       
96        StrSwitch(name)
97                case "loSlide":
98                        loScale=value
99                        ControlInfo/W=SANS_Data hiSlide
100                        hiScale=V_Value
101                        break
102                case "hiSlide":
103                        hiScale=value
104                        ControlInfo/W=SANS_Data loSlide
105                        loScale=V_Value
106                        break
107                case "both":    //poll both of the sliders for their values
108                        ControlInfo/W=SANS_Data hiSlide
109                        hiScale=V_Value
110                        ControlInfo/W=SANS_Data loSlide
111                        loScale=V_Value
112                        break
113                case "reset":           //reset both of the sliders
114                        Slider hiSlide,win=SANS_Data,value=1
115                        hiScale=1
116                        Slider loSlide,win=SANS_Data,value=0
117                        loScale=0
118                        break
119                default:
120                        loScale=0
121                        hiScale=1
122        endswitch
123        String result = ImageInfo("SANS_Data","data",0)
124        String fullPath = StringByKey("ZWAVEDF", result, ":", ";")
125        fullpath += "data"
126        //Print fullpath
127        WaveStats/Q $fullpath
128        maxData=V_max
129        minData=V_min
130               
131        loRange = (maxData-minData)*loScale + minData
132        hiRange = (maxData-minData)*hiScale + minData
133       
134//      Print loRange,hiRange
135//      ScaleColorsToData((loScale*maxData),(hiScale*maxData),NIHColors)
136        ScaleColorsToData(loRange,hiRange,NIHColors)
137        ModifyImage/W=SANS_Data data cindex=NIHColors
138                       
139        return 0        // other return values reserved
140End
141
142//button procedure to display previous RAW data file
143//incremented by run number, not dependent on file prefix
144Function BackOneFileButtonProc(ctrlName) : ButtonControl
145        String ctrlName
146
147        LoadPlotAndDisplayRAW(-1)
148        // re-draw the sectors or annulus if this was a step to prev/next raw file
149        MasterAngleDraw()
150       
151        return(0)
152End
153
154//button procedure to display next RAW data file
155//incremented by run number, not dependent on file prefix
156Function ForwardOneFileButtonProc(ctrlName) : ButtonControl
157        String ctrlName
158
159        LoadPlotAndDisplayRAW(1)
160        // re-draw the sectors or annulus if this was a step to prev/next raw file
161        MasterAngleDraw()
162       
163        return (0)
164End
165
166//displays next (or previous) file in series of run numbers
167//file is read from disk, if path is set and the file number is present
168//increment +1, adds 1 to run number, -1 subtracts one
169//
170// will automatically step a gap of 10 run numbers, but nothing larger. Don't want to loop too long
171// trying to find a file (frustrating), don't want to look past the end of the run numbers (waste)
172// -- may find a more elegant solution later.
173//
174Function LoadPlotAndDisplayRAW(increment)
175        Variable increment
176
177        Variable i,val
178        String filename,tmp
179        //take the currently displayed RAW file (there is only one name in fileList)
180        SVAR oldName = root:Packages:NIST:RAW:fileList
181        oldname = RemoveAllSpaces(oldname)              // the name in the file list will have 21 chars, thus leading spaces if prefix < 5 chars
182       
183//      print oldName
184       
185        filename = oldname
186//      for (i = 0; i < abs(increment); i += 1)
187//              filename = GetPrevNextRawFile(filename,increment/abs(increment))
188//      endfor 
189        i = 1
190        val = increment
191        do
192//              print filename,val
193                filename = GetPrevNextRawFile(filename,val)
194//              print "new= ",filename
195               
196                val = i*increment
197                i+=1
198                tmp = ParseFilePath(0, filename, ":", 1, 0)
199
200//              print val,strlen(tmp),strlen(oldname)
201//              print cmpstr(tmp,oldname)
202
203                if(strlen(tmp) == 0)            //in some cases, a null string can be returned - handle gracefully
204                        return(0)
205                endif
206               
207        while( (cmpstr(tmp,oldname) == 0) && i < 11)
208//      print filename
209       
210        // display the specified RAW data file
211        String/G root:myGlobals:gDataDisplayType="RAW"
212        ReadHeaderAndData(filename)
213       
214        //do the average and plot (either the default, or what is on the panel currently
215        if(!DataFolderExists("root:myGlobals:Drawing"))
216                Execute "InitializeAveragePanel()"
217        endif
218        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
219       
220        //data is displayed here
221        fRawWindowHook()
222       
223        return(0)
224End
225
226//toggles the overlay of the current mask file
227//no effect if no mask exists
228Proc maskButtonProc(ctrlName) : ButtonControl
229        String ctrlName
230               
231        DoWindow/F SANS_Data             //do nothing if SANS_Data is not displayed, make it target if it is open
232        if(V_flag==0)
233                return
234        endif
235       
236        CheckDisplayed/W=SANS_Data root:Packages:NIST:MSK:overlay
237        if(V_flag==1)           //the overlay is present
238                Button $ctrlName,title="Show Mask",win=SANS_Data
239                OverlayMask(0)          //hide the mask
240        else
241                Button $ctrlName,title="Hide Mask",win=SANS_Data
242                OverlayMask(1)          //show the mask
243        endif
244       
245
246End
247
248//I vs. Q button on control bar of SANS_Data window activates this pocedure
249//and simply displays the AvgPanel to solicit input
250//from the user (graphically) before any averaging is done
251//
252Proc ShowAvgPanel_SANSData(ctrlName) : ButtonControl
253        String ctrlName
254
255        ShowAveragePanel()
256End
257
258
259//invoked by function key, (if menu declared)
260// if no window, or if display type is not RAW, do nothing
261Function NextRawFile()
262
263        DoWindow/F SANS_Data
264        if( V_Flag==0 )
265                return 1                        //return error, currently ignored
266        endif
267        SVAR str=root:myGlobals:gDataDisplayType
268        if(cmpstr(str,"RAW")!=0)
269                return 1
270        endif
271       
272        LoadPlotAndDisplayRAW(1)                //go to next file
273
274        return 0
275end
276
277//invoked by function key, (if menu declared)
278// if no window, or if display type is not RAW, do nothing
279Function PreviousRawFile()
280
281        DoWindow/F SANS_Data
282        if( V_Flag==0 )
283                return 1                        //do nothing and return error, currently ignored
284        endif
285        SVAR str=root:myGlobals:gDataDisplayType
286        if(cmpstr(str,"RAW")!=0)
287                return 1
288        endif
289       
290        LoadPlotAndDisplayRAW(-1)               //go to previous file
291
292        return 0
293end
294
295//test function invoked by F5
296// takes the selected file forom the file catalog
297// and displays that file
298// if several files are selected, displays ONLY the first one
299//
300Function LoadSelectedData()
301
302        if(WinType("CatVSTable")==0)
303                return(1)
304        endif
305        GetSelection table,CatVSTable,3
306       
307        Wave/T fWave = $"root:myGlobals:CatVSHeaderInfo:Filenames"
308        String filename=fWave[V_StartRow]
309        PathInfo catPathName
310       
311        // display the specified RAW data file
312        String/G root:myGlobals:gDataDisplayType="RAW"
313        ReadHeaderAndData(S_Path+filename)
314        //data is displayed here
315        fRawWindowHook()
316
317        // if you want a plot, too
318        //do the average and plot (either the default, or what is on the panel currently
319        if(!DataFolderExists("root:myGlobals:Drawing"))
320                Execute "InitializeAveragePanel()"
321        endif
322        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
323       
324        return(0)
325End
Note: See TracBrowser for help on using the repository browser.