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

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

cleanup of TODO items in code, no noteworthy changes

prepare a test release package for the January startup of VSANS, not a general release (since no changes to SANS or USANS)

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