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

Last change on this file since 740 was 683, checked in by srkline, 13 years ago

Updated version of HFIR_DataReadWrite.ipf from Jae Hie.

Updated the initialization of the templates from other facilities to remove the NCNR_Package_Loader.ipf since they are by definition incompatible.

Forward/Back? incrementing of the run number (as for the 2D display) has been moved to the Facility_Utils.ipf for all facilities and for the template.

File size: 9.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       
192        return(0)
193End
194
195//button procedure to display next RAW data file
196//incremented by run number, not dependent on file prefix
197Function ForwardOneFileButtonProc(ctrlName) : ButtonControl
198        String ctrlName
199
200        LoadPlotAndDisplayRAW(1)
201       
202        return (0)
203End
204
205//displays next (or previous) file in series of run numbers
206//file is read from disk, if path is set and the file number is present
207//increment +1, adds 1 to run number, -1 subtracts one
208Function LoadPlotAndDisplayRAW(increment)
209        Variable increment
210
211        Variable i
212        String filename
213        //take the currently displayed RAW file (there is only one name in fileList)
214        SVAR oldName = root:Packages:NIST:RAW:fileList
215       
216//      print oldName
217       
218        filename = oldname
219        for (i = 0; i < abs(increment); i += 1)
220                filename = GetPrevNextRawFile(filename,increment/abs(increment))
221        endfor 
222       
223//      print filename
224       
225        // display the specified RAW data file
226        String/G root:myGlobals:gDataDisplayType="RAW"
227        ReadHeaderAndData(filename)
228       
229        //do the average and plot (either the default, or what is on the panel currently
230        if(!DataFolderExists("root:myGlobals:Drawing"))
231                Execute "InitializeAveragePanel()"
232        endif
233        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
234       
235        //data is displayed here
236        fRawWindowHook()
237       
238        return(0)
239End
240
241//toggles the overlay of the current mask file
242//no effect if no mask exists
243Proc maskButtonProc(ctrlName) : ButtonControl
244        String ctrlName
245               
246        DoWindow/F SANS_Data             //do nothing if SANS_Data is not displayed, make it target if it is open
247        if(V_flag==0)
248                return
249        endif
250       
251        CheckDisplayed/W=SANS_Data root:Packages:NIST:MSK:overlay
252        if(V_flag==1)           //the overlay is present
253                Button $ctrlName,title="Show Mask",win=SANS_Data
254                OverlayMask(0)          //hide the mask
255        else
256                Button $ctrlName,title="Hide Mask",win=SANS_Data
257                OverlayMask(1)          //show the mask
258        endif
259       
260
261End
262
263//I vs. Q button on control bar of SANS_Data window activates this pocedure
264//and simply displays the AvgPanel to solicit input
265//from the user (graphically) before any averaging is done
266//
267Proc ShowAvgPanel_SANSData(ctrlName) : ButtonControl
268        String ctrlName
269
270        ShowAveragePanel()
271End
272
273
274//invoked by function key, (if menu declared)
275// if no window, or if display type is not RAW, do nothing
276Function NextRawFile()
277
278        DoWindow/F SANS_Data
279        if( V_Flag==0 )
280                return 1                        //return error, currently ignored
281        endif
282        SVAR str=root:myGlobals:gDataDisplayType
283        if(cmpstr(str,"RAW")!=0)
284                return 1
285        endif
286       
287        LoadPlotAndDisplayRAW(1)                //go to next file
288
289        return 0
290end
291
292//invoked by function key, (if menu declared)
293// if no window, or if display type is not RAW, do nothing
294Function PreviousRawFile()
295
296        DoWindow/F SANS_Data
297        if( V_Flag==0 )
298                return 1                        //do nothing and return error, currently ignored
299        endif
300        SVAR str=root:myGlobals:gDataDisplayType
301        if(cmpstr(str,"RAW")!=0)
302                return 1
303        endif
304       
305        LoadPlotAndDisplayRAW(-1)               //go to previous file
306
307        return 0
308end
309
310//test function invoked by F5
311// takes the selected file forom the file catalog
312// and displays that file
313// if several files are selected, displays ONLY the first one
314//
315Function LoadSelectedData()
316
317        if(WinType("CatVSTable")==0)
318                return(1)
319        endif
320        GetSelection table,CatVSTable,3
321       
322        Wave/T fWave = $"root:myGlobals:CatVSHeaderInfo:Filenames"
323        String filename=fWave[V_StartRow]
324        PathInfo catPathName
325       
326        // display the specified RAW data file
327        String/G root:myGlobals:gDataDisplayType="RAW"
328        ReadHeaderAndData(S_Path+filename)
329        //data is displayed here
330        fRawWindowHook()
331
332        // if you want a plot, too
333        //do the average and plot (either the default, or what is on the panel currently
334        if(!DataFolderExists("root:myGlobals:Drawing"))
335                Execute "InitializeAveragePanel()"
336        endif
337        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
338       
339        return(0)
340End
Note: See TracBrowser for help on using the repository browser.