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

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

corrected bad logic in reduction when reducing to 2D. Nothing was wrong, just a meaningless error dialog was presented.

updated the beamstop sizes in SASCALC for the NGB-10m SANS instrument. Now the 4 beamstops are 1", 1.5", 2" and 3".

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