source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/PatchFiles.ipf @ 83

Last change on this file since 83 was 76, checked in by srkline, 16 years ago

2nd pass of pulling out NCNR calls. Also cleared a lot of deadwood from the code, removing depricated functions that were mostly already commented out.

File size: 29.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
4
5//**************************
6// Vers. 1.2 092101
7//
8//proceures required to allow patching of raw SANS data headers
9//only a limited number of fields are allowble for changes, although the list could
10//be enhanced quite easily, at the expense of a larger, more complex panel
11//information for the Patch Panel is stored in the root:myGlobals:Patch subfolder
12//
13// writes changes directly to the raw data headers as requested
14// * note that if a data file is currently in a work folder, the (real) header on disk
15// will be updated, but the data in the folder will not reflect these changes, unless
16// the data folder is first cleared
17//
18//**************************
19
20//main entry procedure for displaying the Patch Panel
21//
22Proc PatchFiles()
23       
24        DoWindow/F Patch_Panel
25        If(V_flag == 0)
26                InitializePatchPanel()
27                //draw panel
28                Patch_Panel()
29        Endif
30End
31
32//initialization of the panel, creating the necessary data folder and global
33//variables if necessary - simultaneously initialize the globals for the Trans
34//panel at theis time, to make sure they all exist
35//
36Proc InitializePatchPanel()
37        //create the global variables needed to run the Patch Panel
38        //all are kept in root:myGlobals:Patch
39        If( ! (DataFolderExists("root:myGlobals:Patch"))  )
40                //create the data folder and the globals for BOTH the Patch and Trans panels
41                NewDataFolder/O root:myGlobals:Patch
42                CreatePatchGlobals()
43        Endif
44
45End
46
47//the data folder root:myGlobals:Patch must exist
48//
49Proc CreatePatchGlobals()
50        //ok, create the globals
51        String/G root:myGlobals:Patch:gPatchMatchStr = "*"
52        PathInfo catPathName
53        If(V_flag==1)
54                String dum = S_path
55                String/G root:myGlobals:Patch:gCatPathStr = dum
56        else
57                String/G root:myGlobals:Patch:gCatPathStr = "no path selected"
58        endif
59        String/G root:myGlobals:Patch:gPatchList = "none"
60        String/G root:myGlobals:Patch:gPS1 = "no file selected"
61        String/G root:myGlobals:Patch:gPS2 = "no file selected"
62        String/G root:myGlobals:Patch:gPS3 = "no box selected"
63        Variable/G root:myGlobals:Patch:gPV1 =0
64        Variable/G root:myGlobals:Patch:gPV2 = 0
65        Variable/G root:myGlobals:Patch:gPV3 = 0
66        Variable/G root:myGlobals:Patch:gPV4 = 0
67        Variable/G root:myGlobals:Patch:gPV5 = 0
68        Variable/G root:myGlobals:Patch:gPV6 = 0
69        Variable/G root:myGlobals:Patch:gPV7 = 0
70        Variable/G root:myGlobals:Patch:gPV8 = 0
71        Variable/G root:myGlobals:Patch:gPV9 = 0
72        Variable/G root:myGlobals:Patch:gPV10 = 0
73        Variable/G root:myGlobals:Patch:gPV11 = 0
74        Variable/G root:myGlobals:Patch:gPV12 = 0
75        Variable/G root:myGlobals:Patch:gPV13 = 0
76        Variable/G root:myGlobals:Patch:gPV14 = 0
77        Variable/G root:myGlobals:Patch:gPV15 = 0
78        Variable/G root:myGlobals:Patch:gPV16 = 0
79        Variable/G root:myGlobals:Patch:gPV17 = 0
80        Variable/G root:myGlobals:Patch:gPV18 = 0
81        Variable/G root:myGlobals:Patch:gPV19 = 0
82        Variable/G root:myGlobals:Patch:gTransCts = 0
83End
84
85//button action procedure to select the local path to the folder that
86//contains the SANS data
87//sets catPathName, updates the path display and the popup of files (in that folder)
88//
89Function PickPathButton(PathButton) : ButtonControl
90        String PathButton
91       
92        //set the global string to the selected pathname
93        PickPath()
94        //set a local copy of the path for Patch
95        PathInfo/S catPathName
96        String dum = S_path
97        if (V_flag == 0)
98                //path does not exist - no folder selected
99                String/G root:myGlobals:Patch:gCatPathStr = "no folder selected"
100        else
101                String/G root:myGlobals:Patch:gCatPathStr = dum
102        endif
103       
104        //Update the pathStr variable box
105        ControlUpdate/W=Patch_Panel $"PathDisplay"
106       
107        //then update the popup list
108        PatchPopMenuProc("PatchPopup",1,"")
109End
110
111
112//returns a list of valid files (raw data, no version numbers, no averaged files)
113//that is semicolon delimited, and is suitable for display in a popup menu
114//
115Function/S GetValidPatchPopupList()
116
117        //make sure that path exists
118        PathInfo catPathName
119        String path = S_path
120        if (V_flag == 0)
121                Abort "folder path does not exist - use Pick Path button"
122        Endif
123       
124        String newList = ""
125
126        newList = GetRawDataFileList()
127
128        //trim list to include only selected files
129        SVAR match = root:myGlobals:Patch:gPatchMatchStr
130        newlist = MyMatchList(match,newlist,";")
131       
132        newList = SortList(newList,";",0)
133        Return(newList)
134End
135
136
137//updates the popup list when the menu is "popped" so the list is
138//always fresh, then automatically displays the header of the popped file
139//value of match string is used in the creation of the list - use * to get
140//all valid files
141//
142Function PatchPopMenuProc(PatchPopup,popNum,popStr) : PopupMenuControl
143        String PatchPopup
144        Variable popNum
145        String popStr
146
147        //change the contents of gPatchList that is displayed
148        //based on selected Path, match str, and
149        //further trim list to include only RAW SANS files
150        //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
151
152        String list = GetValidPatchPopupList()
153       
154        String/G root:myGlobals:Patch:gPatchList = list
155        ControlUpdate PatchPopup
156        ShowHeaderButtonProc("SHButton")
157End
158
159//when text is entered in the match string, the popup list is refined to
160//include only the selected files, useful for trimming a lengthy list, or selecting
161//a range of files to patch
162//only one wildcard (*) is allowed
163//
164Function SetMatchStrProc(ctrlName,varNum,varStr,varName) : SetVariableControl
165        String ctrlName
166        Variable varNum
167        String varStr
168        String varName
169
170        //change the contents of gPatchList that is displayed
171        //based on selected Path, match str, and
172        //further trim list to include only RAW SANS files
173        //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
174       
175        String list = GetValidPatchPopupList()
176       
177        String/G root:myGlobals:Patch:gPatchList = list
178        ControlUpdate PatchPopup
179       
180End
181
182
183//displays the header of the selected file (top in the popup) when the button is clicked
184//sort of a redundant button, since the procedure is automatically called (as if it were
185//clicked) when a new file is chosen from the popup
186//
187Function ShowHeaderButtonProc(SHButton) : ButtonControl
188        String SHButton
189
190        //displays (editable) header information about current file in popup control
191        //putting the values in the SetVariable displays (resetting the global variables)
192       
193        //get the popup string
194        String partialName, tempName
195        Variable ok
196        ControlInfo patchPopup
197        If(cmpstr(S_value,"")==0)
198                //null selection
199                Abort "no file selected in popup menu"
200        else
201                //selection not null
202                partialName = S_value
203                //Print partialName
204        Endif
205        //get a valid file based on this partialName and catPathName
206        tempName = FindValidFilename(partialName)
207       
208        //prepend path to tempName for read routine
209        PathInfo catPathName
210        tempName = S_path + tempName
211       
212        //make sure the file is really a RAW data file
213        ok = CheckIfRawData(tempName)
214        if (!ok)
215                Abort "this file is not recognized as a RAW SANS data file"
216        Endif
217       
218        //Print tempName
219       
220        ReadHeaderForPatch(tempName)
221       
222        ControlUpdate/A/W=Patch_Panel
223       
224End
225
226//utility function that polls the checkboxes of the editable parameters
227//returns a wave with the yes/no checked state of the boxes
228// 0 = not checked (user does NOT want this header value updated)
229// 1 = checked (YES, change this value in the header)
230//num (input) is a simple check to make sure that the wave is set up properly
231//from the calling routine
232//
233Function GetCheckBoxesState(w,num)
234        Wave w     //on return, this wave contains the current state of the checkboxes
235        Variable num
236       
237        if(num != 20)
238                Abort "wrong number of checkboxes GetCheckBoxesState()"
239        Endif
240        ControlInfo checkPS1
241        w[0] = V_value
242       
243        Variable ii
244        String baseStr="checkPV"
245       
246        ii=1
247        do
248                ControlInfo $(baseStr + num2str(ii))
249                w[ii] = V_Value
250                ii+=1
251        while(ii<num)
252        return(0)
253End
254
255//on return, wt is a TEXT wave with the values in the SetVar boxes
256//will poll the SetVariable controls to get the new values - will get all the values,
257//and let the writing routine decide which ones it will actually use
258//num (input) is a simple check to make sure that the wave is set up properly
259//from the calling routine
260//
261Function GetEditedSetVarBoxes(wt,num)
262        Wave/T wt         
263        Variable num
264       
265        if(num != 20)
266                Abort "wrong number of checkboxes GetEditedSetVarBoxes()"
267        Endif
268        //pass all as a text wave - so only one wave has to be passed (conversion 2x, though)
269        //global is set to the changed value when entered. read others directly from the control
270        //make sure the text label is exactly 60 characters long, to match VAX field length
271        SVAR dum=root:myGlobals:Patch:gPS1
272        String str60="", junk="junk"
273        str60 = PadString(junk,60,0x20)
274        if(strlen(dum) <= 60)
275                if(strlen(dum) == 60)
276                   str60 = dum
277                else
278                   str60 = PadString(dum,60,0x20)
279                Endif
280        else
281                //too long, truncate
282                str60[0,59] = dum[0,59]
283        Endif
284       
285        wt[0] = str60
286       
287        Variable ii
288        String baseStr="PV"
289        ii=1
290        do
291                ControlInfo $(baseStr + num2str(ii))
292                wt[ii] = num2str(V_Value)
293                ii+=1
294        while(ii<num)
295       
296        return(0)       //no error
297End
298
299
300//simple function to get the string value from the popup list of filenames
301//returned string is only the text in the popup, a partial name with no path
302//or VAX version number.
303//
304Function/S GetPatchPopupString()
305
306        String str=""
307       
308        ControlInfo patchPopup
309        If(cmpstr(S_value,"")==0)
310                //null selection
311                Abort "no file selected in popup menu"
312        else
313                //selection not null
314                str = S_value
315                //Print str
316        Endif
317       
318        Return str
319End
320
321//Changes (writes to disk!) the specified changes to the (single) file selected in the popup
322//reads the checkboxes to determine which (if any) values need to be written
323//
324Function ChangeHeaderButtonProc(CHButton) : ButtonControl
325        String CHButton
326
327        //read the (20) checkboxes to determine what changes to make
328        //The order/length of these waves are crucial!, set by nvars     
329        String partialName="", tempName = ""
330        Variable ok,nvars = 20,ii
331       
332        Make/O/N=(nvars) tempChange
333        Wave w=tempchange
334        GetCheckBoxesState(w,nvars)
335        //Print "w[0] = ",w[0]
336       
337       
338        //Get the current values in each of the fields - to pass to Write() as a textwave
339        Make/O/T/N=(nvars) tempValues
340        Wave/T wt=tempValues
341        //initialize textwave
342        ii=0
343        do
344                wt[ii] = ""
345                ii+=1
346        while(ii<nvars)
347        GetEditedSetVarBoxes(wt,nvars)
348       
349        //get the popup string
350        partialName = GetPatchPopupString()
351       
352        //get a valid file based on this partialName and catPathName
353        tempName = FindValidFilename(partialName)
354       
355        //prepend path to tempName for read routine
356        PathInfo catPathName
357        tempName = S_path + tempName
358       
359        //make sure the file is really a RAW data file
360        ok = CheckIfRawData(tempName)
361        if (!ok)
362                Abort "this file is not recognized as a RAW SANS data file"
363        Endif
364       
365        //go write the changes to the file
366        WriteHeaderForPatch(tempName,w,wt)
367       
368        //clean up wave before leaving
369        KillWaves/Z w,wt
370       
371End
372
373//*****this function actually writes the data to disk*****
374//overwrites the specific bytes the the header that are to be changed
375//real values are written out mimicking VAX format, so that can be properly
376//re-read as raw binary VAX files.
377//if any additional fields are to be edited, the exact byte location must be known
378//
379Function WriteHeaderForPatch(fname,change,textVal)
380        String fname
381        Wave change
382        Wave/T textVal
383       
384        Variable refnum,num
385        String textstr
386       
387        //change the sample label ?
388        if(change[0])
389                WriteSamLabelToHeader(fname,textVal[0])
390        Endif
391       
392        //total count time is an integer, handle separately
393        if(change[6])
394                num =str2num(textVal[6])
395                WriteCountTimeToHeader(fname,num)
396        Endif
397       
398        //ReWriteReal() takes care of open/close on its own
399        if(change[1])           //sample transmission
400                num = str2num(textVal[1])
401                WriteTransmissionToHeader(fname,num)
402        Endif
403        if(change[2])           //sample thickness
404                num = str2num(textVal[2])
405                WriteThicknessToHeader(fname,num)
406        Endif
407        if(change[3])           //pixel X
408                num = str2num(textVal[3])
409                WriteBeamCenterXToHeader(fname,num)
410        Endif
411        if(change[4])           // pixel Y
412                num = str2num(textVal[4])
413                WriteBeamCenterYToHeader(fname,num)
414        Endif
415        if(change[5])           //attenuator number
416                num = str2num(textVal[5])
417                WriteAttenNumberToHeader(fname,num)
418        Endif
419        //[6] was the counting time, integer written above
420        if(change[7])    //monitor count
421                num = str2num(textVal[7])
422                WriteMonitorCountToHeader(fname,num)
423        Endif
424        if(change[8])     //total detector count
425                num = str2num(textVal[8])
426                WriteDetectorCountToHeader(fname,num)
427        Endif
428        if(change[9])      //trans det count
429                num = str2num(textVal[9])
430                WriteTransDetCountToHeader(fname,num)
431        Endif
432        if(change[10])      //wavelength
433                num = str2num(textVal[10])
434                WriteWavelengthToHeader(fname,num)
435        Endif
436        ///
437        if(change[11])      //wavelength spread
438                num = str2num(textVal[11])
439                WriteWavelengthDistrToHeader(fname,num)
440        Endif
441        if(change[12])      //temperature
442                num = str2num(textVal[12])
443                WriteTemperatureToHeader(fname,num)
444        Endif
445        if(change[13])      //magnetic field
446                num = str2num(textVal[13])
447                WriteMagnFieldToHeader(fname,num)
448        Endif
449        if(change[14])      //source aperture
450                num = str2num(textVal[14])
451                WriteSourceApDiamToHeader(fname,num)
452        Endif
453        if(change[15])      //sample aperture
454                num = str2num(textVal[15])
455                WriteSampleApDiamToHeader(fname,num)
456        Endif
457        ///
458        if(change[16])      //source-sam dist
459                num = str2num(textVal[16])
460                WriteSrcToSamDistToHeader(fname,num)
461        Endif
462        if(change[17])      //det offset
463                num = str2num(textVal[17])
464                WriteDetectorOffsetToHeader(fname,num)
465        Endif
466        if(change[18])      //beamstop diam
467                num = str2num(textVal[18])
468                WriteBeamStopDiamToHeader(fname,num)
469        Endif
470        if(change[19])     //SDD
471                num = str2num(textVal[19])
472                WriteSDDToHeader(fname,num)
473        Endif
474        Return(0)
475End
476
477//panel recreation macro for the PatchPanel...
478//
479Proc Patch_Panel()
480        PauseUpdate; Silent 1      // building window...
481        NewPanel /W=(519,85,950,608)/K=1 as "Patch Raw SANS Data Files"
482        DoWindow/C Patch_Panel
483        ModifyPanel cbRGB=(1,39321,19939)
484        ModifyPanel fixedSize=1
485        SetDrawLayer UserBack
486        SetDrawEnv fname= "Courier",fstyle= 1
487        DrawText 3,107,"Change?"
488        DrawLine 7,30,422,30
489        DrawLine 7,288,422,288
490        DrawLine 7,199,422,199
491        DrawLine 7,378,422,378
492        DrawLine 7,469,422,469
493        SetVariable PathDisplay,pos={77,7},size={310,13},title="Path"
494        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"}
495        SetVariable PathDisplay,font="Courier",fSize=10
496        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gCatPathStr
497        Button PathButton,pos={2,3},size={70,20},proc=PickPathButton,title="Pick Path"
498        Button PathButton,help={"Select the folder containing the raw SANS data files"}
499        Button helpButton,pos={400,3},size={25,20},proc=ShowPatchHelp,title="?"
500        Button helpButton,help={"Show the help file for patching raw data headers"}
501        PopupMenu PatchPopup,pos={4,40},size={156,19},proc=PatchPopMenuProc,title="File(s) to Patch"
502        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"}
503        PopupMenu PatchPopup,mode=1,popvalue="none",value= #"root:myGlobals:Patch:gPatchList"
504        Button SHButton,pos={324,37},size={100,20},proc=ShowHeaderButtonProc,title="Show Header"
505        Button SHButton,help={"This will display the header of the file indicated in the popup menu."}
506        Button CHButton,pos={314,60},size={110,20},proc=ChangeHeaderButtonProc,title="Change Header"
507        Button CHButton,help={"This will change the checked values (ONLY) in the single file selected in the popup."}
508        SetVariable PMStr,pos={6,65},size={174,13},proc=SetMatchStrProc,title="Match String"
509        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."}
510        SetVariable PMStr,font="Courier",fSize=10
511        SetVariable PMStr,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPatchMatchStr
512        Button ChAllButton,pos={245,84},size={180,20},proc=ChAllHeadersButtonProc,title="Change All Headers in List"
513        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."}
514        Button DoneButton,pos={310,489},size={110,20},proc=DoneButtonProc,title="Done Patching"
515        Button DoneButton,help={"When done Patching files, this will close this control panel."}
516        Button cat_short,pos={9,485},size={100,20},proc=DoCatShort,title="File Catalog"
517        Button cat_short,help={"Use this button to generate a notebook with file header information. Very useful for identifying files."}
518        SetVariable PS1,pos={42,111},size={338,13},proc=SetLabelVarProc,title="label"
519        SetVariable PS1,help={"Current sample label"},font="Courier",fSize=10
520        SetVariable PS1,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPS1
521        SetVariable PV1,pos={42,129},size={340,13},title="Transmission"
522        SetVariable PV1,help={"Current transmission\rvalue"},font="Courier",fSize=10
523        SetVariable PV1,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV1
524        SetVariable PV2,pos={42,147},size={340,13},title="Thickness (cm)"
525        SetVariable PV2,help={"Current sample thickness, in units of centimeters"}
526        SetVariable PV2,font="Courier",fSize=10
527        SetVariable PV2,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV2
528        SetVariable PV3,pos={42,165},size={340,13},title="Beamcenter X"
529        SetVariable PV3,help={"Current X-position of the beamcenter, in pixels"}
530        SetVariable PV3,font="Courier",fSize=10
531        SetVariable PV3,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV3
532        SetVariable PV4,pos={42,183},size={340,13},title="Beamcenter Y"
533        SetVariable PV4,help={"Current Y-position of the beamcenter, in pixels"}
534        SetVariable PV4,font="Courier",fSize=10
535        SetVariable PV4,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV4
536        SetVariable PV5,pos={42,202},size={340,13},title="Attenuator number"
537        SetVariable PV5,help={"attenuator number present during data collection"}
538        SetVariable PV5,font="Courier",fSize=10
539        SetVariable PV5,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV5
540        SetVariable PV6,pos={42,219},size={340,13},title="Counting time (s)",font="Courier",fSize=10
541        SetVariable PV6,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV6
542        SetVariable PV6,help={"total counting time in seconds"}
543        SetVariable PV7,pos={42,237},size={340,13},title="Monitor count",font="Courier",fSize=10
544        SetVariable PV7,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV7
545        SetVariable PV7,help={"total monitor counts"}
546        SetVariable PV8,pos={42,255},size={340,13},title="Detector count",font="Courier",fSize=10
547        SetVariable PV8,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV8
548        SetVariable PV8,help={"total detector counts"}
549        SetVariable PV9,pos={42,273},size={340,13},title="Trans. det. count",font="Courier",fSize=10
550        SetVariable PV9,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV9
551        SetVariable PV9,help={"Transmission\r detector counts"}
552        SetVariable PV10,pos={42,291},size={340,13},title="Wavelength (A)",font="Courier",fSize=10
553        SetVariable PV10,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV10
554        SetVariable PV10,help={"neutron wavelength in angstroms"}
555        SetVariable PV11,pos={42,309},size={340,13},title="Wavelength spread",font="Courier",fSize=10
556        SetVariable PV11,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV11
557        SetVariable PV11,help={"wavelength spread (delta lambda)/lambda"}
558        SetVariable PV12,pos={42,327},size={340,13},title="Temperature (C)",font="Courier",fSize=10
559        SetVariable PV12,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV12
560        SetVariable PV12,help={"Set point temperature in centigrade"}
561        SetVariable PV13,pos={42,345},size={340,13},title="Magnetic field (G)",font="Courier",fSize=10
562        SetVariable PV13,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV13
563        SetVariable PV13,help={"magnetic field strength units?"}
564        SetVariable PV14,pos={42,363},size={340,13},title="Source aperture (mm)",font="Courier",fSize=10
565        SetVariable PV14,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV14
566        SetVariable PV14,help={"source aperture diameter, in millimeters"}
567        SetVariable PV15,pos={42,381},size={340,13},title="Sample aperture (mm)",font="Courier",fSize=10
568        SetVariable PV15,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV15
569        SetVariable PV15,help={"sample aperture diameter, in millimeters"}
570        SetVariable PV16,pos={42,399},size={340,13},title="Source to sample distance (m)",font="Courier",fSize=10
571        SetVariable PV16,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV16
572        SetVariable PV16,help={"Source to sample distance in meters"}
573        SetVariable PV17,pos={42,417},size={340,13},title="Detector offset (cm)",font="Courier",fSize=10
574        SetVariable PV17,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV17
575        SetVariable PV17,help={"Detector offset, in centimeters"}
576        SetVariable PV18,pos={42,435},size={340,13},title="Beamstop diameter (mm)",font="Courier",fSize=10
577        SetVariable PV18,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV18
578        SetVariable PV18,help={"beamstop diamter, in millimeters (1 inch = 25.4mm)"}
579        SetVariable PV19,pos={42,453},size={340,13},title="Sample to detector distance (m)",font="Courier",fSize=10
580        SetVariable PV19,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV19
581        SetVariable PV19,help={"sample to detector distance, in meters"}
582       
583        CheckBox checkPS1,pos={18,108},size={20,20},title=""
584        CheckBox checkPS1,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
585        CheckBox checkPV1,pos={18,126},size={20,20},title=""
586        CheckBox checkPV1,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
587        CheckBox checkPV2,pos={18,144},size={20,20},title=""
588        CheckBox checkPV2,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
589        CheckBox checkPV3,pos={18,162},size={20,20},title=""
590        CheckBox checkPV3,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
591        CheckBox checkPV4,pos={18,180},size={20,20},title=""
592        CheckBox checkPV4,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
593        CheckBox checkPV5,pos={18,198},size={20,20},title=""
594        CheckBox checkPV5,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
595        CheckBox checkPV6,pos={18,216},size={20,20},title=""
596        CheckBox checkPV6,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
597        CheckBox checkPV7,pos={18,234},size={20,20},title="",value=0
598        CheckBox checkPV7,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
599        CheckBox checkPV8,pos={18,252},size={20,20},title="",value=0
600        CheckBox checkPV8,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
601        CheckBox checkPV9,pos={18,270},size={20,20},title="",value=0
602        CheckBox checkPV9,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
603        CheckBox checkPV10,pos={18,288},size={20,20},title="",value=0
604        CheckBox checkPV10,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
605        CheckBox checkPV11,pos={18,306},size={20,20},title="",value=0
606        CheckBox checkPV11,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
607        CheckBox checkPV12,pos={18,324},size={20,20},title="",value=0
608        CheckBox checkPV12,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
609        CheckBox checkPV13,pos={18,342},size={20,20},title="",value=0
610        CheckBox checkPV13,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
611        CheckBox checkPV14,pos={18,360},size={20,20},title="",value=0
612        CheckBox checkPV14,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
613        CheckBox checkPV15,pos={18,378},size={20,20},title="",value=0
614        CheckBox checkPV15,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
615        CheckBox checkPV16,pos={18,396},size={20,20},title="",value=0
616        CheckBox checkPV16,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
617        CheckBox checkPV17,pos={18,414},size={20,20},title="",value=0
618        CheckBox checkPV17,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
619        CheckBox checkPV18,pos={18,432},size={20,20},title="",value=0
620        CheckBox checkPV18,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
621        CheckBox checkPV19,pos={18,450},size={20,20},title="",value=0
622        CheckBox checkPV19,help={"If checked, the entered value will be written to the data file if either of the \"Change..\" buttons is pressed."},value=0
623End
624
625//This function will read only the selected values editable in the patch panel
626//The values read are passed to the panel through the global variables
627//the function WriteHeaderForPatch() MUST mirror this set of reads, or nothing can be updated
628//
629//fname is the full path:name;vers to open the file
630//
631Function ReadHeaderForPatch(fname)
632        String fname
633        //this function is for reading in values to be patched - so don't save any waves
634        //just reset the global variables that are on the patch panel
635       
636        // each "get" is an individual call to GBLoadWave...
637        // test for acceptable speed over a network...
638       
639        //assign to the globals for display in the panel
640        String/G root:myGlobals:Patch:gPS1= getSampleLabel(fname)
641        Variable/G root:myGlobals:Patch:gPV1 = getSampleTrans(fname)
642        Variable/G root:myGlobals:Patch:gPV2 = getSampleThickness(fname)
643        Variable/G root:myGlobals:Patch:gPV3 = getBeamXPos(fname)
644        Variable/G root:myGlobals:Patch:gPV4 = getBeamYPos(fname)
645        Variable/G root:myGlobals:Patch:gPV5 = getAttenNumber(fname)
646        Variable/G root:myGlobals:Patch:gPV6 = getCountTime(fname)
647        Variable/G root:myGlobals:Patch:gPV7 = getMonitorCount(fname)
648        Variable/G root:myGlobals:Patch:gPV8 = getDetCount(fname)
649        Variable/G root:myGlobals:Patch:gPV9 = getTransDetectorCounts(fname)
650        Variable/G root:myGlobals:Patch:gPV10 = getWavelength(fname)
651        Variable/G root:myGlobals:Patch:gPV11 = getWavelengthSpread(fname)
652        Variable/G root:myGlobals:Patch:gPV12 = getTemperature(fname)
653        Variable/G root:myGlobals:Patch:gPV13 = getFieldStrength(fname)
654        Variable/G root:myGlobals:Patch:gPV14 = getSourceApertureDiam(fname)
655        Variable/G root:myGlobals:Patch:gPV15 = getSampleApertureDiam(fname)
656        Variable/G root:myGlobals:Patch:gPV16 = getSourceToSampleDist(fname)
657        Variable/G root:myGlobals:Patch:gPV17 = getDetectorOffset(fname)
658        Variable/G root:myGlobals:Patch:gPV18 = getBSDiameter(fname)
659        Variable/G root:myGlobals:Patch:gPV19 = getSDD(fname)
660       
661        Return 0
662End
663
664Function ShowPatchHelp(ctrlName) : ButtonControl
665        String ctrlName
666        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Patch File Headers]"
667End
668
669//button action procedure to change the selected information (checked values)
670//in each file in the popup list. This will change multiple files, and as such,
671//the user is given a chance to bail out before the whole list of files
672//is modified
673//useful for patching a series of runs with the same beamcenters, or transmissions
674//
675Function ChAllHeadersButtonProc(ctrlName) : ButtonControl
676        String ctrlName
677       
678        String msg
679        msg = "Do you really want to write all of these values to each data file in the popup list? "
680        msg += "- clicking NO will leave all files unchanged"
681        DoAlert 1,msg
682        If(V_flag == 2)
683                Abort "no files were changed"
684        Endif
685       
686        //this will change (checked) values in ALL of the headers in the popup list
687        SVAR list = root:myGlobals:Patch:gPatchList
688        Variable numitems,ii
689        numitems = ItemsInList(list,";")
690       
691        if(numitems == 0)
692                Abort "no items in list for multiple patch"
693        Endif
694       
695        //read the (6) checkboxes to determine what changes to make
696        //The order/length of these waves are crucial!, set by nvars     
697        String partialName="", tempName = ""
698        Variable ok,nvars = 20
699       
700        Make/O/N=(nvars) tempChange
701        Wave w=tempchange
702        GetCheckBoxesState(w,nvars)
703        //Print "w[0] = ",w[0]
704       
705        //Get the current values in each of the fields - to pass to Write() as a textwave
706        Make/O/T/N=(nvars) tempValues
707        Wave/T wt=tempValues
708        //initialize textwave
709        ii=0
710        do
711                wt[ii] = ""
712                ii+=1
713        while(ii<nvars)
714        GetEditedSetVarBoxes(wt,nvars)
715       
716        //loop through all of the files in the list, applying changes as dictated by w and wt waves
717        ii=0
718        do
719                //get current item in the list
720                partialName = StringFromList(ii, list, ";")
721                   
722                //get a valid file based on this partialName and catPathName
723                tempName = FindValidFilename(partialName)
724       
725                //prepend path to tempName for read routine
726                PathInfo catPathName
727                tempName = S_path + tempName
728       
729                //make sure the file is really a RAW data file
730                ok = CheckIfRawData(tempName)
731                if (!ok)
732                   Print "this file is not recognized as a RAW SANS data file = ",tempName
733                else
734                   //go write the changes to the file
735                   WriteHeaderForPatch(tempName,w,wt)
736                Endif
737               
738                ii+=1
739        while(ii<numitems)
740       
741        //clean up wave before leaving
742        KillWaves/Z w,wt
743               
744End
745
746
747//simple action for button to close the panel
748Function DoneButtonProc(ctrlName) : ButtonControl
749        String ctrlName
750       
751        DoWindow/K Patch_Panel
752       
753End
754
755//resets the global string corresponding to the sample label
756//updates when new text is entered
757//
758Function SetLabelVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
759        String ctrlName
760        Variable varNum
761        String varStr
762        String varName
763       
764        //reset the global variable to the entered text so that it can be relayed to the
765        //write() routine. Only the TEXT SetVariable control needs to be handled this way
766       
767        String/G root:myGlobals:Patch:gPS1 = varStr
768
769End
Note: See TracBrowser for help on using the repository browser.