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

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

changes to handle an arbitrary run number, rather than insisting on 3 or 4 digits.

fix to SANS file catalog where the last file name was cleared from the table, if there are no extra non-raw data files present. not a typical case, but it can happen.

  • Property svn:executable set to *
File size: 40.8 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       
441        //pass all as a text wave - so only one wave has to be passed (conversion 2x, though)
442        //global is set to the changed value when entered. read others directly from the control
443       
444        //make sure the text label is exactly 60 characters long, to match VAX field length
445        SVAR dum=root:Packages:NIST:VSANS:Globals:Patch:gPS1
446//      String str60="", junk="junk"
447//      str60 = PadString(junk,60,0x20)
448//      if(strlen(dum) <= 60)
449//              if(strlen(dum) == 60)
450//                 str60 = dum
451//              else
452//                 str60 = PadString(dum,60,0x20)
453//              Endif
454//      else
455//              //too long, truncate
456//              str60[0,59] = dum[0,59]
457//      Endif
458//     
459//      wt[0] = str60
460        wt[0] = dum                     //with Nexus, no need to enforce 60 character field
461//     
462        Variable ii
463        String baseStr="PV"
464        ii=1
465        do
466                ControlInfo $(baseStr + num2str(ii))
467                wt[ii] = num2str(V_Value)
468                ii+=1
469        while(ii<num)
470       
471        return(0)       //no error
472End
473
474
475//simple function to get the string value from the popup list of filenames
476//returned string is only the text in the popup, a partial name with no path
477//or VAX version number.
478//
479Function/S GetPatchPopupString()
480
481        String str=""
482       
483        ControlInfo patchPopup
484        If(cmpstr(S_value,"")==0)
485                //null selection
486                Abort "no file selected in popup menu"
487        else
488                //selection not null
489                str = S_value
490                //Print str
491        Endif
492       
493        Return str
494End
495
496//Changes (writes to disk!) the specified changes to the (single) file selected in the popup
497//reads the checkboxes to determine which (if any) values need to be written
498//
499Function ChangeHeaderButtonProc(CHButton) : ButtonControl
500        String CHButton
501
502        //read the (20) checkboxes to determine what changes to make
503        //The order/length of these waves are crucial!, set by nvars     
504        String partialName="", tempName = ""
505        Variable ok,nvars = 20,ii
506       
507        Make/O/N=(nvars) tempChange
508        Wave w=tempchange
509        GetCheckBoxesState(w,nvars)
510        //Print "w[0] = ",w[0]
511       
512       
513        //Get the current values in each of the fields - to pass to Write() as a textwave
514        Make/O/T/N=(nvars) tempValues
515        Wave/T wt=tempValues
516        //initialize textwave
517        ii=0
518        do
519                wt[ii] = ""
520                ii+=1
521        while(ii<nvars)
522        GetEditedSetVarBoxes(wt,nvars)
523       
524        //get the popup string
525        partialName = GetPatchPopupString()
526       
527        //get a valid file based on this partialName and catPathName
528        tempName = V_FindValidFilename(partialName)
529       
530        //prepend path to tempName for read routine
531        PathInfo catPathName
532        tempName = S_path + tempName
533       
534        //make sure the file is really a RAW data file
535        ok = V_CheckIfRawData(tempName)
536        if (!ok)
537                Abort "this file is not recognized as a RAW SANS data file"
538        Endif
539       
540        //go write the changes to the file
541        WriteHeaderForPatch(tempName,w,wt)
542       
543        //clean up wave before leaving
544        KillWaves/Z w,wt
545       
546End
547
548//*****this function actually writes the data to disk*****
549//overwrites the specific bytes the the header that are to be changed
550//real values are written out mimicking VAX format, so that can be properly
551//re-read as raw binary VAX files.
552//if any additional fields are to be edited, the exact byte location must be known
553//
554Function WriteHeaderForPatch(fname,change,textVal)
555        String fname
556        Wave change
557        Wave/T textVal
558       
559        Variable refnum,num
560        String textstr
561
562// TODO:
563// -- currently I hard-wired a detector choice. This needs to be changed (somehow), with a better interface
564//
565        String detStr = "FL"
566
567       
568        //change the sample label ?
569        if(change[0])
570                V_writeSampleDescription(fname,textVal[0])
571        Endif
572       
573
574        if(change[1])           //sample transmission
575                num = str2num(textVal[1])
576                V_writeSampleTransmission(fname,num)
577        Endif
578        if(change[2])           //sample thickness
579                num = str2num(textVal[2])
580                V_writeSampleThickness(fname,num)
581        Endif
582        if(change[3])           //pixel X
583                num = str2num(textVal[3])
584                V_writeDet_beam_center_x(fname,detStr,num)              // TODO un-hard-wire
585        Endif
586        if(change[4])           // pixel Y
587                num = str2num(textVal[4])
588                V_writeDet_beam_center_y(fname,detStr,num)              // TODO un-hard-wire
589        Endif
590        if(change[5])           //attenuator number
591                num = str2num(textVal[5])
592                V_writeAtten_num_dropped(fname,num)
593        Endif
594        if(change[6])
595                num =str2num(textVal[6])
596                V_writeCount_time(fname,num)
597        Endif
598        if(change[7])    //monitor count
599                num = str2num(textVal[7])
600                V_writeMonitorCount(fname,num)
601        Endif
602        if(change[8])     //total detector count
603                num = str2num(textVal[8])
604                V_writeDet_IntegratedCount(fname,detStr,num)            // TODO un-hard-wire
605        Endif
606        if(change[9])      //trans det count
607                num = str2num(textVal[9])
608// TODO -- replace call
609//              WriteTransDetCountToHeader(fname,num)
610        Endif
611        if(change[10])      //wavelength
612                num = str2num(textVal[10])
613                V_writeWavelength(fname,num)
614        Endif
615        ///
616        if(change[11])      //wavelength spread
617                num = str2num(textVal[11])
618                V_writeWavelength_spread(fname,num)
619        Endif
620        if(change[12])      //temperature
621                num = str2num(textVal[12])
622// TODO -- replace call
623//              WriteTemperatureToHeader(fname,num)
624        Endif
625        if(change[13])      //magnetic field
626                num = str2num(textVal[13])
627// TODO -- replace call
628//              WriteMagnFieldToHeader(fname,num)
629        Endif
630        if(change[14])      //source aperture
631//              num = str2num(textVal[14])
632                V_writeSourceAp_size(fname,textVal[14])         //this is expecting a string
633        Endif
634        if(change[15])      //sample aperture
635                num = str2num(textVal[15])
636                V_writeSampleAp2_size(fname,num)                //TODO -- not sure if this is correct call
637        Endif
638        ///
639        if(change[16])      //source-sam dist
640                num = str2num(textVal[16])
641// TODO -- replace call
642//              WriteSrcToSamDistToHeader(fname,num)
643        Endif
644        if(change[17])      //det offset
645                num = str2num(textVal[17])
646                V_writeDet_LateralOffset(fname,detStr,num)              // TODO lateral or vertical offset, based on detStr
647        Endif
648        if(change[18])      //beamstop diam
649                num = str2num(textVal[18])
650                V_writeBeamStopC2_size(fname,num)                       //TODO depends on which det carriage I'm working with (2) or (3)
651        Endif
652        if(change[19])     //SDD
653                num = str2num(textVal[19])
654                V_writeDet_distance(fname,detStr,num)   // TODO un-hard-wire
655        Endif
656        Return(0)
657End
658
659//panel recreation macro for the PatchPanel...
660//
661Proc V_Patch_Panel()
662        PauseUpdate; Silent 1      // building window...
663        NewPanel /W=(519,85,950,608)/K=2 as "Patch Raw VSANS Data Files"
664        DoWindow/C V_Patch_Panel
665        ModifyPanel cbRGB=(1,39321,19939)
666        ModifyPanel fixedSize=1
667        SetDrawLayer UserBack
668        SetDrawEnv fname= "Courier",fstyle= 1
669        DrawText 3,107,"Change?"
670        DrawLine 7,30,422,30
671        DrawLine 7,288,422,288
672        DrawLine 7,199,422,199
673        DrawLine 7,378,422,378
674        DrawLine 7,469,422,469
675        SetVariable PathDisplay,pos={77,7},size={310,13},title="Path"
676        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"}
677        SetVariable PathDisplay,font="Courier",fSize=10
678        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gCatPathStr
679        Button PathButton,pos={2,3},size={70,20},proc=PickPathButton,title="Pick Path"
680        Button PathButton,help={"Select the folder containing the raw SANS data files"}
681        Button helpButton,pos={400,3},size={25,20},proc=ShowPatchHelp,title="?"
682        Button helpButton,help={"Show the help file for patching raw data headers"}
683        PopupMenu PatchPopup,pos={4,37},size={156,19},proc=PatchPopMenuProc,title="File(s) to Patch"
684        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"}
685        PopupMenu PatchPopup,mode=1,popvalue="none",value= #"root:Packages:NIST:VSANS:Globals:Patch:gPatchList"
686//      Button SHButton,pos={324,37},size={100,20},proc=ShowHeaderButtonProc,title="Show Header"
687//      Button SHButton,help={"This will display the header of the file indicated in the popup menu."}
688        Button CHButton,pos={314,37},size={110,20},proc=ChangeHeaderButtonProc,title="Change Header"
689        Button CHButton,help={"This will change the checked values (ONLY) in the single file selected in the popup."}
690        SetVariable PMStr,pos={6,63},size={174,13},proc=SetMatchStrProc,title="Match String"
691        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."}
692        SetVariable PMStr,font="Courier",fSize=10
693        SetVariable PMStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPatchMatchStr
694        Button ChAllButton,pos={245,60},size={180,20},proc=ChAllHeadersButtonProc,title="Change All Headers in List"
695        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."}
696        Button DoneButton,pos={310,489},size={110,20},proc=DoneButtonProc,title="Done Patching"
697        Button DoneButton,help={"When done Patching files, this will close this control panel."}
698        Button cat_short,pos={9,485},size={100,20},proc=DoCatShort,title="File Catalog"
699        Button cat_short,help={"Use this button to generate a notebook with file header information. Very useful for identifying files."}
700        SetVariable PS1,pos={42,111},size={338,13},proc=SetLabelVarProc,title="label"
701        SetVariable PS1,help={"Current sample label"},font="Courier",fSize=10
702        SetVariable PS1,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPS1
703        SetVariable PV1,pos={42,129},size={340,13},title="Transmission"
704        SetVariable PV1,help={"Current transmission\rvalue"},font="Courier",fSize=10
705        SetVariable PV1,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV1
706        SetVariable PV2,pos={42,147},size={340,13},title="Thickness (cm)"
707        SetVariable PV2,help={"Current sample thickness, in units of centimeters"}
708        SetVariable PV2,font="Courier",fSize=10
709        SetVariable PV2,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV2
710        SetVariable PV3,pos={42,165},size={340,13},title="Beamcenter X"
711        SetVariable PV3,help={"Current X-position of the beamcenter, in pixels"}
712        SetVariable PV3,font="Courier",fSize=10
713        SetVariable PV3,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV3
714        SetVariable PV4,pos={42,183},size={340,13},title="Beamcenter Y"
715        SetVariable PV4,help={"Current Y-position of the beamcenter, in pixels"}
716        SetVariable PV4,font="Courier",fSize=10
717        SetVariable PV4,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV4
718        SetVariable PV5,pos={42,202},size={340,13},title="Attenuator number"
719        SetVariable PV5,help={"attenuator number present during data collection"}
720        SetVariable PV5,font="Courier",fSize=10
721        SetVariable PV5,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV5
722        SetVariable PV6,pos={42,219},size={340,13},title="Counting time (s)",font="Courier",fSize=10
723        SetVariable PV6,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV6
724        SetVariable PV6,help={"total counting time in seconds"}
725        SetVariable PV7,pos={42,237},size={340,13},title="Monitor count",font="Courier",fSize=10
726        SetVariable PV7,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV7
727        SetVariable PV7,help={"total monitor counts"}
728        SetVariable PV8,pos={42,255},size={340,13},title="Detector count",font="Courier",fSize=10
729        SetVariable PV8,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV8
730        SetVariable PV8,help={"total detector counts"}
731        SetVariable PV9,pos={42,273},size={340,13},title="Trans. det. count",font="Courier",fSize=10
732        SetVariable PV9,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV9
733        SetVariable PV9,help={"Transmission\r detector counts"}
734        SetVariable PV10,pos={42,291},size={340,13},title="Wavelength (A)",font="Courier",fSize=10
735        SetVariable PV10,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV10
736        SetVariable PV10,help={"neutron wavelength in angstroms"}
737        SetVariable PV11,pos={42,309},size={340,13},title="Wavelength spread (dL/L)",font="Courier",fSize=10
738        SetVariable PV11,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV11
739        SetVariable PV11,help={"wavelength spread (delta lambda)/lambda"}
740        SetVariable PV12,pos={42,327},size={340,13},title="Temperature (C)",font="Courier",fSize=10
741        SetVariable PV12,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV12
742        SetVariable PV12,help={"Set point temperature in centigrade"}
743        SetVariable PV13,pos={42,345},size={340,13},title="Magnetic field (G)",font="Courier",fSize=10
744        SetVariable PV13,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV13
745        SetVariable PV13,help={"magnetic field strength units?"}
746        SetVariable PV14,pos={42,363},size={340,13},title="Source aperture diameter (mm)",font="Courier",fSize=10
747        SetVariable PV14,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV14
748        SetVariable PV14,help={"source aperture diameter, in millimeters"}
749        SetVariable PV15,pos={42,381},size={340,13},title="Sample aperture diameter (mm)",font="Courier",fSize=10
750        SetVariable PV15,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV15
751        SetVariable PV15,help={"sample aperture diameter, in millimeters"}
752        SetVariable PV16,pos={42,399},size={340,13},title="Source to sample distance (m)",font="Courier",fSize=10
753        SetVariable PV16,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV16
754        SetVariable PV16,help={"Source to sample distance in meters"}
755        SetVariable PV17,pos={42,417},size={340,13},title="Detector offset (cm)",font="Courier",fSize=10
756        SetVariable PV17,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV17
757        SetVariable PV17,help={"Detector offset, in centimeters"}
758        SetVariable PV18,pos={42,435},size={340,13},title="Beamstop diameter (mm)",font="Courier",fSize=10
759        SetVariable PV18,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV18
760        SetVariable PV18,help={"beamstop diamter, in millimeters (1 inch = 25.4mm)"}
761        SetVariable PV19,pos={42,453},size={340,13},title="Sample to detector distance (m)",font="Courier",fSize=10
762        SetVariable PV19,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Patch:gPV19
763        SetVariable PV19,help={"sample to detector distance, in meters"}
764       
765        CheckBox checkPS1,pos={18,108},size={20,20},title=""
766        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
767        CheckBox checkPV1,pos={18,126},size={20,20},title=""
768        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
769        CheckBox checkPV2,pos={18,144},size={20,20},title=""
770        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
771        CheckBox checkPV3,pos={18,162},size={20,20},title=""
772        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
773        CheckBox checkPV4,pos={18,180},size={20,20},title=""
774        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
775        CheckBox checkPV5,pos={18,198},size={20,20},title=""
776        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
777        CheckBox checkPV6,pos={18,216},size={20,20},title=""
778        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
779        CheckBox checkPV7,pos={18,234},size={20,20},title="",value=0
780        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
781        CheckBox checkPV8,pos={18,252},size={20,20},title="",value=0
782        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
783        CheckBox checkPV9,pos={18,270},size={20,20},title="",value=0
784        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
785        CheckBox checkPV10,pos={18,288},size={20,20},title="",value=0
786        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
787        CheckBox checkPV11,pos={18,306},size={20,20},title="",value=0
788        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
789        CheckBox checkPV12,pos={18,324},size={20,20},title="",value=0
790        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
791        CheckBox checkPV13,pos={18,342},size={20,20},title="",value=0
792        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
793        CheckBox checkPV14,pos={18,360},size={20,20},title="",value=0
794        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
795        CheckBox checkPV15,pos={18,378},size={20,20},title="",value=0
796        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
797        CheckBox checkPV16,pos={18,396},size={20,20},title="",value=0
798        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
799        CheckBox checkPV17,pos={18,414},size={20,20},title="",value=0
800        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
801        CheckBox checkPV18,pos={18,432},size={20,20},title="",value=0
802        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
803        CheckBox checkPV19,pos={18,450},size={20,20},title="",value=0
804        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
805
806        CheckBox check0,pos={18,80},size={40,15},title="Run #",value= 1,mode=1,proc=MatchCheckProc
807        CheckBox check1,pos={78,80},size={40,15},title="Text",value= 0,mode=1,proc=MatchCheckProc
808        CheckBox check2,pos={138,80},size={40,15},title="SDD",value= 0,mode=1,proc=MatchCheckProc
809
810End
811
812
813Function MatchCheckProc(name,value)
814        String name
815        Variable value
816       
817        NVAR gRadioVal= root:Packages:NIST:VSANS:Globals:Patch:gRadioVal
818       
819        strswitch (name)
820                case "check0":
821                        gRadioVal= 1
822                        break
823                case "check1":
824                        gRadioVal= 2
825                        break
826                case "check2":
827                        gRadioVal= 3
828                        break
829        endswitch
830        CheckBox check0,value= gRadioVal==1
831        CheckBox check1,value= gRadioVal==2
832        CheckBox check2,value= gRadioVal==3
833End
834
835//This function will read only the selected values editable in the patch panel
836//The values read are passed to the panel through the global variables
837//the function WriteHeaderForPatch() MUST mirror this set of reads, or nothing can be updated
838//
839//fname is the full path:name;vers to open the file
840//
841Function ReadHeaderForPatch(fname)
842        String fname
843       
844        //assign to the globals for display in the panel
845
846        // TODO -- replace ALL (get) calls below
847        // TODO -- verify that these calls are really returning what is expected by the checkbox label
848        // -- some are clearly wrong for VSANS
849       
850        // TODO -- remove the hard-wired detStr. This will require some serious interface thought.
851        String detStr = "FL"
852       
853        String/G root:Packages:NIST:VSANS:Globals:Patch:gPS1= V_getSampleDescription(fname)
854        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV1 = V_getSampleTransmission(fname)
855        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV2 = V_getSampleThickness(fname)
856        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV3 = V_getDet_beam_center_x(fname,detStr)
857        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV4 = V_getDet_beam_center_y(fname,detStr)
858        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV5 = V_getAtten_Number(fname)
859        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV6 = V_getCount_Time(fname)
860        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV7 = V_getMonitorCount(fname)
861        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV8 = V_getDet_IntegratedCount(fname,detStr)
862        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV9 = -999           // TODO no equivalent for VSANS to --getTransDetectorCounts(fname)
863        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV10 = V_getWavelength(fname)
864        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV11 = V_getWavelength_Spread(fname)
865        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV12 = -999 // TODO no equivalent yet for -- getTemperature(fname)
866        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV13 = -999 // TODO no equivalent yet for -- getFieldStrength(fname)
867        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV14 = str2num(V_getSourceAp_size(fname))
868        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV15 = V_getSampleAp2_size(fname)
869        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV16 = -999 // TODO no equivalent yet for -- getSourceToSampleDist(fname)
870        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV17 = V_getDet_LateralOffset(fname,detStr)  //TODO lateral vs vertical offset
871        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV18 = V_getBeamStopC3_size(fname)
872        Variable/G root:Packages:NIST:VSANS:Globals:Patch:gPV19 = V_getDet_ActualDistance(fname,detStr)
873       
874        Return 0
875End
876
877Function ShowPatchHelp(ctrlName) : ButtonControl
878        String ctrlName
879//      DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[Patch File Headers]"
880//      if(V_flag !=0)
881                DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found"
882//      endif
883End
884
885//button action procedure to change the selected information (checked values)
886//in each file in the popup list. This will change multiple files, and as such,
887//the user is given a chance to bail out before the whole list of files
888//is modified
889//useful for patching a series of runs with the same beamcenters, or transmissions
890//
891Function ChAllHeadersButtonProc(ctrlName) : ButtonControl
892        String ctrlName
893       
894        String msg
895        msg = "Do you really want to write all of these values to each data file in the popup list? "
896        msg += "- clicking NO will leave all files unchanged"
897        DoAlert 1,msg
898        If(V_flag == 2)
899                Abort "no files were changed"
900        Endif
901       
902        //this will change (checked) values in ALL of the headers in the popup list
903        SVAR list = root:Packages:NIST:VSANS:Globals:Patch:gPatchList
904        Variable numitems,ii
905        numitems = ItemsInList(list,";")
906       
907        if(numitems == 0)
908                Abort "no items in list for multiple patch"
909        Endif
910       
911        //read the (6) checkboxes to determine what changes to make
912        //The order/length of these waves are crucial!, set by nvars     
913        String partialName="", tempName = ""
914        Variable ok,nvars = 20
915       
916        Make/O/N=(nvars) tempChange
917        Wave w=tempchange
918        GetCheckBoxesState(w,nvars)
919        //Print "w[0] = ",w[0]
920       
921        //Get the current values in each of the fields - to pass to Write() as a textwave
922        Make/O/T/N=(nvars) tempValues
923        Wave/T wt=tempValues
924        //initialize textwave
925        ii=0
926        do
927                wt[ii] = ""
928                ii+=1
929        while(ii<nvars)
930        GetEditedSetVarBoxes(wt,nvars)
931       
932        //loop through all of the files in the list, applying changes as dictated by w and wt waves
933        ii=0
934        do
935                //get current item in the list
936                partialName = StringFromList(ii, list, ";")
937                   
938                //get a valid file based on this partialName and catPathName
939                tempName = V_FindValidFilename(partialName)
940       
941                //prepend path to tempName for read routine
942                PathInfo catPathName
943                tempName = S_path + tempName
944       
945                //make sure the file is really a RAW data file
946                ok = V_CheckIfRawData(tempName)
947                if (!ok)
948                   Print "this file is not recognized as a RAW SANS data file = ",tempName
949                else
950                   //go write the changes to the file
951                   WriteHeaderForPatch(tempName,w,wt)
952                Endif
953               
954                ii+=1
955        while(ii<numitems)
956       
957        //clean up wave before leaving
958        KillWaves/Z w,wt
959               
960End
961
962
963//simple action for button to close the panel
964//
965// cleans out the RawVSANS folder on closing
966//
967Function DoneButtonProc(ctrlName) : ButtonControl
968        String ctrlName
969
970        DoWindow/K V_Patch_Panel
971
972//      V_CleanOutRawVSANS()
973// present a progress window
974        V_CleanupData_w_Progress(0,1)   
975       
976        return(0)
977End
978
979//resets the global string corresponding to the sample label
980//updates when new text is entered
981//
982Function SetLabelVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
983        String ctrlName
984        Variable varNum
985        String varStr
986        String varName
987       
988        //reset the global variable to the entered text so that it can be relayed to the
989        //write() routine. Only the TEXT SetVariable control needs to be handled this way
990       
991        String/G root:Packages:NIST:VSANS:Globals:Patch:gPS1 = varStr
992
993End
994
995
996// testing, very dangerous batch changing of the file header labels
997//
998// testStr is the string at the front of a label, that will be moved to the "back"
999// if doIt is 1, it will write to the headers, any other value will only print to history
1000Function xMPatchLabel(testStr,doIt)
1001        String testStr
1002        Variable doIt
1003
1004//      SVAR list = root:Packages:NIST:VSANS:Globals:Patch:gPatchList
1005        String list = GetValidPatchPopupList()
1006
1007        Variable numitems,ii
1008        numitems = ItemsInList(list,";")
1009       
1010        if(numitems == 0)
1011                Abort "no items in list for multiple patch"
1012        Endif
1013       
1014        String partialName="", tempName = ""
1015        Variable ok,nvars = 20
1016       
1017        //loop through all of the files in the list, applying changes as dictated by w and wt waves
1018        string str1,str2,str3
1019        Variable match,loc,len,spc,jj,len1
1020        len=strlen(testStr)
1021        ii=0
1022        do
1023                //get current item in the list
1024                partialName = StringFromList(ii, list, ";")
1025                   
1026                //get a valid file based on this partialName and catPathName
1027                tempName = V_FindValidFilename(partialName)
1028       
1029                //prepend path to tempName for read routine
1030                PathInfo catPathName
1031                tempName = S_path + tempName
1032       
1033                //make sure the file is really a RAW data file
1034                ok = V_CheckIfRawData(tempName)
1035                if (!ok)
1036                   Print "this file is not recognized as a RAW SANS data file = ",tempName
1037                else
1038                   //go write the changes to the file
1039                        str1 = V_getSampleDescription(tempName)
1040                        match = strsearch(str1, testStr, 0)
1041                        if(match != -1)
1042                                str2 = ReplaceString(testStr, str1, "", 0, 1)
1043                               
1044                                jj=strlen(str2)
1045                                do
1046                                        jj -= 1
1047                                        spc = cmpstr(str2[jj], " ")             //can add the optional flag ,0), but I don't care about case, and Igor 6.02 is necessary...
1048                                        if (spc != 0)
1049                                                break           //no more spaces found, get out
1050                                        endif
1051                                While(1)        // jj is the location of the last non-space
1052                               
1053                                str2[jj+2,jj+1+len] = testStr
1054                       
1055                        // may need to remove leading spaces???
1056                                str2 = PadString(str2, 60, 0x20 )
1057                               
1058                                if(doIt == 1)
1059                                        V_writeSampleDescription(tempName,str2)
1060                                        print str2," ** Written to file **"
1061                                else
1062                                        //print str2,strlen(str2)
1063                                        print str2," ** Testing, not written to file **"
1064                                endif
1065                        else
1066                               
1067                                jj=strlen(str1)
1068                                do
1069                                        jj -= 1
1070                                        spc = cmpstr(str1[jj], " ")
1071                                        if (spc != 0)
1072                                                break           //no more spaces found, get out
1073                                        endif
1074                                While(1)
1075       
1076                                //print str1, jj, str1[jj]     
1077                        endif
1078                Endif
1079               
1080                ii+=1
1081        while(ii<numitems)
1082
1083
1084end
Note: See TracBrowser for help on using the repository browser.