source: sans/Dev/branches/elliptical_averaging/NCNR_User_Procedures/Reduction/SANS/ProtocolAsPanel.ipf @ 1213

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

Add elliptical averaging into protocol panel.

File size: 79.2 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;Elliptical;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, Elliptical, 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 -OR- Ratio of minor to major axes of ellipse"
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
1010       
1011        if(cmpstr(av_typ,"Elliptical")==0)
1012                Execute "GetEllipticalAvgInfo()"
1013        Endif
1014End
1015
1016Proc GetEllipticalAvgInfo(phi,AxisRatio)
1017        Variable phi=0,AxisRatio=1
1018        Prompt phi,"Orientation Angle (-90,90) degrees (Rectangular, Elliptical, or Sector)"
1019        Prompt AxisRatio, "Ratio of minor to major axes of ellipse"
1020       
1021        root:myGlobals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";"
1022        root:myGlobals:Protocols:gAvgInfoStr += "RATIOAXES=" + num2str(AxisRatio) + ";"
1023End
1024
1025//not used????
1026//checks the syntax of all of the file fields in the panel
1027Function CheckProtocolSyntax(ctrlName) : ButtonControl
1028        String ctrlName
1029       
1030        String retStr=""
1031        //SAM
1032        SVAR list = root:myGlobals:Protocols:gSAM
1033        retStr = ParseRunNumberList(list)
1034        if(strlen(retStr)==0)
1035                //error
1036                Print "SAM Syntax Error"
1037                return(1)
1038        else
1039                list = retStr
1040                Print "SAM syntax OK"
1041        Endif
1042
1043        //MASK
1044        SVAR list = root:myGlobals:Protocols:gMASK
1045        retStr = ParseRunNumberList(list)
1046       
1047End
1048//*************
1049
1050
1051
1052//
1053// Procedure files for creating and executing a data reduction protocol
1054//
1055//**** ONLY invoked from the MAIN PANEL**** NOT REALLY EVER USED ******
1056//Procedure for reducing a sample file (multiple added files) with a specified
1057//protocol. User may create a new protocol, and will be prompted
1058//for information "questionnare-style" where the user must know the
1059//filenames for empty cell, background...etc.. as they will be presented
1060//with standard file open dialogs to select each file desired for use in the
1061//new protocol
1062//once a protocol is selected (or created) the uer is propmted for sample data
1063// and the file is processed through the protocol.
1064//
1065Proc ReduceAFile()
1066
1067        String protocolName="",waveStr="",samStr = "ask"
1068        Variable err
1069       
1070        //pick a protocol wave from the Protocols folder
1071        //must switch to protocols folder to get wavelist (missing parameter)
1072        SetDataFolder root:myGlobals:Protocols
1073        PickAProtocol()
1074       
1075        //get the selected protocol wave choice through a global string variable
1076        protocolName = root:myGlobals:Protocols:gProtoStr
1077       
1078        //If "CreateNew" was selected, go to the questionnare, to make a new set
1079        //and put the name of the new Protocol wave in gProtoStr
1080        if(cmpstr("CreateNew",protocolName) == 0)
1081                ProtocolQuestionnare()
1082                protocolName = root:myGlobals:Protocols:gProtoStr
1083        Endif
1084       
1085        //give the full path:name to the executeProtocol function
1086        waveStr = "root:myGlobals:Protocols:"+protocolName
1087        //samStr is set at top to "ask", since this is the action always desired from "ReduceAFile"
1088       
1089        ExecuteProtocol(waveStr,samStr)
1090       
1091        //return data folder to root before Macro is done
1092        SetDataFolder root:
1093       
1094End
1095
1096
1097//prompts the user to pick a previously created protocol from a popup list
1098//of given the option to create a new protocol
1099//the chosen protocol is passed back to the calling procedure by a global string
1100//the popup is presented as a missing parameter dialog (called with empty parameter list)
1101//
1102Proc PickAProtocol(protocol)
1103        String Protocol
1104        Prompt Protocol "Pick A Protocol",popup, WaveList("*",";","")
1105       
1106        String/G  root:myGlobals:Protocols:gProtoStr = protocol
1107End
1108
1109Proc DeleteAProtocol(protocol)
1110        String Protocol
1111//      Prompt Protocol "Delete A Protocol",popup, WaveList("*",";","")
1112        Prompt Protocol "Delete A Protocol",popup, DeletableProtocols()
1113
1114        String/G  root:myGlobals:Protocols:gProtoStr = protocol
1115End
1116
1117Function/S DeletableProtocols()
1118        String list=WaveList("*",";","")
1119
1120        list= RemoveFromList("Base", list  , ";")
1121        list= RemoveFromList("DoAll", list  , ";")
1122        list= RemoveFromList("CreateNew", list  , ";")
1123        list= RemoveFromList("tempProtocol", list  , ";")
1124        if(cmpstr(list,"")==0)
1125                list = "_no_protocols_;"
1126        endif
1127       
1128        return(list)
1129End
1130
1131//missing paramater dialog to solicit user for a waveStr for the protocol
1132//about to be created
1133//name is passed back as a global string and calling procedure is responsible for
1134//checking for wave conflicts and valid names
1135//
1136Proc AskForName(protocol)
1137        String Protocol
1138        Prompt Protocol "Enter a new name for your protocol (no extension)"
1139       
1140        String/G  root:myGlobals:Protocols:gNewStr = protocol
1141End
1142
1143//this is a lengthy procedure for sequentially polling the user about what data
1144//reduction steps they want to be performed during the protocol
1145//ensures that a valid protocol name was chosen, then fills out each "item"
1146//(6 total) needed for reduction
1147//it the user cancels at any point, the partial protocol will be deleted
1148//
1149Function ProtocolQuestionnare()
1150        String filename,cmd
1151        Variable notDone,refnum
1152       
1153        //prompt for name of new protocol wave to save
1154        do
1155                Execute "AskForName()"
1156                SVAR newProtoStr = root:myGlobals:Protocols:gNewStr
1157               
1158                //make sure it's a valid IGOR name
1159                newProtoStr = CleanupName(newProtoStr,0)        //strict naming convention
1160                String/G root:myGlobals:Protocols:gNewStr=newProtoStr           //reassign, if changed
1161                //Print "newProtoStr = ",newProtoStr
1162               
1163                SetDataFolder root:myGlobals:Protocols
1164                if(WaveExists( $("root:myGlobals:Protocols:" + newProtoStr) ) == 1)
1165                        //wave already exists
1166                        DoAlert 0,"that name is already in use. Please pick a new name"
1167                        notDone = 1
1168                else
1169                        //name is  good
1170                        notDone = 0
1171                Endif
1172        while(notDone)
1173       
1174        //Print "protocol questionnare is "+newProtocol
1175       
1176        //make a new text wave (6 points) and fill it in, in response to questions
1177        SetDataFolder root:myGlobals:Protocols //(redundant - full wave specs are used)
1178        Make/O/T/N=8 $("root:myGlobals:Protocols:" + newProtoStr)
1179        Wave/T newProtocol = $("root:myGlobals:Protocols:" + newProtoStr)
1180       
1181        //ask the questions
1182        /////
1183        //*****Multiple files in these lists are full paths/filenames which may or may not
1184        //have semicolon version numbers in the filename. Therefore, construct the list with
1185        //COMMAS as separators - to avoid messy parsing
1186        ///////
1187       
1188       
1189//////////////////////////
1190        String drkStr="",fileStr=""
1191        DoAlert 1,"Do you want to correct your data for DRK (beam off) counts?"
1192        if(V_flag == 1)         //1=yes
1193                //prompt for DRK  file, but don't actually open it (/D flag)
1194                Open/D/R/T="TEXT????"/M="Select the DRK file"/P=catPathName refnum
1195                //check for cancel
1196                if(strlen(S_filename)==0)
1197                        //user cancelled, abort
1198                        KillWaves/Z newProtocol
1199                        SetDataFolder root:
1200                        Abort "Incomplete protocol has been deleted"
1201                Endif
1202                //assign filename (just the name) to [6]
1203                fileStr = GetFileNameFromPathNoSemi(S_filename)
1204                drkStr = "DRK=none,DRKMODE=0,"
1205                drkStr = ReplaceStringByKey("DRK",drkStr,fileStr,"=",",")
1206                drkStr = ReplaceNumberByKey("DRKMODE", drkStr, 10 ,"=",",")     
1207                newProtocol[6] = drkStr
1208        else
1209                //no Work.DRK desired
1210                newProtocol[6] = "DRK=none,DRKMODE=0,"
1211        Endif
1212       
1213////////////
1214       
1215/////////////////
1216        DoAlert 1,"Do you want to subtract background from your data?"
1217        if(V_flag == 1)         //1=yes
1218                //prompt for background file, but don't actually open it (/D flag)
1219                Open/D/R/T="TEXT????"/M="Select the Background data file"/P=catPathName refnum
1220                //check for cancel
1221                if(strlen(S_filename)==0)
1222                        //user cancelled, abort
1223                        KillWaves/Z newProtocol
1224                        SetDataFolder root:
1225                        Abort "Incomplete protocol has been deleted"
1226                Endif
1227                //assign filename (full path) to [0]
1228                newProtocol[0] = GetFileNameFromPathNoSemi(S_filename)
1229               
1230                notDone=1
1231                do
1232                        //prompt for additional background files
1233                        DoAlert 1,"Do you want to add another background file?"
1234                        if(V_flag == 1)         //yes
1235                                Open/D/R/T="TEXT????"/M="Select another Background data file"/P=catPathName refnum
1236                                //check for cancel
1237                                if(strlen(S_filename)==0)
1238                                        //user cancelled, abort ********maybe just break out of the loop here
1239                                        KillWaves/Z newProtocol
1240                                        SetDataFolder root:
1241                                        Abort "Incomplete protocol has been deleted"
1242                                Endif
1243                                //assign filename (full path) to [0]
1244                                newProtocol[0] += "," + GetFileNameFromPathNoSemi(S_filename)           //***COMMA separated list
1245                                notDone = 1             //keep going
1246                        else
1247                                notDone = 0                     //no more to add
1248                        Endif
1249                While(notDone)
1250        else            //no background desired
1251                newProtocol[0] = "none"
1252        Endif
1253////////////////////// 
1254        DoAlert 1,"Do you want to subtract empty cell scattering from your data?"
1255        if(V_flag == 1)         //1=yes
1256                //prompt for Empty cell file, but don't actually open it (/D flag)
1257                Open/D/R/T="TEXT????"/M="Select the Empty Cell data file"/P=catPathName refnum
1258                //check for cancel
1259                if(strlen(S_filename)==0)
1260                        //user cancelled, abort
1261                        KillWaves/Z newProtocol
1262                        SetDataFolder root:
1263                        Abort "Incomplete protocol has been deleted"
1264                Endif
1265                //assign filename (full path) to [1]
1266                newProtocol[1] = GetFileNameFromPathNoSemi(S_filename)
1267               
1268                notDone=1
1269                do
1270                        //prompt for additional Empty Cell files
1271                        DoAlert 1,"Do you want to add another Empty Cell file?"
1272                        if(V_flag == 1)         //yes
1273                                Open/D/R/T="TEXT????"/M="Select another Empty Cell data file"/P=catPathName refnum
1274                                //check for cancel
1275                                if(strlen(S_filename)==0)
1276                                        //user cancelled, abort ********maybe just break out of the loop here
1277                                        KillWaves/Z newProtocol
1278                                        SetDataFolder root:
1279                                        Abort "Incomplete protocol has been deleted"
1280                                Endif
1281                                //assign filename (full path) to [1]
1282                                newProtocol[1] += "," + GetFileNameFromPathNoSemi(S_filename)           //***COMMA separated list
1283                                notDone = 1             //keep going
1284                        else
1285                                notDone = 0                     //no more to add
1286                        Endif
1287                While(notDone)
1288        else            //no background desired
1289                newProtocol[1] = "none"
1290        Endif
1291//////////////////////////
1292        DoAlert 1,"Do you want to correct your data for detector sensitivity?"
1293        if(V_flag == 1)         //1=yes
1294                //prompt for DIV  file, but don't actually open it (/D flag)
1295                Open/D/R/T="TEXT????"/M="Select the detector sensitivity file"/P=catPathName refnum
1296                //check for cancel
1297                if(strlen(S_filename)==0)
1298                        //user cancelled, abort
1299                        KillWaves/Z newProtocol
1300                        SetDataFolder root:
1301                        Abort "Incomplete protocol has been deleted"
1302                Endif
1303                //assign filename (full path) to [2]
1304                newProtocol[2] = GetFileNameFromPathNoSemi(S_filename)
1305        else
1306                //no Work.DIV desired
1307                newProtocol[2] = "none"
1308        Endif   
1309//////////////////////////
1310        DoAlert 1,"Do you want to mask your files before averaging?"
1311        if(V_flag == 1)         //1=yes
1312                //prompt for mask  file, but don't actually open it (/D flag)
1313                Open/D/R/T="TEXT????MASK"/M="Select the mask file"/P=catPathName refnum
1314                //check for cancel
1315                if(strlen(S_filename)==0)
1316                        //user cancelled, abort
1317                        KillWaves/Z newProtocol
1318                        SetDataFolder root:
1319                        Abort "Incomplete protocol has been deleted"
1320                Endif
1321                //assign filename (full path) to [3]
1322                newProtocol[3] = GetFileNameFromPathNoSemi(S_filename)
1323        else
1324                //no MASK desired
1325                newProtocol[3] = "none"
1326        Endif   
1327       
1328        //absolute scaling
1329       
1330        //////////////////////////
1331        //ABS parameters stored as keyword=value string
1332        DoAlert 1,"Do you want absolute scaling?"
1333        if(V_flag == 1)         //1=yes
1334                //missing param - prompt for values, put in semicolon-separated list
1335                Execute "AskForAbsoluteParams_Quest()"
1336                SVAR absStr =  root:myGlobals:Protocols:gAbsStr
1337                newProtocol[4] = absStr
1338        else
1339                //no absolute scaling desired
1340                newProtocol[4] = "none"
1341        Endif   
1342       
1343        //type of average, plot?, auto/manual naming/saving... put in semicolon separated string
1344        //of KEY=<value> format for easy parsing
1345        //Kewords are: AVTYPE,PHI,DPHI,PLOT,SAVE,NAME,SIDE,WIDTH
1346        //note that AVTYPE,NAME,SIDE have string values, others have numerical values
1347        ///////////////////////
1348        DoAlert 1,"Do you want to average your data to I vs. q?"
1349        if(V_flag == 1)         //1=yes
1350                String/G root:myGlobals:Protocols:gAvgInfoStr = ""
1351                Execute "GetAvgInfo()"          //will put up missing paramter dialog and do all the work
1352                //:gAvgInfo is reset by the Proc(), copy this string tot he protocol
1353                SVAR tempStr=root:myGlobals:Protocols:gAvgInfoStr
1354               
1355                //get a file path for saving files, if desired
1356                /////no - save files to the same data folder as the one with the raw data
1357                //then only one path to manage.
1358                //String yesNo = StringByKey("SAVE", tempStr,"=", ";")
1359                //if(cmpstr("Yes",yesNo) == 0)          //0=yes
1360                        //NewPath/C/M="Select Folder"/O Save_path               //Save_path is the symbolic path
1361                //Endif
1362
1363                newProtocol[5] = tempStr
1364                KillStrings/Z tempStr
1365        else
1366                //no averaging desired
1367                newProtocol[5] = "AVTYPE=none"
1368        Endif
1369       
1370        //returns the name of the newly created (= currently in use) protocol wave through a global
1371        String/G root:myGlobals:Protocols:gProtoStr = newProtoStr
1372End
1373
1374//function to check the work files (to see what's already there)
1375//and compare that with the files that are supposed to be there, according to the
1376//current protocol (to save unnecessary time re-loading files)
1377//
1378//the "type" folder is checked for all files in the list req(ested)Files
1379//note that the list of files is a full path:name;ver, while the
1380//fileList in the folder is just the name (or a list of names)
1381//
1382//returns 0 false, if files are NOT present
1383//or 1 = true, yes, the files are there as requested
1384//
1385Function AreFilesThere(type,reqFiles)
1386        String type,reqFiles
1387       
1388        //in general, reqFiles is a list of full paths to files - which MAY include semicolon version numbers
1389        //reqFiles MUST be constructed with COMMAS as list separators, to avoid disaster
1390        //when the version numbers are interpreted as filenames
1391       
1392        //get the number of files requested
1393        Variable nReq,nCur,match,ii
1394        nReq = ItemsInList(reqFiles,",")
1395       
1396        //get the name of the file currently in BGD - in the global fileList
1397        //fileList has NAMES ONLY - since it was derived from the file header
1398        String testStr
1399        testStr = "root:Packages:NIST:"+type+":fileList"
1400        if(Exists(testStr) == 2)                //2 if string variable exists
1401                SVAR curFiles = $testStr
1402        else
1403                //no files currently in type folder, return zero
1404                Return (0)
1405        Endif
1406        //get the number of files already in folder
1407        nCur = ItemsInList(curFiles,";")
1408        If(nCur != nReq)
1409                Return (0)              //quit now, the wrong number of files present
1410        Endif
1411        //right number of files... are the names right...
1412        //check for a match (case-sensitive!!) of each requested file in the curFile string
1413        //need to extract filenames from reqFiles, since they're the full path and name
1414       
1415        ii=0
1416        do
1417                testStr = StringFromList(ii,reqFiles,",")       //testStr is the Nth full path and filename
1418                //testStr = GetFileNameFromPathNoSemi(testStr)  //testStr will now be just the filename
1419                match = stringmatch(curFiles,testStr)
1420                If(!match)
1421                        Return (0)              //req file was not found in curFile list - get out now
1422                Endif
1423                ii+=1
1424        while(ii<nreq)
1425       
1426        Return (1)              //indicate that files are OK, no changes needed
1427End
1428
1429//will add the files specified in the protocol to the "type" folder
1430//will add multiple files together if more than one file is requested
1431//(list is a comma delimited list of filenames, with NO path information)
1432//
1433// This routine NOW DOES check for the possibility that the filenames may have ";vers" from the
1434// VAX - data should be picked up from Charlotte, where it won't have version numbers.
1435//
1436Function AddFilesInList(type,list)
1437        String type,list
1438       
1439        //type is the work folder to put the data into, and list is a COMMA delimited list of paths/names
1440        Variable num,ii,err=0,refNum
1441        String filename,pathStr=""
1442        PathInfo catPathName                    //this is where the files are
1443        pathstr=S_path
1444       
1445        num = ItemsInList(list,",")             // comma delimited list
1446       
1447        ii=0
1448        do
1449                //FindValidFilename only needed in case of vax version numbers
1450                filename = pathStr + FindValidFilename(StringFromList(ii,list,","))
1451                Open/Z/R refnum as filename
1452                if(V_flag != 0)         //file not found
1453                        //Print "file not found AddFilesInList()"
1454                        //Print filename
1455                        err = 1
1456                        return(err)
1457                Endif
1458                Close refnum            //file was found and opened, so close it
1459                ReadHeaderAndData(filename)
1460                if(ii == 0)
1461                        //first pass, wipe out the old contents of the work file
1462                        err =  Raw_to_work(type)
1463                else
1464                        err = Add_raw_to_work(type)
1465                Endif
1466                ii+=1
1467        while(ii<num)
1468        return(err)
1469End
1470
1471//function will reduce a sample file (or ask for file(s))
1472//using the protocol named as "protoStr" in the Protocols subfolder
1473//samStr is the file(s) or "ask" to force prompt
1474//sequentially proceeds through flowchart, doing reduction steps as needed
1475//show Schematic to debug what steps/values were used
1476//
1477//function is long, but straightforward logic
1478//
1479Function ExecuteProtocol(protStr,samStr)
1480        String protStr,samStr
1481        //protStr is the full path to the selected protocol wave
1482        //samStr is either "ask" or the name ONLY ofthe desired sample data file(s) (NO PATH)
1483        WAVE/T prot = $protStr
1484        SetDataFolder root:myGlobals:Protocols
1485       
1486        Variable filesOK,err,notDone
1487        String activeType, msgStr, junkStr, pathStr=""
1488        PathInfo catPathName                    //this is where the files are
1489        pathStr=S_path
1490       
1491        NVAR useXMLOutput = root:Packages:NIST:gXML_Write
1492        NVAR useNXcanSASOutput = root:Packages:NIST:gNXcanSAS_Write
1493       
1494        //Parse the instructions in the prot wave
1495        //0 - bkg
1496        //1 - emp
1497        //2 - div
1498        //3 - mask
1499        //4 - abs params c2-c5
1500        //5 - average params
1501        //6 = DRK file (**out of sequence)
1502       
1503        //prompt for sam data => read raw data, add to sam folder
1504        //or parse file(s) from the input paramter string
1505        activeType = "SAM"
1506        msgStr = "Select sample data"
1507        //Ask for SAM file or parse
1508        do
1509                if((cmpstr(samStr,"ask") == 0) || (cmpstr(samStr,"")==0) )              //zero if strings are equal
1510                        err = LoadRawSANSData(msgStr)           //will prompt for file
1511                        if(err)
1512                                PathInfo/S catPathName
1513                                Abort "reduction sequence aborted"
1514                        endif
1515                        UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
1516                        err =  Raw_to_work(activeType)          //this is the first file (default)
1517                        //Ask for another SAM file
1518                        do
1519                                DoAlert 1,"Do you want to add another Sample file?"
1520                                if(V_flag == 1)         //yes
1521                                        err = LoadRawSANSData(msgStr)           //will prompt for file
1522                                        if(err)
1523                                                PathInfo/S catPathName
1524                                                Abort "reduction sequence aborted"
1525                                        endif
1526                                        UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
1527                                        err = Add_raw_to_work(activeType)
1528                                        notDone = 1
1529                                else
1530                                        notDone = 0
1531                                endif
1532                        while(notDone)
1533                        break
1534                Endif
1535                //"none" is not an option - you always need a sample file - "none" will never return zero
1536                //if not "ask" AND not "none" then try to parse the filenames
1537                If((cmpstr(samStr,"none") != 0) && (cmpstr(samStr,"ask") != 0))
1538                        //filesOK = AreFilesThere(activeType,samStr)            //return 1 if correct files are already there
1539                        filesOK = 0             // Feb 2008, always force a reload of files. Maybe slow, but always correct
1540                        if(!filesOK)
1541                                //add the correct file(s) to SAM
1542                                err = AddFilesInList(activeType,samStr)
1543                                if(err)
1544                                        //Print "samstr = ",samStr
1545                                        Abort "SAM file not found, reset SAM file"
1546                                Endif
1547                        Endif
1548                Endif
1549        While(0)
1550        //always update
1551        UpdateDisplayInformation(ActiveType)
1552       
1553        //check for bkg file  -- "ask" might not fail - "ask?" will - ? not allowed in VAX filenames
1554        // add if needed
1555        //use a "case" statement
1556        msgStr = "Select background file"
1557        activeType = "BGD"
1558        do
1559                if(cmpstr(prot[0],"ask") == 0)          //zero if strings are equal
1560                        err = LoadRawSANSData(msgStr)           //will prompt for file
1561                        if(err)
1562                                PathInfo/S catPathName
1563                                Abort "reduction sequence aborted"
1564                        endif
1565                        UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
1566                        err =  Raw_to_work(activeType)          //this is the first file (default)
1567                        //Ask for another BGD file
1568                        do
1569                                DoAlert 1,"Do you want to add another Background file?"
1570                                if(V_flag == 1)         //yes
1571                                        err = LoadRawSANSData(msgStr)           //will prompt for file
1572                                        if(err)
1573                                                PathInfo/S catPathName
1574                                                Abort "reduction sequence aborted"
1575                                        endif
1576                                        UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
1577                                        err = Add_raw_to_work(activeType)
1578                                        notDone = 1
1579                                else
1580                                        notDone = 0
1581                                endif
1582                        while(notDone)
1583                        UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1584                        break
1585                Endif
1586                If(cmpstr(prot[0],"none") == 0)
1587                        //clean out the BKG folder?
1588                        //KillDataFolder root:BKG
1589                        //NewDataFolder/O root:BKG
1590                        break
1591                Endif
1592                //if not "ask" AND not "none" then try to parse the filenames
1593                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[0],"ask") != 0))
1594                        //filesOK = AreFilesThere(activeType,prot[0])
1595                        filesOK = 0             // Feb 2008, always force a reload of files. Maybe slow, but always correct
1596                        if(!filesOK)
1597                                //add the correct file(s) to BGD
1598                                err = AddFilesInList(activeType,prot[0])
1599                                If(err)
1600                                        Abort "BGD file not found. Reset BGD file list"
1601                                Endif
1602                        Endif
1603                        UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1604                Endif
1605        While(0)
1606       
1607       
1608        //check for emp file (prot[1])
1609        // add if needed
1610        msgStr = "Select empty cell data"
1611        activeType = "EMP"
1612        do
1613                if(cmpstr(prot[1],"ask") == 0)
1614                        err = LoadRawSANSData(msgStr)           //will prompt for file
1615                        if(err)
1616                                PathInfo/S catPathName
1617                                Abort "reduction sequence aborted"
1618                        endif
1619                        UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
1620                        err =  Raw_to_work(activeType)          //this is the first file (default)
1621                        //Ask for another EMP file
1622                        do
1623                                DoAlert 1,"Do you want to add another Empty Cell file?"
1624                                if(V_flag == 1)         //yes
1625                                        err = LoadRawSANSData(msgStr)           //will prompt for file
1626                                        if(err)
1627                                                PathInfo/S catPathName
1628                                                Abort "reduction sequence aborted"
1629                                        endif
1630                                        UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
1631                                        err = Add_raw_to_work(activeType)
1632                                        notDone = 1
1633                                else
1634                                        notDone = 0
1635                                endif
1636                        while(notDone)
1637                        UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1638                        break
1639                Endif
1640                If(cmpstr(prot[1],"none") == 0)
1641                        //clean out the EMP folder?
1642                        //KillDataFolder root:Packages:NIST:EMP
1643                        //NewDataFolder/O root:Packages:NIST:EMP
1644                        break
1645                Endif
1646                //if not "ask" AND not "none" then try to parse the filenames
1647                If((cmpstr(prot[1],"none") != 0) && (cmpstr(prot[1],"ask") != 0))
1648                        //filesOK = AreFilesThere(activeType,prot[1])
1649                        filesOK = 0             // Feb 2008, always force a reload of files. Maybe slow, but always correct
1650                        if(!filesOK)
1651                                //add the correct file(s) to BGD
1652                                err = AddFilesInList(activeType,prot[1])
1653                                If(err)
1654                                        Abort "EMP file not found. Reset EMP file list"
1655                                Endif
1656                        Endif
1657                        UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1658                Endif
1659        While(0)
1660       
1661        //do the CORRECT step based on the answers to emp and bkg subtraction
1662        //by setting the proper"mode"
1663        //1 = both emp and bgd subtraction
1664        //2 = only bgd subtraction
1665        //3 = only emp subtraction
1666        //4 = no subtraction
1667        //additional modes 091301
1668        //11 = emp, bgd, drk
1669        //12 = bgd and drk
1670        //13 = emp and drk
1671        //14 = no subtractions
1672        //work.drk is from proto[6]
1673        //
1674        //subtracting just the DRK data is NOT an option - it doesnt' really make any physical sense
1675        // - in this case, DRK is skipped (equivalent to mode==4)
1676        // automatically accounts for attenuators given the lookup tables and the
1677        //desired subtractions
1678        //Attenuator lookup tables are alredy implemented (NG1 = NG7)
1679        //
1680       
1681        //read in the DRK data if necessary
1682        //only one file, assumed to be RAW data
1683        //
1684        String fname="",drkStr=""
1685        drkStr=StringByKey("DRK",prot[6],"=",",")
1686        if(cmpstr(drkStr,"none") != 0)
1687                err = ReadHeaderAndData( (pathStr+drkStr) )
1688                if(err)
1689                        PathInfo/S catPathName
1690                        Abort "reduction sequence aborted"
1691                endif
1692                err = Raw_to_Work_NoNorm("DRK")
1693        endif
1694       
1695        //dispatch to the proper "mode" of Correct()
1696        Variable mode=4,val
1697        do
1698                if( (cmpstr("none",prot[0]) == 0)       && (cmpstr("none",prot[1]) == 0) )
1699                        //no subtraction (mode = 4),
1700                        mode = 4
1701                Endif
1702                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[1],"none") == 0))
1703                        //subtract BGD only
1704                        mode=2
1705                Endif
1706                If((cmpstr(prot[0],"none") == 0) && (cmpstr(prot[1],"none") != 0))
1707                        //subtract EMP only
1708                        mode=3
1709                Endif
1710                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[1],"none") != 0))
1711                        // bkg and emp subtraction are to be done (BOTH not "none")
1712                        mode=1
1713                Endif
1714                activeType = "COR"
1715                //add in DRK mode (0= no used, 10 = used)
1716                val = NumberByKey("DRKMODE",prot[6],"=","," )
1717                mode += val
1718//              print "mode = ",mode
1719                err = Correct(mode)
1720                if(err)
1721                        SetDataFolder root:
1722                        Abort "error in Correct, called from executeprotocol, normal cor"
1723                endif
1724                UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1725        While(0)
1726       
1727        //check for work.div file (prot[2])
1728        //add if needed
1729        // can't properly check the filename - so for now add and divide, if anything other than "none"
1730        //do/skip divide step based on div answer
1731        If(cmpstr("none",prot[2])!=0)           // if !0, then there's a file requested
1732                If(cmpstr("ask",prot[2]) == 0)
1733                        //ask user for file
1734                         junkStr = PromptForPath("Select the detector sensitivity file")
1735                        If(strlen(junkStr)==0)
1736                                SetDataFolder root:
1737                                Abort "No file selected, data reduction aborted"
1738                        Endif
1739                         ReadHeaderAndWork("DIV", junkStr)
1740                else
1741                        //assume it's a path, and that the first (and only) item is the path:file
1742                        //list processing is necessary to remove any final comma
1743                        junkStr = pathStr + StringFromList(0, prot[2],"," )
1744                        ReadHeaderAndWork("DIV",junkStr)
1745                Endif
1746                //got a DIV file, select the proper type of work data to DIV (= activeType)
1747                err = Divide_work(activeType)           //returns err = 1 if data doesn't exist in specified folders
1748                If(err)
1749                        SetDataFolder root:
1750                        Abort "data missing in DIV step, call from executeProtocol"
1751                Endif
1752                activeType = "CAL"
1753                UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1754        Endif
1755       
1756        Variable c2,c3,c4,c5,kappa_err
1757        //do absolute scaling if desired
1758        if(cmpstr("none",prot[4])!=0)
1759                if(cmpstr("ask",prot[4])==0)
1760                        //get the params from the user
1761                        Execute "AskForAbsoluteParams_Quest()"
1762                        //then from the list
1763                        SVAR junkAbsStr = root:myGlobals:Protocols:gAbsStr
1764                        c2 = NumberByKey("TSTAND", junkAbsStr, "=", ";")        //parse the list of values
1765                        c3 = NumberByKey("DSTAND", junkAbsStr, "=", ";")
1766                        c4 = NumberByKey("IZERO", junkAbsStr, "=", ";")
1767                        c5 = NumberByKey("XSECT", junkAbsStr, "=", ";")
1768                        kappa_err = NumberByKey("SDEV", junkAbsStr, "=", ";")
1769                else
1770                        //get the parames from the list
1771                        c2 = NumberByKey("TSTAND", prot[4], "=", ";")   //parse the list of values
1772                        c3 = NumberByKey("DSTAND", prot[4], "=", ";")
1773                        c4 = NumberByKey("IZERO", prot[4], "=", ";")
1774                        c5 = NumberByKey("XSECT", prot[4], "=", ";")
1775                        kappa_err = NumberByKey("SDEV", prot[4], "=", ";")
1776                Endif
1777                //get the sample trans and thickness from the activeType folder
1778                String destStr = "root:Packages:NIST:"+activeType+":realsread"
1779                Wave dest = $destStr
1780                Variable c0 = dest[4]           //sample transmission
1781                Variable c1 = dest[5]           //sample thickness
1782               
1783                err = Absolute_Scale(activeType,c0,c1,c2,c3,c4,c5,kappa_err)
1784                if(err)
1785                        SetDataFolder root:
1786                        Abort "Error in Absolute_Scale(), called from executeProtocol"
1787                endif
1788                activeType = "ABS"
1789                UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1790        Endif
1791       
1792        //check for mask
1793        //add mask if needed
1794        // can't properly check the filename - so for now always add
1795        //doesn't change the activeType
1796        if(cmpstr("none",prot[3])!=0)
1797                If(cmpstr("ask",prot[3])==0)
1798                        //get file from user
1799                        junkStr = PromptForPath("Select Mask file")
1800                        If(strlen(junkStr)==0)
1801                                //no selection of mask file is not a fatal error, keep going, and let cirave()
1802                                //make a "null" mask
1803                                //if none desired, make sure that the old mask is deleted
1804                                //junkStr = GetDataFolder(1)
1805                                //SetDataFolder root:Packages:NIST:MSK
1806                                KillWaves/Z root:Packages:NIST:MSK:data
1807                                //SetDataFolder junkStr
1808                                DoAlert 0,"No Mask file selected, data not masked"
1809                        else
1810                                //read in the file from the dialog
1811                                ReadMCID_MASK(junkStr)
1812                        Endif
1813                else
1814                        //just read it in from the protocol
1815                        //list processing is necessary to remove any final comma
1816                        junkStr = pathStr + StringFromList(0, prot[3],"," )
1817                        ReadMCID_MASK(junkStr)
1818                Endif
1819        else
1820                //if none desired, make sure that the old mask is deleted
1821                //junkStr = GetDataFolder(1)
1822                //SetDataFolder root:Packages:NIST:MSK
1823                KillWaves/Z root:Packages:NIST:MSK:data
1824                //SetDataFolder junkStr
1825        Endif
1826       
1827        //mask data if desired (this is done automatically  in the average step) and is
1828        //not done explicitly here (if no mask in MSK folder, a null mask is created and "used")
1829       
1830        // average/save data as specified
1831       
1832        //Parse the keyword=<Value> string as needed, based on AVTYPE
1833       
1834        //average/plot first
1835        String av_type = StringByKey("AVTYPE",prot[5],"=",";")
1836        If(cmpstr(av_type,"none") != 0)
1837                If (cmpstr(av_type,"")==0)              //if the key could not be found... (if "ask" the string)
1838                        //get the averaging parameters from the user, as if the set button was hit
1839                        //in the panel
1840                        SetAverageParamsButtonProc("dummy")             //from "ProtocolAsPanel"
1841                        SVAR tempAveStr = root:myGlobals:Protocols:gAvgInfoStr
1842                        av_type = StringByKey("AVTYPE",tempAveStr,"=",";")
1843                else
1844                        //there is info in the string, use the protocol
1845                        //set the global keyword-string to prot[5]
1846                        String/G root:myGlobals:Protocols:gAvgInfoStr = prot[5]
1847                Endif
1848        Endif
1849       
1850        //convert the folder to linear scale before averaging, then revert by calling the window hook
1851        ConvertFolderToLinearScale(activeType)
1852       
1853        strswitch(av_type)      //dispatch to the proper routine to average to 1D data
1854                case "Rectangular":
1855                        RectangularAverageTo1D(activeType)
1856                        break
1857                case "Annular":
1858                        AnnularAverageTo1D(activeType)
1859                        break
1860                case "Circular":
1861                case "Sector":
1862                case "Elliptical":
1863                        //Circular, Sector, and Elliptical Averaging use Circular Averaging Routine
1864                        CircularAverageTo1D(activeType)
1865                        break
1866                case "Sector_PlusMinus":
1867                        Sector_PlusMinus1D(activeType)
1868                        break
1869                case "none":           
1870                        //do nothing
1871                case "2D_ASCII":       
1872                        //do nothing
1873                case "QxQy_ASCII":
1874                        //do nothing
1875                case "2D_NXcanSAS":
1876                        //do nothing
1877                case "PNG_Graphic":
1878                        //do nothing
1879                default:       
1880                        //do nothing
1881        endswitch
1882///// end of averaging dispatch
1883        // put data back on log or lin scale as set by default
1884        fRawWindowHook()
1885       
1886        //save data if desired
1887        String fullpath = "", newfileName=""
1888        String item = StringByKey("SAVE",prot[5],"=",";")               //does user want to save data?
1889        If( (cmpstr(item,"Yes")==0) && (cmpstr(av_type,"none") != 0) )         
1890                //then save
1891                //get name from textwave of the activeType dataset
1892                String textStr = "root:Packages:NIST:"+activeType+":textread"
1893                Wave/T textPath = $textStr
1894                String tempFilename = samStr
1895                If(WaveExists(textPath) == 1)
1896#if (exists("QUOKKA")==6)
1897                        newFileName = ReplaceString(".nx.hdf", tempFilename, "")
1898#elif (exists("HFIR")==6)
1899//                      newFileName = ReplaceString(".xml",textPath[0],"")              //removes 4 chars
1900//                      newFileName = ReplaceString("SANS",newFileName,"")              //removes 4 more chars = 8
1901//                      newFileName = ReplaceString("exp",newFileName,"")                       //removes 3 more chars = 11
1902//                      newFileName = ReplaceString("scan",newFileName,"")              //removes 4 more chars = 15, should be enough?
1903                        newFileName = GetPrefixStrFromFile(textPath[0])+GetRunNumStrFromFile(textPath[0])
1904#else
1905                        newFileName = UpperStr(GetNameFromHeader(textPath[0]))          //NCNR data drops here, trims to 8 chars
1906#endif
1907                else
1908                        newFileName = ""                        //if the header is missing?
1909                        //Print "can't read the header - newfilename is null"
1910                Endif
1911               
1912                //pick ABS or AVE extension
1913                String exten = activeType
1914                if(cmpstr(exten,"ABS") != 0)
1915                        exten = "AVE"
1916                endif
1917                if(cmpstr(av_type,"2D_ASCII") == 0)
1918                        exten = "ASC"
1919                endif
1920                if(cmpstr(av_type,"QxQy_ASCII") == 0)
1921                        exten = "DAT"
1922                endif
1923                if(cmpstr(av_type,"2D_NXcanSAS") == 0)
1924                        exten = "h5"
1925                endif
1926               
1927                // add an "x" to the file extension if the output is XML
1928                // currently (2010), only for ABS and AVE (1D) output
1929                if( cmpstr(exten,"ABS") == 0 || cmpstr(exten,"AVE") == 0 )
1930                        if(useXMLOutput == 1)
1931                                exten += "x"
1932                        elseif(useNXcanSASOutput == 1)
1933                                exten = "h5"
1934                        endif
1935                endif
1936                               
1937                //Path is catPathName, symbolic path
1938                //if this doesn't exist, a dialog will be presented by setting dialog = 1
1939                Variable dialog = 0
1940                PathInfo/S catPathName
1941                item = StringByKey("NAME",prot[5],"=",";")              //Auto or Manual naming
1942                String autoname = StringByKey("AUTONAME",prot[5],"=",";")               //autoname -  will get empty string if not present
1943                If((cmpstr(item,"Manual")==0) || (cmpstr(newFileName,"") == 0))
1944                        //manual name if requested or if no name can be derived from header
1945                        fullPath = newfileName + "."+ exten //puts possible new name or null string in dialog
1946                        dialog = 1              //force dialog for user to enter name
1947                else
1948                        //auto-generate name and prepend path - won't put up any dialogs since it has all it needs
1949                        //use autoname if present
1950                        if (cmpstr(autoname,"") != 0)
1951                                fullPath = S_Path + autoname + "." +exten
1952                        else
1953                                fullPath = S_Path + newFileName+"." + exten
1954                        endif   
1955                Endif
1956                //
1957                strswitch(av_type)     
1958                        case "Annular":
1959                                WritePhiave_W_Protocol(activeType,fullPath,dialog)
1960                                break
1961                        case "2D_ASCII":
1962                                Fast2DExport(activeType,fullPath,dialog)
1963                                break
1964                        case "2D_NXcanSAS":
1965                                WriteNxCanSAS2D(activeType,fullPath,dialog)
1966                                break
1967                        case "QxQy_ASCII":
1968                                QxQy_Export(activeType,fullPath,dialog)
1969                                break
1970                        case "PNG_Graphic":
1971                                SaveAsPNG(activeType,fullpath,dialog)
1972                                break
1973                        default:
1974                                if (useXMLOutput == 1)
1975                                        WriteXMLWaves_W_Protocol(activeType,fullPath,dialog)
1976                                elseif (useNXcanSASOutput == 1)
1977                                        WriteNxCanSAS1D(activeType,fullPath,dialog)
1978                                else
1979                                        WriteWaves_W_Protocol(activeType,fullpath,dialog)
1980                                endif
1981                endswitch
1982               
1983                //Print "data written to:  "+ fullpath
1984        Endif
1985       
1986        //done with everything in protocol list
1987        Return(0)
1988End
1989
1990//updates the currently displayed information to the data in "type"
1991//data folder - changes the title of the window and the global of the
1992//currently displayed data type - the recreation macro does the work
1993//
1994Function UpdateDisplayInformation(type)
1995        String type
1996
1997//      String newTitle = "WORK_"+type
1998//      DoWindow/F SANS_Data
1999//      DoWindow/T SANS_Data, newTitle
2000//      KillStrings/Z newTitle
2001       
2002        //need to update the display with "data" from the correct dataFolder
2003        //reset the current displaytype to "type"
2004        String/G root:myGlobals:gDataDisplayType=Type
2005       
2006        fRawWindowHook()
2007       
2008        //no error
2009        Return(0)
2010End
2011
2012//missing parameter dialog to solicit the 4 absolute intensity parameters
2013//from the user
2014//values are passed back as a global string variable (keyword=value)
2015//
2016Proc AskForAbsoluteParams(c2,c3,c4,c5,err)
2017        Variable c2=0.95,c3=0.1,c4=1,c5=32.0,err=0
2018        Prompt c2, "Standard Transmission"
2019        Prompt c3, "Standard Thickness (cm)"
2020        Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)"
2021        Prompt c5, "Standard Cross-Section (cm-1)"
2022        Prompt err, "error in I(q=0) (one std dev)"
2023       
2024        String/G root:myGlobals:Protocols:gAbsStr=""
2025       
2026        root:myGlobals:Protocols:gAbsStr = "TSTAND="+num2str(c2)
2027        root:myGlobals:Protocols:gAbsStr +=  ";" + "DSTAND="+num2str(c3)
2028        root:myGlobals:Protocols:gAbsStr +=  ";" + "IZERO="+num2str(c4)
2029        root:myGlobals:Protocols:gAbsStr +=  ";" + "XSECT="+num2str(c5)
2030        root:myGlobals:Protocols:gAbsStr +=  ";" + "SDEV="+num2str(err)
2031       
2032End
2033
2034//asks the user for absolute scaling information. the user can either
2035//enter the 4 necessary values in manually (missing parameter dialog)
2036//or the user can select an empty beam file from a standard open dialog
2037//if an empty beam file is selected, the "kappa" value is automatically calculated
2038//in either case, the global keyword=value string is set.
2039//
2040//Proc AskForAbsoluteParams_Quest()
2041Function AskForAbsoluteParams_Quest()   
2042       
2043        Variable err, isNG5=0,loc,refnum
2044        //ask user if he wants to use a transmision file for absolute scaling
2045        //or if he wants to enter his own information
2046        err = UseStdOrEmpForABS()
2047        //DoAlert 1,"<Yes> to enter your own values, <No> to select an empty beam flux file"
2048        If ( err==1 )
2049                //secondary standard selected, prompt for values
2050                Execute "AskForAbsoluteParams()"                //missing parameters
2051        else
2052                //empty beam flux file selected, prompt for file, and use this to calculate KAPPA
2053                Variable kappa=1
2054               
2055                //ask for file and read it into RAW
2056                //will cancel if no file is selected
2057                err = LoadRawSANSData("select the empty beam file")             //reads the RAW data
2058                UpdateDisplayInformation("RAW")                 //display the new type of data that was loaded
2059                if(err)
2060                        PathInfo/S catPathName
2061                        Abort "reduction sequence aborted"
2062                endif
2063                       
2064                Wave/T tw=$"root:Packages:NIST:RAW:TextRead"
2065                Wave rw=$"root:Packages:NIST:RAW:RealsRead"
2066                Wave iw=$"root:Packages:NIST:RAW:IntegersRead"
2067                String acctStr = tw[3]
2068                //NG5 attenuator transmission is assumed to be the same as the table for NG7
2069                       
2070                //get the necessary variables for the calculation of kappa
2071                Variable detCnt,countTime,attenTrans,monCnt,sdd,pixel
2072                String detStr=tw[9]
2073//              pixel = DetectorPixelResolution(acctStr,detStr)         //get the pixel size from the file information
2074                //note that reading the detector pixel size from the header ASSUMES SQUARE PIXELS! - Jan2008
2075                pixel = rw[10]/10                       // header value (X) is in mm, want cm here
2076       
2077                countTime = iw[2]
2078                //detCnt = rw[2]                //080802 -use sum of data, not scaler from header
2079                monCnt = rw[0]
2080                sdd = rw[18]
2081                sdd *=100               //convert from meters to cm
2082                               
2083                //lookup table for transmission factor
2084                //determine which instrument the measurement was done on from acctStr
2085                Variable lambda = rw[26]
2086                Variable attenNo = rw[3]
2087                Variable atten_err
2088                attenTrans = AttenuationFactor(acctStr,lambda,attenNo,atten_err)
2089                //Print "attenTrans = ",attenTrans
2090               
2091                //get the XY box, if needed
2092                Variable x1,x2,y1,y2,ct_err
2093                String filename=tw[0],tempStr                   //02JUL13
2094                PathInfo/S catPathName
2095                String tempName = S_Path + FindValidFilename(filename)
2096                err = GetXYBoxFromFile(tempName,x1,x2,y1,y2)            //xy's are passed/returned by reference
2097//              Print x1,x2,y1,y2
2098
2099                if( ((x1-x2)==0) || ((y1-y2)==0) )      //need to re-select the box
2100                        err = SelectABS_XYBox(x1,x2,y1,y2)              //this will pause for user input
2101                        if(err)
2102                                Abort "Box not selected properly - Please re-set the ABS parameters"
2103                        Endif
2104                        //box is OK, write box values to file
2105                        WriteXYBoxToHeader(tempName,x1,x2,y1,y2)
2106                else
2107                        //give option to override
2108                        tempStr = "X=("+num2str(x1)+","+num2str(x2)+") Y=("+num2str(y1)+","+num2str(y2)+")"
2109                        DoAlert 1,"The current box is "+tempStr+".  Do you want to override these values?"
2110                        //Print v_flag
2111                        if(V_flag==1)   //1==yes, override
2112                                err = SelectABS_XYBox(x1,x2,y1,y2)
2113                                if(err)
2114                                        Abort "Box not selected properly -Please re-set the ABS parameters"
2115                                Endif
2116                        endif
2117                Endif
2118                Printf "Using Box X(%d,%d),Y(%d,%d)\r",x1,x2,y1,y2
2119               
2120                //need the detector sensitivity file - make a guess, allow to override
2121                String junkStr="",errStr=""
2122                if(! waveexists($"root:Packages:NIST:DIV:data"))
2123                        junkStr = PromptForPath("Select the detector sensitivity file")
2124                        Print junkStr
2125#if(exists("HFIR")==6)
2126                        if(strlen(junkStr)==0 || !CheckIfDIVData(junkStr))              //if either is false, exit
2127                                //Print strlen(junkStr)
2128                                //Print CheckIfDIVData(junkStr)
2129                                SetDataFolder root:
2130                                Abort "No DIV (PLEX) file selected. Please use setABSParams again, selecting the empty beam file and then the detector sensitivity (Plex_) file"
2131                        endif
2132#else
2133                        if(strlen(junkStr)==0 || !CheckIfDIVData(junkStr))              //for NCNR, and other data confirm it is DIV if either is false, exit
2134                                SetDataFolder root:
2135                                Abort "No DIV (PLEX) file selected. Please use setABSParams again, selecting the empty beam file and then the detector sensitivity (Plex_) file"
2136                        endif
2137#endif
2138                        ReadHeaderAndWork("DIV", junkStr)
2139                endif
2140                //toggle SANS_Data to linear display if needed, so that we're working with linear scaled data
2141                ControlInfo/W=SANS_Data bisLog
2142                if(V_Flag==1)
2143                        Log_Lin("bisLog")       
2144                endif   
2145                Wave divData = $"root:Packages:NIST:div:Data"
2146                Wave data = $"root:Packages:NIST:raw:data"              //this will be the linear data
2147                // correct by detector sensitivity
2148                data /= divData
2149               
2150                // now do the sum, only in the box     
2151//              detCnt = sum($"root:Packages:NIST:raw:data", -inf, inf )
2152//              Print "box is now ",x1,x2,y1,y2
2153                detCnt = SumCountsInBox(x1,x2,y1,y2,ct_err,"RAW")
2154                if(cmpstr(tw[9],"ILL   ")==0)
2155                        detCnt /= 4             // for cerca detector, header is right, sum(data) is 4x too large this is usually corrected in the Add step
2156                        pixel *= 1.04                   // correction for true pixel size of the Cerca
2157                endif
2158                //             
2159                kappa = detCnt/countTime/attenTrans*1.0e8/(monCnt/countTime)*(pixel/sdd)^2
2160               
2161                Variable kappa_err
2162                kappa_err = (ct_err/detCnt)^2 + (atten_err/attenTrans)^2
2163                kappa_err = sqrt(kappa_err) * kappa
2164               
2165                junkStr = num2str(kappa)
2166                errStr = num2Str(kappa_err)
2167                // set the parameters in the global string
2168//              Print "AskForAbsoluteParams(1,1,"+junkStr+",1,"+errStr+")"     
2169                Execute "AskForAbsoluteParams(1,1,"+junkStr+",1,"+errStr+")"            //no missing parameters, no dialog
2170               
2171                //should wipe out the data in the RAW folder, since it's not really RAW now
2172                DoWindow/K SANS_Data
2173                // SRK JUL 2006 don't clear the contents - just kill the window to force new data to be loaded
2174                // - obsucre bug if "ask" in ABS section of protocol clears RAW folder, then Q-axes can't be set from RAW:RealsRead
2175                //ClearDataFolder("RAW")
2176                Printf "Kappa was successfully calculated as = %g +/- %g (%g %)\r",kappa,kappa_err,(kappa_err/kappa)*100
2177        Endif
2178       
2179End
2180
2181Function UserSelectBox_Continue(ctrlName) :buttonControl
2182        String ctrlName
2183       
2184        DoWindow/K junkWindow           //kill panel
2185end
2186
2187Function SelectABS_XYBox(x1,x2,y1,y2)
2188        Variable &x1,&x2,&y1,&y2
2189       
2190        Variable err=0
2191       
2192        Variable/G root:V_marquee=1             //sets the sneaky bit to automatically update marquee coords
2193        Variable/G root:V_left,root:V_right,root:V_bottom,root:V_top    //must be global for auto-update
2194        DoWindow/F SANS_Data
2195        NewPanel/K=2 /W=(139,341,382,432) as "Select the primary beam"
2196        DoWindow/C junkWindow
2197        AutoPositionWindow/E/M=1/R=SANS_Data
2198       
2199        Drawtext 21,20 ,"Select the primary beam with the"
2200        DrawText 21,40, "marquee and press continue"
2201        Button button0,pos={80,58},size={92,20},title="Continue"
2202        Button button0,proc=UserSelectBox_Continue
2203       
2204        PauseForUser junkWindow,SANS_Data
2205       
2206        DoWindow/F SANS_Data
2207
2208        //GetMarquee left,bottom                        //not needed
2209        NVAR V_left=V_left
2210        NVAR V_right=V_right
2211        NVAR V_bottom=V_bottom
2212        NVAR V_top=V_top
2213       
2214        x1 = V_left
2215        x2 = V_right
2216        y1 = V_bottom
2217        y2 = V_top
2218//      Print "new values,before rounding = ",x1,x2,y1,y2
2219        KeepSelectionInBounds(x1,x2,y1,y2)
2220        //Print "new values = ",x1,x2,y1,y2
2221       
2222        KillVariables/Z root:V_Marquee,root:V_left,root:V_right,root:V_bottom,root:V_top
2223        if((x1-x2)==0 || (y1-y2)==0)
2224                err=1
2225        endif
2226        return(err)
2227End
2228
2229Function UseStdOrEmpForABS()
2230               
2231        NewPanel/K=2 /W=(139,341,402,448) as "Absolute Scaling"
2232        DoWindow/C junkABSWindow
2233        ModifyPanel cbRGB=(57346,65535,49151)
2234        SetDrawLayer UserBack
2235        SetDrawEnv fstyle= 1
2236        DrawText 21,20,"Method of absolute calibration"
2237        Button button0,pos={52,33},size={150,20},proc=UserSelectABS_Continue,title="Empty Beam Flux"
2238        Button button1,pos={52,65},size={150,20},proc=UserSelectABS_Continue,title="Secondary Standard"
2239       
2240        PauseForUser junkABSWindow
2241        NVAR val = root:myGlobals:tmpAbsVal
2242        return(val)
2243End
2244
2245//returns 0 if button0 (empty beam flux)
2246// or 1 if secondary standard
2247Function UserSelectABS_Continue(ctrlName) :buttonControl
2248        String ctrlName
2249       
2250        variable val=0
2251        If(cmpstr(ctrlName,"button0")==0)
2252                val=0           
2253        else
2254                val=1
2255        endif
2256//      print "val = ",ctrlName,val
2257        Variable/G root:myGlobals:tmpAbsVal = val
2258        DoWindow/K junkABSWindow                //kill panel
2259        return(0)
2260end
2261
2262
2263//save the protocol as an IGOR text wave (.itx)
2264//
2265//
2266Function ExportProtocol(ctrlName) : ButtonControl
2267        String ctrlName
2268// get a list of protocols
2269        String Protocol=""
2270        SetDataFolder root:myGlobals:Protocols
2271        Prompt Protocol "Pick A Protocol",popup, WaveList("*",";","")
2272        DoPrompt "Pick A Protocol to Export",Protocol
2273        if(V_flag==1)
2274                //Print "user cancel"
2275                SetDatafolder root:
2276                return(1)
2277        endif
2278//get the selection, or exit
2279        Wave/T pW= $protocol
2280        Make/O/T/N=13 tw
2281// save in the proper format (must write manually, for demo version)
2282        tw[0] = "IGOR"
2283        tw[1] = "WAVES/T \t"+protocol
2284        tw[2] = "BEGIN"
2285        tw[3,10] = "\t\""+pW[p-3]+"\""
2286        tw[11] = "END"
2287        tw[12] = "X SetScale/P x 0,1,\"\","+protocol+"; SetScale y 0,0,\"\","+protocol
2288       
2289        Variable refnum
2290        String fullPath
2291       
2292        PathInfo/S catPathName
2293        fullPath = DoSaveFileDialog("Export Protocol as",fname=Protocol,suffix="")
2294        If(cmpstr(fullPath,"")==0)
2295                //user cancel, don't write out a file
2296                Close/A
2297                Abort "no Protocol file was written"
2298        Endif
2299
2300        //actually open the file
2301        Open refNum as fullpath+".itx"
2302       
2303        wfprintf refnum, "%s\r", tw
2304        Close refnum
2305        //Print "all is well  ",protocol
2306        KillWaves/Z tw
2307        setDataFolder root:
2308        return(0)
2309
2310End
2311
2312//imports a protocol from disk into the protocols folder
2313//
2314// will overwrite existing protocols if necessary
2315//
2316//
2317Function ImportProtocol(ctrlName) : ButtonControl
2318        String ctrlName
2319
2320        SetDataFolder root:myGlobals:Protocols
2321
2322        String fullPath
2323       
2324        PathInfo/S catPathName
2325        fullPath = DoOpenFileDialog("Import Protocol")
2326        If(cmpstr(fullPath,"")==0)
2327                //user cancel, don't write out a file
2328                Close/A
2329                Abort "no protocol was loaded"
2330        Endif
2331       
2332        LoadWave/O/T fullPath
2333       
2334        SetDataFolder root:
2335        return(0)
2336end
Note: See TracBrowser for help on using the repository browser.