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

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

Lamellar_PS models now set the epsilon wave properly, and it doesn't get overwritten

Small fic to the wrapper to have better behavior with cursors. This issue is not done yet.

File size: 37.1 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                                if(eps[0] == 0)         //if eps already if filled, don't change it
380                                        eps = abs(coef*1e-4) + 1e-10                    //default eps is proportional to the coefficients
381                                endif
382                        endif
383                        // default epsilon values, sometimes needed for the fit
384                       
385
386                        WAVE/T LoLim = $("LoLim_"+suffix)
387                        WAVE/T HiLim = $("HiLim_"+suffix)
388                       
389                        // clear the table (a subwindow)
390                        KillWindow wrapperPanel#T0
391                        Edit/W=(20,174,634,435)/HOST=#
392                        RenameWindow #,T0
393                        // get them onto the table
394                        // how do I get the parameter name?
395                        String param = WaveList("*parameters_"+suffix, "", "TEXT:1," )          //this is *hopefully* one wave
396                        AppendtoTable/W=wrapperPanel#T0 $param,$(popStr)
397                        AppendToTable/W=wrapperPanel#T0 $("Hold_"+suffix),$("LoLim_"+suffix),$("HiLim_"+suffix),$("epsilon_"+suffix)
398                        ModifyTable width(Point)=0
399                       
400                        SetDataFolder root:
401                        break
402        endswitch
403
404        return 0
405End
406
407// if the Function is changed, then update the coef popup (if possible) and then the table (if possible)
408//
409// !! only respond to mouse up
410//
411Function Function_PopMenuProc(pa) : PopupMenuControl
412        STRUCT WMPopupAction &pa
413
414        switch( pa.eventCode )
415                case 2: // mouse up
416                        Variable popNum = pa.popNum
417                        String funcStr = pa.popStr
418                        String coefStr = W_CoefPopupList()
419                       
420//                      Print "coefStr = ",coefStr
421                       
422                        ControlInfo/W=WrapperPanel popup_0
423                        String folderStr=S_Value
424                       
425                        String listStr = W_CoefPopupList()
426                        Variable num=WhichListItem(coefStr, listStr, ";")
427                        String str=StringFromList(num, listStr  ,";")
428//                      print "str = ",str
429                        //set the item in the coef popup, and pop it
430                        PopupMenu popup_2 win=WrapperPanel,mode=(num+1)
431                       
432                        Struct WMPopupAction ps
433                        ps.eventCode = 2                //fake mouse up
434                        ps.popStr = str
435                        Coef_PopMenuProc(ps)
436                       
437                        SetDataFolder root:
438                        break
439        endswitch
440
441        return 0
442End
443
444// if the Data Set is changed, then update the function (if possible)
445// and the coef popup (if possible) and then the table (if possible)
446//
447// !! only respond to mouse up here, and simply send a fake mouse up
448// to the function pop, which will do what it can do
449//
450Function DataSet_PopMenuProc(pa) : PopupMenuControl
451        STRUCT WMPopupAction &pa
452
453        switch( pa.eventCode )
454                case 2: // mouse up
455                // make sure that the cursors are on/off appropriately
456                // check to make sure there really is a "topmost" graph         
457//                      String topGraph= WinName(0,1)   //this is the topmost graph
458//                      if(cmpstr(topGraph,"")==0)      //no graphs, uncheck and exit
459//                              CheckBox check_0,value=0
460//                      else
461//                              String ciStr = CsrInfo(A , topGraph)
462//                             
463//                              ControlInfo/W=wrapperpanel popup_0
464//                              String folderStr=S_Value
465//                              String traceList = TraceNameList(topGraph, ";", 1 )             
466//                     
467//                      endif
468                                               
469                        // then cascade the function/coefficient popups
470                        Struct WMPopupAction ps
471                        ps.eventCode = 2                //fake mouse up
472                        Function_PopMenuProc(ps)
473                       
474                        SetDataFolder root:
475                        break
476        endswitch
477
478        return 0
479End
480
481
482
483// always pass this the coefficient string
484//
485// either "coef_"
486// or "smear_coef_"
487//
488Function/S getFunctionCoef(funcStr)
489        String funcStr
490
491        SVAR listStr=root:Packages:NIST:coefKWStr
492        String coefStr = StringByKey(funcStr, listStr  ,"=",";",0)
493
494        return(coefStr)
495End
496
497// always pass this the coefficient string
498//
499// either "coef_"
500// or "smear_coef_"
501//
502// does NOT return the leading "_" as part of the suffix
503Function/S getModelSuffix(coefStr)
504        String coefStr
505
506        SVAR listStr=root:Packages:NIST:suffixKWStr
507        String suffixStr = StringByKey(coefStr, listStr  ,"=",";",0)
508
509        return(suffixStr)
510//      Variable pos,start=0
511
512//      if(stringmatch(coefStr,"smear_*") == 1)
513//              start=7 //look forwards to find "_", skipping "smear_coe" if necessary
514//      endif
515//      pos=Strsearch(coefStr,"_",start,0)
516        //Print start, pos
517//      return(coefStr[pos,strlen(coefStr)-1])
518End
519
520
521
522// - this is based on stringent "PlotNNN" naming requirements
523//
524//  ???
525// - how to kill the generated table and graph, that are not needed now
526//
527Function PlotModelFunction(ba) : ButtonControl
528        STRUCT WMButtonAction &ba
529
530        String folderStr,funcStr,coefStr,cmdStr=""
531        Variable useCursors,useEps,useConstr
532       
533        Variable killWhat=0             //kill nothing as default
534       
535        switch( ba.eventCode )
536                case 2: // mouse up
537                        ControlInfo/W=WrapperPanel popup_0
538                        folderStr=S_Value
539                       
540                        ControlInfo/W=WrapperPanel popup_1
541                        funcStr=S_Value
542                       
543                        // maybe nothing has been loaded yet...
544                        if(cmpstr(funcStr,"No functions plotted") == 0)
545                                break
546                        endif
547                       
548                        // check for smeared or smeared function
549                        if(stringmatch(funcStr, "Smear*" )==1)
550                                //it's a smeared model
551                                // check for the special case of RPA that has an extra parameter
552                                if(strsearch(funcStr, "RPAForm", 0 ,0) == -1)
553                                        sprintf cmdStr, "Plot%s(\"%s\")",funcStr,folderStr              //not RPA
554                                else
555                                        sprintf cmdStr, "Plot%s(\"%s\",)",funcStr,folderStr             //yes RPA, leave a comma for input
556                                endif
557                                killWhat = 1
558                        else
559                                // it's not,    don't kill the graph, just the table           
560                                sprintf cmdStr, "Plot%s()",funcStr
561                                killWhat = 2
562                        endif
563                       
564                        //Print cmdStr
565                        Execute cmdStr
566                       
567                        //pop the function menu to set the proper coefficients
568                        DoWindow/F WrapperPanel
569                        STRUCT WMPopupAction pa
570                        pa.popStr = funcStr
571                        pa.eventcode = 2
572                        Function_PopMenuProc(pa)
573       
574                        KillTopGraphAndTable(killWhat)          // crude
575       
576                        break
577        endswitch
578       
579        return 0
580End
581
582// passing 0 kills nothing
583// passing 1 kills the top graph and table
584// passing 2 kills the top table only
585//
586Function KillTopGraphAndTable(killwhat)
587        Variable killWhat
588       
589        String topGraph= WinName(0,1)   //this is the topmost graph     
590        String topTable= WinName(0,2)   //this is the topmost table
591
592        if(killWhat == 0)
593                return(0)
594        endif
595       
596        if(killWhat == 1)
597                KillWindow $topGraph
598                KillWindow $topTable
599        endif
600       
601        if(killWhat == 2)
602                KillWindow $topTable
603        endif
604       
605        return(0)
606End
607
608// How to bypass the step of plot and append?
609//
610// do it in two separate events
611//
612Function AppendModelToTarget(ba) : ButtonControl
613        STRUCT WMButtonAction &ba
614
615        String coefStr,suffix,yWStr,xWStr,folderStr
616       
617        switch( ba.eventCode )
618                case 2: // mouse up                     
619                        ControlInfo/W=WrapperPanel popup_2
620                        coefStr=S_Value
621                        suffix = getModelSuffix(coefStr)
622                       
623                        // check for smeared or smeared function
624                        if(stringmatch(coefStr, "smear*" )==1)
625                                //it's a smeared model
626                                ControlInfo/W=WrapperPanel popup_0
627                                folderStr=S_Value
628                                xWStr = "root:"+folderStr+":smeared_qvals"
629                                ywStr = "root:"+folderStr+":smeared_"+suffix
630                        else
631                                // it's not, so it's in the root folder
632                                xWStr = "xwave_"+suffix
633                                yWStr = "ywave_"+suffix
634                        endif
635                       
636                        Wave/Z yw = $yWStr
637                        Wave/Z xw = $xWStr
638                        if(WaveExists(yw) && WaveExists(xw))
639                                AppendtoGraph yw vs xw
640                        else
641                                DoAlert 0,"The selected model has not been plotted for the selected data set."
642                        endif
643                        break
644        endswitch
645       
646        return 0
647End
648
649
650// this should parse the panel and call the FitWrapper() function
651Function DoTheFitButton(ba) : ButtonControl
652        STRUCT WMButtonAction &ba
653
654        String folderStr,funcStr,coefStr
655        Variable useCursors,useEps,useConstr
656       
657        switch( ba.eventCode )
658                case 2: // mouse up
659                        ControlInfo/W=WrapperPanel popup_0
660                        folderStr=S_Value
661                       
662                        ControlInfo/W=WrapperPanel popup_1
663                        funcStr=S_Value
664                       
665                        ControlInfo/W=WrapperPanel popup_2
666                        coefStr=S_Value
667                       
668                        ControlInfo/W=WrapperPanel check_0
669                        useCursors=V_Value
670                        ControlInfo/W=WrapperPanel check_1
671                        useEps=V_Value
672                        ControlInfo/W=WrapperPanel check_2
673                        useConstr=V_Value
674                       
675                        if(!CheckFunctionAndCoef(funcStr,coefStr))
676                                DoAlert 0,"The coefficients and function type do not match. Please correct the selections in the popup menus."
677                                break
678                        endif
679                       
680                        FitWrapper(folderStr,funcStr,coefStr,useCursors,useEps,useConstr)
681                       
682                        //      DoUpdate (does not work!)
683                        //?? why do I need to force an update ??
684                        if(!exists("root:"+folderStr+":"+coefStr))
685                                Wave w=$coefStr
686                        else
687                                Wave w=$("root:"+folderStr+":"+coefStr) //smeared coefs in data folder
688                        endif
689                        w[0] += 1e-6
690                        w[0] -= 1e-6
691       
692                        break
693        endswitch
694       
695        return 0
696End
697
698Function CheckFunctionAndCoef(funcStr,coefStr)
699        String funcStr,coefStr
700       
701        SVAR listStr=root:Packages:NIST:coefKWStr
702        String properCoefStr = StringByKey(funcStr, listStr  ,"=",";",0)
703        if(cmpstr(coefStr,properCoefStr)==0)
704                return(1)               //true, the coef is the correct match
705        endif
706        return(0)                       //false, wrong coef
707End
708
709/////////////////////////////////
710
711// wrapper to do the desired fit
712//
713// folderStr is the data folder for the desired data set
714//
715//
716Function FitWrapper(folderStr,funcStr,coefStr,useCursors,useEps,useConstr)
717        String folderStr,funcStr,coefStr
718        Variable useCursors,useEps,useConstr
719
720        String suffix=getModelSuffix(coefStr)
721       
722        SetDataFolder $("root:"+folderStr)
723        if(!exists(coefStr))
724                // must be unsmeared model, work in the root folder
725                SetDataFolder root:                             
726                if(!exists(coefStr))            //this should be fine if the coef filter is working, but check anyhow
727                        DoAlert 0,"the coefficient and data sets do not match"
728                        return 0
729                endif
730        endif
731               
732        WAVE cw=$(coefStr)     
733        Wave hold=$("Hold_"+suffix)
734        Wave/T lolim=$("LoLim_"+suffix)
735        Wave/T hilim=$("HiLim_"+suffix)
736        Wave eps=$("epsilon_"+suffix)
737       
738// fill a struct instance whether I need one or not
739        String DF="root:"+folderStr+":"
740       
741        Struct ResSmearAAOStruct fs
742        WAVE/Z resW = $(DF+folderStr+"_res")                    //these may not exist, if 3-column data is used
743        WAVE/Z fs.resW =  resW
744        WAVE yw=$(DF+folderStr+"_i")
745        WAVE xw=$(DF+folderStr+"_q")
746        WAVE sw=$(DF+folderStr+"_s")
747        Wave fs.coefW = cw
748        Wave fs.yW = yw
749        Wave fs.xW = xw
750       
751        Duplicate/O yw $(DF+"FitYw")
752        WAVE fitYw = $(DF+"FitYw")
753        fitYw = NaN
754       
755        Variable useRes=0
756        if(stringmatch(funcStr, "Smear*"))              // if it's a smeared function, need a struct
757                useRes=1
758        endif
759       
760        // do not construct constraints for any of the coefficients that are being held
761        // -- this will generate an "unknown error" from the curve fitting
762        Make/O/T/N=0 constr
763        if(useConstr)
764                String constraintExpression
765                Variable i, nPnts=DimSize(lolim, 0),nextRow=0
766                for (i=0; i < nPnts; i += 1)
767                        if (strlen(lolim[i]) > 0 && hold[i] == 0)
768                                InsertPoints nextRow, 1, constr
769                                sprintf constraintExpression, "K%d > %s", i, lolim[i]
770                                constr[nextRow] = constraintExpression
771                                nextRow += 1
772                        endif
773                        if (strlen(hilim[i]) > 0 && hold[i] == 0)
774                                InsertPoints nextRow, 1, constr
775                                sprintf constraintExpression, "K%d < %s", i, hilim[i]
776                                constr[nextRow] = constraintExpression
777                                nextRow += 1
778                        endif
779                endfor
780        endif
781
782        // 20JUN if useCursors is true, and there are no cursors on the specified data set, uncheck and set to false
783        if(useCursors)
784                useCursors = AreCursorsCorrect(folderStr)
785        endif
786        //if useCursors, and the data is USANS, need to recalculate the matrix if the range is new
787        Variable pt1,pt2,newN,mPt1,mPt2
788        String noteStr
789        if(useCursors && (dimsize(resW,1) > 4) )
790                //where are the cursors, and what is the status of the current matrix?
791                if(pcsr(A) > pcsr(B))
792                        pt1 = pcsr(B)
793                        pt2 = pcsr(A)
794                else
795                        pt1 = pcsr(A)
796                        pt2 = pcsr(B)
797                endif
798               
799                noteStr = note(resW)
800                mPt1 = NumberByKey("P1",noteStr,"=",";")
801                mPt2 = NumberByKey("P2",noteStr,"=",";")
802                if((mPt1 != pt1) || (mPt2 != pt2) )
803                        // need to recalculate
804                        USANS_RE_CalcWeights(folderStr,pt1,pt2)
805                endif
806                Wave trimResW=$(DF+folderStr+"_res"+"t")        //put the trimmed resW in the struct for the fit!
807                Wave fs.resW=trimResW
808               
809                Print "Done recalculating the matrix"
810//////WRONG WAY
811//              Make/O/D/N=(newN,newN) $(DF+"crsrResW")
812//              WAVE crsrResW = $(DF+"crsrResW")
813//              crsrResW = resW[p+pt1][q+pt1]
814//              //assign to the struct
815//              WAVE fs.resW =  crsrResW               
816/////////////
817        endif
818       
819        if(!useCursors && (dimsize(resW,1) > 4) )
820                // avoid an odd sequence of y/n cursors that can lead to a truncated res matrix, but useCursors is not selected
821                if(waveExists($("root:"+folderStr+":weights_save")))
822                        Duplicate/O $("root:"+folderStr+":weights_save"), $("root:"+folderStr+":"+folderStr+"_res")
823                endif
824        endif
825       
826// create these variables so that FuncFit will set them on exit
827        Variable/G V_FitError=0                         //0=no err, 1=error,(2^1+2^0)=3=singular matrix
828        Variable/G V_FitQuitReason=0            //0=ok,1=maxiter,2=user stop,3=no chisq decrease
829       
830// don't use the auto-destination with no flag, it doesn't appear to work correctly
831// dispatch the fit
832        do
833                if(useRes && useEps && useCursors && useConstr)         //do it all
834                        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
835                        break
836                endif
837               
838                if(useRes && useEps && useCursors)              //no constr
839                        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
840                        break
841                endif
842               
843                if(useRes && useEps && useConstr)               //no crsr
844                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs
845                        break
846                endif
847               
848                if(useRes && useCursors && useConstr)           //no eps
849                        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
850                        break
851                endif
852               
853                if(useRes && useCursors)                //no eps, no constr
854                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
855                        break
856                endif
857               
858                if(useRes && useEps)            //no crsr, no constr
859//                      Print "timing test for Cylinder_PolyRadius --- the supposedly threaded version ---"
860//                      Variable t0 = stopMStimer(-2)
861                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
862//                      t0 = (stopMSTimer(-2) - t0)*1e-6
863//                      Printf  "CylPolyRad fit time using res and eps and /NTHR=0 time = %g seconds\r\r",t0
864                       
865//                      cw[0] = .01
866//                      cw[1] = 20
867//                      cw[2] = 400
868//                      cw[3] = 0.2
869//                      cw[4] = 3e-6
870//                      cw[5] = 0.0
871//                     
872//                      t0 = stopMSTimer(-2)
873//                      FuncFit/H=getHStr(hold) $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
874//                      t0 = (stopMSTimer(-2) - t0)*1e-6
875//                      Printf  "CylPolyRad fit time using res and eps and NO THREADING time = %g seconds\r\r",t0
876                        break
877                endif
878       
879                if(useRes && useConstr)         //no crsr, no eps
880                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs
881                        break
882                endif
883               
884                if(useRes)              //just res
885                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
886                        break
887                endif
888               
889/////   same as above, but all without useRes (no /STRC flag)
890                if(useEps && useCursors && useConstr)           //do it all
891                        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
892                        break
893                endif
894               
895                if(useEps && useCursors)                //no constr
896                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /E=eps /D=fitYw
897                        break
898                endif
899               
900                if(useEps && useConstr)         //no crsr
901                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr
902                        break
903                endif
904               
905                if(useCursors && useConstr)             //no eps
906                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw /C=constr
907                        break
908                endif
909               
910                if(useCursors)          //no eps, no constr
911                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw[pcsr(A),pcsr(B)] /X=xw /W=sw /I=1 /D=fitYw
912                        break
913                endif
914               
915                if(useEps)              //no crsr, no constr
916                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw
917                        break
918                endif
919       
920                if(useConstr)           //no crsr, no eps
921                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr
922                        break
923                endif
924               
925                //just a plain vanilla fit
926                FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw
927       
928        while(0)
929       
930        // append the fit
931        // need to manage duplicate copies
932        // Don't plot the full curve if cursors were used (set fitYw to NaN on entry...)
933        String traces=TraceNameList("", ";", 1 )                //"" as first parameter == look on the target graph
934        if(strsearch(traces,"FitYw",0) == -1)
935                AppendToGraph FitYw vs xw
936        else
937                RemoveFromGraph FitYw
938                AppendToGraph FitYw vs xw
939        endif
940        ModifyGraph lsize(FitYw)=2,rgb(FitYw)=(0,0,0)
941       
942        DoUpdate                //force update of table and graph with fitted values (why doesn't this work? - the table still does not update)
943       
944        // report the results (to the panel?)
945        print "V_chisq = ",V_chisq
946        print cw
947        WAVE/Z w_sigma
948        print w_sigma
949        String resultStr=""
950               
951        //now re-write the results
952        sprintf resultStr,"Chi^2 = %g  Sqrt(X^2/N) = %g",V_chisq,sqrt(V_chisq/V_Npnts)
953        resultStr = PadString(resultStr,63,0x20)
954        GroupBox grpBox_2 title=resultStr
955        ControlUpdate/W=WrapperPanel grpBox_2
956        sprintf resultStr,"FitErr = %s : FitQuit = %s",W_ErrorMessage(V_FitError),W_QuitMessage(V_FitQuitReason)
957        resultStr = PadString(resultStr,63,0x20)
958        GroupBox grpBox_3 title=resultStr
959        ControlUpdate/W=WrapperPanel grpBox_3
960       
961        Variable yesSave=0,yesReport=0
962        ControlInfo/W=WrapperPanel check_4
963        yesReport = V_Value
964        ControlInfo/W=WrapperPanel check_5
965        yesSave = V_Value
966       
967       
968        if(yesReport)
969                String parStr=GetWavesDataFolder(cw,1)+ WaveList("*param*"+suffix, "", "TEXT:1," )              //this is *hopefully* one wave
970                String topGraph= WinName(0,1)   //this is the topmost graph
971       
972                DoUpdate                //force an update of the graph before making a copy of it for the report
973
974                W_GenerateReport(funcStr,folderStr,$parStr,cw,yesSave,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph)
975        endif
976       
977        SetDataFolder root:
978        return(0)
979End
980
981// parse something off of a table, or ?
982Function/S getHStr(hold)
983        Wave hold
984       
985        String str=""
986        Variable ii
987        for(ii=0;ii<numpnts(hold);ii+=1)
988                str += num2str(hold[ii])
989        endfor
990
991//      print str
992        if(strsearch(str, "1", 0) == -1)
993                return ("")
994        else
995                return(str)
996        endif
997End
998
999//taken from SRK Auto_Fit, and modified to work better with FitWrapper
1000//must have AutoGraph as the name of the graph window (any size)
1001// func is the name of the function (for print only)
1002//par and coef are the exact names of the waves
1003//yesSave==1 will save the file(name=func+time)
1004//
1005Function W_GenerateReport(func,dataname,param,ans,yesSave,chiSq,sigWave,npts,fitErr,fitQuit,fitStart,fitEnd,topGraph)
1006        String func,dataname
1007        Wave/T param
1008        Wave ans
1009        Variable yesSave,chiSq
1010        Wave sigWave
1011        Variable npts,fitErr,fitQuit,fitStart,fitEnd
1012        String topGraph
1013       
1014        String str,pictStr="P_"
1015        String nb="Report"
1016               
1017        // bring report up
1018        DoWindow/F Report
1019        if (V_flag == 0)                // Report notebook doesn't exist ?
1020                NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report"
1021        endif
1022        // delete old stuff
1023        Notebook $nb selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile}
1024       
1025        //setup
1026        Notebook $nb defaultTab=36, statusWidth=252, pageMargins={72,72,72,72}
1027        Notebook $nb showRuler=1, rulerUnits=1, updating={1, 60}
1028        Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Geneva",10,0,(0,0,0)}
1029//     
1030        // insert title
1031        Notebook $nb newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)}
1032        sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time()
1033        Notebook $nb ruler=Title, text=str
1034       
1035        // insert fit results
1036        Variable num=numpnts(ans),ii=0
1037        Notebook $nb ruler=Normal
1038        Notebook $nb  margins={18,18,504}, tabs={63 + 3*8192}
1039        str = "Data file: " + dataname + "\r\r"
1040        Notebook $nb text=str
1041        Notebook $nb ruler=Normal
1042        Notebook $nb margins={18,18,504}, tabs={144,234,252}
1043        do
1044                sprintf str, "%s = \t%g\t±\t%g\r", param[ii],ans[ii],sigwave[ii]
1045                Notebook $nb text=str
1046                ii+=1
1047        while(ii<num)
1048       
1049        //
1050        // no "fitted range" for 2D data, so make sure that this exists before using it
1051        Wave/Z dataXw = $("root:"+dataname+":"+dataname+"_q")   
1052        //
1053        Notebook $nb ruler=Normal
1054        Notebook $nb  margins={18,18,504}, tabs={63+3*8192}, fStyle=1, textRGB=(65000,0,0)
1055       
1056        sprintf str,"chisq = %g\r",chisq
1057        Notebook $nb textRGB=(65000,0,0),fstyle=1,text=str
1058        sprintf str,"Npnts = %g \t\t Sqrt(X^2/N) = %g\r",npts,sqrt(chiSq/npts)
1059        Notebook $nb textRGB=(0,0,0),fstyle=0, text=str
1060        if(WaveExists(dataXw))
1061                sprintf str "Fitted range = [%d,%d] = %g < Q < %g\r",fitStart,fitEnd,dataXw(fitStart),dataXw(fitEnd)
1062                Notebook $nb textRGB=(0,0,0),fstyle=0, text=str
1063        endif
1064        sprintf str,"FitError = %s\t\tFitQuitReason = %s\r",W_ErrorMessage(FitErr),W_QuitMessage(FitQuit)
1065        Notebook $nb textRGB=(65000,0,0),fstyle=1,text=str
1066        Notebook $nb ruler=Normal
1067       
1068        // insert graphs
1069        if(WaveExists(dataXw))
1070                Notebook $nb picture={$topGraph(0, 0, 400, 300), 0, 1}, text="\r"
1071        //
1072        else            //must be 2D Gizmo
1073                Execute "ExportGizmo Clip"
1074                LoadPict/Q/O "Clipboard",tmp_Gizmo
1075                Notebook $nb picture={tmp_Gizmo(0, 0, 400, 300), 0, 1}, text="\r"
1076        endif
1077        //Notebook Report picture={Table1, 0, 0}, text="\r"
1078       
1079        // show the top of the report
1080        Notebook $nb  selection= {startOfFile, startOfFile},  findText={"", 1}
1081       
1082        //save the notebook and the graphic file
1083        if(yesSave)
1084                String nameStr=CleanupName(func,0)
1085                nameStr = nameStr[0,8]  //shorten the name
1086                nameStr += "_"+dataname
1087                //make sure the name is no more than 31 characters
1088                namestr = namestr[0,30]         //if shorter than 31, this will NOT pad to 31 characters
1089                Print "file saved as ",nameStr
1090                SaveNotebook /O/P=home/S=2 $nb as nameStr
1091                //save the graph separately as a PICT file, 2x screen
1092                pictStr += nameStr
1093                pictStr = pictStr[0,28]         //need a shorter name - why?
1094//              DoWindow/F $topGraph
1095                // E=-5 is png @screen resolution
1096                // E=2 is PICT @2x screen resolution
1097///             SavePICT /E=-5/O/P=home /I/W=(0,0,3,3) as pictStr
1098                if(WaveExists(dataXw))
1099                        SavePICT /E=-5/O/P=home/WIN=$topGraph /W=(0,0,400,300) as pictStr
1100                else
1101                        Execute "ExportGizmo /P=home as \""+pictStr+"\""
1102                        //SavePICT /E=-5/O/P=home/WIN=$topGraph /W=(0,0,400,300) as pictStr
1103                endif
1104        Endif
1105       
1106        // ???maybe print the notebook too?
1107End
1108
1109Function/S W_ErrorMessage(code)
1110        Variable code
1111       
1112        switch (code)
1113                case 0:
1114                        return "No Error"
1115                        break
1116                case 3: //2^0 + 2^1
1117                        return "Singular Matrix"
1118                        break
1119                case 5:         //(2^0 + 2^2)
1120                        return "Out of Memory"
1121                        break
1122                case 9:         //(2^0 + 2^3)
1123                        return "Func= NaN or Inf"
1124                        break
1125                default:
1126                        return "Unknown error code "+num2str(code)
1127        endswitch
1128end
1129
1130Function/S W_QuitMessage(code)
1131        Variable code
1132       
1133        switch (code)
1134                case 0:
1135                        return "No Error"
1136                        break
1137                case 1:
1138                        return "Max iterations - re-run fit"
1139                        break
1140                case 2:
1141                        return "User terminated fit"
1142                        break
1143                case 3:
1144                        return "No decrease in chi-squared"
1145                        break
1146                default:
1147                        return "Unknown Quit code "+num2str(code)
1148        endswitch
1149end
1150
1151Function Toggle2DControlsCheckProc(cba) : CheckBoxControl
1152        STRUCT WMCheckboxAction &cba
1153
1154        switch( cba.eventCode )
1155                case 2: // mouse up
1156                        Variable checked = cba.checked
1157                        if(checked)
1158                                //print "change the buttons to 2D"
1159                                Button button_0,proc=Do2DFitButtonProc,title="Do 2D Fit"
1160                                Button button_1,size={120,20},proc=Plot2DFunctionButtonProc,title="Plot 2D Function"
1161                                Button button_2,size={100,20},proc=Append2DModelButtonProc,title="Append 2D"
1162                                Button button_3,size={100,20},proc=Load2DDataButtonProc,title="Load 2D Data"
1163                               
1164                                Button button_2D_0,pos={550,60},size={70,20},proc=LogToggle2DButtonProc,title="Log/Lin"
1165                                Button button_2D_1,pos={520,37},size={100,20},proc=Plot2DButtonProc,title="Plot 2D Data"
1166                               
1167                                Button button_2D_0,disable=0            //visible again, and enabled
1168                                Button button_2D_1,disable=0
1169                        else
1170                                //print "unchecked, change them back to 1D"
1171                                Button button_0,pos={520,93},size={100,20},proc=DoTheFitButton,title="Do 1D Fit"
1172                                Button button_1,pos={280,57},size={120,20},proc=PlotModelFunction,title="Plot 1D Function"
1173                                Button button_2,pos={300,93},size={100,20},proc=AppendModelToTarget,title="Append 1D"
1174                                Button button_3,pos={300,20},size={100,20},proc=W_LoadDataButtonProc,title="Load 1D Data"
1175                               
1176                                Button button_2D_0,disable=3    //hide the extra 2D buttons, and disable
1177                                Button button_2D_1,disable=3
1178                        endif
1179                        break
1180        endswitch
1181
1182        return 0
1183End
1184
1185// function to either add or remove the cursors from the topmost graph, as needed
1186
1187Function UseCursorsWrapperProc(cba) : CheckBoxControl
1188        STRUCT WMCheckboxAction &cba
1189
1190
1191        switch( cba.eventCode )
1192                case 2: // mouse up
1193                        // check to make sure there really is a "topmost" graph         
1194                        String topGraph= WinName(0,1)   //this is the topmost graph
1195                        if(cmpstr(topGraph,"")==0)      //no graphs, uncheck and exit
1196                                CheckBox check_0,value=0
1197                                return(0)
1198                        endif
1199                               
1200                        String ciStr = CsrInfo(A , topGraph)
1201                       
1202                        ControlInfo/W=wrapperpanel popup_0
1203                        String folderStr=S_Value
1204                        String traceList = TraceNameList(topGraph, ";", 1 )             
1205               
1206                        Variable checked = cba.checked
1207                       
1208                        if(checked)
1209                                //print "add the cursors to the topmost graph, if the data set is there, or move them"
1210                                if(strlen(ciStr)==0 && strsearch(traceList, folderStr, 0) != -1 )               //no cursors && data is there
1211                                        ShowInfo
1212                                        Wave yw=$("root:"+folderStr+":"+folderStr+"_i")
1213                                        Cursor/P/W=$topGraph A, $(folderStr+"_i"),0
1214                                        Cursor/P/W=$topGraph/A=0 B, $(folderStr+"_i"),numpnts(yw)-1                     //deactivate the one at the high Q end
1215                                        DoUpdate
1216//                              else            //if (strlen(ciStr)!=0 && strsearch(traceList, folderStr, 0) != -1 ) //cursors present, but on wrong data
1217//                                      Wave yw=$("root:"+folderStr+":"+folderStr+"_i")
1218//                                      Cursor/P/W=$topGraph A, $(folderStr+"_i"),0                                                             //move the cursors
1219//                                      Cursor/P/W=$topGraph/A=0 B, $(folderStr+"_i"),numpnts(yw)-1
1220//                                      DoUpdate
1221                                endif
1222                       
1223                        else
1224                                //print "unchecked, remove the cursors"
1225                                // go back to the full matrix for the resolution calculation (not if SANS data...)
1226                                if(waveExists($("root:"+folderStr+":weights_save")))
1227                                        Duplicate/O $("root:"+folderStr+":weights_save"), $("root:"+folderStr+":"+folderStr+"_res")
1228                                endif
1229                                HideInfo
1230                                Cursor/K A
1231                                Cursor/K B
1232                        endif
1233                        break
1234        endswitch
1235
1236        return 0
1237End
1238
1239// returns 1 if the specified data is on the top graph && has cursors on it
1240// returns 0 and unchecks the box if anything is wrong
1241//
1242// only call this function if the cursor box is checked, to uncheck it as needed
1243// if the box is unchecked, leave it be.
1244//
1245Function AreCursorsCorrect(folderStr)
1246        String folderStr
1247       
1248        String topGraph= WinName(0,1)   //this is the topmost graph
1249        if(cmpstr(topGraph,"")==0)      //no graphs, uncheck and exit
1250                CheckBox check_0,win=wrapperpanel,value=0
1251                return(0)
1252        endif
1253               
1254        String traceAisOn = CsrWave(A , "", 0)
1255        if(     strsearch(traceAisOn, folderStr, 0) == -1)              //data and cursors don't match
1256                CheckBox check_0,win=wrapperpanel,value=0
1257                return(0)
1258        endif
1259       
1260        return(1)
1261End
Note: See TracBrowser for help on using the repository browser.