source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Protocol_Reduction.ipf @ 1057

Last change on this file since 1057 was 1057, checked in by srkline, 5 years ago

adding the annular average option to the protocol definition and execution.

File size: 94.3 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//
8//*************************
9//////////////////////////////////
10//
11//              KEYWORD=<value> lists used in protocol definitions
12//
13//              KEYWORDS are ALWAYS capitalized, and yes, it does matter
14//
15//              for ABSOLUTE parameters
16//              (4) possible keywords, all with numerical values
17//              TSTAND=value            transmission of the standard
18//              DSTAND=value            thickness of the standard, in centimeters
19//              IZERO=value             I(q=0) value for the standard, in normalized neutron counts
20//              XSECT=value             calibrated cross-section of the standard sample
21//
22//              For calibration with a transmission file, set TSTAND, DSTAND, and XSECT to 1.0
23//              and set IZERO to KAPPA (defined in Tania's handout, or in documentation of MRED_KAP on VAX)
24//
25//
26//              For AVERAGE and for DRAWING
27//                      DRAWING routines only use a subset of the total list, since saving, naming, etc. don't apply
28//              (10) possible keywords, some numerical, some string values
29//              AVTYPE=string           string from set {Circular,Annular,Rectangular,Sector,2D_ASCII,QxQy_ASCII,PNG_Graphic;Sector_PlusMinus;}
30//              PHI=value                       azimuthal angle (-90,90)
31//              DPHI=value                      +/- angular range around phi for average
32//              WIDTH=value             total width of rectangular section, in pixels
33//              SIDE=string             string from set {left,right,both} **note NOT capitalized
34
35//              QCENTER=value           q-value (1/A) of center of annulus for annular average
36//              QDELTA=value            (+/-) width of annulus centered at QCENTER, in units of q
37//              DETGROUP=value  string with "F" or "M" to name the detector group where the annulus lies.
38
39//              PLOT=string             string from set {Yes,No} = truth of generating plot of averaged data
40//              SAVE=string             string from set {Yes,No} = truth of saving averaged data to disk, now with "Concatenate"  or "Individual"
41//              NAME=string             string from set {Auto,Manual} = Automatic name generation or Manual(dialog)
42//
43//
44//    BINTYPE=string (VSANS binning type) "One;Two;Four;Slit Mode;", as defined by ksBinTypeStr
45//
46//
47//              For work.DRK usage:
48//              **the list is COMMA delimited, separator is =
49//              DRK=none,DRKMODE=0,
50//              DRK=name                        is the name of the file, must be a full name, expected to be raw data
51//              DRKMODE=value           is a numeric value (0 or 10 to add to the Correct(mode) switch (unused?)
52//
53//////////////////////////////////
54
55
56//main entry procedure for initialzing and displaying the protocol panel
57// initilaizes folders and globals as needed
58//
59Proc V_ReductionProtocolPanel()
60        DoWindow/F V_ProtocolPanel
61        if(V_flag==0)
62                V_InitProtocolPanel()
63                V_ProtocolPanel()
64        Endif
65End
66
67//initialization procedure for the protocol panel
68//note that :gAbsStr is also shared (common global) to that used in
69//the questionnare form of the protcol (see protocol.ipf)
70//
71//0901, uses 8 points in protocol wave
72Proc V_InitProtocolPanel()
73
74        if(exists("     root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames") == 0)
75                Abort "You must generate a file catalog before building protocols"
76        endif
77       
78        //set up the global variables needed for the protocol panel
79        //global strings to put in a temporary protocol textwave
80        Variable ii=0
81        String waveStr="tempProtocol"
82        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
83        Make/O/T/N=(kNumProtocolSteps) $"root:Packages:NIST:VSANS:Globals:Protocols:tempProtocol" = ""
84
85        String/G root:Packages:NIST:VSANS:Globals:Protocols:gSAM="ask"
86        String/G root:Packages:NIST:VSANS:Globals:Protocols:gBGD="ask"
87        String/G root:Packages:NIST:VSANS:Globals:Protocols:gEMP="ask"
88        String/G root:Packages:NIST:VSANS:Globals:Protocols:gDIV="ask"
89        String/G root:Packages:NIST:VSANS:Globals:Protocols:gMASK="ask"
90        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr="ask"
91        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAVE="AVTYPE=Circular;SAVE=Yes - Concatenate;NAME=Auto;PLOT=No;BINTYPE=One;"
92        String/G root:Packages:NIST:VSANS:Globals:Protocols:gDRK="DRK=none,DRKMODE=0,"
93       
94        // global strings for trimming data are initialized in the main VSANS initilization
95        //  in case the trimming is done before the protocol panel is opened
96       
97        SetDataFolder root:
98       
99End
100
101
102//button procedure to reset the panel seletctions/checks...etc...
103//to reflect the choices in a previously saved protocol
104// - parses through the protocol and resets the appropriate global strings and
105//updates the panel display
106//
107Function V_RecallProtocolButton(ctrlName) : ButtonControl
108        String ctrlName
109
110        //will reset panel values based on a previously saved protocol
111        //pick a protocol wave from the Protocols folder
112        //MUST move to Protocols folder to get wavelist
113        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
114        Execute "V_PickAProtocol()"
115       
116        //get the selected protocol wave choice through a global string variable
117        SVAR protocolName = root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
118
119        //If "CreateNew" was selected, ask user to try again
120        if(cmpstr("CreateNew",protocolName) == 0)
121                Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol"
122        Endif
123       
124        //reset the panel based on the protocol textwave (currently a string)
125        V_ResetToSavedProtocol(protocolName)
126       
127        SetDataFolder root:
128        return(0)
129End
130
131//deletes the selected protocol from the list and from memory
132//
133Function V_DeleteProtocolButton(ctrlName) : ButtonControl
134        String ctrlName
135
136        //put up a list of protocols and pick one
137        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
138//      Execute "DeleteAProtocol()"
139        String Protocol=""
140        Prompt Protocol "Delete A Protocol",popup, V_DeletableProtocols()
141        DoPrompt "Select protocol to delete",protocol
142        If(V_flag==1)
143                return(0)
144        endif
145
146        //If "CreateNew, Base, DoAll, or tempProtocol" was selected, do nothing
147        strswitch(protocol)
148                case "CreateNew":
149                        break
150                case "DoAll":
151                        break
152                case "Base":
153                        break
154                case "tempProtocol":
155                        break
156                default:
157                        //delete the protocol
158                        KillWaves/Z $protocol
159        endswitch
160       
161        SetDataFolder root:
162        return(0)
163End
164
165//
166//function that actually parses the protocol specified by nameStr
167//which is just the name of the wave, without a datafolder path
168//
169// TODO
170//  -- update this for 12 steps
171//
172Function V_ResetToSavedProtocol(nameStr)
173        String nameStr
174       
175        //allow special cases of Base and DoAll Protocols to be recalled to panel - since they "ask"
176        //and don't need paths
177       
178        String catPathStr
179        PathInfo catPathName
180        catPathStr=S_path
181       
182        //SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols              //on windows, data folder seems to get reset (erratically) to root:
183        Wave/T w=$("root:Packages:NIST:VSANS:Globals:Protocols:" + nameStr)
184       
185        String fullPath="",comma=",",list="",nameList="",PathStr="",item=""
186        Variable ii=0,numItems,checked,specialProtocol
187       
188        if((cmpstr(nameStr,"Base")==0) || (cmpstr(nameStr,"DoAll")==0))
189                specialProtocol = 1
190        else
191                specialProtocol = 0
192        Endif
193       
194        //background
195        checked = 1
196        nameList = w[0]
197        If(cmpstr(nameList,"none") ==0)
198                checked = 0
199        Endif
200
201        //set the global string to display and checkbox
202        String/G root:Packages:NIST:VSANS:Globals:Protocols:gBGD = nameList
203        CheckBox prot_check win=V_ProtocolPanel,value=checked
204       
205        //empty
206        checked = 1
207        nameList = w[1]
208        If(cmpstr(nameList,"none") ==0)
209                checked = 0
210        Endif
211
212        //set the global string to display and checkbox
213        String/G root:Packages:NIST:VSANS:Globals:Protocols:gEMP = nameList
214        CheckBox prot_check_1 win=V_ProtocolPanel,value=checked
215       
216        //DIV file
217        checked = 1
218        nameList = w[2]
219        If(cmpstr(nameList,"none") ==0)
220                checked = 0
221        Endif
222
223        //set the global string to display and checkbox
224        String/G root:Packages:NIST:VSANS:Globals:Protocols:gDIV = nameList
225        CheckBox prot_check_2 win=V_ProtocolPanel,value=checked
226       
227        //Mask file
228        checked = 1
229        nameList = w[3]
230        If(cmpstr(nameList,"none") ==0)
231                checked = 0
232        Endif
233
234        //set the global string to display and checkbox
235        String/G root:Packages:NIST:VSANS:Globals:Protocols:gMASK = nameList
236        CheckBox prot_check_3 win=V_ProtocolPanel,value=checked
237       
238        //4 = abs parameters
239        list = w[4]
240        numItems = ItemsInList(list,";")
241        checked = 1
242        if(numitems == 4 || numitems == 5)              //allow for protocols with no SDEV list item
243                //correct number of parameters, assume ok
244                String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr = list
245                CheckBox prot_check_9 win=V_ProtocolPanel,value=checked
246        else
247                item = StringFromList(0,list,";")
248                if(cmpstr(item,"none")==0)
249                        checked = 0
250                        list = "none"
251                        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr = list
252                        CheckBox prot_check_9 win=V_ProtocolPanel,value=checked
253                else
254                        //force to "ask"
255                        checked = 1
256                        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr = "ask"
257                        CheckBox prot_check_9 win=V_ProtocolPanel,value=checked
258                Endif
259        Endif
260       
261        //5 = averaging choices
262        list = w[5]
263        item = StringByKey("AVTYPE",list,"=",";")
264        if(cmpstr(item,"none") == 0)
265                checked = 0
266                String/G root:Packages:NIST:VSANS:Globals:Protocols:gAVE = "none"
267                CheckBox prot_check_5 win=V_ProtocolPanel,value=checked
268        else
269                checked = 1
270                String/G root:Packages:NIST:VSANS:Globals:Protocols:gAVE = list
271                CheckBox prot_check_5 win=V_ProtocolPanel,value=checked
272        Endif
273       
274//      //6 = DRK choice
275//      list = w[6]
276//      item = StringByKey("DRK",list,"=",",")
277//      //print list,item
278//      if(cmpstr(item,"none") == 0)
279//              checked = 0
280//              String/G root:Packages:NIST:VSANS:Globals:Protocols:gDRK = list
281//              CheckBox prot_check_6 win=V_ProtocolPanel,value=checked
282//      else
283//              checked = 1
284//              String/G root:Packages:NIST:VSANS:Globals:Protocols:gDRK = list
285//              CheckBox prot_check_6 win=V_ProtocolPanel,value=checked
286//      Endif
287       
288        //7 = beginning trim points
289        SVAR gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
290        gBegPtsStr = w[7]
291        //8 = end trim points
292        SVAR gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
293        gEndPtsStr = w[8]
294       
295        //9 = unused
296        //10 = unused
297        //11 = unused
298
299
300        //all has been reset, get out
301        Return (0)
302End
303
304//button action procedure that simply closes the panel
305//
306Function V_DoneProtocolButton(ctrlName) : ButtonControl
307        String ctrlName
308
309        //will gracefully close and exit the protocol panel
310       
311        DoWindow/K V_ProtocolPanel
312End
313
314//button action procedure that saves the current choices on the panel
315//as a named protocol, for later recall
316//asks for a valid name, then creates a protocol from the panel choices
317//creates a wave, and sets the current protocol name to this new protocol
318//
319//now allows the user the choice to overwrite a protocol
320//
321Function V_SaveProtocolButton(ctrlName) : ButtonControl
322        String ctrlName
323
324        Variable notDone=1, newProto=1
325        //will prompt for protocol name, and save the protocol as a text wave
326        //prompt for name of new protocol wave to save
327        do
328                Execute "V_AskForName()"
329                SVAR newProtocol = root:Packages:NIST:VSANS:Globals:Protocols:gNewStr
330               
331                //make sure it's a valid IGOR name
332                newProtocol = CleanupName(newProtocol,0)        //strict naming convention
333                String/G root:Packages:NIST:VSANS:Globals:Protocols:gNewStr=newProtocol         //reassign, if changed
334                Print "newProtocol = ",newProtocol
335               
336                SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
337                if(WaveExists( $("root:Packages:NIST:VSANS:Globals:Protocols:" + newProtocol) ) == 1)
338                        //wave already exists
339                        DoAlert 1,"That name is already in use. Do you wish to overwrite the existing protocol?"
340                        if(V_Flag==1)
341                                notDone = 0
342                                newProto = 0
343                        else
344                                notDone = 1
345                        endif
346                else
347                        //name is good
348                        notDone = 0
349                Endif
350        while(notDone)
351       
352        //current data folder is  root:Packages:NIST:VSANS:Globals:Protocols
353        if(newProto)
354                Make/O/T/N=(kNumProtocolSteps) $("root:Packages:NIST:VSANS:Globals:Protocols:" + newProtocol)
355        Endif
356       
357        V_MakeProtocolFromPanel( $("root:Packages:NIST:VSANS:Globals:Protocols:" + newProtocol) )
358        String/G  root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = newProtocol
359       
360        //the data folder WAS changed above, this must be reset to root:
361        SetDatafolder root:
362End
363
364//function that does the guts of reading the panel controls and globals
365//to create the necessary text fields for a protocol
366//Wave/T w (input) is an empty text wave of 8 elements for the protocol
367//on output, w[] is filled with the protocol strings as needed from the panel
368//
369// TODO
370// -- update for 12 points
371//
372Function V_MakeProtocolFromPanel(w)
373        Wave/T w
374       
375        //construct the protocol text wave form the panel
376        //it is to be parsed by ExecuteProtocol() for the actual data reduction
377        PathInfo catPathName                    //this is where the files came from
378        String pathstr=S_path,tempStr,curList
379        Variable checked,ii,numItems
380       
381        //look for checkbox, then take each item in list and prepend the path
382        //w[0] = background
383        ControlInfo/W=V_ProtocolPanel prot_check
384        checked = V_value
385        if(checked)
386                //build the list
387                //just read the global
388                SVAR str=root:Packages:NIST:VSANS:Globals:Protocols:gBGD
389                if(cmpstr(str,"ask")==0)
390                        w[0] = str              //just ask
391                else
392                        tempstr = V_ParseRunNumberList(str)
393                        if(strlen(tempStr)==0)
394                                return(1)                               //error parsing list
395                        else
396                                w[0] = tempstr
397                                str = tempstr           //set the protocol and the global
398                        endif
399                endif
400        else
401                //none used - set textwave (and global?)
402                w[0] = "none"
403                String/G root:Packages:NIST:VSANS:Globals:Protocols:gBGD = "none"
404        endif
405       
406        //w[1] = empty
407        ControlInfo/W=V_ProtocolPanel prot_check_1
408        checked = V_value
409        if(checked)
410                //build the list
411                //just read the global
412                SVAR str=root:Packages:NIST:VSANS:Globals:Protocols:gEMP
413                if(cmpstr(str,"ask")==0)
414                        w[1] = str
415                else
416                        tempstr = V_ParseRunNumberList(str)
417                        if(strlen(tempStr)==0)
418                                return(1)
419                        else
420                                w[1] = tempstr
421                                str=tempStr
422                        endif
423                endif
424        else
425                //none used - set textwave (and global?)
426                w[1] = "none"
427                String/G root:Packages:NIST:VSANS:Globals:Protocols:gEMP = "none"
428        endif
429       
430        //w[2] = div file
431        ControlInfo/W=V_ProtocolPanel prot_check_2
432        checked = V_value
433        if(checked)
434                //build the list
435                //just read the global
436                SVAR str=root:Packages:NIST:VSANS:Globals:Protocols:gDIV
437                if(cmpstr(str,"ask")==0)
438                        w[2] = str
439                else
440                        tempStr = V_ParseRunNumberList(str)
441                        if(strlen(tempStr)==0)
442                                return(1)
443                        else
444                                w[2] = tempstr
445                                str=tempstr
446                        endif
447                endif
448        else
449                //none used - set textwave (and global?)
450                w[2] = "none"
451                String/G root:Packages:NIST:VSANS:Globals:Protocols:gDIV = "none"
452        endif
453       
454        //w[3] = mask file
455        ControlInfo/W=V_ProtocolPanel prot_check_3
456        checked = V_value
457        if(checked)
458                //build the list
459                //just read the global
460                SVAR str=root:Packages:NIST:VSANS:Globals:Protocols:gMASK
461                if(cmpstr(str,"ask")==0)
462                        w[3] = str
463                else
464                        tempstr = V_ParseRunNumberList(str)
465                        if(strlen(tempstr)==0)
466                                return(1)
467                        else
468                                w[3] = tempstr
469                                str = tempstr
470                        endif
471                endif
472        else
473                //none used - set textwave (and global?)
474                w[3] = "none"
475                String/G root:Packages:NIST:VSANS:Globals:Protocols:gMASK = "none"
476        endif
477       
478        //w[4] = abs parameters
479        ControlInfo/W=V_ProtocolPanel prot_check_9
480        checked = V_value
481        if(checked)
482                //build the list
483                //just read the global
484                SVAR str=root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr
485                w[4] = str
486        else
487                //none used - set textwave (and global?)
488                w[4] = "none"
489                String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr = "none"
490        endif
491       
492        //w[5] = averaging choices
493        ControlInfo/W=V_ProtocolPanel prot_check_5                      //do the average?
494        checked = V_value
495        if(checked)
496                //just read the global
497                SVAR avestr=root:Packages:NIST:VSANS:Globals:Protocols:gAVE
498                w[5] = avestr
499        else
500                //none used - set textwave
501                w[5] = "AVTYPE=none;"
502        endif
503       
504        //w[6]
505        //work.DRK information
506        SVAR drkStr=root:Packages:NIST:VSANS:Globals:Protocols:gDRK
507        w[6] = drkStr
508       
509        //w[7]
510        // beginning trim points
511        SVAR gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
512        w[7] = gBegPtsStr
513       
514        //w[8]
515        // End trim points
516        SVAR gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr   
517        w[8] = gEndPtsStr
518       
519        //w[9]
520        //currently unused
521        w[9] = ""
522        //w[10]
523        //currently unused
524        w[10] = ""
525        //w[11]
526        //currently unused
527        w[11] = ""
528               
529        return(0)
530End
531
532
533//
534Function V_PickSAMButton(ctrlName) : ButtonControl
535        String ctrlName
536
537
538End
539
540
541
542
543//
544// TODO
545// -- identifying "intent" using V_get can be very slow, since it reads in each and every data file.
546//   grep is a lot faster, but there can be a lot of false "hits" unless I do it correctly.
547//
548//
549//      //grep through what text I can find in the VAX binary
550//      // Grep Note: the \\b sequences limit matches to a word boundary before and after
551//      // "boondoggle", so "boondoggles" and "aboondoggle" won't match.
552//      if(gRadioVal == 2)
553//              for(ii=0;ii<num;ii+=1)
554//                      item=StringFromList(ii, newList , ";")
555////                    Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
556//                      Grep/P=catPathName/Q/E=("(?i)"+match) item
557//                      if( V_value )   // at least one instance was found
558////                            Print "found ", item,ii
559//                              list += item + ";"
560//                      endif
561//              endfor
562//
563//              newList = list
564//      endif
565
566// match is the string to look for in the search
567// 0 is a flag to tell it to look in the file catalog (the fastest method)
568// Other options are to grep, or to read the intent field in every file
569Function/S V_GetSAMList()
570
571        String match="SAMPLE"
572        String list = V_getFileIntentList(match,0)
573
574//      Printf "SAM files = %s\r",list 
575        return(list)
576end
577
578
579Function/S V_GetBGDList()
580
581        String match="BLOCKED BEAM"
582        String list = V_getFileIntentList(match,0)
583
584//      Printf "BGD files = %s\r",list 
585        return(list)
586end
587
588
589Function/S V_GetEMPList()
590
591        String match="EMPTY CELL"
592        String list = V_getFileIntentList(match,0)
593
594//      Printf "EMP files = %s\r",list 
595        return(list)
596end
597
598
599// testStr is the "intent" string, or grep string
600// method is the method to use to find the file
601// 0 = (default) is to use the file catalog (= fastest)
602// 1 = Grep (not terribly slow)
603// 2 = read every file (bad choice)
604//
605Function/S V_getFileIntentList(testStr,method)
606        String testStr
607        Variable method
608       
609        Variable ii,num
610        String list="",item="",fname,newList,intent
611
612        // read every file...
613        if(method == 2)
614                PathInfo catPathName
615                String path = S_path
616                newList = V_GetRawDataFileList()
617                num=ItemsInList(newList)
618               
619                for(ii=0;ii<num;ii+=1)
620                        item=StringFromList(ii, newList , ";")
621                        fname = path + item
622                        intent = V_getReduction_intent(fname)
623                        if(cmpstr(intent,testStr) == 0)
624                                list += item + ";"
625                        endif
626                endfor 
627        endif
628       
629        // use Grep
630        if(method == 1)
631                newList = V_GetRawDataFileList()
632                num=ItemsInList(newList)
633                for(ii=0;ii<num;ii+=1)
634                        item=StringFromList(ii, newList , ";")
635                        Grep/P=catPathName/Q/E=("(?i)"+testStr) item
636                        if( V_value )   // at least one instance was found
637        //                              Print "found ", item,ii
638                                list += item + ";"
639                        endif
640                endfor 
641       
642        else
643        // get the list from the file catalog
644       
645                WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
646                WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
647               
648                Variable np = numpnts(intentW)          //fileNameW is LONGER - so don't use numpnts(fileWave)
649                for(ii=0;ii<np;ii+=1)
650                        if(cmpstr(intentW[ii],testStr)==0)              //this is case-INSENSITIVE (necessary, since the case is unknown)
651                                list += fileNameW[ii] + ";"
652                        endif           
653                endfor
654               
655                List = SortList(List,";",0)
656        endif
657       
658        return(list)
659end
660
661//
662// TODO
663// -- decide on the way to locate the blocked beam files. Is the enumerated text of the intent
664//    sufficiently unique to locate the file?
665// -- can I use the Data Catalog waves to locate the files  - faster?
666//    (fails if the catalog has not been read in recently enough)
667//
668//
669Function/S V_PickBGDButton(ctrlName) : ButtonControl
670        String ctrlName
671
672        String list="",item="",fname,newList,intent
673        Variable ii,num
674       
675        PathInfo catPathName
676        String path = S_path
677
678        String match="BLOCKED BEAM"
679
680//v_tic()
681// get the list from the file catalog (=0.0007s)
682//     
683        WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
684        WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
685       
686        Variable np = numpnts(intentW)
687        for(ii=0;ii<np;ii+=1)
688                if(cmpstr(intentW[ii],match)==0)
689                        list += fileNameW[ii] + ";"
690                endif           
691        endfor
692       
693        List = SortList(List,";",0)
694        Printf "BGD files = %s\r",list 
695//v_toc()       
696       
697       
698////v_tic()                     // from grep = 3.3s
699//      newList = V_GetRawDataFileList()
700//      num=ItemsInList(newList)
701//     
702////    for(ii=0;ii<num;ii+=1)
703////            item=StringFromList(ii, newList , ";")
704////            fname = path + item
705////            intent = V_getReduction_intent(fname)
706////            if(cmpstr(intent,"BLOCKED BEAM") == 0)
707////                    list += item + ";"
708////            endif
709////
710////    endfor
711//      list = ""       
712//      for(ii=0;ii<num;ii+=1)
713//              item=StringFromList(ii, newList , ";")
714//              Grep/P=catPathName/Q/E=("(?i)"+match) item
715//              if( V_value )   // at least one instance was found
716////                            Print "found ", item,ii
717//                      list += item + ";"
718//              endif
719//      endfor
720//             
721//             
722//      List = SortList(List,";",0)
723//      Printf "BGD files = %s\r",list
724////v_toc()
725       
726        return(list)
727End
728
729
730//
731Function/S V_PickEMPButton(ctrlName) : ButtonControl
732        String ctrlName
733        String list="",item="",fname,newList,intent
734        Variable ii,num
735       
736        PathInfo catPathName
737        String path = S_path
738
739        String match="EMPTY CELL"
740
741// get the list from the file catalog (=0.0007s)
742//     
743        WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
744        WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
745       
746        Variable np = numpnts(intentW)
747        for(ii=0;ii<np;ii+=1)
748                if(cmpstr(intentW[ii],match)==0)
749                        list += fileNameW[ii] + ";"
750                endif           
751        endfor
752       
753        List = SortList(List,";",0)
754        Printf "EMP files = %s\r",list 
755
756
757//     
758//      newList = V_GetRawDataFileList()
759//      num=ItemsInList(newList)
760//     
761////    for(ii=0;ii<num;ii+=1)
762////            item=StringFromList(ii, newList , ";")
763////            fname = path + item
764////            intent = V_getReduction_intent(fname)
765////            if(cmpstr(intent,"EMPTY CELL") == 0)
766////                    list += item + ";"
767////            endif
768////
769////    endfor
770//
771//      for(ii=0;ii<num;ii+=1)
772//              item=StringFromList(ii, newList , ";")
773//              Grep/P=catPathName/Q/E=("(?i)"+match) item
774//              if( V_value )   // at least one instance was found
775////                            Print "found ", item,ii
776//                      list += item + ";"
777//              endif
778//
779//      endfor
780//             
781//      List = SortList(List,";",0)
782//      Printf "EMP files = %s\r",list
783       
784        return(list)
785End
786
787
788//
789Function/S V_PickEMPBeamButton(ctrlName) : ButtonControl
790        String ctrlName
791        String list="",item="",fname,newList,intent
792        Variable ii,num
793       
794        PathInfo catPathName
795        String path = S_path
796
797        String match="EMPTY BEAM"
798
799// get the list from the file catalog (=0.0007s)
800//     
801        WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
802        WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
803       
804        Variable np = numpnts(intentW)
805        for(ii=0;ii<np;ii+=1)
806                if(cmpstr(intentW[ii],match)==0)
807                        list += fileNameW[ii] + ";"
808                endif           
809        endfor
810       
811        List = SortList(List,";",0)
812        Printf "EMP Beam files = %s\r",list     
813
814
815
816       
817        return(list)
818End
819
820Function/S V_GetDIVList()
821
822        String list="",item="",fname,newList,intent
823        Variable ii,num
824       
825        PathInfo catPathName
826        String path = S_path
827       
828        newList = V_Get_NotRawDataFileList()
829        num=ItemsInList(newList)
830       
831//      for(ii=0;ii<num;ii+=1)
832//              item=StringFromList(ii, newList , ";")
833//              fname = path + item
834//              intent = V_getReduction_intent(fname)
835//              if(cmpstr(intent,"SENSITIVITY") == 0)
836//                      list += item + ";"
837//              endif
838//
839//      endfor
840
841        String match="DIV"
842        for(ii=0;ii<num;ii+=1)
843                item=StringFromList(ii, newList , ";")
844                Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
845//              Grep/P=catPathName/Q/E=("(?i)"+match) item
846                if( V_value )   // at least one instance was found
847//                              Print "found ", item,ii
848                        if(strsearch(item,"pxp",0,2) == -1)             //does NOT contain .pxp (the current experiment will be a match)
849                                list += item + ";"
850                        endif
851                endif
852        endfor
853               
854        List = SortList(List,";",0)
855
856        return(list)
857end
858
859// TODO
860// -- find proper way to search for these files
861// -- they *may* be written to the file header(reduction block)
862// -- or grep for VSANS_DIV (in the title)
863Function/S V_PickDIVButton(ctrlName) : ButtonControl
864        String ctrlName
865        String list="",item="",fname,newList,intent
866        Variable ii,num
867       
868        PathInfo catPathName
869        String path = S_path
870       
871        newList = V_Get_NotRawDataFileList()
872        num=ItemsInList(newList)
873       
874//      for(ii=0;ii<num;ii+=1)
875//              item=StringFromList(ii, newList , ";")
876//              fname = path + item
877//              intent = V_getReduction_intent(fname)
878//              if(cmpstr(intent,"SENSITIVITY") == 0)
879//                      list += item + ";"
880//              endif
881//
882//      endfor
883
884        String match="VSANS_DIV"                //this is part of the title of a VSANS DIV file
885        for(ii=0;ii<num;ii+=1)
886                item=StringFromList(ii, newList , ";")
887                Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
888//              Grep/P=catPathName/Q/E=("(?i)"+match) item
889                if( V_value )   // at least one instance was found
890//                              Print "found ", item,ii
891                                list += item + ";"
892                endif
893
894        endfor
895               
896        List = SortList(List,";",0)
897        Printf "DIV files = %s\r",list
898       
899        return(list)
900
901End
902
903Function/S V_GetMSKList()
904
905        String list="",item="",fname,newList,intent
906        Variable ii,num
907       
908        PathInfo catPathName
909        String path = S_path
910       
911        newList = V_Get_NotRawDataFileList()
912        num=ItemsInList(newList)
913       
914//      for(ii=0;ii<num;ii+=1)
915//              item=StringFromList(ii, newList , ";")
916//              fname = path + item
917//              intent = V_getReduction_intent(fname)
918//              if(cmpstr(intent,"SENSITIVITY") == 0)
919//                      list += item + ";"
920//              endif
921//
922//      endfor
923
924//      String match="MASK"             // this is part of the title of a VSANS MASK file
925        String match="VSANS_MASK"               // this is part of the title of a VSANS MASK file
926        for(ii=0;ii<num;ii+=1)
927                item=StringFromList(ii, newList , ";")
928                Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
929//              Grep/P=catPathName/Q/E=("(?i)"+match) item
930                if( V_value )   // at least one instance was found
931//                              Print "found ", item,ii
932                        if(strsearch(item,"pxp",0,2) == -1)             //does NOT contain .pxp (the current experiment will be a match)
933                                list += item + ";"
934                        endif
935                endif
936
937        endfor
938               
939        List = SortList(List,";",0)
940
941        return(list)
942end
943
944
945//
946// TODO
947// -- find proper way to search for these files
948// -- they *may* be written to the file header(reduction block)
949// -- or grep for VSANS_MASK (in the title)
950Function/S V_PickMASKButton(ctrlName) : ButtonControl
951        String ctrlName
952        String list="",item="",fname,newList,intent
953        Variable ii,num
954       
955        PathInfo catPathName
956        String path = S_path
957       
958        newList = V_Get_NotRawDataFileList()
959        num=ItemsInList(newList)
960       
961//      for(ii=0;ii<num;ii+=1)
962//              item=StringFromList(ii, newList , ";")
963//              fname = path + item
964//              intent = V_getReduction_intent(fname)
965//              if(cmpstr(intent,"MASK") == 0)
966//                      list += item + ";"
967//              endif
968//
969//      endfor
970
971        String match="MASK"
972        for(ii=0;ii<num;ii+=1)
973                item=StringFromList(ii, newList , ";")
974                Grep/P=catPathName/Q/E=("(?i)\\b"+match+"\\b") item
975//              Grep/P=catPathName/Q/E=("(?i)"+match) item
976                if( V_value )   // at least one instance was found
977//                              Print "found ", item,ii
978                        list += item + ";"
979                endif
980
981        endfor
982               
983        List = SortList(List,";",0)
984        Printf "MASK files = %s\r",list
985       
986        return(list)   
987
988       
989End
990
991//button action function to reduce one file with the information specified on
992//the panel
993//a temporary protocol is created, even if the fields correspond to a named protocol
994//(only the protocol wave values are written to the data header, but the name is written to the
995//schematic - this could cause some unwanted confusion)
996//
997//if a sample file(s) is selected, only that file(s) will be reduced
998//if no file is selected, the user will be prompted with a standard open
999//dialog to select sample data file(s)
1000//
1001Function V_ReduceOneButton(ctrlName) : ButtonControl
1002        String ctrlName
1003
1004        //parse the information on the panel and assign to tempProtocol wave (in protocol folder)
1005        //and execute
1006        String temp="root:Packages:NIST:VSANS:Globals:Protocols:tempProtocol"
1007        Wave/T w=$temp
1008        Variable ii=0,num=12
1009        do
1010                w[ii] = ""
1011                ii+=1
1012        while(ii<num)
1013       
1014        V_MakeProtocolFromPanel(w)
1015
1016        //the "current" protocol is the "tempProtocol" that was parsed from the panel input
1017        //set the global, so that the data writing routine can find the protocol wave (fatal otherwise)
1018        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr="tempProtocol"
1019       
1020        PathInfo catPathName                    //this is where the files came from
1021        String pathstr=S_path,samStr
1022       
1023        //take the string from the panel
1024        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gSAM
1025       
1026        if( (strlen(tempStr) == 0) || (cmpstr(tempStr,"ask")==0) )
1027                //let user select the files
1028                tempStr="ask"
1029                V_ExecuteProtocol(temp,tempStr)
1030                return(0)
1031        Else
1032                //parse the list of numbers
1033                //send only the filenames, without paths
1034                samStr = V_ParseRunNumberList(tempStr)
1035                If(strlen(samStr)==0)
1036                        DoAlert 0,"The SAM file number cound not be interpreted. Please enter a valid run number or filename"
1037                        return(1)
1038                endif
1039                tempStr=samStr          //reset the global
1040                V_ExecuteProtocol(temp,samStr)
1041                return(0)
1042        endif
1043End
1044
1045
1046//button action function will prompt user for absolute scaling parameters
1047//either from an empty beam file or by manually entering the 4 required values
1048//uses the same function and shared global string as the questionnare form of reduction
1049//in "protocol.ipf" - the string is root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr
1050//
1051Function V_SetABSParamsButton(ctrlName) : ButtonControl
1052        String ctrlName
1053
1054        //will prompt for a list of ABS parameters (4) through a global string variable
1055       
1056        Execute "V_AskForAbsoluteParams_Quest()"
1057       
1058End
1059
1060
1061
1062//the panel recreation macro
1063//
1064Window V_ProtocolPanel()
1065        PauseUpdate; Silent 1           // building window...
1066        NewPanel /W=(1280,332,1630,932) /K=1 as "VSANS Reduction Protocol"
1067        ModifyPanel cbRGB=(56589,50441,50159), fixedSize=1
1068        SetDrawLayer UserBack
1069        DrawLine 3,65,301,65
1070        DrawLine 3,157,301,157
1071        DrawLine 3,208,301,208
1072        DrawLine 3,257,301,257
1073        DrawLine 3,305,301,305
1074        DrawLine 3,350,301,350
1075        DrawLine 3,445,301,445
1076        DrawLine 3,513,301,513
1077        DrawLine 3,396,301,396
1078
1079//
1080        Button button_help,pos={300,2},size={25,20},proc=V_ShowProtoHelp,title="?"
1081        Button button_help,help={"Show the help file for setting up a reduction protocol"}
1082        Button button_quest,pos={20,2},size={150,20},proc=V_ProtocolQuestionnaire,title="Questions"
1083        Button button_quest,help={"Run through the questionnaire for setting up a reduction protocol"}
1084        Button button_quest,disable=2
1085
1086
1087        PopupMenu popup_sam,pos={85,68},size={51,23},proc=SAMFilePopMenuProc
1088        PopupMenu popup_sam,mode=1,value= #"V_getSAMList()"     
1089        PopupMenu popup_bkg,pos={85,164},size={51,23},proc=BKGFilePopMenuProc
1090        PopupMenu popup_bkg,mode=1,value= #"V_getBGDList()"
1091        PopupMenu popup_emp,pos={85,213},size={51,23},proc=EMPFilePopMenuProc
1092        PopupMenu popup_emp,mode=1,value= #"V_getEMPList()"
1093        PopupMenu popup_div,pos={85,263},size={51,23},proc=DIVFilePopMenuProc
1094        PopupMenu popup_div,mode=1,value= #"V_getDIVList()"
1095        PopupMenu popup_msk,pos={85,356},size={51,23},proc=MSKFilePopMenuProc
1096        PopupMenu popup_msk,mode=1,value= #"V_getMSKList()"     
1097               
1098               
1099        CheckBox prot_check,pos={6,163},size={74,14},title="Background"
1100        CheckBox prot_check,help={"If checked, the specified background file will be included in the data reduction. If the file name is \"ask\", then the user will be prompted for the file"}
1101        CheckBox prot_check,value= 1
1102        CheckBox prot_check_1,pos={6,215},size={71,14},title="Empty Cell"
1103        CheckBox prot_check_1,help={"If checked, the specified empty cell file will be included in the data reduction. If the file name is \"ask\", then the user will be prompted for the file"}
1104        CheckBox prot_check_1,value= 1
1105        CheckBox prot_check_2,pos={6,263},size={72,14},title="Sensitivity"
1106        CheckBox prot_check_2,help={"If checked, the specified detector sensitivity file will be included in the data reduction. If the file name is \"ask\", then the user will be prompted for the file"}
1107        CheckBox prot_check_2,value= 1
1108        CheckBox prot_check_3,pos={6,356},size={43,14},title="Mask"
1109        CheckBox prot_check_3,help={"If checked, the specified mask file will be included in the data reduction. If the file name is \"ask\", then the user will be prompted for the file"}
1110        CheckBox prot_check_3,value= 1
1111        CheckBox prot_check_4,pos={6,70},size={53,14},title="Sample"
1112        CheckBox prot_check_4,help={"If checked, the specified sample file will be included in the data reduction. If the file name is \"ask\", then the user will be prompted for the file"}
1113        CheckBox prot_check_4,value= 1
1114        CheckBox prot_check_5,pos={6,399},size={56,14},title="Average"
1115        CheckBox prot_check_5,help={"If checked, the specified averaging will be performed at the end of the data reduction."}
1116        CheckBox prot_check_5,value= 1 
1117        CheckBox prot_check_9,pos={6,310},size={59,14},title="Absolute"
1118        CheckBox prot_check_9,help={"If checked, absolute calibration will be included in the data reduction. If the parameter list is \"ask\", then the user will be prompted for absolue parameters"}
1119        CheckBox prot_check_9,value= 1
1120       
1121
1122//      Button pick_sam,pos={214,28},size={70,20},proc=V_PickSAMButton,title="set SAM"
1123//      Button pick_sam,help={"This button will set the file selected in the File Catalog table to be the sample file"}
1124//      Button pick_bgd,pos={214,75},size={70,20},proc=V_PickBGDButton,title="set BGD"
1125//      Button pick_bgd,help={"This button will set the file selected in the File Catalog table to be the background file."}
1126//      Button pick_emp,pos={214,125},size={70,20},proc=V_PickEMPButton,title="set EMP"
1127//      Button pick_emp,help={"This button will set the file selected in the File Catalog table to be the empty cell file."}
1128//      Button pick_DIV,pos={214,173},size={70,20},proc=V_PickDIVButton,title="set DIV"
1129//      Button pick_DIV,help={"This button will set the file selected in the File Catalog table to be the sensitivity file."}
1130        Button pick_ABS,pos={264,308},size={70,20},proc=V_SetABSParamsButton,title="set ABS"
1131        Button pick_ABS,help={"This button will prompt the user for absolute scaling parameters"}       
1132//      Button pick_MASK,pos={214,266},size={70,20},proc=V_PickMASKButton,title="set MASK"
1133//      Button pick_MASK,help={"This button will set the file selected in the File Catalog table to be the mask file."}
1134
1135
1136        Button pick_AVE,pos={188,401},size={150,20},proc=V_SetAverageParamsButtonProc,title="set AVERAGE params"
1137        Button pick_AVE,help={"Prompts the user for the type of 1-D averaging to perform, as well as saving options"}
1138
1139       
1140        Button pick_trim,pos={264,454},size={70,20},proc=V_TrimDataProtoButton,title="Trim"
1141        Button pick_trim,help={"This button will prompt the user for trimming parameters"}     
1142       
1143       
1144        SetVariable samStr,pos={6,90},size={250,15},title="file:"
1145        SetVariable samStr,help={"Filename of the sample file(s) to be used in the data reduction"}
1146        SetVariable samStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gSAM           
1147        SetVariable bgdStr,pos={7,186},size={250,15},title="file:"
1148        SetVariable bgdStr,help={"Filename of the background file(s) to be used in the data reduction"}
1149        SetVariable bgdStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gBGD
1150        SetVariable empStr,pos={8,236},size={250,15},title="file:"
1151        SetVariable empStr,help={"Filename of the empty cell file(s) to be used in the data reduction"}
1152        SetVariable empStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gEMP
1153        SetVariable divStr,pos={9,285},size={250,15},title="file:"
1154        SetVariable divStr,help={"Filename of the detector sensitivity file to be used in the data reduction"}
1155        SetVariable divStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gDIV
1156        SetVariable maskStr,pos={9,377},size={250,15},title="file:"
1157        SetVariable maskStr,help={"Filename of the mask file to be used in the data reduction"}
1158        SetVariable maskStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gMASK
1159        SetVariable absStr,pos={7,331},size={250,15},title="parameters:"
1160        SetVariable absStr,help={"Keyword-string of values necessary for absolute scaling of data. Remaining parameters are taken from the sample file."}
1161        SetVariable absStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr
1162        SetVariable aveStr,pos={9,424},size={250,15},title="parameters:"
1163        SetVariable aveStr,help={"Keyword-string of choices used for averaging and saving the 1-D data files"}
1164        SetVariable aveStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gAVE
1165
1166        SetVariable begStr,pos={9,464},size={250,15},title="Beg Trim:"
1167        SetVariable begStr,help={"Keyword-string of choices used for averaging and saving the 1-D data files"}
1168        SetVariable begStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
1169        SetVariable endStr,pos={9,484},size={250,15},title="End Trim:"
1170        SetVariable endStr,help={"Keyword-string of choices used for averaging and saving the 1-D data files"}
1171        SetVariable endStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
1172
1173
1174       
1175        //only show DRK if user wants to see it
1176        //if global = 1,then show => set disable = 0
1177//      CheckBox prot_check_6,pos={6,363},size={113,14},proc=DrkCheckProc,title="Use DRK correction"
1178//      CheckBox prot_check_6,help={"If checked, the selected file will be used for DRK correction. Typically this is NOT checked"}
1179//      CheckBox prot_check_6,value= 0,disable = (!root:Packages:NIST:gAllowDRK)
1180//      SetVariable drkStr,pos={120,363},size={150,15},title="."
1181//      SetVariable drkStr,help={"DRK detector count file"},disable = (!root:Packages:NIST:gAllowDRK)
1182//      SetVariable drkStr,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:Protocols:gDRK
1183
1184
1185        Button export_button, size={120,20},pos={125,540},title="Export to Data",proc=V_ExportFileProtocol
1186        Button export_button, help={"Exports the protocol to data file on disk for Importing into another experiment"}
1187        Button import_button, size={120,20},pos={125,562},title="Import from Data",proc=V_ImportFileProtocol
1188        Button import_button,help={"Imports a protocol from a data file on disk for use in this experiment"}
1189        Button recallProt,pos={7,540},size={107,20},proc=V_RecallProtocolButton,title="Recall Protocol"
1190        Button recallProt,help={"Resets the panel to the file choices in  a previously saved protocol"}
1191        Button del_protocol,pos={7,562},size={110,20},proc=V_DeleteProtocolButton,title="Delete Protocol"
1192        Button del_protocol,help={"Use this to delete a previously saved protocol."}
1193        Button done_protocol,pos={285,562},size={45,20},proc=V_DoneProtocolButton,title="Done"
1194        Button done_protocol,help={"This button will close the panel. The panel can be recalled at any time from the SANS menu."}
1195        Button saveProtocol,pos={7,518},size={100,20},proc=V_SaveProtocolButton,title="Save Protocol"
1196        Button saveProtocol,help={"Saves the cerrent selections in the panel to a protocol which can be later recalled"}
1197        Button ReduceOne,pos={240,518},size={100,20},proc=V_ReduceOneButton,title="Reduce A File"
1198        Button ReduceOne,help={"Using the panel selections, the specified sample file will be reduced. If none is specified, the user will be prompted for a sample file"}
1199
1200EndMacro
1201
1202
1203
1204
1205
1206Function SAMFilePopMenuProc(pa) : PopupMenuControl
1207        STRUCT WMPopupAction &pa
1208
1209        switch( pa.eventCode )
1210                case 2: // mouse up
1211                        Variable popNum = pa.popNum
1212                        String popStr = pa.popStr
1213                        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gSAM
1214                        tempStr = popStr
1215                        break
1216                case -1: // control being killed
1217                        break
1218        endswitch
1219
1220        return 0
1221End
1222
1223
1224Function BKGFilePopMenuProc(pa) : PopupMenuControl
1225        STRUCT WMPopupAction &pa
1226
1227        switch( pa.eventCode )
1228                case 2: // mouse up
1229                        Variable popNum = pa.popNum
1230                        String popStr = pa.popStr
1231                        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gBGD
1232                        tempStr = popStr
1233                        break
1234                case -1: // control being killed
1235                        break
1236        endswitch
1237
1238        return 0
1239End
1240
1241Function EMPFilePopMenuProc(pa) : PopupMenuControl
1242        STRUCT WMPopupAction &pa
1243
1244        switch( pa.eventCode )
1245                case 2: // mouse up
1246                        Variable popNum = pa.popNum
1247                        String popStr = pa.popStr
1248                        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gEMP
1249                        tempStr = popStr
1250                        break
1251                case -1: // control being killed
1252                        break
1253        endswitch
1254
1255        return 0
1256End
1257
1258Function DIVFilePopMenuProc(pa) : PopupMenuControl
1259        STRUCT WMPopupAction &pa
1260
1261        switch( pa.eventCode )
1262                case 2: // mouse up
1263                        Variable popNum = pa.popNum
1264                        String popStr = pa.popStr
1265                        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gDIV
1266                        tempStr = popStr
1267                        break
1268                case -1: // control being killed
1269                        break
1270        endswitch
1271
1272        return 0
1273End
1274
1275Function MSKFilePopMenuProc(pa) : PopupMenuControl
1276        STRUCT WMPopupAction &pa
1277
1278        switch( pa.eventCode )
1279                case 2: // mouse up
1280                        Variable popNum = pa.popNum
1281                        String popStr = pa.popStr
1282                        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gMASK
1283                        tempStr = popStr
1284                        break
1285                case -1: // control being killed
1286                        break
1287        endswitch
1288
1289        return 0
1290End
1291
1292////activated when user checks/unchecks the box
1293////either prompts for a file using a standard dialog, or removes the current file
1294//Function V_DrkCheckProc(ctrlName,checked) : CheckBoxControl
1295//      String ctrlName
1296//      Variable checked                //Desired state, not previous state
1297//
1298//      SVAR drkStr=root:Packages:NIST:VSANS:Globals:Protocols:gDRK
1299//      if(checked==1)
1300//              //print "Unchecked on call"
1301//              //this just asks for the filename, doesn't open the file
1302//              String msgStr="Select the DRK file",fullPath="",fileStr=""
1303//              Variable refnum
1304//             
1305//              Open/D/R/T="????"/M=(msgStr)/P=catPathName refNum
1306//              fullPath = S_FileName           //fname is the full path
1307//              if(cmpstr(fullpath,"")==0)
1308//                      //user cancelled
1309//                      CheckBox prot_check_6,value=0           //keep box unchecked
1310//                      return(0)
1311//              Endif
1312//              fileStr=V_GetFileNameFromPathNoSemi(fullPath)
1313//              //Print fileStr
1314//              //update the global string
1315//              drkStr = ReplaceStringByKey("DRK",drkStr,fileStr,"=",",")
1316//              drkStr = ReplaceNumberByKey("DRKMODE", drkStr, 10 ,"=",",")
1317//      else
1318//              //print "checked on call"
1319//              drkStr="DRK=none,DRKMODE=0,"            //change the global
1320//      endif
1321//     
1322//End
1323
1324
1325Function V_ShowProtoHelp(ctrlName) : ButtonControl
1326        String ctrlName
1327        DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[VSANS Reduction Protocol]"
1328        if(V_flag !=0)
1329                DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found"
1330        endif
1331End
1332
1333//button action procedure to get the type of average requested by the user
1334//presented as a missing parameter dialog, which is really user-UN-friendly
1335//and will need to be re-thought. Defaults of dialog are set for normal
1336//circular average, so typically click "continue" and proceed
1337//
1338Function V_SetAverageParamsButtonProc(ctrlName) : ButtonControl
1339        String ctrlName
1340       
1341//      Execute "V_GetAvgInfo_Full()"
1342        Execute "V_GetAvgInfo()"
1343       
1344        //set the global string
1345        SVAR tempStr = root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr
1346        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAVE = tempStr
1347
1348End
1349
1350// TODO
1351// -- this is a trimmed down version of the "full" set of averaging options
1352//    add to this as needed as I figure out what functionality is appropriate
1353//
1354//procedure called by protocol panel to ask user for average type choices
1355// somewhat confusing and complex, but may be as good as it gets.
1356//
1357//Proc V_GetAvgInfo(av_typ,autoSave,autoName,autoPlot,side,phi,dphi,width,QCtr,QDelta)
1358Proc V_GetAvgInfo(av_typ,autoSave,autoName,binType,qCtr,qDelta,detGroup)
1359        String av_typ,autoSave,AutoName,binType
1360//      Variable phi=0,dphi=10,width=10,Qctr = 0.01,qDelta=10
1361        Variable Qctr=0.1,qDelta=0.01
1362        String detGroup="F"
1363
1364//      Prompt av_typ, "Type of Average",popup,"Circular;Sector;Rectangular;Annular;2D_ASCII;QxQy_ASCII;PNG_Graphic;Sector_PlusMinus;"
1365        Prompt av_typ, "Type of Average",popup,"Circular;Annular;"
1366
1367// comment out above line in DEMO_MODIFIED version, and uncomment the line below (to disable PNG save)
1368//      Prompt av_typ, "Type of Average",popup,"Circular;Sector;Rectangular;Annular;2D_ASCII;QxQy_ASCII"
1369        Prompt autoSave,"Save files to disk?",popup,"Yes - Concatenate;Yes - Individual;No"
1370        Prompt autoName,"Auto-Name files?",popup,"Auto;Manual"
1371//      Prompt autoPlot,"Plot the averaged Data?",popup,"Yes;No"
1372//      Prompt side,"Include detector halves?",popup,"both;right;left"
1373//      Prompt phi,"Orientation Angle (-90,90) degrees (Rectangular or Sector)"
1374//      Prompt dphi, "Azimuthal range (0,45) degrees (Sector only)"
1375//      Prompt width, "Width of Rectangular average (1,128)"
1376        Prompt binType,"Binning Type?",popup,ksBinTypeStr
1377
1378        Prompt Qctr, "q-value of center of annulus"
1379        Prompt Qdelta,"(+/-) q-width of annulus"
1380        Prompt detGroup,"Group for annulus"
1381       
1382        //assign results of dialog to key=value string, semicolon separated
1383        //do only what is necessary, based on av_typ
1384        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr=""
1385
1386        // TODO:
1387        // hard wired value
1388        String autoPlot = "No"
1389       
1390               
1391        // all averages need these values
1392        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "AVTYPE=" + av_typ + ";"
1393        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SAVE=" + autoSave + ";"
1394        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "NAME=" + autoName + ";"
1395        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PLOT=" + autoPlot + ";"
1396        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "BINTYPE=" + binType + ";"
1397       
1398//      if(cmpstr(av_typ,"Sector")==0 || cmpstr(av_typ,"Sector_PlusMinus")==0)
1399//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SIDE=" + side + ";"
1400//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";"
1401//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "DPHI=" + num2str(dphi) + ";"
1402//      Endif
1403//     
1404//      if(cmpstr(av_typ,"Rectangular")==0)
1405//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SIDE=" + side + ";"
1406//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";"
1407//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "WIDTH=" + num2str(width) + ";"
1408//      Endif
1409//     
1410        if(cmpstr(av_typ,"Annular")==0)
1411                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "QCENTER=" + num2str(QCtr) + ";"
1412                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "QDELTA=" + num2str(QDelta) + ";"
1413                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "DETGROUP=" + detGroup + ";"
1414        Endif
1415End
1416
1417
1418// TODO
1419// -- this is the original(SANS) version, and needs to be updated for VSANS as the averaging options are
1420//    worked out
1421// -- there have been changes made to V_GetAvgInfo() above -- so work from that version, NOT this one.
1422//
1423//
1424//procedure called by protocol panel to ask user for average type choices
1425// somewhat confusing and complex, but may be as good as it gets.
1426//
1427Proc V_GetAvgInfo_Full(av_typ,autoSave,autoName,autoPlot,side,phi,dphi,width,QCtr,QDelta)
1428        String av_typ,autoSave,AutoName,autoPlot,side
1429        Variable phi=0,dphi=10,width=10,Qctr = 0.01,qDelta=10
1430        Prompt av_typ, "Type of Average",popup,"Circular;Sector;Rectangular;Annular;2D_ASCII;QxQy_ASCII;PNG_Graphic;Sector_PlusMinus;"
1431// comment out above line in DEMO_MODIFIED version, and uncomment the line below (to disable PNG save)
1432//      Prompt av_typ, "Type of Average",popup,"Circular;Sector;Rectangular;Annular;2D_ASCII;QxQy_ASCII"
1433        Prompt autoSave,"Save files to disk?",popup,"Yes;No"
1434        Prompt autoName,"Auto-Name files?",popup,"Auto;Manual"
1435        Prompt autoPlot,"Plot the averaged Data?",popup,"Yes;No"
1436        Prompt side,"Include detector halves?",popup,"both;right;left"
1437        Prompt phi,"Orientation Angle (-90,90) degrees (Rectangular or Sector)"
1438        Prompt dphi, "Azimuthal range (0,45) degrees (Sector only)"
1439        Prompt width, "Width of Rectangular average (1,128)"
1440        Prompt Qctr, "q-value of center of annulus"
1441        Prompt Qdelta,"Pixel width of annulus"
1442
1443        //assign results of dialog to key=value string, semicolon separated
1444        //do only what is necessary, based on av_typ
1445        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr=""
1446       
1447        // all averages need these four values
1448        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "AVTYPE=" + av_typ + ";"
1449        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SAVE=" + autoSave + ";"
1450        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "NAME=" + autoName + ";"
1451        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PLOT=" + autoPlot + ";"
1452       
1453        if(cmpstr(av_typ,"Sector")==0 || cmpstr(av_typ,"Sector_PlusMinus")==0)
1454                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SIDE=" + side + ";"
1455                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";"
1456                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "DPHI=" + num2str(dphi) + ";"
1457        Endif
1458       
1459        if(cmpstr(av_typ,"Rectangular")==0)
1460                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SIDE=" + side + ";"
1461                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";"
1462                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "WIDTH=" + num2str(width) + ";"
1463        Endif
1464       
1465        if(cmpstr(av_typ,"Annular")==0)
1466                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "QCENTER=" + num2str(QCtr) + ";"
1467                root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "QDELTA=" + num2str(QDelta) + ";"
1468        Endif
1469End
1470
1471
1472//prompts the user to pick a previously created protocol from a popup list
1473//of given the option to create a new protocol
1474//the chosen protocol is passed back to the calling procedure by a global string
1475//the popup is presented as a missing parameter dialog (called with empty parameter list)
1476//
1477// MAXROWS is present to exclude the PanelNameW from appearing as a protocol
1478Proc V_PickAProtocol(protocol)
1479        String Protocol
1480        Prompt Protocol "Pick A Protocol",popup, V_RecallableProtocols()
1481       
1482        String/G  root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocol
1483End
1484
1485Proc V_DeleteAProtocol(protocol)
1486        String Protocol
1487//      Prompt Protocol "Delete A Protocol",popup, WaveList("*",";","TEXT:1")
1488        Prompt Protocol "Delete A Protocol",popup, V_DeletableProtocols()
1489
1490        String/G  root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocol
1491End
1492
1493Function/S V_DeletableProtocols()
1494        String list=WaveList("*",";","TEXT:1,MAXROWS:13")
1495
1496        list= RemoveFromList("Base", list  , ";")
1497        list= RemoveFromList("DoAll", list  , ";")
1498        list= RemoveFromList("CreateNew", list  , ";")
1499        list= RemoveFromList("tempProtocol", list  , ";")
1500        list= RemoveFromList("wTTmpWrite", list  , ";")
1501        if(cmpstr(list,"")==0)
1502                list = "_no_protocols_;"
1503        endif
1504       
1505        return(list)
1506End
1507
1508Function/S V_RecallableProtocols()
1509        String list=WaveList("*",";","TEXT:1,MAXROWS:13")
1510
1511//      list= RemoveFromList("Base", list  , ";")
1512//      list= RemoveFromList("DoAll", list  , ";")
1513        list= RemoveFromList("CreateNew", list  , ";")
1514        list= RemoveFromList("tempProtocol", list  , ";")
1515        list= RemoveFromList("wTTmpWrite", list  , ";")
1516        if(cmpstr(list,"")==0)
1517                list = "_no_protocols_;"
1518        endif
1519       
1520        return(list)
1521End
1522
1523
1524//missing parameter dialog to solicit user for a waveStr for the protocol
1525//about to be created
1526//name is passed back as a global string and calling procedure is responsible for
1527//checking for wave conflicts and valid names
1528//
1529Proc V_AskForName(protocol)
1530        String Protocol
1531        Prompt Protocol "Enter a new name for your protocol (no extension)"
1532       
1533        String/G  root:Packages:NIST:VSANS:Globals:Protocols:gNewStr = protocol
1534End
1535
1536//this is a lengthy procedure for sequentially polling the user about what data
1537//reduction steps they want to be performed during the protocol
1538//ensures that a valid protocol name was chosen, then fills out each "item"
1539//(6 total) needed for reduction
1540//it the user cancels at any point, the partial protocol will be deleted
1541//
1542Function V_ProtocolQuestionnaire(ctrlName)
1543        String ctrlName
1544
1545        String filename,cmd
1546        Variable notDone,refnum
1547       
1548        //prompt for name of new protocol wave to save
1549        do
1550                Execute "V_AskForName()"
1551                SVAR newProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gNewStr
1552               
1553                //make sure it's a valid IGOR name
1554                newProtoStr = CleanupName(newProtoStr,0)        //strict naming convention
1555                String/G root:Packages:NIST:VSANS:Globals:Protocols:gNewStr=newProtoStr         //reassign, if changed
1556                //Print "newProtoStr = ",newProtoStr
1557               
1558                SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
1559                if(WaveExists( $("root:Packages:NIST:VSANS:Globals:Protocols:" + newProtoStr) ) == 1)
1560                        //wave already exists
1561                        DoAlert 0,"that name is already in use. Please pick a new name"
1562                        notDone = 1
1563                else
1564                        //name is  good
1565                        notDone = 0
1566                Endif
1567        while(notDone)
1568       
1569        //Print "protocol questionnaire is "+newProtocol
1570       
1571        //make a new text wave (12 points) and fill it in, in response to questions
1572        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols //(redundant - full wave specs are used)
1573        Make/O/T/N=(kNumProtocolSteps) $("root:Packages:NIST:VSANS:Globals:Protocols:" + newProtoStr)
1574        Wave/T newProtocol = $("root:Packages:NIST:VSANS:Globals:Protocols:" + newProtoStr)
1575        newProtocol = ""
1576       
1577        //ask the questions
1578        /////
1579        //*****Multiple files in these lists are full paths/filenames which may or may not
1580        //have semicolon version numbers in the filename. Therefore, construct the list with
1581        //COMMAS as separators - to avoid messy parsing
1582        ///////
1583       
1584        String fileFilters = "VSANS Data Files (*.ngv,*.h5):.ngv,.h5;"
1585//      fileFilters += "HTML Files (*.htm,*.html):.htm,.html;"
1586        fileFilters += "All Files:.*;"
1587//////////////////////////
1588        String drkStr="",fileStr=""
1589       
1590       
1591//////////////////////////     
1592//      DoAlert 1,"Do you want to correct your data for DRK (beam off) counts?"
1593//      if(V_flag == 1)         //1=yes
1594//              //prompt for DRK  file, but don't actually open it (/D flag)
1595//              Open/D/R/F=fileFilters/M="Select the DRK file"/P=catPathName refnum
1596//              //check for cancel
1597//              if(strlen(S_filename)==0)
1598//                      //user cancelled, abort
1599//                      KillWaves/Z newProtocol
1600//                      SetDataFolder root:
1601//                      Abort "Incomplete protocol has been deleted"
1602//              Endif
1603//              //assign filename (just the name) to [6]
1604//              fileStr = V_GetFileNameFromPathNoSemi(S_filename)
1605//              drkStr = "DRK=none,DRKMODE=0,"
1606//              drkStr = ReplaceStringByKey("DRK",drkStr,fileStr,"=",",")
1607//              drkStr = ReplaceNumberByKey("DRKMODE", drkStr, 10 ,"=",",")     
1608//              newProtocol[6] = drkStr
1609//      else
1610//              //no Work.DRK desired
1611//              newProtocol[6] = "DRK=none,DRKMODE=0,"
1612//      Endif
1613//     
1614////////////
1615       
1616       
1617// TODO:
1618// -- there is a lag in the V_pick() routine as it greps through all of the files. Several seconds even when there
1619//   are 20-ish files. Pre-search for the strings? When to refresh them for new data?   
1620/////////////////
1621        DoAlert 1,"Do you want to subtract background from your data?"
1622        if(V_flag == 1)         //1=yes
1623               
1624                Prompt filename,"BKG File",popup,V_PickBGDButton("")
1625                DoPrompt "Select File",filename
1626                if (V_Flag)
1627                        return 0                                                                        // user canceled
1628                endif
1629//              //assign filename to [0]
1630                newProtocol[0] = V_GetFileNameFromPathNoSemi(fileName)
1631       
1632               
1633// OLD way, using an open file dialog   
1634// and allowing for multiple files to be added together
1635//     
1636//              //prompt for background file, but don't actually open it (/D flag)
1637//              Open/D/R/F=fileFilters/M="Select the Background data file"/P=catPathName refnum
1638//              //check for cancel
1639//              if(strlen(S_filename)==0)
1640//                      //user cancelled, abort
1641//                      KillWaves/Z newProtocol
1642//                      SetDataFolder root:
1643//                      Abort "Incomplete protocol has been deleted"
1644//              Endif
1645//              //assign filename (full path) to [0]
1646//              newProtocol[0] = V_GetFileNameFromPathNoSemi(S_filename)
1647               
1648//              notDone=1
1649//              do
1650//                      //prompt for additional background files
1651//                      DoAlert 1,"Do you want to add another background file?"
1652//                      if(V_flag == 1)         //yes
1653//                              Open/D/R/F=fileFilters/M="Select another Background data file"/P=catPathName refnum
1654//                              //check for cancel
1655//                              if(strlen(S_filename)==0)
1656//                                      //user cancelled, abort ********maybe just break out of the loop here
1657//                                      KillWaves/Z newProtocol
1658//                                      SetDataFolder root:
1659//                                      Abort "Incomplete protocol has been deleted"
1660//                              Endif
1661//                              //assign filename (full path) to [0]
1662//                              newProtocol[0] += "," + V_GetFileNameFromPathNoSemi(S_filename)         //***COMMA separated list
1663//                              notDone = 1             //keep going
1664//                      else
1665//                              notDone = 0                     //no more to add
1666//                      Endif
1667//              While(notDone)
1668//////
1669
1670        else            //no background desired
1671                newProtocol[0] = "none"
1672        Endif
1673       
1674       
1675////////////////////// 
1676        DoAlert 1,"Do you want to subtract empty cell scattering from your data?"
1677        if(V_flag == 1)         //1=yes
1678               
1679                Prompt filename,"EMP File",popup,V_PickEMPButton("")
1680                DoPrompt "Select File",filename
1681                if (V_Flag)
1682                        return 0                                                                        // user canceled
1683                endif
1684//              //assign filename to [1]
1685                newProtocol[1] = V_GetFileNameFromPathNoSemi(fileName)         
1686       
1687
1688               
1689//              //prompt for Empty cell file, but don't actually open it (/D flag)
1690//              Open/D/R/F=fileFilters/M="Select the Empty Cell data file"/P=catPathName refnum
1691//              //check for cancel
1692//              if(strlen(S_filename)==0)
1693//                      //user cancelled, abort
1694//                      KillWaves/Z newProtocol
1695//                      SetDataFolder root:
1696//                      Abort "Incomplete protocol has been deleted"
1697//              Endif
1698//              //assign filename (full path) to [1]
1699//              newProtocol[1] = V_GetFileNameFromPathNoSemi(S_filename)
1700//             
1701//              notDone=1
1702//              do
1703//                      //prompt for additional Empty Cell files
1704//                      DoAlert 1,"Do you want to add another Empty Cell file?"
1705//                      if(V_flag == 1)         //yes
1706//                              Open/D/R/F=fileFilters/M="Select another Empty Cell data file"/P=catPathName refnum
1707//                              //check for cancel
1708//                              if(strlen(S_filename)==0)
1709//                                      //user cancelled, abort ********maybe just break out of the loop here
1710//                                      KillWaves/Z newProtocol
1711//                                      SetDataFolder root:
1712//                                      Abort "Incomplete protocol has been deleted"
1713//                              Endif
1714//                              //assign filename (full path) to [1]
1715//                              newProtocol[1] += "," + V_GetFileNameFromPathNoSemi(S_filename)         //***COMMA separated list
1716//                              notDone = 1             //keep going
1717//                      else
1718//                              notDone = 0                     //no more to add
1719//                      Endif
1720//              While(notDone)
1721
1722
1723        else            //no background desired
1724                newProtocol[1] = "none"
1725        Endif
1726       
1727       
1728//////////////////////////
1729        DoAlert 1,"Do you want to correct your data for detector sensitivity?"
1730       
1731        if(V_flag == 1)         //1=yes
1732               
1733                Prompt filename,"DIV File",popup,V_PickDIVButton("")
1734                DoPrompt "Select File",filename
1735                if (V_Flag)
1736                        return 0                                                                        // user canceled
1737                endif
1738//              //assign filename to [2]
1739                newProtocol[2] = V_GetFileNameFromPathNoSemi(fileName)
1740               
1741//              //prompt for DIV  file, but don't actually open it (/D flag)
1742//              Open/D/R/F=fileFilters/M="Select the detector sensitivity file"/P=catPathName refnum
1743//              //check for cancel
1744//              if(strlen(S_filename)==0)
1745//                      //user cancelled, abort
1746//                      KillWaves/Z newProtocol
1747//                      SetDataFolder root:
1748//                      Abort "Incomplete protocol has been deleted"
1749//              Endif
1750//              //assign filename (full path) to [2]
1751//              newProtocol[2] = V_GetFileNameFromPathNoSemi(S_filename)
1752               
1753               
1754        else
1755                //no Work.DIV desired
1756                newProtocol[2] = "none"
1757        Endif   
1758//////////////////////////
1759        DoAlert 1,"Do you want to mask your files before averaging?"
1760       
1761        if(V_flag == 1)         //1=yes
1762       
1763                Prompt filename,"MASK File",popup,V_PickMASKButton("")
1764                DoPrompt "Select File",filename
1765                if (V_Flag)
1766                        return 0                                                                        // user canceled
1767                endif
1768//              //assign filename to [3]
1769                newProtocol[3] = V_GetFileNameFromPathNoSemi(fileName)
1770                       
1771//              //prompt for mask  file, but don't actually open it (/D flag)
1772//              Open/D/R/F=fileFilters/M="Select the mask file"/P=catPathName refnum
1773//              //check for cancel
1774//              if(strlen(S_filename)==0)
1775//                      //user cancelled, abort
1776//                      KillWaves/Z newProtocol
1777//                      SetDataFolder root:
1778//                      Abort "Incomplete protocol has been deleted"
1779//              Endif
1780//              //assign filename (full path) to [3]
1781//              newProtocol[3] = V_GetFileNameFromPathNoSemi(S_filename)
1782               
1783               
1784        else
1785                //no MASK desired
1786                newProtocol[3] = "none"
1787        Endif   
1788       
1789        //absolute scaling
1790       
1791        //////////////////////////
1792        //ABS parameters stored as keyword=value string
1793        DoAlert 1,"Do you want absolute scaling?"
1794        if(V_flag == 1)         //1=yes
1795                //missing param - prompt for values, put in semicolon-separated list
1796                Execute "V_AskForAbsoluteParams_Quest()"
1797                SVAR absStr =  root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr
1798                newProtocol[4] = absStr
1799        else
1800                //no absolute scaling desired
1801                newProtocol[4] = "none"
1802        Endif   
1803       
1804        //type of average, plot?, auto/manual naming/saving... put in semicolon separated string
1805        //of KEY=<value> format for easy parsing
1806        //Kewords are: AVTYPE,PHI,DPHI,PLOT,SAVE,NAME,SIDE,WIDTH
1807        //note that AVTYPE,NAME,SIDE have string values, others have numerical values
1808        ///////////////////////
1809        DoAlert 1,"Do you want to average your data to I vs. q?"
1810        if(V_flag == 1)         //1=yes
1811                String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr = ""
1812                Execute "V_GetAvgInfo()"                //will put up missing paramter dialog and do all the work
1813                //:gAvgInfo is reset by the Proc(), copy this string tot he protocol
1814                SVAR tempStr=root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr
1815               
1816                //get a file path for saving files, if desired
1817                /////no - save files to the same data folder as the one with the raw data
1818                //then only one path to manage.
1819                //String yesNo = StringByKey("SAVE", tempStr,"=", ";")
1820                //if(cmpstr("Yes",yesNo) == 0)          //0=yes
1821                        //NewPath/C/M="Select Folder"/O Save_path               //Save_path is the symbolic path
1822                //Endif
1823
1824                newProtocol[5] = tempStr
1825                KillStrings/Z tempStr
1826        else
1827                //no averaging desired
1828                newProtocol[5] = "AVTYPE=none"
1829        Endif
1830       
1831        //returns the name of the newly created (= currently in use) protocol wave through a global
1832        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = newProtoStr
1833       
1834        //reset the panel based on the protocol textwave (currently a string)
1835        V_ResetToSavedProtocol(newProtoStr)
1836       
1837        SetDataFolder root:
1838       
1839        return(0)
1840End
1841
1842
1843// TODO
1844// -- this function may not work properly for VSANS, but I haven't tested it yet
1845// -- I'd rather have some sort of display to show the current content of the WORK folders
1846//
1847// -- the global string fileList does not exist, so this will always fail and return zero
1848//
1849//
1850//function to check the work files (to see what's already there)
1851//and compare that with the files that are supposed to be there, according to the
1852//current protocol (to save unnecessary time re-loading files)
1853//
1854//the "type" folder is checked for all files in the list req(ested)Files
1855//note that the list of files is a full path:name;ver, while the
1856//fileList in the folder is just the name (or a list of names)
1857//
1858//returns 0 false, if files are NOT present
1859//or 1 = true, yes, the files are there as requested
1860//
1861Function V_AreFilesThere(type,reqFiles)
1862        String type,reqFiles
1863       
1864        //in general, reqFiles is a list of full paths to files - which MAY include semicolon version numbers
1865        //reqFiles MUST be constructed with COMMAS as list separators, to avoid disaster
1866        //when the version numbers are interpreted as filenames
1867       
1868        //get the number of files requested
1869        Variable nReq,nCur,match,ii
1870        nReq = ItemsInList(reqFiles,",")
1871       
1872        //get the name of the file currently in BGD - in the global fileList
1873        //fileList has NAMES ONLY - since it was derived from the file header
1874        String testStr
1875        testStr = "root:Packages:NIST:"+type+":fileList"
1876        if(Exists(testStr) == 2)                //2 if string variable exists
1877                SVAR curFiles = $testStr
1878        else
1879                //no files currently in type folder, return zero
1880                Return (0)
1881        Endif
1882        //get the number of files already in folder
1883        nCur = ItemsInList(curFiles,";")
1884        If(nCur != nReq)
1885                Return (0)              //quit now, the wrong number of files present
1886        Endif
1887        //right number of files... are the names right...
1888        //check for a match (case-sensitive!!) of each requested file in the curFile string
1889        //need to extract filenames from reqFiles, since they're the full path and name
1890       
1891        ii=0
1892        do
1893                testStr = StringFromList(ii,reqFiles,",")       //testStr is the Nth full path and filename
1894                //testStr = GetFileNameFromPathNoSemi(testStr)  //testStr will now be just the filename
1895                match = stringmatch(curFiles,testStr)
1896                If(!match)
1897                        Return (0)              //req file was not found in curFile list - get out now
1898                Endif
1899                ii+=1
1900        while(ii<nreq)
1901       
1902        Return (1)              //indicate that files are OK, no changes needed
1903End
1904
1905
1906//
1907//will add the files specified in the protocol to the "type" folder
1908//will add multiple files together if more than one file is requested
1909//(list is a comma delimited list of filenames, with NO path information)
1910//
1911// This routine NOW DOES check for the possibility that the filenames may have ";vers" from the
1912// VAX - data should be picked up from Charlotte, where it won't have version numbers.
1913//
1914Function V_AddFilesInList(type,list)
1915        String type,list
1916       
1917        //type is the work folder to put the data into, and list is a COMMA delimited list of paths/names
1918        Variable num,ii,err=0,refNum
1919        String filename,pathStr=""
1920        PathInfo catPathName                    //this is where the files are
1921        pathstr=S_path
1922       
1923        num = ItemsInList(list,",")             // comma delimited list
1924       
1925        ii=0
1926        do
1927                //FindValidFilename only needed in case of vax version numbers
1928                filename = pathStr + V_FindValidFilename(StringFromList(ii,list,","))
1929                Open/Z/R refnum as filename
1930                if(V_flag != 0)         //file not found
1931                        //Print "file not found AddFilesInList()"
1932                        //Print filename
1933                        err = 1
1934                        return(err)
1935                Endif
1936                Close refnum            //file was found and opened, so close it
1937               
1938//              Abort "Find equivalent to ReadHeaderAndData(filename)"
1939//              ReadHeaderAndData(filename)
1940                err = V_LoadHDF5Data(filename,"RAW")   
1941               
1942                if(ii == 0)
1943                        //first pass, wipe out the old contents of the work file
1944                        err =  V_Raw_to_work(type)
1945                else
1946                        err = V_Add_raw_to_work(type)
1947                Endif
1948                ii+=1
1949        while(ii<num)
1950        return(err)
1951End
1952
1953//function will reduce a sample file (or ask for file(s))
1954//using the protocol named as "protoStr" in the Protocols subfolder
1955//samStr is the file(s) or "ask" to force prompt
1956//sequentially proceeds through flowchart, doing reduction steps as needed
1957//show Schematic to debug what steps/values were used
1958//
1959//function is long, but straightforward logic
1960//
1961Function V_ExecuteProtocol(protStr,samStr)
1962        String protStr,samStr
1963        //protStr is the full path to the selected protocol wave
1964        //samStr is either "ask" or the name ONLY ofthe desired sample data file(s) (NO PATH)
1965        WAVE/T prot = $protStr
1966        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
1967       
1968        Variable filesOK,err,notDone
1969        String activeType, msgStr, junkStr, pathStr=""
1970        PathInfo catPathName                    //this is where the files are
1971        pathStr=S_path
1972       
1973//      NVAR useXMLOutput = root:Packages:NIST:gXML_Write
1974       
1975        //Parse the instructions in the prot wave
1976        //0 - bkg
1977        //1 - emp
1978        //2 - div
1979        //3 - mask
1980        //4 - abs params c2-c5
1981        //5 - average params
1982        //6 = DRK file (**out of sequence)
1983        //7 = beginning trim points
1984        //8 = end trim points
1985        //9 = unused
1986        //10 = unused
1987        //11 = unused
1988
1989// for VSANS, DIV is used on each data file as it is converted to WORK, so it needs to be
1990//  the first thing in place, before any data or backgrounds are loaded
1991
1992
1993//
1994// TODO:
1995// x- this is no longer done after the COR step, and CAL is not produced as output of DIV       
1996// x- needs to be aware of the file name passed in
1997// x- PromptForPath does not exist in VSANS. Need a better (automated) way to find the file.
1998
1999//check for work.div file (prot[2])
2000//load in if needed
2001// no math is done here, DIV is applied as files are converted to WORK (the first operation in VSANS)
2002//
2003        String divFileName = ""
2004
2005        If(cmpstr("none",prot[2])!=0)           // if !0, then there's a file requested
2006                If(cmpstr("ask",prot[2]) == 0)
2007                        //ask user for file
2008//                       junkStr = PromptForPath("Select the detector sensitivity file")
2009                        Prompt divFileName,"DIV File",popup,V_PickDIVButton("")
2010                        DoPrompt "Select File",divFileName
2011
2012                        If(strlen(divFileName)==0)
2013                                SetDataFolder root:
2014                                Abort "No file selected, data reduction aborted"
2015                        Endif
2016                        V_LoadHDF5Data(divFileName,"DIV")
2017                else
2018                        //assume it's a path, and that the first (and only) item is the path:file
2019                        //list processing is necessary to remove any final comma
2020                        junkStr = pathStr + StringFromList(0, prot[2],"," )
2021                        V_LoadHDF5Data(junkStr,"DIV")
2022                Endif
2023       
2024        else
2025        // DIV step is being skipped
2026                NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor
2027                Variable saved_gDoDIVCor = gDoDIVCor
2028                gDoDIVCor = 0                   // protocol says to turn it off for now (reset later)
2029        Endif
2030
2031
2032// TODO:
2033// -- currently does not allow adding RAW data files together, so no parsing is done
2034//       -- NOTE detector corrections (including DIV) are done at the V_Raw_to_Work() step
2035//   So if the DIV is not part of the protocol, be sure to set/reset the global preference
2036//
2037        //prompt for sam data => read raw data, add to sam folder
2038        //or parse file(s) from the input paramter string
2039        activeType = "SAM"
2040        msgStr = "Select sample data"
2041        //Ask for SAM file or parse
2042        do
2043                if((cmpstr(samStr,"ask") == 0) || (cmpstr(samStr,"")==0) )              //zero if strings are equal
2044                        err = V_LoadHDF5Data("","RAW")          //will prompt for file
2045                        if(err)
2046                                PathInfo/S catPathName
2047                                Abort "reduction sequence aborted"
2048                        endif
2049                        V_UpdateDisplayInformation("RAW")                       //display the new type of data that was loaded
2050                        err =  V_Raw_to_work(activeType)                //this is the first file (default)
2051                        //Ask for another SAM file
2052                        do
2053                                DoAlert 1,"Do you want to add another Sample file?"
2054                                if(V_flag == 1)         //yes
2055                                        err = V_LoadHDF5Data("","RAW")          //will prompt for file
2056                                        if(err)
2057                                                PathInfo/S catPathName
2058                                                Abort "reduction sequence aborted"
2059                                        endif
2060                                        V_UpdateDisplayInformation("RAW")                       //display the new type of data that was loaded
2061                                        err = V_Add_raw_to_work(activeType)
2062                                        notDone = 1
2063                                else
2064                                        notDone = 0
2065                                endif
2066                        while(notDone)
2067                        break
2068                Endif
2069                //"none" is not an option - you always need a sample file - "none" will never return zero
2070                //if not "ask" AND not "none" then try to parse the filenames
2071                If((cmpstr(samStr,"none") != 0) && (cmpstr(samStr,"ask") != 0))
2072                        //filesOK = AreFilesThere(activeType,samStr)            //return 1 if correct files are already there
2073                        filesOK = 0             // Feb 2008, always force a reload of files. Maybe slow, but always correct
2074                        if(!filesOK)
2075                                //add the correct file(s) to SAM
2076                               
2077                                // TODO: only one file is allowed currently
2078                                err = V_AddFilesInList(activeType,samStr)
2079                               
2080                                if(err)
2081                                        //Print "samstr = ",samStr
2082                                        Abort "SAM file not found, reset SAM file"
2083                                Endif
2084                        Endif
2085                Endif
2086        While(0)
2087        // TODO
2088        // -- this may not be the most reliable way to pass the file name (for naming of the saved file later)
2089        SVAR file_name = root:file_Name
2090        String samFileLoaded = file_name                //keep a copy of the sample file loaded
2091       
2092        //always update
2093        V_UpdateDisplayInformation(ActiveType)
2094       
2095        //check for bkg file  -- "ask" might not fail - "ask?" will - ? not allowed in VAX filenames
2096        // add if needed
2097        //use a "case" statement
2098        msgStr = "Select background file"
2099        activeType = "BGD"
2100        do
2101                if(cmpstr(prot[0],"ask") == 0)          //zero if strings are equal
2102                        err = V_LoadHDF5Data("","RAW")          //will prompt for file
2103                        if(err)
2104                                PathInfo/S catPathName
2105                                Abort "reduction sequence aborted"
2106                        endif
2107                        V_UpdateDisplayInformation("RAW")                       //display the new type of data that was loaded
2108                        err =  V_Raw_to_work(activeType)                //this is the first file (default)
2109                        //Ask for another BGD file
2110                        do
2111                                DoAlert 1,"Do you want to add another Background file?"
2112                                if(V_flag == 1)         //yes
2113                                        err = V_LoadHDF5Data("","RAW")          //will prompt for file
2114                                        if(err)
2115                                                PathInfo/S catPathName
2116                                                Abort "reduction sequence aborted"
2117                                        endif
2118                                        V_UpdateDisplayInformation("RAW")                       //display the new type of data that was loaded
2119                                        err = V_Add_raw_to_work(activeType)
2120                                        notDone = 1
2121                                else
2122                                        notDone = 0
2123                                endif
2124                        while(notDone)
2125                        V_UpdateDisplayInformation(ActiveType)  //update before breaking from loop
2126                        break
2127                Endif
2128                If(cmpstr(prot[0],"none") == 0)
2129                        //clean out the BKG folder?
2130                        //KillDataFolder root:BKG
2131                        //NewDataFolder/O root:BKG
2132                        break
2133                Endif
2134                //if not "ask" AND not "none" then try to parse the filenames
2135                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[0],"ask") != 0))
2136                        //filesOK = AreFilesThere(activeType,prot[0])
2137                        filesOK = 0             // Feb 2008, always force a reload of files. Maybe slow, but always correct
2138                        if(!filesOK)
2139                                //add the correct file(s) to BGD
2140                                string bgdStr = prot[0]
2141                                err = V_AddFilesInList(activeType,bgdStr)
2142                                If(err)
2143                                        Abort "BGD file not found. Reset BGD file list"
2144                                Endif
2145                        Endif
2146                        V_UpdateDisplayInformation(ActiveType)          //update before breaking from loop
2147                Endif
2148        While(0)
2149       
2150       
2151        //check for emp file (prot[1])
2152        // add if needed
2153        msgStr = "Select empty cell data"
2154        activeType = "EMP"
2155        do
2156                if(cmpstr(prot[1],"ask") == 0)
2157                        err = V_LoadHDF5Data("","RAW")          //will prompt for file
2158                        if(err)
2159                                PathInfo/S catPathName
2160                                Abort "reduction sequence aborted"
2161                        endif
2162                        V_UpdateDisplayInformation("RAW")                       //display the new type of data that was loaded
2163                        err =  V_Raw_to_work(activeType)                //this is the first file (default)
2164                        //Ask for another EMP file
2165                        do
2166                                DoAlert 1,"Do you want to add another Empty Cell file?"
2167                                if(V_flag == 1)         //yes
2168                                        err = V_LoadHDF5Data("","RAW")          //will prompt for file
2169                                        if(err)
2170                                                PathInfo/S catPathName
2171                                                Abort "reduction sequence aborted"
2172                                        endif
2173                                        V_UpdateDisplayInformation("RAW")                       //display the new type of data that was loaded
2174                                        err = V_Add_raw_to_work(activeType)
2175                                        notDone = 1
2176                                else
2177                                        notDone = 0
2178                                endif
2179                        while(notDone)
2180                        V_UpdateDisplayInformation(ActiveType)          //update before breaking from loop
2181                        break
2182                Endif
2183                If(cmpstr(prot[1],"none") == 0)
2184                        //clean out the EMP folder?
2185                        //KillDataFolder root:Packages:NIST:EMP
2186                        //NewDataFolder/O root:Packages:NIST:EMP
2187                        break
2188                Endif
2189                //if not "ask" AND not "none" then try to parse the filenames
2190                If((cmpstr(prot[1],"none") != 0) && (cmpstr(prot[1],"ask") != 0))
2191                        //filesOK = AreFilesThere(activeType,prot[1])
2192                        filesOK = 0             // Feb 2008, always force a reload of files. Maybe slow, but always correct
2193                        if(!filesOK)
2194                                //add the correct file(s) to BGD
2195                                err = V_AddFilesInList(activeType,prot[1])
2196                                If(err)
2197                                        Abort "EMP file not found. Reset EMP file list"
2198                                Endif
2199                        Endif
2200                        V_UpdateDisplayInformation(ActiveType)  //update before breaking from loop
2201                Endif
2202        While(0)
2203       
2204        //do the CORRECT step based on the answers to emp and bkg subtraction
2205        //by setting the proper"mode"
2206        //1 = both emp and bgd subtraction
2207        //2 = only bgd subtraction
2208        //3 = only emp subtraction
2209        //4 = no subtraction
2210        //additional modes 091301
2211        //11 = emp, bgd, drk
2212        //12 = bgd and drk
2213        //13 = emp and drk
2214        //14 = no subtractions
2215        //work.drk is from proto[6]
2216        //
2217        //subtracting just the DRK data is NOT an option - it doesnt' really make any physical sense
2218        // - in this case, DRK is skipped (equivalent to mode==4)
2219        // automatically accounts for attenuators given the lookup tables and the
2220        //desired subtractions
2221        //Attenuator lookup tables are alredy implemented (NG1 = NG7)
2222        //
2223
2224
2225/////// DRK is SKIPPED
2226       
2227//      //read in the DRK data if necessary
2228//      //only one file, assumed to be RAW data
2229//      //
2230//      String fname="",drkStr=""
2231//      drkStr=StringByKey("DRK",prot[6],"=",",")
2232//      if(cmpstr(drkStr,"none") != 0)
2233//              err = ReadHeaderAndData( (pathStr+drkStr) )
2234//              if(err)
2235//                      PathInfo/S catPathName
2236//                      Abort "reduction sequence aborted"
2237//              endif
2238//              err = V_Raw_to_Work_NoNorm("DRK")
2239//      endif
2240
2241
2242       
2243        //dispatch to the proper "mode" of Correct()
2244        Variable mode=4,val
2245        do
2246                if( (cmpstr("none",prot[0]) == 0)       && (cmpstr("none",prot[1]) == 0) )
2247                        //no subtraction (mode = 4),
2248                        mode = 4
2249                Endif
2250                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[1],"none") == 0))
2251                        //subtract BGD only
2252                        mode=2
2253                Endif
2254                If((cmpstr(prot[0],"none") == 0) && (cmpstr(prot[1],"none") != 0))
2255                        //subtract EMP only
2256                        mode=3
2257                Endif
2258                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[1],"none") != 0))
2259                        // bkg and emp subtraction are to be done (BOTH not "none")
2260                        mode=1
2261                Endif
2262                activeType = "COR"
2263                //add in DRK mode (0= no used, 10 = used)
2264                val = NumberByKey("DRKMODE",prot[6],"=","," )
2265                mode += val
2266//              print "mode = ",mode
2267                err = V_Correct(mode)
2268                if(err)
2269                        SetDataFolder root:
2270                        Abort "error in Correct, called from executeprotocol, normal cor"
2271                endif
2272                V_UpdateDisplayInformation(ActiveType)          //update before breaking from loop
2273        While(0)
2274
2275
2276////////////////////////////////////////////////////////
2277
2278// TODO:
2279// -- calculation works, needs proper inputs (solid angle aware)
2280// --   Open beam method needs to be verified in V_AskForAbsoluteParams_Quest()
2281        Variable c2,c3,c4,c5,kappa_err
2282        //do absolute scaling if desired
2283//              DoAlert 0,"Abs step incomplete"
2284
2285        if(cmpstr("none",prot[4])!=0)
2286                if(cmpstr("ask",prot[4])==0)
2287                        //get the params from the user
2288                        Execute "V_AskForAbsoluteParams_Quest()"
2289                        //then from the list
2290                        SVAR junkAbsStr = root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr
2291                        c2 = NumberByKey("TSTAND", junkAbsStr, "=", ";")        //parse the list of values
2292                        c3 = NumberByKey("DSTAND", junkAbsStr, "=", ";")
2293                        c4 = NumberByKey("IZERO", junkAbsStr, "=", ";")
2294                        c5 = NumberByKey("XSECT", junkAbsStr, "=", ";")
2295                        kappa_err = NumberByKey("SDEV", junkAbsStr, "=", ";")
2296                else
2297                        //get the parames from the list
2298                        c2 = NumberByKey("TSTAND", prot[4], "=", ";")   //parse the list of values
2299                        c3 = NumberByKey("DSTAND", prot[4], "=", ";")
2300                        c4 = NumberByKey("IZERO", prot[4], "=", ";")
2301                        c5 = NumberByKey("XSECT", prot[4], "=", ";")
2302                        kappa_err = NumberByKey("SDEV", prot[4], "=", ";")
2303                Endif
2304                //get the sample trans and thickness from the activeType folder
2305                Variable c0 = V_getSampleTransmission(activeType)               //sample transmission
2306                Variable c1 = V_getSampleThickness(activeType)          //sample thickness
2307               
2308                err = V_Absolute_Scale(activeType,c0,c1,c2,c3,c4,c5,kappa_err)
2309                if(err)
2310                        SetDataFolder root:
2311                        Abort "Error in V_Absolute_Scale(), called from V_ExecuteProtocol"
2312                endif
2313                activeType = "ABS"
2314                V_UpdateDisplayInformation(ActiveType)                  //update before breaking from loop
2315        Endif
2316
2317//
2318// TODO
2319//              x- fill in the "ask" step
2320//  -- none is OK, except if the kill fails for any reason
2321// x- the regular case of the file name specified by the protocol works correctly
2322// x- don't create a null mask if not used, it will handle the error and print out that the mask is missing
2323
2324//mask data if desired (this is done automatically when the data is binned to I(q)) and is
2325//not done explicitly here
2326       
2327        //check for mask
2328        //doesn't change the activeType
2329        String mskFileName=""
2330       
2331        if(cmpstr("none",prot[3])!=0)
2332                If(cmpstr("ask",prot[3])==0)
2333                        //get file from user
2334                        // TODO
2335                        // x- fill in the get file prompt, and handle the result
2336                        Prompt mskFileName,"MASK File",popup,V_PickMASKButton("")
2337                        DoPrompt "Select File",mskFileName
2338//                      if (V_Flag)
2339//                              return 0                                                                        // user cancelled
2340//                      endif
2341
2342                        If(strlen(mskFileName)==0)              //use cancelled
2343                                //if none desired, make sure that the old mask is deleted
2344                                KillDataFolder/Z root:Packages:NIST:VSANS:MSK:
2345                                NewDataFolder/O root:Packages:NIST:VSANS:MSK
2346                               
2347                                DoAlert 0,"No Mask file selected, data not masked"
2348                        else
2349                                //read in the file from the selection
2350                                V_LoadHDF5Data(mskFileName,"MSK")
2351                        Endif
2352                else
2353                        //just read it in from the protocol
2354                        //list processing is necessary to remove any final comma
2355                        mskFileName = pathStr + StringFromList(0, prot[3],"," )
2356                        V_LoadHDF5Data(mskFileName,"MSK")
2357                Endif
2358               
2359        else
2360                //if none desired, make sure that the old mask is deleted
2361// TODO
2362// x- clean out the data folder
2363// x- note that V_KillNamedDataFolder() points to RawVSANS, and won't work
2364// -- what happens if the kill fails? need error handling
2365//
2366                KillDataFolder/Z root:Packages:NIST:VSANS:MSK:
2367                NewDataFolder/O root:Packages:NIST:VSANS:MSK
2368
2369        Endif
2370       
2371
2372        // average/save data as specified
2373        //Parse the keyword=<Value> string as needed, based on AVTYPE
2374       
2375        //average/plot first
2376        String av_type = StringByKey("AVTYPE",prot[5],"=",";")
2377        If(cmpstr(av_type,"none") != 0)
2378                If (cmpstr(av_type,"")==0)              //if the key could not be found... (if "ask" the string)
2379                        //get the averaging parameters from the user, as if the set button was hit in the panel
2380                        V_SetAverageParamsButtonProc("dummy")           //from "ProtocolAsPanel"
2381                        SVAR tempAveStr = root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr
2382                        av_type = StringByKey("AVTYPE",tempAveStr,"=",";")
2383                else
2384                        //there is info in the string, use the protocol
2385                        //set the global keyword-string to prot[5]
2386                        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr = prot[5]
2387                Endif
2388        Endif
2389       
2390        //convert the folder to linear scale before averaging, then revert by calling the window hook
2391        // (not needed for VSANS, data is always linear scale)
2392
2393        // bin and plot the data
2394       
2395        // TODO
2396// -- this switch does nothing -- fill it in
2397//       x- need to convert BINTYPE keyword into a numerical value to pass
2398//
2399
2400        String binTypeStr = StringByKey("BINTYPE",prot[5],"=",";")
2401        // plotting is not really necessary, and the graph may not be open - so skip for now?
2402        Variable binType
2403        binType = V_BinTypeStr2Num(binTypeStr)
2404        if(binType == 0)
2405                        Abort "Binning mode not found in V_QBinAllPanels() "// when no case matches
2406        endif
2407
2408
2409//
2410// TODO:
2411// -- do I calculate the proper resolution here? I've already decoded the binning type
2412//   and the averaging type has been specified by the protocol
2413// -- if I calculate the resolution here, then the Trimming routines must be updated
2414//    to trim the resolution waves also. This positioning may work for
2415//    pinhole resolution, but anything using the matrix method - it won't work - and I'll need
2416//    a different solution
2417//
2418        strswitch(av_type)      //dispatch to the proper routine to average to 1D data
2419                case "none":           
2420                        //still do nothing
2421                        break                   
2422                case "2D_ASCII":       
2423                        //do nothing
2424                        break
2425                case "QxQy_ASCII":
2426                        //do nothing
2427                        break
2428                case "PNG_Graphic":
2429                        //do nothing
2430                        break
2431                case "Rectangular":
2432//                      RectangularAverageTo1D(activeType)
2433                        break
2434                case "Annular":
2435//                      AnnularAverageTo1D(activeType)
2436                        String detGroup = StringByKey("DETGROUP",prot[5],"=",";")
2437                        Variable qCtr_Ann = NumberByKey("QCENTER",prot[5],"=",";")
2438                        Variable qWidth = NumberByKey("QDELTA",prot[5],"=",";")
2439                        V_QBinAllPanels_Annular(activeType,detGroup,qCtr_Ann,qWidth)
2440                        break
2441                case "Circular":
2442
2443                        V_QBinAllPanels_Circular(activeType,binType)            // this does a default circular average
2444                        break
2445                case "Sector":
2446//                      CircularAverageTo1D(activeType)
2447                        break
2448                case "Sector_PlusMinus":
2449//                      Sector_PlusMinus1D(activeType)
2450                        break
2451                default:       
2452                        //do nothing
2453        endswitch
2454
2455// TODO
2456// x- this call will bin the active type, then the next call bins the active type
2457// x- then later, I dispatch to bin the active type... 
2458// x- !!!need to split out the panel draw and the binning calls from V_PlotData_Panel
2459//
2460// TODO:
2461// -- BAD logic here, skipping the normal graph if annular is chosen. Go back and see how I do this
2462// in SANS for a better and more foolproof way to do this
2463        //
2464        if(cmpstr(av_type,"Annular") != 0)
2465                V_PlotData_Panel()              //this brings the plot window to the front, or draws it (ONLY)
2466                V_Update1D_Graph(activeType,binType)            //update the graph, data was already binned
2467        endif
2468///// end of averaging dispatch
2469
2470
2471// TODO
2472// x- how do I get the sample file name?
2473//    local variable samFileLoaded is the file name loaded (contains the extension)
2474//     
2475        //save data if desired
2476        String fullpath = "", newfileName=""
2477        String saveType = StringByKey("SAVE",prot[5],"=",";")           //does user want to save data?
2478        If( (cmpstr(saveType[0,2],"Yes")==0) && (cmpstr(av_type,"none") != 0) )         
2479                //then save
2480                newFileName = RemoveEnding(samFileLoaded,".nxs.ngv")
2481               
2482                //pick ABS or AVE extension
2483                String exten = activeType
2484                if(cmpstr(exten,"ABS") != 0)
2485                        exten = "AVE"
2486                endif
2487                if(cmpstr(av_type,"2D_ASCII") == 0)
2488                        exten = "ASC"
2489                endif
2490                if(cmpstr(av_type,"QxQy_ASCII") == 0)
2491                        exten = "DAT"
2492                endif
2493               
2494//              // add an "x" to the file extension if the output is XML
2495//              // currently (2010), only for ABS and AVE (1D) output
2496//              if( cmpstr(exten,"ABS") == 0 || cmpstr(exten,"AVE") == 0 )
2497//                      if(useXMLOutput == 1)
2498//                              exten += "x"
2499//                      endif
2500//              endif
2501                               
2502                //Path is catPathName, symbolic path
2503                //if this doesn't exist, a dialog will be presented by setting dialog = 1
2504                //
2505                //
2506                Variable dialog = 0
2507
2508// TODO
2509// -- need to define nBeg and nEnd somewhere
2510// -- currently hard-wired
2511// --do I need to define these "per-panel"?             
2512               
2513                PathInfo/S catPathName
2514                String item = StringByKey("NAME",prot[5],"=",";")               //Auto or Manual naming
2515                String autoname = StringByKey("AUTONAME",prot[5],"=",";")               //autoname -  will get empty string if not present
2516                If((cmpstr(item,"Manual")==0) || (cmpstr(newFileName,"") == 0))
2517                        //manual name if requested or if no name can be derived from header
2518                        fullPath = newfileName + "."+ exten //puts possible new name or null string in dialog
2519                        dialog = 1              //force dialog for user to enter name
2520                else
2521                        //auto-generate name and prepend path - won't put up any dialogs since it has all it needs
2522                        //use autoname if present
2523                        if (cmpstr(autoname,"") != 0)
2524                                fullPath = S_Path + autoname + "." +exten
2525                        else
2526                                fullPath = S_Path + newFileName+"." + exten
2527                        endif   
2528                Endif
2529                //
2530                strswitch(av_type)     
2531                        case "Annular":
2532//                              WritePhiave_W_Protocol(activeType,fullPath,dialog)
2533                                V_fWrite1DAnnular("root:Packages:NIST:VSANS:",activeType,detGroup,newFileName+".phi")
2534                                Print "data written to:  "+ newFileName+".phi"
2535
2536                                break
2537                        case "2D_ASCII":
2538//                              Fast2DExport(activeType,fullPath,dialog)
2539                                break
2540                        case "QxQy_ASCII":
2541//                              QxQy_Export(activeType,fullPath,dialog)
2542                                break
2543                        case "PNG_Graphic":
2544//                              SaveAsPNG(activeType,fullpath,dialog)
2545                                break
2546                        default:
2547//                              if (useXMLOutput == 1)
2548//                                      WriteXMLWaves_W_Protocol(activeType,fullPath,dialog)
2549//                              else
2550//                                      WriteWaves_W_Protocol(activeType,fullpath,dialog)
2551//                              endif
2552//
2553// TODO:
2554// -- fill in all of the cases, default is only the "standard" circular average I(q)
2555// -- get the trim strings from somewhere-- from the file or from the protocol??
2556//   then replace the null strings being passed
2557
2558                                if(cmpstr(saveType,"Yes - Concatenate")==0)
2559                                        V_Trim1DDataStr(activeType,binType,prot[7],prot[8])                     // TODO -- passing null strings uses global or default trim values
2560//                                      V_Trim1DData(activeType,binType,nBeg,nEnd)
2561                                        V_ConcatenateForSave("root:Packages:NIST:VSANS:",activeType,"",binType)         // this removes q=0 point, concatenates, sorts
2562                                        V_Write1DData("root:Packages:NIST:VSANS:",activeType,newFileName+"."+exten)             //don't pass the full path, just the name
2563                                else
2564                                        // remove the q=0 point from the back detector, if it's there
2565                                        // does not trim any of the data
2566                                        V_RemoveQ0_B(activeType)
2567                                        V_Write1DData_ITX("root:Packages:NIST:VSANS:",activeType,newFileName,binType)
2568                                endif
2569                                Print "data written to:  "+ newFileName+"."+exten
2570
2571                endswitch
2572               
2573        Endif
2574       
2575        //done with everything in protocol list
2576       
2577       
2578        // reset any global preferences that I had changed
2579        gDoDIVCor = saved_gDoDIVCor
2580       
2581       
2582        Return(0)
2583End
2584
2585
2586
2587
2588
2589//missing parameter dialog to solicit the 4 absolute intensity parameters
2590//from the user
2591//values are passed back as a global string variable (keyword=value)
2592//
2593Proc V_AskForAbsoluteParams(c2,c3,c4,c5,I_err)
2594        Variable c2=1,c3=1,c4=1e8,c5=1,I_err=1
2595        Prompt c2, "Standard Transmission"
2596        Prompt c3, "Standard Thickness (cm)"
2597        Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)"
2598        Prompt c5, "Standard Cross-Section (cm-1)"
2599        Prompt I_err, "error in I(q=0) (one std dev)"
2600       
2601        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr=""
2602       
2603        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr = "TSTAND="+num2str(c2)
2604        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "DSTAND="+num2str(c3)
2605        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "IZERO="+num2str(c4)
2606        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "XSECT="+num2str(c5)
2607        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "SDEV="+num2str(I_err)
2608       
2609End
2610
2611
2612//
2613// TODO
2614// -- fill in all of the functionality for calculation from direct beam
2615//  and verify that the calculations are numerically correct
2616//
2617//asks the user for absolute scaling information. the user can either
2618//enter the necessary values in manually (missing parameter dialog)
2619//or the user can select an empty beam file from a standard open dialog
2620//if an empty beam file is selected, the "kappa" value is automatically calculated
2621//in either case, the global keyword=value string is set.
2622//
2623Function V_AskForAbsoluteParams_Quest()
2624       
2625        Variable err,loc,refnum
2626        //ask user if he wants to use a transmision file for absolute scaling
2627        //or if he wants to enter his own information
2628        err = V_UseStdOrEmpForABS()
2629        //DoAlert 1,"<Yes> to enter your own values, <No> to select an empty beam flux file"
2630        If ( err==1 )
2631                //secondary standard selected, prompt for values
2632                Execute "V_AskForAbsoluteParams()"              //missing parameters
2633        else
2634                //empty beam flux file selected, prompt for file, and use this to calculate KAPPA
2635                Variable kappa=1
2636                Variable kappa_err
2637                       
2638                //get the necessary variables for the calculation of kappa
2639                Variable countTime,monCnt,sdd,pixel
2640                String detStr,junkStr,errStr
2641
2642                Variable empAttenFactor,        emp_atten_err
2643               
2644                //get the XY box and files
2645                Variable x1,x2,y1,y2,emptyCts,empty_ct_err
2646                String emptyFileName,tempStr,divFileName
2647               
2648                // TODO
2649                // x- need an empty beam file name
2650                //
2651                Prompt emptyFileName,"Empty Beam File",popup,V_PickEMPBeamButton("")
2652                DoPrompt "Select File",emptyFileName
2653                if (V_Flag)
2654                        return 0                                                                        // user canceled
2655                endif
2656
2657                //need the detector sensitivity file - make a guess, allow to override
2658                Prompt divFileName,"DIV File",popup,V_PickDIVButton("")
2659                DoPrompt "Select File",divFileName
2660                if (V_Flag)
2661                        return 0                                                                        // user canceled
2662                endif
2663                V_LoadHDF5Data(divFileName,"DIV")
2664
2665
2666                WAVE xyBoxW = V_getBoxCoordinates(emptyFileName)
2667                // TODO
2668                // -- need to get the panel string for the sum.
2669                // -- the detector string is currently hard-wired
2670                detStr = "B"
2671
2672               
2673                // load in the data, and use all of the corrections, especially DIV
2674                // (be sure the corrections are actually set to "on", don't assume that they are)
2675                // save preferences for file loading
2676                Variable savDivPref,savSAPref
2677                NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor
2678                savDivPref = gDoDIVCor
2679                NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor
2680                savSAPref = gDoSolidAngleCor
2681               
2682                // set local preferences
2683                gDoDIVCor = 1
2684                gDoSolidAngleCor = 1
2685               
2686                V_LoadAndPlotRAW_wName(emptyFileName)
2687                // convert raw->SAM
2688                V_Raw_to_work("SAM")
2689                V_UpdateDisplayInformation("SAM")       
2690               
2691                // and determine box sum and error
2692                // store these locally
2693                emptyCts = V_SumCountsInBox(xyBoxW[0],xyBoxW[1],xyBoxW[2],xyBoxW[3],empty_ct_err,"SAM",detStr)
2694
2695                Print "empty counts = ",emptyCts
2696                Print "empty err/counts = ",empty_ct_err/emptyCts
2697
2698                //              TODO
2699                // -- get all of the proper values for the calculation
2700                // -- currently the attenuation is incorrect
2701                //   such that kappa_err = 1*kappa
2702                // -- verify the calculation (no solid angle needed)
2703               
2704                DoAlert 0,"This calculation is not reliable - attenuation is not calibrated"
2705               
2706                // get the attenuation factor for the empty beam
2707                empAttenFactor = V_getAttenuator_transmission(emptyFileName)
2708                emp_atten_err = V_getAttenuator_trans_err(emptyFileName)
2709               
2710                countTime = V_getCount_time(emptyFileName)
2711               
2712                // TODO
2713                // -- not sure if this is the correct monitor count to use, but I do know to use "SAM"
2714                //   rather than the file.
2715                monCnt = V_getBeamMonNormData("SAM")
2716               
2717               
2718               
2719//              kappa = detCnt/countTime/attenTrans*1.0e8/(monCnt/countTime)*(pixel/sdd)^2
2720                kappa = emptyCts/countTime/empAttenFactor*1.0e8/(monCnt/countTime)
2721               
2722                kappa_err = (empty_ct_err/emptyCts)^2 + (emp_atten_err/empAttenFactor)^2
2723                kappa_err = sqrt(kappa_err) * kappa
2724               
2725                // TODO
2726                // -- set the parameters in the global string
2727                junkStr = num2str(kappa)
2728                errStr = num2Str(kappa_err)
2729                Execute "V_AskForAbsoluteParams(1,1,"+junkStr+",1,"+errStr+")"          //no missing parameters, no dialog
2730               
2731
2732                Printf "Kappa was (maybe) successfully calculated as = %g +/- %g (%g %)\r",kappa,kappa_err,(kappa_err/kappa)*100
2733       
2734                // restore preferences on exit
2735                gDoDIVCor = savDivPref
2736                gDoSolidAngleCor = savSAPref
2737
2738        Endif
2739       
2740End
2741
2742Function V_UserSelectBox_Continue(ctrlName) :buttonControl
2743        String ctrlName
2744       
2745        DoWindow/K junkWindow           //kill panel
2746end
2747
2748Function V_SelectABS_XYBox(x1,x2,y1,y2)
2749        Variable &x1,&x2,&y1,&y2
2750       
2751        Variable err=0
2752       
2753        Variable/G root:V_marquee=1             //sets the sneaky bit to automatically update marquee coords
2754        Variable/G root:V_left,root:V_right,root:V_bottom,root:V_top    //must be global for auto-update
2755        DoWindow/F SANS_Data
2756        NewPanel/K=2 /W=(139,341,382,432) as "Select the primary beam"
2757        DoWindow/C junkWindow
2758        AutoPositionWindow/E/M=1/R=SANS_Data
2759       
2760        Drawtext 21,20 ,"Select the primary beam with the"
2761        DrawText 21,40, "marquee and press continue"
2762        Button button0,pos={80,58},size={92,20},title="Continue"
2763        Button button0,proc=V_UserSelectBox_Continue
2764       
2765        PauseForUser junkWindow,SANS_Data
2766       
2767        DoWindow/F SANS_Data
2768
2769        //GetMarquee left,bottom                        //not needed
2770        NVAR V_left=V_left
2771        NVAR V_right=V_right
2772        NVAR V_bottom=V_bottom
2773        NVAR V_top=V_top
2774       
2775        x1 = V_left
2776        x2 = V_right
2777        y1 = V_bottom
2778        y2 = V_top
2779//      Print "new values,before rounding = ",x1,x2,y1,y2
2780
2781// TODO -- replace this call
2782//      KeepSelectionInBounds(x1,x2,y1,y2)
2783        //Print "new values = ",x1,x2,y1,y2
2784       
2785        KillVariables/Z root:V_Marquee,root:V_left,root:V_right,root:V_bottom,root:V_top
2786        if((x1-x2)==0 || (y1-y2)==0)
2787                err=1
2788        endif
2789        return(err)
2790End
2791
2792Function V_UseStdOrEmpForABS()
2793               
2794        NewPanel/K=2 /W=(139,341,402,448) as "Absolute Scaling"
2795        DoWindow/C junkABSWindow
2796        ModifyPanel cbRGB=(57346,65535,49151)
2797        SetDrawLayer UserBack
2798        SetDrawEnv fstyle= 1
2799        DrawText 21,20,"Method of absolute calibration"
2800        Button button0,pos={52,33},size={150,20},proc=V_UserSelectABS_Continue,title="Empty Beam Flux"
2801        Button button1,pos={52,65},size={150,20},proc=V_UserSelectABS_Continue,title="Secondary Standard"
2802       
2803        PauseForUser junkABSWindow
2804        NVAR val = root:Packages:NIST:VSANS:Globals:tmpAbsVal
2805        return(val)
2806End
2807
2808//returns 0 if button0 (empty beam flux)
2809// or 1 if secondary standard
2810Function V_UserSelectABS_Continue(ctrlName) :buttonControl
2811        String ctrlName
2812       
2813        variable val=0
2814        If(cmpstr(ctrlName,"button0")==0)
2815                val=0           
2816        else
2817                val=1
2818        endif
2819//      print "val = ",ctrlName,val
2820        Variable/G root:Packages:NIST:VSANS:Globals:tmpAbsVal = val
2821        DoWindow/K junkABSWindow                //kill panel
2822        return(0)
2823end
2824
2825
2826Function V_TrimDataProtoButton(ctrlName) :buttonControl
2827        String ctrlName
2828       
2829        Execute "V_CombineDataGraph()"
2830        return(0)
2831end
2832
2833//
2834// export protocol to a data file
2835//
2836//
2837Function V_ExportFileProtocol(ctrlName) : ButtonControl
2838        String ctrlName
2839// get a list of protocols
2840        String Protocol=""
2841        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
2842        Prompt Protocol "Pick A Protocol",popup, V_DeletableProtocols()
2843        DoPrompt "Pick A Protocol to Export",Protocol
2844        if(V_flag==1)
2845                //Print "user cancel"
2846                SetDatafolder root:
2847                return(1)
2848        endif
2849
2850        String fileName = V_DoSaveFileDialog("pick the file to write to")
2851        print fileName
2852//     
2853        if(strlen(fileName) == 0)
2854                return(0)
2855        endif
2856
2857        V_writeReductionProtocolWave(fileName,$("root:Packages:NIST:VSANS:Globals:Protocols:"+Protocol) )
2858
2859        setDataFolder root:
2860        return(0)
2861
2862End
2863
2864//
2865// imports a protocol from a file on disk into the protocols folder
2866//
2867//
2868Function V_ImportFileProtocol(ctrlName) : ButtonControl
2869        String ctrlName
2870
2871//      SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
2872
2873        String fullPath,fileName
2874        fullPath = DoOpenFileDialog("Import Protocol from file")
2875        print fullPath
2876//     
2877        if(strlen(fullPath) == 0)
2878                return(0)
2879        endif
2880       
2881        fileName = ParseFilePath(0, fullPath, ":", 1, 0)                        //just the file name at the end of the full path
2882       
2883        Wave/T tmpW = V_getReductionProtocolWave(fileName)
2884        if(numpnts(tmpW) == 0)
2885                DoAlert 0,"No protocol wave has been saved to this data file"
2886                return(0)
2887        endif
2888       
2889        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
2890        String newName
2891        newName = CleanupName(fileName,0) + "_proto"
2892        duplicate/o tmpw $newName
2893       
2894       
2895        SetDataFolder root:
2896        return(0)
2897end
2898
2899
2900// currently not used - and not updated to 12 point protocols (5/2017)
2901//
2902//save the protocol as an IGOR text wave (.itx)
2903//
2904//
2905Function V_ExportProtocol(ctrlName) : ButtonControl
2906        String ctrlName
2907// get a list of protocols
2908        String Protocol=""
2909        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
2910        Prompt Protocol "Pick A Protocol",popup, WaveList("*",";","")
2911        DoPrompt "Pick A Protocol to Export",Protocol
2912        if(V_flag==1)
2913                //Print "user cancel"
2914                SetDatafolder root:
2915                return(1)
2916        endif
2917//get the selection, or exit
2918        Wave/T pW= $protocol
2919        Make/O/T/N=13 tw
2920// save in the proper format (must write manually, for demo version)
2921        tw[0] = "IGOR"
2922        tw[1] = "WAVES/T \t"+protocol
2923        tw[2] = "BEGIN"
2924        tw[3,10] = "\t\""+pW[p-3]+"\""
2925        tw[11] = "END"
2926        tw[12] = "X SetScale/P x 0,1,\"\","+protocol+"; SetScale y 0,0,\"\","+protocol
2927       
2928        Variable refnum
2929        String fullPath
2930       
2931        PathInfo/S catPathName
2932        fullPath = DoSaveFileDialog("Export Protocol as",fname=Protocol,suffix="")
2933        If(cmpstr(fullPath,"")==0)
2934                //user cancel, don't write out a file
2935                Close/A
2936                Abort "no Protocol file was written"
2937        Endif
2938
2939        //actually open the file
2940        Open refNum as fullpath+".itx"
2941       
2942        wfprintf refnum, "%s\r", tw
2943        Close refnum
2944        //Print "all is well  ",protocol
2945        KillWaves/Z tw
2946        setDataFolder root:
2947        return(0)
2948
2949End
2950
2951
2952// currently not used - and not updated to 12 point protocols (5/2017)
2953//imports a protocol from disk into the protocols folder
2954//
2955// will overwrite existing protocols if necessary
2956//
2957//
2958Function V_ImportProtocol(ctrlName) : ButtonControl
2959        String ctrlName
2960
2961        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
2962
2963        String fullPath
2964       
2965        PathInfo/S catPathName
2966        fullPath = DoOpenFileDialog("Import Protocol")
2967        If(cmpstr(fullPath,"")==0)
2968                //user cancel, don't write out a file
2969                Close/A
2970                Abort "no protocol was loaded"
2971        Endif
2972       
2973        LoadWave/O/T fullPath
2974       
2975        SetDataFolder root:
2976        return(0)
2977end
Note: See TracBrowser for help on using the repository browser.