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

Last change on this file since 741 was 741, checked in by srkline, 12 years ago

added a wildcard to the SDD selector for the Patch Panel.

now can use wild card at the END of the distance. the actual distance is round(SDD), so 13* will find 13.17m, and 4* will find the ICE-reported 3.9995m

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