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

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

many changes to PatchFiles?.ipf to get the reads and writes separated
and put into NCNR_DataReadWrite.ipf

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