1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.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 |
---|
14 | Function 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: |
---|
39 | End |
---|
40 | |
---|
41 | //prints out information about the currently displayed file to the history window |
---|
42 | // |
---|
43 | Function 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: |
---|
70 | End |
---|
71 | |
---|
72 | /////not used//// |
---|
73 | // function control a background task of "live" image updating |
---|
74 | // |
---|
75 | Function 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 |
---|
87 | End |
---|
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 |
---|
91 | Function 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 |
---|
114 | End |
---|
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 |
---|
126 | Function 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 |
---|
183 | End |
---|
184 | |
---|
185 | //button procedure to display previous RAW data file |
---|
186 | //incremented by run number, not dependent on file prefix |
---|
187 | Function BackOneFileButtonProc(ctrlName) : ButtonControl |
---|
188 | String ctrlName |
---|
189 | |
---|
190 | LoadPlotAndDisplayRAW(-1) |
---|
191 | |
---|
192 | return(0) |
---|
193 | End |
---|
194 | |
---|
195 | //button procedure to display next RAW data file |
---|
196 | //incremented by run number, not dependent on file prefix |
---|
197 | Function ForwardOneFileButtonProc(ctrlName) : ButtonControl |
---|
198 | String ctrlName |
---|
199 | |
---|
200 | LoadPlotAndDisplayRAW(1) |
---|
201 | |
---|
202 | return (0) |
---|
203 | End |
---|
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 |
---|
208 | Function LoadPlotAndDisplayRAW(increment) |
---|
209 | Variable increment |
---|
210 | |
---|
211 | //take the currently displayed RAW file (there is only one name in fileList) |
---|
212 | SVAR oldName = root:RAW:fileList |
---|
213 | |
---|
214 | //get the run number |
---|
215 | Variable num = GetRunNumFromFile(oldName) |
---|
216 | |
---|
217 | //increment |
---|
218 | num += increment |
---|
219 | |
---|
220 | //find the next specified file by number |
---|
221 | String fileName = FindFileFromRunNumber(num) |
---|
222 | if(cmpstr(fileName,"")==0) |
---|
223 | //null return, do nothing |
---|
224 | Return(1) |
---|
225 | Endif |
---|
226 | |
---|
227 | // display the specified RAW data file |
---|
228 | String/G root:myGlobals:gDataDisplayType="RAW" |
---|
229 | ReadHeaderAndData(filename) |
---|
230 | |
---|
231 | //do the average and plot (either the default, or what is on the panel currently |
---|
232 | if(!DataFolderExists("root:myGlobals:Drawing")) |
---|
233 | Execute "InitializeAveragePanel()" |
---|
234 | endif |
---|
235 | Panel_DoAverageButtonProc("") //the avg panel does not need to be open, folders must exist |
---|
236 | |
---|
237 | //data is displayed here |
---|
238 | fRawWindowHook() |
---|
239 | |
---|
240 | return(0) |
---|
241 | End |
---|
242 | |
---|
243 | //toggles the overlay of the current mask file |
---|
244 | //no effect if no mask exists |
---|
245 | Proc maskButtonProc(ctrlName) : ButtonControl |
---|
246 | String ctrlName |
---|
247 | |
---|
248 | DoWindow/F SANS_Data //do nothing if SANS_Data is not displayed, make it target if it is open |
---|
249 | if(V_flag==0) |
---|
250 | return |
---|
251 | endif |
---|
252 | |
---|
253 | CheckDisplayed/W=SANS_Data root:MSK:overlay |
---|
254 | if(V_flag==1) //the overlay is present |
---|
255 | Button $ctrlName,title="Show Mask",win=SANS_Data |
---|
256 | OverlayMask(0) //hide the mask |
---|
257 | else |
---|
258 | Button $ctrlName,title="Hide Mask",win=SANS_Data |
---|
259 | OverlayMask(1) //show the mask |
---|
260 | endif |
---|
261 | |
---|
262 | |
---|
263 | End |
---|
264 | |
---|
265 | //I vs. Q button on control bar of SANS_Data window activates this pocedure |
---|
266 | //and simply displays the AvgPanel to solicit input |
---|
267 | //from the user (graphically) before any averaging is done |
---|
268 | // |
---|
269 | Proc ShowAvgPanel_SANSData(ctrlName) : ButtonControl |
---|
270 | String ctrlName |
---|
271 | |
---|
272 | ShowAveragePanel() |
---|
273 | End |
---|
274 | |
---|
275 | |
---|
276 | //invoked by function key, (if menu declared) |
---|
277 | // if no window, or if display type is not RAW, do nothing |
---|
278 | Function NextRawFile() |
---|
279 | |
---|
280 | DoWindow/F SANS_Data |
---|
281 | if( V_Flag==0 ) |
---|
282 | return 1 //return error, currently ignored |
---|
283 | endif |
---|
284 | SVAR str=root:myGlobals:gDataDisplayType |
---|
285 | if(cmpstr(str,"RAW")!=0) |
---|
286 | return 1 |
---|
287 | endif |
---|
288 | |
---|
289 | LoadPlotAndDisplayRAW(1) //go to next file |
---|
290 | |
---|
291 | return 0 |
---|
292 | end |
---|
293 | |
---|
294 | //invoked by function key, (if menu declared) |
---|
295 | // if no window, or if display type is not RAW, do nothing |
---|
296 | Function PreviousRawFile() |
---|
297 | |
---|
298 | DoWindow/F SANS_Data |
---|
299 | if( V_Flag==0 ) |
---|
300 | return 1 //do nothing and return error, currently ignored |
---|
301 | endif |
---|
302 | SVAR str=root:myGlobals:gDataDisplayType |
---|
303 | if(cmpstr(str,"RAW")!=0) |
---|
304 | return 1 |
---|
305 | endif |
---|
306 | |
---|
307 | LoadPlotAndDisplayRAW(-1) //go to previous file |
---|
308 | |
---|
309 | return 0 |
---|
310 | end |
---|
311 | |
---|
312 | //test function invoked by F5 |
---|
313 | // takes the selected file forom the file catalog |
---|
314 | // and displays that file |
---|
315 | // if several files are selected, displays ONLY the first one |
---|
316 | // |
---|
317 | Function LoadSelectedData() |
---|
318 | |
---|
319 | if(WinType("CatVSTable")==0) |
---|
320 | return(1) |
---|
321 | endif |
---|
322 | GetSelection table,CatVSTable,3 |
---|
323 | |
---|
324 | Wave/T fWave = $"root:myGlobals:CatVSHeaderInfo:Filenames" |
---|
325 | String filename=fWave[V_StartRow] |
---|
326 | PathInfo catPathName |
---|
327 | |
---|
328 | // display the specified RAW data file |
---|
329 | String/G root:myGlobals:gDataDisplayType="RAW" |
---|
330 | ReadHeaderAndData(S_Path+filename) |
---|
331 | //data is displayed here |
---|
332 | fRawWindowHook() |
---|
333 | |
---|
334 | // if you want a plot, too |
---|
335 | //do the average and plot (either the default, or what is on the panel currently |
---|
336 | if(!DataFolderExists("root:myGlobals:Drawing")) |
---|
337 | Execute "InitializeAveragePanel()" |
---|
338 | endif |
---|
339 | Panel_DoAverageButtonProc("") //the avg panel does not need to be open, folders must exist |
---|
340 | |
---|
341 | return(0) |
---|
342 | End |
---|