source: sans/Dev/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Packages/Wrapper_v40.ipf @ 384

Last change on this file since 384 was 384, checked in by srkline, 15 years ago

New install instructions, for manual install

New diagnostics in the installer that check to see if proper permissions exist, and suggest manual instll if not OK.

Wrapper now behaves better when new data files are loaded, selecting and "popping" the new file in the dataSet popup. also some better behvior if useCursors is checked.

File size: 36.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=4.00
3#pragma IgorVersion=6.0
4
5//
6// need a way of importing more functions into the experiment
7// ? call the picker panel from the panel?
8//
9//
10
11//Macro OpenWrapperPanel()
12//      Init_WrapperPanel()
13//End
14
15Function Init_WrapperPanel()
16        //make sure that folders exist - this is the first initialization to be called
17        NewDataFolder/O root:Packages
18        NewDataFolder/O root:Packages:NIST
19
20        //Create useful globals
21        Variable/G root:Packages:NIST:SANS_ANA_VERSION=4.00
22        String/G root:Packages:NIST:SANS_ANA_EXTENSION="_v40"
23        //Set this variable to 1 to force use of trapezoidal integration routine for USANS smearing
24        Variable/G root:Packages:NIST:USANSUseTrap = 0
25        Variable/G root:Packages:NIST:USANS_dQv = 0.117
26       
27        DoWindow/F WrapperPanel
28        if(V_flag==0)
29                if(exists("root:Packages:NIST:coefKWStr")==0)
30                        String/G root:Packages:NIST:coefKWStr=""
31                endif
32                if(exists("root:Packages:NIST:suffixKWStr")==0)
33                        String/G root:Packages:NIST:suffixKWStr=""
34                endif
35                Execute "WrapperPanel()"
36        endif
37End
38
39////////
40//
41// if model is Smeared, search the DF for coefficients
42// if new DF chosen, need to reset
43// if new model function, need to reset table
44//
45// create hold_mod (0/1), constr_low_mod, constr_hi_mod
46// in either DF (smeared) or in root: (normal)
47// and put these in the table as needed
48//
49Window WrapperPanel()
50        PauseUpdate; Silent 1           // building window...
51        NewPanel /W=(459,44,1113,499)/N=wrapperPanel/K=1 as "Curve Fit Setup"
52        ModifyPanel fixedSize=1
53       
54        GroupBox grpBox_0,pos={18,11},size={390,113}
55        GroupBox grpBox_1,pos={426,10},size={207,113}
56        GroupBox grpBox_2 title="No Fit",pos={10,130},size={0,0},frame=1,fSize=10,fstyle=1,fColor=(39321,1,1)
57        GroupBox grpBox_3 title="",pos={10,150},size={0,0},frame=1,fSize=10,fstyle=1,fColor=(39321,1,1)
58
59        Button button_1,pos={280,57},size={120,20},proc=PlotModelFunction,title="Plot 1D Function"
60        Button button_2,pos={300,93},size={100,20},proc=AppendModelToTarget,title="Append 1D"
61        Button button_3,pos={300,20},size={100,20},proc=W_LoadDataButtonProc,title="Load 1D Data"
62        PopupMenu popup_0,pos={30,21},size={218,20},title="Data Set",proc=DataSet_PopMenuProc
63        PopupMenu popup_0,mode=1,value= #"W_DataSetPopupList()"
64        PopupMenu popup_1,pos={30,57},size={136,20},title="Function"
65        PopupMenu popup_1,mode=1,value= #"W_FunctionPopupList()",proc=Function_PopMenuProc
66        PopupMenu popup_2,pos={30,93},size={123,20},title="Coefficients"
67        PopupMenu popup_2,mode=1,value= #"W_CoefPopupList()",proc=Coef_PopMenuProc
68        CheckBox check_0,pos={440,19},size={79,14},title="Use Cursors?",value= 0
69        CheckBox check_0,proc=UseCursorsWrapperProc
70        CheckBox check_1,pos={440,42},size={74,14},title="Use Epsilon?",value= 0
71        CheckBox check_2,pos={440,65},size={95,14},title="Use Constraints?",value= 0
72        CheckBox check_3,pos={530,18},size={72,14},title="2D Functions?",value= 0
73        CheckBox check_3 proc=Toggle2DControlsCheckProc
74        CheckBox check_4,pos={440,85},size={72,14},title="Report?",value= 0
75        CheckBox check_5,pos={454,103},size={72,14},title="Save it?",value= 0
76        //change draw order to put button over text of checkbox
77        Button button_0,pos={520,93},size={100,20},proc=DoTheFitButton,title="Do 1D Fit"
78        Button button_4,pos={520,126},size={100,20},proc=FeedbackButtonProc,title="Feedback"
79        Button button_5,pos={520,150},size={100,20},proc=FitHelpButtonProc,title="Help"
80
81        Edit/W=(20,174,634,435)/HOST=# 
82        ModifyTable width(Point)=0
83        RenameWindow #,T0
84        SetActiveSubwindow ##
85EndMacro
86
87//open the Help file for the Fit Manager
88Function FitHelpButtonProc(ba) : ButtonControl
89        STRUCT WMButtonAction &ba
90
91        switch( ba.eventCode )
92                case 2: // mouse up
93                        // click code here
94                        DisplayHelpTopic/Z/K=1 "Fit Manager"
95                        if(V_flag !=0)
96                                DoAlert 0,"The Fit Manager Help file could not be found"
97                        endif
98                        break
99        endswitch
100
101        return 0
102End
103
104
105//open the trac page for feedback
106Function FeedbackButtonProc(ba) : ButtonControl
107        STRUCT WMButtonAction &ba
108
109        switch( ba.eventCode )
110                case 2: // mouse up
111                        // click code here
112                        OpenTracTicketPage()
113                        break
114        endswitch
115
116        return 0
117End
118
119
120//obvious use, now finds the most recent data loaded, finds the folder, and pops the menu with that selection...
121//
122Function W_LoadDataButtonProc(ba) : ButtonControl
123        STRUCT WMButtonAction &ba
124
125        switch( ba.eventCode )
126                case 2: // mouse up
127                        // click code here
128                        String  topGraph= WinName(0,1)
129                        if(strlen(topGraph) != 0)
130                                DoWindow/F $topGraph                    //so that the panel is not on top
131                        endif
132                        Execute "A_LoadOneDData()"
133                       
134                        ControlUpdate/W=WrapperPanel popup_0
135                        //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow
136                        // convoluted method to find the right item and pop the menu.
137
138                        // data is plotted, so get the "new" top graph
139                        topGraph= WinName(0,1)  //this is the topmost graph, and should exist, but...
140                        if(cmpstr(topGraph,"")==0)
141                                return(0)
142                        endif
143                        String list,folderStr
144                        Variable num
145                        list = TraceNameList(topGraph,";",1)            //want the last item in the list
146                        num= ItemsInList(list)
147                        FolderStr = StringFromList(num-1,list,";")
148                        folderStr = folderStr[0,strlen(folderStr)-3]            //remove the "_i" that the loader enforced
149                        list = W_DataSetPopupList()
150                        num=WhichListItem(folderStr,list,";",0,0)
151                        if(num != -1)
152                                PopupMenu popup_0,mode=num+1,win=WrapperPanel
153                                ControlUpdate/W=WrapperPanel popup_0
154                               
155                                // fake mouse up
156                                Struct WMPopupAction ps
157                                ps.eventCode = 2                //fake mouse up
158        //                      ps.popStr = str
159                                DataSet_PopMenuProc(ps)
160                               
161                                // new data set has been selected, always uncheck the "use cursors", other checkboxes are benign.
162                                CheckBox check_0,win=WrapperPanel,value=0
163                        endif
164                        break
165        endswitch
166
167
168        return 0
169End
170
171
172// is there a simpler way to do this?
173Function/S W_DataSetPopupList()
174
175        String str=GetAList(4),tmp="",onTargetStr=""
176        Variable ii
177//      ControlInfo/W=WrapperPanel check_3
178//      if(V_Value==1)          //if "from target" checked
179//              //ther must be a better way to do this
180//              onTargetStr = TraceNameList("",";",1)
181//              onTargetStr = ReplaceString("_i",onTargetStr,"")                //get rid of the "_i"
182//              for(ii=0;ii<ItemsInList(onTargetStr);ii+=1)
183//                      if(WhichListItem(StringFromList(ii,onTargetStr,";"), str  , ";") != -1)
184//                              tmp = Addlistitem(StringFromList(ii,onTargetStr,";"),tmp)               //only keep the matches w/data folder listing
185//                      endif
186//              endfor
187//              return(tmp)
188//      endif
189
190        if(strlen(str)==0)
191                str = "No data loaded"
192        endif
193        str = SortList(str)
194       
195        return(str)
196End
197
198
199// show the available models
200// not the f*(cw,xw) point calculations
201// not the *X(cw,xw) XOPS
202//
203// KIND:10 should show only user-defined curve fitting functions
204// - not XOPs
205// - not other user-defined functions
206Function/S W_FunctionPopupList()
207        String list,tmp
208        list = FunctionList("*",";","KIND:10")          //get every user defined curve fit function
209
210        //now start to remove everything the user doesn't need to see...
211               
212        tmp = FunctionList("*_proto",";","KIND:10")             //prototypes
213        list = RemoveFromList(tmp, list  ,";")
214        //prototypes that show up if GF is loaded
215        list = RemoveFromList("GFFitFuncTemplate", list)
216        list = RemoveFromList("GFFitAllAtOnceTemplate", list)
217        list = RemoveFromList("NewGlblFitFunc", list)
218        list = RemoveFromList("NewGlblFitFuncAllAtOnce", list)
219        list = RemoveFromList("GlobalFitFunc", list)
220        list = RemoveFromList("GlobalFitAllAtOnce", list)
221        list = RemoveFromList("GFFitAAOStructTemplate", list)
222        list = RemoveFromList("NewGF_SetXWaveInList", list)
223        list = RemoveFromList("NewGlblFitFuncAAOStruct", list)
224       
225        // more to remove as a result of 2D/Gizmo
226        list = RemoveFromList("A_WMRunLessThanDelta", list)
227        list = RemoveFromList("WMFindNaNValue", list)
228        list = RemoveFromList("WM_Make3DBarChartParametricWave", list)
229        list = RemoveFromList("UpdateQxQy2Mat", list)
230        list = RemoveFromList("MakeBSMask", list)
231       
232
233        tmp = FunctionList("f*",";","NPARAMS:2")                //point calculations
234        list = RemoveFromList(tmp, list  ,";")
235       
236        tmp = FunctionList("fSmear*",";","NPARAMS:3")           //smeared dependency calculations
237        list = RemoveFromList(tmp, list  ,";")
238       
239//      tmp = FunctionList("*X",";","KIND:4")           //XOPs, but these shouldn't show up if KIND:10 is used initially
240//      Print "X* = ",tmp
241//      print " "
242//      list = RemoveFromList(tmp, list  ,";")
243       
244        //non-fit functions that I can't seem to filter out
245        list = RemoveFromList("BinaryHS_PSF11;BinaryHS_PSF12;BinaryHS_PSF22;EllipCyl_Integrand;PP_Inner;PP_Outer;Phi_EC;TaE_Inner;TaE_Outer;",list,";")
246
247        if(strlen(list)==0)
248                list = "No functions plotted"
249        endif
250       
251        list = SortList(list)
252        return(list)
253End
254
255
256// show all the appropriate coefficient waves
257//
258// also need to search the folder listed in "data set" popup
259// for smeared coefs
260//
261// - or - restrict the coefficient list based on the model function
262// - new way, filter the possible values based on the data folder and function
263Function/S W_CoefPopupList()
264
265        String notPlotted="Please plot the function"
266        ControlInfo/W=wrapperpanel popup_1
267        String funcStr=S_Value
268        String coefStr=getFunctionCoef(funcStr)
269       
270        if(cmpstr(coefStr,"")==0)               //no correspondence in the KW string
271                return(notPlotted)
272        endif
273       
274       
275        //found a coefficient wave - only two places to look
276        // is it in the root folder?
277        if(exists("root:"+coefStr) != 0)
278                return(coefStr)
279        endif
280       
281        // is it in the data folder?
282        ControlInfo/W=wrapperpanel popup_0
283        String folderStr=S_Value
284        if(exists("root:"+folderStr+":"+coefStr) != 0)
285                return(coefStr)
286        endif
287
288        return(notPlotted)
289End
290
291// show all the appropriate coefficient waves
292//
293// also need to search the folder listed in "data set" popup
294// for smeared coefs
295//
296// - or - restrict the coefficient list based on the model function
297//
298// --old way
299//Function/S W_CoefPopupList()
300//      String list
301//      setDataFolder root:
302//      list = WaveList("coef*",";","")
303//     
304//      ControlInfo/W=wrapperpanel popup_0
305//      if(V_Value != 0)                //0== no items in menu
306//              if(DataFolderExists("root:"+S_Value))
307//                      SetDataFolder $("root:"+S_Value)
308//                      list += WaveList("*coef*",";","")
309//              endif
310//      endif
311//     
312//      // tmp coefficients that aren't being cleaned up from somewhere...
313//      list = RemoveFromList("temp_coef_1;temp_coef_2;", list  ,";")
314//
315//      if(strlen(list)==0)
316//              list = "No functions plotted"
317//      endif
318//      list = SortList(list)
319//     
320////    Print itemsinlist(list,";")
321//     
322//      setDataFolder root:
323//      return(list)
324//End
325
326// if the coefficients are changed, then update the table
327//
328//update the table
329// may be easier to just kill the subwindow (table) and create a new one
330// need to set/reset all of the waves in the table
331//
332// !! only respond to mouse up
333//
334Function Coef_PopMenuProc(pa) : PopupMenuControl
335        STRUCT WMPopupAction &pa
336
337        switch( pa.eventCode )
338                case 2: // mouse up
339                        Variable popNum = pa.popNum
340                        String popStr = pa.popStr
341                        String suffix = getModelSuffix(popStr)
342                        ControlInfo/W=WrapperPanel popup_0
343                        String folderStr=S_Value
344                       
345                        if(cmpstr(popStr,"Please plot the function")==0)
346//                              Print "function not plotted"
347                                return(0)
348                        endif
349
350// this if/else/endif should not ever return an error alert     
351// it should simply set the data folder properly       
352                        if(DataFolderExists("root:"+folderStr))
353                                SetDataFolder $("root:"+folderStr)
354                                if(!exists(popStr))
355                                        // must be unsmeared model, work in the root folder
356                                        SetDataFolder root:                             
357                                        if(!exists(popStr))             //this should be fine if the coef filter is working, but check anyhow
358                                                DoAlert 0,"the coefficient and data sets do not match (1)"
359                                                return 0
360                                        endif
361                                endif
362                        else
363                                // must be unsmeared model, work in the root folder
364                                SetDataFolder root:     
365                                if(!exists(popStr))             //this should be fine if the coef filter is working, but check anyhow
366                                        DoAlert 0,"the coefficient and data sets do not match (2)"
367                                        return 0
368                                endif
369                        endif
370                       
371                        // farm the work out to another function?
372                        Variable num=numpnts($popStr)
373                        // make the necessary waves if they don't exist already
374                        if(exists("Hold_"+suffix) == 0)
375                                Make/O/D/N=(num) $("epsilon_"+suffix),$("Hold_"+suffix)
376                                Make/O/T/N=(num) $("LoLim_"+suffix),$("HiLim_"+suffix)
377                                Wave eps = $("epsilon_"+suffix)
378                                Wave coef=$popStr
379                                eps = abs(coef*1e-4) + 1e-10                    //default eps is proportional to the coefficients
380                        endif
381                        // default epsilon values, sometimes needed for the fit
382                       
383
384                        WAVE/T LoLim = $("LoLim_"+suffix)
385                        WAVE/T HiLim = $("HiLim_"+suffix)
386                       
387                        // clear the table (a subwindow)
388                        KillWindow wrapperPanel#T0
389                        Edit/W=(20,174,634,435)/HOST=#
390                        RenameWindow #,T0
391                        // get them onto the table
392                        // how do I get the parameter name?
393                        String param = WaveList("*parameters_"+suffix, "", "TEXT:1," )          //this is *hopefully* one wave
394                        AppendtoTable/W=wrapperPanel#T0 $param,$(popStr)
395                        AppendToTable/W=wrapperPanel#T0 $("Hold_"+suffix),$("LoLim_"+suffix),$("HiLim_"+suffix),$("epsilon_"+suffix)
396                        ModifyTable width(Point)=0
397                       
398                        SetDataFolder root:
399                        break
400        endswitch
401
402        return 0
403End
404
405// if the Function is changed, then update the coef popup (if possible) and then the table (if possible)
406//
407// !! only respond to mouse up
408//
409Function Function_PopMenuProc(pa) : PopupMenuControl
410        STRUCT WMPopupAction &pa
411
412        switch( pa.eventCode )
413                case 2: // mouse up
414                        Variable popNum = pa.popNum
415                        String funcStr = pa.popStr
416                        String coefStr = W_CoefPopupList()
417                       
418//                      Print "coefStr = ",coefStr
419                       
420                        ControlInfo/W=WrapperPanel popup_0
421                        String folderStr=S_Value
422                       
423                        String listStr = W_CoefPopupList()
424                        Variable num=WhichListItem(coefStr, listStr, ";")
425                        String str=StringFromList(num, listStr  ,";")
426//                      print "str = ",str
427                        //set the item in the coef popup, and pop it
428                        PopupMenu popup_2 win=WrapperPanel,mode=(num+1)
429                       
430                        Struct WMPopupAction ps
431                        ps.eventCode = 2                //fake mouse up
432                        ps.popStr = str
433                        Coef_PopMenuProc(ps)
434                       
435                        SetDataFolder root:
436                        break
437        endswitch
438
439        return 0
440End
441
442// if the Data Set is changed, then update the function (if possible)
443// and the coef popup (if possible) and then the table (if possible)
444//
445// !! only respond to mouse up here, and simply send a fake mouse up
446// to the function pop, which will do what it can do
447//
448Function DataSet_PopMenuProc(pa) : PopupMenuControl
449        STRUCT WMPopupAction &pa
450
451        switch( pa.eventCode )
452                case 2: // mouse up
453//                      Variable popNum = pa.popNum
454//                      String funcStr = pa.popStr
455//                      String coefStr = W_CoefPopupList()
456//                     
457////                    Print "coefStr = ",coefStr
458//                     
459//                      ControlInfo/W=WrapperPanel popup_0
460//                      String folderStr=S_Value
461//                     
462//                      String listStr = W_CoefPopupList()
463//                      Variable num=WhichListItem(coefStr, listStr, ";")
464//                      String str=StringFromList(num, listStr  ,";")
465////                    print "str = ",str
466//                      //set the item in the coef popup, and pop it
467//                      PopupMenu popup_2 mode=(num+1)
468                       
469                        Struct WMPopupAction ps
470                        ps.eventCode = 2                //fake mouse up
471                        Function_PopMenuProc(ps)
472                       
473                        SetDataFolder root:
474                        break
475        endswitch
476
477        return 0
478End
479
480
481
482// always pass this the coefficient string
483//
484// either "coef_"
485// or "smear_coef_"
486//
487Function/S getFunctionCoef(funcStr)
488        String funcStr
489
490        SVAR listStr=root:Packages:NIST:coefKWStr
491        String coefStr = StringByKey(funcStr, listStr  ,"=",";",0)
492
493        return(coefStr)
494End
495
496// always pass this the coefficient string
497//
498// either "coef_"
499// or "smear_coef_"
500//
501// does NOT return the leading "_" as part of the suffix
502Function/S getModelSuffix(coefStr)
503        String coefStr
504
505        SVAR listStr=root:Packages:NIST:suffixKWStr
506        String suffixStr = StringByKey(coefStr, listStr  ,"=",";",0)
507
508        return(suffixStr)
509//      Variable pos,start=0
510
511//      if(stringmatch(coefStr,"smear_*") == 1)
512//              start=7 //look forwards to find "_", skipping "smear_coe" if necessary
513//      endif
514//      pos=Strsearch(coefStr,"_",start,0)
515        //Print start, pos
516//      return(coefStr[pos,strlen(coefStr)-1])
517End
518
519
520
521// - this is based on stringent "PlotNNN" naming requirements
522//
523//  ???
524// - how to kill the generated table and graph, that are not needed now
525//
526Function PlotModelFunction(ba) : ButtonControl
527        STRUCT WMButtonAction &ba
528
529        String folderStr,funcStr,coefStr,cmdStr=""
530        Variable useCursors,useEps,useConstr
531       
532        Variable killWhat=0             //kill nothing as default
533       
534        switch( ba.eventCode )
535                case 2: // mouse up
536                        ControlInfo/W=WrapperPanel popup_0
537                        folderStr=S_Value
538                       
539                        ControlInfo/W=WrapperPanel popup_1
540                        funcStr=S_Value
541                       
542                        // maybe nothing has been loaded yet...
543                        if(cmpstr(funcStr,"No functions plotted") == 0)
544                                break
545                        endif
546                       
547                        // check for smeared or smeared function
548                        if(stringmatch(funcStr, "Smear*" )==1)
549                                //it's a smeared model
550                                // check for the special case of RPA that has an extra parameter
551                                if(strsearch(funcStr, "RPAForm", 0 ,0) == -1)
552                                        sprintf cmdStr, "Plot%s(\"%s\")",funcStr,folderStr              //not RPA
553                                else
554                                        sprintf cmdStr, "Plot%s(\"%s\",)",funcStr,folderStr             //yes RPA, leave a comma for input
555                                endif
556                                killWhat = 1
557                        else
558                                // it's not,    don't kill the graph, just the table           
559                                sprintf cmdStr, "Plot%s()",funcStr
560                                killWhat = 2
561                        endif
562                       
563                        //Print cmdStr
564                        Execute cmdStr
565                       
566                        //pop the function menu to set the proper coefficients
567                        DoWindow/F WrapperPanel
568                        STRUCT WMPopupAction pa
569                        pa.popStr = funcStr
570                        pa.eventcode = 2
571                        Function_PopMenuProc(pa)
572       
573                        KillTopGraphAndTable(killWhat)          // crude
574       
575                        break
576        endswitch
577       
578        return 0
579End
580
581// passing 0 kills nothing
582// passing 1 kills the top graph and table
583// passing 2 kills the top table only
584//
585Function KillTopGraphAndTable(killwhat)
586        Variable killWhat
587       
588        String topGraph= WinName(0,1)   //this is the topmost graph     
589        String topTable= WinName(0,2)   //this is the topmost table
590
591        if(killWhat == 0)
592                return(0)
593        endif
594       
595        if(killWhat == 1)
596                KillWindow $topGraph
597                KillWindow $topTable
598        endif
599       
600        if(killWhat == 2)
601                KillWindow $topTable
602        endif
603       
604        return(0)
605End
606
607// How to bypass the step of plot and append?
608//
609// do it in two separate events
610//
611Function AppendModelToTarget(ba) : ButtonControl
612        STRUCT WMButtonAction &ba
613
614        String coefStr,suffix,yWStr,xWStr,folderStr
615       
616        switch( ba.eventCode )
617                case 2: // mouse up                     
618                        ControlInfo/W=WrapperPanel popup_2
619                        coefStr=S_Value
620                        suffix = getModelSuffix(coefStr)
621                       
622                        // check for smeared or smeared function
623                        if(stringmatch(coefStr, "smear*" )==1)
624                                //it's a smeared model
625                                ControlInfo/W=WrapperPanel popup_0
626                                folderStr=S_Value
627                                xWStr = "root:"+folderStr+":smeared_qvals"
628                                ywStr = "root:"+folderStr+":smeared_"+suffix
629                        else
630                                // it's not, so it's in the root folder
631                                xWStr = "xwave_"+suffix
632                                yWStr = "ywave_"+suffix
633                        endif
634                       
635                        Wave/Z yw = $yWStr
636                        Wave/Z xw = $xWStr
637                        if(WaveExists(yw) && WaveExists(xw))
638                                AppendtoGraph yw vs xw
639                        else
640                                DoAlert 0,"The selected model has not been plotted for the selected data set."
641                        endif
642                        break
643        endswitch
644       
645        return 0
646End
647
648
649// this should parse the panel and call the FitWrapper() function
650Function DoTheFitButton(ba) : ButtonControl
651        STRUCT WMButtonAction &ba
652
653        String folderStr,funcStr,coefStr
654        Variable useCursors,useEps,useConstr
655       
656        switch( ba.eventCode )
657                case 2: // mouse up
658                        ControlInfo/W=WrapperPanel popup_0
659                        folderStr=S_Value
660                       
661                        ControlInfo/W=WrapperPanel popup_1
662                        funcStr=S_Value
663                       
664                        ControlInfo/W=WrapperPanel popup_2
665                        coefStr=S_Value
666                       
667                        ControlInfo/W=WrapperPanel check_0
668                        useCursors=V_Value
669                        ControlInfo/W=WrapperPanel check_1
670                        useEps=V_Value
671                        ControlInfo/W=WrapperPanel check_2
672                        useConstr=V_Value
673                       
674                        if(!CheckFunctionAndCoef(funcStr,coefStr))
675                                DoAlert 0,"The coefficients and function type do not match. Please correct the selections in the popup menus."
676                                break
677                        endif
678                       
679                        FitWrapper(folderStr,funcStr,coefStr,useCursors,useEps,useConstr)
680                       
681                        //      DoUpdate (does not work!)
682                        //?? why do I need to force an update ??
683                        if(!exists("root:"+folderStr+":"+coefStr))
684                                Wave w=$coefStr
685                        else
686                                Wave w=$("root:"+folderStr+":"+coefStr) //smeared coefs in data folder
687                        endif
688                        w[0] += 1e-6
689                        w[0] -= 1e-6
690       
691                        break
692        endswitch
693       
694        return 0
695End
696
697Function CheckFunctionAndCoef(funcStr,coefStr)
698        String funcStr,coefStr
699       
700        SVAR listStr=root:Packages:NIST:coefKWStr
701        String properCoefStr = StringByKey(funcStr, listStr  ,"=",";",0)
702        if(cmpstr(coefStr,properCoefStr)==0)
703                return(1)               //true, the coef is the correct match
704        endif
705        return(0)                       //false, wrong coef
706End
707
708/////////////////////////////////
709
710// wrapper to do the desired fit
711//
712// folderStr is the data folder for the desired data set
713//
714//
715Function FitWrapper(folderStr,funcStr,coefStr,useCursors,useEps,useConstr)
716        String folderStr,funcStr,coefStr
717        Variable useCursors,useEps,useConstr
718
719        String suffix=getModelSuffix(coefStr)
720       
721        SetDataFolder $("root:"+folderStr)
722        if(!exists(coefStr))
723                // must be unsmeared model, work in the root folder
724                SetDataFolder root:                             
725                if(!exists(coefStr))            //this should be fine if the coef filter is working, but check anyhow
726                        DoAlert 0,"the coefficient and data sets do not match"
727                        return 0
728                endif
729        endif
730               
731        WAVE cw=$(coefStr)     
732        Wave hold=$("Hold_"+suffix)
733        Wave/T lolim=$("LoLim_"+suffix)
734        Wave/T hilim=$("HiLim_"+suffix)
735        Wave eps=$("epsilon_"+suffix)
736       
737// fill a struct instance whether I need one or not
738        String DF="root:"+folderStr+":"
739       
740        Struct ResSmearAAOStruct fs
741        WAVE/Z resW = $(DF+folderStr+"_res")                    //these may not exist, if 3-column data is used
742        WAVE/Z fs.resW =  resW
743        WAVE yw=$(DF+folderStr+"_i")
744        WAVE xw=$(DF+folderStr+"_q")
745        WAVE sw=$(DF+folderStr+"_s")
746        Wave fs.coefW = cw
747        Wave fs.yW = yw
748        Wave fs.xW = xw
749       
750        Duplicate/O yw $(DF+"FitYw")
751        WAVE fitYw = $(DF+"FitYw")
752        fitYw = NaN
753       
754        Variable useRes=0
755        if(stringmatch(funcStr, "Smear*"))              // if it's a smeared function, need a struct
756                useRes=1
757        endif
758       
759        // do not construct constraints for any of the coefficients that are being held
760        // -- this will generate an "unknown error" from the curve fitting
761        Make/O/T/N=0 constr
762        if(useConstr)
763                String constraintExpression
764                Variable i, nPnts=DimSize(lolim, 0),nextRow=0
765                for (i=0; i < nPnts; i += 1)
766                        if (strlen(lolim[i]) > 0 && hold[i] == 0)
767                                InsertPoints nextRow, 1, constr
768                                sprintf constraintExpression, "K%d > %s", i, lolim[i]
769                                constr[nextRow] = constraintExpression
770                                nextRow += 1
771                        endif
772                        if (strlen(hilim[i]) > 0 && hold[i] == 0)
773                                InsertPoints nextRow, 1, constr
774                                sprintf constraintExpression, "K%d < %s", i, hilim[i]
775                                constr[nextRow] = constraintExpression
776                                nextRow += 1
777                        endif
778                endfor
779        endif
780
781        //if useCursors, and the data is USANS, need to recalculate the matrix if the range is new
782        Variable pt1,pt2,newN,mPt1,mPt2
783        String noteStr
784        if(useCursors && (dimsize(resW,1) > 4) )
785                //where are the cursors, and what is the status of the current matrix?
786                if(pcsr(A) > pcsr(B))
787                        pt1 = pcsr(B)
788                        pt2 = pcsr(A)
789                else
790                        pt1 = pcsr(A)
791                        pt2 = pcsr(B)
792                endif
793               
794                noteStr = note(resW)
795                mPt1 = NumberByKey("P1",noteStr,"=",";")
796                mPt2 = NumberByKey("P2",noteStr,"=",";")
797                if((mPt1 != pt1) || (mPt2 != pt2) )
798                        // need to recalculate
799                        USANS_RE_CalcWeights(folderStr,pt1,pt2)
800                endif
801                Wave trimResW=$(DF+folderStr+"_res"+"t")        //put the trimmed resW in the struct for the fit!
802                Wave fs.resW=trimResW
803               
804                Print "Done recalculating the matrix"
805//////WRONG WAY
806//              Make/O/D/N=(newN,newN) $(DF+"crsrResW")
807//              WAVE crsrResW = $(DF+"crsrResW")
808//              crsrResW = resW[p+pt1][q+pt1]
809//              //assign to the struct
810//              WAVE fs.resW =  crsrResW               
811/////////////
812        endif
813       
814        if(!useCursors && (dimsize(resW,1) > 4) )
815                // avoid an odd sequence of y/n cursors that can lead to a truncated res matrix, but useCursors is not selected
816                if(waveExists($("root:"+folderStr+":weights_save")))
817                        Duplicate/O $("root:"+folderStr+":weights_save"), $("root:"+folderStr+":"+folderStr+"_res")
818                endif
819        endif
820       
821// create these variables so that FuncFit will set them on exit
822        Variable/G V_FitError=0                         //0=no err, 1=error,(2^1+2^0)=3=singular matrix
823        Variable/G V_FitQuitReason=0            //0=ok,1=maxiter,2=user stop,3=no chisq decrease
824       
825// don't use the auto-destination with no flag, it doesn't appear to work correctly
826// dispatch the fit
827        do
828                if(useRes && useEps && useCursors && useConstr)         //do it all
829                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs
830                        break
831                endif
832               
833                if(useRes && useEps && useCursors)              //no constr
834                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
835                        break
836                endif
837               
838                if(useRes && useEps && useConstr)               //no crsr
839                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs
840                        break
841                endif
842               
843                if(useRes && useCursors && useConstr)           //no eps
844                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs
845                        break
846                endif
847               
848                if(useRes && useCursors)                //no eps, no constr
849                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
850                        break
851                endif
852               
853                if(useRes && useEps)            //no crsr, no constr
854//                      Print "timing test for Cylinder_PolyRadius --- the supposedly threaded version ---"
855//                      Variable t0 = stopMStimer(-2)
856                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
857//                      t0 = (stopMSTimer(-2) - t0)*1e-6
858//                      Printf  "CylPolyRad fit time using res and eps and /NTHR=0 time = %g seconds\r\r",t0
859                       
860//                      cw[0] = .01
861//                      cw[1] = 20
862//                      cw[2] = 400
863//                      cw[3] = 0.2
864//                      cw[4] = 3e-6
865//                      cw[5] = 0.0
866//                     
867//                      t0 = stopMSTimer(-2)
868//                      FuncFit/H=getHStr(hold) $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
869//                      t0 = (stopMSTimer(-2) - t0)*1e-6
870//                      Printf  "CylPolyRad fit time using res and eps and NO THREADING time = %g seconds\r\r",t0
871                        break
872                endif
873       
874                if(useRes && useConstr)         //no crsr, no eps
875                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs
876                        break
877                endif
878               
879                if(useRes)              //just res
880                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
881                        break
882                endif
883               
884/////   same as above, but all without useRes (no /STRC flag)
885                if(useEps && useCursors && useConstr)           //do it all
886                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr
887                        break
888                endif
889               
890                if(useEps && useCursors)                //no constr
891                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /E=eps /D=fitYw
892                        break
893                endif
894               
895                if(useEps && useConstr)         //no crsr
896                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr
897                        break
898                endif
899               
900                if(useCursors && useConstr)             //no eps
901                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw /C=constr
902                        break
903                endif
904               
905                if(useCursors)          //no eps, no constr
906                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw
907                        break
908                endif
909               
910                if(useEps)              //no crsr, no constr
911                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw
912                        break
913                endif
914       
915                if(useConstr)           //no crsr, no eps
916                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr
917                        break
918                endif
919               
920                //just a plain vanilla fit
921                FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw
922       
923        while(0)
924       
925        // append the fit
926        // need to manage duplicate copies
927        // Don't plot the full curve if cursors were used (set fitYw to NaN on entry...)
928        String traces=TraceNameList("", ";", 1 )                //"" as first parameter == look on the target graph
929        if(strsearch(traces,"FitYw",0) == -1)
930                AppendToGraph FitYw vs xw
931        else
932                RemoveFromGraph FitYw
933                AppendToGraph FitYw vs xw
934        endif
935        ModifyGraph lsize(FitYw)=2,rgb(FitYw)=(0,0,0)
936       
937        DoUpdate                //force update of table and graph with fitted values (why doesn't this work? - the table still does not update)
938       
939        // report the results (to the panel?)
940        print "V_chisq = ",V_chisq
941        print cw
942        WAVE/Z w_sigma
943        print w_sigma
944        String resultStr=""
945               
946        //now re-write the results
947        sprintf resultStr,"Chi^2 = %g  Sqrt(X^2/N) = %g",V_chisq,sqrt(V_chisq/V_Npnts)
948        resultStr = PadString(resultStr,63,0x20)
949        GroupBox grpBox_2 title=resultStr
950        ControlUpdate/W=WrapperPanel grpBox_2
951        sprintf resultStr,"FitErr = %s : FitQuit = %s",W_ErrorMessage(V_FitError),W_QuitMessage(V_FitQuitReason)
952        resultStr = PadString(resultStr,63,0x20)
953        GroupBox grpBox_3 title=resultStr
954        ControlUpdate/W=WrapperPanel grpBox_3
955       
956        Variable yesSave=0,yesReport=0
957        ControlInfo/W=WrapperPanel check_4
958        yesReport = V_Value
959        ControlInfo/W=WrapperPanel check_5
960        yesSave = V_Value
961       
962       
963        if(yesReport)
964                String parStr=GetWavesDataFolder(cw,1)+ WaveList("*param*"+suffix, "", "TEXT:1," )              //this is *hopefully* one wave
965                String topGraph= WinName(0,1)   //this is the topmost graph
966       
967                DoUpdate                //force an update of the graph before making a copy of it for the report
968
969                W_GenerateReport(funcStr,folderStr,$parStr,cw,yesSave,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph)
970        endif
971       
972        SetDataFolder root:
973        return(0)
974End
975
976// parse something off of a table, or ?
977Function/S getHStr(hold)
978        Wave hold
979       
980        String str=""
981        Variable ii
982        for(ii=0;ii<numpnts(hold);ii+=1)
983                str += num2str(hold[ii])
984        endfor
985
986//      print str
987        if(strsearch(str, "1", 0) == -1)
988                return ("")
989        else
990                return(str)
991        endif
992End
993
994//taken from SRK Auto_Fit, and modified to work better with FitWrapper
995//must have AutoGraph as the name of the graph window (any size)
996// func is the name of the function (for print only)
997//par and coef are the exact names of the waves
998//yesSave==1 will save the file(name=func+time)
999//
1000Function W_GenerateReport(func,dataname,param,ans,yesSave,chiSq,sigWave,npts,fitErr,fitQuit,fitStart,fitEnd,topGraph)
1001        String func,dataname
1002        Wave/T param
1003        Wave ans
1004        Variable yesSave,chiSq
1005        Wave sigWave
1006        Variable npts,fitErr,fitQuit,fitStart,fitEnd
1007        String topGraph
1008       
1009        String str,pictStr="P_"
1010        String nb="Report"
1011               
1012        // bring report up
1013        DoWindow/F Report
1014        if (V_flag == 0)                // Report notebook doesn't exist ?
1015                NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report"
1016        endif
1017        // delete old stuff
1018        Notebook $nb selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile}
1019       
1020        //setup
1021        Notebook $nb defaultTab=36, statusWidth=252, pageMargins={72,72,72,72}
1022        Notebook $nb showRuler=1, rulerUnits=1, updating={1, 60}
1023        Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Geneva",10,0,(0,0,0)}
1024//     
1025        // insert title
1026        Notebook $nb newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)}
1027        sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time()
1028        Notebook $nb ruler=Title, text=str
1029       
1030        // insert fit results
1031        Variable num=numpnts(ans),ii=0
1032        Notebook $nb ruler=Normal
1033        Notebook $nb  margins={18,18,504}, tabs={63 + 3*8192}
1034        str = "Data file: " + dataname + "\r\r"
1035        Notebook $nb text=str
1036        Notebook $nb ruler=Normal
1037        Notebook $nb margins={18,18,504}, tabs={144,234,252}
1038        do
1039                sprintf str, "%s = \t%g\t±\t%g\r", param[ii],ans[ii],sigwave[ii]
1040                Notebook $nb text=str
1041                ii+=1
1042        while(ii<num)
1043       
1044        //
1045        // no "fitted range" for 2D data, so make sure that this exists before using it
1046        Wave/Z dataXw = $("root:"+dataname+":"+dataname+"_q")   
1047        //
1048        Notebook $nb ruler=Normal
1049        Notebook $nb  margins={18,18,504}, tabs={63+3*8192}, fStyle=1, textRGB=(65000,0,0)
1050       
1051        sprintf str,"chisq = %g\r",chisq
1052        Notebook $nb textRGB=(65000,0,0),fstyle=1,text=str
1053        sprintf str,"Npnts = %g \t\t Sqrt(X^2/N) = %g\r",npts,sqrt(chiSq/npts)
1054        Notebook $nb textRGB=(0,0,0),fstyle=0, text=str
1055        if(WaveExists(dataXw))
1056                sprintf str "Fitted range = [%d,%d] = %g < Q < %g\r",fitStart,fitEnd,dataXw(fitStart),dataXw(fitEnd)
1057                Notebook $nb textRGB=(0,0,0),fstyle=0, text=str
1058        endif
1059        sprintf str,"FitError = %s\t\tFitQuitReason = %s\r",W_ErrorMessage(FitErr),W_QuitMessage(FitQuit)
1060        Notebook $nb textRGB=(65000,0,0),fstyle=1,text=str
1061        Notebook $nb ruler=Normal
1062       
1063        // insert graphs
1064        if(WaveExists(dataXw))
1065                Notebook $nb picture={$topGraph(0, 0, 400, 300), 0, 1}, text="\r"
1066        //
1067        else            //must be 2D Gizmo
1068                Execute "ExportGizmo Clip"
1069                LoadPict/Q/O "Clipboard",tmp_Gizmo
1070                Notebook $nb picture={tmp_Gizmo(0, 0, 400, 300), 0, 1}, text="\r"
1071        endif
1072        //Notebook Report picture={Table1, 0, 0}, text="\r"
1073       
1074        // show the top of the report
1075        Notebook $nb  selection= {startOfFile, startOfFile},  findText={"", 1}
1076       
1077        //save the notebook and the graphic file
1078        if(yesSave)
1079                String nameStr=CleanupName(func,0)
1080                nameStr = nameStr[0,8]  //shorten the name
1081                nameStr += "_"+dataname
1082                //make sure the name is no more than 31 characters
1083                namestr = namestr[0,30]         //if shorter than 31, this will NOT pad to 31 characters
1084                Print "file saved as ",nameStr
1085                SaveNotebook /O/P=home/S=2 $nb as nameStr
1086                //save the graph separately as a PICT file, 2x screen
1087                pictStr += nameStr
1088                pictStr = pictStr[0,28]         //need a shorter name - why?
1089//              DoWindow/F $topGraph
1090                // E=-5 is png @screen resolution
1091                // E=2 is PICT @2x screen resolution
1092///             SavePICT /E=-5/O/P=home /I/W=(0,0,3,3) as pictStr
1093                if(WaveExists(dataXw))
1094                        SavePICT /E=-5/O/P=home/WIN=$topGraph /W=(0,0,400,300) as pictStr
1095                else
1096                        Execute "ExportGizmo /P=home as \""+pictStr+"\""
1097                        //SavePICT /E=-5/O/P=home/WIN=$topGraph /W=(0,0,400,300) as pictStr
1098                endif
1099        Endif
1100       
1101        // ???maybe print the notebook too?
1102End
1103
1104Function/S W_ErrorMessage(code)
1105        Variable code
1106       
1107        switch (code)
1108                case 0:
1109                        return "No Error"
1110                        break
1111                case 3: //2^0 + 2^1
1112                        return "Singular Matrix"
1113                        break
1114                case 5:         //(2^0 + 2^2)
1115                        return "Out of Memory"
1116                        break
1117                case 9:         //(2^0 + 2^3)
1118                        return "Func= NaN or Inf"
1119                        break
1120                default:
1121                        return "Unknown error code "+num2str(code)
1122        endswitch
1123end
1124
1125Function/S W_QuitMessage(code)
1126        Variable code
1127       
1128        switch (code)
1129                case 0:
1130                        return "No Error"
1131                        break
1132                case 1:
1133                        return "Max iterations - re-run fit"
1134                        break
1135                case 2:
1136                        return "User terminated fit"
1137                        break
1138                case 3:
1139                        return "No decrease in chi-squared"
1140                        break
1141                default:
1142                        return "Unknown Quit code "+num2str(code)
1143        endswitch
1144end
1145
1146Function Toggle2DControlsCheckProc(cba) : CheckBoxControl
1147        STRUCT WMCheckboxAction &cba
1148
1149        switch( cba.eventCode )
1150                case 2: // mouse up
1151                        Variable checked = cba.checked
1152                        if(checked)
1153                                //print "change the buttons to 2D"
1154                                Button button_0,proc=Do2DFitButtonProc,title="Do 2D Fit"
1155                                Button button_1,size={120,20},proc=Plot2DFunctionButtonProc,title="Plot 2D Function"
1156                                Button button_2,size={100,20},proc=Append2DModelButtonProc,title="Append 2D"
1157                                Button button_3,size={100,20},proc=Load2DDataButtonProc,title="Load 2D Data"
1158                               
1159                                Button button_2D_0,pos={550,60},size={70,20},proc=LogToggle2DButtonProc,title="Log/Lin"
1160                                Button button_2D_1,pos={520,37},size={100,20},proc=Plot2DButtonProc,title="Plot 2D Data"
1161                               
1162                                Button button_2D_0,disable=0            //visible again, and enabled
1163                                Button button_2D_1,disable=0
1164                        else
1165                                //print "unchecked, change them back to 1D"
1166                                Button button_0,pos={520,93},size={100,20},proc=DoTheFitButton,title="Do 1D Fit"
1167                                Button button_1,pos={280,57},size={120,20},proc=PlotModelFunction,title="Plot 1D Function"
1168                                Button button_2,pos={300,93},size={100,20},proc=AppendModelToTarget,title="Append 1D"
1169                                Button button_3,pos={300,20},size={100,20},proc=W_LoadDataButtonProc,title="Load 1D Data"
1170                               
1171                                Button button_2D_0,disable=3    //hide the extra 2D buttons, and disable
1172                                Button button_2D_1,disable=3
1173                        endif
1174                        break
1175        endswitch
1176
1177        return 0
1178End
1179
1180// function to either add or remove the cursors from the topmost graph, as needed
1181
1182Function UseCursorsWrapperProc(cba) : CheckBoxControl
1183        STRUCT WMCheckboxAction &cba
1184
1185        String topGraph= WinName(0,1)   //this is the topmost graph
1186        if(cmpstr(topGraph,"")==0)      //no graphs, uncheck and exit
1187                CheckBox check_0,value=0
1188                return(0)
1189        endif
1190               
1191        String ciStr = CsrInfo(A , topGraph)
1192       
1193        ControlInfo/W=wrapperpanel popup_0
1194        String folderStr=S_Value
1195        String traceList = TraceNameList(topGraph, ";", 1 )
1196       
1197        switch( cba.eventCode )
1198                case 2: // mouse up
1199                        Variable checked = cba.checked
1200                        if(checked)
1201                                //print "add the cursors to the topmost graph, if the data set is there, or move them"
1202                                if(strlen(ciStr)==0 && strsearch(traceList, folderStr, 0) != -1 )               //no cursors && data is there
1203                                        ShowInfo
1204                                        Wave yw=$("root:"+folderStr+":"+folderStr+"_i")
1205                                        Cursor/P/W=$topGraph A, $(folderStr+"_i"),0
1206                                        Cursor/P/W=$topGraph/A=0 B, $(folderStr+"_i"),numpnts(yw)-1                     //deactivate the one at the high Q end
1207                                        DoUpdate
1208//                              else            //if (strlen(ciStr)!=0 && strsearch(traceList, folderStr, 0) != -1 ) //cursors present, but on wrong data
1209//                                      Wave yw=$("root:"+folderStr+":"+folderStr+"_i")
1210//                                      Cursor/P/W=$topGraph A, $(folderStr+"_i"),0                                                             //move the cursors
1211//                                      Cursor/P/W=$topGraph/A=0 B, $(folderStr+"_i"),numpnts(yw)-1
1212//                                      DoUpdate
1213                                endif
1214                       
1215                        else
1216                                //print "unchecked, remove the cursors"
1217                                // go back to the full matrix for the resolution calculation (not if SANS data...)
1218                                if(waveExists($("root:"+folderStr+":weights_save")))
1219                                        Duplicate/O $("root:"+folderStr+":weights_save"), $("root:"+folderStr+":"+folderStr+"_res")
1220                                endif
1221                                HideInfo
1222                                Cursor/K A
1223                                Cursor/K B
1224                        endif
1225                        break
1226        endswitch
1227
1228        return 0
1229End
Note: See TracBrowser for help on using the repository browser.