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

Last change on this file since 1242 was 1242, checked in by srkline, 3 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

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