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

Last change on this file since 1029 was 1029, checked in by srkline, 6 years ago

added basics of RealTime? updating. Added both my origianl version, plus ANSTO version to allow a protocol to be executed at each update. Will decide what blend of the two is most useful.

File size: 24.0 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 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        //read in the data
319       
320        //      get the new data by re-reading the datafile from charlotte?
321        V_LoadHDF5Data(filename,"RAW")
322        // data folder "old" will be copied to "new" (either kills/copies or will overwrite)
323        V_CopyHDFToWorkFolder("RAW","RealTime")
324
325        V_UpdateDisplayInformation("RealTime")          // plot the data in whatever folder type
326       
327        //the calling macro must change the display type
328        String/G root:Packages:NIST:VSANS:Globals:gCurDispType="RealTime"               //displayed data type is RealTime
329       
330        //data is displayed here, and needs header info
331//      WAVE data = $"root:Packages:NIST:RealTime:data"
332        NVAR totCounts = root:Packages:NIST:VSANS:Globals:RT:totalCounts
333        NVAR countTime = root:Packages:NIST:VSANS:Globals:RT:countTime
334        NVAR countRate = root:Packages:NIST:VSANS:Globals:RT:countRate
335        NVAR monitorCounts = root:Packages:NIST:VSANS:Globals:RT:monitorCounts
336        NVAR monitorCountRate = root:Packages:NIST:VSANS:Globals:RT:monitorCountRate
337        SVAR/Z title = root:Packages:NIST:VSANS:Globals:gCurDispFile
338       
339        title="Real-Time : "+filename
340        //sum the total counts, global variable will automatically update
341
342        totCounts = V_getDetector_counts("RealTime")
343
344        //Update other live values
345
346        countTime = V_getCount_time("RealTime")
347        countRate = totCounts/countTime
348// TODO: -- this may not be the correct monitor to use
349// -- may not be the correct detectior integral to report
350
351        monitorCounts = V_getBeamMonNormData("RealTime")
352        monitorCountRate = monitorCounts/countTime
353       
354        // set the VSANS_Data graph to "live" mode to allow fast updating
355
356//      ModifyGraph/W=VSANS_Data live=1         //not much speed help...
357       
358        return(0)
359End
360
361
362// action procedure to start/stop the updating process.
363//checks for update display graph, current background task, etc..
364// then update the button and at last controls the background task
365//
366Function V_UpdateHSTButton(ctrlName) : ButtonControl
367        String ctrlName
368       
369        //check that the RT window is open, and that the display type is "RealTime"
370        if(WinType("VSANS_Data")==0)
371                return(1) //SANS_Data window not open
372        Endif
373        SVAR type=root:Packages:NIST:VSANS:Globals:gCurDispType
374        if(cmpstr("RealTime",type)!=0)
375                return(1)               //display not RealTime
376        Endif
377        //check the current state of the background task
378        BackgroundInfo          //returns 0 if no task defined, 1 if idle, 2 if running
379        if(V_flag==0)
380                V_AssignBackgroundTask()
381        Endif
382       
383        String Str=""
384        //control the task, and update the button text
385        if (cmpstr(ctrlName,"bkgStart") == 0)
386                Button $ctrlName,win=VSANS_RT_Panel,title="Stop Updating",rename=bkgStop               
387        //      Start the updating - BkgUpdateHST() has been designated as the background task
388                CtrlBackground start
389        else
390                Button $ctrlName,win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart
391                NVAR elapsed=root:Packages:NIST:VSANS:Globals:RT:elapsed
392                elapsed=0       //reset the timer
393        //      Stop the updating
394                CtrlBackground stop
395        endif
396        return(0)
397End
398
399
400// THIS IS THE BACKGROUND TASK
401//
402// simply re-reads the designated Live Data file (which can be located anywhere, as long as it
403// appears as a local disk)
404// return value of 0 continues background execution
405// return value of 1 turns background task off
406//
407Function V_BkgUpdate_RTData()
408
409//      WAVE data = $"root:Packages:NIST:RealTime:data"
410
411        NVAR elapsed=root:Packages:NIST:VSANS:Globals:RT:elapsed
412        NVAR timeout=root:Packages:NIST:VSANS:Globals:RT:timeout
413        NVAR updateInt=root:Packages:NIST:VSANS:Globals:RT:updateInt
414        NVAR totCounts = root:Packages:NIST:VSANS:Globals:RT:totalCounts
415        NVAR countTime = root:Packages:NIST:VSANS:Globals:RT:countTime
416        NVAR countRate =root:Packages:NIST:VSANS:Globals:RT:countRate
417        NVAR monitorCounts = root:Packages:NIST:VSANS:Globals:RT:monitorCounts
418        NVAR monitorCountRate = root:Packages:NIST:VSANS:Globals:RT:monitorCountRate
419        SVAR/Z title=root:Packages:NIST:VSANS:Globals:gCurDispFile
420        SVAR/Z sampledesc=root:Packages:NIST:VSANS:Globals:gCurTitle
421                       
422        Variable err=0
423//      Variable t1=ticks
424        SVAR RT_fileStr=root:Packages:NIST:VSANS:Globals:RT:RT_fileStr
425       
426        elapsed += updateInt
427
428
429//      if(elapsed<timeout)
430       
431                if(WinType("VSANS_Data")==0)
432                        Button $"bkgStop",win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart
433                        return(1) //SANS_Data window not open
434                Endif
435                SVAR type=root:Packages:NIST:VSANS:Globals:gDataDisplayType
436                if(cmpstr("RealTime",type)!=0)
437                        Button $"bkgStop",win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart
438                        return(1)               //display not RealTime
439                Endif
440                title="Reading new data..."
441                ControlUpdate/W=VSANS_Data/A
442               
443               
444                if(err==1)
445                        Button $"bkgStop",win=VSANS_RT_Panel,title="Start Updating",rename=bkgStart
446                        return(err)     //file not found
447                Endif
448               
449
450        //      get the new data by re-reading the datafile from charlotte?
451                V_LoadHDF5Data(RT_fileStr,"RAW")
452        // data folder "old" will be copied to "new" (either kills/copies or will overwrite)
453                V_CopyHDFToWorkFolder("RAW","RealTime")
454               
455                V_UpdateDisplayInformation("RealTime")          // plot the data in whatever folder type
456
457                // for testing only...
458//              data += abs(enoise(data))
459                //
460               
461                // TODO:
462                // -- fill in the title and sampledesc fields from the realTime folder
463//              title=textw[0]
464//              sampledesc=textw[6]
465
466        //              //sum the total counts, global variable will automatically update
467        //
468                totCounts = V_getDetector_counts("RealTime")
469       
470                //Update other live values
471       
472                countTime = V_getCount_time("RealTime")
473                countRate = totCounts/countTime
474        // TODO: -- this may not be the correct monitor to use
475        // -- may not be the correct detectior integral to report
476       
477                monitorCounts = V_getBeamMonNormData("RealTime")
478                monitorCountRate = monitorCounts/countTime
479
480
481// TODO:
482// -- is the 1D plot being updated?
483////                   
484//              //if the 1D plot is open, update this too
485//              // make sure folders exist first
486//              if(!DataFolderExists("root:myGlobals:Drawing"))
487//                      Execute "InitializeAveragePanel()"
488//              endif
489//             
490//              // check for the mask, generate one? Two pixels all around
491//                     
492//              // update the 1d plot
493//              if(WinType("Plot_1d")==1)               //if the 1D graph exists
494////                    Panel_DoAverageButtonProc("")   
495//                      DoWindow/F V_SANS_Data 
496//              endif
497//              ///////
498               
499//              print "Bkg task time (s) =",(ticks-t1)/60.15
500                return 0                //keep the process going
501       
502End
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
521Function V_ShowOnlineReductionPanel()
522
523        //check for the path
524        PathInfo catPathName
525        if(V_Flag==0)
526                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
527                return 0
528        Endif
529       
530        DoWindow/F V_ORPanel
531        If(V_flag != 0)
532                return 0
533        endif
534       
535        // data
536        NewDataFolder/O root:Packages:NIST:VSANS:Globals:OnlineReduction
537       
538        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = ""
539        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol = ""
540        Variable/G root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification = 0
541       
542        // panel
543        PauseUpdate; Silent 1
544        NewPanel /W=(300,350,702,481) /K=2              //K=2 to force exit using "done" button to exit the background procedure
545       
546        DoWindow/C V_ORPanel
547        DoWindow/T V_ORPanel,"Online Reduction"
548        ModifyPanel cbRGB=(240*255,170*255,175*255)
549
550        Variable top = 5
551        Variable groupWidth = 390
552
553        // filename
554        GroupBox group_Flename          pos={6,top},            size={groupWidth,18+26},                title="select file for online reduction:"
555        PopupMenu popup_Filename        pos={12,top+18},        size={groupWidth-12-0,20},      title=""
556        PopupMenu popup_Filename        mode=1,                 value=V_GetRawDataFileList(),                   bodyWidth=groupWidth-12-0
557        PopupMenu popup_Filename        proc=V_ORPopupSelectFileProc
558       
559        string fileList = V_GetRawDataFileList()
560        if (ItemsInList(fileList) > 0)
561                String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = StringFromList(0, fileList)
562        else
563                String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = ""
564        endif
565
566        top += 18+26+7
567
568        // protocol
569        GroupBox group_Protocol         pos={6,top},            size={groupWidth,18+22},                title="select protocol for online reduction:"
570        SetVariable setvar_Protocol     pos={12,top+18},        size={groupWidth-12-18,0},      title=" "
571        SetVariable setvar_Protocol     value=root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol
572       
573        Button button_SelectProtocol pos={12+groupWidth-12-18,top+18-1}, size={18,18}, title="...", proc=V_ORButtonSelectProtocolProc
574
575        top += 18+22+7
576        Variable left = 12
577       
578        // sart, stop, done     
579        Button button_Start     pos={left + 70 * 0, top},       size={60,20},   title="Start",  proc=V_ORButtonStartProc
580        Button button_Stop      pos={left + 70 * 1, top},       size={60,20},   title="Stop",   proc=V_ORButtonStopProc,        disable=2
581        Button button_Done      pos={left + 70 * 2, top},       size={60,20},   title="Done",   proc=V_ORButtonDoneProc
582       
583end
584
585Function V_ORPopupSelectFileProc(ctrlName,popNum,popStr) : PopupMenuControl
586        String ctrlName
587        Variable popNum
588        String popStr
589
590        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = popStr
591       
592End
593
594Function V_ORButtonSelectProtocolProc(ctrlName) : ButtonControl
595        String ctrlName
596
597        String protocolName=""
598        SVar gProtoStr=root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
599       
600        //pick a protocol wave from the Protocols folder
601        //must switch to protocols folder to get wavelist (missing parameter)
602        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
603        Execute "V_PickAProtocol()"
604       
605        //get the selected protocol wave choice through a global string variable
606        protocolName = gProtoStr
607       
608//      //If "CreateNew" was selected, go to the questionnare, to make a new set
609//      //and put the name of the new Protocol wave in gProtoStr
610//      if(cmpstr("CreateNew",protocolName) == 0)
611//              ProtocolQuestionnare()
612//              protocolName = gProtoStr
613//      Endif
614       
615        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol = protocolName
616
617        SetDataFolder root:
618       
619End
620
621Function V_ORButtonStartProc(ctrlName) : ButtonControl
622        String ctrlName
623
624        BackgroundInfo
625        if(V_Flag != 2) // task is not running
626                if (V_ORReduceFile() == 0) // check if first reduction works
627               
628                        // set up task
629                        SetBackground V_ORUpdate()
630                        CtrlBackground period=(5*60), noBurst=1 // 60 = 1 sec // noBurst prevents rapid "catch-up" calls
631                        CtrlBackground start
632                       
633                        DoWindow /T V_ORPanel, "Online Reduction - Running (Updated: " + time() + ")"
634                        DoWindow /F V_ORPanel
635                        // enable
636                        Button button_Stop                      disable = 0
637                        // disable
638                        Button button_Start                     disable = 2             
639                        PopupMenu popup_Filename        disable = 2
640                        SetVariable setvar_Protocol     disable = 2
641                        Button button_SelectProtocol    disable = 2
642                       
643                endif
644        endif
645
646end
647
648Function V_ORButtonStopProc(ctrlName) : ButtonControl
649        String ctrlName
650
651        BackgroundInfo
652        if(V_Flag == 2) // task is running
653                // stop task
654                CtrlBackground stop
655        endif
656               
657        DoWindow /T V_ORPanel, "Online Reduction"
658        DoWindow /F V_ORPanel
659        // enable
660        Button button_Start                     disable = 0     
661        PopupMenu popup_Filename        disable = 0
662        SetVariable setvar_Protocol     disable = 0
663        Button button_SelectProtocol    disable = 0
664        // disable
665        Button button_Stop                      disable = 2
666
667End
668
669Function V_ORButtonDoneProc(ctrlName) : ButtonControl
670        String ctrlName
671
672        V_ORButtonStopProc(ctrlName)
673        DoWindow/K V_ORPanel
674
675End
676
677Function V_ORUpdate()
678
679        SVAR filename = root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename
680        NVAR/Z lastFileModification = root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification
681       
682        if (lastFileModification == V_GetModificationDate(filename)) // no changes
683       
684                return 0 // continue task       
685                       
686        elseif (V_ORReduceFile() == 0) // update
687               
688                DoWindow /T V_ORPanel, "Online Reduction - Running (Updated: " + time() + ")"
689                print "Last Update: " + time()
690                return 0 // continue task
691               
692        else     // failure
693               
694                Beep
695                V_ORButtonStopProc("")
696                return 2 // stop task if error occurs
697                       
698        endif
699End
700
701Function V_ORReduceFile()
702
703        SVAR protocol = root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol
704        SVAR filename = root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename
705
706        String waveStr  = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocol
707        String samStr   = filename
708       
709        if (exists(waveStr) != 1)
710                DoAlert 0,"The Protocol with the name \"" + protocol + "\" was not found."
711                return 1 // for error
712        endif
713       
714        NVAR/Z lastFileModification = root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification
715        lastFileModification = V_GetModificationDate(samStr)
716
717        // TODO:
718        // file needs to be removed from the DataFolder so that it will be reloaded
719//      string partialName = filename
720//      variable index = strsearch(partialName,".",0)
721//      if (index != -1)
722//              partialName = partialName[0,index-1]
723//      endif
724//      KillDataFolder/Z $"root:Packages:quokka:"+partialName
725
726
727       
728        return V_ExecuteProtocol(waveStr, samStr)
729
730End
731
732Function V_GetModificationDate(filename)
733        string filename
734       
735        PathInfo catPathName // this is where the files are
736        string path = S_path + filename
737
738        Getfilefolderinfo/q/z path
739        if(V_flag)
740                Abort "file was not found"
741        endif
742
743        return  V_modificationDate
744       
745End
746
747
Note: See TracBrowser for help on using the repository browser.