source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_PatchFiles.ipf @ 1022

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

ADDED:

included common NCNR procedures for the PlotManager?, to allow plotting of 1D data sets using a familiar interface

greatly expanded Patch functionality to include input in the multiple sections of the Nexus file, including separate panels to handle patching of waves to the file - needed for non-linear coefficients, dead time, and XY beam centers. All patch operations are expandable as more fields become necessary to patch.

removed bug of group_id being defined in /reduction and in /sample (removed R/W that referenced /reduction)

added panel to "isolate" a single detector panel, allowing the corrections to be applied/removed/recalculated as needed to directly see their effects.

linked new procedures to their appropriate action buttons

Added more data fields (label, intent, etc.) to the VCALC to Nexus data writer to get more realistic values into the fake data files for testing

Added VCALC simulation functions with EMP and BGD in anticipation of testing the CORRECT step

more little bug and documentation fixes which I can't remember, but they are all important...

  • Property svn:executable set to *
File size: 58.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5
6//////////////////////////////////
7//
8// TODO --  January 2107
9//
10// This is experimental, making the patch work with list boxes as "groups" of the Nexus file structure
11//
12// some of the groupings are more natural, some will need to be re-organized for the
13// more natural needs of what will typically be patched in the most common cases.
14//
15///////////////////////////////
16
17// TODOs have been inserted to comment out all of the calls that don't compile and need to be replaced
18
19// TODO
20// -- not all of the functions here have been prefixed with "V_", especially the action procedures from the panel
21//   so this cannot be opened with the SANS Reduction, or there will be clashes
22// -- same file load/reload issue as with other operations that read a field from the file. ANY read requires
23//   that the entire file is read in, even just to check and see if it's raw data... then there is a local
24//   copy present to confuse matters of what was actually written
25//
26// -- for the batch entering of fields, when all of the proper beam center values are determined, then
27//    all (2 x 9 = 18) of these values will need to be entered in all of the data files that "match" this
28//    "configuration" - however a configuration is to be defined and differentiated from other configurations.
29//
30// -- there may be other situations where batch entering needs are
31//               different, and this may lead to different interface choices
32//
33// -- need to add some mechanism (new panel?) to enter:
34//    -- box coordinates
35//    -- ABS parameters
36//    -- averaging options -- these will have new options versus SANS (binning panels, slit mode, etc.)
37//
38
39
40//**************************
41//
42//procedures required to allow patching of raw vSANS data headers
43//information for the Patch Panel is stored in the root:Packages:NIST:VSANS:Globals:Patch subfolder
44//
45// writes changes directly to the raw data headers as requested
46// * note that if a data file is currently in a work folder, the (real) header on disk
47// will be updated, but the data in the (WORK) folder will not reflect these changes, unless
48// the data folder is first cleared and the data is re-loaded
49//
50//**************************
51
52//main entry procedure for displaying the Patch Panel
53//
54Proc V_PatchFiles()
55       
56        DoWindow/F V_Patch_Panel
57        If(V_flag == 0)
58                V_InitializePatchPanel()
59                //draw panel
60                V_Patch_Panel()
61        Endif
62End
63
64//initialization of the panel, creating the necessary data folder and global
65//variables if necessary -
66//
67// root:Packages:NIST:VSANS:Globals:
68Proc V_InitializePatchPanel()
69        //create the global variables needed to run the Patch Panel
70        //all are kept in root:Packages:NIST:VSANS:Globals:Patch
71        If( ! (DataFolderExists("root:Packages:NIST:VSANS:Globals:Patch"))  )
72                //create the data folder and the globals for BOTH the Patch and Trans panels
73                NewDataFolder/O root:Packages:NIST:VSANS:Globals:Patch
74        Endif
75        V_CreatePatchGlobals()          //re-create them every time (so text and radio buttons are correct)
76End
77
78//the data folder root:Packages:NIST:VSANS:Globals:Patch must exist
79//
80Proc V_CreatePatchGlobals()
81        //ok, create the globals
82        String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr = "*"
83        String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchCurLabel = "no file selected"
84       
85        PathInfo catPathName
86        If(V_flag==1)
87                String dum = S_path
88                String/G root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr = dum
89        else
90                String/G root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr = "no path selected"
91        endif
92        String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchList = "none"
93
94        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gRadioVal = 1
95       
96
97        SetDataFolder root:Packages:NIST:VSANS:Globals:Patch:   
98        Make/O/T/N=(10,3) PP_ListWave
99        Make/O/B/N=(10,3) PP_SelWave
100        Make/O/T/N=3 PP_TitleWave
101       
102        PP_TitleWave = {"Ch?","Label","Value"}
103       
104        PP_SelWave[][0] = 2^5           // checkboxes
105        PP_SelWave[][2] = 2^1           // 3rd column editable
106       
107       
108        SetDataFolder root:
109       
110End
111
112
113//panel recreation macro for the PatchPanel...
114//
115Proc V_Patch_Panel()
116        PauseUpdate; Silent 1      // building window...
117        NewPanel /W=(533,50,1140,588)/K=2 as "Patch Raw VSANS Data Files"
118        DoWindow/C V_Patch_Panel
119//      ShowTools/A
120        SetDataFolder root:Packages:NIST:VSANS:Globals:Patch:
121
122       
123        ModifyPanel cbRGB=(11291,48000,3012)
124        ModifyPanel fixedSize=1
125        SetDrawLayer UserBack
126        DrawLine 7,30,422,30
127
128       
129        SetVariable PathDisplay,pos={77,7},size={310,13},title="Path"
130        SetVariable PathDisplay,help={"This is the path to the folder that will be used to find the SANS data while patching. If no files appear in the popup, make sure that this folder is set correctly"}
131        SetVariable PathDisplay,font="Courier",fSize=10
132        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr
133        Button PathButton,pos={2,3},size={70,20},proc=V_PickPathButton,title="Pick Path"
134        Button PathButton,help={"Select the folder containing the raw SANS data files"}
135        Button helpButton,pos={400,3},size={25,20},proc=V_ShowPatchHelp,title="?"
136        Button helpButton,help={"Show the help file for patching raw data headers"}
137        PopupMenu PatchPopup,pos={4,37},size={156,19},proc=V_PatchPopMenuProc,title="File(s) to Patch"
138        PopupMenu PatchPopup,help={"The displayed file is the one that will be edited. The entire list will be edited if \"Change All..\" is selected. \r If no items, or the wrong items appear, click on the popup to refresh. \r List items are selected from the file based on MatchString"}
139        PopupMenu PatchPopup,mode=1,popvalue="none",value= #"root:Packages:NIST:VSANS:Globals:Patch:gPatchList"
140
141        Button CHButton,pos={314,37},size={110,20},proc=V_ChangeHeaderButtonProc,title="Change Header"
142        Button CHButton,help={"This will change the checked values (ONLY) in the single file selected in the popup."}
143        SetVariable PMStr,pos={6,63},size={174,13},proc=V_SetMatchStrProc,title="Match String"
144        SetVariable PMStr,help={"Enter the search string to narrow the list of files. \"*\" is the wildcard character. After entering, \"pop\" the menu to refresh the file list."}
145        SetVariable PMStr,font="Courier",fSize=10
146        SetVariable PMStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr
147        Button ChAllButton,pos={245,60},size={180,20},proc=V_ChAllHeadersButtonProc,title="Change All Headers in List"
148        Button ChAllButton,help={"This will change the checked values (ONLY) in ALL of the files in the popup list, not just the top file. If the \"change\" checkbox for the item is not checked, nothing will be changed for that item."}
149        Button DoneButton,pos={450,60},size={110,20},proc=V_DoneButtonProc,title="Done Patching"
150        Button DoneButton,help={"When done Patching files, this will close this control panel."}
151        CheckBox check0,pos={18,80},size={40,15},title="Run #",value= 1,mode=1,proc=V_MatchCheckProc
152        CheckBox check1,pos={78,80},size={40,15},title="Text",value= 0,mode=1,proc=V_MatchCheckProc
153        CheckBox check2,pos={138,80},size={40,15},title="Group_ID",value= 0,mode=1,proc=V_MatchCheckProc
154
155        SetVariable curStr,pos={50,112},size={350,20},title="File Label:"
156        SetVariable curStr,help={"Label of current file in popup list"}
157        SetVariable curStr,font="Courier",fSize=10
158        SetVariable curStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPatchCurLabel
159       
160        PopupMenu popup_0,pos={450,112},size={109,20},title="Detector Panel",proc=V_PatchPopMenuProc
161        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;B;\""
162
163
164        TabControl PatchTab,pos={20,140},size={570,380}
165        TabControl PatchTab,tabLabel(0)="Control",tabLabel(1)="Reduction",tabLabel(2)="Sample"
166        TabControl PatchTab,tabLabel(3)="Instrument",tabLabel(4)="Detectors",tabLabel(5)="PolSANS"
167        TabControl PatchTab,value=0,labelBack=(47748,57192,54093),proc=V_PatchTabProc
168
169
170        ListBox list0,pos={30,170.00},size={550.00,330},proc=V_PatchListBoxProc,frame=1
171        ListBox list0,fSize=10,userColumnResize= 1,listWave=PP_ListWave,selWave=PP_SelWave,titleWave=PP_TitleWave
172        ListBox list0,mode=2,widths={30,200}
173
174
175// put these in a tabbed? section for the 9 different panels
176// will it be able to patch all "FL" with the proper values, then all "FR", etc. to batchwise correct files?
177
178// TODO: add functions for these, make the intent a popup (since it's an enumerated type)
179
180//      PopupMenu popup_1,pos={42,base+14*step},size={109,20},title="File intent"
181//      PopupMenu popup_1,mode=1,popvalue="SCATTER",value= #"\"SCATTER;EMPTY;BLOCKED BEAM;TRANS;EMPTY BEAM;\""
182
183
184
185        SetDataFolder root:
186End
187
188//
189// function to control the display of the list box, based on the selection of the tab
190//
191Function V_PatchTabProc(name,tab)
192        String name
193        Variable tab
194       
195//      Print "name,number",name,tab
196        SetDataFolder root:Packages:NIST:VSANS:Globals:Patch:
197       
198        Wave/T PP_listWave = PP_ListWave
199        Wave PP_selWave = PP_selWave
200       
201        //clear the listWave and SelWave
202        PP_ListWave = ""
203        PP_SelWave = 0
204       
205        Variable nRows=1
206        // switch based on the tab number
207        switch(tab)     
208                case 0:
209                        //Print "tab 0 = CONTROL"
210                       
211                        V_FillListBox0(PP_ListWave,PP_SelWave)
212                        break           
213                case 1:
214                        //Print "tab 1 = REDUCTION"
215                       
216                        V_FillListBox1(PP_ListWave,PP_SelWave)
217                        break
218                case 2:
219                        //Print "tab 2 = SAMPLE"
220                       
221                        V_FillListBox2(PP_ListWave,PP_SelWave)
222                        break
223                case 3:
224                        //Print "tab 3 = INSTRUMENT"
225                       
226                        V_FillListBox3(PP_ListWave,PP_SelWave)
227                        break
228                case 4:
229                        //Print "tab 4 = DETECTORS"
230                       
231                        V_FillListBox4(PP_ListWave,PP_SelWave)
232                        break
233                case 5:
234                        //Print "tab 5 = POL_SANS"
235
236                        V_FillListBox5(PP_ListWave,PP_SelWave)
237                        break
238                default:                        // optional default expression executed
239                        SetDataFolder root:
240                        Abort "No tab found -- PatchTabProc"            // when no case matches
241        endswitch
242
243
244        SetDataFolder root:
245        return(0)
246End
247
248// fill list boxes based on the tab
249//
250// *** if the number of elements is changed, then be sure that the variable nRows is updated
251//    * this is the same procedure for all of the tabs
252//    * then be sure that the new listWave assignments are properly indexed
253//
254// CONTROL
255//
256Function V_FillListBox0(listWave,selWave)
257        Wave/T listWave
258        Wave selWave
259       
260        // trust that I'm getting a valid raw data file name from the popup
261        String fname
262        ControlInfo/W=V_Patch_Panel PatchPopup
263        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
264                Abort "no file selected in popup menu"          //null selection
265        else
266                fname = S_value                         //selection not null
267        Endif
268        //prepend path for read routine
269        PathInfo catPathName
270        fname = S_path + fname
271
272        Variable nRows = 3
273        Redimension/N=(nRows,3) ListWave
274        Redimension/N=(nRows,3) selWave
275        // clear the contents
276        listWave = ""
277        selWave = 0
278        SelWave[][0] = 2^5              // checkboxes
279        SelWave[][2] = 2^1              // 3rd column editable
280       
281       
282       
283        listWave[0][1] = "count_time"
284        listWave[0][2] = num2str(V_getCount_time(fname))
285       
286        listWave[1][1] = "detector_counts"
287        listWave[1][2] = num2str(V_getDetector_counts(fname))
288       
289        listWave[2][1] = "monitor_counts"
290        listWave[2][2] = num2str(V_getMonitorCount(fname))
291       
292        return(0)
293End
294
295// fill list boxes based on the tab
296//
297// REDUCTION items
298//
299Function V_FillListBox1(listWave,selWave)
300        Wave/T listWave
301        Wave selWave
302
303        // trust that I'm getting a valid raw data file name from the popup
304        String fname
305        ControlInfo/W=V_Patch_Panel PatchPopup
306        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
307                Abort "no file selected in popup menu"          //null selection
308        else
309                fname = S_value                         //selection not null
310        Endif
311        //prepend path for read routine
312        PathInfo catPathName
313        fname = S_path + fname
314
315        Variable nRows = 13
316        Redimension/N=(nRows,3) ListWave
317        Redimension/N=(nRows,3) selWave
318        // clear the contents
319        listWave = ""
320        selWave = 0
321        SelWave[][0] = 2^5              // checkboxes
322        SelWave[][2] = 2^1              // 3rd column editable
323       
324       
325        listWave[0][1] = "empty_beam_file_name"
326        listWave[0][2] = V_getEmptyBeamFileName(fname)
327       
328        listWave[1][1] = "background_file_name"
329        listWave[1][2] = V_getBackgroundFileName(fname)
330       
331        listWave[2][1] = "empty_file_name"
332        listWave[2][2] = V_getEmptyFileName(fname)
333       
334        listWave[3][1] = "sensitivity_file_name"
335        listWave[3][2] = V_getSensitivityFileName(fname)
336       
337        listWave[4][1] = "mask_file_name"
338        listWave[4][2] = V_getMaskFileName(fname)
339       
340        listWave[5][1] = "transmission_file_name"
341        listWave[5][2] = V_getTransmissionFileName(fname)
342       
343        listWave[6][1] = "intent"
344        listWave[6][2] = V_getReduction_intent(fname)
345       
346        listWave[7][1] = "file_purpose (polSANS)"
347        listWave[7][2] = V_getReduction_polSANSPurpose(fname)
348       
349        listWave[8][1] = "group_id (sample)"
350        listWave[8][2] = num2str(V_getSample_group_ID(fname))
351
352        listWave[9][1] = "box_count"
353        listWave[9][2] = num2str(V_getBoxCounts(fname))
354       
355        listWave[10][1] = "box_count_error"
356        listWave[10][2] = num2str(V_getBoxCountsError(fname))
357       
358        listWave[11][1] = "whole_trans"
359        listWave[11][2] = num2str(V_getSampleTransWholeDetector(fname))
360       
361        listWave[12][1] = "whole_trans_error"
362        listWave[12][2] = num2str(V_getSampleTransWholeDetErr(fname))
363       
364       
365               
366       
367
368        return(0)
369End
370
371// fill list boxes based on the tab
372//
373// SAMPLE
374//
375Function V_FillListBox2(listWave,selWave)
376        Wave/T listWave
377        Wave selWave
378       
379        // trust that I'm getting a valid raw data file name from the popup
380        String fname
381        ControlInfo/W=V_Patch_Panel PatchPopup
382        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
383                Abort "no file selected in popup menu"          //null selection
384        else
385                fname = S_value                         //selection not null
386        Endif
387        //prepend path for read routine
388        PathInfo catPathName
389        fname = S_path + fname
390
391        Variable nRows = 4
392        Redimension/N=(nRows,3) ListWave
393        Redimension/N=(nRows,3) selWave
394        // clear the contents
395        listWave = ""
396        selWave = 0
397        SelWave[][0] = 2^5              // checkboxes
398        SelWave[][2] = 2^1              // 3rd column editable
399       
400       
401        listWave[0][1] = "description"
402        listWave[0][2] = V_getSampleDescription(fname)
403       
404        listWave[1][1] = "thickness"
405        listWave[1][2] = num2str(V_getSampleThickness(fname))
406       
407        listWave[2][1] = "transmission"
408        listWave[2][2] = num2str(V_getSampleTransmission(fname))
409       
410        listWave[3][1] = "transmission_error"
411        listWave[3][2] = num2str(V_getSampleTransError(fname))
412       
413
414
415        return(0)
416End
417
418// fill list boxes based on the tab
419//
420// INSTRUMENT
421//
422Function V_FillListBox3(listWave,selWave)
423        Wave/T listWave
424        Wave selWave
425       
426        // trust that I'm getting a valid raw data file name from the popup
427        String fname
428        ControlInfo/W=V_Patch_Panel PatchPopup
429        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
430                Abort "no file selected in popup menu"          //null selection
431        else
432                fname = S_value                         //selection not null
433        Endif
434        //prepend path for read routine
435        PathInfo catPathName
436        fname = S_path + fname
437
438        Variable nRows = 6
439        Redimension/N=(nRows,3) ListWave
440        Redimension/N=(nRows,3) selWave
441        // clear the contents
442        listWave = ""
443        selWave = 0
444        SelWave[][0] = 2^5              // checkboxes
445        SelWave[][2] = 2^1              // 3rd column editable
446       
447       
448        listWave[0][1] = "attenuator_transmission"
449        listWave[0][2] = num2str(V_getAttenuator_transmission(fname))   
450       
451        listWave[1][1] = "attenuator_transmission_error"
452        listWave[1][2] = num2str(V_getAttenuator_trans_err(fname))     
453
454        listWave[2][1] = "monochromator type"
455        listWave[2][2] = V_getMonochromatorType(fname)
456       
457        listWave[3][1] = "wavelength"
458        listWave[3][2] = num2str(V_getWavelength(fname))       
459       
460        listWave[4][1] = "wavelength_spread"
461        listWave[4][2] = num2str(V_getWavelength_spread(fname))
462
463        listWave[5][1] = "distance (source aperture)"
464        listWave[5][2] = num2str(V_getSourceAp_distance(fname))         
465               
466        return(0)
467End
468
469
470// fill list boxes based on the tab
471//
472// TODO -- is this all of the fields that I want to edit?
473//
474// DETECTORS
475//
476Function V_FillListBox4(listWave,selWave)
477        Wave/T listWave
478        Wave selWave
479       
480        // trust that I'm getting a valid raw data file name from the popup
481        String fname
482        ControlInfo/W=V_Patch_Panel PatchPopup
483        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
484                Abort "no file selected in popup menu"          //null selection
485        else
486                fname = S_value                         //selection not null
487        Endif
488        //prepend path for read routine
489        PathInfo catPathName
490        fname = S_path + fname
491
492        Variable nRows = 12
493        Redimension/N=(nRows,3) ListWave
494        Redimension/N=(nRows,3) selWave
495        // clear the contents
496        listWave = ""
497        selWave = 0
498        SelWave[][0] = 2^5              // checkboxes
499        SelWave[][2] = 2^1              // 3rd column editable
500       
501        ControlInfo popup_0                     // which detector panel?
502        String detStr = S_value
503       
504        listWave[0][1] = "beam_center_x"
505        listWave[0][2] = num2str(V_getDet_Beam_center_x(fname,detStr)) 
506
507        listWave[1][1] = "beam_center_y"
508        listWave[1][2] = num2str(V_getDet_Beam_center_y(fname,detStr)) 
509
510        listWave[2][1] = "distance (nominal)"
511        listWave[2][2] = num2str(V_getDet_NominalDistance(fname,detStr))       
512
513        listWave[3][1] = "integrated_count"
514        listWave[3][2] = num2str(V_getDet_IntegratedCount(fname,detStr))       
515
516        listWave[4][1] = "pixel_fwhm_x"
517        listWave[4][2] = num2str(V_getDet_pixel_fwhm_x(fname,detStr))   
518
519        listWave[5][1] = "pixel_fwhm_y"
520        listWave[5][2] = num2str(V_getDet_pixel_fwhm_y(fname,detStr))   
521
522        listWave[6][1] = "pixel_num_x"
523        listWave[6][2] = num2str(V_getDet_pixel_num_x(fname,detStr))   
524
525        listWave[7][1] = "pixel_num_y"
526        listWave[7][2] = num2str(V_getDet_pixel_num_y(fname,detStr))   
527
528        listWave[8][1] = "setback"
529        listWave[8][2] = num2str(V_getDet_TBSetback(fname,detStr))     
530
531        if(cmpstr(detStr,"B") == 0 ||cmpstr(detStr,"FR") == 0 || cmpstr(detStr,"FL") == 0 || cmpstr(detStr,"MR") == 0 || cmpstr(detStr,"ML") == 0)
532                listWave[9][1] = "lateral_offset"                       // "B" detector drops here
533                listWave[9][2] = num2str(V_getDet_LateralOffset(fname,detStr)) 
534        else   
535                listWave[9][1] = "vertical_offset"     
536                listWave[9][2] = num2str(V_getDet_VerticalOffset(fname,detStr))
537        endif   
538
539        listWave[10][1] = "x_pixel_size"
540        listWave[10][2] = num2str(V_getDet_x_pixel_size(fname,detStr)) 
541
542        listWave[11][1] = "y_pixel_size"
543        listWave[11][2] = num2str(V_getDet_y_pixel_size(fname,detStr)) 
544
545
546        return(0)
547End
548
549
550// fill list boxes based on the tab
551//
552// TODO -- this all needs to be filled in, once I figure out what is needed
553//
554// PolSANS
555//
556Function V_FillListBox5(listWave,selWave)
557        Wave/T listWave
558        Wave selWave
559       
560        // trust that I'm getting a valid raw data file name from the popup
561        String fname
562        ControlInfo/W=V_Patch_Panel PatchPopup
563        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
564                Abort "no file selected in popup menu"          //null selection
565        else
566                fname = S_value                         //selection not null
567        Endif
568        //prepend path for read routine
569        PathInfo catPathName
570        fname = S_path + fname
571
572        Variable nRows = 3
573        Redimension/N=(nRows,3) ListWave
574        Redimension/N=(nRows,3) selWave
575        // clear the contents
576        listWave = ""
577        selWave = 0
578        SelWave[][0] = 2^5              // checkboxes
579        SelWave[][2] = 2^1              // 3rd column editable
580       
581       
582        listWave[0][1] = "count_time"
583        listWave[0][2] = num2str(V_getCount_time(fname))       
584
585        return(0)
586End
587
588
589// TODO -- determine if I really need this --- I don't
590//  think I really have any reason to respond to events from list box actions
591//  or edits. the final action of patching is done with the button
592//
593Function V_PatchListBoxProc(lba) : ListBoxControl
594        STRUCT WMListboxAction &lba
595
596        Variable row = lba.row
597        Variable col = lba.col
598        WAVE/T/Z listWave = lba.listWave
599        WAVE/Z selWave = lba.selWave
600
601        switch( lba.eventCode )
602                case -1: // control being killed
603                        break
604                case 1: // mouse down
605                        break
606                case 3: // double click
607                        break
608                case 4: // cell selection
609                case 5: // cell selection plus shift key
610                        break
611                case 6: // begin edit
612                        break
613                case 7: // finish edit
614                        break
615                case 13: // checkbox clicked (Igor 6.2 or later)
616                        break
617        endswitch
618
619        return 0
620End
621
622
623
624
625
626
627//button action procedure to select the local path to the folder that
628//contains the vSANS data
629//sets catPathName, updates the path display and the popup of files (in that folder)
630//
631Function V_PickPathButton(PathButton) : ButtonControl
632        String PathButton
633       
634        // call the main procedure to set the data path
635        V_PickPath()
636       
637        //set the global string to the selected pathname
638        //set a local copy of the path for Patch
639        PathInfo/S catPathName
640   String dum = S_path
641        if (V_flag == 0)
642                //path does not exist - no folder selected
643                String/G root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr = "no folder selected"
644        else
645                String/G root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr = dum
646        endif
647       
648        //Update the pathStr variable box
649        ControlUpdate/W=V_Patch_Panel $"PathDisplay"
650       
651        //then update the popup list
652        // (don't update the list - not until someone enters a search critera) -- Jul09
653        //
654        V_SetMatchStrProc("",0,"*","")          //this is equivalent to finding everything, typical startup case
655
656        return(0)
657End
658
659//
660//returns a list of valid files (raw data, no version numbers, no averaged files)
661//that is semicolon delimited, and is suitable for display in a popup menu
662//
663Function/S xGetValidPatchPopupList()
664
665        //make sure that path exists
666        PathInfo catPathName
667        String path = S_path
668        if (V_flag == 0)
669                Abort "folder path does not exist - use Pick Path button"
670        Endif
671       
672        String newList = ""
673
674        newList = V_GetRawDataFileList()
675
676        //trim list to include only selected files
677        SVAR match = root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr
678        if(strlen(match) == 0)          //if nothing is entered for a match string, return everything, rather than nothing
679                match = "*"
680        endif
681
682        newlist = V_MyMatchList(match,newlist,";")
683       
684        newList = SortList(newList,";",0)
685        Return(newList)
686End
687
688
689
690//
691// TODO:
692// -- test all of the filters to be sure they actually work properly.
693//   Run # filter works
694//   Text filter works
695//
696// -- SDD filter does not apply -- what is a better filter choice?
697// -- can I filter intent? group_id?
698// -- can't just search for "sample" - this returns everything
699//
700//
701//
702//
703//
704//returns a list of valid files (raw data, no version numbers, no averaged files)
705//that is semicolon delimited, and is suitable for display in a popup menu
706//
707// Uses Grep to look through the any text in the file, which includes the sample label
708// can be very slow across the network, as it re-pops the menu on a selection (since some folks don't hit
709// enter when inputing a filter string)
710//
711// - or -
712// a list or range of run numbers
713// - or -
714// a SDD (to within 0.001m)
715// - or -
716// * to get everything
717//
718//      NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
719 // 1== Run # (comma range OK)
720 // 2== Grep the text (SLOW)
721 // 3== filter by SDD (within 0.001 m)
722Function/S V_GetValidPatchPopupList()
723
724        //make sure that path exists
725        PathInfo catPathName
726        String path = S_path
727        if (V_flag == 0)
728                Abort "folder path does not exist - use Pick Path button"
729        Endif
730       
731        String newList = ""
732
733        newList = V_GetRawDataFileList()
734
735        //trim list to include only selected files
736        SVAR match = root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr
737        if(strlen(match) == 0 || cmpstr(match,"*")==0)          //if nothing or "*" entered for a match string, return everything, rather than nothing
738                match = "*"
739        // old way, with simply a wildcard
740                newlist = V_MyMatchList(match,newlist,";")
741                newList = SortList(newList,";",0)
742                return(newList)
743        endif
744       
745        //loop through all of the files as needed
746
747       
748        String list="",item="",fname,runList="",numStr=""
749        Variable ii,num=ItemsInList(newList),val,group_id
750        NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
751       
752        // run number list
753        if(gRadioVal == 1)
754                       
755                list = V_ExpandNumRanges(match)         //now simply comma delimited
756                num=ItemsInList(list,",")
757                for(ii=0;ii<num;ii+=1)
758                        item = StringFromList(ii,list,",")
759                        val=str2num(item)
760
761                        runList += V_GetFileNameFromPathNoSemi(V_FindFileFromRunNumber(val)) + ";"             
762                endfor
763                newlist = runList
764               
765        endif
766       
767        //grep through what text I can find in the VAX binary
768        // Grep Note: the \\b sequences limit matches to a word boundary before and after
769        // "boondoggle", so "boondoggles" and "aboondoggle" won't match.
770        if(gRadioVal == 2)
771                for(ii=0;ii<num;ii+=1)
772                        item=StringFromList(ii, newList , ";")
773//                      Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
774                        Grep/P=catPathName/Q/E=("(?i)"+match) item
775                        if( V_value )   // at least one instance was found
776//                              Print "found ", item,ii
777                                list += item + ";"
778                        endif
779                endfor
780
781                newList = list
782        endif
783       
784        // group_id
785        // replace this with: V_getSample_GroupID(fname)
786        Variable pos
787        String IDStr=""
788        if(gRadioVal == 3)
789                pos = strsearch(match, "*", 0)
790                if(pos == -1)           //no wildcard
791                        val = str2num(match)
792                else
793                        val = str2num(match[0,pos-1])
794                endif
795               
796//              print val
797                for(ii=0;ii<num;ii+=1)
798                        item=StringFromList(ii, newList , ";")
799                        fname = path + item
800                        group_id = V_getSample_GroupID(fname)
801                        if(group_id == val)
802                                list += item + ";"
803                        endif
804       
805                endfor
806               
807                newList = list
808        endif
809
810        newList = SortList(newList,";",0)
811        Return(newList)
812End
813
814
815
816
817// -- no longer refreshes the list - this seems redundant, and can be slow if grepping
818//
819//updates the popup list when the menu is "popped" so the list is
820//always fresh, then automatically displays the header of the popped file
821//value of match string is used in the creation of the list - use * to get
822//all valid files
823//
824Function V_PatchPopMenuProc(PatchPopup,popNum,popStr) : PopupMenuControl
825        String PatchPopup
826        Variable popNum
827        String popStr
828
829       
830//      String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchList = list
831//      ControlUpdate PatchPopup
832        V_ShowHeaderButtonProc("SHButton")
833       
834        return(0)
835End
836
837//when text is entered in the match string, the popup list is refined to
838//include only the selected files, useful for trimming a lengthy list, or selecting
839//a range of files to patch
840//only one wildcard (*) is allowed
841//
842Function V_SetMatchStrProc(ctrlName,varNum,varStr,varName) : SetVariableControl
843        String ctrlName
844        Variable varNum
845        String varStr
846        String varName
847
848        //change the contents of gPatchList that is displayed
849        //based on selected Path, match str, and
850        //further trim list to include only RAW SANS files
851        //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
852       
853        String list = V_GetValidPatchPopupList()
854       
855        String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchList = list
856        ControlUpdate PatchPopup
857        PopupMenu PatchPopup,mode=1
858       
859        if(strlen(list) > 0)
860                V_ShowHeaderButtonProc("SHButton")
861        endif
862        return(0)
863End
864
865
866//displays the header of the selected file (top in the popup) when the button is clicked
867//sort of a redundant button, since the procedure is automatically called (as if it were
868//clicked) when a new file is chosen from the popup
869//
870// TODO - make sure this is tab-aware
871//
872Function V_ShowHeaderButtonProc(SHButton) : ButtonControl
873        String SHButton
874
875        //displays (editable) header information about current file in popup control
876        //putting the values in the SetVariable displays (resetting the global variables)
877       
878        //get the popup string
879        String partialName, tempName
880        Variable ok
881        ControlInfo/W=V_Patch_Panel PatchPopup
882        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
883                //null selection
884                Abort "no file selected in popup menu"
885        else
886                //selection not null
887                partialName = S_value
888                //Print partialName
889        Endif
890        //get a valid file based on this partialName and catPathName
891        tempName = V_FindValidFilename(partialName)
892       
893        //prepend path to tempName for read routine
894        PathInfo catPathName
895        tempName = S_path + tempName
896       
897        //make sure the file is really a RAW data file
898        ok = V_CheckIfRawData(tempName)                 //--- This loads the whole file to read the instrument string
899        if (!ok)
900                Abort "this file is not recognized as a RAW SANS data file"
901        Endif
902       
903        //Print tempName
904       
905        V_ReadHeaderForPatch(tempName)
906       
907        ControlUpdate/A/W=V_Patch_Panel
908       
909        // no matter what tab is selected, show the file label
910        SVAR fileLabel = root:Packages:NIST:VSANS:Globals:Patch:gPatchCurLabel
911        fileLabel = V_getSampleDescription(tempName)
912       
913        return(0)
914End
915
916
917
918//simple function to get the string value from the popup list of filenames
919//returned string is only the text in the popup, a partial name with no path
920//or VAX version number.
921//
922Function/S V_GetPatchPopupString()
923
924        String str=""
925       
926        ControlInfo patchPopup
927        If(cmpstr(S_value,"")==0)
928                //null selection
929                Abort "no file selected in popup menu"
930        else
931                //selection not null
932                str = S_value
933                //Print str
934        Endif
935       
936        Return str
937End
938
939//Changes (writes to disk!) the specified changes to the (single) file selected in the popup
940//reads the checkboxes to determine which (if any) values need to be written
941//
942// This currently makes sure the name is valid,
943// determines the active tab,
944// and dispatches to the correct (numbered) writer
945//
946Function V_ChangeHeaderButtonProc(CHButton) : ButtonControl
947        String CHButton
948
949        String partialName="", tempName = ""
950        Variable ok
951        //get the popup string
952        partialName = V_GetPatchPopupString()
953       
954        //get a valid file based on this partialName and catPathName
955        tempName = V_FindValidFilename(partialName)
956       
957        //prepend path to tempName for read routine
958        PathInfo catPathName
959        tempName = S_path + tempName
960       
961        //make sure the file is really a RAW data file
962        ok = V_CheckIfRawData(tempName)
963        if (!ok)
964                Abort "this file is not recognized as a RAW SANS data file"
965        Endif
966       
967        // which tab is active?
968        ControlInfo/W=V_Patch_Panel PatchTab
969       
970        switch(V_Value) // numeric switch
971                case 0: // execute if case matches expression
972                        V_WriteHeaderForPatch_0(tempName)
973                        break           // exit from switch
974                case 1:
975                        V_WriteHeaderForPatch_1(tempName)
976                        break
977                case 2:
978                        V_WriteHeaderForPatch_2(tempName)
979                        break
980                case 3:
981                        V_WriteHeaderForPatch_3(tempName)
982                        break
983                case 4:
984                        V_WriteHeaderForPatch_4(tempName)
985                        break
986                case 5:
987                        V_WriteHeaderForPatch_5(tempName)
988                        break
989                default:                        // optional default expression executed
990                        Abort "Tab not found - V_ChangeHeaderButtonProc"
991        endswitch
992
993       
994        //after writing the changes to the file
995        // clean up, to force a reload from disk
996        V_CleanupData_w_Progress(0,1)
997       
998        return(0)
999End
1000
1001//     
1002//*****this function actually writes the data to disk*****
1003//
1004// TODO - re-write a series of these function to mirror the "fill" functions
1005//   specific to each tab
1006//
1007// TODO x- clear out the old data and force a re-load from disk, or the old data
1008//    will be read in from the RawVSANS folder, and it will look like nothing was written
1009//                      (done in the calling function)
1010//
1011// currently, all errors are printed out by the writer, but ignored here
1012//
1013Function V_WriteHeaderForPatch_0(fname)
1014        String fname
1015       
1016        Variable val,err
1017        String textstr
1018               
1019        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1020        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1021
1022        // test bit 4 to see if the checkbox is selected
1023        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1024                val = str2num(listWave[0][2])
1025                err = V_writeCount_time(fname,val)              // count_time
1026        endif
1027
1028        if ((selWave[1][0] & 2^4) != 0)         // "detector_counts"
1029                val = str2num(listWave[1][2])
1030                err = V_writeDetector_counts(fname,val)
1031        endif   
1032       
1033        if ((selWave[2][0] & 2^4) != 0)         //"monitor_counts"
1034                val = str2num(listWave[2][2])
1035                err = V_writeMonitorCount(fname,val)
1036        endif   
1037       
1038
1039
1040
1041        Return(0)
1042End
1043
1044//
1045// tab 1
1046//
1047Function V_WriteHeaderForPatch_1(fname)
1048        String fname
1049
1050        Variable val,err
1051        String str
1052               
1053        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1054        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1055
1056        // test bit 4 to see if the checkbox is selected
1057        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1058                str = listWave[0][2]                    // empty_beam_file_name
1059                err = V_writeEmptyBeamFileName(fname,str)               
1060        endif
1061
1062        if ((selWave[1][0] & 2^4) != 0)         // "background_file_name"
1063                str = listWave[1][2]
1064                err = V_writeBackgroundFileName(fname,str)
1065        endif   
1066       
1067        if ((selWave[2][0] & 2^4) != 0)         //"empty_file_name"
1068                str = listWave[2][2]
1069                err = V_writeEmptyFileName(fname,str)
1070        endif   
1071       
1072        if ((selWave[3][0] & 2^4) != 0)         //"sensitivity_file_name"
1073                str = listWave[3][2]
1074                err = V_writeSensitivityFileName(fname,str)
1075        endif   
1076       
1077        if ((selWave[4][0] & 2^4) != 0)         //"mask_file_name"
1078                str = listWave[4][2]
1079                err = V_writeMaskFileName(fname,str)
1080        endif   
1081       
1082        if ((selWave[5][0] & 2^4) != 0)         //"transmission_file_name"
1083                str = listWave[5][2]
1084                err = V_writeTransmissionFileName(fname,str)
1085        endif   
1086
1087        if ((selWave[6][0] & 2^4) != 0)         //"intent"
1088                str = listWave[6][2]
1089                err = V_writeReductionIntent(fname,str)
1090        endif   
1091       
1092        if ((selWave[7][0] & 2^4) != 0)         //"file_purpose (polSANS)"
1093                str = listWave[7][2]
1094                err = V_writePolReduction_purpose(fname,str)
1095        endif           
1096
1097        if ((selWave[8][0] & 2^4) != 0)         //"group_id (sample)"
1098                val = str2num(listWave[8][2])
1099                err = V_writeSample_GroupID(fname,val)
1100        endif   
1101       
1102        if ((selWave[9][0] & 2^4) != 0)         //"box_count"
1103                val = str2num(listWave[9][2])
1104                err = V_writeBoxCounts(fname,val)
1105        endif   
1106       
1107        if ((selWave[10][0] & 2^4) != 0)                //"box_count_error"
1108                val = str2num(listWave[10][2])
1109                err = V_writeBoxCountsError(fname,val)
1110        endif   
1111       
1112        if ((selWave[11][0] & 2^4) != 0)                //"whole_trans"
1113                val = str2num(listWave[11][2])
1114                err = V_writeSampleTransWholeDetector(fname,val)
1115        endif   
1116       
1117        if ((selWave[12][0] & 2^4) != 0)                //"whole_trans_error"
1118                val = str2num(listWave[12][2])
1119                err = V_writeSampleTransWholeDetErr(fname,val)
1120        endif   
1121       
1122       
1123               
1124               
1125        return(0)
1126End
1127
1128// SAMPLE
1129Function V_WriteHeaderForPatch_2(fname)
1130        String fname
1131       
1132        Variable val,err
1133        String str
1134               
1135        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1136        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1137
1138        // test bit 4 to see if the checkbox is selected
1139        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1140                str = listWave[0][2]                    // "description"
1141                err = V_writeSampleDescription(fname,str)               
1142        endif
1143
1144        if ((selWave[1][0] & 2^4) != 0)         // "thickness"
1145                val = str2num(listWave[1][2])
1146                err = V_writeSampleThickness(fname,val)
1147        endif   
1148       
1149        if ((selWave[2][0] & 2^4) != 0)         //"transmission"
1150                val = str2num(listWave[2][2])
1151                err = V_writeSampleTransmission(fname,val)
1152        endif   
1153       
1154        if ((selWave[3][0] & 2^4) != 0)         //"transmission_error"
1155                val = str2num(listWave[3][2])
1156                err = V_writeSampleTransError(fname,val)
1157        endif   
1158       
1159        return(0)
1160End
1161
1162// INSTRUMENT
1163Function V_WriteHeaderForPatch_3(fname)
1164        String fname
1165
1166        Variable val,err
1167        String str
1168               
1169        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1170        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1171
1172        // test bit 4 to see if the checkbox is selected
1173        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1174                val = str2num(listWave[0][2])                   // "attenuator_transmission"
1175                err = V_writeAttenuator_transmission(fname,val)         
1176        endif
1177
1178        if ((selWave[1][0] & 2^4) != 0)         // "attenuator_transmission_error"
1179                val = str2num(listWave[1][2])
1180                err = V_writeAttenuator_trans_err(fname,val)
1181        endif   
1182       
1183        if ((selWave[2][0] & 2^4) != 0)         //"monochromator type"
1184                str = listWave[2][2]
1185                err = V_writeMonochromatorType(fname,str)
1186        endif   
1187       
1188        if ((selWave[3][0] & 2^4) != 0)         //"wavelength"
1189                val = str2num(listWave[3][2])
1190                err = V_writeWavelength(fname,val)
1191        endif   
1192
1193        if ((selWave[4][0] & 2^4) != 0)         //"wavelength_spread"
1194                val = str2num(listWave[4][2])
1195                err = V_writeWavelength_spread(fname,val)
1196        endif   
1197       
1198        if ((selWave[5][0] & 2^4) != 0)         //"distance (source aperture)"
1199                val = str2num(listWave[5][2])
1200                err = V_writeSourceAp_distance(fname,val)
1201        endif           
1202       
1203       
1204        return(0)
1205End
1206
1207// DETECTOR
1208Function V_WriteHeaderForPatch_4(fname)
1209        String fname
1210
1211        Variable val,err
1212        String str
1213               
1214        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1215        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1216
1217        ControlInfo popup_0
1218        String detStr = S_Value
1219
1220        // test bit 4 to see if the checkbox is selected
1221        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1222                val = str2num(listWave[0][2])                   // "beam_center_x"
1223                err = V_writeDet_beam_center_x(fname,detStr,val)       
1224        endif
1225
1226        if ((selWave[1][0] & 2^4) != 0)         // "beam_center_y"
1227                val = str2num(listWave[1][2])
1228                err = V_writeDet_beam_center_y(fname,detStr,val)
1229        endif   
1230       
1231        if ((selWave[2][0] & 2^4) != 0)         //"distance (nominal)"
1232                val = str2num(listWave[2][2])
1233                err = V_writeDet_distance(fname,detStr,val)
1234        endif   
1235       
1236        if ((selWave[3][0] & 2^4) != 0)         //"integrated_count"
1237                val = str2num(listWave[3][2])
1238                err = V_writeDet_IntegratedCount(fname,detStr,val)
1239        endif   
1240       
1241        if ((selWave[4][0] & 2^4) != 0)         //"pixel_fwhm_x"
1242                val = str2num(listWave[4][2])
1243                err = V_writeDet_pixel_fwhm_x(fname,detStr,val)
1244        endif   
1245       
1246        if ((selWave[5][0] & 2^4) != 0)         //"pixel_fwhm_y"
1247                val = str2num(listWave[5][2])
1248                err = V_writeDet_pixel_fwhm_y(fname,detStr,val)
1249        endif   
1250
1251        if ((selWave[6][0] & 2^4) != 0)         //"pixel_num_x"
1252                val = str2num(listWave[6][2])
1253                err = V_writeDet_pixel_num_x(fname,detStr,val)
1254        endif   
1255       
1256        if ((selWave[7][0] & 2^4) != 0)         //"pixel_num_y"
1257                val = str2num(listWave[7][2])
1258                err = V_writeDet_pixel_num_y(fname,detStr,val)
1259        endif           
1260       
1261        if ((selWave[8][0] & 2^4) != 0)         //"setback" -- only for TB detectors
1262                val = str2num(listWave[8][2])
1263                if(cmpstr(detStr,"FT") == 0 || cmpstr(detStr,"FB") == 0 || cmpstr(detStr,"MT") == 0 || cmpstr(detStr,"MB") == 0)
1264                        err = V_writeDet_TBSetback(fname,detStr,val)
1265                endif
1266        endif   
1267
1268        if ((selWave[9][0] & 2^4) != 0)         //"lateral_offset" or "vertical_offset"
1269                val = str2num(listWave[9][2])
1270                if(cmpstr(detStr,"B") == 0 ||cmpstr(detStr,"FR") == 0 || cmpstr(detStr,"FL") == 0 || cmpstr(detStr,"MR") == 0 || cmpstr(detStr,"ML") == 0)
1271                        err = V_writeDet_LateralOffset(fname,detStr,val)
1272                else
1273                        err = V_writeDet_VerticalOffset(fname,detStr,val)
1274                endif
1275        endif   
1276       
1277        if ((selWave[10][0] & 2^4) != 0)                //"x_pixel_size"
1278                val = str2num(listWave[10][2])
1279                err = V_writeDet_x_pixel_size(fname,detStr,val)
1280        endif   
1281       
1282        if ((selWave[11][0] & 2^4) != 0)                //"y_pixel_size"
1283                val = str2num(listWave[11][2])
1284                err = V_writeDet_y_pixel_size(fname,detStr,val)
1285        endif   
1286       
1287
1288
1289       
1290        return(0)
1291End
1292
1293// TODO -- not yet implemented
1294Function V_WriteHeaderForPatch_5(fname)
1295        String fname
1296       
1297        return(0)
1298End
1299
1300
1301// control the display of the radio buttons
1302Function V_MatchCheckProc(name,value)
1303        String name
1304        Variable value
1305       
1306        NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
1307       
1308        strswitch (name)
1309                case "check0":
1310                        gRadioVal= 1
1311                        break
1312                case "check1":
1313                        gRadioVal= 2
1314                        break
1315                case "check2":
1316                        gRadioVal= 3
1317                        break
1318        endswitch
1319        CheckBox check0,value= gRadioVal==1
1320        CheckBox check1,value= gRadioVal==2
1321        CheckBox check2,value= gRadioVal==3
1322        return(0)
1323End
1324
1325//This function will read only the selected values editable in the patch panel
1326//
1327// DONE
1328// x- re-write this to be tab-aware. ShowHeaderForPatch() calls this, but does nothing
1329//    to update the tab content. Figure out which function is in charge, and update the content.
1330//
1331Function V_ReadHeaderForPatch(fname)
1332        String fname
1333       
1334       
1335        // figure out which is the active tab, then let PatchTabProc fill it in
1336        ControlInfo/W=V_Patch_Panel PatchTab
1337        V_PatchTabProc("",V_Value)     
1338       
1339        Return 0
1340End
1341
1342Function V_ShowPatchHelp(ctrlName) : ButtonControl
1343        String ctrlName
1344//      DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[Patch File Headers]"
1345//      if(V_flag !=0)
1346                DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found"
1347//      endif
1348        return(0)
1349End
1350
1351//button action procedure to change the selected information (checked values)
1352//in each file in the popup list. This will change multiple files, and as such,
1353//the user is given a chance to bail out before the whole list of files
1354//is modified
1355//useful for patching a series of runs with the same beamcenters, or transmissions
1356//
1357Function V_ChAllHeadersButtonProc(ctrlName) : ButtonControl
1358        String ctrlName
1359       
1360        String msg
1361        msg = "Do you really want to write all of these values to each data file in the popup list? "
1362        msg += "- clicking NO will leave all files unchanged"
1363        DoAlert 1,msg
1364        If(V_flag == 2)
1365                Abort "no files were changed"
1366        Endif
1367       
1368        //this will change (checked) values in ALL of the headers in the popup list
1369        SVAR list = root:Packages:NIST:VSANS:Globals:Patch:gPatchList
1370        Variable numitems,ii
1371        String partialName="", tempName = ""
1372        Variable ok
1373       
1374        numitems = ItemsInList(list,";")
1375       
1376        if(numitems == 0)
1377                Abort "no items in list for multiple patch"
1378        Endif
1379       
1380        // loop through all of the files
1381        ii=0
1382        do
1383                //get current item in the list
1384                partialName = StringFromList(ii, list, ";")
1385                   
1386                //get a valid file based on this partialName and catPathName
1387                tempName = V_FindValidFilename(partialName)
1388       
1389                //prepend path to tempName for read routine
1390                PathInfo catPathName
1391                tempName = S_path + tempName
1392       
1393                //make sure the file is really a RAW data file
1394                ok = V_CheckIfRawData(tempName)
1395                if (!ok)
1396                   Print "this file is not recognized as a RAW SANS data file = ",tempName
1397                else
1398                   //go write the changes to the file
1399                        // which tab is active?
1400                        ControlInfo/W=V_Patch_Panel PatchTab
1401                       
1402                        switch(V_Value) // numeric switch
1403                                case 0: // execute if case matches expression
1404                                        V_WriteHeaderForPatch_0(tempName)
1405                                        break           // exit from switch
1406                                case 1:
1407                                        V_WriteHeaderForPatch_1(tempName)
1408                                        break
1409                                case 2:
1410                                        V_WriteHeaderForPatch_2(tempName)
1411                                        break
1412                                case 3:
1413                                        V_WriteHeaderForPatch_3(tempName)
1414                                        break
1415                                case 4:
1416                                        V_WriteHeaderForPatch_4(tempName)
1417                                        break
1418                                case 5:
1419                                        V_WriteHeaderForPatch_5(tempName)
1420                                        break
1421                                default:                        // optional default expression executed
1422                                        Abort "Tab not found - V_ChAllHeadersButtonProc"
1423                        endswitch
1424                Endif
1425               
1426                ii+=1
1427        while(ii<numitems)
1428
1429
1430        //after writing the changes to the file
1431        // clean up, to force a reload from disk
1432        V_CleanupData_w_Progress(0,1)
1433
1434        return(0)
1435End
1436
1437
1438//simple action for button to close the panel
1439//
1440// cleans out the RawVSANS folder on closing
1441//
1442Function V_DoneButtonProc(ctrlName) : ButtonControl
1443        String ctrlName
1444
1445        DoWindow/K V_Patch_Panel
1446
1447//      V_CleanOutRawVSANS()
1448// present a progress window
1449        V_CleanupData_w_Progress(0,1)   
1450       
1451        return(0)
1452End
1453
1454
1455
1456////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1457////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1458///////////////
1459//
1460// this is a block to patch DEADTIME waves to the file headers, and can patch multiple files
1461//
1462// uses a simple panel to show what the table of values is.
1463// "read" will read only the first run number contents.
1464//
1465// TODO -- need to clear out the contents from RawVSANS, or else re-reading to check the values
1466//        will read locally, and it will look like nothing was written. Executing "save" will also
1467//        trigger a cleanout.
1468//
1469// TODO -- link this to a panel somewhere - a button? menu item? will there be a lot more of these little panels?
1470//
1471// TODO -- currently, this does not patch the deadtime for the back "B" detector. it is a single
1472//        value, not a wave see V_WritePerfectDeadTime(filename) for how the perfect (fake) values is written.
1473//
1474//
1475Proc V_PatchDetectorDeadtime(firstFile,lastFile,detStr,deadtimeStr)
1476        Variable firstFile=1,lastFile=100
1477        String detStr = "FL",deadtimeStr="deadTimeWave"
1478
1479        V_fPatchDetectorDeadtime(firstFile,lastFile,detStr,$deadtimeStr)
1480
1481End
1482
1483Proc V_ReadDetectorDeadtime(firstFile,lastFile,detStr)
1484        Variable firstFile=1,lastFile=100
1485        String detStr = "FL"
1486       
1487        V_fReadDetectorDeadtime(firstFile,lastFile,detStr)
1488       
1489End
1490
1491// simple utility to patch the detector deadtime in the file headers
1492// lo is the first file number
1493// hi is the last file number (inclusive)
1494//
1495Function V_fPatchDetectorDeadtime(lo,hi,detStr,deadtimeW)
1496        Variable lo,hi
1497        String detStr
1498        Wave deadtimeW
1499       
1500        Variable ii
1501        String fname
1502       
1503        // check the dimensions of the deadtimeW/N=48
1504        if (DimSize(deadtimeW, 0) != 48 )
1505                Abort "dead time wave is not of proper dimension (48)"
1506        endif
1507       
1508        //loop over all files
1509        for(ii=lo;ii<=hi;ii+=1)
1510                fname = V_FindFileFromRunNumber(ii)
1511                if(strlen(fname) != 0)
1512                        V_writeDetector_deadtime(fname,detStr,deadtimeW)                       
1513                else
1514                        printf "run number %d not found\r",ii
1515                endif
1516        endfor
1517       
1518        return(0)
1519End
1520
1521// simple utility to read the detector deadtime stored in the file header
1522Function V_fReadDetectorDeadtime(lo,hi,detStr)
1523        Variable lo,hi
1524        String detStr
1525       
1526        String fname
1527        Variable ii
1528       
1529        for(ii=lo;ii<=hi;ii+=1)
1530                fname = V_FindFileFromRunNumber(ii)
1531                if(strlen(fname) != 0)
1532                        Wave deadtimeW = V_getDetector_deadtime(fname,detStr)
1533                        Duplicate/O deadTimeW root:Packages:NIST:VSANS:Globals:Patch:deadtimeWave
1534//                      printf "File %d:  Detector Dead time (s) = %g\r",ii,deadtime
1535                else
1536                        printf "run number %d not found\r",ii
1537                endif
1538        endfor
1539       
1540        return(0)
1541End
1542
1543
1544
1545Proc V_PatchDetectorDeadtimePanel()
1546        DoWindow/F DeadtimePanel
1547        if(V_flag==0)
1548       
1549                NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Patch
1550
1551                Make/O/D/N=48 deadTimeWave
1552               
1553                SetDataFolder root:
1554               
1555                Execute "V_DeadtimePatchPanel()"
1556        endif
1557End
1558
1559
1560// TODO:
1561// x- add method for generating "perfect" dead time to write
1562// x- check deadtime wave dimension before writing (check for bad paste operation)
1563// -- load from file? different ways to import?
1564// -- Dead time constants for "B" are different, and not handled here (yet)
1565// -- add help button/file
1566// -- add done button
1567// -- adjust after user testing
1568//
1569Proc V_DeadtimePatchPanel() : Panel
1570        PauseUpdate; Silent 1           // building window...
1571
1572
1573        NewPanel /W=(600,400,1000,1000)/N=DeadtimePanel /K=1
1574//      ShowTools/A
1575        ModifyPanel cbRGB=(16266,47753,2552,23355)
1576
1577        SetDrawLayer UserBack
1578        DrawText 85,99,"Current Values"
1579        DrawText 21,258,"Write to all files (inlcusive)"
1580        SetDrawEnv fsize= 14,fstyle= 1
1581        DrawText 209,30,"Dead Time Constants"
1582        DrawText 20,133,"Run Number(s)"
1583       
1584        PopupMenu popup_0,pos={20,40},size={109,20},title="Detector Panel"
1585        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;\""
1586       
1587        Button button0,pos={20,81},size={50.00,20.00},proc=V_ReadDTButtonProc,title="Read"
1588        Button button0_1,pos={20,220},size={50.00,20.00},proc=V_WriteDTButtonProc,title="Write"
1589        Button button0_2,pos={18.00,336.00},size={140.00,20.00},proc=V_GeneratePerfDTButton,title="Perfect Dead Time"
1590       
1591        SetVariable setvar0,pos={20,141},size={100.00,14.00},title="first"
1592        SetVariable setvar0,value= K0
1593        SetVariable setvar1,pos={20.00,167},size={100.00,14.00},title="last"
1594        SetVariable setvar1,value= K1
1595
1596
1597// display the wave     
1598        Edit/W=(180,40,380,550)/HOST=#  root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1599        ModifyTable width(Point)=40
1600        ModifyTable width(root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave)=120
1601        RenameWindow #,T0
1602        SetActiveSubwindow ##
1603
1604       
1605EndMacro
1606
1607
1608
1609Function V_GeneratePerfDTButton(ba) : ButtonControl
1610        STRUCT WMButtonAction &ba
1611
1612        switch( ba.eventCode )
1613                case 2: // mouse up
1614                        // click code here
1615
1616                        WAVE deadTimeWave = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1617                        ControlInfo popup_0
1618                        strswitch(S_Value)
1619                                case "FR":
1620                                case "FL":
1621                                case "MR":
1622                                case "ML":
1623                                case "FT":
1624                                case "FB":
1625                                case "MT":
1626                                case "MB":
1627                                        deadTimeWave = 1e-18
1628
1629                                        break
1630                                default:
1631                                        Print "Det type not found: V_GeneratePerfDTButton()"
1632                        endswitch
1633                       
1634                        break
1635                case -1: // control being killed
1636                        break
1637        endswitch
1638
1639        return 0
1640End
1641
1642
1643
1644
1645Function V_ReadDTButtonProc(ba) : ButtonControl
1646        STRUCT WMButtonAction &ba
1647
1648        switch( ba.eventCode )
1649                case 2: // mouse up
1650                        // click code here
1651                       
1652                        ControlInfo popup_0
1653                        String detStr = S_Value
1654                        ControlInfo setvar0
1655                        Variable lo=V_Value
1656                        Variable hi=lo
1657                       
1658                        V_fReadDetectorDeadtime(lo,hi,detStr)
1659                       
1660                        break
1661                case -1: // control being killed
1662                        break
1663        endswitch
1664
1665        return 0
1666End
1667
1668Function V_WriteDTButtonProc(ba) : ButtonControl
1669        STRUCT WMButtonAction &ba
1670
1671        switch( ba.eventCode )
1672                case 2: // mouse up
1673                        // click code here
1674                       
1675                        ControlInfo popup_0
1676                        String detStr = S_Value
1677                        ControlInfo setvar0
1678                        Variable lo=V_Value
1679                        ControlInfo setvar1
1680                        Variable hi=V_Value
1681                        Wave deadTimeW = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1682                       
1683                        V_fPatchDetectorDeadtime(lo,hi,detStr,deadtimeW)
1684                       
1685                        break
1686                case -1: // control being killed
1687                        break
1688        endswitch
1689
1690        return 0
1691End
1692
1693//////////////////////////////////////////////////////////////////////////////////////////////////
1694//////////////////////////////////////////////////////////////////////////////////////////////////
1695// this is a block to patch CALIBRATION waves to the file headers, and can patch multiple files
1696//
1697// uses a simple panel to show what the table of values is.
1698// "read" will read only the first run number contents.
1699//
1700// TODO -- need to clear out the contents from RawVSANS, or else re-reading to check the values
1701//        will read locally, and it will look like nothing was written. Executing "save" will also
1702//        trigger a cleanout.
1703//
1704// TODO -- link this to a panel somewhere - a button? menu item? will there be a lot more of these little panels?
1705//
1706// TODO -- currently this does not handle the back detector "B". see V_WritePerfectSpatialCalib(filename)
1707//         for how fake data is written to the files
1708//
1709// TODO -- verify that the calibration waves are not transposed
1710//
1711Proc V_PatchDetectorCalibration(firstFile,lastFile,detStr,calibStr)
1712        Variable firstFile=1,lastFile=100
1713        String detStr = "FL",calibStr="calibrationWave"
1714
1715        V_fPatchDetectorCalibration(firstFile,lastFile,detStr,$calibStr)
1716
1717End
1718
1719Proc V_ReadDetectorCalibration(firstFile,lastFile,detStr)
1720        Variable firstFile=1,lastFile=100
1721        String detStr = "FL"
1722       
1723        V_fReadDetectorCalibration(firstFile,lastFile,detStr)
1724End
1725
1726// simple utility to patch the detector calibration wave in the file headers
1727// lo is the first file number
1728// hi is the last file number (inclusive)
1729//
1730Function V_fPatchDetectorCalibration(lo,hi,detStr,calibW)
1731        Variable lo,hi
1732        String detStr
1733        Wave calibW
1734       
1735        Variable ii
1736        String fname
1737       
1738        // check the dimensions of the calibW (3,48)
1739        if (DimSize(calibW, 0) != 3 || DimSize(calibW, 1) != 48 )
1740                Abort "Calibration wave is not of proper dimension (3,48)"
1741        endif
1742       
1743        //loop over all files
1744        for(ii=lo;ii<=hi;ii+=1)
1745                fname = V_FindFileFromRunNumber(ii)
1746                if(strlen(fname) != 0)
1747                        V_writeDetTube_spatialCalib(fname,detStr,calibW)                       
1748                else
1749                        printf "run number %d not found\r",ii
1750                endif
1751        endfor
1752       
1753        return(0)
1754End
1755
1756// simple utility to read the detector deadtime stored in the file header
1757Function V_fReadDetectorCalibration(lo,hi,detStr)
1758        Variable lo,hi
1759        String detStr
1760       
1761        String fname
1762        Variable ii
1763       
1764        for(ii=lo;ii<=hi;ii+=1)
1765                fname = V_FindFileFromRunNumber(ii)
1766                if(strlen(fname) != 0)
1767                        Wave calibW = V_getDetTube_spatialCalib(fname,detStr)
1768                        Duplicate/O calibW root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
1769                else
1770                        printf "run number %d not found\r",ii
1771                endif
1772        endfor
1773       
1774        return(0)
1775End
1776
1777
1778Proc V_PatchDetectorCalibrationPanel()
1779        DoWindow/F CalibrationPanel
1780        if(V_flag==0)
1781       
1782                NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Patch
1783
1784                Make/O/D/N=(3,48) calibrationWave
1785               
1786                SetDataFolder root:
1787               
1788                Execute "V_CalibrationPatchPanel()"
1789        endif
1790End
1791
1792
1793//
1794// TODO:
1795// x- add method for generating "perfect" calibration to write
1796// x- check Nx3 dimension before writing (check for bad paste operation)
1797// -- load from file? different ways to import?
1798// -- calibration constants for "B" are different, and not handled here (yet)
1799// -- add help button/file
1800// -- add done button
1801// -- adjust after user testing
1802//
1803Proc V_CalibrationPatchPanel() : Panel
1804        PauseUpdate; Silent 1           // building window...
1805
1806
1807        NewPanel /W=(600,400,1200,1000)/N=CalibrationPanel /K=1
1808//      ShowTools/A
1809        ModifyPanel cbRGB=(16266,47753,2552,23355)
1810
1811        SetDrawLayer UserBack
1812        DrawText 85,99,"Current Values"
1813        DrawText 21,258,"Write to all files (inlcusive)"
1814        SetDrawEnv fsize= 14,fstyle= 1
1815        DrawText 227,28,"Quadratic Calibration Constants per Tube"
1816        DrawText 20,133,"Run Number(s)"
1817               
1818        PopupMenu popup_0,pos={20,40},size={109,20},title="Detector Panel"
1819        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;\""
1820       
1821        Button button0,pos={20,81},size={50.00,20.00},proc=V_ReadCalibButtonProc,title="Read"
1822        Button button0_1,pos={20,220},size={50.00,20.00},proc=V_WriteCalibButtonProc,title="Write"
1823        Button button0_2,pos={18.00,336.00},size={140.00,20.00},proc=V_GeneratePerfCalibButton,title="Perfect Calibration"
1824               
1825        SetVariable setvar0,pos={20,141},size={100.00,14.00},title="first"
1826        SetVariable setvar0,value= K0
1827        SetVariable setvar1,pos={20.00,167},size={100.00,14.00},title="last"
1828        SetVariable setvar1,value= K1
1829
1830
1831// display the wave     
1832        Edit/W=(180,40,580,550)/HOST=#  root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
1833        ModifyTable width(Point)=40
1834        ModifyTable width(root:Packages:NIST:VSANS:Globals:Patch:calibrationWave)=110
1835        // the elements() command transposes the view in the table, but does not transpose the wave
1836        ModifyTable elements(root:Packages:NIST:VSANS:Globals:Patch:calibrationWave) = (-3, -2)
1837        RenameWindow #,T0
1838        SetActiveSubwindow ##
1839
1840       
1841EndMacro
1842
1843
1844
1845//      // and for the back detector "B"
1846//      Make/O/D/N=3 tmpCalib
1847//      tmpCalib[0] = 1
1848//      tmpCalib[1] = 1
1849//      tmpcalib[2] = 10000
1850//      V_writeDet_cal_x(filename,"B",tmpCalib)
1851//      V_writeDet_cal_y(filename,"B",tmpCalib)
1852//
1853Function V_GeneratePerfCalibButton(ba) : ButtonControl
1854        STRUCT WMButtonAction &ba
1855
1856        switch( ba.eventCode )
1857                case 2: // mouse up
1858                        // click code here
1859
1860                        WAVE calibrationWave = root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
1861                        ControlInfo popup_0
1862                        strswitch(S_Value)
1863                                case "FR":
1864                                case "FL":
1865                                case "MR":
1866                                case "ML":
1867                                        //      // for the "tall" L/R banks
1868                                        calibrationWave[0][] = -512
1869                                        calibrationWave[1][] = 8
1870                                        calibrationWave[2][] = 0
1871                                        break
1872                                case "FT":
1873                                case "FB":
1874                                case "MT":
1875                                case "MB":
1876                                        //      // for the "short" T/B banks
1877                                        calibrationWave[0][] = -256
1878                                        calibrationWave[1][] = 4
1879                                        calibrationWave[2][] = 0
1880
1881                                        break
1882                                default:
1883                                        Print "Det type not found: V_GeneratePerfCalibButton()"
1884                        endswitch
1885
1886
1887                       
1888                        break
1889                case -1: // control being killed
1890                        break
1891        endswitch
1892
1893        return 0
1894End
1895
1896
1897Function V_ReadCalibButtonProc(ba) : ButtonControl
1898        STRUCT WMButtonAction &ba
1899
1900        switch( ba.eventCode )
1901                case 2: // mouse up
1902                        // click code here
1903                       
1904                        ControlInfo popup_0
1905                        String detStr = S_Value
1906                        ControlInfo setvar0
1907                        Variable lo=V_Value
1908                        Variable hi=lo
1909                       
1910                        V_fReadDetectorCalibration(lo,hi,detStr)
1911                       
1912                        break
1913                case -1: // control being killed
1914                        break
1915        endswitch
1916
1917        return 0
1918End
1919
1920Function V_WriteCalibButtonProc(ba) : ButtonControl
1921        STRUCT WMButtonAction &ba
1922
1923        switch( ba.eventCode )
1924                case 2: // mouse up
1925                        // click code here
1926                       
1927                        ControlInfo popup_0
1928                        String detStr = S_Value
1929                        ControlInfo setvar0
1930                        Variable lo=V_Value
1931                        ControlInfo setvar1
1932                        Variable hi=V_Value
1933                        Wave calibW = root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
1934                       
1935                        V_fPatchDetectorCalibration(lo,hi,detStr,calibW)
1936                       
1937                        break
1938                case -1: // control being killed
1939                        break
1940        endswitch
1941
1942        return 0
1943End
1944
1945
1946
1947//////////////////////////////////////////////////////////////////////////////////////////////////
1948//////////////////////////////////////////////////////////////////////////////////////////////////
1949
1950
1951
1952////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1953////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1954///////////////
1955//
1956// this is a block to patch beam centers to the file headers
1957// it will patch the headers for all 9 detectors
1958// and can patch multiple files
1959//
1960// uses a simple panel to show what the table of values is.
1961// "read" will read only the first run number contents. this is the "good" set of XY
1962//  that you want to write out to other files.
1963//
1964// TODO -- need to clear out the contents from RawVSANS, or else re-reading to check the values
1965//        will read locally, and it will look like nothing was written. Executing "save" will also
1966//        trigger a cleanout.
1967//
1968// TODO - link this to a panel somewhere - a button? menu item? will there be a lot more of these little panels?
1969//
1970Proc V_PatchDet_xyCenters(firstFile,lastFile)
1971        Variable firstFile=1,lastFile=100
1972
1973        V_fPatchDet_xyCenters(firstFile,lastFile)
1974
1975End
1976
1977Proc V_ReadDet_xyCenters(firstFile,lastFile)
1978        Variable firstFile=1,lastFile=100
1979
1980       
1981        V_fReadDet_xyCenters(firstFile,lastFile)
1982End
1983
1984// simple utility to patch the xy center in the file headers
1985// lo is the first file number
1986// hi is the last file number (inclusive)
1987//
1988Function V_fPatchDet_xyCenters(lo,hi)
1989        Variable lo,hi
1990
1991       
1992        Variable ii,jj
1993        String fname,detStr
1994       
1995        Wave xCtr_pix = root:Packages:NIST:VSANS:Globals:Patch:xCtr_pix
1996        Wave yCtr_pix = root:Packages:NIST:VSANS:Globals:Patch:yCtr_pix
1997        Wave/T panelW = root:Packages:NIST:VSANS:Globals:Patch:panelW
1998       
1999        // check the dimensions of the waves (9)
2000        if (DimSize(xCtr_pix, 0) != 9 || DimSize(yCtr_pix, 0) != 9 || DimSize(panelW, 0) != 9)
2001                Abort "waves are not of proper dimension (9)"
2002        endif
2003       
2004        //loop over all files
2005        for(jj=lo;jj<=hi;jj+=1)
2006                fname = V_FindFileFromRunNumber(jj)
2007                if(strlen(fname) != 0)
2008               
2009                        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
2010                                detStr = panelW[ii]
2011                                V_writeDet_beam_center_x(fname,detStr,xCtr_pix[ii])
2012                                V_writeDet_beam_center_y(fname,detStr,yCtr_pix[ii])             
2013                        endfor 
2014               
2015                else
2016                        printf "run number %d not found\r",ii
2017                endif
2018        endfor
2019       
2020        return(0)
2021End
2022
2023// simple utility to read the detector xy centers stored in the file header
2024Function V_fReadDet_xyCenters(lo,hi)
2025        Variable lo,hi
2026
2027       
2028        String fname,detStr
2029        Variable ii,jj
2030       
2031        Wave xCtr_pix = root:Packages:NIST:VSANS:Globals:Patch:xCtr_pix
2032        Wave yCtr_pix = root:Packages:NIST:VSANS:Globals:Patch:yCtr_pix
2033        Wave/T panelW = root:Packages:NIST:VSANS:Globals:Patch:panelW
2034       
2035        for(jj=lo;jj<=hi;jj+=1)
2036                fname = V_FindFileFromRunNumber(jj)
2037                if(strlen(fname) != 0)
2038               
2039                        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
2040                                detStr = StringFromList(ii, ksDetectorListAll, ";")
2041                                panelW[ii] = detStr
2042                                xCtr_pix[ii] = V_getDet_beam_center_x(fname,detStr)
2043                                yCtr_pix[ii] = V_getDet_beam_center_y(fname,detStr)
2044                        endfor
2045               
2046               
2047                else
2048                        printf "run number %d not found\r",jj
2049                endif
2050               
2051        endfor
2052
2053       
2054        return(0)
2055End
2056
2057
2058
2059Proc V_PatchDet_xyCenters_Panel()
2060        DoWindow/F Patch_XY_Panel
2061        if(V_flag==0)
2062       
2063                NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Patch
2064
2065                Make/O/D/N=9 xCtr_pix,yCtr_pix
2066                Make/O/T/N=9 panelW
2067               
2068                SetDataFolder root:
2069               
2070                Execute "V_Patch_xyCtr_Panel()"
2071        endif
2072End
2073
2074
2075// TODO:
2076// -- add method to read (import) from beam center panel
2077// x- check wave dimensions before writing (check for bad paste operation)
2078// -- load from file? different ways to import?
2079// -- add help button/file
2080// -- add done button
2081// -- adjust after user testing
2082//
2083Proc V_Patch_xyCtr_Panel() : Panel
2084        PauseUpdate; Silent 1           // building window...
2085
2086
2087        NewPanel /W=(600,400,1150,800)/N=Patch_XY_Panel /K=1
2088//      ShowTools/A
2089       
2090        ModifyPanel cbRGB=(16266,47753,2552,23355)
2091
2092        SetDrawLayer UserBack
2093        DrawText 85,99,"Current Values"
2094        DrawText 21,258,"Write to all files (inlcusive)"
2095        SetDrawEnv fsize= 14,fstyle= 1
2096        DrawText 262,30,"Beam Center (pixels)"
2097        DrawText 20,133,"Run Number(s)"
2098       
2099        Button button0,pos={20,81},size={50.00,20.00},proc=V_ReadXYButtonProc,title="Read"
2100        Button button0_1,pos={20,220},size={50.00,20.00},proc=V_WriteXYButtonProc,title="Write"
2101        SetVariable setvar0,pos={20,141},size={100.00,14.00},title="first"
2102        SetVariable setvar0,value= K0
2103        SetVariable setvar1,pos={20.00,167},size={100.00,14.00},title="last"
2104        SetVariable setvar1,value= K1
2105
2106       
2107        SetDataFolder root:Packages:NIST:VSANS:Globals:Patch
2108// display the wave     
2109        Edit/W=(180,40,500,370)/HOST=#  panelW,xCtr_pix,yCtr_pix
2110        ModifyTable width(Point)=0
2111        ModifyTable width(panelW)=80
2112        ModifyTable width(xCtr_pix)=100
2113        ModifyTable width(yCtr_pix)=100
2114        RenameWindow #,T0
2115        SetActiveSubwindow ##
2116
2117        SetDataFolder root:
2118       
2119EndMacro
2120
2121
2122Function V_ReadXYButtonProc(ba) : ButtonControl
2123        STRUCT WMButtonAction &ba
2124
2125        switch( ba.eventCode )
2126                case 2: // mouse up
2127                        // click code here
2128                       
2129//                      ControlInfo popup_0
2130//                      String detStr = S_Value
2131                        ControlInfo setvar0
2132                        Variable lo=V_Value
2133                        Variable hi=lo
2134                       
2135                        V_fReadDet_xyCenters(lo,hi)
2136                       
2137                        break
2138                case -1: // control being killed
2139                        break
2140        endswitch
2141
2142        return 0
2143End
2144
2145Function V_WriteXYButtonProc(ba) : ButtonControl
2146        STRUCT WMButtonAction &ba
2147
2148        switch( ba.eventCode )
2149                case 2: // mouse up
2150                        // click code here
2151                       
2152//                      ControlInfo popup_0
2153//                      String detStr = S_Value
2154                        ControlInfo setvar0
2155                        Variable lo=V_Value
2156                        ControlInfo setvar1
2157                        Variable hi=V_Value
2158//                      Wave deadTimeW = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
2159                       
2160                        V_fPatchDet_xyCenters(lo,hi)
2161                       
2162                        break
2163                case -1: // control being killed
2164                        break
2165        endswitch
2166
2167        return 0
2168End
2169
2170//////////////////////////////////////////////////////////////////////////////////////////////////
2171//////////////////////////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.