source: sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/SANS/ProtocolAsPanel.ipf @ 1171

Last change on this file since 1171 was 1171, checked in by krzywon, 3 years ago

Add 2D NXcanSAS output as SANS reduction option.

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