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

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

Added procedures to read in and patch calibration and dead time for all (8) or (9) deteector panels from the CSV files - the same ones that are to be supplied to NICE for direct writing to the data files. Faster than one detetctor panel at a time.

Fixed bug in display of q-values on data display panel where the wavelength was being read incorrectly.

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