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

Last change on this file since 779 was 764, checked in by srkline, 12 years ago
  • fixed a few bugs with GenCurveFit?, and how the reports are generated


  • the DEFAULT.MASK file is automatically loaded when the path is set, if it can be found. this only happens from the main (yellow) panel. Nothing happens if that exact file is not found.


  • a "Sector_PlusMinus" averaging option is added. This defines the LEFT sector as being "negative" q-values. Everything else behaves as a normal sector average. This is from Lionel, a very old ticket #31


  • if sectors or annular regions are drawn on RAW data files, the drawn lines are re-drawn correctly as the data is scrolled using the < and > buttons.


  • a super secret option for a "histogram pair" has been added. May be useful for alignment, may ditch if Jeff and Cedric don't like it. To do this, put cursor A on the 2D image at the center of where you want the vertical and horizontal swath to be. +-5 pixels is hard-wired. draw any marquee(size, location is ignored) and select SANS Histogram, and you get the pair. If cursor A is not on the graph, you get the normal histogram as defined by the marquee.


  • arrow buttons on RAW 2D data display now search +- 10 data files for "next", in case there are missing file numbers.


  • Incorporated Lionel's changes to ILL_* files for his generation of a "DIV" file for D22


  • Added the offset traces checkbox back to the SASCALC panel. previously it was hidden on the simulation panels.


  • loosened the tolerance for SDD matching onn the MRED panel to 0.1 m



File size: 10.3 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/////not used////
73// function control a background task of "live" image updating
74//
75Function UpdateImage(ctrlName) : ButtonControl
76        String ctrlName
77       
78        if (cmpstr(ctrlName,"bStart") == 0)
79                Button $ctrlName,title="Stop",rename=bStop
80        //      Start the updating - FakeUpdate() has been designated as the background task
81                CtrlBackground period=60,start
82        else
83                Button $ctrlName,title="Start",rename=bStart
84        //      Stop the updating
85                CtrlBackground stop
86        endif
87End
88
89//not used, but useful for real-time display of the detector
90//old, and likely not up-to-date with the present data folder structure
91Function FakeUpdate()
92
93        //get the current displayed data (so the correct folder is used)
94        SVAR cur_folder=root:myGlobals:gDataDisplayType
95        SetDataFolder "root:Packages:NIST:"+cur_folder          //use the full path, so it will always work
96        WAVE data = $"data"
97//      WAVE vlegend = $"vlegend"
98       
99        //alter the raw data
100        data = abs(enoise(10))
101       
102        // adjust the color bar
103        WaveStats/Q data
104//      SetScale/I y,V_min,V_max,"" vlegend
105//      vlegend=y
106               
107        // assume all is OK, return 0
108        // button1 controls the start/stop of the background task
109       
110        //back to root folder
111        SetDataFolder root:
112       
113        return 0
114End
115
116//Updates the color map used for the SANS data based on the values of the slider bars
117// checks to see which (name) slider was moved and its value. event is ignored
118//
119// procedure is attached to the sliders, but is also called to reset the color map
120// using MapSliderProc("junk",0,0) to skip to default map values
121// MapSliderProc("both",0,0) will produce behavior as if either slider was hit
122// but will poll for values
123//
124// when called by a moving slider, all is OK
125// when called manually to force a reset, SANS_Data window must be the target
126Function MapSliderProc(name, value, event)
127        String name     // name of this slider control
128        Variable value  // value of slider
129        Variable event  // bit field: bit 0: value set; 1: mouse down, 2: mouse up, 3: mouse moved
130       
131        WAVE NIHColors = $"root:myGlobals:NIHColors"
132        Variable loscale,hiScale,maxData,minData,loRange,hiRange
133       
134//      DoWindow/F SANS_Data
135        if(WinType("SANS_Data")==0)             //check for existence without explicity bringing it to the front
136                return(1)               //no data window, don't do anything
137        Endif
138       
139        StrSwitch(name)
140                case "loSlide":
141                        loScale=value
142                        ControlInfo/W=SANS_Data hiSlide
143                        hiScale=V_Value
144                        break
145                case "hiSlide":
146                        hiScale=value
147                        ControlInfo/W=SANS_Data loSlide
148                        loScale=V_Value
149                        break
150                case "both":    //poll both of the sliders for their values
151                        ControlInfo/W=SANS_Data hiSlide
152                        hiScale=V_Value
153                        ControlInfo/W=SANS_Data loSlide
154                        loScale=V_Value
155                        break
156                case "reset":           //reset both of the sliders
157                        Slider hiSlide,win=SANS_Data,value=1
158                        hiScale=1
159                        Slider loSlide,win=SANS_Data,value=0
160                        loScale=0
161                        break
162                default:
163                        loScale=0
164                        hiScale=1
165        endswitch
166        String result = ImageInfo("SANS_Data","data",0)
167        String fullPath = StringByKey("ZWAVEDF", result, ":", ";")
168        fullpath += "data"
169        //Print fullpath
170        WaveStats/Q $fullpath
171        maxData=V_max
172        minData=V_min
173               
174        loRange = (maxData-minData)*loScale + minData
175        hiRange = (maxData-minData)*hiScale + minData
176       
177//      Print loRange,hiRange
178//      ScaleColorsToData((loScale*maxData),(hiScale*maxData),NIHColors)
179        ScaleColorsToData(loRange,hiRange,NIHColors)
180        ModifyImage/W=SANS_Data data cindex=NIHColors
181                       
182        return 0        // other return values reserved
183End
184
185//button procedure to display previous RAW data file
186//incremented by run number, not dependent on file prefix
187Function BackOneFileButtonProc(ctrlName) : ButtonControl
188        String ctrlName
189
190        LoadPlotAndDisplayRAW(-1)
191        // re-draw the sectors or annulus if this was a step to prev/next raw file
192        MasterAngleDraw()
193       
194        return(0)
195End
196
197//button procedure to display next RAW data file
198//incremented by run number, not dependent on file prefix
199Function ForwardOneFileButtonProc(ctrlName) : ButtonControl
200        String ctrlName
201
202        LoadPlotAndDisplayRAW(1)
203        // re-draw the sectors or annulus if this was a step to prev/next raw file
204        MasterAngleDraw()
205       
206        return (0)
207End
208
209//displays next (or previous) file in series of run numbers
210//file is read from disk, if path is set and the file number is present
211//increment +1, adds 1 to run number, -1 subtracts one
212//
213// will automatically step a gap of 10 run numbers, but nothing larger. Don't want to loop too long
214// trying to find a file (frustrating), don't want to look past the end of the run numbers (waste)
215// -- may find a more elegant solution later.
216//
217Function LoadPlotAndDisplayRAW(increment)
218        Variable increment
219
220        Variable i,val
221        String filename,tmp
222        //take the currently displayed RAW file (there is only one name in fileList)
223        SVAR oldName = root:Packages:NIST:RAW:fileList
224        oldname = RemoveAllSpaces(oldname)              // the name in the file list will have 21 chars, thus leading spaces if prefix < 5 chars
225       
226//      print oldName
227       
228        filename = oldname
229//      for (i = 0; i < abs(increment); i += 1)
230//              filename = GetPrevNextRawFile(filename,increment/abs(increment))
231//      endfor 
232        i = 1
233        val = increment
234        do
235//              print filename,val
236                filename = GetPrevNextRawFile(filename,val)
237//              print "new= ",filename
238               
239                val = i*increment
240                i+=1
241                tmp = ParseFilePath(0, filename, ":", 1, 0)
242
243//              print val,strlen(tmp),strlen(oldname)
244//              print cmpstr(tmp,oldname)
245
246                if(strlen(tmp) == 0)            //in some cases, a null string can be returned - handle gracefully
247                        return(0)
248                endif
249               
250        while( (cmpstr(tmp,oldname) == 0) && i < 11)
251//      print filename
252       
253        // display the specified RAW data file
254        String/G root:myGlobals:gDataDisplayType="RAW"
255        ReadHeaderAndData(filename)
256       
257        //do the average and plot (either the default, or what is on the panel currently
258        if(!DataFolderExists("root:myGlobals:Drawing"))
259                Execute "InitializeAveragePanel()"
260        endif
261        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
262       
263        //data is displayed here
264        fRawWindowHook()
265       
266        return(0)
267End
268
269//toggles the overlay of the current mask file
270//no effect if no mask exists
271Proc maskButtonProc(ctrlName) : ButtonControl
272        String ctrlName
273               
274        DoWindow/F SANS_Data             //do nothing if SANS_Data is not displayed, make it target if it is open
275        if(V_flag==0)
276                return
277        endif
278       
279        CheckDisplayed/W=SANS_Data root:Packages:NIST:MSK:overlay
280        if(V_flag==1)           //the overlay is present
281                Button $ctrlName,title="Show Mask",win=SANS_Data
282                OverlayMask(0)          //hide the mask
283        else
284                Button $ctrlName,title="Hide Mask",win=SANS_Data
285                OverlayMask(1)          //show the mask
286        endif
287       
288
289End
290
291//I vs. Q button on control bar of SANS_Data window activates this pocedure
292//and simply displays the AvgPanel to solicit input
293//from the user (graphically) before any averaging is done
294//
295Proc ShowAvgPanel_SANSData(ctrlName) : ButtonControl
296        String ctrlName
297
298        ShowAveragePanel()
299End
300
301
302//invoked by function key, (if menu declared)
303// if no window, or if display type is not RAW, do nothing
304Function NextRawFile()
305
306        DoWindow/F SANS_Data
307        if( V_Flag==0 )
308                return 1                        //return error, currently ignored
309        endif
310        SVAR str=root:myGlobals:gDataDisplayType
311        if(cmpstr(str,"RAW")!=0)
312                return 1
313        endif
314       
315        LoadPlotAndDisplayRAW(1)                //go to next file
316
317        return 0
318end
319
320//invoked by function key, (if menu declared)
321// if no window, or if display type is not RAW, do nothing
322Function PreviousRawFile()
323
324        DoWindow/F SANS_Data
325        if( V_Flag==0 )
326                return 1                        //do nothing and return error, currently ignored
327        endif
328        SVAR str=root:myGlobals:gDataDisplayType
329        if(cmpstr(str,"RAW")!=0)
330                return 1
331        endif
332       
333        LoadPlotAndDisplayRAW(-1)               //go to previous file
334
335        return 0
336end
337
338//test function invoked by F5
339// takes the selected file forom the file catalog
340// and displays that file
341// if several files are selected, displays ONLY the first one
342//
343Function LoadSelectedData()
344
345        if(WinType("CatVSTable")==0)
346                return(1)
347        endif
348        GetSelection table,CatVSTable,3
349       
350        Wave/T fWave = $"root:myGlobals:CatVSHeaderInfo:Filenames"
351        String filename=fWave[V_StartRow]
352        PathInfo catPathName
353       
354        // display the specified RAW data file
355        String/G root:myGlobals:gDataDisplayType="RAW"
356        ReadHeaderAndData(S_Path+filename)
357        //data is displayed here
358        fRawWindowHook()
359
360        // if you want a plot, too
361        //do the average and plot (either the default, or what is on the panel currently
362        if(!DataFolderExists("root:myGlobals:Drawing"))
363                Execute "InitializeAveragePanel()"
364        endif
365        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
366       
367        return(0)
368End
Note: See TracBrowser for help on using the repository browser.