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

Last change on this file since 1093 was 1093, checked in by srkline, 4 years ago

New dimensions added for the back detector. many functions neede to be updated to accomodate these changes. Beam center is handled in the same way (in cm, not pixels) as other panels even though this panel is like the 2D detectors on SANS.

Still missing is the real values for caibration, pixel size, dead time, etc. that are yet to be measured.

  • Property svn:executable set to *
File size: 74.3 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 = 9
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        listWave[6][1] = "source aperture size (mm)"
477        listWave[6][2] = V_getSourceAp_size(fname)
478       
479        listWave[7][1] = "sample aperture size (internal) (mm)"
480        listWave[7][2] = V_getSampleAp_size(fname)
481
482        listWave[8][1] = "sample aperture diam (external) (cm)"
483        listWave[8][2] = num2str(V_getSampleAp2_size(fname))   
484                               
485        return(0)
486End
487
488
489// fill list boxes based on the tab
490//
491// TODO -- is this all of the fields that I want to edit?
492//
493// DETECTORS
494//
495Function V_FillListBox4(listWave,selWave)
496        Wave/T listWave
497        Wave selWave
498       
499        // trust that I'm getting a valid raw data file name from the popup
500        String fname
501        ControlInfo/W=V_Patch_Panel PatchPopup
502        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
503                Abort "no file selected in popup menu"          //null selection
504        else
505                fname = S_value                         //selection not null
506        Endif
507        //prepend path for read routine
508        PathInfo catPathName
509        fname = S_path + fname
510
511        Variable nRows = 12
512        Redimension/N=(nRows,3) ListWave
513        Redimension/N=(nRows,3) selWave
514        // clear the contents
515        listWave = ""
516        selWave = 0
517        SelWave[][0] = 2^5              // checkboxes
518        SelWave[][2] = 2^1              // 3rd column editable
519       
520        ControlInfo popup_0                     // which detector panel?
521        String detStr = S_value
522       
523        listWave[0][1] = "beam_center_x (cm)"
524        listWave[0][2] = num2str(V_getDet_Beam_center_x(fname,detStr)) 
525
526        listWave[1][1] = "beam_center_y (cm)"
527        listWave[1][2] = num2str(V_getDet_Beam_center_y(fname,detStr)) 
528
529        listWave[2][1] = "distance (nominal) (cm)"
530        listWave[2][2] = num2str(V_getDet_NominalDistance(fname,detStr))       
531
532        listWave[3][1] = "integrated_count"
533        listWave[3][2] = num2str(V_getDet_IntegratedCount(fname,detStr))       
534
535        listWave[4][1] = "pixel_fwhm_x (cm)"
536        listWave[4][2] = num2str(V_getDet_pixel_fwhm_x(fname,detStr))   
537
538        listWave[5][1] = "pixel_fwhm_y (cm)"
539        listWave[5][2] = num2str(V_getDet_pixel_fwhm_y(fname,detStr))   
540
541        listWave[6][1] = "pixel_num_x"
542        listWave[6][2] = num2str(V_getDet_pixel_num_x(fname,detStr))   
543
544        listWave[7][1] = "pixel_num_y"
545        listWave[7][2] = num2str(V_getDet_pixel_num_y(fname,detStr))   
546
547        listWave[8][1] = "setback (cm)"
548        listWave[8][2] = num2str(V_getDet_TBSetback(fname,detStr))     
549
550        if(cmpstr(detStr,"B") == 0 ||cmpstr(detStr,"FR") == 0 || cmpstr(detStr,"FL") == 0 || cmpstr(detStr,"MR") == 0 || cmpstr(detStr,"ML") == 0)
551                listWave[9][1] = "lateral_offset (cm)"                  // "B" detector drops here
552                listWave[9][2] = num2str(V_getDet_LateralOffset(fname,detStr)) 
553        else   
554                listWave[9][1] = "vertical_offset (cm)"
555                listWave[9][2] = num2str(V_getDet_VerticalOffset(fname,detStr))
556        endif   
557
558        listWave[10][1] = "x_pixel_size (mm)"
559        listWave[10][2] = num2str(V_getDet_x_pixel_size(fname,detStr)) 
560
561        listWave[11][1] = "y_pixel_size (mm)"
562        listWave[11][2] = num2str(V_getDet_y_pixel_size(fname,detStr)) 
563
564
565        return(0)
566End
567
568
569// fill list boxes based on the tab
570//
571// TODO -- this all needs to be filled in, once I figure out what is needed
572//
573// PolSANS
574//
575Function V_FillListBox5(listWave,selWave)
576        Wave/T listWave
577        Wave selWave
578       
579        // trust that I'm getting a valid raw data file name from the popup
580        String fname
581        ControlInfo/W=V_Patch_Panel PatchPopup
582        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
583                Abort "no file selected in popup menu"          //null selection
584        else
585                fname = S_value                         //selection not null
586        Endif
587        //prepend path for read routine
588        PathInfo catPathName
589        fname = S_path + fname
590
591        Variable nRows = 3
592        Redimension/N=(nRows,3) ListWave
593        Redimension/N=(nRows,3) selWave
594        // clear the contents
595        listWave = ""
596        selWave = 0
597        SelWave[][0] = 2^5              // checkboxes
598        SelWave[][2] = 2^1              // 3rd column editable
599       
600       
601        listWave[0][1] = "count_time (s)"
602        listWave[0][2] = num2str(V_getCount_time(fname))       
603
604        return(0)
605End
606
607
608// TODO -- determine if I really need this --- I don't
609//  think I really have any reason to respond to events from list box actions
610//  or edits. the final action of patching is done with the button
611//
612Function V_PatchListBoxProc(lba) : ListBoxControl
613        STRUCT WMListboxAction &lba
614
615        Variable row = lba.row
616        Variable col = lba.col
617        WAVE/T/Z listWave = lba.listWave
618        WAVE/Z selWave = lba.selWave
619
620        switch( lba.eventCode )
621                case -1: // control being killed
622                        break
623                case 1: // mouse down
624                        break
625                case 3: // double click
626                        break
627                case 4: // cell selection
628                case 5: // cell selection plus shift key
629                        break
630                case 6: // begin edit
631                        break
632                case 7: // finish edit
633                        break
634                case 13: // checkbox clicked (Igor 6.2 or later)
635                        break
636        endswitch
637
638        return 0
639End
640
641
642
643
644
645
646//button action procedure to select the local path to the folder that
647//contains the vSANS data
648//sets catPathName, updates the path display and the popup of files (in that folder)
649//
650Function V_PickPathButton(PathButton) : ButtonControl
651        String PathButton
652       
653        // call the main procedure to set the data path
654        V_PickPath()
655       
656        //set the global string to the selected pathname
657        //set a local copy of the path for Patch
658        PathInfo/S catPathName
659   String dum = S_path
660        if (V_flag == 0)
661                //path does not exist - no folder selected
662                String/G root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr = "no folder selected"
663        else
664                String/G root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr = dum
665        endif
666       
667        //Update the pathStr variable box
668        ControlUpdate/W=V_Patch_Panel $"PathDisplay"
669       
670        //then update the popup list
671        // (don't update the list - not until someone enters a search critera) -- Jul09
672        //
673       
674        STRUCT WMSetVariableAction sva
675        sva.eventCode = 2       
676        V_SetMatchStrProc(sva)          //this is equivalent to finding everything, typical startup case
677
678        return(0)
679End
680
681//
682//returns a list of valid files (raw data, no version numbers, no averaged files)
683//that is semicolon delimited, and is suitable for display in a popup menu
684//
685Function/S V_xGetValidPatchPopupList()
686
687        //make sure that path exists
688        PathInfo catPathName
689        String path = S_path
690        if (V_flag == 0)
691                Abort "folder path does not exist - use Pick Path button"
692        Endif
693       
694        String newList = ""
695
696        newList = V_GetRawDataFileList()
697
698        //trim list to include only selected files
699        SVAR match = root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr
700        if(strlen(match) == 0)          //if nothing is entered for a match string, return everything, rather than nothing
701                match = "*"
702        endif
703
704        newlist = V_MyMatchList(match,newlist,";")
705       
706        newList = SortList(newList,";",0)
707        Return(newList)
708End
709
710
711
712//
713// TODO:
714// -- test all of the filters to be sure they actually work properly.
715//   Run # filter works
716//   Text filter works
717//
718// -- SDD filter does not apply -- what is a better filter choice?
719// -- can I filter intent? group_id?
720// -- can't just search for "sample" - this returns everything
721//
722//
723//
724//
725//
726//returns a list of valid files (raw data, no version numbers, no averaged files)
727//that is semicolon delimited, and is suitable for display in a popup menu
728//
729// Uses Grep to look through the any text in the file, which includes the sample label
730// can be very slow across the network, as it re-pops the menu on a selection (since some folks don't hit
731// enter when inputing a filter string)
732//
733// - or -
734// a list or range of run numbers
735// - or -
736// a SDD (to within 0.001m)
737// - or -
738// * to get everything
739//
740//      NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
741 // 1== Run # (comma range OK)
742 // 2== Grep the text (SLOW)
743 // 3== filter by SDD (within 0.001 m)
744Function/S V_GetValidPatchPopupList()
745
746        //make sure that path exists
747        PathInfo catPathName
748        String path = S_path
749        if (V_flag == 0)
750                Abort "folder path does not exist - use Pick Path button"
751        Endif
752       
753        String newList = ""
754
755        newList = V_GetRawDataFileList()
756
757        //trim list to include only selected files
758        SVAR match = root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr
759        if(strlen(match) == 0 || cmpstr(match,"*")==0)          //if nothing or "*" entered for a match string, return everything, rather than nothing
760                match = "*"
761        // old way, with simply a wildcard
762                newlist = V_MyMatchList(match,newlist,";")
763                newList = SortList(newList,";",0)
764                return(newList)
765        endif
766       
767        //loop through all of the files as needed
768
769       
770        String list="",item="",fname,runList="",numStr=""
771        Variable ii,num=ItemsInList(newList),val,group_id
772        NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
773       
774        // run number list
775        if(gRadioVal == 1)
776                       
777                list = V_ExpandNumRanges(match)         //now simply comma delimited
778                num=ItemsInList(list,",")
779                for(ii=0;ii<num;ii+=1)
780                        item = StringFromList(ii,list,",")
781                        val=str2num(item)
782
783                        runList += V_GetFileNameFromPathNoSemi(V_FindFileFromRunNumber(val)) + ";"             
784                endfor
785                newlist = runList
786               
787        endif
788       
789        //grep through what text I can find in the VAX binary
790        // Grep Note: the \\b sequences limit matches to a word boundary before and after
791        // "boondoggle", so "boondoggles" and "aboondoggle" won't match.
792        if(gRadioVal == 2)
793                for(ii=0;ii<num;ii+=1)
794                        item=StringFromList(ii, newList , ";")
795//                      Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
796                        Grep/P=catPathName/Q/E=("(?i)"+match) item
797                        if( V_value )   // at least one instance was found
798//                              Print "found ", item,ii
799                                list += item + ";"
800                        endif
801                endfor
802
803                newList = list
804        endif
805       
806        // group_id
807        // replace this with: V_getSample_GroupID(fname)
808        Variable pos
809        String IDStr=""
810        if(gRadioVal == 3)
811                pos = strsearch(match, "*", 0)
812                if(pos == -1)           //no wildcard
813                        val = str2num(match)
814                else
815                        val = str2num(match[0,pos-1])
816                endif
817               
818//              print val
819                for(ii=0;ii<num;ii+=1)
820                        item=StringFromList(ii, newList , ";")
821                        fname = path + item
822                        group_id = V_getSample_GroupID(fname)
823                        if(group_id == val)
824                                list += item + ";"
825                        endif
826       
827                endfor
828               
829                newList = list
830        endif
831
832        newList = SortList(newList,";",0)
833        Return(newList)
834End
835
836
837
838
839// -- no longer refreshes the list - this seems redundant, and can be slow if grepping
840//
841//updates the popup list when the menu is "popped" so the list is
842//always fresh, then automatically displays the header of the popped file
843//value of match string is used in the creation of the list - use * to get
844//all valid files
845//
846Function V_PatchPopMenuProc(PatchPopup,popNum,popStr) : PopupMenuControl
847        String PatchPopup
848        Variable popNum
849        String popStr
850
851       
852//      String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchList = list
853//      ControlUpdate PatchPopup
854        V_ShowHeaderButtonProc("SHButton")
855       
856        return(0)
857End
858
859
860//when text is entered in the match string, the popup list is refined to
861//include only the selected files, useful for trimming a lengthy list, or selecting
862//a range of files to patch
863//only one wildcard (*) is allowed
864//
865//change the contents of gPatchList that is displayed
866//based on selected Path, match str, and
867//further trim list to include only RAW SANS files
868//this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
869Function V_SetMatchStrProc(sva) : SetVariableControl
870        STRUCT WMSetVariableAction &sva
871
872        switch( sva.eventCode )
873                case 1: // mouse up
874                case 2: // Enter key
875                case 8:         // edit end
876                        Variable dval = sva.dval
877                        String sval = sva.sval
878                       
879                        String list = V_GetValidPatchPopupList()
880       
881                        String/G root:Packages:NIST:VSANS:Globals:Patch:gPatchList = list
882                        ControlUpdate PatchPopup
883                        PopupMenu PatchPopup,mode=1
884                       
885                        if(strlen(list) > 0)
886                                V_ShowHeaderButtonProc("SHButton")
887                        endif
888                case 3: // Live update
889
890                        break
891                case -1: // control being killed
892                        break
893        endswitch
894
895        return 0
896End
897
898//displays the header of the selected file (top in the popup) when the button is clicked
899//sort of a redundant button, since the procedure is automatically called (as if it were
900//clicked) when a new file is chosen from the popup
901//
902// TODO - make sure this is tab-aware
903//
904Function V_ShowHeaderButtonProc(SHButton) : ButtonControl
905        String SHButton
906
907        //displays (editable) header information about current file in popup control
908        //putting the values in the SetVariable displays (resetting the global variables)
909       
910        //get the popup string
911        String partialName, tempName
912        Variable ok
913        ControlInfo/W=V_Patch_Panel PatchPopup
914        If(strlen(S_value)==0 || cmpstr(S_Value,"none")==0)
915                //null selection
916                Abort "no file selected in popup menu"
917        else
918                //selection not null
919                partialName = S_value
920                //Print partialName
921        Endif
922        //get a valid file based on this partialName and catPathName
923        tempName = V_FindValidFilename(partialName)
924       
925        //prepend path to tempName for read routine
926        PathInfo catPathName
927        tempName = S_path + tempName
928       
929        //make sure the file is really a RAW data file
930        ok = V_CheckIfRawData(tempName)                 //--- This loads the whole file to read the instrument string
931        if (!ok)
932                Abort "this file is not recognized as a RAW SANS data file"
933        Endif
934       
935        //Print tempName
936       
937        V_ReadHeaderForPatch(tempName)
938       
939        ControlUpdate/A/W=V_Patch_Panel
940       
941        // no matter what tab is selected, show the file label
942        SVAR fileLabel = root:Packages:NIST:VSANS:Globals:Patch:gPatchCurLabel
943        fileLabel = V_getSampleDescription(tempName)
944       
945        return(0)
946End
947
948
949
950//simple function to get the string value from the popup list of filenames
951//returned string is only the text in the popup, a partial name with no path
952//or VAX version number.
953//
954Function/S V_GetPatchPopupString()
955
956        String str=""
957       
958        ControlInfo patchPopup
959        If(cmpstr(S_value,"")==0)
960                //null selection
961                Abort "no file selected in popup menu"
962        else
963                //selection not null
964                str = S_value
965                //Print str
966        Endif
967       
968        Return str
969End
970
971//Changes (writes to disk!) the specified changes to the (single) file selected in the popup
972//reads the checkboxes to determine which (if any) values need to be written
973//
974// This currently makes sure the name is valid,
975// determines the active tab,
976// and dispatches to the correct (numbered) writer
977//
978Function V_ChangeHeaderButtonProc(CHButton) : ButtonControl
979        String CHButton
980
981        String partialName="", tempName = ""
982        Variable ok
983        //get the popup string
984        partialName = V_GetPatchPopupString()
985       
986        //get a valid file based on this partialName and catPathName
987        tempName = V_FindValidFilename(partialName)
988       
989        //prepend path to tempName for read routine
990        PathInfo catPathName
991        tempName = S_path + tempName
992       
993        //make sure the file is really a RAW data file
994        ok = V_CheckIfRawData(tempName)
995        if (!ok)
996                Abort "this file is not recognized as a RAW SANS data file"
997        Endif
998       
999        // which tab is active?
1000        ControlInfo/W=V_Patch_Panel PatchTab
1001       
1002        switch(V_Value) // numeric switch
1003                case 0: // execute if case matches expression
1004                        V_WriteHeaderForPatch_0(tempName)               //control
1005                        break           // exit from switch
1006                case 1:
1007                        V_WriteHeaderForPatch_1(tempName)               //reduction
1008                        break
1009                case 2:
1010                        V_WriteHeaderForPatch_2(tempName)               // sample
1011                        break
1012                case 3:
1013                        V_WriteHeaderForPatch_3(tempName)               // instrument
1014                        break
1015                case 4:
1016                        V_WriteHeaderForPatch_4(tempName)               //detectors
1017                        break
1018                case 5:
1019                        V_WriteHeaderForPatch_5(tempName)               // polSANS
1020                        break
1021                default:                        // optional default expression executed
1022                        Abort "Tab not found - V_ChangeHeaderButtonProc"
1023        endswitch
1024
1025       
1026        //after writing the changes to the file
1027        // clean up, to force a reload from disk
1028        V_CleanupData_w_Progress(0,1)
1029       
1030        return(0)
1031End
1032
1033//     
1034//*****this function actually writes the data to disk*****
1035//
1036// DONE x- re-write a series of these function to mirror the "fill" functions
1037//   specific to each tab
1038//
1039// DONE x- clear out the old data and force a re-load from disk, or the old data
1040//    will be read in from the RawVSANS folder, and it will look like nothing was written
1041//                      (done in the calling function)
1042//
1043// currently, all errors are printed out by the writer, but ignored here
1044//
1045Function V_WriteHeaderForPatch_0(fname)
1046        String fname
1047       
1048        Variable val,err
1049        String textstr
1050               
1051        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1052        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1053
1054        // test bit 4 to see if the checkbox is selected
1055        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1056                val = str2num(listWave[0][2])
1057                err = V_writeCount_time(fname,val)              // count_time
1058        endif
1059
1060        if ((selWave[1][0] & 2^4) != 0)         // "detector_counts"
1061                val = str2num(listWave[1][2])
1062                err = V_writeDetector_counts(fname,val)
1063        endif   
1064       
1065        if ((selWave[2][0] & 2^4) != 0)         //"monitor_counts"
1066                val = str2num(listWave[2][2])
1067                err = V_writeMonitorCount(fname,val)
1068        endif   
1069       
1070
1071
1072
1073        Return(0)
1074End
1075
1076//
1077// tab 1
1078//
1079Function V_WriteHeaderForPatch_1(fname)
1080        String fname
1081
1082        Variable val,err
1083        String str
1084               
1085        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1086        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1087
1088        // test bit 4 to see if the checkbox is selected
1089        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1090                str = listWave[0][2]                    // empty_beam_file_name
1091                err = V_writeEmptyBeamFileName(fname,str)               
1092        endif
1093
1094        if ((selWave[1][0] & 2^4) != 0)         // "background_file_name"
1095                str = listWave[1][2]
1096                err = V_writeBackgroundFileName(fname,str)
1097        endif   
1098       
1099        if ((selWave[2][0] & 2^4) != 0)         //"empty_file_name"
1100                str = listWave[2][2]
1101                err = V_writeEmptyFileName(fname,str)
1102        endif   
1103       
1104        if ((selWave[3][0] & 2^4) != 0)         //"sensitivity_file_name"
1105                str = listWave[3][2]
1106                err = V_writeSensitivityFileName(fname,str)
1107        endif   
1108       
1109        if ((selWave[4][0] & 2^4) != 0)         //"mask_file_name"
1110                str = listWave[4][2]
1111                err = V_writeMaskFileName(fname,str)
1112        endif   
1113       
1114        if ((selWave[5][0] & 2^4) != 0)         //"transmission_file_name"
1115                str = listWave[5][2]
1116                err = V_writeTransmissionFileName(fname,str)
1117        endif   
1118
1119        if ((selWave[6][0] & 2^4) != 0)         //"intent"
1120                str = listWave[6][2]
1121                err = V_writeReductionIntent(fname,str)
1122        endif   
1123       
1124        if ((selWave[7][0] & 2^4) != 0)         //"file_purpose"
1125                str = listWave[7][2]
1126                err = V_writeReduction_purpose(fname,str)
1127        endif           
1128
1129        if ((selWave[8][0] & 2^4) != 0)         //"group_id (sample)"
1130                val = str2num(listWave[8][2])
1131                err = V_writeSample_GroupID(fname,val)
1132        endif   
1133
1134
1135
1136        if ((selWave[9][0] & 2^4) != 0)         //"box coordinates"
1137                str = listWave[9][2]
1138                err = V_writeBoxCoordinates(fname,V_List2NumWave(str,";","inW"))
1139        endif   
1140       
1141
1142       
1143        if ((selWave[10][0] & 2^4) != 0)                //"box_count"
1144                val = str2num(listWave[10][2])
1145                err = V_writeBoxCounts(fname,val)
1146        endif   
1147       
1148        if ((selWave[11][0] & 2^4) != 0)                //"box_count_error"
1149                val = str2num(listWave[11][2])
1150                err = V_writeBoxCountsError(fname,val)
1151        endif   
1152       
1153        if ((selWave[12][0] & 2^4) != 0)                //"whole_trans"
1154                val = str2num(listWave[12][2])
1155                err = V_writeSampleTransWholeDetector(fname,val)
1156        endif   
1157       
1158        if ((selWave[13][0] & 2^4) != 0)                //"whole_trans_error"
1159                val = str2num(listWave[13][2])
1160                err = V_writeSampleTransWholeDetErr(fname,val)
1161        endif   
1162       
1163       
1164               
1165               
1166        return(0)
1167End
1168
1169// SAMPLE
1170Function V_WriteHeaderForPatch_2(fname)
1171        String fname
1172       
1173        Variable val,err
1174        String str
1175               
1176        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1177        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1178
1179        // test bit 4 to see if the checkbox is selected
1180        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1181                str = listWave[0][2]                    // "description"
1182                err = V_writeSampleDescription(fname,str)               
1183        endif
1184
1185        if ((selWave[1][0] & 2^4) != 0)         // "thickness"
1186                val = str2num(listWave[1][2])
1187                err = V_writeSampleThickness(fname,val)
1188        endif   
1189       
1190        if ((selWave[2][0] & 2^4) != 0)         //"transmission"
1191                val = str2num(listWave[2][2])
1192                err = V_writeSampleTransmission(fname,val)
1193        endif   
1194       
1195        if ((selWave[3][0] & 2^4) != 0)         //"transmission_error"
1196                val = str2num(listWave[3][2])
1197                err = V_writeSampleTransError(fname,val)
1198        endif   
1199       
1200        return(0)
1201End
1202
1203// INSTRUMENT
1204Function V_WriteHeaderForPatch_3(fname)
1205        String fname
1206
1207        Variable val,err
1208        String str
1209               
1210        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1211        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1212
1213        // test bit 4 to see if the checkbox is selected
1214        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1215                val = str2num(listWave[0][2])                   // "attenuator_transmission"
1216                err = V_writeAttenuator_transmission(fname,val)         
1217        endif
1218
1219        if ((selWave[1][0] & 2^4) != 0)         // "attenuator_transmission_error"
1220                val = str2num(listWave[1][2])
1221                err = V_writeAttenuator_trans_err(fname,val)
1222        endif   
1223       
1224        if ((selWave[2][0] & 2^4) != 0)         //"monochromator type"
1225                str = listWave[2][2]
1226                err = V_writeMonochromatorType(fname,str)
1227        endif   
1228       
1229        if ((selWave[3][0] & 2^4) != 0)         //"wavelength"
1230                val = str2num(listWave[3][2])
1231                err = V_writeWavelength(fname,val)
1232        endif   
1233
1234        if ((selWave[4][0] & 2^4) != 0)         //"wavelength_spread"
1235                val = str2num(listWave[4][2])
1236                err = V_writeWavelength_spread(fname,val)
1237        endif   
1238       
1239        if ((selWave[5][0] & 2^4) != 0)         //"distance (source aperture)"
1240                val = str2num(listWave[5][2])
1241                err = V_writeSourceAp_distance(fname,val)
1242        endif           
1243
1244        if ((selWave[6][0] & 2^4) != 0)         //"source aperture size (mm)" (a string with units)
1245                str = listWave[6][2]
1246                err = V_writeSourceAp_size(fname,str)
1247        endif           
1248
1249        if ((selWave[7][0] & 2^4) != 0)         //"sample aperture size (internal) (mm)" (a string with units)
1250                str = listWave[7][2]
1251                err = V_writeSampleAp_size(fname,str)
1252        endif   
1253               
1254        if ((selWave[8][0] & 2^4) != 0)         //"sample aperture diam (external) (cm)"
1255                val = str2num(listWave[8][2])
1256                err = V_writeSampleAp2_size(fname,val)
1257        endif           
1258
1259        return(0)
1260End
1261
1262// DETECTOR
1263Function V_WriteHeaderForPatch_4(fname)
1264        String fname
1265
1266        Variable val,err
1267        String str
1268               
1269        Wave/T listWave = root:Packages:NIST:VSANS:Globals:Patch:PP_ListWave
1270        Wave selWave = root:Packages:NIST:VSANS:Globals:Patch:PP_selWave
1271
1272        ControlInfo popup_0
1273        String detStr = S_Value
1274
1275        // test bit 4 to see if the checkbox is selected
1276        if ((selWave[0][0] & 2^4) != 0)         // Test if bit 4 is set
1277                val = str2num(listWave[0][2])                   // "beam_center_x"
1278                err = V_writeDet_beam_center_x(fname,detStr,val)       
1279        endif
1280
1281        if ((selWave[1][0] & 2^4) != 0)         // "beam_center_y"
1282                val = str2num(listWave[1][2])
1283                err = V_writeDet_beam_center_y(fname,detStr,val)
1284        endif   
1285       
1286        if ((selWave[2][0] & 2^4) != 0)         //"distance (nominal)"
1287                val = str2num(listWave[2][2])
1288                err = V_writeDet_distance(fname,detStr,val)
1289        endif   
1290       
1291        if ((selWave[3][0] & 2^4) != 0)         //"integrated_count"
1292                val = str2num(listWave[3][2])
1293                err = V_writeDet_IntegratedCount(fname,detStr,val)
1294        endif   
1295       
1296        if ((selWave[4][0] & 2^4) != 0)         //"pixel_fwhm_x"
1297                val = str2num(listWave[4][2])
1298                err = V_writeDet_pixel_fwhm_x(fname,detStr,val)
1299        endif   
1300       
1301        if ((selWave[5][0] & 2^4) != 0)         //"pixel_fwhm_y"
1302                val = str2num(listWave[5][2])
1303                err = V_writeDet_pixel_fwhm_y(fname,detStr,val)
1304        endif   
1305
1306        if ((selWave[6][0] & 2^4) != 0)         //"pixel_num_x"
1307                val = str2num(listWave[6][2])
1308                err = V_writeDet_pixel_num_x(fname,detStr,val)
1309        endif   
1310       
1311        if ((selWave[7][0] & 2^4) != 0)         //"pixel_num_y"
1312                val = str2num(listWave[7][2])
1313                err = V_writeDet_pixel_num_y(fname,detStr,val)
1314        endif           
1315       
1316        if ((selWave[8][0] & 2^4) != 0)         //"setback" -- only for TB detectors
1317                val = str2num(listWave[8][2])
1318                if(cmpstr(detStr,"FT") == 0 || cmpstr(detStr,"FB") == 0 || cmpstr(detStr,"MT") == 0 || cmpstr(detStr,"MB") == 0)
1319                        err = V_writeDet_TBSetback(fname,detStr,val)
1320                endif
1321        endif   
1322
1323        if ((selWave[9][0] & 2^4) != 0)         //"lateral_offset" or "vertical_offset"
1324                val = str2num(listWave[9][2])
1325                if(cmpstr(detStr,"B") == 0 ||cmpstr(detStr,"FR") == 0 || cmpstr(detStr,"FL") == 0 || cmpstr(detStr,"MR") == 0 || cmpstr(detStr,"ML") == 0)
1326                        err = V_writeDet_LateralOffset(fname,detStr,val)
1327                else
1328                        err = V_writeDet_VerticalOffset(fname,detStr,val)
1329                endif
1330        endif   
1331       
1332        if ((selWave[10][0] & 2^4) != 0)                //"x_pixel_size"
1333                val = str2num(listWave[10][2])
1334                err = V_writeDet_x_pixel_size(fname,detStr,val)
1335        endif   
1336       
1337        if ((selWave[11][0] & 2^4) != 0)                //"y_pixel_size"
1338                val = str2num(listWave[11][2])
1339                err = V_writeDet_y_pixel_size(fname,detStr,val)
1340        endif   
1341       
1342
1343
1344       
1345        return(0)
1346End
1347
1348// TODO -- not yet implemented
1349Function V_WriteHeaderForPatch_5(fname)
1350        String fname
1351       
1352        return(0)
1353End
1354
1355
1356// control the display of the radio buttons
1357Function V_MatchCheckProc(name,value)
1358        String name
1359        Variable value
1360       
1361        NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
1362       
1363        strswitch (name)
1364                case "check0":
1365                        gRadioVal= 1
1366                        break
1367                case "check1":
1368                        gRadioVal= 2
1369                        break
1370                case "check2":
1371                        gRadioVal= 3
1372                        break
1373        endswitch
1374        CheckBox check0,value= gRadioVal==1
1375        CheckBox check1,value= gRadioVal==2
1376        CheckBox check2,value= gRadioVal==3
1377        return(0)
1378End
1379
1380//This function will read only the selected values editable in the patch panel
1381//
1382// DONE
1383// x- re-write this to be tab-aware. ShowHeaderForPatch() calls this, but does nothing
1384//    to update the tab content. Figure out which function is in charge, and update the content.
1385//
1386Function V_ReadHeaderForPatch(fname)
1387        String fname
1388       
1389       
1390        // figure out which is the active tab, then let PatchTabProc fill it in
1391        ControlInfo/W=V_Patch_Panel PatchTab
1392        V_PatchTabProc("",V_Value)     
1393       
1394        Return 0
1395End
1396
1397Function V_ShowPatchHelp(ctrlName) : ButtonControl
1398        String ctrlName
1399//      DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[Patch File Headers]"
1400//      if(V_flag !=0)
1401                DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found"
1402//      endif
1403        return(0)
1404End
1405
1406//button action procedure to change the selected information (checked values)
1407//in each file in the popup list. This will change multiple files, and as such,
1408//the user is given a chance to bail out before the whole list of files
1409//is modified
1410//useful for patching a series of runs with the same beamcenters, or transmissions
1411//
1412Function V_ChAllHeadersButtonProc(ctrlName) : ButtonControl
1413        String ctrlName
1414       
1415        String msg
1416        msg = "Do you really want to write all of these values to each data file in the popup list? "
1417        msg += "- clicking NO will leave all files unchanged"
1418        DoAlert 1,msg
1419        If(V_flag == 2)
1420                Abort "no files were changed"
1421        Endif
1422       
1423        //this will change (checked) values in ALL of the headers in the popup list
1424        SVAR list = root:Packages:NIST:VSANS:Globals:Patch:gPatchList
1425        Variable numitems,ii
1426        String partialName="", tempName = ""
1427        Variable ok
1428       
1429        numitems = ItemsInList(list,";")
1430       
1431        if(numitems == 0)
1432                Abort "no items in list for multiple patch"
1433        Endif
1434       
1435        // loop through all of the files
1436        ii=0
1437        do
1438                //get current item in the list
1439                partialName = StringFromList(ii, list, ";")
1440                   
1441                //get a valid file based on this partialName and catPathName
1442                tempName = V_FindValidFilename(partialName)
1443       
1444                //prepend path to tempName for read routine
1445                PathInfo catPathName
1446                tempName = S_path + tempName
1447       
1448                //make sure the file is really a RAW data file
1449                ok = V_CheckIfRawData(tempName)
1450                if (!ok)
1451                   Print "this file is not recognized as a RAW SANS data file = ",tempName
1452                else
1453                   //go write the changes to the file
1454                        // which tab is active?
1455                        ControlInfo/W=V_Patch_Panel PatchTab
1456                       
1457                        switch(V_Value) // numeric switch
1458                                case 0: // execute if case matches expression
1459                                        V_WriteHeaderForPatch_0(tempName)
1460                                        break           // exit from switch
1461                                case 1:
1462                                        V_WriteHeaderForPatch_1(tempName)
1463                                        break
1464                                case 2:
1465                                        V_WriteHeaderForPatch_2(tempName)
1466                                        break
1467                                case 3:
1468                                        V_WriteHeaderForPatch_3(tempName)
1469                                        break
1470                                case 4:
1471                                        V_WriteHeaderForPatch_4(tempName)
1472                                        break
1473                                case 5:
1474                                        V_WriteHeaderForPatch_5(tempName)
1475                                        break
1476                                default:                        // optional default expression executed
1477                                        Abort "Tab not found - V_ChAllHeadersButtonProc"
1478                        endswitch
1479                Endif
1480               
1481                ii+=1
1482        while(ii<numitems)
1483
1484
1485        //after writing the changes to the file
1486        // clean up, to force a reload from disk
1487        V_CleanupData_w_Progress(0,1)
1488
1489        return(0)
1490End
1491
1492
1493//simple action for button to close the panel
1494//
1495// cleans out the RawVSANS folder on closing
1496//
1497Function V_DoneButtonProc(ctrlName) : ButtonControl
1498        String ctrlName
1499
1500        DoWindow/K V_Patch_Panel
1501
1502//      V_CleanOutRawVSANS()
1503// present a progress window
1504        V_CleanupData_w_Progress(0,1)   
1505       
1506        return(0)
1507End
1508
1509
1510
1511////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1512////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1513///////////////
1514//
1515// this is a block to patch DEADTIME waves to the file headers, and can patch multiple files
1516//
1517// uses a simple panel to show what the table of values is.
1518// "read" will read only the first run number contents.
1519//
1520// TODO -- need to clear out the contents from RawVSANS, or else re-reading to check the values
1521//        will read locally, and it will look like nothing was written. Executing "save" will also
1522//        trigger a cleanout.
1523//
1524// TODO -- link this to a panel somewhere - a button? menu item? will there be a lot more of these little panels?
1525//
1526// TODO -- currently, this does not patch the deadtime for the back "B" detector. it is a single
1527//        value, not a wave see V_WritePerfectDeadTime(filename) for how the perfect (fake) values is written.
1528//
1529//
1530Proc V_PatchDetectorDeadtime(firstFile,lastFile,detStr,deadtimeStr)
1531        Variable firstFile=1,lastFile=100
1532        String detStr = "FL",deadtimeStr="deadTimeWave"
1533
1534        V_fPatchDetectorDeadtime(firstFile,lastFile,detStr,$deadtimeStr)
1535
1536End
1537
1538Proc V_ReadDetectorDeadtime(firstFile,lastFile,detStr)
1539        Variable firstFile=1,lastFile=100
1540        String detStr = "FL"
1541       
1542        V_fReadDetectorDeadtime(firstFile,lastFile,detStr)
1543       
1544End
1545
1546// simple utility to patch the detector deadtime in the file headers
1547// lo is the first file number
1548// hi is the last file number (inclusive)
1549//
1550Function V_fPatchDetectorDeadtime(lo,hi,detStr,deadtimeW)
1551        Variable lo,hi
1552        String detStr
1553        Wave deadtimeW
1554       
1555        Variable ii
1556        String fname
1557       
1558        // check the dimensions of the deadtimeW/N=48
1559        if (DimSize(deadtimeW, 0) != 48 )
1560                Abort "dead time wave is not of proper dimension (48)"
1561        endif
1562       
1563        //loop over all files
1564        for(ii=lo;ii<=hi;ii+=1)
1565                fname = V_FindFileFromRunNumber(ii)
1566                if(strlen(fname) != 0)
1567                        V_writeDetector_deadtime(fname,detStr,deadtimeW)                       
1568                else
1569                        printf "run number %d not found\r",ii
1570                endif
1571        endfor
1572       
1573        return(0)
1574End
1575
1576// simple utility to read the detector deadtime stored in the file header
1577Function V_fReadDetectorDeadtime(lo,hi,detStr)
1578        Variable lo,hi
1579        String detStr
1580       
1581        String fname
1582        Variable ii
1583       
1584        for(ii=lo;ii<=hi;ii+=1)
1585                fname = V_FindFileFromRunNumber(ii)
1586                if(strlen(fname) != 0)
1587                        Wave deadtimeW = V_getDetector_deadtime(fname,detStr)
1588                        Duplicate/O deadTimeW root:Packages:NIST:VSANS:Globals:Patch:deadtimeWave
1589//                      printf "File %d:  Detector Dead time (s) = %g\r",ii,deadtime
1590                else
1591                        printf "run number %d not found\r",ii
1592                endif
1593        endfor
1594       
1595        return(0)
1596End
1597
1598
1599
1600Proc V_PatchDetectorDeadtimePanel()
1601        DoWindow/F DeadtimePanel
1602        if(V_flag==0)
1603       
1604                NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Patch
1605
1606                Make/O/D/N=48 deadTimeWave
1607                Variable/G gFileNum_Lo,gFileNum_Hi
1608               
1609                SetDataFolder root:
1610               
1611                Execute "V_DeadtimePatchPanel()"
1612        endif
1613End
1614
1615
1616// TODO:
1617// x- add method for generating "perfect" dead time to write
1618// x- check deadtime wave dimension before writing (check for bad paste operation)
1619// -- load from file? different ways to import?
1620// -- Dead time constants for "B" are different, and not handled here (yet)
1621// -- add help button/file
1622// -- add done button
1623// -- adjust after user testing
1624//
1625Proc V_DeadtimePatchPanel() : Panel
1626        PauseUpdate; Silent 1           // building window...
1627
1628
1629        NewPanel /W=(600,400,1000,1000)/N=DeadtimePanel /K=1
1630//      ShowTools/A
1631        ModifyPanel cbRGB=(16266,47753,2552,23355)
1632
1633        SetDrawLayer UserBack
1634        DrawText 85,99,"Current Values"
1635        DrawText 21,258,"Write to all files (inlcusive)"
1636        SetDrawEnv fsize= 14,fstyle= 1
1637        DrawText 209,30,"Dead Time Constants"
1638        DrawText 20,133,"Run Number(s)"
1639       
1640        PopupMenu popup_0,pos={20,40},size={109,20},title="Detector Panel"
1641        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;\""
1642       
1643        Button button0,pos={20,81},size={50.00,20.00},proc=V_ReadDTButtonProc,title="Read"
1644        Button button0_1,pos={20,220},size={50.00,20.00},proc=V_WriteDTButtonProc,title="Write"
1645        Button button0_2,pos={18.00,336.00},size={140.00,20.00},proc=V_GeneratePerfDTButton,title="Perfect Dead Time"
1646        Button button0_3,pos={18.00,370.00},size={140.00,20.00},proc=V_LoadCSVDTButton,title="Load Dead Time CSV"
1647        Button button0_4,pos={18.00,400.00},size={140.00,20.00},proc=V_WriteCSVDTButton,title="Write Dead Time CSV"
1648       
1649        SetVariable setvar0,pos={20,141},size={100.00,14.00},title="first"
1650        SetVariable setvar0,value= root:Packages:NIST:VSANS:Globals:Patch:gFileNum_Lo
1651        SetVariable setvar1,pos={20.00,167},size={100.00,14.00},title="last"
1652        SetVariable setvar1,value= root:Packages:NIST:VSANS:Globals:Patch:gFileNum_Hi
1653
1654
1655// display the wave     
1656        Edit/W=(180,40,380,550)/HOST=#  root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1657        ModifyTable width(Point)=40
1658        ModifyTable width(root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave)=120
1659        RenameWindow #,T0
1660        SetActiveSubwindow ##
1661
1662       
1663EndMacro
1664
1665
1666Function V_LoadCSVDTButton(ba) : ButtonControl
1667        STRUCT WMButtonAction &ba
1668
1669        switch( ba.eventCode )
1670                case 2: // mouse up
1671                        // click code here
1672
1673                        LoadWave/J/A/D/O/W/E=1/K=0                              //will prompt for the file, auto name
1674                       
1675                        break
1676                case -1: // control being killed
1677                        break
1678        endswitch
1679
1680        return 0
1681End
1682
1683//TODO
1684// -- currently this skips detector "B", since its dead time is not like the tubes
1685// -- fails miserably if the deadtime_** waves don't exist
1686// -- the writing may take a long time. Warn the user.
1687// -- if the data files are not "cleaned up", re-reading will pick up the rawVSANS copy and it
1688//    will look like nothing was written
1689//
1690// writes the entire content of the CSV file (all 8 panels) to each detector entry in each data file
1691// as specified by the run number range
1692//
1693Function V_WriteCSVDTButton(ba) : ButtonControl
1694        STRUCT WMButtonAction &ba
1695
1696        Variable ii
1697        String detStr
1698       
1699        switch( ba.eventCode )
1700                case 2: // mouse up
1701                        // click code here
1702                       
1703//                      ControlInfo popup_0
1704//                      String detStr = S_Value
1705                        ControlInfo setvar0
1706                        Variable lo=V_Value
1707                        ControlInfo setvar1
1708                        Variable hi=V_Value
1709                        Wave deadTimeW = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1710                       
1711                        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
1712                                detStr = StringFromList(ii, ksDetectorListNoB, ";")
1713                                Wave tmpW = $("root:deadtime_"+detStr)
1714                                deadTimeW = tmpW
1715                                V_fPatchDetectorDeadtime(lo,hi,detStr,deadtimeW)
1716                        endfor
1717                       
1718                        break
1719                case -1: // control being killed
1720                        break
1721        endswitch
1722
1723        // TODO
1724        // -- clear out the data folders (from lo to hi?)
1725//
1726// root:Packages:NIST:VSANS:RawVSANS:sans1301:
1727        for(ii=lo;ii<=hi;ii+=1)
1728                KillDataFolder/Z $("root:Packages:NIST:VSANS:RawVSANS:sans"+num2str(ii))
1729        endfor
1730        return 0
1731End
1732
1733
1734Function V_GeneratePerfDTButton(ba) : ButtonControl
1735        STRUCT WMButtonAction &ba
1736
1737        switch( ba.eventCode )
1738                case 2: // mouse up
1739                        // click code here
1740
1741                        WAVE deadTimeWave = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1742                        ControlInfo popup_0
1743                        strswitch(S_Value)
1744                                case "FR":
1745                                case "FL":
1746                                case "MR":
1747                                case "ML":
1748                                case "FT":
1749                                case "FB":
1750                                case "MT":
1751                                case "MB":
1752                                        deadTimeWave = 1e-18
1753
1754                                        break
1755                                default:
1756                                        Print "Det type not found: V_GeneratePerfDTButton()"
1757                        endswitch
1758                       
1759                        break
1760                case -1: // control being killed
1761                        break
1762        endswitch
1763
1764        return 0
1765End
1766
1767
1768
1769
1770Function V_ReadDTButtonProc(ba) : ButtonControl
1771        STRUCT WMButtonAction &ba
1772
1773        switch( ba.eventCode )
1774                case 2: // mouse up
1775                        // click code here
1776                       
1777                        ControlInfo popup_0
1778                        String detStr = S_Value
1779                        ControlInfo setvar0
1780                        Variable lo=V_Value
1781                        Variable hi=lo
1782                       
1783                        V_fReadDetectorDeadtime(lo,hi,detStr)
1784                       
1785                        break
1786                case -1: // control being killed
1787                        break
1788        endswitch
1789
1790        return 0
1791End
1792
1793Function V_WriteDTButtonProc(ba) : ButtonControl
1794        STRUCT WMButtonAction &ba
1795
1796        switch( ba.eventCode )
1797                case 2: // mouse up
1798                        // click code here
1799                       
1800                        ControlInfo popup_0
1801                        String detStr = S_Value
1802                        ControlInfo setvar0
1803                        Variable lo=V_Value
1804                        ControlInfo setvar1
1805                        Variable hi=V_Value
1806                        Wave deadTimeW = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
1807                       
1808                        V_fPatchDetectorDeadtime(lo,hi,detStr,deadtimeW)
1809                       
1810                        break
1811                case -1: // control being killed
1812                        break
1813        endswitch
1814
1815        return 0
1816End
1817
1818//////////////////////////////////////////////////////////////////////////////////////////////////
1819//////////////////////////////////////////////////////////////////////////////////////////////////
1820// this is a block to patch CALIBRATION waves to the file headers, and can patch multiple files
1821//
1822// uses a simple panel to show what the table of values is.
1823// "read" will read only the first run number contents.
1824//
1825// TODO -- need to clear out the contents from RawVSANS, or else re-reading to check the values
1826//        will read locally, and it will look like nothing was written. Executing "save" will also
1827//        trigger a cleanout.
1828//
1829// TODO -- link this to a panel somewhere - a button? menu item? will there be a lot more of these little panels?
1830//
1831// TODO -- currently this does not handle the back detector "B". see V_WritePerfectSpatialCalib(filename)
1832//         for how fake data is written to the files
1833//
1834// TODO -- verify that the calibration waves are not transposed
1835//
1836Proc V_PatchDetectorCalibration(firstFile,lastFile,detStr,calibStr)
1837        Variable firstFile=1,lastFile=100
1838        String detStr = "FL",calibStr="calibrationWave"
1839
1840        V_fPatchDetectorCalibration(firstFile,lastFile,detStr,$calibStr)
1841
1842End
1843
1844Proc V_ReadDetectorCalibration(firstFile,lastFile,detStr)
1845        Variable firstFile=1,lastFile=100
1846        String detStr = "FL"
1847       
1848        V_fReadDetectorCalibration(firstFile,lastFile,detStr)
1849End
1850
1851// simple utility to patch the detector calibration wave in the file headers
1852// lo is the first file number
1853// hi is the last file number (inclusive)
1854//
1855Function V_fPatchDetectorCalibration(lo,hi,detStr,calibW)
1856        Variable lo,hi
1857        String detStr
1858        Wave calibW
1859       
1860        Variable ii
1861        String fname
1862       
1863        // check the dimensions of the calibW (3,48)
1864        if (DimSize(calibW, 0) != 3 || DimSize(calibW, 1) != 48 )
1865                Abort "Calibration wave is not of proper dimension (3,48)"
1866        endif
1867       
1868        //loop over all files
1869        for(ii=lo;ii<=hi;ii+=1)
1870                fname = V_FindFileFromRunNumber(ii)
1871                if(strlen(fname) != 0)
1872                        V_writeDetTube_spatialCalib(fname,detStr,calibW)                       
1873                else
1874                        printf "run number %d not found\r",ii
1875                endif
1876        endfor
1877       
1878        return(0)
1879End
1880
1881// simple utility to read the detector deadtime stored in the file header
1882Function V_fReadDetectorCalibration(lo,hi,detStr)
1883        Variable lo,hi
1884        String detStr
1885       
1886        String fname
1887        Variable ii
1888       
1889        for(ii=lo;ii<=hi;ii+=1)
1890                fname = V_FindFileFromRunNumber(ii)
1891                if(strlen(fname) != 0)
1892                        Wave calibW = V_getDetTube_spatialCalib(fname,detStr)
1893                        Duplicate/O calibW root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
1894                else
1895                        printf "run number %d not found\r",ii
1896                endif
1897        endfor
1898       
1899        return(0)
1900End
1901
1902
1903Proc V_PatchDetectorCalibrationPanel()
1904        DoWindow/F CalibrationPanel
1905        if(V_flag==0)
1906       
1907                NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Patch
1908
1909                Make/O/D/N=(3,48) calibrationWave
1910               
1911                Variable/G gFileNum_Lo,gFileNum_Hi
1912                SetDataFolder root:
1913               
1914                Execute "V_CalibrationPatchPanel()"
1915        endif
1916End
1917
1918
1919//
1920// TODO:
1921// x- add method for generating "perfect" calibration to write
1922// x- check Nx3 dimension before writing (check for bad paste operation)
1923// -- load from file? different ways to import?
1924// -- calibration constants for "B" are different, and not handled here (yet)
1925// -- add help button/file
1926// -- add done button
1927// -- adjust after user testing
1928//
1929Proc V_CalibrationPatchPanel() : Panel
1930        PauseUpdate; Silent 1           // building window...
1931
1932
1933        NewPanel /W=(600,400,1200,1000)/N=CalibrationPanel /K=1
1934//      ShowTools/A
1935        ModifyPanel cbRGB=(16266,47753,2552,23355)
1936
1937        SetDrawLayer UserBack
1938        DrawText 85,99,"Current Values"
1939        DrawText 21,258,"Write to all files (inlcusive)"
1940        SetDrawEnv fsize= 14,fstyle= 1
1941        DrawText 227,28,"Quadratic Calibration Constants per Tube"
1942        DrawText 20,133,"Run Number(s)"
1943               
1944        PopupMenu popup_0,pos={20,40},size={109,20},title="Detector Panel"
1945        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;\""
1946       
1947        Button button0,pos={20,81},size={50.00,20.00},proc=V_ReadCalibButtonProc,title="Read"
1948        Button button0_1,pos={20,220},size={50.00,20.00},proc=V_WriteCalibButtonProc,title="Write"
1949        Button button0_2,pos={18.00,336.00},size={140.00,20.00},proc=V_GeneratePerfCalibButton,title="Perfect Calibration"
1950        Button button0_3,pos={18.00,370.00},size={140.00,20.00},proc=V_LoadCSVCalibButton,title="Load Calibration CSV"
1951        Button button0_4,pos={18.00,400.00},size={140.00,20.00},proc=V_WriteCSVCalibButton,title="Write Calibration CSV"
1952               
1953        SetVariable setvar0,pos={20,141},size={100.00,14.00},title="first"
1954        SetVariable setvar0,value= root:Packages:NIST:VSANS:Globals:Patch:gFileNum_Lo
1955        SetVariable setvar1,pos={20.00,167},size={100.00,14.00},title="last"
1956        SetVariable setvar1,value= root:Packages:NIST:VSANS:Globals:Patch:gFileNum_Hi
1957
1958
1959// display the wave     
1960        Edit/W=(180,40,580,550)/HOST=#  root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
1961        ModifyTable width(Point)=40
1962        ModifyTable width(root:Packages:NIST:VSANS:Globals:Patch:calibrationWave)=110
1963        // the elements() command transposes the view in the table, but does not transpose the wave
1964        ModifyTable elements(root:Packages:NIST:VSANS:Globals:Patch:calibrationWave) = (-3, -2)
1965        RenameWindow #,T0
1966        SetActiveSubwindow ##
1967
1968       
1969EndMacro
1970
1971
1972Function V_LoadCSVCalibButton(ba) : ButtonControl
1973        STRUCT WMButtonAction &ba
1974
1975        switch( ba.eventCode )
1976                case 2: // mouse up
1977                        // click code here
1978
1979                        LoadWave/J/A/D/O/W/E=1/K=0                              //will prompt for the file, auto name
1980                       
1981                        break
1982                case -1: // control being killed
1983                        break
1984        endswitch
1985
1986        return 0
1987End
1988
1989//TODO
1990// -- currently this skips detector "B", since its calibration is not like the tubes
1991// -- fails miserably if the a,b,c_** waves don't exist
1992// -- the writing may take a long time. Warn the user.
1993// -- if the data files are not "cleaned up", re-reading will pick up the rawVSANS copy and it
1994//    will look like nothing was written
1995//
1996// writes the entire content of the CSV file (all 8 panels) to each detector entry in each data file
1997// as specified by the run number range
1998//
1999Function V_WriteCSVCalibButton(ba) : ButtonControl
2000        STRUCT WMButtonAction &ba
2001
2002        Variable ii
2003        String detStr
2004       
2005        switch( ba.eventCode )
2006                case 2: // mouse up
2007                        // click code here
2008                       
2009//                      ControlInfo popup_0
2010//                      String detStr = S_Value
2011                        ControlInfo setvar0
2012                        Variable lo=V_Value
2013                        ControlInfo setvar1
2014                        Variable hi=V_Value
2015                        WAVE calibrationWave = root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
2016                       
2017                        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
2018                                detStr = StringFromList(ii, ksDetectorListNoB, ";")
2019                                Wave tmp_a = $("root:a_"+detStr)
2020                                Wave tmp_b = $("root:b_"+detStr)
2021                                Wave tmp_c = $("root:c_"+detStr)
2022                                calibrationWave[0][] = tmp_a[q]
2023                                calibrationWave[1][] = tmp_b[q]
2024                                calibrationWave[2][] = tmp_c[q]
2025                                V_fPatchDetectorCalibration(lo,hi,detStr,calibrationWave)
2026                        endfor
2027                       
2028                        break
2029                case -1: // control being killed
2030                        break
2031        endswitch
2032
2033        // TODO
2034        // -- clear out the data folders (from lo to hi?)
2035//
2036// root:Packages:NIST:VSANS:RawVSANS:sans1301:
2037        for(ii=lo;ii<=hi;ii+=1)
2038                KillDataFolder/Z $("root:Packages:NIST:VSANS:RawVSANS:sans"+num2str(ii))
2039        endfor
2040        return 0
2041End
2042
2043
2044
2045//      // and for the back detector "B"
2046//      Make/O/D/N=3 tmpCalib
2047//      tmpCalib[0] = 1
2048//      tmpCalib[1] = 1
2049//      tmpcalib[2] = 10000
2050//      V_writeDet_cal_x(filename,"B",tmpCalib)
2051//      V_writeDet_cal_y(filename,"B",tmpCalib)
2052//
2053// "Perfect" values here are from Phil (2/2018)
2054//
2055Function V_GeneratePerfCalibButton(ba) : ButtonControl
2056        STRUCT WMButtonAction &ba
2057
2058        switch( ba.eventCode )
2059                case 2: // mouse up
2060                        // click code here
2061
2062                        WAVE calibrationWave = root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
2063                        ControlInfo popup_0
2064                        strswitch(S_Value)
2065                                case "FR":
2066                                case "FL":
2067                                case "MR":
2068                                case "ML":
2069                                        //      // for the "tall" L/R banks
2070                                        calibrationWave[0][] = -521
2071                                        calibrationWave[1][] = 8.14
2072                                        calibrationWave[2][] = 0
2073                                        break
2074                                case "FT":
2075                                case "FB":
2076                                case "MT":
2077                                case "MB":
2078                                        //      // for the "short" T/B banks
2079                                        calibrationWave[0][] = -266
2080                                        calibrationWave[1][] = 4.16
2081                                        calibrationWave[2][] = 0
2082
2083                                        break
2084                                default:
2085                                        Print "Det type not found: V_GeneratePerfCalibButton()"
2086                        endswitch
2087
2088
2089                       
2090                        break
2091                case -1: // control being killed
2092                        break
2093        endswitch
2094
2095        return 0
2096End
2097
2098
2099Function V_ReadCalibButtonProc(ba) : ButtonControl
2100        STRUCT WMButtonAction &ba
2101
2102        switch( ba.eventCode )
2103                case 2: // mouse up
2104                        // click code here
2105                       
2106                        ControlInfo popup_0
2107                        String detStr = S_Value
2108                        ControlInfo setvar0
2109                        Variable lo=V_Value
2110                        Variable hi=lo
2111                       
2112                        V_fReadDetectorCalibration(lo,hi,detStr)
2113                       
2114                        break
2115                case -1: // control being killed
2116                        break
2117        endswitch
2118
2119        return 0
2120End
2121
2122Function V_WriteCalibButtonProc(ba) : ButtonControl
2123        STRUCT WMButtonAction &ba
2124
2125        switch( ba.eventCode )
2126                case 2: // mouse up
2127                        // click code here
2128                       
2129                        ControlInfo popup_0
2130                        String detStr = S_Value
2131                        ControlInfo setvar0
2132                        Variable lo=V_Value
2133                        ControlInfo setvar1
2134                        Variable hi=V_Value
2135                        Wave calibW = root:Packages:NIST:VSANS:Globals:Patch:calibrationWave
2136                       
2137                        V_fPatchDetectorCalibration(lo,hi,detStr,calibW)
2138                       
2139                        break
2140                case -1: // control being killed
2141                        break
2142        endswitch
2143
2144        return 0
2145End
2146
2147
2148
2149//////////////////////////////////////////////////////////////////////////////////////////////////
2150//////////////////////////////////////////////////////////////////////////////////////////////////
2151
2152
2153
2154////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2155////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2156///////////////
2157//
2158// this is a block to patch beam centers to the file headers
2159// it will patch the headers for all 9 detectors
2160// and can patch multiple files
2161//
2162// uses a simple panel to show what the table of values is.
2163// "read" will read only the first run number contents. this is the "good" set of XY
2164//  that you want to write out to other files.
2165//
2166// TODO -- need to clear out the contents from RawVSANS, or else re-reading to check the values
2167//        will read locally, and it will look like nothing was written. Executing "save" will also
2168//        trigger a cleanout.
2169//
2170// TODO - link this to a panel somewhere - a button? menu item? will there be a lot more of these little panels?
2171//
2172Proc V_PatchDet_xyCenters(firstFile,lastFile)
2173        Variable firstFile=1,lastFile=100
2174
2175        V_fPatchDet_xyCenters(firstFile,lastFile)
2176
2177End
2178
2179Proc V_ReadDet_xyCenters(firstFile,lastFile)
2180        Variable firstFile=1,lastFile=100
2181
2182       
2183        V_fReadDet_xyCenters(firstFile,lastFile)
2184End
2185
2186// simple utility to patch the xy center in the file headers
2187// lo is the first file number
2188// hi is the last file number (inclusive)
2189//
2190Function V_fPatchDet_xyCenters(lo,hi)
2191        Variable lo,hi
2192
2193       
2194        Variable ii,jj
2195        String fname,detStr
2196       
2197        Wave xCtr_cm = root:Packages:NIST:VSANS:Globals:Patch:xCtr_cm
2198        Wave yCtr_cm = root:Packages:NIST:VSANS:Globals:Patch:yCtr_cm
2199        Wave/T panelW = root:Packages:NIST:VSANS:Globals:Patch:panelW
2200       
2201        // check the dimensions of the waves (9)
2202        if (DimSize(xCtr_cm, 0) != 9 || DimSize(yCtr_cm, 0) != 9 || DimSize(panelW, 0) != 9)
2203                Abort "waves are not of proper dimension (9)"
2204        endif
2205       
2206        //loop over all files
2207        for(jj=lo;jj<=hi;jj+=1)
2208                fname = V_FindFileFromRunNumber(jj)
2209                if(strlen(fname) != 0)
2210               
2211                        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
2212                                detStr = panelW[ii]
2213                                V_writeDet_beam_center_x(fname,detStr,xCtr_cm[ii])
2214                                V_writeDet_beam_center_y(fname,detStr,yCtr_cm[ii])             
2215                        endfor 
2216               
2217                else
2218                        printf "run number %d not found\r",jj
2219                endif
2220        endfor
2221       
2222        return(0)
2223End
2224
2225// simple utility to read the detector xy centers stored in the file header
2226Function V_fReadDet_xyCenters(lo,hi)
2227        Variable lo,hi
2228
2229       
2230        String fname,detStr
2231        Variable ii,jj
2232       
2233        Wave xCtr_cm = root:Packages:NIST:VSANS:Globals:Patch:xCtr_cm
2234        Wave yCtr_cm = root:Packages:NIST:VSANS:Globals:Patch:yCtr_cm
2235        Wave/T panelW = root:Packages:NIST:VSANS:Globals:Patch:panelW
2236       
2237        for(jj=lo;jj<=hi;jj+=1)
2238                fname = V_FindFileFromRunNumber(jj)
2239                if(strlen(fname) != 0)
2240               
2241                        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
2242                                detStr = StringFromList(ii, ksDetectorListAll, ";")
2243                                panelW[ii] = detStr
2244                                xCtr_cm[ii] = V_getDet_beam_center_x(fname,detStr)              //these values are in cm, not pixels
2245                                yCtr_cm[ii] = V_getDet_beam_center_y(fname,detStr)
2246                        endfor
2247               
2248               
2249                else
2250                        printf "run number %d not found\r",jj
2251                endif
2252               
2253        endfor
2254
2255       
2256        return(0)
2257End
2258
2259
2260
2261Proc V_PatchDet_xyCenters_Panel()
2262        DoWindow/F Patch_XY_Panel
2263        if(V_flag==0)
2264       
2265                NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Patch
2266
2267                Make/O/D/N=9 xCtr_cm,yCtr_cm
2268                Make/O/T/N=9 panelW
2269               
2270                Variable/G gFileNum_Lo,gFileNum_Hi
2271               
2272                SetDataFolder root:
2273               
2274                Execute "V_Patch_xyCtr_Panel()"
2275        endif
2276End
2277
2278
2279// TODO:
2280// -- add method to read (import) from beam center panel
2281// x- check wave dimensions before writing (check for bad paste operation)
2282// -- load from file? different ways to import?
2283// -- add help button/file
2284// -- add done button
2285// -- adjust after user testing
2286//
2287Proc V_Patch_xyCtr_Panel() : Panel
2288        PauseUpdate; Silent 1           // building window...
2289
2290
2291        NewPanel /W=(600,400,1150,800)/N=Patch_XY_Panel /K=1
2292//      ShowTools/A
2293       
2294        ModifyPanel cbRGB=(16266,47753,2552,23355)
2295
2296        SetDrawLayer UserBack
2297        DrawText 85,99,"Current Values"
2298        DrawText 21,258,"Write to all files (inlcusive)"
2299        SetDrawEnv fsize= 14,fstyle= 1
2300        DrawText 262,30,"Beam Center (cm)"
2301        DrawText 20,133,"Run Number(s)"
2302       
2303        Button button0,pos={20,81},size={50.00,20.00},proc=V_ReadXYButtonProc,title="Read"
2304        Button button0_1,pos={20,220},size={50.00,20.00},proc=V_WriteXYButtonProc,title="Write"
2305        SetVariable setvar0,pos={20,141},size={100.00,14.00},title="first"
2306        SetVariable setvar0,value= root:Packages:NIST:VSANS:Globals:Patch:gFileNum_Lo
2307        SetVariable setvar1,pos={20.00,167},size={100.00,14.00},title="last"
2308        SetVariable setvar1,value= root:Packages:NIST:VSANS:Globals:Patch:gFileNum_Hi
2309
2310       
2311        SetDataFolder root:Packages:NIST:VSANS:Globals:Patch
2312// display the wave     
2313        Edit/W=(180,40,500,370)/HOST=#  panelW,xCtr_cm,yCtr_cm
2314        ModifyTable width(Point)=0
2315        ModifyTable width(panelW)=80
2316        ModifyTable width(xCtr_cm)=100
2317        ModifyTable width(yCtr_cm)=100
2318        RenameWindow #,T0
2319        SetActiveSubwindow ##
2320
2321        SetDataFolder root:
2322       
2323EndMacro
2324
2325
2326Function V_ReadXYButtonProc(ba) : ButtonControl
2327        STRUCT WMButtonAction &ba
2328
2329        switch( ba.eventCode )
2330                case 2: // mouse up
2331                        // click code here
2332                       
2333//                      ControlInfo popup_0
2334//                      String detStr = S_Value
2335                        ControlInfo setvar0
2336                        Variable lo=V_Value
2337                        Variable hi=lo
2338                       
2339                        V_fReadDet_xyCenters(lo,hi)
2340                       
2341                        break
2342                case -1: // control being killed
2343                        break
2344        endswitch
2345
2346        return 0
2347End
2348
2349Function V_WriteXYButtonProc(ba) : ButtonControl
2350        STRUCT WMButtonAction &ba
2351
2352        switch( ba.eventCode )
2353                case 2: // mouse up
2354                        // click code here
2355                       
2356//                      ControlInfo popup_0
2357//                      String detStr = S_Value
2358                        ControlInfo setvar0
2359                        Variable lo=V_Value
2360                        ControlInfo setvar1
2361                        Variable hi=V_Value
2362//                      Wave deadTimeW = root:Packages:NIST:VSANS:Globals:Patch:deadTimeWave
2363                       
2364                        V_fPatchDet_xyCenters(lo,hi)
2365                       
2366                        break
2367                case -1: // control being killed
2368                        break
2369        endswitch
2370
2371        return 0
2372End
2373
2374//////////////////////////////////////////////////////////////////////////////////////////////////
2375//////////////////////////////////////////////////////////////////////////////////////////////////
2376
2377
2378Proc V_PatchDet_Offset(lo,hi)
2379        Variable lo,hi
2380       
2381        V_fPatchDet_Offset(lo,hi)
2382End
2383
2384Proc V_MarkLeftRightFlip_Done(lo,hi)
2385        Variable lo,hi
2386       
2387        V_fWriteFlipState(lo,hi,1)      // value == 1 means flip done
2388End
2389
2390Proc V_MarkLeftRightFlip_Not_Done(lo,hi)
2391        Variable lo,hi
2392       
2393        V_fWriteFlipState(lo,hi,-999999)        // value == -999999 means flip not done
2394End
2395
2396
2397Proc V_Patch_GroupID_catTable()
2398        V_fPatch_GroupID_catTable()
2399end
2400
2401Proc V_Patch_Purpose_catTable()
2402        V_fPatch_Purpose_catTable()
2403end
2404
2405Proc V_Patch_Intent_catTable()
2406        V_fPatch_Intent_catTable()
2407end
2408
2409Proc V_PatchDet_Gap(lo,hi)
2410        Variable lo,hi
2411       
2412        V_fPatchDet_Gap(lo,hi)
2413End
2414
2415Proc V_ReadDet_Gap(lo,hi)
2416        Variable lo,hi
2417       
2418        V_fReadDet_Gap(lo,hi)
2419End
2420
2421Proc V_PatchDet_Distance(lo,hi,dist_f,dist_m,dist_b)
2422        Variable lo,hi,dist_f=400,dist_m=1900,dist_b=2200
2423       
2424        V_fPatchDet_distance(lo,hi,dist_f,dist_m,dist_b)
2425End
2426
2427Proc V_Patch_Back_Detector(lo,hi)
2428        Variable lo,hi
2429       
2430        V_fPatch_BackDetector(lo,hi)
2431End
2432
2433
2434// simple utility to patch the offset values in the file headers
2435//
2436// Swaps only the L/R detector values
2437// lo is the first file number
2438// hi is the last file number (inclusive)
2439//
2440//              V_getLeftRightFlipDone(fname)
2441//
2442//
2443// updated the function to check for the "already done" flag
2444// - if already done, report this and do nothing.
2445// - if not done, do the flip and set the flag
2446//
2447Function V_fPatchDet_Offset(lo,hi)
2448        Variable lo,hi
2449
2450       
2451        Variable ii,jj,flipDone=0
2452        String fname,detStr
2453       
2454        Variable offset_ML,offset_MR,offset_FL,offset_FR
2455
2456       
2457        //loop over all files
2458        for(jj=lo;jj<=hi;jj+=1)
2459                fname = V_FindFileFromRunNumber(jj)
2460                if(strlen(fname) != 0)
2461               
2462                        flipDone = V_getLeftRightFlipDone(fname)
2463                        if(flipDone == 1)
2464                                printf "run number %d already flipped - nothing done\r",jj
2465                        else
2466                                offset_FL = V_getDet_LateralOffset(fname,"FL")
2467                                offset_FR = V_getDet_LateralOffset(fname,"FR")
2468       
2469                                offset_ML = V_getDet_LateralOffset(fname,"ML")
2470                                offset_MR = V_getDet_LateralOffset(fname,"MR")
2471                       
2472                        // swap L/R offset values
2473                                V_WriteDet_LateralOffset(fname,"FL",-offset_FR)
2474                                V_WriteDet_LateralOffset(fname,"FR",-offset_FL)
2475                               
2476                                V_WriteDet_LateralOffset(fname,"ML",-offset_MR)
2477                                V_WriteDet_LateralOffset(fname,"MR",-offset_ML)
2478                       
2479                        // set the flag
2480                                V_writeLeftRightFlipDone(fname,1)               // value == 1 means the flip was done
2481                                Print fname
2482                                Print "swapped FL, FR = ",-offset_FR,-offset_FL
2483                                Print "swapped ML, MR = ",-offset_MR,-offset_ML
2484                       
2485                        endif
2486               
2487                else
2488                        printf "run number %d not found\r",jj
2489                endif
2490               
2491        endfor
2492       
2493        return(0)
2494End
2495
2496//  utility to reset the flip state in the file headers
2497//
2498// lo is the first file number
2499// hi is the last file number (inclusive)
2500//
2501// setting value == 1 means done
2502// setting value == -999999 means not done (mimics a missing /entry)
2503//
2504Function V_fWriteFlipState(lo,hi,val)
2505        Variable lo,hi,val
2506
2507       
2508        Variable ii,jj,flipDone=0
2509        String fname,detStr
2510       
2511        Variable offset_ML,offset_MR,offset_FL,offset_FR
2512
2513        //loop over all files
2514        for(jj=lo;jj<=hi;jj+=1)
2515                fname = V_FindFileFromRunNumber(jj)
2516                if(strlen(fname) != 0)
2517       
2518                // set the flag
2519                        V_writeLeftRightFlipDone(fname,val)             //
2520                        Print fname
2521                        printf "run number %d flag reset to %d\r",jj,val
2522                       
2523                else
2524                        printf "run number %d not found\r",jj
2525                endif
2526               
2527        endfor
2528       
2529        return(0)
2530End
2531
2532
2533
2534// simple utility to read the detector offset stored in the file header
2535Function V_fReadDet_Offset(lo,hi)
2536        Variable lo,hi
2537
2538        String fname,detStr
2539        Variable jj
2540        Variable offset_ML,offset_MR,offset_FL,offset_FR
2541       
2542        for(jj=lo;jj<=hi;jj+=1)
2543                fname = V_FindFileFromRunNumber(jj)
2544                if(strlen(fname) != 0)
2545               
2546                        offset_FL = V_getDet_LateralOffset(fname,"FL")
2547                        offset_FR = V_getDet_LateralOffset(fname,"FR")
2548
2549                        offset_ML = V_getDet_LateralOffset(fname,"ML")
2550                        offset_MR = V_getDet_LateralOffset(fname,"MR")
2551               
2552                        Print fname
2553                        Print "FL, FR = ",offset_FL,offset_FR
2554                        Print "ML, MR = ",offset_ML,offset_MR
2555               
2556               
2557                else
2558                        printf "run number %d not found\r",jj
2559                endif
2560               
2561        endfor
2562
2563       
2564        return(0)
2565End
2566
2567
2568// patches the group_ID, based on whatever is in the catTable
2569//
2570Function V_fPatch_GroupID_catTable()
2571        Variable lo,hi
2572
2573       
2574        Variable ii,jj,num
2575       
2576        Wave id = root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID
2577        Wave/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
2578
2579        num = numpnts(id)       
2580        //loop over all files
2581        for(jj=0;jj<num;jj+=1)
2582                Print "update file ",jj,fileNameW[jj]
2583                V_writeSample_GroupID(fileNameW[jj],id[jj])     
2584        endfor
2585       
2586        return(0)
2587End
2588
2589
2590// patches the Purpose, based on whatever is in the catTable
2591//
2592Function V_fPatch_Purpose_catTable()
2593        Variable lo,hi
2594
2595       
2596        Variable ii,jj,num
2597       
2598        Wave/T purpose = root:Packages:NIST:VSANS:CatVSHeaderInfo:Purpose
2599        Wave/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
2600
2601        num = numpnts(purpose) 
2602        //loop over all files
2603        for(jj=0;jj<num;jj+=1)
2604                Print "update file ",jj,fileNameW[jj]
2605                V_writeReduction_Purpose(fileNameW[jj],purpose[jj])     
2606        endfor
2607       
2608        return(0)
2609End
2610
2611// patches the Intent, based on whatever is in the catTable
2612//
2613Function V_fPatch_Intent_catTable()
2614        Variable lo,hi
2615
2616       
2617        Variable ii,jj,num
2618       
2619        Wave/T intent = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
2620        Wave/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
2621
2622        num = numpnts(intent)   
2623        //loop over all files
2624        for(jj=0;jj<num;jj+=1)
2625                Print "update file ",jj,fileNameW[jj]
2626                V_writeReductionIntent(fileNameW[jj],intent[jj])       
2627        endfor
2628       
2629        return(0)
2630End
2631
2632
2633
2634// simple utility to patch the detector gap values in the file headers
2635//
2636// values are measured values in [mm], not estimated
2637//
2638// lo is the first file number
2639// hi is the last file number (inclusive)
2640//
2641Function V_fPatchDet_Gap(lo,hi)
2642        Variable lo,hi
2643
2644       
2645        Variable ii,jj
2646        String fname,detStr
2647               
2648        //loop over all files
2649        for(jj=lo;jj<=hi;jj+=1)
2650                fname = V_FindFileFromRunNumber(jj)
2651                if(strlen(fname) != 0)
2652               
2653                // write gap values
2654                        V_writeDet_panel_gap(fname,"FL",3.5)
2655                        V_writeDet_panel_gap(fname,"FR",3.5)
2656
2657                        V_writeDet_panel_gap(fname,"FT",3.3)
2658                        V_writeDet_panel_gap(fname,"FB",3.3)
2659
2660                        V_writeDet_panel_gap(fname,"ML",5.9)
2661                        V_writeDet_panel_gap(fname,"MR",5.9)
2662
2663                        V_writeDet_panel_gap(fname,"MT",18.3)
2664                        V_writeDet_panel_gap(fname,"MB",18.3)           
2665               
2666                else
2667                        printf "run number %d not found\r",jj
2668                endif
2669        endfor
2670       
2671        return(0)
2672End
2673
2674// simple utility to read the detector gap values stored in the file header
2675Function V_fReadDet_Gap(lo,hi)
2676        Variable lo,hi
2677
2678        String fname,detStr
2679        Variable jj
2680        Variable gap_FL,gap_FR,gap_FT,gap_FB,gap_ML,gap_MR,gap_MT,gap_MB
2681       
2682        for(jj=lo;jj<=hi;jj+=1)
2683                fname = V_FindFileFromRunNumber(jj)
2684                if(strlen(fname) != 0)
2685               
2686                        gap_FL = V_getDet_panel_gap(fname,"FL")
2687                        gap_FR = V_getDet_panel_gap(fname,"FR")
2688                        gap_FT = V_getDet_panel_gap(fname,"FT")
2689                        gap_FB = V_getDet_panel_gap(fname,"FB")
2690
2691                        gap_ML = V_getDet_panel_gap(fname,"ML")
2692                        gap_MR = V_getDet_panel_gap(fname,"MR")
2693                        gap_MT = V_getDet_panel_gap(fname,"MT")
2694                        gap_MB = V_getDet_panel_gap(fname,"MB")
2695                       
2696                        print fname     
2697                        Print "FL, FR, FT, FB = ",gap_FL,gap_FR,gap_FT,gap_FB
2698                        Print "ML, MR, MT, MB = ",gap_ML,gap_MR,gap_MT,gap_MB
2699               
2700               
2701                else
2702                        printf "run number %d not found\r",jj
2703                endif
2704               
2705        endfor
2706
2707       
2708        return(0)
2709End
2710
2711
2712// simple utility to patch the detector distance values in the file headers
2713//
2714// values are in [cm]
2715//
2716// lo is the first file number
2717// hi is the last file number (inclusive)
2718//
2719Function V_fPatchDet_distance(lo,hi,d_f,d_m,d_b)
2720        Variable lo,hi,d_f,d_m,d_b
2721
2722       
2723        Variable ii,jj
2724        String fname,detStr
2725               
2726        //loop over all files
2727        for(jj=lo;jj<=hi;jj+=1)
2728                fname = V_FindFileFromRunNumber(jj)
2729                if(strlen(fname) != 0)
2730               
2731                // write gap values
2732                        V_writeDet_distance(fname,"FL",d_f)
2733                        V_writeDet_distance(fname,"FR",d_f)
2734                        V_writeDet_distance(fname,"FT",d_f)
2735                        V_writeDet_distance(fname,"FB",d_f)
2736
2737                        V_writeDet_distance(fname,"ML",d_m)
2738                        V_writeDet_distance(fname,"MR",d_m)
2739                        V_writeDet_distance(fname,"MT",d_m)
2740                        V_writeDet_distance(fname,"MB",d_m)             
2741
2742                        V_writeDet_distance(fname,"B",d_b)             
2743               
2744                else
2745                        printf "run number %d not found\r",jj
2746                endif
2747        endfor
2748       
2749        return(0)
2750End
2751
2752
2753//
2754// simple utility to patch all of the values associated with the back detector
2755//
2756//
2757//
2758//
2759//
2760// lo is the first file number
2761// hi is the last file number (inclusive)
2762//
2763Function V_fPatch_BackDetector(lo,hi)
2764        Variable lo,hi
2765
2766       
2767        Variable ii,jj
2768        String fname,detStr
2769       
2770        detStr = "B"
2771       
2772        Make/O/D/N=3 cal_x,cal_y
2773        cal_x[0] = VCALC_getPixSizeX(detStr)*10                 // pixel size in mm  VCALC_getPixSizeX(detStr) is [cm]
2774        cal_x[1] = 1
2775        cal_x[2] = 10000
2776        cal_y[0] = VCALC_getPixSizeY(detStr)*10                 // pixel size in mm  VCALC_getPixSizeX(detStr) is [cm]
2777        cal_y[1] = 1
2778        cal_y[2] = 10000
2779       
2780        Make/O/I/N=(680,1656) tmpData=1
2781       
2782        //loop over all files
2783        for(jj=lo;jj<=hi;jj+=1)
2784                fname = V_FindFileFromRunNumber(jj)
2785                if(strlen(fname) != 0)
2786               
2787                // patch cal_x and cal_y
2788                        V_writeDet_cal_x(fname,detStr,cal_x)
2789                        V_writeDet_cal_y(fname,detStr,cal_y)
2790               
2791                // patch n_pix_x and y
2792                        V_writeDet_pixel_num_x(fname,detStr,680)
2793                        V_writeDet_pixel_num_y(fname,detStr,1656)
2794                       
2795                // patch pixel size x and y [cm]
2796                        V_writeDet_x_pixel_size(fname,detStr,0.034)
2797                        V_writeDet_y_pixel_size(fname,detStr,0.034)
2798                       
2799                // patch dead time
2800                // TODO: enter a proper value here once it's actually measured
2801                        V_writeDetector_deadtime_B(fname,detStr,1e-20)
2802               
2803                // patch fwhm_x and y
2804                // TODO: verify the values once they are measured, and also the UNITS!!! [cm]???
2805                        V_writeDet_pixel_fwhm_x(fname,detStr,0.034)
2806                        V_writeDet_pixel_fwhm_y(fname,detStr,0.034)
2807               
2808                // patch beam center (nominal x,y) [cm] values
2809                        V_writeDet_beam_center_x(fname,detStr,11)
2810                        V_writeDet_beam_center_y(fname,detStr,25)
2811               
2812                // fake data
2813                        V_writeDetectorData(fname,detStr,tmpData)
2814                       
2815                       
2816                else
2817                        printf "run number %d not found\r",jj
2818                endif
2819        endfor
2820       
2821        KillWaves/Z cal_x,cal_y,tmpData
2822        return(0)
2823End
Note: See TracBrowser for help on using the repository browser.