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

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

Final set of first pass changes to reduction code. Next is to throuroughly test before heading to the second pass of non-obvious function calls and documentation of the "required" stubs for a particular file type.

File size: 37.8 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        String list
124        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
125        //trim list to include only selected files
126        SVAR match = root:myGlobals:Patch:gPatchMatchStr
127        list = MyMatchList(match,list,";")
128        //further trim list to include only RAW SANS files
129        //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
130        Variable num = ItemsInList(list,";")
131        Variable ii,isRAW
132        String item="",newList = "",fullName = "",partialName=""
133       
134        //get rid of version numbers first (up to 11)
135        ii=1
136        do
137                item = num2str(ii)
138                list = RemoveFromList(item, list ,";" )
139                ii+=1
140        while(ii<12)
141       
142        //then filter out only the raw data files
143        num = ItemsInList(list,";")        //get the new number of items in the list
144        ii=0
145        do
146                //build valid filename
147                item = StringFromList(ii, list  ,";" )
148                if(strlen(item) != 0)
149                   partialName = FindValidFileName(item)
150                   if(strlen(partialName) != 0)      //non-null return from FindValidFileName()
151                      fullName = path + partialName
152                      //check if RAW, if so, add original item to newList
153                      isRAW = CheckIfRawData(fullName)
154                      if(isRaw)
155                         newList += item + ";"
156                      Endif
157                   Endif
158                Endif
159                ii+=1
160        while(ii<num)      //process all items in list
161
162        newList = SortList(newList,";",0)
163        Return(newList)
164End
165
166
167//updates the popup list when the menu is "popped" so the list is
168//always fresh, then automatically displays the header of the popped file
169//value of match string is used in the creation of the list - use * to get
170//all valid files
171//
172Function PatchPopMenuProc(PatchPopup,popNum,popStr) : PopupMenuControl
173        String PatchPopup
174        Variable popNum
175        String popStr
176
177        //change the contents of gPatchList that is displayed
178        //based on selected Path, match str, and
179        //further trim list to include only RAW SANS files
180        //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
181
182        String list = GetValidPatchPopupList()
183       
184        String/G root:myGlobals:Patch:gPatchList = list
185        ControlUpdate PatchPopup
186        ShowHeaderButtonProc("SHButton")
187End
188
189//when text is entered in the match string, the popup list is refined to
190//include only the selected files, useful for trimming a lengthy list, or selecting
191//a range of files to patch
192//only one wildcard (*) is allowed
193//
194Function SetMatchStrProc(ctrlName,varNum,varStr,varName) : SetVariableControl
195        String ctrlName
196        Variable varNum
197        String varStr
198        String varName
199
200        //change the contents of gPatchList that is displayed
201        //based on selected Path, match str, and
202        //further trim list to include only RAW SANS files
203        //this will exclude version numbers, .AVE, .ABS files, etc. from the popup (which can't be patched)
204       
205        String list = GetValidPatchPopupList()
206       
207        String/G root:myGlobals:Patch:gPatchList = list
208        ControlUpdate PatchPopup
209       
210End
211
212
213//displays the header of the selected file (top in the popup) when the button is clicked
214//sort of a redundant button, since the procedure is automatically called (as if it were
215//clicked) when a new file is chosen from the popup
216//
217Function ShowHeaderButtonProc(SHButton) : ButtonControl
218        String SHButton
219
220        //displays (editable) header information about current file in popup control
221        //putting the values in the SetVariable displays (resetting the global variables)
222       
223        //get the popup string
224        String partialName, tempName
225        Variable ok
226        ControlInfo patchPopup
227        If(cmpstr(S_value,"")==0)
228                //null selection
229                Abort "no file selected in popup menu"
230        else
231                //selection not null
232                partialName = S_value
233                //Print partialName
234        Endif
235        //get a valid file based on this partialName and catPathName
236        tempName = FindValidFilename(partialName)
237       
238        //prepend path to tempName for read routine
239        PathInfo catPathName
240        tempName = S_path + tempName
241       
242        //make sure the file is really a RAW data file
243        ok = CheckIfRawData(tempName)
244        if (!ok)
245                Abort "this file is not recognized as a RAW SANS data file"
246        Endif
247       
248        //Print tempName
249       
250        ReadHeaderForPatch(tempName)
251       
252        ControlUpdate/A/W=Patch_Panel
253       
254End
255
256//utility function that polls the checkboxes of the editable parameters
257//returns a wave with the yes/no checked state of the boxes
258// 0 = not checked (user does NOT want this header value updated)
259// 1 = checked (YES, change this value in the header)
260//num (input) is a simple check to make sure that the wave is set up properly
261//from the calling routine
262//
263Function GetCheckBoxesState(w,num)
264        Wave w     //on return, this wave contains the current state of the checkboxes
265        Variable num
266       
267        if(num != 20)
268                Abort "wrong number of checkboxes GetCheckBoxesState()"
269        Endif
270        ControlInfo checkPS1
271        w[0] = V_value
272       
273        Variable ii
274        String baseStr="checkPV"
275       
276        ii=1
277        do
278                ControlInfo $(baseStr + num2str(ii))
279                w[ii] = V_Value
280                ii+=1
281        while(ii<num)
282        return(0)
283End
284
285//on return, wt is a TEXT wave with the values in the SetVar boxes
286//will poll the SetVariable controls to get the new values - will get all the values,
287//and let the writing routine decide which ones it will actually use
288//num (input) is a simple check to make sure that the wave is set up properly
289//from the calling routine
290//
291Function GetEditedSetVarBoxes(wt,num)
292        Wave/T wt         
293        Variable num
294       
295        if(num != 20)
296                Abort "wrong number of checkboxes GetEditedSetVarBoxes()"
297        Endif
298        //pass all as a text wave - so only one wave has to be passed (conversion 2x, though)
299        //global is set to the changed value when entered. read others directly from the control
300        //make sure the text label is exactly 60 characters long, to match VAX field length
301        SVAR dum=root:myGlobals:Patch:gPS1
302        String str60="", junk="junk"
303        str60 = PadString(junk,60,0x20)
304        if(strlen(dum) <= 60)
305                if(strlen(dum) == 60)
306                   str60 = dum
307                else
308                   str60 = PadString(dum,60,0x20)
309                Endif
310        else
311                //too long, truncate
312                str60[0,59] = dum[0,59]
313        Endif
314       
315        wt[0] = str60
316       
317        Variable ii
318        String baseStr="PV"
319        ii=1
320        do
321                ControlInfo $(baseStr + num2str(ii))
322                wt[ii] = num2str(V_Value)
323                ii+=1
324        while(ii<num)
325       
326        return(0)       //no error
327End
328
329
330//simple function to get the string value from the popup list of filenames
331//returned string is only the text in the popup, a partial name with no path
332//or VAX version number.
333//
334Function/S GetPatchPopupString()
335
336        String str=""
337       
338        ControlInfo patchPopup
339        If(cmpstr(S_value,"")==0)
340                //null selection
341                Abort "no file selected in popup menu"
342        else
343                //selection not null
344                str = S_value
345                //Print str
346        Endif
347       
348        Return str
349End
350
351//Changes (writes to disk!) the specified changes to the (single) file selected in the popup
352//reads the checkboxes to determine which (if any) values need to be written
353//
354Function ChangeHeaderButtonProc(CHButton) : ButtonControl
355        String CHButton
356
357        //read the (20) checkboxes to determine what changes to make
358        //The order/length of these waves are crucial!, set by nvars     
359        String partialName="", tempName = ""
360        Variable ok,nvars = 20,ii
361       
362        Make/O/N=(nvars) tempChange
363        Wave w=tempchange
364        GetCheckBoxesState(w,nvars)
365        //Print "w[0] = ",w[0]
366       
367       
368        //Get the current values in each of the fields - to pass to Write() as a textwave
369        Make/O/T/N=(nvars) tempValues
370        Wave/T wt=tempValues
371        //initialize textwave
372        ii=0
373        do
374                wt[ii] = ""
375                ii+=1
376        while(ii<nvars)
377        GetEditedSetVarBoxes(wt,nvars)
378       
379        //get the popup string
380        partialName = GetPatchPopupString()
381       
382        //get a valid file based on this partialName and catPathName
383        tempName = FindValidFilename(partialName)
384       
385        //prepend path to tempName for read routine
386        PathInfo catPathName
387        tempName = S_path + tempName
388       
389        //make sure the file is really a RAW data file
390        ok = CheckIfRawData(tempName)
391        if (!ok)
392                Abort "this file is not recognized as a RAW SANS data file"
393        Endif
394       
395        //go write the changes to the file
396        WriteHeaderForPatch(tempName,w,wt)
397       
398        //clean up wave before leaving
399        KillWaves/Z w,wt
400       
401End
402
403//*****this function actually writes the data to disk*****
404//overwrites the specific bytes the the header that are to be changed
405//real values are written out mimicking VAX format, so that can be properly
406//re-read as raw binary VAX files.
407//if any additional fields are to be edited, the exact byte location must be known
408//
409Function WriteHeaderForPatch(fname,change,textVal)
410        String fname
411        Wave change
412        Wave/T textVal
413       
414        Variable refnum,num
415        String textstr
416       
417        //change the sample label ?
418        if(change[0])
419                WriteSamLabelToHeader(fname,textVal[0])
420        Endif
421       
422        //total count time is an integer, handle separately
423        if(change[6])
424                num =str2num(textVal[6])
425                WriteCountTimeToHeader(fname,num)
426        Endif
427       
428        //ReWriteReal() takes care of open/close on its own
429        if(change[1])           //sample transmission
430                num = str2num(textVal[1])
431                WriteTransmissionToHeader(fname,num)
432        Endif
433        if(change[2])           //sample thickness
434                num = str2num(textVal[2])
435                WriteThicknessToHeader(fname,num)
436        Endif
437        if(change[3])           //pixel X
438                num = str2num(textVal[3])
439                WriteBeamCenterXToHeader(fname,num)
440        Endif
441        if(change[4])           // pixel Y
442                num = str2num(textVal[4])
443                WriteBeamCenterYToHeader(fname,num)
444        Endif
445        if(change[5])           //attenuator number
446                num = str2num(textVal[5])
447                WriteAttenNumberToHeader(fname,num)
448        Endif
449        //[6] was the counting time, integer written above
450        if(change[7])    //monitor count
451                num = str2num(textVal[7])
452                WriteMonitorCountToHeader(fname,num)
453        Endif
454        if(change[8])     //total detector count
455                num = str2num(textVal[8])
456                WriteDetectorCountToHeader(fname,num)
457        Endif
458        if(change[9])      //trans det count
459                num = str2num(textVal[9])
460                WriteTransDetCountToHeader(fname,num)
461        Endif
462        if(change[10])      //wavelength
463                num = str2num(textVal[10])
464                WriteWavelengthToHeader(fname,num)
465        Endif
466        ///
467        if(change[11])      //wavelength spread
468                num = str2num(textVal[11])
469                WriteWavelengthDistrToHeader(fname,num)
470        Endif
471        if(change[12])      //temperature
472                num = str2num(textVal[12])
473                WriteTemperatureToHeader(fname,num)
474        Endif
475        if(change[13])      //magnetic field
476                num = str2num(textVal[13])
477                WriteMagnFieldToHeader(fname,num)
478        Endif
479        if(change[14])      //source aperture
480                num = str2num(textVal[14])
481                WriteSourceApDiamToHeader(fname,num)
482        Endif
483        if(change[15])      //sample aperture
484                num = str2num(textVal[15])
485                WriteSampleApDiamToHeader(fname,num)
486        Endif
487        ///
488        if(change[16])      //source-sam dist
489                num = str2num(textVal[16])
490                WriteSrcToSamDistToHeader(fname,num)
491        Endif
492        if(change[17])      //det offset
493                num = str2num(textVal[17])
494                WriteDetectorOffsetToHeader(fname,num)
495        Endif
496        if(change[18])      //beamstop diam
497                num = str2num(textVal[18])
498                WriteBeamStopDiamToHeader(fname,num)
499        Endif
500        if(change[19])     //SDD
501                num = str2num(textVal[19])
502                WriteSDDToHeader(fname,num)
503        Endif
504        Return(0)
505End
506
507//panel recreation macro for the PatchPanel...
508//
509Proc Patch_Panel()
510        PauseUpdate; Silent 1      // building window...
511        NewPanel /W=(519,85,950,608)/K=1 as "Patch Raw SANS Data Files"
512        DoWindow/C Patch_Panel
513        ModifyPanel cbRGB=(1,39321,19939)
514        ModifyPanel fixedSize=1
515        SetDrawLayer UserBack
516        SetDrawEnv fname= "Courier",fstyle= 1
517        DrawText 3,107,"Change?"
518        DrawLine 7,30,422,30
519        DrawLine 7,288,422,288
520        DrawLine 7,199,422,199
521        DrawLine 7,378,422,378
522        DrawLine 7,469,422,469
523        SetVariable PathDisplay,pos={77,7},size={310,13},title="Path"
524        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"}
525        SetVariable PathDisplay,font="Courier",fSize=10
526        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gCatPathStr
527        Button PathButton,pos={2,3},size={70,20},proc=PickPathButton,title="Pick Path"
528        Button PathButton,help={"Select the folder containing the raw SANS data files"}
529        Button helpButton,pos={400,3},size={25,20},proc=ShowPatchHelp,title="?"
530        Button helpButton,help={"Show the help file for patching raw data headers"}
531        PopupMenu PatchPopup,pos={4,40},size={156,19},proc=PatchPopMenuProc,title="File(s) to Patch"
532        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"}
533        PopupMenu PatchPopup,mode=1,popvalue="none",value= #"root:myGlobals:Patch:gPatchList"
534        Button SHButton,pos={324,37},size={100,20},proc=ShowHeaderButtonProc,title="Show Header"
535        Button SHButton,help={"This will display the header of the file indicated in the popup menu."}
536        Button CHButton,pos={314,60},size={110,20},proc=ChangeHeaderButtonProc,title="Change Header"
537        Button CHButton,help={"This will change the checked values (ONLY) in the single file selected in the popup."}
538        SetVariable PMStr,pos={6,65},size={174,13},proc=SetMatchStrProc,title="Match String"
539        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."}
540        SetVariable PMStr,font="Courier",fSize=10
541        SetVariable PMStr,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPatchMatchStr
542        Button ChAllButton,pos={245,84},size={180,20},proc=ChAllHeadersButtonProc,title="Change All Headers in List"
543        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."}
544        Button DoneButton,pos={310,489},size={110,20},proc=DoneButtonProc,title="Done Patching"
545        Button DoneButton,help={"When done Patching files, this will close this control panel."}
546        Button cat_short,pos={9,485},size={100,20},proc=DoCatShort,title="File Catalog"
547        Button cat_short,help={"Use this button to generate a notebook with file header information. Very useful for identifying files."}
548        SetVariable PS1,pos={42,111},size={338,13},proc=SetLabelVarProc,title="label"
549        SetVariable PS1,help={"Current sample label"},font="Courier",fSize=10
550        SetVariable PS1,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPS1
551        SetVariable PV1,pos={42,129},size={340,13},title="Transmission"
552        SetVariable PV1,help={"Current transmission\rvalue"},font="Courier",fSize=10
553        SetVariable PV1,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV1
554        SetVariable PV2,pos={42,147},size={340,13},title="Thickness (cm)"
555        SetVariable PV2,help={"Current sample thickness, in units of centimeters"}
556        SetVariable PV2,font="Courier",fSize=10
557        SetVariable PV2,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV2
558        SetVariable PV3,pos={42,165},size={340,13},title="Beamcenter X"
559        SetVariable PV3,help={"Current X-position of the beamcenter, in pixels"}
560        SetVariable PV3,font="Courier",fSize=10
561        SetVariable PV3,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV3
562        SetVariable PV4,pos={42,183},size={340,13},title="Beamcenter Y"
563        SetVariable PV4,help={"Current Y-position of the beamcenter, in pixels"}
564        SetVariable PV4,font="Courier",fSize=10
565        SetVariable PV4,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV4
566        SetVariable PV5,pos={42,202},size={340,13},title="Attenuator number"
567        SetVariable PV5,help={"attenuator number present during data collection"}
568        SetVariable PV5,font="Courier",fSize=10
569        SetVariable PV5,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV5
570        SetVariable PV6,pos={42,219},size={340,13},title="Counting time (s)",font="Courier",fSize=10
571        SetVariable PV6,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV6
572        SetVariable PV6,help={"total counting time in seconds"}
573        SetVariable PV7,pos={42,237},size={340,13},title="Monitor count",font="Courier",fSize=10
574        SetVariable PV7,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV7
575        SetVariable PV7,help={"total monitor counts"}
576        SetVariable PV8,pos={42,255},size={340,13},title="Detector count",font="Courier",fSize=10
577        SetVariable PV8,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV8
578        SetVariable PV8,help={"total detector counts"}
579        SetVariable PV9,pos={42,273},size={340,13},title="Trans. det. count",font="Courier",fSize=10
580        SetVariable PV9,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV9
581        SetVariable PV9,help={"Transmission\r detector counts"}
582        SetVariable PV10,pos={42,291},size={340,13},title="Wavelength (A)",font="Courier",fSize=10
583        SetVariable PV10,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV10
584        SetVariable PV10,help={"neutron wavelength in angstroms"}
585        SetVariable PV11,pos={42,309},size={340,13},title="Wavelength spread",font="Courier",fSize=10
586        SetVariable PV11,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV11
587        SetVariable PV11,help={"wavelength spread (delta lambda)/lambda"}
588        SetVariable PV12,pos={42,327},size={340,13},title="Temperature (C)",font="Courier",fSize=10
589        SetVariable PV12,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV12
590        SetVariable PV12,help={"Set point temperature in centigrade"}
591        SetVariable PV13,pos={42,345},size={340,13},title="Magnetic field (G)",font="Courier",fSize=10
592        SetVariable PV13,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV13
593        SetVariable PV13,help={"magnetic field strength units?"}
594        SetVariable PV14,pos={42,363},size={340,13},title="Source aperture (mm)",font="Courier",fSize=10
595        SetVariable PV14,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV14
596        SetVariable PV14,help={"source aperture diameter, in millimeters"}
597        SetVariable PV15,pos={42,381},size={340,13},title="Sample aperture (mm)",font="Courier",fSize=10
598        SetVariable PV15,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV15
599        SetVariable PV15,help={"sample aperture diameter, in millimeters"}
600        SetVariable PV16,pos={42,399},size={340,13},title="Source to sample distance (m)",font="Courier",fSize=10
601        SetVariable PV16,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV16
602        SetVariable PV16,help={"Source to sample distance in meters"}
603        SetVariable PV17,pos={42,417},size={340,13},title="Detector offset (cm)",font="Courier",fSize=10
604        SetVariable PV17,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV17
605        SetVariable PV17,help={"Detector offset, in centimeters"}
606        SetVariable PV18,pos={42,435},size={340,13},title="Beamstop diameter (mm)",font="Courier",fSize=10
607        SetVariable PV18,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV18
608        SetVariable PV18,help={"beamstop diamter, in millimeters (1 inch = 25.4mm)"}
609        SetVariable PV19,pos={42,453},size={340,13},title="Sample to detector distance (m)",font="Courier",fSize=10
610        SetVariable PV19,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV19
611        SetVariable PV19,help={"sample to detector distance, in meters"}
612       
613        CheckBox checkPS1,pos={18,108},size={20,20},title=""
614        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
615        CheckBox checkPV1,pos={18,126},size={20,20},title=""
616        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
617        CheckBox checkPV2,pos={18,144},size={20,20},title=""
618        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
619        CheckBox checkPV3,pos={18,162},size={20,20},title=""
620        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
621        CheckBox checkPV4,pos={18,180},size={20,20},title=""
622        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
623        CheckBox checkPV5,pos={18,198},size={20,20},title=""
624        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
625        CheckBox checkPV6,pos={18,216},size={20,20},title=""
626        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
627        CheckBox checkPV7,pos={18,234},size={20,20},title="",value=0
628        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
629        CheckBox checkPV8,pos={18,252},size={20,20},title="",value=0
630        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
631        CheckBox checkPV9,pos={18,270},size={20,20},title="",value=0
632        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
633        CheckBox checkPV10,pos={18,288},size={20,20},title="",value=0
634        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
635        CheckBox checkPV11,pos={18,306},size={20,20},title="",value=0
636        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
637        CheckBox checkPV12,pos={18,324},size={20,20},title="",value=0
638        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
639        CheckBox checkPV13,pos={18,342},size={20,20},title="",value=0
640        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
641        CheckBox checkPV14,pos={18,360},size={20,20},title="",value=0
642        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
643        CheckBox checkPV15,pos={18,378},size={20,20},title="",value=0
644        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
645        CheckBox checkPV16,pos={18,396},size={20,20},title="",value=0
646        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
647        CheckBox checkPV17,pos={18,414},size={20,20},title="",value=0
648        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
649        CheckBox checkPV18,pos={18,432},size={20,20},title="",value=0
650        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
651        CheckBox checkPV19,pos={18,450},size={20,20},title="",value=0
652        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
653End
654
655//This function will read only the selected values editable in the patch panel
656//The values read are passed to the panel through the global variables
657//the function WriteHeaderForPatch() MUST mirror this set of reads, or nothing can be updated
658//
659//fname is the full path:name;vers to open the file
660//
661Function ReadHeaderForPatch(fname)
662        String fname
663        //this function is for reading in values to be patched - so don't save any waves
664        //just reset the global variables that are on the patch panel
665       
666//      Variable refNum,integer,realval
667//      String textstr=""
668//      Variable countTime
669//     
670//      //full filename with path is passed in
671//      //actually open the file
672//      Open/R refNum as fname
673//     
674//      // read the sample.label text field
675//      FSetPos refNum,98          //will start reading at byte 99
676//      FReadLine/N=60 refNum,textstr
677//      FSetPos refNum,31
678//      FBinRead/B=3/F=3 refnum,countTime
679//     
680//      Close refNum
681//     
682//      //Print "countTime = ",countTime
683//     
684//      //now get all of the reals
685//      //
686//      //Do all the GBLoadWaves at the end
687//      //
688//      //FBinRead Cannot handle 32 bit VAX floating point
689//      //GBLoadWave, however, can properly read it
690//      String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
691//      String strToExecute
692//      //append "/S=offset/U=numofreals" to control the read
693//      // then append fname to give the full file path
694//      // then execute
695//     
696//      // NEW reads
697//      Variable moncnt,savmon,detcnt,atten,trans,thick,temp,field
698//      Variable dis,ang,bstop,ap1,ap2,ap12dis,lmda,dlmda,beamx,beamy,trnscnt
699//     
700//      strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""
701//      Execute strToExecute
702//      Wave w=$"tempGBWave0"
703//      moncnt = w[0]
704//      savmon = w[1]
705//      detcnt = w[2]
706//      atten = w[3]
707//      //printf "moncnt = %g,savmon = %g,detcnt = %g,atten = %g\r",moncnt,savmon,detcnt,atten
708//     
709//      strToExecute = GBLoadStr + "/S=158/U=2" + "\"" + fname + "\""
710//      Execute strToExecute
711//      trans = w[0]
712//      thick = w[1]
713//      //printf "trans = %g, thick = %g\r",trans,thick
714//     
715//      strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""
716//      Execute strToExecute
717//      temp = w[0]
718//      field = w[1]
719//      //printf "temp = %g, field = %g\r",temp,field
720//     
721//      strToExecute = GBLoadStr + "/S=252/U=12" + "\"" + fname + "\""
722//      Execute strToExecute
723//      beamx = w[0]
724//      beamy = w[1]
725//      dis = w[2]
726//      ang = w[3]
727//      // w[4] det size
728//      bstop = w[5]
729//      // w[6] blank
730//      ap1 = w[7]
731//      ap2 = w[8]
732//      ap12dis = w[9]
733//      lmda = w[10]
734//      dlmda = w[11]
735//      //printf "beamx = %g, beamy = %g\r",beamx,beamy
736//      //printf "dis = %g,ang = %g, bstop = %g,ap1= %g,ap2 = %g\r",dis,ang,bstop,ap1,ap2
737//      //printf "ap12dis = %g, lmda = %g, dlmda = %g\r",ap12dis,lmda,dlmda
738//     
739//      strToExecute = GBLoadStr + "/S=388/U=1" + "\"" + fname + "\""
740//      Execute strToExecute
741//      trnscnt = w[0]
742//      //printf "trnscnt = %g\r",trnscnt
743//     
744//      //assign to the globals for display in the panel
745//      String/G root:myGlobals:Patch:gPS1= textstr
746//      Variable/G root:myGlobals:Patch:gPV1 = trans
747//      Variable/G root:myGlobals:Patch:gPV2 = thick
748//      Variable/G root:myGlobals:Patch:gPV3 = beamx
749//      Variable/G root:myGlobals:Patch:gPV4 = beamy
750//      Variable/G root:myGlobals:Patch:gPV5 = atten
751//      Variable/G root:myGlobals:Patch:gPV6 = countTime
752//      Variable/G root:myGlobals:Patch:gPV7 = moncnt
753//      Variable/G root:myGlobals:Patch:gPV8 = detcnt
754//      Variable/G root:myGlobals:Patch:gPV9 = trnscnt
755//      Variable/G root:myGlobals:Patch:gPV10 = lmda
756//      Variable/G root:myGlobals:Patch:gPV11 = dlmda
757//      Variable/G root:myGlobals:Patch:gPV12 = temp
758//      Variable/G root:myGlobals:Patch:gPV13 = field
759//      Variable/G root:myGlobals:Patch:gPV14 = ap1
760//      Variable/G root:myGlobals:Patch:gPV15 = ap2
761//      Variable/G root:myGlobals:Patch:gPV16 = ap12dis
762//      Variable/G root:myGlobals:Patch:gPV17 = ang
763//      Variable/G root:myGlobals:Patch:gPV18 = bstop
764//      Variable/G root:myGlobals:Patch:gPV19 = dis
765//     
766//      //clean up - get rid of w = $"tempGBWave0"
767//      KillWaves/Z w
768       
769        // each "get" is an individual call to GBLoadWave...
770        // test for acceptable speed over a network...
771       
772        //assign to the globals for display in the panel
773        String/G root:myGlobals:Patch:gPS1= getSampleLabel(fname)
774        Variable/G root:myGlobals:Patch:gPV1 = getSampleTrans(fname)
775        Variable/G root:myGlobals:Patch:gPV2 = getSampleThickness(fname)
776        Variable/G root:myGlobals:Patch:gPV3 = getBeamXPos(fname)
777        Variable/G root:myGlobals:Patch:gPV4 = getBeamYPos(fname)
778        Variable/G root:myGlobals:Patch:gPV5 = getAttenNumber(fname)
779        Variable/G root:myGlobals:Patch:gPV6 = getCountTime(fname)
780        Variable/G root:myGlobals:Patch:gPV7 = getMonitorCount(fname)
781        Variable/G root:myGlobals:Patch:gPV8 = getDetCount(fname)
782        Variable/G root:myGlobals:Patch:gPV9 = getTransDetectorCounts(fname)
783        Variable/G root:myGlobals:Patch:gPV10 = getWavelength(fname)
784        Variable/G root:myGlobals:Patch:gPV11 = getWavelengthSpread(fname)
785        Variable/G root:myGlobals:Patch:gPV12 = getTemperature(fname)
786        Variable/G root:myGlobals:Patch:gPV13 = getFieldStrength(fname)
787        Variable/G root:myGlobals:Patch:gPV14 = getSourceApertureDiam(fname)
788        Variable/G root:myGlobals:Patch:gPV15 = getSampleApertureDiam(fname)
789        Variable/G root:myGlobals:Patch:gPV16 = getSourceToSampleDist(fname)
790        Variable/G root:myGlobals:Patch:gPV17 = getDetectorOffset(fname)
791        Variable/G root:myGlobals:Patch:gPV18 = getBSDiameter(fname)
792        Variable/G root:myGlobals:Patch:gPV19 = getSDD(fname)
793       
794        Return 0
795End
796
797Function ShowPatchHelp(ctrlName) : ButtonControl
798        String ctrlName
799        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Patch File Headers]"
800End
801
802//button action procedure to change the selected information (checked values)
803//in each file in the popup list. This will change multiple files, and as such,
804//the user is given a chance to bail out before the whole list of files
805//is modified
806//useful for patching a series of runs with the same beamcenters, or transmissions
807//
808Function ChAllHeadersButtonProc(ctrlName) : ButtonControl
809        String ctrlName
810       
811        String msg
812        msg = "Do you really want to write all of these values to each data file in the popup list? "
813        msg += "- clicking NO will leave all files unchanged"
814        DoAlert 1,msg
815        If(V_flag == 2)
816                Abort "no files were changed"
817        Endif
818       
819        //this will change (checked) values in ALL of the headers in the popup list
820        SVAR list = root:myGlobals:Patch:gPatchList
821        Variable numitems,ii
822        numitems = ItemsInList(list,";")
823       
824        if(numitems == 0)
825                Abort "no items in list for multiple patch"
826        Endif
827       
828        //read the (6) checkboxes to determine what changes to make
829        //The order/length of these waves are crucial!, set by nvars     
830        String partialName="", tempName = ""
831        Variable ok,nvars = 20
832       
833        Make/O/N=(nvars) tempChange
834        Wave w=tempchange
835        GetCheckBoxesState(w,nvars)
836        //Print "w[0] = ",w[0]
837       
838        //Get the current values in each of the fields - to pass to Write() as a textwave
839        Make/O/T/N=(nvars) tempValues
840        Wave/T wt=tempValues
841        //initialize textwave
842        ii=0
843        do
844                wt[ii] = ""
845                ii+=1
846        while(ii<nvars)
847        GetEditedSetVarBoxes(wt,nvars)
848       
849        //loop through all of the files in the list, applying changes as dictated by w and wt waves
850        ii=0
851        do
852                //get current item in the list
853                partialName = StringFromList(ii, list, ";")
854                   
855                //get a valid file based on this partialName and catPathName
856                tempName = FindValidFilename(partialName)
857       
858                //prepend path to tempName for read routine
859                PathInfo catPathName
860                tempName = S_path + tempName
861       
862                //make sure the file is really a RAW data file
863                ok = CheckIfRawData(tempName)
864                if (!ok)
865                   Print "this file is not recognized as a RAW SANS data file = ",tempName
866                else
867                   //go write the changes to the file
868                   WriteHeaderForPatch(tempName,w,wt)
869                Endif
870               
871                ii+=1
872        while(ii<numitems)
873       
874        //clean up wave before leaving
875        KillWaves/Z w,wt
876               
877End
878
879
880//simple action for button to close the panel
881//closes all file that may accidently be open at this point
882//(but none are open)
883//
884Function DoneButtonProc(ctrlName) : ButtonControl
885        String ctrlName
886
887        // this button will make sure all files are closed
888        //and close the panel
889       
890        Close/A
891        DoWindow/K Patch_Panel
892       
893End
894
895//resets the global string corresponding to the sample label
896//updates when new text is entered
897//
898Function SetLabelVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
899        String ctrlName
900        Variable varNum
901        String varStr
902        String varName
903       
904        //reset the global variable to the entered text so that it can be relayed to the
905        //write() routine. Only the TEXT SetVariable control needs to be handles this way
906       
907        String/G root:myGlobals:Patch:gPS1 = varStr
908
909End
910
911
912//button action function to set the XY box for the empty beam file (or reset it)
913//this function is called by the button on the Patch Panel to set the XY box
914//panel, but is nearly identical. This function resets the string used in the Patch
915//panel to list the current empty beam file
916//
917//depends on the user slecting and setting the box with the marquee (see marquee.ipf)
918//then reads the set coordinates from the global keyword string
919//
920//**********UNUSED******************
921//Function SetXYBoxButton(ctrlName) : ButtonControl
922//      String ctrlName
923//
924//      String msgStr = "Select the Empty Beam FIle"
925//      String filename,shortName
926//     
927//      //get the filename, then read it in
928//      filename = PromptForPath(msgStr)
929//      //check for cancel from dialog
930//      if(strlen(filename)==0)
931//              //user cancelled, abort
932//              SetDataFolder root:
933//              Abort "No file selected, action aborted"
934//      Endif
935//      shortName = GetFileNameFromPathKeepSemi(filename)
936//      String/G root:myGlobals:Patch:gPS2 = filename      //(reset the string for the patch panel)
937//     
938//      ReadHeaderAndData(filename)
939//      //data is displayed here (go htrough the normal display steps, so all is created properly
940//      String/G root:myGlobals:gDataDisplayType="RAW"
941//      fRawWindowHook()
942//     
943//      // check the empty beam file for previously selected coordinates
944//      //if they exist, set the xy string , save the normalized counts somewhere
945//      //the value was written to an unused r*4 header analysis.factor (@b494)
946//      Variable refnum,x1,x2,y1,y2,err
947//      Open/R refnum as filename
948//      FSetPos refnum,478
949//      FBinRead/F=3/B=3 refnum, x1
950//      FBinRead/F=3/B=3 refnum, x2
951//      FBinRead/F=3/B=3 refnum, y1
952//      FBinRead/F=3/B=3 refnum, y2
953//      Close refnum
954//      //read the real count value
955//      String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
956//      String strToExecute
957//      strToExecute = GBLoadStr + "/S=494/U=1" + "\"" + filename + "\""
958//      Execute strToExecute
959//      Wave w=$"tempGBWave0"
960//      Variable/G root:myGlobals:Patch:gTransCts = w[0]
961//      //
962//      if( ((x1-x2)==0) || ((y1-y2)==0) )         //zero width marquee in either direction
963//              //no region selected
964//             
965//              //add the empty beam file to work.SAM
966//              err = Raw_to_work("SAM")
967//     
968//              //the calling macro must change the display type
969//              String/G root:myGlobals:gDataDisplayType="SAM"      //displayed data type is sam
970//     
971//              //data is displayed here
972//              fRawWindowHook()
973//     
974//              //prompt user to select box w/marquee
975//              DoAlert 0,"Select the region to sum with the Marquee"
976//     
977//              //from here the Marquee menu selection must handle the task of setting the box
978//              //and updating the information in the file header
979//      else
980//              // region already selected, just put up the values from the file header
981//              //allow user the option of overriding the current box region
982//              msgStr = "X1="+num2str(x1)+";"
983//              msgStr += "X2="+num2str(x2)+";"
984//              msgStr += "Y1="+num2str(y1)+";"
985//              msgStr += "Y2="+num2str(y2)+";"
986//              String textStr
987//              textStr = "Override current box  "+msgStr+" ?"
988//              DoAlert 1,textStr
989//              If((V_flag)==1)
990//                 //get new box coordinates, same procedure as above
991//                 //add the empty beam file to work.SAM
992//                 err = Raw_to_work("SAM")
993//     
994//                 //the calling macro must change the display type
995//                 String/G root:myGlobals:gDataDisplayType="SAM"      //displayed data type is sam
996//     
997//                 //data is displayed here
998//                 fRawWindowHook()
999//     
1000//                 //prompt user to select box w/marquee
1001//                 DoAlert 0,"Select the region to sum with the Marquee"
1002//     
1003//                 //from here the Marquee menu selection must handle the task of setting the box
1004//                 //and updating the information in the file header
1005//              else
1006//                 String/G root:myGlobals:Patch:gPS3 = msgStr
1007//              Endif
1008//      Endif
1009//     
1010//      KillWaves/Z w
1011//      Return (0)
1012//End
1013
Note: See TracBrowser for help on using the repository browser.