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

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

First pass at routines to interactively combine and mask VSANS 1-D data sets. Based on masking as done in the USANS Desmearing panel.

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