source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_RealTimeUpdate.ipf @ 1154

Last change on this file since 1154 was 1133, checked in by srkline, 4 years ago

many changes to the VCALC procedures to add in the hard/soft shadowing to the calculation, visualization of the shadowed regions, and the actual q-values. Added a separate panel to view the shadowed regions.

simpe fix to the real time routine to allow easy updating of both the raw 2D data and 1-D average

update to the USANS package to handle the new NICE generated data where the data is collected in terms of q-values rather than angle. On startup asks user which style of data they have. Sets a preference that can be un-checked if you have old-style ICP data. (there is nothing in the data file that I can key on).

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