source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/PatchFiles.ipf @ 494

Last change on this file since 494 was 494, checked in by srkline, 13 years ago

Changes to how Patch interprets the match string. 3 cases now:
(1) - interpret as a run number list, just like all other run number lists and ranges.
(2) grep for text in the raw VAX binary. can be slow. did not allow generic regular expressions to be entered since of the three people on earth that know how to use them, none are neutron scatterers.
(3) filter on SDD, just like in the MRED beta ops. Radio buttons control how it's interpreted. Removed the redundant "Show Header" button, as the header is displayed for the currently popped item without user intervention.

This closes Cedric's ticket #212

Plus a few tweaks of MC and Wrapper.

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