source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_PatchFiles.ipf @ 1003

Last change on this file since 1003 was 1003, checked in by srkline, 6 years ago

* updated the detector dead time constants in NCNR_Utils for the new NISTO hardware *

other changes were to the file catalog and patch files, which are still works in progress.

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