source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ProtocolAsPanel.ipf @ 857

Last change on this file since 857 was 857, checked in by srkline, 10 years ago

Added support for reading 4-column data into the 2D reader

Calculation of kappa for ABS now does a specific byte check for ensuring a "good" DIV file. hopefully this will eliminate errors where incorrect DIV files are selected and bad kappa values are generated - and the program thinks (incorrectly) that there is a valid DVI file present, when there really isn't one (and then there is no easy recovery from this)

Added CheckIfDIVData() functions to NCNR_Utils and to FACILITY_Utils, and to other (facility)_Utils

Changed the calls to writing BT5 files after adding so that it could be more easily scripted in the future.

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