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

Last change on this file since 1091 was 1091, checked in by srkline, 5 years ago

a number of changes, mostly to allow everything to compile.

added conditional compile to ensure that XML code would not be compiled if VSANS was present, since it's not XML-aware.

modified V_MainPanel to avoid conflicts with the SANS version. There still may be some functions hidden in procedures that do not have the V_ prefix yet, but these are either for functions that should point to a common file, or procedures that have been hidden from the VSANS panel

modified saving of VSANS mask files so that they can still be saved from teh deom version where home path is not defined.

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 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// TODO:
483// -- is the 1D plot being updated?
484////                   
485//              //if the 1D plot is open, update this too
486//              // make sure folders exist first
487//              if(!DataFolderExists("root:myGlobals:Drawing"))
488//                      Execute "InitializeAveragePanel()"
489//              endif
490//             
491//              // check for the mask, generate one? Two pixels all around
492//                     
493//              // update the 1d plot
494//              if(WinType("Plot_1d")==1)               //if the 1D graph exists
495////                    Panel_DoAverageButtonProc("")   
496//                      DoWindow/F V_SANS_Data 
497//              endif
498//              ///////
499               
500//              print "Bkg task time (s) =",(ticks-t1)/60.15
501                return 0                //keep the process going
502       
503End
504
505
506
507
508////////////// Routines from ANSTO
509//
510// these are designed to do the reduction (protocol) as the data is displayed
511//
512// also not loaded with SANS (R/T/I) baggage, as the complete header is assumed in the live file.
513//
514//
515// TODO:
516// -- completely untested, so that's a starting point...
517// -- no provision for setting the refresh time
518// -- is the file modification time actually written for the live file? if not - then nothing happens here
519//    since it always looks like the file is unchanged.
520//
521
522Function V_ShowOnlineReductionPanel()
523
524        //check for the path
525        PathInfo catPathName
526        if(V_Flag==0)
527                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
528                return 0
529        Endif
530       
531        DoWindow/F V_ORPanel
532        If(V_flag != 0)
533                return 0
534        endif
535       
536        // data
537        NewDataFolder/O root:Packages:NIST:VSANS:Globals:OnlineReduction
538       
539        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = ""
540        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol = ""
541        Variable/G root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification = 0
542       
543        // panel
544        PauseUpdate; Silent 1
545        NewPanel /W=(300,350,702,481) /K=2              //K=2 to force exit using "done" button to exit the background procedure
546       
547        DoWindow/C V_ORPanel
548        DoWindow/T V_ORPanel,"Online Reduction"
549        ModifyPanel cbRGB=(240*255,170*255,175*255)
550
551        Variable top = 5
552        Variable groupWidth = 390
553
554        // filename
555        GroupBox group_Flename          pos={6,top},            size={groupWidth,18+26},                title="select file for online reduction:"
556        PopupMenu popup_Filename        pos={12,top+18},        size={groupWidth-12-0,20},      title=""
557        PopupMenu popup_Filename        mode=1,                 value=V_GetRawDataFileList(),                   bodyWidth=groupWidth-12-0
558        PopupMenu popup_Filename        proc=V_ORPopupSelectFileProc
559       
560        string fileList = V_GetRawDataFileList()
561        if (ItemsInList(fileList) > 0)
562                String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = StringFromList(0, fileList)
563        else
564                String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = ""
565        endif
566
567        top += 18+26+7
568
569        // protocol
570        GroupBox group_Protocol         pos={6,top},            size={groupWidth,18+22},                title="select protocol for online reduction:"
571        SetVariable setvar_Protocol     pos={12,top+18},        size={groupWidth-12-18,0},      title=" "
572        SetVariable setvar_Protocol     value=root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol
573       
574        Button button_SelectProtocol pos={12+groupWidth-12-18,top+18-1}, size={18,18}, title="...", proc=V_ORButtonSelectProtocolProc
575
576        top += 18+22+7
577        Variable left = 12
578       
579        // sart, stop, done     
580        Button button_Start     pos={left + 70 * 0, top},       size={60,20},   title="Start",  proc=V_ORButtonStartProc
581        Button button_Stop      pos={left + 70 * 1, top},       size={60,20},   title="Stop",   proc=V_ORButtonStopProc,        disable=2
582        Button button_Done      pos={left + 70 * 2, top},       size={60,20},   title="Done",   proc=V_ORButtonDoneProc
583       
584end
585
586Function V_ORPopupSelectFileProc(ctrlName,popNum,popStr) : PopupMenuControl
587        String ctrlName
588        Variable popNum
589        String popStr
590
591        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename = popStr
592       
593End
594
595Function V_ORButtonSelectProtocolProc(ctrlName) : ButtonControl
596        String ctrlName
597
598        String protocolName=""
599        SVar gProtoStr=root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
600       
601        //pick a protocol wave from the Protocols folder
602        //must switch to protocols folder to get wavelist (missing parameter)
603        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
604        Execute "V_PickAProtocol()"
605       
606        //get the selected protocol wave choice through a global string variable
607        protocolName = gProtoStr
608       
609//      //If "CreateNew" was selected, go to the questionnare, to make a new set
610//      //and put the name of the new Protocol wave in gProtoStr
611//      if(cmpstr("CreateNew",protocolName) == 0)
612//              ProtocolQuestionnare()
613//              protocolName = gProtoStr
614//      Endif
615       
616        String/G root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol = protocolName
617
618        SetDataFolder root:
619       
620End
621
622Function V_ORButtonStartProc(ctrlName) : ButtonControl
623        String ctrlName
624
625        BackgroundInfo
626        if(V_Flag != 2) // task is not running
627                if (V_ORReduceFile() == 0) // check if first reduction works
628               
629                        // set up task
630                        SetBackground V_ORUpdate()
631                        CtrlBackground period=(5*60), noBurst=1 // 60 = 1 sec // noBurst prevents rapid "catch-up" calls
632                        CtrlBackground start
633                       
634                        DoWindow /T V_ORPanel, "Online Reduction - Running (Updated: " + time() + ")"
635                        DoWindow /F V_ORPanel
636                        // enable
637                        Button button_Stop                      disable = 0
638                        // disable
639                        Button button_Start                     disable = 2             
640                        PopupMenu popup_Filename        disable = 2
641                        SetVariable setvar_Protocol     disable = 2
642                        Button button_SelectProtocol    disable = 2
643                       
644                endif
645        endif
646
647end
648
649Function V_ORButtonStopProc(ctrlName) : ButtonControl
650        String ctrlName
651
652        BackgroundInfo
653        if(V_Flag == 2) // task is running
654                // stop task
655                CtrlBackground stop
656        endif
657               
658        DoWindow /T V_ORPanel, "Online Reduction"
659        DoWindow /F V_ORPanel
660        // enable
661        Button button_Start                     disable = 0     
662        PopupMenu popup_Filename        disable = 0
663        SetVariable setvar_Protocol     disable = 0
664        Button button_SelectProtocol    disable = 0
665        // disable
666        Button button_Stop                      disable = 2
667
668End
669
670Function V_ORButtonDoneProc(ctrlName) : ButtonControl
671        String ctrlName
672
673        V_ORButtonStopProc(ctrlName)
674        DoWindow/K V_ORPanel
675
676End
677
678Function V_ORUpdate()
679
680        SVAR filename = root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename
681        NVAR/Z lastFileModification = root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification
682       
683        if (lastFileModification == V_GetModificationDate(filename)) // no changes
684       
685                return 0 // continue task       
686                       
687        elseif (V_ORReduceFile() == 0) // update
688               
689                DoWindow /T V_ORPanel, "Online Reduction - Running (Updated: " + time() + ")"
690                print "Last Update: " + time()
691                return 0 // continue task
692               
693        else     // failure
694               
695                Beep
696                V_ORButtonStopProc("")
697                return 2 // stop task if error occurs
698                       
699        endif
700End
701
702Function V_ORReduceFile()
703
704        SVAR protocol = root:Packages:NIST:VSANS:Globals:OnlineReduction:Protocol
705        SVAR filename = root:Packages:NIST:VSANS:Globals:OnlineReduction:Filename
706
707        String waveStr  = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocol
708        String samStr   = filename
709       
710        if (exists(waveStr) != 1)
711                DoAlert 0,"The Protocol with the name \"" + protocol + "\" was not found."
712                return 1 // for error
713        endif
714       
715        NVAR/Z lastFileModification = root:Packages:NIST:VSANS:Globals:OnlineReduction:LastFileModification
716        lastFileModification = V_GetModificationDate(samStr)
717
718        // TODO:
719        // file needs to be removed from the DataFolder so that it will be reloaded
720//      string partialName = filename
721//      variable index = strsearch(partialName,".",0)
722//      if (index != -1)
723//              partialName = partialName[0,index-1]
724//      endif
725//      KillDataFolder/Z $"root:Packages:quokka:"+partialName
726
727
728       
729        return V_ExecuteProtocol(waveStr, samStr)
730
731End
732
733Function V_GetModificationDate(filename)
734        string filename
735       
736        PathInfo catPathName // this is where the files are
737        string path = S_path + filename
738
739        Getfilefolderinfo/q/z path
740        if(V_flag)
741                Abort "file was not found"
742        endif
743
744        return  V_modificationDate
745       
746End
747
748
Note: See TracBrowser for help on using the repository browser.