source: sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/PatchFiles.ipf @ 41

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

change to UNIX line endings

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