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

Last change on this file since 1092 was 1092, checked in by srkline, 4 years ago

added a few corrections to the reduction:

Added sample apertures to the patch panel so that they can be corrected

A flag is now written to the data files if the "flip" has been done, and it will refuse to flip again. This flag can be reset if something goes wrong.

Multiple reduce now allows run numbers to be entered as is for SANS,

Filtering of files for the protocol panel should be better behaved now.

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