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

Last change on this file since 1074 was 1073, checked in by srkline, 5 years ago

lots of changes here:
many little fixes to clean up TODO items and marke them DONE

changed the handling of the panel "gap" to split the gap evenly. Q-calculations have been re-verified with this change.

re-named the list of "bin Type" values, and added a few more choices. Streamlined how the averaging and plotting works with this list so that it can be more easily modified as different combinations of binning are envisioned. This resulted in a lot of excess code being cut out and replaced with cleaner logic. This change has also been verified to work as intended.

Attenuation is now always calculated from the table. The table also by (NEW) definition has values for the white beam (one waelength) and graphite (multiple possible wavelengths) where the wavelengths are artificially scaled (*1000) or *1e6) so that the interpolations can be done internally without the need for multiple attenuator tables.

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