1 | #pragma TextEncoding = "MacRoman" |
---|
2 | #pragma rtGlobals=3 // Use modern global access method and strict wave access. |
---|
3 | #pragma IgorVersion = 7.00 |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | // Two versions are present here, and in partial states of operation: |
---|
8 | |
---|
9 | // (1) RealTime Display |
---|
10 | // -- this is the typical read every (n) seconds. It is assumed that the data file is complete - with a |
---|
11 | // complete header that reflects the current data acquisition snapshot. |
---|
12 | // |
---|
13 | // |
---|
14 | // (2) RT Reduction |
---|
15 | // -- this is the ANSTO version, which will read data in and apply the reduction protocol. This |
---|
16 | // will likely be the most useful, but may suffer from speed issues in re-executing a protocol |
---|
17 | // and re-loading all of the data every time. That will be seen. |
---|
18 | // |
---|
19 | // -- what may be more useful for this is "partial" reduction, where say only the DIV is applied to the data |
---|
20 | // so that its effects can be seen on the data. This implies that a new set of "default" protocols that |
---|
21 | // carry out simple subsets of the corrections would be quite useful. See how everyone responds. |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | //TODO: |
---|
26 | // -- currently, RAW data is copied over to RealTime. The data is titled "WORK_RealTime", but has |
---|
27 | // only the same corrections as RAW data, not all of the WORK conversions. |
---|
28 | // |
---|
29 | // |
---|
30 | |
---|
31 | // |
---|
32 | // |
---|
33 | //***************************** |
---|
34 | |
---|
35 | |
---|
36 | // Proc to bring the RT control panel to the front, always initializes the panel |
---|
37 | // - always initialize to make sure that the background task is properly set |
---|
38 | // |
---|
39 | Proc V_Show_RealTime_Panel() |
---|
40 | V_Init_RT() //always init, data folders and globals are created here |
---|
41 | DoWindow/F VSANS_RT_Panel |
---|
42 | if(V_flag==0) |
---|
43 | VSANS_RT_Panel() |
---|
44 | Endif |
---|
45 | End |
---|
46 | |
---|
47 | // folder and globals that are needed ONLY for the RT process |
---|
48 | // |
---|
49 | Function V_Init_RT() |
---|
50 | //create folders |
---|
51 | NewDataFolder/O root:Packages:NIST:VSANS:RealTime |
---|
52 | NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:RT |
---|
53 | //create default globals only if they don't already exist, so you don't overwrite user-entered values. |
---|
54 | // NVAR/Z xCtr=xCtr |
---|
55 | // if(NVAR_Exists(xctr)==0) |
---|
56 | // Variable/G xCtr=110 //pixels |
---|
57 | // endif |
---|
58 | // NVAR/Z yCtr=yCtr |
---|
59 | // if(NVAR_Exists(yCtr)==0) |
---|
60 | // Variable/G yCtr=64 |
---|
61 | // endif |
---|
62 | // NVAR/Z SDD=SDD |
---|
63 | // if(NVAR_Exists(SDD)==0) |
---|
64 | // Variable/G SDD=3.84 //in meters |
---|
65 | // endif |
---|
66 | // NVAR/Z lambda=lambda |
---|
67 | // if(NVAR_Exists(lambda)==0) |
---|
68 | // Variable/G lambda=6 //angstroms |
---|
69 | // endif |
---|
70 | NVAR/Z updateInt=updateInt |
---|
71 | if(NVAR_Exists(updateInt)==0) |
---|
72 | Variable/G updateInt=10 //seconds |
---|
73 | endif |
---|
74 | NVAR/Z timeout=timeout |
---|
75 | if(NVAR_Exists(timeout)==0) |
---|
76 | Variable/G timeout=300 //seconds |
---|
77 | endif |
---|
78 | NVAR/Z elapsed=elapsed |
---|
79 | if(NVAR_Exists(elapsed)==0) |
---|
80 | Variable/G elapsed=0 |
---|
81 | endif |
---|
82 | NVAR/Z totalCounts=totalCounts //total detector counts |
---|
83 | if(NVAR_Exists(totalCounts)==0) |
---|
84 | Variable/G totalCounts=0 |
---|
85 | endif |
---|
86 | NVAR/Z countTime = countTime |
---|
87 | if(NVAR_Exists(countTime)==0) |
---|
88 | Variable/G countTime = 0 |
---|
89 | endif |
---|
90 | NVAR/Z countRate = countRate |
---|
91 | if(NVAR_Exists(countRate)==0) |
---|
92 | Variable/G countRate = 0 |
---|
93 | endif |
---|
94 | NVAR/Z monitorCountRate = monitorCountRate |
---|
95 | if(NVAR_Exists(monitorCountRate)==0) |
---|
96 | Variable/G monitorCountRate = 0 |
---|
97 | endif |
---|
98 | NVAR/Z monitorCounts = monitorCounts |
---|
99 | if(NVAR_Exists(monitorCounts)==0) |
---|
100 | Variable/G monitorCounts = 0 |
---|
101 | endif |
---|
102 | |
---|
103 | // set the explicit path to the data file on "relay" computer (the user will be propmted for this) |
---|
104 | SVAR/Z RT_fileStr=RT_fileStr |
---|
105 | if(SVAR_Exists(RT_fileStr)==0) |
---|
106 | String/G RT_fileStr="" |
---|
107 | endif |
---|
108 | |
---|
109 | // set the background task |
---|
110 | V_AssignBackgroundTask() |
---|
111 | |
---|
112 | SetDataFolder root: |
---|
113 | End |
---|
114 | |
---|
115 | //sets the background task and period (in ticks) |
---|
116 | // |
---|
117 | Function V_AssignBackgroundTask() |
---|
118 | |
---|
119 | Variable updateInt=NumVarOrDefault("root:Packages:NIST:VSANS:Globals:RT:updateInt",10) |
---|
120 | // set the background task |
---|
121 | SetBackground V_BkgUpdate_RTData() |
---|
122 | CtrlBackground period=(updateInt*60),noBurst=1 //noBurst=1 prevents rapid "catch-up" calls |
---|
123 | return(0) |
---|
124 | End |
---|
125 | |
---|
126 | //draws the RT panel and enforces bounds on the SetVariable controls for update period and timeout |
---|
127 | // |
---|
128 | Proc VSANS_RT_Panel() |
---|
129 | Variable sc = 1 |
---|
130 | |
---|
131 | if(root:Packages:NIST:VSANS:Globals:gLaptopMode == 1) |
---|
132 | sc = 0.7 |
---|
133 | endif |
---|
134 | |
---|
135 | PauseUpdate; Silent 1 // building window... |
---|
136 | NewPanel /W=(300*sc,350*sc,602*sc,580*sc) /K=2 // force the user to close using done |
---|
137 | DoWindow/C VSANS_RT_Panel |
---|
138 | DoWindow/T RT_Panel,"Real Time Display Controls" |
---|
139 | ModifyPanel cbRGB=(65535,52428,6168) |
---|
140 | SetDrawLayer UserBack |
---|
141 | SetDrawEnv fstyle= 1,fsize=14*sc |
---|
142 | DrawText 26*sc,21*sc,"Enter values for real-time display" |
---|
143 | Button bkgStart,pos={sc*171,54*sc},size={sc*120,20*sc},proc=V_UpdateHSTButton,title="Start Updating" |
---|
144 | Button bkgStart,help={"Starts or stops the updating of the real-time SANS image"} |
---|
145 | // SetVariable setvar_0,pos={sc*15,29*sc},size={sc*100,15*sc},proc=RT_Param_SetVarProc,title="X Center" |
---|
146 | // SetVariable setvar_0,help={"Set this to the current beamcenter x-coordinate (in pixels)"} |
---|
147 | // SetVariable setvar_0,limits={0,128,0},value= root:myGlobals:RT:xCtr |
---|
148 | // SetVariable setvar_1,pos={sc*14,46*sc},size={sc*100,15*sc},proc=RT_Param_SetVarProc,title="Y Center" |
---|
149 | // SetVariable setvar_1,help={"Set this to the current beamcenter y-coordinate (in pixels)"} |
---|
150 | // SetVariable setvar_1,limits={0,128,0},value= root:myGlobals:RT:yCtr |
---|
151 | // SetVariable setvar_2,pos={sc*14,64*sc},size={sc*100,15*sc},proc=RT_Param_SetVarProc,title="SDD (m)" |
---|
152 | // SetVariable setvar_2,help={"Set this to the sample-to-detector distance of the current instrument configuration"} |
---|
153 | // SetVariable setvar_2,limits={0,1600,0},value= root:myGlobals:RT:SDD |
---|
154 | // SetVariable setvar_3,pos={sc*15,82*sc},size={sc*100,15*sc},proc=RT_Param_SetVarProc,title="Lambda (A)" |
---|
155 | // SetVariable setvar_3,help={"Set this to the wavelength of the current instrument configuration"} |
---|
156 | // SetVariable setvar_3,limits={0,30,0},value= root:myGlobals:RT:lambda |
---|
157 | SetVariable setvar_4,pos={sc*11,31*sc},size={sc*150,20*sc},proc=V_UpdateInt_SetVarProc,title="Update Interval (s)" |
---|
158 | SetVariable setvar_4,help={"This is the period of the update"} |
---|
159 | SetVariable setvar_4,limits={1,3600,0},value= root:Packages:NIST:VSANS:Globals:RT:updateInt |
---|
160 | // SetVariable setvar_5,pos={sc*11,56*sc},size={sc*150,20*sc},title="Timeout Interval (s)" |
---|
161 | // SetVariable setvar_5,help={"After the timeout interval has expired, the update process will automatically stop"} |
---|
162 | // SetVariable setvar_5,limits={1,3600,0},value= root:myGlobals:RT:timeout |
---|
163 | Button button_1,pos={sc*170,29*sc},size={sc*120,20*sc},proc=V_LoadRTButtonProc,title="Load Live Data" |
---|
164 | Button button_1,help={"Load the data file for real-time display"} |
---|
165 | Button button_2,pos={sc*250,2*sc},size={sc*30,20*sc},proc=V_RT_HelpButtonProc,title="?" |
---|
166 | Button button_2,help={"Display the help file for real-time controls"} |
---|
167 | Button button_3,pos={sc*230,200*sc},size={sc*60,20*sc},proc=V_RT_DoneButtonProc,title="Done" |
---|
168 | Button button_3,help={"Closes the panel and stops the updating process"} |
---|
169 | SetVariable setvar_6,pos={sc*11,105*sc},size={sc*250,20*sc},title="Total Detector Counts" |
---|
170 | SetVariable setvar_6,help={"Total counts on the detector, as displayed"},noedit=1 |
---|
171 | SetVariable setvar_6,limits={0,Inf,0},value= root:Packages:NIST:VSANS:Globals:RT:totalCounts |
---|
172 | SetVariable setvar_7,pos={sc*11,82*sc},size={sc*250,20*sc},title=" Count Time" |
---|
173 | SetVariable setvar_7,help={"Count time, as displayed"},noedit=1 |
---|
174 | SetVariable setvar_7,limits={0,Inf,0},value= root:Packages:NIST:VSANS:Globals:RT:countTime |
---|
175 | SetVariable setvar_8,pos={sc*11,127*sc},size={sc*250,20*sc},title=" Detector Count Rate" |
---|
176 | SetVariable setvar_8,help={"Count rate, as displayed"},noedit=1 |
---|
177 | SetVariable setvar_8,limits={0,Inf,0},value= root:Packages:NIST:VSANS:Globals:RT:countRate |
---|
178 | SetVariable setvar_9,pos={sc*11,149*sc},size={sc*250,20*sc},title=" Monitor Counts" |
---|
179 | SetVariable setvar_9,help={"Count rate, as displayed"},noedit=1 |
---|
180 | SetVariable setvar_9,limits={0,Inf,0},value= root:Packages:NIST:VSANS:Globals:RT:monitorCounts |
---|
181 | SetVariable setvar_10,pos={sc*11,171*sc},size={sc*250,20*sc},title=" Monitor Count Rate" |
---|
182 | SetVariable setvar_10,help={"Count rate, as displayed"},noedit=1 |
---|
183 | SetVariable setvar_10,limits={0,Inf,0},value= root:Packages:NIST:VSANS:Globals:RT:monitorCountRate |
---|
184 | EndMacro |
---|
185 | |
---|
186 | // |
---|
187 | Proc V_RT_HelpButtonProc(ctrlName) : ButtonControl |
---|
188 | String ctrlName |
---|
189 | DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Documentation[VSANS RealTime Display]" |
---|
190 | if(V_flag !=0) |
---|
191 | DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found" |
---|
192 | endif |
---|
193 | End |
---|
194 | |
---|
195 | //close the panel gracefully, and stop the background task if necessary |
---|
196 | // |
---|
197 | Proc V_RT_DoneButtonProc(ctrlName) : ButtonControl |
---|
198 | String ctrlName |
---|
199 | |
---|
200 | BackgroundInfo |
---|
201 | if(V_Flag==2) //task is currently running |
---|
202 | CtrlBackground stop |
---|
203 | endif |
---|
204 | DoWindow/K VSANS_RT_Panel |
---|
205 | End |
---|
206 | |
---|
207 | //prompts for the RT data file - only needs to be set once, then the user can start/stop |
---|
208 | // |
---|
209 | Function V_LoadRTButtonProc(ctrlName) : ButtonControl |
---|
210 | String ctrlName |
---|
211 | |
---|
212 | DoAlert 0,"The RealTime detector image is located on charlotte" |
---|
213 | V_Read_RT_File("Select the Live Data file") |
---|
214 | return(0) |
---|
215 | End |
---|
216 | |
---|
217 | // Sets "fake" header information to allow qx,qy scales on the graph, and to allow |
---|
218 | // averaging to be done on the real-time dataset |
---|
219 | // |
---|
220 | // keep in mind that only the select bits of header information that is USER-SUPPLIED |
---|
221 | // on the panel is available for calculations. The RT data arrives at the relay computer |
---|
222 | // with NO header, only the 128x128 data.... |
---|
223 | // |
---|
224 | // see also FillFakeHeader() for a few constant header values ... |
---|
225 | // |
---|
226 | // |
---|
227 | //// check on a case-by-case basis |
---|
228 | //Function V_RT_Param_SetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
229 | // String ctrlName |
---|
230 | // Variable varNum |
---|
231 | // String varStr |
---|
232 | // String varName |
---|
233 | // |
---|
234 | // Wave rw=$"root:Packages:NIST:RealTime:RealsRead" |
---|
235 | // if(WaveExists(rw)==0) |
---|
236 | // return(1) |
---|
237 | // Endif |
---|
238 | // strswitch(ctrlName) // string switch |
---|
239 | // case "setvar_0": //xCtr |
---|
240 | // rw[16]=varNum |
---|
241 | // break |
---|
242 | // case "setvar_1": //yCtr |
---|
243 | // rw[17]=varNum |
---|
244 | // break |
---|
245 | // case "setvar_2": //SDD |
---|
246 | // rw[18]=varNum |
---|
247 | // break |
---|
248 | // case "setvar_3": //lambda |
---|
249 | // rw[26]=varNum |
---|
250 | // break |
---|
251 | // endswitch |
---|
252 | // //only update the graph if it is open, and is a RealTime display... |
---|
253 | // if(WinType("SANS_Data")==0) |
---|
254 | // return(0) //SANS_Data window not open |
---|
255 | // Endif |
---|
256 | // SVAR type=root:myGlobals:gDataDisplayType |
---|
257 | // if(cmpstr("RealTime",type)!=0) |
---|
258 | // return(0) //display not RealTime |
---|
259 | // Endif |
---|
260 | // |
---|
261 | // |
---|
262 | // |
---|
263 | // |
---|
264 | //// fRawWindowHook() //force a redraw of the graph |
---|
265 | // |
---|
266 | // |
---|
267 | // |
---|
268 | // DoWindow/F VSANS_RT_Panel //return panel to the front |
---|
269 | // return(0) |
---|
270 | //End |
---|
271 | |
---|
272 | // |
---|
273 | // (re)-sets the period of the update background task |
---|
274 | // |
---|
275 | Function V_UpdateInt_SetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
276 | String ctrlName |
---|
277 | Variable varNum |
---|
278 | String varStr |
---|
279 | String varName |
---|
280 | |
---|
281 | // BackgroundInfo |
---|
282 | // if(V_flag==2) |
---|
283 | // CtrlBackground stop |
---|
284 | // Endif |
---|
285 | |
---|
286 | // quite surprised that you can change the period of repeat while the task is active |
---|
287 | CtrlBackground period=(varNum*60),noBurst=1 |
---|
288 | return(0) |
---|
289 | End |
---|
290 | |
---|
291 | |
---|
292 | |
---|
293 | |
---|
294 | //function called by the main entry procedure (the load button) |
---|
295 | //sets global display variable, reads in the data, and displays it |
---|
296 | //aborts if no file was selected |
---|
297 | // |
---|
298 | //(re)-sets the GLOBAL path:filename of the RT file to update |
---|
299 | // also resets the path to the RT file, so that the dialog brings you back to the right spot |
---|
300 | // |
---|
301 | // reads the data in if all is OK |
---|
302 | // |
---|
303 | Function V_Read_RT_File(msgStr) |
---|
304 | String msgStr |
---|
305 | |
---|
306 | String filename="",pathStr="" |
---|
307 | Variable refnum |
---|
308 | |
---|
309 | //check for the path |
---|
310 | PathInfo RT_Path |
---|
311 | If(V_Flag==1) // /D does not open the file |
---|
312 | Open/D/R/T="????"/M=(msgStr)/P=RT_Path refNum |
---|
313 | else |
---|
314 | Open/D/R/T="????"/M=(msgStr) refNum |
---|
315 | endif |
---|
316 | filename = S_FileName //get the filename, or null if canceled from dialog |
---|
317 | if(strlen(filename)==0) |
---|
318 | //user cancelled, abort |
---|
319 | SetDataFolder root: |
---|
320 | Abort "No file selected, action aborted" |
---|
321 | Endif |
---|
322 | //set the globals and reset the RT_Path value |
---|
323 | pathStr = ParseFilePath(1, filename, ":", 1, 0) |
---|
324 | NewPath/O RT_Path,pathStr |
---|
325 | // Variable/G root:Packages:NIST:RealTime:gIsLogScale = 0 //force data to linear scale (1st read) |
---|
326 | String/G root:Packages:NIST:VSANS:Globals:RT:RT_fileStr=filename //full path:file of the Run.hst file to re-read |
---|
327 | |
---|
328 | //read in the data |
---|
329 | |
---|
330 | // get the new data by re-reading the datafile from charlotte? |
---|
331 | V_LoadHDF5Data(filename,"RAW") |
---|
332 | // data folder "old" will be copied to "new" (either kills/copies or will overwrite) |
---|
333 | V_CopyHDFToWorkFolder("RAW","RealTime") |
---|
334 | |
---|
335 | V_UpdateDisplayInformation("RealTime") // plot the data in whatever folder type |
---|
336 | |
---|
337 | //the calling macro must change the display type |
---|
338 | String/G root:Packages:NIST:VSANS:Globals:gCurDispType="RealTime" //displayed data type is RealTime |
---|
339 | |
---|
340 | //data is displayed here, and needs header info |
---|
341 | // WAVE data = $"root:Packages:NIST:RealTime:data" |
---|
342 | NVAR totCounts = root:Packages:NIST:VSANS:Globals:RT:totalCounts |
---|
343 | NVAR countTime = root:Packages:NIST:VSANS:Globals:RT:countTime |
---|
344 | NVAR countRate = root:Packages:NIST:VSANS:Globals:RT:countRate |
---|
345 | NVAR monitorCounts = root:Packages:NIST:VSANS:Globals:RT:monitorCounts |
---|
346 | NVAR monitorCountRate = root:Packages:NIST:VSANS:Globals:RT:monitorCountRate |
---|
347 | SVAR/Z title = root:Packages:NIST:VSANS:Globals:gCurDispFile |
---|
348 | |
---|
349 | title="Real-Time : "+filename |
---|
350 | //sum the total counts, global variable will automatically update |
---|
351 | |
---|
352 | totCounts = V_getDetector_counts("RealTime") |
---|
353 | |
---|
354 | //Update other live values |
---|
355 | |
---|
356 | countTime = V_getCount_time("RealTime") |
---|
357 | countRate = totCounts/countTime |
---|
358 | // TODO: -- this may not be the correct monitor to use |
---|
359 | // -- may not be the correct detectior integral to report |
---|
360 | |
---|
361 | monitorCounts = V_getBeamMonNormData("RealTime") |
---|
362 | monitorCountRate = monitorCounts/countTime |
---|
363 | |
---|
364 | // set the VSANS_Data graph to "live" mode to allow fast updating |
---|
365 | |
---|
366 | // ModifyGraph/W=VSANS_Data live=1 //not much speed help... |
---|
367 | |
---|
368 | return(0) |
---|
369 | End |
---|
370 | |
---|
371 | |
---|
372 | // action procedure to start/stop the updating process. |
---|
373 | //checks for update display graph, current background task, etc.. |
---|
374 | // then update the button and at last controls the background task |
---|
375 | // |
---|
376 | Function V_UpdateHSTButton(ctrlName) : ButtonControl |
---|
377 | String ctrlName |
---|
378 | |
---|
379 | //check that the RT window is open, and that the display type is "RealTime" |
---|
380 | if(WinType("VSANS_Data")==0) |
---|
381 | return(1) //SANS_Data window not open |
---|
382 | Endif |
---|
383 | SVAR type=root:Packages:NIST:VSANS:Globals:gCurDispType |
---|
384 | if(cmpstr("RealTime",type)!=0) |
---|
385 | return(1) //display not RealTime |
---|
386 | Endif |
---|
387 | //check the current state of the background task |
---|
388 | BackgroundInfo //returns 0 if no task defined, 1 if idle, 2 if running |
---|
389 | if(V_flag==0) |
---|
390 | V_AssignBackgroundTask() |
---|
391 | Endif |
---|
392 | |
---|
393 | String Str="" |
---|
394 | //control the task, and update the button text |
---|
395 | if (cmpstr(ctrlName,"bkgStart") == 0) |
---|
396 | Button $ctrlName,win=VSANS_RT_Panel,title="Stop Updating",rename=bkgStop |
---|
397 | // Start the updating - BkgUpdateHST() has been designated as the background task |
---|
398 | CtrlBackground start |
---|
399 | else |
---|
400 | Button $ctrlName,win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart |
---|
401 | NVAR elapsed=root:Packages:NIST:VSANS:Globals:RT:elapsed |
---|
402 | elapsed=0 //reset the timer |
---|
403 | // Stop the updating |
---|
404 | CtrlBackground stop |
---|
405 | endif |
---|
406 | return(0) |
---|
407 | End |
---|
408 | |
---|
409 | |
---|
410 | // THIS IS THE BACKGROUND TASK |
---|
411 | // |
---|
412 | // simply re-reads the designated Live Data file (which can be located anywhere, as long as it |
---|
413 | // appears as a local disk) |
---|
414 | // return value of 0 continues background execution |
---|
415 | // return value of 1 turns background task off |
---|
416 | // |
---|
417 | Function V_BkgUpdate_RTData() |
---|
418 | |
---|
419 | // WAVE data = $"root:Packages:NIST:RealTime:data" |
---|
420 | |
---|
421 | NVAR elapsed=root:Packages:NIST:VSANS:Globals:RT:elapsed |
---|
422 | NVAR timeout=root:Packages:NIST:VSANS:Globals:RT:timeout |
---|
423 | NVAR updateInt=root:Packages:NIST:VSANS:Globals:RT:updateInt |
---|
424 | NVAR totCounts = root:Packages:NIST:VSANS:Globals:RT:totalCounts |
---|
425 | NVAR countTime = root:Packages:NIST:VSANS:Globals:RT:countTime |
---|
426 | NVAR countRate =root:Packages:NIST:VSANS:Globals:RT:countRate |
---|
427 | NVAR monitorCounts = root:Packages:NIST:VSANS:Globals:RT:monitorCounts |
---|
428 | NVAR monitorCountRate = root:Packages:NIST:VSANS:Globals:RT:monitorCountRate |
---|
429 | SVAR/Z title=root:Packages:NIST:VSANS:Globals:gCurDispFile |
---|
430 | SVAR/Z sampledesc=root:Packages:NIST:VSANS:Globals:gCurTitle |
---|
431 | |
---|
432 | Variable err=0 |
---|
433 | // Variable t1=ticks |
---|
434 | SVAR RT_fileStr=root:Packages:NIST:VSANS:Globals:RT:RT_fileStr |
---|
435 | |
---|
436 | elapsed += updateInt |
---|
437 | |
---|
438 | |
---|
439 | // if(elapsed<timeout) |
---|
440 | |
---|
441 | if(WinType("VSANS_Data")==0) |
---|
442 | Button $"bkgStop",win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart |
---|
443 | return(1) //SANS_Data window not open |
---|
444 | Endif |
---|
445 | SVAR type=root:Packages:NIST:VSANS:Globals:gCurDispType |
---|
446 | if(cmpstr("RealTime",type)!=0) |
---|
447 | Button $"bkgStop",win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart |
---|
448 | return(1) //display not RealTime |
---|
449 | Endif |
---|
450 | title="Reading new data..." |
---|
451 | ControlUpdate/W=VSANS_Data/A |
---|
452 | |
---|
453 | |
---|
454 | if(err==1) |
---|
455 | Button $"bkgStop",win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart |
---|
456 | return(err) //file not found |
---|
457 | Endif |
---|
458 | |
---|
459 | |
---|
460 | // get the new data by re-reading the datafile from charlotte? |
---|
461 | V_LoadHDF5Data(RT_fileStr,"RAW") |
---|
462 | // data folder "old" will be copied to "new" (either kills/copies or will overwrite) |
---|
463 | V_CopyHDFToWorkFolder("RAW","RealTime") |
---|
464 | |
---|
465 | V_UpdateDisplayInformation("RealTime") // plot the data in whatever folder type |
---|
466 | |
---|
467 | // for testing only... |
---|
468 | // data += abs(enoise(data)) |
---|
469 | // |
---|
470 | |
---|
471 | // TODO: |
---|
472 | // -- fill in the title and sampledesc fields from the realTime folder |
---|
473 | // title=textw[0] |
---|
474 | // sampledesc=textw[6] |
---|
475 | |
---|
476 | // //sum the total counts, global variable will automatically update |
---|
477 | // |
---|
478 | totCounts = V_getDetector_counts("RealTime") |
---|
479 | |
---|
480 | //Update other live values |
---|
481 | |
---|
482 | countTime = V_getCount_time("RealTime") |
---|
483 | countRate = totCounts/countTime |
---|
484 | // TODO: -- this may not be the correct monitor to use |
---|
485 | // -- may not be the correct detectior integral to report |
---|
486 | |
---|
487 | monitorCounts = V_getBeamMonNormData("RealTime") |
---|
488 | monitorCountRate = monitorCounts/countTime |
---|
489 | |
---|
490 | |
---|
491 | // DONE: |
---|
492 | // x- update the 1D plot |
---|
493 | // repeat what the IQ button does -- V_IvsQPanelButtonProc() |
---|
494 | V_PlotData_Panel() //-9999 requests a read from the popup on the panel |
---|
495 | Variable binType = V_GetBinningPopMode() |
---|
496 | ControlInfo/W=V_1D_Data popup0 |
---|
497 | V_BinningModePopup("",binType,S_Value) // does binning of current popString and updates the graph |
---|
498 | |
---|
499 | // print "Bkg task time (s) =",(ticks-t1)/60.15 |
---|
500 | return 0 //keep the process going |
---|
501 | |
---|
502 | End |
---|
503 | |
---|
504 | |
---|
505 | |
---|
506 | |
---|
507 | ////////////// Routines from ANSTO |
---|
508 | // |
---|
509 | // these are designed to do the reduction (protocol) as the data is displayed |
---|
510 | // |
---|
511 | // also not loaded with SANS (R/T/I) baggage, as the complete header is assumed in the live file. |
---|
512 | // |
---|
513 | // |
---|
514 | // TODO: |
---|
515 | // -- completely untested, so that's a starting point... |
---|
516 | // -- no provision for setting the refresh time |
---|
517 | // -- is the file modification time actually written for the live file? if not - then nothing happens here |
---|
518 | // since it always looks like the file is unchanged. |
---|
519 | // |
---|
520 | |
---|
521 | Function V_ShowOnlineReductionPanel() |
---|
522 | |
---|
523 | Variable sc = 1 |
---|
524 | |
---|
525 | NVAR gLaptopMode = root:Packages:NIST:VSANS:Globals:gLaptopMode |
---|
526 | |
---|
527 | if(gLaptopMode == 1) |
---|
528 | sc = 0.7 |
---|
529 | endif |
---|
530 | |
---|
531 | //check for the path |
---|
532 | PathInfo catPathName |
---|
533 | if(V_Flag==0) |
---|
534 | DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel" |
---|
535 | return 0 |
---|
536 | Endif |
---|
537 | |
---|
538 | DoWindow/F V_ORPanel |
---|
539 | If(V_flag != 0) |
---|
540 | return 0 |
---|
541 | endif |
---|
542 | |
---|
543 | // data |
---|
544 | NewDataFolder/O root:Packages:NIST:VSANS:Globals:OnlineReduction |
---|
545 | |
---|
546 | String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = "" |
---|
547 | String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol = "" |
---|
548 | Variable/G root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification = 0 |
---|
549 | |
---|
550 | // panel |
---|
551 | PauseUpdate; Silent 1 |
---|
552 | NewPanel /W=(300*sc,350*sc,702*sc,481*sc) /K=2 //K=2 to force exit using "done" button to exit the background procedure |
---|
553 | |
---|
554 | DoWindow/C V_ORPanel |
---|
555 | DoWindow/T V_ORPanel,"Online Reduction" |
---|
556 | ModifyPanel cbRGB=(240*255,170*255,175*255) |
---|
557 | |
---|
558 | Variable top = 5 |
---|
559 | Variable groupWidth = 390 |
---|
560 | |
---|
561 | // filename |
---|
562 | GroupBox group_Flename pos={sc*6,top*sc}, size={sc*groupWidth,(18+26)*sc}, title="select file for online reduction:" |
---|
563 | PopupMenu popup_Filename pos={sc*12,(top+18)*sc}, size={sc*(groupWidth-12-0),20*sc}, title="" |
---|
564 | PopupMenu popup_Filename mode=1, value=V_GetRawDataFileList(), bodyWidth=sc*(groupWidth-12-0) |
---|
565 | PopupMenu popup_Filename proc=V_ORPopupSelectFileProc |
---|
566 | |
---|
567 | string fileList = V_GetRawDataFileList() |
---|
568 | if (ItemsInList(fileList) > 0) |
---|
569 | String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = StringFromList(0, fileList) |
---|
570 | else |
---|
571 | String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = "" |
---|
572 | endif |
---|
573 | |
---|
574 | top += 18+26+7 |
---|
575 | |
---|
576 | // protocol |
---|
577 | GroupBox group_Protocol pos={sc*6,top*sc}, size={sc*groupWidth,(18+22)*sc}, title="select protocol for online reduction:" |
---|
578 | SetVariable setvar_Protocol pos={sc*12,(top+18)*sc}, size={sc*(groupWidth-12-18),0*sc}, title=" " |
---|
579 | SetVariable setvar_Protocol value=root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol |
---|
580 | |
---|
581 | Button button_SelectProtocol pos={sc*(12+groupWidth-12-18),(top+18-1)*sc}, size={sc*18,18*sc}, title="...", proc=V_ORButtonSelectProtocolProc |
---|
582 | |
---|
583 | top += 18+22+7 |
---|
584 | Variable left = 12 |
---|
585 | |
---|
586 | // sart, stop, done |
---|
587 | Button button_Start pos={sc*(left + 70 * 0), top*sc}, size={sc*60,20*sc}, title="Start", proc=V_ORButtonStartProc |
---|
588 | Button button_Stop pos={sc*(left + 70 * 1), top*sc}, size={sc*60,20*sc}, title="Stop", proc=V_ORButtonStopProc, disable=2 |
---|
589 | Button button_Done pos={sc*(left + 70 * 2), top*sc}, size={sc*60,20*sc}, title="Done", proc=V_ORButtonDoneProc |
---|
590 | |
---|
591 | end |
---|
592 | |
---|
593 | Function V_ORPopupSelectFileProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
594 | String ctrlName |
---|
595 | Variable popNum |
---|
596 | String popStr |
---|
597 | |
---|
598 | String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = popStr |
---|
599 | |
---|
600 | End |
---|
601 | |
---|
602 | Function V_ORButtonSelectProtocolProc(ctrlName) : ButtonControl |
---|
603 | String ctrlName |
---|
604 | |
---|
605 | String protocolName="" |
---|
606 | SVar gProtoStr=root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr |
---|
607 | |
---|
608 | //pick a protocol wave from the Protocols folder |
---|
609 | //must switch to protocols folder to get wavelist (missing parameter) |
---|
610 | SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols |
---|
611 | Execute "V_PickAProtocol()" |
---|
612 | |
---|
613 | //get the selected protocol wave choice through a global string variable |
---|
614 | protocolName = gProtoStr |
---|
615 | |
---|
616 | // //If "CreateNew" was selected, go to the questionnare, to make a new set |
---|
617 | // //and put the name of the new Protocol wave in gProtoStr |
---|
618 | // if(cmpstr("CreateNew",protocolName) == 0) |
---|
619 | // ProtocolQuestionnare() |
---|
620 | // protocolName = gProtoStr |
---|
621 | // Endif |
---|
622 | |
---|
623 | String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol = protocolName |
---|
624 | |
---|
625 | SetDataFolder root: |
---|
626 | |
---|
627 | End |
---|
628 | |
---|
629 | Function V_ORButtonStartProc(ctrlName) : ButtonControl |
---|
630 | String ctrlName |
---|
631 | |
---|
632 | BackgroundInfo |
---|
633 | if(V_Flag != 2) // task is not running |
---|
634 | if (V_ORReduceFile() == 0) // check if first reduction works |
---|
635 | |
---|
636 | // set up task |
---|
637 | SetBackground V_ORUpdate() |
---|
638 | CtrlBackground period=(5*60), noBurst=1 // 60 = 1 sec // noBurst prevents rapid "catch-up" calls |
---|
639 | CtrlBackground start |
---|
640 | |
---|
641 | DoWindow /T V_ORPanel, "Online Reduction - Running (Updated: " + time() + ")" |
---|
642 | DoWindow /F V_ORPanel |
---|
643 | // enable |
---|
644 | Button button_Stop disable = 0 |
---|
645 | // disable |
---|
646 | Button button_Start disable = 2 |
---|
647 | PopupMenu popup_Filename disable = 2 |
---|
648 | SetVariable setvar_Protocol disable = 2 |
---|
649 | Button button_SelectProtocol disable = 2 |
---|
650 | |
---|
651 | endif |
---|
652 | endif |
---|
653 | |
---|
654 | end |
---|
655 | |
---|
656 | Function V_ORButtonStopProc(ctrlName) : ButtonControl |
---|
657 | String ctrlName |
---|
658 | |
---|
659 | BackgroundInfo |
---|
660 | if(V_Flag == 2) // task is running |
---|
661 | // stop task |
---|
662 | CtrlBackground stop |
---|
663 | endif |
---|
664 | |
---|
665 | DoWindow /T V_ORPanel, "Online Reduction" |
---|
666 | DoWindow /F V_ORPanel |
---|
667 | // enable |
---|
668 | Button button_Start disable = 0 |
---|
669 | PopupMenu popup_Filename disable = 0 |
---|
670 | SetVariable setvar_Protocol disable = 0 |
---|
671 | Button button_SelectProtocol disable = 0 |
---|
672 | // disable |
---|
673 | Button button_Stop disable = 2 |
---|
674 | |
---|
675 | End |
---|
676 | |
---|
677 | Function V_ORButtonDoneProc(ctrlName) : ButtonControl |
---|
678 | String ctrlName |
---|
679 | |
---|
680 | V_ORButtonStopProc(ctrlName) |
---|
681 | DoWindow/K V_ORPanel |
---|
682 | |
---|
683 | End |
---|
684 | |
---|
685 | Function V_ORUpdate() |
---|
686 | |
---|
687 | SVAR filename = root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename |
---|
688 | NVAR/Z lastFileModification = root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification |
---|
689 | |
---|
690 | if (lastFileModification == V_GetModificationDate(filename)) // no changes |
---|
691 | |
---|
692 | return 0 // continue task |
---|
693 | |
---|
694 | elseif (V_ORReduceFile() == 0) // update |
---|
695 | |
---|
696 | DoWindow /T V_ORPanel, "Online Reduction - Running (Updated: " + time() + ")" |
---|
697 | print "Last Update: " + time() |
---|
698 | return 0 // continue task |
---|
699 | |
---|
700 | else // failure |
---|
701 | |
---|
702 | Beep |
---|
703 | V_ORButtonStopProc("") |
---|
704 | return 2 // stop task if error occurs |
---|
705 | |
---|
706 | endif |
---|
707 | End |
---|
708 | |
---|
709 | Function V_ORReduceFile() |
---|
710 | |
---|
711 | SVAR protocol = root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol |
---|
712 | SVAR filename = root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename |
---|
713 | |
---|
714 | String waveStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocol |
---|
715 | String samStr = filename |
---|
716 | |
---|
717 | if (exists(waveStr) != 1) |
---|
718 | DoAlert 0,"The Protocol with the name \"" + protocol + "\" was not found." |
---|
719 | return 1 // for error |
---|
720 | endif |
---|
721 | |
---|
722 | NVAR/Z lastFileModification = root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification |
---|
723 | lastFileModification = V_GetModificationDate(samStr) |
---|
724 | |
---|
725 | // TODO: |
---|
726 | // file needs to be removed from the DataFolder so that it will be reloaded |
---|
727 | // string partialName = filename |
---|
728 | // variable index = strsearch(partialName,".",0) |
---|
729 | // if (index != -1) |
---|
730 | // partialName = partialName[0,index-1] |
---|
731 | // endif |
---|
732 | // KillDataFolder/Z $"root:Packages:quokka:"+partialName |
---|
733 | |
---|
734 | |
---|
735 | |
---|
736 | return V_ExecuteProtocol(waveStr, samStr) |
---|
737 | |
---|
738 | End |
---|
739 | |
---|
740 | Function V_GetModificationDate(filename) |
---|
741 | string filename |
---|
742 | |
---|
743 | PathInfo catPathName // this is where the files are |
---|
744 | string path = S_path + filename |
---|
745 | |
---|
746 | Getfilefolderinfo/q/z path |
---|
747 | if(V_flag) |
---|
748 | Abort "file was not found" |
---|
749 | endif |
---|
750 | |
---|
751 | return V_modificationDate |
---|
752 | |
---|
753 | End |
---|
754 | |
---|
755 | |
---|