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

Last change on this file since 502 was 502, checked in by srkline, 14 years ago

List of small changes:
Lin_Fits - added I(0) error to one calculation, Need to propagate this to all logical places. (and submit a ticket)
MainPanel? - correctly handle cancel of raw data display
Transmssion - add a "guess" option of a user-supplied "N" characters
Correct - revert back to zero error for beam center mismatch
NCNR_DataRW - add utility to patch monitor counts (comment out of menu later)

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 = 1
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
303        ShowHeaderButtonProc("SHButton")
304End
305
306
307//displays the header of the selected file (top in the popup) when the button is clicked
308//sort of a redundant button, since the procedure is automatically called (as if it were
309//clicked) when a new file is chosen from the popup
310//
311Function ShowHeaderButtonProc(SHButton) : ButtonControl
312        String SHButton
313
314        //displays (editable) header information about current file in popup control
315        //putting the values in the SetVariable displays (resetting the global variables)
316       
317        //get the popup string
318        String partialName, tempName
319        Variable ok
320        ControlInfo patchPopup
321        If(cmpstr(S_value,"")==0)
322                //null selection
323                Abort "no file selected in popup menu"
324        else
325                //selection not null
326                partialName = S_value
327                //Print partialName
328        Endif
329        //get a valid file based on this partialName and catPathName
330        tempName = FindValidFilename(partialName)
331       
332        //prepend path to tempName for read routine
333        PathInfo catPathName
334        tempName = S_path + tempName
335       
336        //make sure the file is really a RAW data file
337        ok = CheckIfRawData(tempName)
338        if (!ok)
339                Abort "this file is not recognized as a RAW SANS data file"
340        Endif
341       
342        //Print tempName
343       
344        ReadHeaderForPatch(tempName)
345       
346        ControlUpdate/A/W=Patch_Panel
347       
348End
349
350//utility function that polls the checkboxes of the editable parameters
351//returns a wave with the yes/no checked state of the boxes
352// 0 = not checked (user does NOT want this header value updated)
353// 1 = checked (YES, change this value in the header)
354//num (input) is a simple check to make sure that the wave is set up properly
355//from the calling routine
356//
357Function GetCheckBoxesState(w,num)
358        Wave w     //on return, this wave contains the current state of the checkboxes
359        Variable num
360       
361        if(num != 20)
362                Abort "wrong number of checkboxes GetCheckBoxesState()"
363        Endif
364        ControlInfo checkPS1
365        w[0] = V_value
366       
367        Variable ii
368        String baseStr="checkPV"
369       
370        ii=1
371        do
372                ControlInfo $(baseStr + num2str(ii))
373                w[ii] = V_Value
374                ii+=1
375        while(ii<num)
376        return(0)
377End
378
379//on return, wt is a TEXT wave with the values in the SetVar boxes
380//will poll the SetVariable controls to get the new values - will get all the values,
381//and let the writing routine decide which ones it will actually use
382//num (input) is a simple check to make sure that the wave is set up properly
383//from the calling routine
384//
385Function GetEditedSetVarBoxes(wt,num)
386        Wave/T wt         
387        Variable num
388       
389        if(num != 20)
390                Abort "wrong number of checkboxes GetEditedSetVarBoxes()"
391        Endif
392        //pass all as a text wave - so only one wave has to be passed (conversion 2x, though)
393        //global is set to the changed value when entered. read others directly from the control
394        //make sure the text label is exactly 60 characters long, to match VAX field length
395        SVAR dum=root:myGlobals:Patch:gPS1
396        String str60="", junk="junk"
397        str60 = PadString(junk,60,0x20)
398        if(strlen(dum) <= 60)
399                if(strlen(dum) == 60)
400                   str60 = dum
401                else
402                   str60 = PadString(dum,60,0x20)
403                Endif
404        else
405                //too long, truncate
406                str60[0,59] = dum[0,59]
407        Endif
408       
409        wt[0] = str60
410       
411        Variable ii
412        String baseStr="PV"
413        ii=1
414        do
415                ControlInfo $(baseStr + num2str(ii))
416                wt[ii] = num2str(V_Value)
417                ii+=1
418        while(ii<num)
419       
420        return(0)       //no error
421End
422
423
424//simple function to get the string value from the popup list of filenames
425//returned string is only the text in the popup, a partial name with no path
426//or VAX version number.
427//
428Function/S GetPatchPopupString()
429
430        String str=""
431       
432        ControlInfo patchPopup
433        If(cmpstr(S_value,"")==0)
434                //null selection
435                Abort "no file selected in popup menu"
436        else
437                //selection not null
438                str = S_value
439                //Print str
440        Endif
441       
442        Return str
443End
444
445//Changes (writes to disk!) the specified changes to the (single) file selected in the popup
446//reads the checkboxes to determine which (if any) values need to be written
447//
448Function ChangeHeaderButtonProc(CHButton) : ButtonControl
449        String CHButton
450
451        //read the (20) checkboxes to determine what changes to make
452        //The order/length of these waves are crucial!, set by nvars     
453        String partialName="", tempName = ""
454        Variable ok,nvars = 20,ii
455       
456        Make/O/N=(nvars) tempChange
457        Wave w=tempchange
458        GetCheckBoxesState(w,nvars)
459        //Print "w[0] = ",w[0]
460       
461       
462        //Get the current values in each of the fields - to pass to Write() as a textwave
463        Make/O/T/N=(nvars) tempValues
464        Wave/T wt=tempValues
465        //initialize textwave
466        ii=0
467        do
468                wt[ii] = ""
469                ii+=1
470        while(ii<nvars)
471        GetEditedSetVarBoxes(wt,nvars)
472       
473        //get the popup string
474        partialName = GetPatchPopupString()
475       
476        //get a valid file based on this partialName and catPathName
477        tempName = FindValidFilename(partialName)
478       
479        //prepend path to tempName for read routine
480        PathInfo catPathName
481        tempName = S_path + tempName
482       
483        //make sure the file is really a RAW data file
484        ok = CheckIfRawData(tempName)
485        if (!ok)
486                Abort "this file is not recognized as a RAW SANS data file"
487        Endif
488       
489        //go write the changes to the file
490        WriteHeaderForPatch(tempName,w,wt)
491       
492        //clean up wave before leaving
493        KillWaves/Z w,wt
494       
495End
496
497//*****this function actually writes the data to disk*****
498//overwrites the specific bytes the the header that are to be changed
499//real values are written out mimicking VAX format, so that can be properly
500//re-read as raw binary VAX files.
501//if any additional fields are to be edited, the exact byte location must be known
502//
503Function WriteHeaderForPatch(fname,change,textVal)
504        String fname
505        Wave change
506        Wave/T textVal
507       
508        Variable refnum,num
509        String textstr
510       
511        //change the sample label ?
512        if(change[0])
513                WriteSamLabelToHeader(fname,textVal[0])
514        Endif
515       
516        //total count time is an integer, handle separately
517        if(change[6])
518                num =str2num(textVal[6])
519                WriteCountTimeToHeader(fname,num)
520        Endif
521       
522        //ReWriteReal() takes care of open/close on its own
523        if(change[1])           //sample transmission
524                num = str2num(textVal[1])
525                WriteTransmissionToHeader(fname,num)
526        Endif
527        if(change[2])           //sample thickness
528                num = str2num(textVal[2])
529                WriteThicknessToHeader(fname,num)
530        Endif
531        if(change[3])           //pixel X
532                num = str2num(textVal[3])
533                WriteBeamCenterXToHeader(fname,num)
534        Endif
535        if(change[4])           // pixel Y
536                num = str2num(textVal[4])
537                WriteBeamCenterYToHeader(fname,num)
538        Endif
539        if(change[5])           //attenuator number
540                num = str2num(textVal[5])
541                WriteAttenNumberToHeader(fname,num)
542        Endif
543        //[6] was the counting time, integer written above
544        if(change[7])    //monitor count
545                num = str2num(textVal[7])
546                WriteMonitorCountToHeader(fname,num)
547        Endif
548        if(change[8])     //total detector count
549                num = str2num(textVal[8])
550                WriteDetectorCountToHeader(fname,num)
551        Endif
552        if(change[9])      //trans det count
553                num = str2num(textVal[9])
554                WriteTransDetCountToHeader(fname,num)
555        Endif
556        if(change[10])      //wavelength
557                num = str2num(textVal[10])
558                WriteWavelengthToHeader(fname,num)
559        Endif
560        ///
561        if(change[11])      //wavelength spread
562                num = str2num(textVal[11])
563                WriteWavelengthDistrToHeader(fname,num)
564        Endif
565        if(change[12])      //temperature
566                num = str2num(textVal[12])
567                WriteTemperatureToHeader(fname,num)
568        Endif
569        if(change[13])      //magnetic field
570                num = str2num(textVal[13])
571                WriteMagnFieldToHeader(fname,num)
572        Endif
573        if(change[14])      //source aperture
574                num = str2num(textVal[14])
575                WriteSourceApDiamToHeader(fname,num)
576        Endif
577        if(change[15])      //sample aperture
578                num = str2num(textVal[15])
579                WriteSampleApDiamToHeader(fname,num)
580        Endif
581        ///
582        if(change[16])      //source-sam dist
583                num = str2num(textVal[16])
584                WriteSrcToSamDistToHeader(fname,num)
585        Endif
586        if(change[17])      //det offset
587                num = str2num(textVal[17])
588                WriteDetectorOffsetToHeader(fname,num)
589        Endif
590        if(change[18])      //beamstop diam
591                num = str2num(textVal[18])
592                WriteBeamStopDiamToHeader(fname,num)
593        Endif
594        if(change[19])     //SDD
595                num = str2num(textVal[19])
596                WriteSDDToHeader(fname,num)
597        Endif
598        Return(0)
599End
600
601//panel recreation macro for the PatchPanel...
602//
603Proc Patch_Panel()
604        PauseUpdate; Silent 1      // building window...
605//      NewPanel /W=(519,85,950,608)/K=1 as "Patch Raw SANS Data Files"
606        NewPanel /W=(519,85,950,608) as "Patch Raw SANS Data Files"
607        DoWindow/C Patch_Panel
608        ModifyPanel cbRGB=(1,39321,19939)
609        ModifyPanel fixedSize=1
610        SetDrawLayer UserBack
611        SetDrawEnv fname= "Courier",fstyle= 1
612        DrawText 3,107,"Change?"
613        DrawLine 7,30,422,30
614        DrawLine 7,288,422,288
615        DrawLine 7,199,422,199
616        DrawLine 7,378,422,378
617        DrawLine 7,469,422,469
618        SetVariable PathDisplay,pos={77,7},size={310,13},title="Path"
619        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"}
620        SetVariable PathDisplay,font="Courier",fSize=10
621        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gCatPathStr
622        Button PathButton,pos={2,3},size={70,20},proc=PickPathButton,title="Pick Path"
623        Button PathButton,help={"Select the folder containing the raw SANS data files"}
624        Button helpButton,pos={400,3},size={25,20},proc=ShowPatchHelp,title="?"
625        Button helpButton,help={"Show the help file for patching raw data headers"}
626        PopupMenu PatchPopup,pos={4,37},size={156,19},proc=PatchPopMenuProc,title="File(s) to Patch"
627        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"}
628        PopupMenu PatchPopup,mode=1,popvalue="none",value= #"root:myGlobals:Patch:gPatchList"
629//      Button SHButton,pos={324,37},size={100,20},proc=ShowHeaderButtonProc,title="Show Header"
630//      Button SHButton,help={"This will display the header of the file indicated in the popup menu."}
631        Button CHButton,pos={314,37},size={110,20},proc=ChangeHeaderButtonProc,title="Change Header"
632        Button CHButton,help={"This will change the checked values (ONLY) in the single file selected in the popup."}
633        SetVariable PMStr,pos={6,63},size={174,13},proc=SetMatchStrProc,title="Match String"
634        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."}
635        SetVariable PMStr,font="Courier",fSize=10
636        SetVariable PMStr,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPatchMatchStr
637        Button ChAllButton,pos={245,60},size={180,20},proc=ChAllHeadersButtonProc,title="Change All Headers in List"
638        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."}
639        Button DoneButton,pos={310,489},size={110,20},proc=DoneButtonProc,title="Done Patching"
640        Button DoneButton,help={"When done Patching files, this will close this control panel."}
641        Button cat_short,pos={9,485},size={100,20},proc=DoCatShort,title="File Catalog"
642        Button cat_short,help={"Use this button to generate a notebook with file header information. Very useful for identifying files."}
643        SetVariable PS1,pos={42,111},size={338,13},proc=SetLabelVarProc,title="label"
644        SetVariable PS1,help={"Current sample label"},font="Courier",fSize=10
645        SetVariable PS1,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPS1
646        SetVariable PV1,pos={42,129},size={340,13},title="Transmission"
647        SetVariable PV1,help={"Current transmission\rvalue"},font="Courier",fSize=10
648        SetVariable PV1,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV1
649        SetVariable PV2,pos={42,147},size={340,13},title="Thickness (cm)"
650        SetVariable PV2,help={"Current sample thickness, in units of centimeters"}
651        SetVariable PV2,font="Courier",fSize=10
652        SetVariable PV2,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV2
653        SetVariable PV3,pos={42,165},size={340,13},title="Beamcenter X"
654        SetVariable PV3,help={"Current X-position of the beamcenter, in pixels"}
655        SetVariable PV3,font="Courier",fSize=10
656        SetVariable PV3,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV3
657        SetVariable PV4,pos={42,183},size={340,13},title="Beamcenter Y"
658        SetVariable PV4,help={"Current Y-position of the beamcenter, in pixels"}
659        SetVariable PV4,font="Courier",fSize=10
660        SetVariable PV4,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV4
661        SetVariable PV5,pos={42,202},size={340,13},title="Attenuator number"
662        SetVariable PV5,help={"attenuator number present during data collection"}
663        SetVariable PV5,font="Courier",fSize=10
664        SetVariable PV5,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV5
665        SetVariable PV6,pos={42,219},size={340,13},title="Counting time (s)",font="Courier",fSize=10
666        SetVariable PV6,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV6
667        SetVariable PV6,help={"total counting time in seconds"}
668        SetVariable PV7,pos={42,237},size={340,13},title="Monitor count",font="Courier",fSize=10
669        SetVariable PV7,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV7
670        SetVariable PV7,help={"total monitor counts"}
671        SetVariable PV8,pos={42,255},size={340,13},title="Detector count",font="Courier",fSize=10
672        SetVariable PV8,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV8
673        SetVariable PV8,help={"total detector counts"}
674        SetVariable PV9,pos={42,273},size={340,13},title="Trans. det. count",font="Courier",fSize=10
675        SetVariable PV9,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV9
676        SetVariable PV9,help={"Transmission\r detector counts"}
677        SetVariable PV10,pos={42,291},size={340,13},title="Wavelength (A)",font="Courier",fSize=10
678        SetVariable PV10,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV10
679        SetVariable PV10,help={"neutron wavelength in angstroms"}
680        SetVariable PV11,pos={42,309},size={340,13},title="Wavelength spread",font="Courier",fSize=10
681        SetVariable PV11,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV11
682        SetVariable PV11,help={"wavelength spread (delta lambda)/lambda"}
683        SetVariable PV12,pos={42,327},size={340,13},title="Temperature (C)",font="Courier",fSize=10
684        SetVariable PV12,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV12
685        SetVariable PV12,help={"Set point temperature in centigrade"}
686        SetVariable PV13,pos={42,345},size={340,13},title="Magnetic field (G)",font="Courier",fSize=10
687        SetVariable PV13,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV13
688        SetVariable PV13,help={"magnetic field strength units?"}
689        SetVariable PV14,pos={42,363},size={340,13},title="Source aperture (mm)",font="Courier",fSize=10
690        SetVariable PV14,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV14
691        SetVariable PV14,help={"source aperture diameter, in millimeters"}
692        SetVariable PV15,pos={42,381},size={340,13},title="Sample aperture (mm)",font="Courier",fSize=10
693        SetVariable PV15,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV15
694        SetVariable PV15,help={"sample aperture diameter, in millimeters"}
695        SetVariable PV16,pos={42,399},size={340,13},title="Source to sample distance (m)",font="Courier",fSize=10
696        SetVariable PV16,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV16
697        SetVariable PV16,help={"Source to sample distance in meters"}
698        SetVariable PV17,pos={42,417},size={340,13},title="Detector offset (cm)",font="Courier",fSize=10
699        SetVariable PV17,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV17
700        SetVariable PV17,help={"Detector offset, in centimeters"}
701        SetVariable PV18,pos={42,435},size={340,13},title="Beamstop diameter (mm)",font="Courier",fSize=10
702        SetVariable PV18,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV18
703        SetVariable PV18,help={"beamstop diamter, in millimeters (1 inch = 25.4mm)"}
704        SetVariable PV19,pos={42,453},size={340,13},title="Sample to detector distance (m)",font="Courier",fSize=10
705        SetVariable PV19,limits={-Inf,Inf,0},value= root:myGlobals:Patch:gPV19
706        SetVariable PV19,help={"sample to detector distance, in meters"}
707       
708        CheckBox checkPS1,pos={18,108},size={20,20},title=""
709        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
710        CheckBox checkPV1,pos={18,126},size={20,20},title=""
711        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
712        CheckBox checkPV2,pos={18,144},size={20,20},title=""
713        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
714        CheckBox checkPV3,pos={18,162},size={20,20},title=""
715        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
716        CheckBox checkPV4,pos={18,180},size={20,20},title=""
717        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
718        CheckBox checkPV5,pos={18,198},size={20,20},title=""
719        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
720        CheckBox checkPV6,pos={18,216},size={20,20},title=""
721        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
722        CheckBox checkPV7,pos={18,234},size={20,20},title="",value=0
723        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
724        CheckBox checkPV8,pos={18,252},size={20,20},title="",value=0
725        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
726        CheckBox checkPV9,pos={18,270},size={20,20},title="",value=0
727        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
728        CheckBox checkPV10,pos={18,288},size={20,20},title="",value=0
729        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
730        CheckBox checkPV11,pos={18,306},size={20,20},title="",value=0
731        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
732        CheckBox checkPV12,pos={18,324},size={20,20},title="",value=0
733        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
734        CheckBox checkPV13,pos={18,342},size={20,20},title="",value=0
735        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
736        CheckBox checkPV14,pos={18,360},size={20,20},title="",value=0
737        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
738        CheckBox checkPV15,pos={18,378},size={20,20},title="",value=0
739        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
740        CheckBox checkPV16,pos={18,396},size={20,20},title="",value=0
741        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
742        CheckBox checkPV17,pos={18,414},size={20,20},title="",value=0
743        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
744        CheckBox checkPV18,pos={18,432},size={20,20},title="",value=0
745        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
746        CheckBox checkPV19,pos={18,450},size={20,20},title="",value=0
747        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
748
749        CheckBox check0,pos={18,80},size={40,15},title="Run #",value= 1,mode=1,proc=MatchCheckProc
750        CheckBox check1,pos={78,80},size={40,15},title="Text",value= 0,mode=1,proc=MatchCheckProc
751        CheckBox check2,pos={138,80},size={40,15},title="SDD",value= 0,mode=1,proc=MatchCheckProc
752
753End
754
755
756Function MatchCheckProc(name,value)
757        String name
758        Variable value
759       
760        NVAR gRadioVal= root:myGlobals:Patch:gRadioVal
761       
762        strswitch (name)
763                case "check0":
764                        gRadioVal= 1
765                        break
766                case "check1":
767                        gRadioVal= 2
768                        break
769                case "check2":
770                        gRadioVal= 3
771                        break
772        endswitch
773        CheckBox check0,value= gRadioVal==1
774        CheckBox check1,value= gRadioVal==2
775        CheckBox check2,value= gRadioVal==3
776End
777
778//This function will read only the selected values editable in the patch panel
779//The values read are passed to the panel through the global variables
780//the function WriteHeaderForPatch() MUST mirror this set of reads, or nothing can be updated
781//
782//fname is the full path:name;vers to open the file
783//
784Function ReadHeaderForPatch(fname)
785        String fname
786        //this function is for reading in values to be patched - so don't save any waves
787        //just reset the global variables that are on the patch panel
788       
789        // each "get" is an individual call to GBLoadWave...
790        // test for acceptable speed over a network...
791       
792        //assign to the globals for display in the panel
793        String/G root:myGlobals:Patch:gPS1= getSampleLabel(fname)
794        Variable/G root:myGlobals:Patch:gPV1 = getSampleTrans(fname)
795        Variable/G root:myGlobals:Patch:gPV2 = getSampleThickness(fname)
796        Variable/G root:myGlobals:Patch:gPV3 = getBeamXPos(fname)
797        Variable/G root:myGlobals:Patch:gPV4 = getBeamYPos(fname)
798        Variable/G root:myGlobals:Patch:gPV5 = getAttenNumber(fname)
799        Variable/G root:myGlobals:Patch:gPV6 = getCountTime(fname)
800        Variable/G root:myGlobals:Patch:gPV7 = getMonitorCount(fname)
801        Variable/G root:myGlobals:Patch:gPV8 = getDetCount(fname)
802        Variable/G root:myGlobals:Patch:gPV9 = getTransDetectorCounts(fname)
803        Variable/G root:myGlobals:Patch:gPV10 = getWavelength(fname)
804        Variable/G root:myGlobals:Patch:gPV11 = getWavelengthSpread(fname)
805        Variable/G root:myGlobals:Patch:gPV12 = getTemperature(fname)
806        Variable/G root:myGlobals:Patch:gPV13 = getFieldStrength(fname)
807        Variable/G root:myGlobals:Patch:gPV14 = getSourceApertureDiam(fname)
808        Variable/G root:myGlobals:Patch:gPV15 = getSampleApertureDiam(fname)
809        Variable/G root:myGlobals:Patch:gPV16 = getSourceToSampleDist(fname)
810        Variable/G root:myGlobals:Patch:gPV17 = getDetectorOffset(fname)
811        Variable/G root:myGlobals:Patch:gPV18 = getBSDiameter(fname)
812        Variable/G root:myGlobals:Patch:gPV19 = getSDD(fname)
813       
814        Return 0
815End
816
817Function ShowPatchHelp(ctrlName) : ButtonControl
818        String ctrlName
819        DisplayHelpTopic/Z/K=1 "SANS Data Reduction Tutorial[Patch File Headers]"
820        if(V_flag !=0)
821                DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found"
822        endif
823End
824
825//button action procedure to change the selected information (checked values)
826//in each file in the popup list. This will change multiple files, and as such,
827//the user is given a chance to bail out before the whole list of files
828//is modified
829//useful for patching a series of runs with the same beamcenters, or transmissions
830//
831Function ChAllHeadersButtonProc(ctrlName) : ButtonControl
832        String ctrlName
833       
834        String msg
835        msg = "Do you really want to write all of these values to each data file in the popup list? "
836        msg += "- clicking NO will leave all files unchanged"
837        DoAlert 1,msg
838        If(V_flag == 2)
839                Abort "no files were changed"
840        Endif
841       
842        //this will change (checked) values in ALL of the headers in the popup list
843        SVAR list = root:myGlobals:Patch:gPatchList
844        Variable numitems,ii
845        numitems = ItemsInList(list,";")
846       
847        if(numitems == 0)
848                Abort "no items in list for multiple patch"
849        Endif
850       
851        //read the (6) checkboxes to determine what changes to make
852        //The order/length of these waves are crucial!, set by nvars     
853        String partialName="", tempName = ""
854        Variable ok,nvars = 20
855       
856        Make/O/N=(nvars) tempChange
857        Wave w=tempchange
858        GetCheckBoxesState(w,nvars)
859        //Print "w[0] = ",w[0]
860       
861        //Get the current values in each of the fields - to pass to Write() as a textwave
862        Make/O/T/N=(nvars) tempValues
863        Wave/T wt=tempValues
864        //initialize textwave
865        ii=0
866        do
867                wt[ii] = ""
868                ii+=1
869        while(ii<nvars)
870        GetEditedSetVarBoxes(wt,nvars)
871       
872        //loop through all of the files in the list, applying changes as dictated by w and wt waves
873        ii=0
874        do
875                //get current item in the list
876                partialName = StringFromList(ii, list, ";")
877                   
878                //get a valid file based on this partialName and catPathName
879                tempName = FindValidFilename(partialName)
880       
881                //prepend path to tempName for read routine
882                PathInfo catPathName
883                tempName = S_path + tempName
884       
885                //make sure the file is really a RAW data file
886                ok = CheckIfRawData(tempName)
887                if (!ok)
888                   Print "this file is not recognized as a RAW SANS data file = ",tempName
889                else
890                   //go write the changes to the file
891                   WriteHeaderForPatch(tempName,w,wt)
892                Endif
893               
894                ii+=1
895        while(ii<numitems)
896       
897        //clean up wave before leaving
898        KillWaves/Z w,wt
899               
900End
901
902
903//simple action for button to close the panel
904Function DoneButtonProc(ctrlName) : ButtonControl
905        String ctrlName
906       
907        DoWindow/K Patch_Panel
908       
909End
910
911//resets the global string corresponding to the sample label
912//updates when new text is entered
913//
914Function SetLabelVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
915        String ctrlName
916        Variable varNum
917        String varStr
918        String varName
919       
920        //reset the global variable to the entered text so that it can be relayed to the
921        //write() routine. Only the TEXT SetVariable control needs to be handled this way
922       
923        String/G root:myGlobals:Patch:gPS1 = varStr
924
925End
926
927
928// testing, very dangerous batch changing of the file header labels
929//
930// testStr is the string at the front of a label, that will be moved to the "back"
931// if doIt is 1, it will write to the headers, any other value will only print to history
932Function MPatchLabel(testStr,doIt)
933        String testStr
934        Variable doIt
935
936//      SVAR list = root:myGlobals:Patch:gPatchList
937        String list = GetValidPatchPopupList()
938
939        Variable numitems,ii
940        numitems = ItemsInList(list,";")
941       
942        if(numitems == 0)
943                Abort "no items in list for multiple patch"
944        Endif
945       
946        String partialName="", tempName = ""
947        Variable ok,nvars = 20
948       
949        //loop through all of the files in the list, applying changes as dictated by w and wt waves
950        string str1,str2,str3
951        Variable match,loc,len,spc,jj,len1
952        len=strlen(testStr)
953        ii=0
954        do
955                //get current item in the list
956                partialName = StringFromList(ii, list, ";")
957                   
958                //get a valid file based on this partialName and catPathName
959                tempName = FindValidFilename(partialName)
960       
961                //prepend path to tempName for read routine
962                PathInfo catPathName
963                tempName = S_path + tempName
964       
965                //make sure the file is really a RAW data file
966                ok = CheckIfRawData(tempName)
967                if (!ok)
968                   Print "this file is not recognized as a RAW SANS data file = ",tempName
969                else
970                   //go write the changes to the file
971                   str1 = getSampleLabel(tempName)
972                        match = strsearch(str1, testStr, 0)
973                        if(match != -1)
974                                str2 = ReplaceString(testStr, str1, "", 0, 1)
975                               
976                                jj=strlen(str2)
977                                do
978                                        jj -= 1
979                                        spc = cmpstr(str2[jj], " ")             //can add the optional flag ,0), but I don't care about case, and Igor 6.02 is necessary...
980                                        if (spc != 0)
981                                                break           //no more spaces found, get out
982                                        endif
983                                While(1)        // jj is the location of the last non-space
984                               
985                                str2[jj+2,jj+1+len] = testStr
986                       
987                        // may need to remove leading spaces???
988                                str2 = PadString(str2, 60, 0x20 )
989                               
990                                if(doIt == 1)
991                                        WriteSamLabelToHeader(tempName,str2)
992                                        print str2," ** Written to file **"
993                                else
994                                        //print str2,strlen(str2)
995                                        print str2," ** Testing, not written to file **"
996                                endif
997                        else
998                               
999                                jj=strlen(str1)
1000                                do
1001                                        jj -= 1
1002                                        spc = cmpstr(str1[jj], " ")
1003                                        if (spc != 0)
1004                                                break           //no more spaces found, get out
1005                                        endif
1006                                While(1)
1007       
1008                                //print str1, jj, str1[jj]     
1009                        endif
1010                Endif
1011               
1012                ii+=1
1013        while(ii<numitems)
1014
1015
1016end
1017
Note: See TracBrowser for help on using the repository browser.