source: sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/Buttons.ipf @ 40

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

Initial checkin of V5.00 SANSReduction files

File size: 11.0 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 eun 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         OverlayMask()
303End
304
305//I vs. Q button on control bar of SANS_Data window activates this pocedure
306//and simply displays the AvgPanel to solicit input
307//from the user (graphically) before any averaging is done
308//
309Proc ShowAvgPanel_SANSData(ctrlName) : ButtonControl
310        String ctrlName
311
312        ShowAveragePanel()
313End
314
315
316//invoked by function key, (if menu declared)or the arrow button
317//on Raw data display
318// if no window, or if display type is not RAW, do nothing
319Function NextRawFile()
320
321        DoWindow/F SANS_Data
322        if( V_Flag==0 )
323                return 1                        //return error, currently ignored
324        endif
325        SVAR str=root:myGlobals:gDataDisplayType
326        if(cmpstr(str,"RAW")!=0)
327                return 1
328        endif
329       
330        LoadPlotAndDisplayRAW(1)                //go to next file
331
332//      //do the average (either the default, or what is on the panel currently
333//      if(!DataFolderExists("root:myGlobals:Drawing"))
334//              Execute "InitializeAveragePanel()"
335//      endif
336//      Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
337        return 0
338end
339
340//invoked by function key, (if menu declared)or the arrow button
341//on Raw data display
342// if no window, or if display type is not RAW, do nothing
343Function PreviousRawFile()
344
345        DoWindow/F SANS_Data
346        if( V_Flag==0 )
347                return 1                        //do nothing and return error, currently ignored
348        endif
349        SVAR str=root:myGlobals:gDataDisplayType
350        if(cmpstr(str,"RAW")!=0)
351                return 1
352        endif
353       
354        LoadPlotAndDisplayRAW(-1)               //go to previous file
355
356//      //do the average (either the default, or what is on the panel currently
357//      if(!DataFolderExists("root:myGlobals:Drawing"))
358//              Execute "InitializeAveragePanel()"
359//      endif
360//      Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
361        return 0
362end
363
364
365//test function invoked by F5
366// takes the selected file forom the file catalog
367// and displays that file
368// if several files are selected, displays ONLY the first one
369//
370Function LoadSelectedData()
371
372        if(WinType("CatVSTable")==0)
373                return(1)
374        endif
375        GetSelection table,CatVSTable,3
376//      Print V_startRow
377       
378        Wave/T fWave = $"root:myGlobals:CatVSHeaderInfo:Filenames"
379        String filename=fWave[V_StartRow]
380        PathInfo catPathName
381       
382        // display the specified RAW data file
383        String/G root:myGlobals:gDataDisplayType="RAW"
384        ReadHeaderAndData(S_Path+filename)
385        //data is displayed here
386        fRawWindowHook()
387
388        //do the average (either the default, or what is on the panel currently
389        if(!DataFolderExists("root:myGlobals:Drawing"))
390                Execute "InitializeAveragePanel()"
391        endif
392        Panel_DoAverageButtonProc("")           //the avg panel does not need to be open, folders must exist
393        return(0)
394End
Note: See TracBrowser for help on using the repository browser.