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

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

PatchFiles? now sorts the list of files, rather than the WinOS-garbled listing
NSORT has changes to Beta-only procedures, changes to avoid wave/varaible name conflicts that have shown up in Igor 6
Includes_v500 is the Beta/no Beta compile switch, left on for now before release

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