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

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

Adjusting testing macros and panels to be listed on the VSANS menu rather than the Macros menu.

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