source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Auto_Fit.ipf @ 838

Last change on this file since 838 was 828, checked in by srkline, 11 years ago

adding some loaders to the macros menu - strictly for testing so that some of the newest procedures can be easily tested.

File size: 56.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3
4// This was originally written 2001-2003 ish. This works very differently than SANSview, and I havne't
5// mentioned that this exists, so that their ideas will be new. Still, some of this may be
6// serviceable for use within the Igor package, with some cleanup of the interface and functionality.
7//
8//
9//
10// to do - July 2010
11//
12// X- smeared models don't work at all (now they work)
13// -- the report is good, but the parsing is not great - the format
14//      could be more convenient to read back in to a table (text col, num cols (matrix that can be plotted?)
15//      -- Maybe the report could be compiled as waves. Then they would be numeric. Nothing to plot them against
16//                      other than file names, but with a table of values and names, one could manually enter a meaningful
17//                      column of values to plot against.
18// -- Make_HoldConstraintEps_Waves() is  currently disabled, both on the macros menu and the checkbox on the panel
19//                      Constraints and holds are part of the matrix already, soo this would only be for epsilon
20// -- Many of the items on the Macros menu are just junk.
21//
22// -- Comprehensive instructions (after features are finalized)
23//
24// -- savePath seems to be obsolete. Report saving is sent to the procedure defined in Wrapper.ipf, and uses the home path
25//
26
27
28Menu "Macros"
29        SubMenu "Auto-Fit"
30                "InitializeAutoFitPanel"
31                "-"
32                "Generate_Data_Checklist"
33//              "Make_HoldConstraintEps_Waves"          //this is currently disabled
34                "-"
35                "CompileAndLoadReports"
36                "LoadCompiledReports"
37                "Compile_GlobalFit_Reports"
38                "-"
39                "PrintOpenNotebooks"
40                "Close Open Notebooks"
41                "-"
42                "Generate_PICTS_list"
43                "Layout_PICTS"
44               
45        End
46End
47
48
49//***********
50//Automatic fitting routines for SANS or NSE data
51//requires model functions and their associated files
52//
53//**************
54
55
56
57//path to the data
58// ? have this automatically do the listing?
59Function PDPButton(ctrlName) : ButtonControl
60        String ctrlName
61       
62        //set the global string to the selected pathname
63        NewPath/O/M="pick the data folder" dataPath
64        PathInfo/S dataPath
65        Return(0)
66End
67
68Function SavePathButtonProc(ctrlName) : ButtonControl
69        String ctrlName
70
71        //set the global string to the selected pathname
72        NewPath/O/M="pick the save folder" savePath
73        PathInfo/S savePath
74        Return(0)
75End
76
77//
78// this re-sizes AND re-initializes the guessMatrix
79// and is only done when the files are re-listed, using the list button - since the
80// new list will screw up the correspondence with the guess matrix
81//
82Function FileListButtonProc(ctrlName) : ButtonControl
83        String ctrlName
84
85        DoAlert 1,"This will re-initialize the file list and ALL of the entries in the guess matrix. Do you want to proceed?"
86        if(V_flag!=1)           //if the answer is not yes, get out
87                return(0)
88        endif
89       
90        String fileList=""
91        fileList = IndexedFile(dataPath,-1,"????")
92        fileList = RemoveFromList(".DS_Store", fileList, ";",0)
93        List2TextWave(Filelist,";","root:AutoFit:fileListWave")
94        Wave/T lw = $"root:AutoFit:fileListWave"
95        Redimension/N=(-1,2) lw
96        lw[][1] = ""
97        Variable num = DimSize(lw,0)
98       
99        Wave sw = $"root:AutoFit:fileSelWave"
100        Redimension/B/N=(num,2) sw
101        sw[][1] = (sw[p][1] == 0) ? 2^5 : sw[p][1]              //if the element is zero, make it 32, otherwise leave it alone
102       
103        // force a re-size (and re-initialization) of the guess-hold-constr-range matrices
104        ToMatrixButtonProc("")
105       
106        return(0)
107End
108
109//
110// this re-sizes AND re-initializes the guessMatrix
111// and is only done when the files are re-listed, using the list button - since the
112// new list will screw up the correspondence with the guess matrix
113//
114Function ToMatrixButtonProc(ctrlName) : ButtonControl
115        String ctrlName
116       
117        SetDataFolder root:AutoFit
118        WAVE sel = fileSelWave
119        NVAR numPar=numPar
120        Variable jj,numSelFiles=0
121       
122        //update the number of steps for the progress bar
123        // commented out - SRK - 28MAR05
124//      NVAR cur=curProgress
125//      NVAR totSteps=endProgress
126//      cur=0
127//      totSteps=numSelFiles*3          //3 fits per file
128//      ValDisplay progressValdisp,limits={0,totSteps,0}
129//      ControlUpdate/W=AutoFitPanel progressValdisp
130       
131        //redimension the matrices and lists
132        Redimension/N=(numPar,DimSize(sel,0)) guessMatrix,HoldMatrix,constrMatrix,rangeMatrix
133        Redimension/N=(numPar) guessList,holdList,constrList,rangeList,guessSel,holdSel,constrSel,rangeSel
134       
135        //Set the matrices to zero
136        WAVE/T aa = guessMatrix
137        WAVE/T bb = holdMatrix
138        WAVE/T cc = constrMatrix
139        WAVE/T rr = rangeMatrix
140        aa="1"
141        bb="0"
142        cc=""           //set to no constraints
143        rr="0"          // zero in points 0 and 1 force a fit of all of the data (default)
144        //set the Lists to "0"
145        WAVE/T dd=guessList
146        WAVE/T ee=holdList
147        WAVE/T ff=constrList
148        WAVE/T rrl=rangeList
149        dd="0"
150        ee="0"
151        ff="0"
152        rrl="0"
153        //Set the sel waves to 2 (editable)
154        WAVE gg=guessSel
155        WAVE hh=holdSel
156        WAVE ii=constrSel
157        WAVE rrs=rangeSel
158        gg=2
159        hh=2
160        ii=2
161        rrs=2
162       
163        SetDataFolder root:
164       
165        DisplayGuess()
166        tabProc("",0)           //force the Guess tab to top
167        TabControl tabC,value=0
168       
169        return(0)
170End
171
172
173//updates the lists (text waves) to display, depending on the current highlighted file
174Function DisplayGuess()
175       
176        //find the selected data file -[][0] is the file, not the checkbox
177        Variable row
178        row = FindSelectedRowInLB(0)    // send 0 to look at the column with filenames
179
180        //update the text waves based on the values in the matrix
181        WAVE/T gm = root:AutoFit:guessMatrix
182        WAVE/T gl = root:AutoFit:guessList
183       
184        // the hold matrix
185        WAVE/T hm=root:AutoFit:holdMatrix
186        WAVE/T hl=root:AutoFit:holdList
187       
188        // the constraint matrix
189        WAVE/T cm=root:AutoFit:constrMatrix
190        WAVE/T cl=root:AutoFit:constrList
191       
192        // the range matrix
193        WAVE/T rm=root:AutoFit:rangeMatrix
194        WAVE/T rl=root:AutoFit:rangeList
195       
196        WAVE sel = root:AutoFit:fileSelWave
197        if( (sel[row][1] & 0x10) == 16 ) //box is checked
198               
199                gl = gm[p][row]
200                hl = hm[p][row]
201                cl = cm[p][row]
202                rl = rm[p][row]
203        else
204                //file is not checked, don't display guess
205                gl = "Not checked"
206                hl = "Not checked"
207                cl = "Not checked"
208                rl = "Not checked"
209        endif
210       
211        return(0)
212End
213
214
215//column 0 is the filenames, 1 is the checkboxes
216//returns the row that is selected, -1 if not found
217Function  FindSelectedRowInLB(col)
218        Variable col
219       
220        WAVE sel = root:AutoFit:fileSelWave
221        Variable jj=0,row=-1
222        if(col==0)
223                do
224                        if( (sel[jj][0] & 0x01) == 1 )                  //returns 1 (bit 0) if selected, 0 otherwise   
225                                row=jj
226                                //print "Row = ",jj
227                                break
228                        endif
229                        jj+=1
230                while(jj<DimSize(sel,0))
231        else
232                do
233                        if( (sel[jj][1] & 0x01) == 1 )                  //the checkbox is selected, but not necessarily checked!
234                                row=jj
235                                //print "Row = ",jj
236                                break
237                        endif
238                        jj+=1
239                while(jj<DimSize(sel,0))
240        endif
241       
242        return(row)
243end
244
245
246Proc InitializeAutoFitPanel()
247        if (wintype("AutoFitPanel") == 0)
248                InitializeAutoFit()
249                AutoFitPanel()
250                tabProc("",0)           //force the tab control to display correctly
251        else
252                DoWindow/F AutoFitPanel
253        endif
254//      RangeCheckProc("",1)            //check the box to use all of the data
255End
256
257Function InitializeAutoFit()
258        //set up all of the globals for the lists, globals, etc...
259        NewDataFolder/O/S root:AutoFit
260        Make/O/T/N=(1,2) fileListWave           //list boxes need text waves
261        Make/O/B/N=(1,2) fileSelWave            //for the checkboxes
262        Make/O/T/N=1 guessList,holdList,ConstrList,rangeList            //list boxes need text waves
263        Make/O/T/N=(1,1) guessMatrix,holdMatrix,rangeMatrix                     //guesses, etc... need real values (later)
264        Make/O/T/N=(1,1) constrMatrix                                   //constraint matrix is text
265        Make/O/B/N=1 guessSel,holdSel,ConstrSel,rangeSel                                                //SelWave is byte data
266        Variable/G numPar=5,ptLow=0,ptHigh=0,fitTol=1e-3,curProgress=0,endProgress=10
267        Variable/G startTicks=0
268       
269        String/G gStatFormat="\K(65535,0,0)\f01"
270        String/G gStatus=gStatFormat+"the fit engine is currently idle"
271        string/g gExt="ABC"
272       
273        fileListWave = ""
274       
275        //make the second column of the file sel wave a checkbox (set bit 5)
276        fileSelWave[][1] = 2^5
277       
278        SetDataFolder root:
279End
280
281Window AutoFitPanel()
282        PauseUpdate; Silent 1           // building window...
283        NewPanel /W=(685,44,1001,740) /K=1
284        DoWindow/C AutoFitPanel
285        SetDrawLayer UserBack
286//      DrawText 11,418,"Point Range"
287//      DrawText 5,167,"Suffix"
288        DrawLine 8,362,287,362
289        PopupMenu popup0,pos={2,2},size={175,20},title="pick a function"
290        PopupMenu popup0,mode=1,value= #"User_FunctionPopupList()",proc=AF_FuncPopupProc
291               
292        ListBox lb pos={11,90},size={280,230},proc=FileListboxProc
293        ListBox lb listWave=root:AutoFit:fileListWave,selWave=root:AutoFit:fileSelWave
294        ListBox lb editStyle=1,mode=5
295        ListBox lb userColumnResize=1,widths={200,80}
296       
297//      Button DelButton,pos={245,61},size={40,20},proc=DelButtonProc,title="Del",disable=2
298        Button PathButton,pos={6,61},size={50,20},proc=PDPButton,title="Path..."
299        Button FileListButton,pos={182,61},size={50,20},proc=FileListButtonProc,title="List"
300        ListBox guessBox,pos={24,398},size={139,208},disable=1,proc=UpdateGuessMatrixProc
301        ListBox guessBox,frame=2,listWave=root:AutoFit:guessList
302        ListBox guessBox,selWave=root:AutoFit:guessSel,mode= 2,selRow= 0
303        Button FillAllGuessButton,pos={196,406},size={50,20},disable=1,proc=FillAllGuessButtonProc,title="Fill All"
304        Button FillAllHoldButton,pos={196,406},size={50,20},disable=1,proc=FillAllHoldButtonProc,title="Fill All"
305        Button FillAllConstrButton,pos={196,406},size={50,20},proc=FillAllConstrButtonProc,title="Fill All"
306        Button FillAllRangeB,pos={196,406},size={50,20},disable=1,proc=FillAllRangeButtonProc,title="Fill All"
307        SetVariable NumParams,pos={7,31},size={161,15},proc=SetNumParamProc,title="Number of Parameters"
308        SetVariable NumParams,limits={2,Inf,0},value= root:AutoFit:numPar
309//      CheckBox typeCheck,pos={207,31},size={32,14},title="NSE Data?",value=0
310//      SetVariable fitTol,pos={80,208},size={80,15},title="Fit Tol"
311//      SetVariable fitTol,limits={0.0001,0.1,0},value= root:AutoFit:fitTol
312//      CheckBox epsilonCheck,pos={180,208},size={32,14},value=0,title="Use Epsilon Wave?"
313
314        TabControl tabC,pos={13,371},size={273,244},proc=tabProc,tabLabel(0)="Guess"
315        TabControl tabC,tabLabel(1)="Hold",tabLabel(2)="Constraint",tabLabel(3)="Range",value= 0
316//      CheckBox rangeCheck,pos={92,404},size={32,14},proc=RangeCheckProc,title="All"
317//      CheckBox rangeCheck,value= 1,disable=2
318        SetVariable lowPt,pos={136,404},size={60,15},title="low"
319        SetVariable lowPt,limits={0,Inf,0},value= root:AutoFit:ptLow,noedit=1,disable=1
320        SetVariable highPt,pos={201,404},size={60,15},title=" to "
321        SetVariable highPt,limits={0,Inf,0},value= root:AutoFit:ptHigh,noedit=1,disable=1
322        ListBox holdBox,pos={24,398},size={139,208},disable=1,proc=UpdateHoldMatrixProc
323        ListBox holdBox,frame=2,listWave=root:AutoFit:holdList
324        ListBox holdBox,selWave=root:AutoFit:holdSel,mode= 2,selRow= 2
325        ListBox ConstrBox,pos={24,398},size={170,208},proc=UpdateConstrMatrixProc
326        ListBox ConstrBox,frame=2,listWave=root:AutoFit:ConstrList
327        ListBox ConstrBox,selWave=root:AutoFit:ConstrSel,mode= 2,selRow= 2
328        ListBox RangeBox,pos={24,398},size={139,208},proc=UpdateRangeMatrixProc
329        ListBox RangeBox,frame=2,listWave=root:AutoFit:rangeList
330        ListBox RangeBox,selWave=root:AutoFit:RangeSel,mode= 2,selRow= 2
331//      Button MatrixButton,pos={12,205},size={60,20},proc=ToMatrixButtonProc,title="Matrix",disable=2
332        Button DoItButton,pos={21,632},size={80,20},proc=DoTheFitsButtonProc,title="Do the fits"
333        Button savePathButton,pos={82,61},size={80,20},proc=SavePathButtonProc,title="Save Path..."
334        TitleBox tb1,pos={139,634},size={128,12},anchor=MC,variable=root:AutoFit:gStatus,frame=0
335        Button button0,pos={14,331},size={40,20},title="Plot",proc=LoadForGuessProc
336//      SetVariable extStr,pos={4,170},size={40,15},title=" ",value= root:AutoFit:gExt
337       
338        Button GuessCoefB,pos={198,440},size={50,20},title="Guess",proc=UseCoefAsGuess
339        Button GuessHoldB,pos={198,440},size={50,20},title="Guess",disable=1,proc=UseHoldAsGuess
340        Button GuessConstrB,pos={198,440},size={50,20},title="Guess",disable=1,proc=UseConstraintsAsGuess
341       
342        ValDisplay progressValdisp,pos={113,663},size={161,7},title="00:00"
343        ValDisplay progressValdisp,limits={0,root:AutoFit:endProgress,0},barmisc={0,0},value= root:AutoFit:curProgress
344EndMacro
345
346
347Function AF_FuncPopupProc(pa) : PopupMenuControl
348        STRUCT WMPopupAction &pa
349
350        switch( pa.eventCode )
351                case 2: // mouse up
352                        Variable popNum = pa.popNum
353                        String popStr = pa.popStr
354                        String name=pa.ctrlName
355                        Variable num=0,nc
356                       
357                        String coefStr = getFunctionCoef(popStr)
358                        String str
359                       
360                        NVAR pts1 = root:AutoFit:numPar
361                        SVAR suff = root:AutoFit:gExt
362                       
363                        Wave/Z coef=$("root:"+coefStr)
364                        if(WaveExists(coef))
365                                num=numpnts(coef)
366                                suff = getModelSuffix(popStr)           //get the suffix from the unsmeared model function
367                        else
368                                //try getting rid of "Smeared" from the beginning of the function string
369                                nc = strlen(popStr)
370                                str = getFunctionCoef(popStr[7,nc-1])
371                                Wave/Z cw = $("root:"+str)
372                                if(WaveExists(cw))
373                                        num=numpnts(cw)
374                                endif
375                                suff = getModelSuffix(popStr[7,nc-1])           //get the suffix from the unsmeared model function
376                        endif
377                       
378                        // set the globals
379                        pts1 = num
380                       
381                       
382                       
383                        // set the size of the matrix of initial guesses
384                        SetNumParamProc("",num,"","")
385                       
386                        break
387        endswitch
388
389        return 0
390End
391
392
393Function tabProc(name,tab)
394        String name
395        Variable tab
396       
397        Button FillAllGuessButton disable= (tab!=0)
398        Button GuessCoefB disable=(tab!=0)
399        ListBox guessBox disable= (tab!=0)
400       
401        Button FillAllHoldButton disable= (tab!=1)
402        Button GuessHoldB disable=(tab!=1)
403        ListBox holdBox disable=(tab!=1)
404       
405        Button FillAllConstrButton disable= (tab!=2)
406        Button GuessConstrB disable=(tab!=2)
407        ListBox ConstrBox disable=(tab!=2)
408       
409        //no buttons on the range tab
410        ListBox RangeBox disable=(tab!=3)
411        Button FillAllRangeB disable= (tab!=3)
412       
413        return(0)
414End
415
416
417Function FillAllGuessButtonProc(ctrlName) : ButtonControl
418        String ctrlName
419
420        //fills all of the guesses with the "current" list of guesses
421        WAVE/T gl=root:AutoFit:guessList
422        WAVE/T gm=root:AutoFit:guessMatrix
423        gm[][] = gl[p]
424        return(0)
425End
426
427Function FillAllHoldButtonProc(ctrlName) : ButtonControl
428        String ctrlName
429
430        //fills all of the guesses with the "current" list of guesses
431        WAVE/T hl=root:AutoFit:holdList
432        WAVE/T hm=root:AutoFit:holdMatrix
433        hm[][] = hl[p]
434        return(0)
435End
436
437Function FillAllConstrButtonProc(ctrlName) : ButtonControl
438        String ctrlName
439
440        //fills all of the guesses with the "current" list of guesses
441        WAVE/T cl=root:AutoFit:constrList
442        WAVE/T cm=root:AutoFit:ConstrMatrix
443        cm[][] = cl[p]
444        return(0)
445End
446
447Function FillAllRangeButtonProc(ctrlName) : ButtonControl
448        String ctrlName
449
450        //fills all of the range values with the top values
451        WAVE/T rl=root:AutoFit:rangeList
452        WAVE/T rm=root:AutoFit:rangeMatrix
453        rm[][] = rl[p]
454        return(0)
455End
456
457Function SetNumParamProc(ctrlName,varNum,varStr,varName) : SetVariableControl
458        String ctrlName
459        Variable varNum
460        String varStr
461        String varName
462
463        //set the number of parameters for the function
464        Variable/G numPar=varNum
465       
466        // adjust the number of parameters in the guesses
467        SetMatrixRows(varNum)
468       
469        return(0)
470End
471
472//expand or collapse the matrices to the number of parameters
473Function SetMatrixRows(newRows)
474        Variable newRows
475       
476        SetDataFolder root:AutoFit
477       
478        WAVE/T aa = guessMatrix
479        WAVE/T bb = holdMatrix
480        WAVE/T cc = constrMatrix
481        WAVE/T rr = rangeMatrix
482       
483        Redimension/N=(newRows,-1) aa,bb,cc,rr
484       
485        //redimension the lists too
486        WAVE/T dd=guessList
487        WAVE/T ee=holdList
488        WAVE/T ff=constrList
489        WAVE/T rrl=rangeList
490        Redimension/N=(newRows) dd,ee,ff,rrl
491       
492        WAVE gg=guessSel
493        WAVE hh=holdSel
494        WAVE ii=constrSel
495        WAVE rrs=rangeSel
496        //set the selection wave for the individual lists to 2 == editable
497        Redimension/N=(newRows) gg,hh,ii,rrs
498        gg=2
499        hh=2
500        ii=2
501        rrs=2
502       
503        SetDataFolder root:
504       
505        return 0
506end
507
508
509Function FileListboxProc(ctrlName,row,col,event)
510        String ctrlName     // name of this control
511        Variable row        // row if click in interior, -1 if click in title
512        Variable col        // column number
513        Variable event      // event code
514       
515        if(event==4 && col==0)          //selection of a file, not a checkbox
516                //then update the listbox display of guesses for the new file
517        //      Print "file selected"
518                DisplayGuess()
519        Endif
520       
521        return 0            // other return values reserved
522End
523
524Function UpdateGuessMatrixProc(ctrlName,row,col,event)
525        String ctrlName     // name of this control
526        Variable row        // row if click in interior, -1 if click in title
527        Variable col        // column number
528        Variable event      // event code
529       
530        if(event==7)            //finished edit of a cell, update the matrix of guesses
531                //Print "updating"
532                WAVE/T gl=root:AutoFit:guessList
533                WAVE/T gm=root:AutoFit:guessMatrix
534                //put new value in guessMatrix
535                Variable datafile
536                datafile = FindSelectedRowInLB(0)               //selected row in file list
537                gm[row][datafile] = gl[row]
538                //print "row= ",row
539        Endif
540        return 0            // other return values reserved
541End
542
543Function UpdateHoldMatrixProc(ctrlName,row,col,event)
544        String ctrlName     // name of this control
545        Variable row        // row if click in interior, -1 if click in title
546        Variable col        // column number
547        Variable event      // event code
548       
549        if(event==7)            //finished edit of a cell, update the matrix of guesses
550                //Print "updating"     
551                WAVE/T hl=root:AutoFit:holdList
552                WAVE/T hm=root:AutoFit:holdMatrix
553                // put new value in holdMatrix
554                Variable datafile
555                datafile = FindSelectedRowInLB(0)
556                hm[row][datafile] = hl[row]
557                //print "row= ",row
558        Endif
559        return 0            // other return values reserved
560End
561
562Function UpdateConstrMatrixProc(ctrlName,row,col,event)
563        String ctrlName     // name of this control
564        Variable row        // row if click in interior, -1 if click in title
565        Variable col        // column number
566        Variable event      // event code
567       
568        if(event==7)            //finished edit of a cell, update the matrix of guesses
569                //Print "updating"
570                WAVE/T cl=root:AutoFit:ConstrList
571                WAVE/T cm=root:AutoFit:constrMatrix
572                //put new value in constrMatrix
573                Variable datafile
574                datafile = FindSelectedRowInLB(0)
575                cm[row][datafile] = cl[row]
576                //print "row= ",row
577        Endif
578        return 0            // other return values reserved
579End
580
581Function UpdateRangeMatrixProc(ctrlName,row,col,event)
582        String ctrlName     // name of this control
583        Variable row        // row if click in interior, -1 if click in title
584        Variable col        // column number
585        Variable event      // event code
586       
587        if(event==7)            //finished edit of a cell, update the matrix of guesses
588                //Print "updating"
589                WAVE/T cl=root:AutoFit:RangeList
590                WAVE/T cm=root:AutoFit:RangeMatrix
591                //put new value in constrMatrix
592                Variable datafile
593                datafile = FindSelectedRowInLB(0)
594                cm[row][datafile] = cl[row]
595                //print "row= ",row
596        Endif
597        return 0            // other return values reserved
598End
599
600//returns the total number of files checked
601Function numChecked()
602       
603        WAVE sel = root:AutoFit:fileSelWave
604       
605        Variable ii,num=0
606        for(ii=0;ii<DimSize(sel,0);ii+=1)
607                if( (sel[ii][1] & 0x10) == 16 )
608                        num += 1
609                endif
610        endfor
611        return num
612       
613End
614
615
616//Function RangeCheckProc(ctrlName,checked) : CheckBoxControl
617//      String ctrlName
618//      Variable checked
619//     
620//      SetVariable lowPt disable=(checked)
621//      SetVariable highPt disable=(checked)
622//End
623
624Function DoTheFitsButtonProc(ctrlName) : ButtonControl
625        String ctrlName
626
627        //read the values from the panel
628        ControlInfo/W=AutoFitPanel popup0
629        String funcStr=S_Value
630        String fileName
631        NVAR numPar=root:AutoFit:numPar
632        NVAR startTicks=root:AutoFit:startTicks
633        NVAR curProgress=root:AutoFit:curProgress
634        NVAR endProgress=root:AutoFit:endProgress
635       
636        WAVE/T fileWave=root:AutoFit:fileListWave
637        WAVE sel = root:AutoFit:fileSelWave
638       
639        WAVE/T guessMatrix=root:AutoFit:guessMatrix
640        WAVE/T holdMatrix=root:AutoFit:holdMatrix
641        WAVE/T constrMatrix=root:AutoFit:constrMatrix
642        WAVE/T rangeMatrix=root:AutoFit:rangeMatrix
643               
644        Variable ii=0,numFiles=DimSize(fileWave,0),t1=ticks,t2,matrixindex,count=0
645        //print numFiles
646        //for the timer-progress bar - timer shows time, bar shows number of fits remaining
647        curProgress = 0
648        endProgress = 3*numChecked()                    //3 fits per file that is fit
649        ValDisplay progressValdisp,limits={0,endProgress,0}
650        ControlUpdate/W=AutoFitPanel progressValdisp
651       
652        //print "numChecked() = ",numChecked()
653        startTicks=t1                   //starting now
654        for(ii=0;ii<numFiles;ii+=1)             //loop over everything in the file list, dispatching only checked items
655                if( (sel[ii][1] & 0x10) == 16 )         //the box is checked, then go fit it
656                        fileName = fileWave[ii][0]
657                        DoOneFit(funcStr,fileName,numPar,fileWave,ii,guessMatrix,holdMatrix,constrMatrix,rangeMatrix)
658                        count+=1
659                endif
660        endfor
661        UpdateStatusString("All files processed")
662        t2=ticks
663        t1=(t2-t1)/60
664        Printf "All %d files processed in %g seconds =(%g minutes) =(%g hours)\r",count,t1,t1/60,t1/60/60
665        return(0)
666End
667
668
669Function DoOneFit(funcStr,fileName,numPar,fileWave,ii,guessMatrix,holdMatrix,constrMatrix,rangeMatrix)
670        String funcStr,fileName
671        Variable numPar
672        WAVE/T fileWave //length <= ii
673        Variable ii             //index in the full list
674        WAVE/T guessMatrix,holdMatrix,constrMatrix,rangeMatrix
675       
676        String list="",fullName="",dataname="",str=""
677        //be sure all is clear (no data, window... etc)
678        DoWindow/K AutoGraph                            //no error is reported
679        DoWindow/K AutoGraph_NSE                               
680        list=WaveList("*__*",";","")            //not case sensitive?
681        DoKillList(list)                                                //get rid of all of the old data
682        list=WaveList("wave*",";","")           //"wave(n)" can be generated if not all NSE times are collected
683        DoKillList(list)
684       
685        //SANS or NSE data?
686        ControlInfo/W=AutoFitPanel typeCheck
687        Variable isNSE=v_value
688        //load in the data
689        PathInfo dataPath
690        fullName = S_path
691        //fullName += fileWave[ii]
692        fullName += fileName
693        if(isNSE)
694                //load, don't plot
695                str = "A_LoadNSEDataWithName(\""+fullName+"\",0)"
696                Execute str
697//              A_LoadNSEDataWithName(fullName,0)                               //load, don't plot
698        else
699                //load, default name, no plot, overwrite data if needed
700                str = "A_LoadOneDDataToName(\""+fullName+"\",\"\",0,1)"
701                Execute str
702//              A_LoadOneDDataToName(fullName,"",0,1)           //load, default name, no plot, overwrite data if needed
703        endif
704        dataName=GetFileNameFromPathNoSemi(fullName)
705        dataname=CleanupName(dataname,0)
706       
707        //graph it - creates window named "AutoGraph"
708        if(isNSE)
709                Execute "DoGraph_NSE(\""+dataname+"\")"
710        else
711                Execute "DoGraph(\""+dataname+"\")"
712        endif
713       
714        //generate the needed strings to add to the execute stmt
715        // rangeStr, guessStr,constrStr,holdStr
716        // and waves - the coefficient wave and paramter wave
717        Variable useRes,useEps,useCursors,useConstr
718        Variable val,pt1,pt2
719        useEps = 0
720        useConstr = 0
721        useCursors = 0
722        useRes = 0
723       
724        String holdStr="",rangeStr="",cStr="",epsilonStr=""
725        String DF="root:"+dataname+":" 
726
727       
728        Make/O/D/N=(numPar) myCoef              //always named "myCoef"
729        Wave cw = root:myCoef
730
731        //range string
732        useCursors = ParseRangeString(ii,dataname,rangeMatrix,pt1,pt2)          //read range from the matrix, return values and set flag
733
734       
735        //params to hold
736        holdStr = ParseHoldString(ii,numpar,holdMatrix)
737        //initial guesses
738        ParseGuessString(ii,numpar,guessMatrix,"myCoef")
739        //constraints
740        cStr = ParseConstraints(ii,numpar,constrMatrix,"myConstraints")
741        WAVE/Z constr = $"myConstraints"
742        if(strlen(cStr)!=0)
743                useConstr = 1
744        endif
745        //epsilon wave
746        epsilonStr = GetEpsilonWave()
747       
748        //fit it
749        //these two global variables must be created for IGOR to set them, so that
750        //any errors in the fitting can be diagnosed
751        Variable/G V_FitError=0                         //0=no err, 1=error,(2^1+2^0)=3=singular matrix
752        Variable/G V_FitQuitReason=0            //0=ok,1=maxiter,2=user stop,3=no chisq decrease
753        NVAR tol=root:AutoFit:fitTol
754        Variable/G V_FitTol=tol         //default is 0.0001
755        Variable/G V_fitOptions=4               //suppress the dialog during fitting (we're not waiting for OK, anyways)
756
757
758        Wave yw = $(DF+dataName+"_i")
759        Wave xw = $(DF+dataName+"_q")
760        Wave sw = $(DF+dataName+"_s")
761       
762        if(stringmatch(funcStr, "Smear*"))              // if it's a smeared function, need a struct
763                useRes=1
764        endif
765       
766        Struct ResSmearAAOStruct fs
767        WAVE/Z resW = $(DF+dataName+"_res")                     //these may not exist, if 3-column data is used
768        WAVE/Z fs.resW =  resW
769        WAVE yw=$(DF+dataName+"_i")
770        WAVE xw=$(DF+dataName+"_q")
771        WAVE sw=$(DF+dataName+"_s")
772        Wave fs.coefW = cw
773        Wave fs.yW = yw
774        Wave fs.xW = xw
775       
776        Duplicate/O yw $(DF+"FitYw")
777        WAVE fitYw = $(DF+"FitYw")
778        fitYw = NaN
779       
780        NVAR useGenCurveFit = root:Packages:NIST:gUseGenCurveFit
781        ///// SEE FitWrapper() for more details.
782       
783        Variable nPass = 1
784       
785        do      // outer do is the loop over passes
786        do      // this inner loop is abig switch to select the correct FutFunc to dispatch
787                if(useGenCurveFit)
788#if !(exists("GenCurveFit"))
789                        // XOP not available
790                        useGenCurveFit = 0
791                        Abort "Genetic Optimiztion XOP not available. Reverting to normal optimization."       
792#endif
793                        //send everything to a function, to reduce the clutter
794                        // useEps and useConstr are not needed
795                        // pass the structure to get the current waves, including the trimmed USANS matrix
796                        Variable chi,pt
797
798                        chi = DoGenCurveFit(useRes,useCursors,sw,fitYw,fs,funcStr,ParseHoldString(ii,numpar,holdMatrix),val,lolim,hilim,pt1,pt2)
799                        pt = val
800
801                        break
802                       
803                endif
804               
805               
806                if(useRes && useEps && useCursors && useConstr)         //do it all
807                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs
808                        break
809                endif
810               
811                if(useRes && useEps && useCursors)              //no constr
812                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
813                        break
814                endif
815               
816                if(useRes && useEps && useConstr)               //no crsr
817                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs
818                        break
819                endif
820               
821                if(useRes && useCursors && useConstr)           //no eps
822                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs
823                        break
824                endif
825               
826                if(useRes && useCursors)                //no eps, no constr
827                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
828                        break
829                endif
830               
831                if(useRes && useEps)            //no crsr, no constr
832                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
833                        break
834                endif
835       
836                if(useRes && useConstr)         //no crsr, no eps
837                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs
838                        break
839                endif
840               
841                if(useRes)              //just res
842                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
843                        break
844                endif
845               
846/////   same as above, but all without useRes (no /STRC flag)
847                if(useEps && useCursors && useConstr)           //do it all
848                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr
849                        break
850                endif
851               
852                if(useEps && useCursors)                //no constr
853                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw
854                        break
855                endif
856               
857                if(useEps && useConstr)         //no crsr
858                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr
859                        break
860                endif
861               
862                if(useCursors && useConstr)             //no eps
863                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /C=constr
864                        break
865                endif
866               
867                if(useCursors)          //no eps, no constr
868                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw
869                        break
870                endif
871               
872                if(useEps)              //no crsr, no constr
873                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw
874                        break
875                endif
876       
877                if(useConstr)           //no crsr, no eps
878                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr
879                        break
880                endif
881               
882                //just a plain vanilla fit
883                FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw
884       
885        while(0)                //always exit the inner do to select the FutFunc syntax. The break will exit this loop
886       
887                if(nPass == 1)
888                        UpdateStatusString(dataname +" Fit #1")
889                        Variable/G gChiSq1 = V_chisq
890                endif
891               
892                if(nPass == 2)
893                        UpdateStatusString(dataname +" Fit #2")
894                        Variable/G gChiSq2 = V_chisq
895                endif
896               
897                if(nPass == 3)
898                        UpdateStatusString(dataname +" Fit #3")
899                endif
900               
901                nPass += 1
902        while(nPass < 4)
903
904        // append the fit
905        // need to manage duplicate copies
906        // Don't plot the full curve if cursors were used (set fitYw to NaN on entry...)
907        String traces=TraceNameList("", ";", 1 )                //"" as first parameter == look on the target graph
908        if(strsearch(traces,"FitYw",0) == -1)
909                if(useGenCurveFit && useCursors)
910                        WAVE trimX = trimX
911                        AppendtoGraph fitYw vs trimX
912                else
913                        AppendToGraph FitYw vs xw
914                endif
915        else
916                RemoveFromGraph FitYw
917                if(useGenCurveFit && useCursors)
918                        WAVE trimX = trimX
919                        AppendtoGraph fitYw vs trimX
920                else
921                        AppendToGraph FitYw vs xw
922                endif
923        endif
924        ModifyGraph lsize(FitYw)=2,rgb(FitYw)=(52428,1,1)
925
926
927        //do the report calling the function, not the proc
928        String topGraph= WinName(0,1)   //this is the topmost graph
929        SVAR suffix = root:AutoFit:gExt         //don't try to read as getModelSuffix(funcStr), since the smeared() may not be plotted
930        String parStr=GetWavesDataFolder(cw,1)+ WaveList("*param*"+"_"+suffix, "", "TEXT:1," )          // this is *hopefully* one wave
931
932        if(isNSE)
933                GenerateReport_NSE(funcStr,dataname,"par","myCoef",1)
934        else
935                W_GenerateReport(funcStr,dataname,$parStr,$"myCoef",1,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph)
936
937//              AutoFit_GenerateReport(funcStr,dataname,"par","myCoef",1)       
938        endif
939       
940        return(0)
941End
942
943//// to be able to simply fill in the pt range of the yw[lo,hi]
944//Function LowRange()
945//      NVAR val = root:AutoFit:ptLow
946//      return(val)
947//End
948//
949//Function HighRange()
950//      NVAR val = root:AutoFit:ptHigh
951//      return(val)
952//End
953
954//updates the status string, forcing a redraw twice, to overcome what seems to be a bug in Igor4
955//also updates the progress bar and the countdown
956Function UpdateStatusString(newStr)
957        String newStr
958       
959        SVAR gStatus=root:AutoFit:gStatus
960        SVAR gStatFormat=root:AutoFit:gStatFormat
961        gStatus=""
962        ControlUpdate/W=AutoFitPanel tb1                //clears the line
963        gStatus=gStatFormat+newStr
964        ControlUpdate/W=AutoFitPanel tb1
965       
966        //update the progress bar and timer
967        NVAR cur=root:AutoFit:curProgress
968        NVAR endProgress=root:AutoFit:endProgress
969        NVAR startTicks=root:AutoFit:startTicks
970        cur+=1
971       
972//      Print "****"
973//      Print "cur = ",cur
974       
975        Variable t2=ticks,projTot,projRemain
976        String titleStr=""
977       
978        projTot = (t2-startTicks)/(cur-1)*endProgress
979        projRemain = projTot - (t2-startTicks)
980        projRemain /= 60.15             //to seconds
981        DoWindow/F AutoFitPanel
982        ValDisplay progressValdisp,title=Secs2time(projRemain,5)
983        ControlUpdate/W=AutoFitPanel progressValdisp
984       
985//      Print "End Progress = ",endProgress
986//      Print "ProjTot = ",projTot/60.15
987//      Print "ProjRemain = ",projRemain
988       
989        return(0)
990End
991
992// returns a string with the name of the epsilon wave, or null if it doesn't exist
993Function/S GetEpsilonWave()
994       
995        String retStr="",testStr
996        SVAR extStr = root:AutoFit:gExt
997        //do you want to use epsilon wave?
998        ControlInfo/W=AutoFitPanel epsilonCheck
999        if(V_Value == 0)                //not checked
1000                return(retStr)
1001        endif
1002       
1003        testStr = "Epsilon_"+extStr
1004        if(waveexists($testStr) != 0)
1005                return(" /E="+testStr)
1006        endif
1007        return(retStr)
1008End
1009
1010//returns the y data to fit - "_i" suffix, and range if selected
1011// enter the range as the first element[0] as low point, second element[1] as high point
1012// leave the other elements blank
1013//
1014// if either point value is not entered, the whole data set is used
1015//
1016// -- if both of the elements are between 0 and 1, assume they are q-values (check for fractional part)
1017// and find the appropriate points...
1018//
1019Function ParseRangeString(set,dataStr,rMat,lo,hi)
1020        Variable set
1021        String dataStr
1022        WAVE/T rMat
1023        Variable &lo,&hi
1024       
1025        Variable useCursors
1026                       
1027        lo = str2num(rMat[0][set])
1028        hi = str2num(rMat[1][set])
1029       
1030        if(lo == 0 && hi == 0)
1031                return(0)
1032        endif
1033       
1034        if(numtype(lo) != 0 || numtype(hi) != 0)                //not a normal number
1035                return(0)               //don't use cursor values, use all of the dataset
1036        endif
1037       
1038       
1039        if(lo>=hi) //error in specification, or all data desired (both zero or undefined)
1040                return(0)               //use all of the dataset
1041        endif
1042       
1043       
1044        if(trunc(lo) != lo || trunc(hi) != hi)          //values have fractional parts
1045                WAVE xW = $("root:"+dataStr+":"+dataStr + "_q")
1046                FindLevel/P/Q xW, lo
1047                lo = trunc(V_levelX)            //find the corresponding point values
1048                FindLevel/P/Q xW, hi
1049                hi = trunc(V_levelX)
1050        endif
1051       
1052        Variable/G root:AutoFit:ptLow = lo
1053        Variable/G root:AutoFit:ptHigh = hi
1054
1055        return(1)
1056End
1057
1058//returns the holdStr, i.e. "1010101"
1059Function/S ParseHoldString(set,npar,hMat)
1060        Variable set,npar
1061        WAVE/T hMat
1062       
1063        Variable ii
1064        String retStr=""
1065       
1066        for(ii=0;ii<npar;ii+=1)
1067                if(strlen(hMat[ii][set]) == 0)
1068                        retStr += "0"
1069                else
1070                        retStr += hMat[ii][set]
1071                endif
1072        endfor
1073
1074//      Print retStr
1075       
1076        return(retStr)
1077End
1078
1079//returns only error - wave must already exist
1080Function ParseGuessString(set,npar,gMat,outWStr)
1081        Variable set,npar
1082        WAVE/T gMat
1083        String outWStr
1084       
1085        Variable ii
1086        String retStr=outWStr
1087       
1088        WAVE outWave=$outWStr
1089        for(ii=0;ii<npar;ii+=1)
1090                outWave[ii] = str2num(gMat[ii][set])
1091        endfor
1092        return(0)
1093End
1094
1095//the constraint wave is created here
1096Function/S ParseConstraints(set,npar,cMat,outWStr)
1097        Variable set,npar
1098        WAVE/T cMat
1099        String outWStr
1100       
1101        String retStr="",loStr="",hiStr=""
1102        Variable ii=0,jj=0     
1103        Make/O/T/N=0 $outWStr
1104        WAVE/T cw = $outWStr   
1105        //return "/C="+outWStr if parsed ok, or null if not
1106
1107        String listStr=""
1108        for(ii=0;ii<npar;ii+=1)
1109                listStr=cMat[ii][set]
1110                loStr=StringFromList(0, listStr ,";")
1111                hiStr=StringFromList(1, listStr ,";")
1112                if(cmpstr(loStr,"")!=0) //something there...
1113                        InsertPoints jj,1,cw            //insert before element jj
1114                        cw[jj] = "K"+num2Str(ii)+">"+loStr
1115                        jj+=1
1116                endif
1117                if(cmpstr(hiStr,"")!=0) //something there...
1118                        InsertPoints jj,1,cw            //insert before element jj
1119                        cw[jj] = "K"+num2Str(ii)+"<"+hiStr
1120                        jj+=1
1121                endif
1122        endfor
1123        if(numpnts(cw) > 0 )
1124                retStr = "/C=" + outWStr
1125        Endif
1126//      print "strlen, conStr= ",strlen(retStr),retstr
1127
1128        return(retStr)  //null string will be returned if no constraints
1129End
1130
1131
1132//*************************
1133Proc DoGraph(dataname)
1134        String dataname
1135       
1136        SetDataFolder $dataname
1137
1138        PauseUpdate; Silent 1           // building window...
1139        Display /W=(5,42,301,313)/K=1 $(dataname+"_i") vs $(dataname+"_q")
1140        DoWindow/C AutoGraph
1141        ModifyGraph mode($(dataname+"_i"))=3
1142        ModifyGraph marker($(dataname+"_i"))=19
1143        ModifyGraph rgb($(dataname+"_i"))=(1,4,52428)
1144        ModifyGraph msize($(dataname+"_i"))=2
1145        ModifyGraph grid=1
1146        ModifyGraph log=1
1147        ModifyGraph tickUnit=1
1148        //
1149        ModifyGraph mirror=2
1150        //
1151        ErrorBars $(dataname+"_i") Y,wave=($(dataname+"_s"),$(dataname+"_s"))
1152//      Legend/A=LB
1153//      Legend/A=LB/X=0.00/Y=-32                //defaults to the top right
1154        Legend/A=MT/E           // /X=-16.16/Y=5.17/E
1155       
1156        SetDataFolder root:
1157       
1158EndMacro
1159
1160Proc DoGraph_NSE(dataname)
1161        String dataname
1162       
1163        SetDataFolder $dataname
1164
1165        PauseUpdate; Silent 1           // building window...
1166        Display /W=(5,42,301,313)/K=1 $(dataname+"_i") vs $(dataname+"_q")
1167        DoWindow/C AutoGraph_NSE
1168        ModifyGraph mode($(dataname+"_i"))=3
1169        ModifyGraph marker($(dataname+"_i"))=19
1170        ModifyGraph rgb($(dataname+"_i"))=(1,4,52428)
1171        ModifyGraph msize($(dataname+"_i"))=3
1172        ModifyGraph zColor($(dataname+"_i"))={$(dataname+"__Q"),$(dataname+"__Q")[0]*0.99,*,Rainbow}
1173        ModifyGraph grid=1
1174        ModifyGraph mirror=2
1175        ModifyGraph log(left)=1
1176        ErrorBars $(dataname+"_i") Y,wave=($(dataname+"_s"),$(dataname+"_s"))
1177        Legend/A=MB
1178        SetAxis/A/E=1 bottom
1179        ModifyGraph standoff=0
1180        SetAxis left 0.1,1
1181        //ModifyGraph tickUnit(left)=1
1182EndMacro
1183
1184//*************************
1185
1186
1187//**************************
1188// Generate the report
1189//**************************
1190
1191////must have AutoGraph as the name of the graph window (any size)
1192//// func is the name of the function (for print only)
1193////par and coef are the exact names of the waves
1194////yesSave==1 will save the file(name=func+time)
1195////
1196////
1197//// general report function from the wrapper is used instead
1198////    W_GenerateReport(funcStr,folderStr,$parStr,cw,yesSave,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph)
1199////
1200//Function AutoFit_GenerateReport(func,dataname,par,myCoef,yesSave)
1201//      String func,dataname,par,myCoef
1202//      Variable yesSave
1203//     
1204//      String str,pictStr="P_"
1205//      Wave sigWave=$"W_sigma"
1206//      Wave ans=$myCoef
1207////    Wave/T param=$par
1208//      SVAR ext=root:AutoFit:gExt
1209//      Wave/T param=$"parameters_"+ext
1210//     
1211//      NVAR V_chisq = V_chisq
1212//      NVAR V_npnts = V_npnts
1213//      NVAR V_FitError = V_FitError
1214//      NVAR V_FitQuitReason = V_FitQuitReason
1215//      NVAR chi1=gChiSq1
1216//      NVAR chi2=gChiSq2
1217//      NVAR V_startRow = V_startRow
1218//      NVAR V_endRow = V_endRow
1219//     
1220//      // bring report up
1221//      DoWindow/F Report
1222//      if (V_flag == 0)                // Report notebook doesn't exist ?
1223//              NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report"
1224//      endif
1225//     
1226//      // delete old stuff
1227//      Notebook Report selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile}
1228//     
1229//      // insert title
1230//      Notebook Report newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)}
1231//      sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time()
1232//      Notebook Report ruler=Title, text=str
1233//     
1234//      // insert fit results
1235//      Variable num=numpnts(ans),ii=0
1236//      Notebook Report ruler=Normal; Notebook Report  margins={18,18,504}, tabs={63 + 3*8192}
1237//      str = "Data file: " + dataname + "\r\r"
1238//      Notebook Report text=str
1239//      do
1240//              sprintf str, "%s = %g±%g\r", param[ii],ans[ii],sigwave[ii]
1241//              Notebook Report text=str
1242//              ii+=1
1243//      while(ii<num)
1244//     
1245//      //
1246//      Wave dataXw = $(dataname+"_q")
1247//      Variable nData=numpnts(dataXw)
1248//     
1249//      //
1250//      sprintf str,"chisq = %g , %g , %g\r",chi1,chi2,V_chisq
1251//      Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1252//      sprintf str,"Npnts = %g, sqrt(X^2/N) = %g\r",V_npnts,sqrt(V_chisq/V_npnts)
1253//      Notebook Report textRGB=(0,0,0),fstyle=0, text=str
1254//      sprintf str "Fitted range = [%d,%d] = %g < Q < %g\r",V_startRow,V_endRow,dataXw(V_startRow),dataXw(V_endRow)
1255//      Notebook Report textRGB=(0,0,0),fstyle=0, text=str
1256//      sprintf str,"V_FitError = %g\t\tV_FitQuitReason = %g\r",V_FitError,V_FitQuitReason
1257//      Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1258//      Notebook Report ruler=Normal
1259//     
1260//      // insert graphs
1261//      Notebook Report picture={AutoGraph(0, 0, 400, 300), 0, 1}, text="\r"
1262//     
1263//
1264//      //Notebook Report picture={Table1, 0, 0}, text="\r"
1265//     
1266//      // show the top of the report
1267//      Notebook Report  selection= {startOfFile, startOfFile},  findText={"", 1}
1268//     
1269//      //save the notebook
1270//      if(yesSave)
1271//              String nameStr=CleanupName(func,0)
1272//              nameStr = nameStr[0,8]  //shorten the name
1273//              nameStr += "_"+dataname
1274//              //make sure the name is no more than 31 characters
1275//              namestr = namestr[0,30]         //if shorter than 31, this will NOT pad to 31 characters
1276//              Print "file saved as ",nameStr
1277//              SaveNotebook /O/P=savePath/S=2 Report as nameStr
1278//              //save the graph separately as a PICT file, 2x screen
1279//              pictStr += nameStr
1280//              pictStr = pictStr[0,28]         //need a shorter name - why?
1281//              DoWindow/F AutoGraph
1282//              // E=-5 is png @screen resolution
1283//              // E=2 is PICT @2x screen resolution
1284//              SavePICT /E=2/O/I/P=savePath /W=(0,0,3,3) as pictStr
1285//      Endif
1286//     
1287//      // ???maybe print the notebook too?
1288//End
1289
1290
1291
1292//
1293//Proc DoGenerateReport(fname,dataname,param,coef,yesno)
1294//      String fname,dataname="",param,coef,yesno="No"
1295//      Prompt fname,"function name",popup,FunctionList("!Sme*",";","KIND:15,")
1296//      Prompt dataname,"name of the dataset"
1297//      Prompt param,"parameter names",popup,WaveList("par*",";","")
1298//      Prompt coef,"coefficient wave",popup,WaveList("coe*",";","")
1299//      Prompt yesno,"Save the report?",popup,"Yes;No;"
1300//     
1301//      //Print "fname = ",fname
1302//      //Print "param = ",param
1303//      //Print "coef = ",coef
1304//      //Print "yesno = ",yesno
1305//     
1306//      Variable doSave=0
1307//      if(cmpstr(yesno,"Yes")==0)
1308//              doSave=1
1309//      Endif
1310//      GenerateReport(fname,dataname,param,coef,dosave)
1311//     
1312//End
1313
1314
1315
1316//must have AutoGraph_NSE as the name of the graph window (any size)
1317// func is the name of the function (for print only)
1318//par and coef are the exact names of the waves
1319//yesSave==1 will save the file(name=func+time)
1320//
1321Function GenerateReport_NSE(func,dataname,par,coef,yesSave)
1322        String func,dataname,par,coef
1323        Variable yesSave
1324       
1325        String str
1326        Wave sigWave=$"W_sigma"
1327        Wave ans=$coef
1328        Wave/T param=$par
1329       
1330        NVAR V_chisq = V_chisq
1331        NVAR V_npnts = V_npnts
1332        NVAR V_FitError = V_FitError
1333        NVAR V_FitQuitReason = V_FitQuitReason
1334       
1335        // bring report up
1336        DoWindow/F Report
1337        if (V_flag == 0)                // Report notebook doesn't exist ?
1338                NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report"
1339        endif
1340       
1341        // delete old stuff
1342        Notebook Report selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile}
1343       
1344        // insert title
1345        Notebook Report newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)}
1346        sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time()
1347        Notebook Report ruler=Title, text=str
1348       
1349        // insert fit results
1350        Variable num=numpnts(ans),ii=0
1351        Notebook Report ruler=Normal; Notebook Report  margins={18,18,504}, tabs={63 + 3*8192}
1352        str = "Data file: " + dataname + "\r\r"
1353        Notebook Report text=str
1354        do
1355                sprintf str, "%s = %g±%g\r", param[ii],ans[ii],sigwave[ii]
1356                Notebook Report text=str
1357                ii+=1
1358        while(ii<num)
1359               
1360        sprintf str,"chisq = %g\r",V_chisq
1361        Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1362        sprintf str,"Npnts = %g\r",V_npnts
1363        Notebook Report textRGB=(0,0,0),fstyle=0, text=str
1364        sprintf str,"V_FitError = %g\rV_FitQuitReason = %g\r",V_FitError,V_FitQuitReason
1365        Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1366        Notebook Report ruler=Normal
1367       
1368        // insert graphs
1369        Notebook Report picture={AutoGraph_NSE(0, 0, 400, 300), 0, 1}, text="\r"
1370        //Notebook Report picture={Table1, 0, 0}, text="\r"
1371       
1372        // show the top of the report
1373        Notebook Report  selection= {startOfFile, startOfFile},  findText={"", 1}
1374       
1375        //save the notebook
1376        if(yesSave)
1377                String nameStr=CleanupName(func,0)
1378                nameStr = nameStr[0,8]  //shorten the name
1379                nameStr += "_"+dataname
1380                //make sure the name is no more than 31 characters
1381                namestr = namestr[0,30]         //if shorter than 31, this will NOT pad to 31 characters
1382                Print "file saved as ",nameStr
1383                SaveNotebook /O/P=savePath/S=2 Report as nameStr
1384        Endif
1385
1386        //save a pict file, just of the graph
1387        namestr = "PICT_" + namestr
1388        namestr = namestr[0,28]         //PICT names in IGOR must be shorter, to allow auto-naming?
1389        DoWindow/F AutoGraph_NSE
1390        SavePICT /E=2/O/I/P=savePath /W=(0,0,3,3) as nameStr
1391End
1392
1393
1394//*********************
1395//
1396//*********************
1397// List utilities
1398//*********************
1399//
1400// List2TextWave is also in SANS_Utilities.ipf, but to keep from having big lists of dependencies,
1401// have definitions here that are local and Static
1402
1403//
1404Static Function List2TextWave(list,sep,waveStr)
1405        String list,sep,waveStr
1406       
1407        Variable n= ItemsInList(list,sep)
1408        Make/O/T/N=(n) $waveStr= StringFromList(p,list,sep)
1409End
1410
1411Function List2NumWave(list,sep,waveStr)
1412        String list,sep,waveStr
1413       
1414        Variable n= ItemsInList(list,sep)
1415        Make/O/D/N=(n) $waveStr= str2num( StringFromList(p,list,sep) )
1416End
1417
1418Function/S TextWave2List(w,sep)
1419        Wave/T w
1420        String sep
1421       
1422        String newList=""
1423        Variable n=numpnts(w),ii=0
1424        do
1425                newList += w[ii] + sep
1426                ii+=1
1427        while(ii<n)
1428        return(newList)
1429End
1430
1431//for single precision numerical waves
1432Function/S NumWave2List(w,sep)
1433        Wave w
1434        String sep
1435       
1436        String newList="",temp=""
1437        Variable n=numpnts(w),ii=0,val
1438        do
1439                val=w[ii]
1440                temp=""
1441                sprintf temp,"%g",val
1442                newList += temp
1443                newList += sep
1444                ii+=1
1445        while(ii<n)
1446        return(newList)
1447End
1448
1449Function DoKillList(list)
1450        String list
1451       
1452        String item=""
1453        do
1454                item = StringFromList(0, list ,";" )
1455                KillWaves/Z $item
1456                list = RemoveFromList(item, list, ";")
1457        while(ItemsInList(list, ";")>0)
1458End
1459
1460//*********************
1461
1462
1463
1464//*******************
1465//Notebook Utils
1466//*******************
1467
1468Proc PrintOpenNotebooks()
1469
1470        String list=WinList("*", ";", "WIN:16")
1471        String item = ""
1472        do
1473                item=StringFromList(0,list,";")
1474                Print item
1475                PrintNotebook $item
1476                list = RemoveFromList(item, list, ";")
1477        while(ItemsInList(list, ";")>0)
1478End
1479
1480Proc CloseOpenNotebooks()
1481
1482        String list=WinList("*", ";", "WIN:16")
1483        String item = ""
1484        do
1485                item=StringFromList(0,list,";")
1486                DoWindow/K $item
1487                list = RemoveFromList(item, list, ";")
1488        while(ItemsInList(list, ";")>0)
1489End
1490
1491Proc Generate_PICTS_list()
1492        fGenerate_PICTS_list()
1493End
1494
1495//spits up a list of PICTS
1496Function fGenerate_PICTS_list()
1497
1498        String List=IndexedFile(savePath, -1, "PICT")
1499        List2TextWave(List,";","PICT_files")
1500        WAVE/T picts=$"PICT_files"
1501        Edit/K=1 picts
1502End
1503
1504Proc Layout_PICTS(pStr)
1505        String pStr=""
1506        Prompt pStr,"wave of PICTs to use",popup,WaveList("PICT_f*", ";", "")
1507               
1508        String List=TextWave2List($pStr,";")
1509        String item = ""
1510        //kill old picts
1511        KillPicts/A/Z
1512        //make a new layout
1513        Layout/C=1 as "PICT_Layout"
1514        DoWindow/C PICTLayout
1515        do
1516                item=StringFromList(0,List,";")
1517                //load each PICT, and append it to the layout
1518                Print "load item = ",item
1519                LoadPICT /O/Q/P=savePath item
1520                DoWindow/F PICTLayout           //be sure layout is on top
1521                AppendLayoutObject /F=1/W=PICTLayout picture  $item
1522                //AppendToLayout $item
1523                //Print item
1524                List = RemoveFromList(item, List, ";")
1525        while(ItemsInList(List, ";")>0)
1526        //tile the PICTs in the layout
1527        Tile/O=8
1528End
1529
1530//spit up a list of everything in the folder that is a text file
1531Proc Generate_Data_Checklist()
1532        fGenerate_Data_list()
1533End
1534Function fGenerate_Data_list()
1535
1536        String List=IndexedFile(dataPath, -1, "TEXT")
1537        List2TextWave(List,";","data_files")
1538        WAVE/T files=$"data_files"
1539        Duplicate/O/T files ModelToUse,Done
1540        ModelToUse = ""
1541        Done = ""
1542        Edit/K=1 files,ModelToUse,Done
1543End
1544
1545//***************
1546
1547// with all of the notebooks open for a given model (with N parameters)
1548// this will comile the reports, save the text notebook, then load it back in
1549// and put it in a table for easy printing
1550//
1551Proc CompileAndLoadReports()
1552        Compile_Reports()
1553        SaveNotebook /O/P=savePath/S=2 Compilation
1554//      Print "Saved as:  ",S_Path
1555        DoWindow/K Compilation
1556        LoadCompiledReports(S_Path)
1557End
1558
1559Proc LoadCompiledReports(str)
1560        String str
1561        LoadWave/J/D/W/E=1/K=0/V={"\t"," $",0,0} str
1562End
1563
1564Proc Compile_Reports(Number_of_Parameters)
1565        Variable Number_of_Parameters=7
1566        fCompile_Reports(Number_of_Parameters)
1567End
1568
1569Proc Compile_GlobalFit_Reports(WhichParameter,FileStr,ParamStr,ParamErrStr)
1570        Variable WhichParameter=7
1571        String FileStr="FileName_",ParamStr="par_",ParamErrStr="parErr_"
1572        fCompile_GlobalFit_Reports(WhichParameter,FileStr,ParamStr,ParamErrStr)
1573End
1574
1575////
1576Function fCompile_Reports(nPar)
1577        Variable nPar
1578       
1579        String list=WinList("*", ";", "WIN:16")
1580        String item = "",textStr="",newStr=""
1581        Variable sstop,dum,chi
1582       
1583        Variable ii
1584        NewNotebook/F=0 /N=Compilation as "Compilation"
1585        Notebook Compilation text="Variable Name \tValues\tErrors\r"
1586        do
1587                item=StringFromList(0,list,";")
1588                DoWindow/F $item
1589               
1590                Notebook $item selection={(2,0), (3,0)}         //paragraph 3 (starts from 0) = filename
1591                GetSelection notebook,$item,2
1592                textStr=S_Selection
1593                textStr=textStr[0,strlen(textStr)-2]            //remove CR
1594                textStr=textStr[10,strlen(textStr)-1]           //remove "DATA FILE:
1595                Notebook Compilation text="File:\t"+textStr+"\t"
1596                Notebook Compilation text=textStr+"_err\r"
1597               
1598//              printf "%s %s\r",textStr,textStr+"_err"
1599//
1600// results are written as:  "%s = \t%g\t±\t%g\r"
1601//
1602                for(ii=0;ii<nPar;ii+=1)         //gather the parameters
1603               
1604                        Notebook $item selection={(ii+4,0), (ii+5,0)}           //paragraph 5           = parameter 0
1605                        GetSelection notebook,$item,2
1606                        textStr=S_Selection
1607                        textStr=textStr[0,strlen(textStr)-2]
1608                        //textStr=textStr[13,strlen(textStr)-1]         // remove "parameter"
1609                        textStr = ReplaceString("=",textStr,"")
1610                        textStr = ReplaceString("±\t",textStr,"")
1611                        Notebook Compilation text=textStr+"\r"
1612                        //printf "%s\r",textStr
1613                        //Print strlen(textStr)
1614                endfor
1615                //get the chi-squared/N value
1616                ii+=1
1617                Notebook $item selection={(ii+4,0), (ii+5,0)}           //
1618                GetSelection notebook,$item,2
1619                textStr=S_Selection
1620                Print textStr
1621               
1622                sscanf textStr,"Npnts = %g\t\tSqrt(X^2/N) = %g\r",dum,chi
1623                sprintf textStr,"Sqrt(X^2/N)\t%s\t\r",num2str(chi)
1624                Notebook Compilation text=textStr
1625               
1626                Notebook Compilation text="\r"          //separate items
1627               
1628                list = RemoveFromList(item, list, ";")
1629        while(ItemsInList(list, ";")>0)
1630       
1631        DoWindow/F Compilation
1632        Notebook Compilation selection={startOfFile,startOfFile}
1633End
1634
1635////
1636Function fCompile_GlobalFit_Reports(nPar,Files,Param,Param_err)
1637        Variable nPar
1638        String Files,Param,Param_Err
1639       
1640        String list=SortList(WinList("*", ";", "WIN:16"))
1641        String item = "",textStr="",fileStr,funcStr,dumStr
1642        Variable sstop,dum,chi,nFiles,val1,val2
1643       
1644        Variable ii,jj
1645
1646        nFiles = ItemsInList(list)
1647        Make/O/D/N=(nFiles) $Param,$Param_err
1648        Make/O/T/N=(nFiles) $Files
1649        WAVE pw = $Param
1650        WAVE pw_err = $Param_err
1651        WAVE/T fw = $Files
1652       
1653        for(jj=0;jj<nFiles;jj+=1)
1654       
1655                item=StringFromList(jj,list,";")
1656                DoWindow/F $item
1657               
1658                Notebook $item selection={(6,0), (7,0)}         //paragraph 7 (starts from 0) = filename
1659                GetSelection notebook,$item,2
1660                textStr=S_Selection
1661                sscanf textStr,"Data Set:%s ; Function:%s\r",fileStr,funcStr
1662                fw[jj] = fileStr
1663//              Notebook Compilation text=fileStr+"\r"
1664//              Notebook Compilation text=funcStr+"\r"
1665               
1666               
1667//              printf "%s %s\r",textStr,textStr+"_err"
1668
1669                for(ii=nPar;ii<=nPar;ii+=1)             //gather the parameters
1670               
1671                        Notebook $item selection={(ii+7,0), (ii+8,0)}           //paragraph 8           = parameter 0
1672                        GetSelection notebook,$item,2
1673                        textStr=S_Selection
1674//                      Print textStr
1675                        sscanf textStr,"%s %g +- %g\r",dumStr,val1,val2
1676                        pw[jj] = val1
1677                        pw_err[jj] = val2
1678                endfor
1679               
1680        endfor
1681
1682End
1683
1684
1685
1686//DOES NOT graph the data, does not create a weighting wave
1687//NSE data assumed to be 4-column
1688//q (all the same) - t(ns) - I(q,t) - dI(q,t)
1689Static Function LoadNSEDataWithName(fileStr)
1690        String fileStr
1691        //Load the waves, using default waveX names
1692        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
1693        LoadWave/G/D/A/Q fileStr
1694        String fileName = S_fileName
1695       
1696       
1697        String w0,w1,w2,n0,n1,n2,wt,w3,n3
1698        Variable rr,gg,bb
1699       
1700        // put the names of the four loaded waves into local names
1701        n0 = StringFromList(0, S_waveNames ,";" )
1702        n1 = StringFromList(1, S_waveNames ,";" )
1703        n2 = StringFromList(2, S_waveNames ,";" )
1704        n3 = StringFromList(3, S_waveNames ,";" )
1705       
1706       
1707        //remove the semicolon AND period from files from the VAX
1708        w0 = CleanupName((S_fileName+"__Q"),0)
1709        w1 = CleanupName((S_fileName+"__X"),0)
1710        w2 = CleanupName((S_fileName+"__Y"),0)
1711        w3 = CleanupName((S_fileName+"__S"),0)
1712       
1713        if(exists(w0) !=0)
1714                //waves already exist
1715                KillWaves $n0,$n1,$n2,$n3               // kill the default waveX that were loaded
1716                return(0)
1717        endif
1718       
1719        // Rename to give nice names
1720        Rename $n0, $w0
1721        Rename $n1, $w1
1722        Rename $n2, $w2
1723        Rename $n3, $w3
1724
1725End
1726
1727/////
1728//wStr is the coef_ wave with the initial guess
1729Function FillCoefGuess(wStr)
1730        String wStr
1731       
1732        Wave w=$wStr
1733        if (! WaveExists(w) )
1734                DoAlert 0, "The coefficient wave "+wStr+" does not exist. Either create the wave or enter the correct suffix"
1735                return(0)
1736        endif
1737        Wave/T guess=root:AutoFit:guessMatrix
1738        Variable ii=0,num=numpnts(w)
1739        Variable tmp
1740       
1741        Variable selRow,matrixRow
1742        selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames
1743
1744        do
1745                tmp=w[ii]
1746                guess[ii][selRow] = num2str(tmp)
1747                ii+=1
1748        while(ii<num)
1749End
1750
1751/////
1752//wStr is the hold_ wave with the initial guess
1753Function FillHoldGuess(wStr)
1754        String wStr
1755       
1756        Wave w=$wStr
1757        if (! WaveExists(w) )
1758                DoAlert 0, "The hold wave "+wStr+" does not exist. Either create the wave or enter the correct suffix"
1759                return(0)
1760        endif
1761        Wave/T hold=root:AutoFit:holdMatrix
1762        Variable ii=0,num=numpnts(w)
1763        Variable tmp
1764       
1765        Variable selRow,matrixRow
1766        selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames
1767       
1768        do
1769                tmp=w[ii]
1770                hold[ii][selRow] = num2str(tmp)
1771                ii+=1
1772        while(ii<num)
1773End
1774
1775/////
1776//wStr is the Constr_ wave with the initial guess
1777// --- this is a Text wave
1778Function FillConstrGuess(wStr)
1779        String wStr
1780       
1781        Wave/T w=$wStr
1782        if (! WaveExists(w) )
1783                DoAlert 0, "The Constraint wave "+wStr+" does not exist. Either create the (TEXT) wave or enter the correct suffix"
1784                return(0)
1785        endif
1786        Wave/T constr=root:AutoFit:constrMatrix
1787        Variable ii=0,num=numpnts(w)
1788        String tmp
1789       
1790        Variable selRow,matrixRow
1791        selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames
1792
1793        do
1794                tmp=w[ii]
1795                constr[ii][selRow] = tmp
1796                ii+=1
1797        while(ii<num)
1798End
1799
1800////
1801//need the extension of the model wave to append
1802//
1803// it will plot the UN-smeared model for generating the initial guesses
1804// -- fitting will use Smeared or unsmeared, depending on the popup selection
1805//
1806//
1807Function fLoadSelected(extStr)
1808        string extStr
1809
1810        Variable datafile,ii
1811        String fullName,dataName,str
1812       
1813        WAVE/T fileWave=root:AutoFit:fileListWave
1814        Wave sel = root:AutoFit:fileSelWave
1815        ii=0
1816        do
1817                if((sel[ii][0] & 0x01) == 1)    // the file is selected in the list box
1818                        datafile = ii
1819                        break
1820                endif
1821                ii+=1
1822        while(ii<numpnts(sel))
1823       
1824        //load in the data
1825        PathInfo dataPath
1826        fullName = S_path
1827        fullName += fileWave[datafile][0]
1828
1829        str = "A_LoadOneDDataToName(\""+fullName+"\",\"\",0,1)"         //don't plot, force overwrite
1830        Execute str             
1831       
1832        dataName=GetFileNameFromPathNoSemi(fullName)
1833        dataname=CleanupName(dataname,0)
1834       
1835        //graph it - creates window named "AutoGraph"
1836        DoWindow/K tmpGraph
1837        Execute "DoGraph(\""+dataname+"\")"
1838        DoWindow/C tmpGraph
1839//      Wave/Z yw = $("ywave_"+extStr)
1840//      Wave/Z xw = $("xwave_"+extStr)
1841
1842        if(exists("ywave_"+extStr) && exists("xwave_"+extStr))
1843                AppendtoGraph $("ywave_"+extStr) vs $("xwave_"+extStr)
1844        else
1845                DoAlert 0,"Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix"
1846        endif
1847
1848//      ControlInfo/W=AutoFitPanel popup0
1849//      if(cmpstr(S_Value[0,4], "Smear" ) == 0 )
1850//              SetDataFolder $dataname
1851//              if(exists("smeared_"+extStr) && exists("smeared_qvals"))
1852//                     
1853//                      AppendtoGraph $("smeared_"+extStr) vs $("smeared_qvals")
1854//              else
1855//                      SetDataFolder root:
1856//                      DoAlert 0,"Smeared Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix"
1857//              endif
1858//             
1859//      else
1860//              if(exists("ywave_"+extStr) && exists("xwave_"+extStr))
1861//                      AppendtoGraph $("ywave_"+extStr) vs $("xwave_"+extStr)
1862//              else
1863//                      DoAlert 0,"Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix"
1864//              endif
1865//      endif
1866
1867
1868        SetDataFolder root:
1869        return(0)
1870End
1871
1872//loads the selected file in a temporary graph
1873Function LoadForGuessProc(ctrlName) : ButtonControl
1874        String ctrlName
1875       
1876        SVAR ext=root:AutoFit:gExt
1877        fLoadSelected(ext)
1878        return(0)
1879End
1880
1881//makes the holdWave and Constraint wave that are needed to set the values in the list boxes (and the matrix)
1882// these are not generated when plotting a model.
1883Function Make_HoldConstraintEps_Waves()
1884       
1885        SVAR  ext=root:AutoFit:gExt
1886        Variable num=numpnts($("coef_"+ext))
1887        if(WaveExists($("coef_"+ext)) == 0 )
1888                DoAlert 0,"coef_"+ext+" does not exist. You must set the prefix correctly and plot the model first"
1889        else
1890                Make/O/D/N=(num) $("Hold_"+ext)
1891                Make/O/T/N=(num) $("Constr_"+ext)
1892                Make/O/D/N=(num) $("Epsilon_"+ext)=0.0003
1893       
1894                String str=WinList("*", ";","WIN:2"),sel
1895                Prompt sel, "Select Table to Append Waves", popup str
1896                DoPrompt "asdf",sel
1897                if (V_Flag)
1898                        return 0        // user canceled
1899                endif
1900                DoWindow/F $sel
1901                AppendToTable $("Hold_"+ext), $("Constr_"+ext), $("Epsilon_"+ext)
1902        endif
1903End
1904//needs the name (as a string) of the coefficient wave
1905//it assumes "coef_" plus an extension
1906//
1907Function UseCoefAsGuess(ctrlName) : ButtonControl
1908        String ctrlName
1909       
1910        String wStr = "coef_"
1911        SVAR ext=root:AutoFit:gExt
1912        FillCoefGuess(wStr+ext)
1913        DisplayGuess()
1914        return(0)
1915End
1916
1917//needs the name (as a string) of the hold string wave
1918//it assumes "hold_" plus an extension
1919//
1920Function UseHoldAsGuess(ctrlName) : ButtonControl
1921        String ctrlName
1922       
1923//      String wStr = "hold_"
1924//      SVAR ext=root:AutoFit:gExt
1925//      FillHoldGuess(wStr+ext)
1926//      DisplayGuess()
1927        return(0)
1928End
1929
1930//needs the name (as a string) of the coefficient wave
1931//it assumes "constr" plus an extension
1932//
1933Function UseConstraintsAsGuess(ctrlName) : ButtonControl
1934        String ctrlName
1935       
1936//      String wStr = "Constr_"
1937//      SVAR ext=root:AutoFit:gExt
1938//      FillConstrGuess(wStr+ext)
1939//      DisplayGuess()
1940        return(0)
1941End
1942
Note: See TracBrowser for help on using the repository browser.