source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Buttons.ipf @ 72

Last change on this file since 72 was 47, checked in by srkline, 16 years ago

bug fixes and performance tweaks

File size: 11.4 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
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:"+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:"+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//sets the low cutoff of the color mapping (threshold)
186//Function LowThreshSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
187//      String ctrlName
188//      Variable varNum
189//      String varStr
190//      String varName
191//     
192//      ControlInfo/W=SANS_Data lowThresh
193//      Variable loScale = V_Value
194//
195//      ControlInfo/W=SANS_Data highThresh
196//      Variable hiScale = V_Value
197//
198//      String result = ImageInfo("SANS_Data","data",0)
199//      String fullPath = StringByKey("ZWAVEDF", result, ":", ";")
200//      fullpath += "data"
201//      //Print fullpath
202//      WaveStats/Q $fullpath
203//      Variable maxData=V_max
204//
205//   WAVE NIHColors = $"root:myGlobals:NIHColors"
206//      ScaleColorsToData((loScale*maxData),(hiScale*maxData),NIHColors)
207//      ModifyImage/W=SANS_Data data cindex=NIHColors
208////    ModifyImage/W=SANS_Data vlegend cindex=NIHColors
209//
210//End
211
212//sets the high cutoff of the color mapping (threshold)
213//Function HighThreshSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
214//      String ctrlName
215//      Variable varNum
216//      String varStr
217//      String varName
218//
219//      ControlInfo/W=SANS_Data lowThresh
220//      Variable loScale = V_Value
221//
222//      ControlInfo/W=SANS_Data highThresh
223//      Variable hiScale = V_Value
224//
225//      String result = ImageInfo("SANS_Data","data",0)
226//      String fullPath = StringByKey("ZWAVEDF", result, ":", ";")
227//      fullpath += "data"
228//      //Print fullpath
229//      WaveStats/Q $fullpath
230//      Variable maxData=V_max
231//
232//      WAVE NIHColors = $"root:myGlobals:NIHColors"
233//      ScaleColorsToData((loScale*maxData),(hiScale*maxData),NIHColors)
234//      ModifyImage/W=SANS_Data data cindex=NIHColors
235////    ModifyImage/W=SANS_Data vlegend cindex=NIHColors
236//     
237//End
238
239//button procedure to display previous RAW data file
240//incremented by run number, not dependent on file prefix
241Function BackOneFileButtonProc(ctrlName) : ButtonControl
242        String ctrlName
243
244        LoadPlotAndDisplayRAW(-1)
245       
246        return(0)
247End
248
249//button procedure to display next RAW data file
250//incremented by run number, not dependent on file prefix
251Function ForwardOneFileButtonProc(ctrlName) : ButtonControl
252        String ctrlName
253
254        LoadPlotAndDisplayRAW(1)
255       
256        return (0)
257End
258
259//displays next (or previous) file in series of run numbers
260//file is read from disk, if path is set and the file number is present
261//increment +1, adds 1 to run number, -1 subtracts one
262Function LoadPlotAndDisplayRAW(increment)
263        Variable increment
264
265        //take the currently displayed RAW file (there is only one name in fileList)
266        SVAR oldName = root:RAW:fileList
267       
268        //get the run number
269        Variable num = GetRunNumFromFile(oldName)
270       
271        //increment
272        num += increment
273       
274        //find the next specified file by number
275        String fileName = FindFileFromRunNumber(num)
276        if(cmpstr(fileName,"")==0)
277                //null return, do nothing
278                Return(1)
279        Endif
280       
281        // display the specified RAW data file
282        String/G root:myGlobals:gDataDisplayType="RAW"
283        ReadHeaderAndData(filename)
284       
285        //do the average and plot (either the default, or what is on the panel currently
286        if(!DataFolderExists("root:myGlobals:Drawing"))
287                Execute "InitializeAveragePanel()"
288        endif
289        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
290       
291        //data is displayed here
292        fRawWindowHook()
293       
294        return(0)
295End
296
297//toggles the overlay of the current mask file
298//no effect if no mask exists
299Proc maskButtonProc(ctrlName) : ButtonControl
300        String ctrlName
301               
302        DoWindow/F SANS_Data             //do nothing if SANS_Data is not displayed, make it target if it is open
303        if(V_flag==0)
304                return
305        endif
306       
307        CheckDisplayed/W=SANS_Data root:MSK:overlay
308        if(V_flag==1)           //the overlay is present
309                Button $ctrlName,title="Show Mask",win=SANS_Data
310                OverlayMask(0)          //hide the mask
311        else
312                Button $ctrlName,title="Hide Mask",win=SANS_Data
313                OverlayMask(1)          //show the mask
314        endif
315       
316
317End
318
319//I vs. Q button on control bar of SANS_Data window activates this pocedure
320//and simply displays the AvgPanel to solicit input
321//from the user (graphically) before any averaging is done
322//
323Proc ShowAvgPanel_SANSData(ctrlName) : ButtonControl
324        String ctrlName
325
326        ShowAveragePanel()
327End
328
329
330//invoked by function key, (if menu declared)or the arrow button
331//on Raw data display
332// if no window, or if display type is not RAW, do nothing
333Function NextRawFile()
334
335        DoWindow/F SANS_Data
336        if( V_Flag==0 )
337                return 1                        //return error, currently ignored
338        endif
339        SVAR str=root:myGlobals:gDataDisplayType
340        if(cmpstr(str,"RAW")!=0)
341                return 1
342        endif
343       
344        LoadPlotAndDisplayRAW(1)                //go to next file
345
346//      //do the average (either the default, or what is on the panel currently
347//      if(!DataFolderExists("root:myGlobals:Drawing"))
348//              Execute "InitializeAveragePanel()"
349//      endif
350//      Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
351        return 0
352end
353
354//invoked by function key, (if menu declared)or the arrow button
355//on Raw data display
356// if no window, or if display type is not RAW, do nothing
357Function PreviousRawFile()
358
359        DoWindow/F SANS_Data
360        if( V_Flag==0 )
361                return 1                        //do nothing and return error, currently ignored
362        endif
363        SVAR str=root:myGlobals:gDataDisplayType
364        if(cmpstr(str,"RAW")!=0)
365                return 1
366        endif
367       
368        LoadPlotAndDisplayRAW(-1)               //go to previous file
369
370//      //do the average (either the default, or what is on the panel currently
371//      if(!DataFolderExists("root:myGlobals:Drawing"))
372//              Execute "InitializeAveragePanel()"
373//      endif
374//      Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
375        return 0
376end
377
378
379//test function invoked by F5
380// takes the selected file forom the file catalog
381// and displays that file
382// if several files are selected, displays ONLY the first one
383//
384Function LoadSelectedData()
385
386        if(WinType("CatVSTable")==0)
387                return(1)
388        endif
389        GetSelection table,CatVSTable,3
390//      Print V_startRow
391       
392        Wave/T fWave = $"root:myGlobals:CatVSHeaderInfo:Filenames"
393        String filename=fWave[V_StartRow]
394        PathInfo catPathName
395       
396        // display the specified RAW data file
397        String/G root:myGlobals:gDataDisplayType="RAW"
398        ReadHeaderAndData(S_Path+filename)
399        //data is displayed here
400        fRawWindowHook()
401
402        //do the average (either the default, or what is on the panel currently
403        if(!DataFolderExists("root:myGlobals:Drawing"))
404                Execute "InitializeAveragePanel()"
405        endif
406        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
407        return(0)
408End
Note: See TracBrowser for help on using the repository browser.