source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Packages/ModelPicker/SANSModelPicker.ipf @ 130

Last change on this file since 130 was 130, checked in by srkline, 16 years ago

-Fixed RPA and HPMSA functions to be up-to-date and use data folders properly for the smeared calculations.

-Changed the coef/param naming scheme for RPA to be consistent with all other models.

-SANSModelPicker now finds Smeared Plot Procs with the correct number of parameters to populate the menus

File size: 23.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=4.0
3#pragma version=3.00
4
5//************************
6//
7// Utility procedure to allow the user to select exactly which fitting
8// functions they wish to include in their experiment. Smearing and plotting
9// procedures are automatically included
10//
11// Functions are now in "SANS Models" Menu, with submenus for
12// smeared/unsmeared functions
13//
14// this change was prompted due to the 31 item limitation of Windows submenus
15// resulting in functions being unavailable in the curve fitting dialog
16//
17// A built-in list of procedure files is included, and should match the current
18// distribution package -- see the procedure asdf() for instructions on how
19// to update the built-in list of procedures
20//
21// SRK 091801
22//
23// Updated for easier use 02 JUL 04 SRK
24//
25// SRK 16DEC05 added utility function to get the list of all functions
26// first - select and include all of the models
27//    -- Proc GetAllModelFunctions()
28//
29// SEE TypeNewModelList() for instructions on how to permanently add new model
30// functions to the list... (APR 06 SRK)
31//
32// added Freeze Model - to duplicate a model function/strip the dependency
33// and plot it on the top graph - so that parameters can be changed...
34// SRK 09 JUN 2006
35//
36//***************************
37
38// main procedure for invoking the Procedure list panel
39// initializes each time to make sure
40Proc ModelPicker_Panel()
41
42        Variable/G root:SANS_ANA_VERSION=3.00
43       
44        DoWindow/F Procedure_List
45        if(V_Flag==0)
46                Init_FileList()
47                Procedure_List()
48        endif
49End
50
51// initialization procedure to create the necessary data folder and the waves for
52// the list box in the panel
53Proc Init_FileList()
54        //create the data folder
55        if(!DataFolderExists("root:FileList"))
56                NewDataFolder/O/S root:FileList
57                //create the waves
58                Make/O/T/N=0 fileWave,includedFileWave
59                Make/O/N=0 selWave,selToDelWave
60        //      String/G allFiles=""
61                String/G MenuItemStr1=""
62                String/G MenuItemStr2=""
63                //DON'T create MenuItemStr_def
64               
65                // a switch for me to turn off file checking
66                Variable/G checkForFiles=1              //set to true initially
67               
68                //fill the list of procedures
69                //
70                // first time, create wave from built-in list
71                FileList_BuiltInList()          //makes sure that the wave exists
72                FileList_GetListButtonProc("")  //converts it into a list for the panel
73               
74                // "include" nothing to force a load of the utility procedures
75                FileList_InsertButtonProc("")
76               
77                NewDataFolder/O root:myGlobals          //others will need this...make it just in case
78               
79                SetDataFolder root:
80        Endif
81End
82
83
84// for my own testing to read in a new list of procedures
85// FileList_GetListButtonProc("") will only read in a new list
86// if the wave SANS_Model_List does not exist
87Proc ReadNewProcList()
88        KillWaves/Z root:FileList:SANS_Model_List               //kill the old list
89        FileList_GetListButtonProc("")
90End
91
92// To create a new "Built-in" list of procedures, edit the
93// wave SANS_Model_List (a text wave), adding your new procedure names
94// (sort alphabetically if desired)
95// then use TypeNewModelList() to spit out the text format.
96// then paste this list into FileList_BuiltInList
97//
98// note that you won't have help for these new procedures until
99// you update the function documentation, making the name of the procedure
100// file a Subtopic
101//
102Proc TypeNewModelList()
103        variable ii=0,num=numpnts(root:FileList:SANS_Model_List)
104        printf "Make/O/T/N/=%d  SANS_Model_List\r\r",num
105        do
106                printf "SANS_Model_List[%d] = \"%s\"\r",ii,root:FileList:SANS_Model_List[ii]
107                ii+=1
108        while(ii<num)
109End
110
111Proc FileList_BuiltInList()
112        SetDataFolder root:FileList
113
114////paste here... after deleting the old make statement and list
115       
116        Make/O/T/N=62 SANS_Model_List
117       
118  SANS_Model_List[0] = "Beaucage.ipf"
119  SANS_Model_List[1] = "BE_Polyelectrolyte.ipf"
120  SANS_Model_List[2] = "BimodalSchulzSpheres.ipf"
121  SANS_Model_List[3] = "BinaryHardSpheres.ipf"
122  SANS_Model_List[4] = "CoreShell.ipf"
123  SANS_Model_List[5] = "CoreShellCylinder.ipf"
124  SANS_Model_List[6] = "CoreShell_and_Struct.ipf"
125  SANS_Model_List[7] = "CylinderForm.ipf"
126  SANS_Model_List[8] = "Cylinder_and_Struct.ipf"
127  SANS_Model_List[9] = "Cylinder_PolyLength.ipf"
128  SANS_Model_List[10] = "Cylinder_PolyRadius.ipf"
129  SANS_Model_List[11] = "DAB_model.ipf"
130  SANS_Model_List[12] = "Debye.ipf"
131  SANS_Model_List[13] = "EllipticalCylinder.ipf"
132  SANS_Model_List[14] = "FlexCyl_EllipCross.ipf"
133  SANS_Model_List[15] = "FlexCyl_PolyLen.ipf"
134  SANS_Model_List[16] = "FlexCyl_PolyRadius.ipf"
135  SANS_Model_List[17] = "FlexibleCylinder.ipf"
136  SANS_Model_List[18] = "Fractal.ipf"
137  SANS_Model_List[19] = "GaussSpheres.ipf"
138  SANS_Model_List[20] = "GaussSpheres_and_Struct.ipf"
139  SANS_Model_List[21] = "HardSphereStruct.ipf"
140  SANS_Model_List[22] = "HollowCylinders.ipf"
141  SANS_Model_List[23] = "HPMSA.ipf"
142  SANS_Model_List[24] = "LamellarFF.ipf"
143  SANS_Model_List[25] = "LamellarFF_HG.ipf"
144  SANS_Model_List[26] = "LamellarPS.ipf"
145  SANS_Model_List[27] = "LamellarPS_HG.ipf"
146  SANS_Model_List[28] = "LogNormalSphere.ipf"
147  SANS_Model_List[29] = "LogNormSpheres_and_Struct.ipf"
148  SANS_Model_List[30] = "Lorentz_model.ipf"
149  SANS_Model_List[31] = "MultiShell.ipf"
150  SANS_Model_List[32] = "OblateCS_and_Struct.ipf"
151  SANS_Model_List[33] = "OblateForm.ipf"
152  SANS_Model_List[34] = "Parallelepiped.ipf"
153  SANS_Model_List[35] = "Peak_Gauss_model.ipf"
154  SANS_Model_List[36] = "Peak_Lorentz_model.ipf"
155  SANS_Model_List[37] = "PolyCore.ipf"
156  SANS_Model_List[38] = "PolyCoreShellCylinder.ipf"
157  SANS_Model_List[39] = "PolyCoreShellRatio.ipf"
158  SANS_Model_List[40] = "PolyCore_and_Struct.ipf"
159  SANS_Model_List[41] = "PolyCSRatio_and_Struct.ipf"
160  SANS_Model_List[42] = "PolyHardSphereInten.ipf"
161  SANS_Model_List[43] = "PolyRectSphere_and_Struct.ipf"
162  SANS_Model_List[44] = "Power_Law_model.ipf"
163  SANS_Model_List[45] = "ProlateCS_and_Struct.ipf"
164  SANS_Model_List[46] = "ProlateForm.ipf"
165  SANS_Model_List[47] = "RectPolySpheres.ipf"
166  SANS_Model_List[48] = "SchulzSpheres.ipf"
167  SANS_Model_List[49] = "SchulzSpheres_and_Struct.ipf"
168  SANS_Model_List[50] = "SmearedRPA.ipf"
169  SANS_Model_List[51] = "Sphere.ipf"
170  SANS_Model_List[52] = "Sphere_and_Struct.ipf"
171  SANS_Model_List[53] = "SquareWellStruct.ipf"
172  SANS_Model_List[54] = "StackedDiscs.ipf"
173  SANS_Model_List[55] = "StickyHardSphereStruct.ipf"
174  SANS_Model_List[56] = "Teubner.ipf"
175  SANS_Model_List[57] = "TriaxialEllipsoid.ipf"
176  SANS_Model_List[58] = "UnifEllipsoid_and_Struct.ipf"
177  SANS_Model_List[59] = "UniformEllipsoid.ipf"
178  SANS_Model_List[60] = "Vesicle_UL.ipf"
179  SANS_Model_List[61] = "Vesicle_UL_and_Struct.ipf"
180 
181  ///end paste here
182End
183
184//another way to add a single procedure name to the list
185// (only in the current experiment!)
186// not a permanent add to the template, unless you re-save the
187// template
188Proc AddProcedureToList(ProcedureName)
189        String ProcedureName
190       
191        SetDataFolder root:FileList
192        Variable num
193        num=numpnts(fileWave)
194        Redimension/N=(num+1) fileWave
195        fileWave[num] = ProcedureName
196        num=numpnts(selWave)
197        Redimension/N=(num+1) selWave
198        selWave[num] = 0
199       
200        SetDataFolder root:
201End
202/////////////////////////////////////////////////////////////
203
204
205Proc doCheck(val)
206        Variable val
207        // a switch for me to turn off file checking
208        root:FileList:checkForFiles=val //0==no check, 1=check 
209End
210
211
212Function MakeMenu_ButtonProc(ctrlName) : ButtonControl
213        String ctrlName
214
215        RefreshMenu()
216End
217
218//procedure for drawing the simple panel to pick and compile selected models
219//
220Proc Procedure_List()
221        PauseUpdate; Silent 1           // building window...
222        NewPanel /W=(582,44,920,263) /K=2
223        DoWindow/C Procedure_List
224        ModifyPanel fixedSize=1
225        ListBox fileList,pos={4,3},size={200,100},listWave=root:FileList:fileWave
226        ListBox fileList,selWave=root:FileList:selWave,mode= 4
227        ListBox inclList,pos={4,110},size={200,100}
228        ListBox inclList,listWave=root:FileList:includedFileWave
229        ListBox inclList,selWave=root:FileList:selToDelWave,mode= 4
230        Button button0,pos={212,77},size={110,20},proc=FileList_InsertButtonProc,title="Include File(s)"
231        Button button0,help={"Includes the selected procedures, functions appear under the SANS Models menu"}
232        Button button5,pos={212,187},size={110,20},proc=FileList_RemoveButtonProc,title="Remove File(s)"
233        Button button5,help={"Removes selected procedures from the experiment"}
234        Button PickerButton,pos={212,12},size={90,20},proc=FileList_HelpButtonProc,title="Picker Help"
235        Button PickerButton,help={"If you need help understanding what a help button does, you really need help"}
236        Button button1,pos={212,35},size={100,20},proc=FileList_HelpButtonProc,title="Function Help"
237        Button button1,help={"If you need help understanding what a help button does, you really need help"}
238EndMacro
239
240//button function to prompt user to select path where procedures are located
241Function FL_PickButtonProc(ctrlName) : ButtonControl
242        String ctrlName
243
244        PickProcPath()
245End
246
247//bring the help notebook to the front
248Function FileList_HelpButtonProc(ctrlName) : ButtonControl
249        String ctrlName
250
251        if(cmpstr(ctrlName,"PickerButton")==0)          //PickerButton is the picker help
252                DisplayHelpTopic "SANS Model Picker"
253                return(0)
254        endif
255       
256        //otherwise, show the help for the selected function   
257        //loop through the selected files in the list...
258        //
259        Wave/T fileWave=$"root:FileList:fileWave"
260        Wave sel=$"root:FileList:selWave"
261       
262        Variable num=numpnts(sel),ii
263        String fname=""
264       
265//      NVAR doCheck=root:FileList:checkForFiles
266        ii=num-1                //work bottom-up to not lose the index
267        do
268                if(sel[ii] == 1)               
269                                fname = fileWave[ii] //RemoveExten(fileWave[ii])
270                endif
271                ii-=1
272        while(ii>=0)
273       
274        // nothing selected in the list to include,
275        //try the list of already-included files
276        if(cmpstr(fname,"")==0)
277                Wave/T inclFileWave=$"root:FileList:includedFileWave"
278                Wave seltoDel=$"root:FileList:selToDelWave"
279                num=numpnts(seltoDel)
280                ii=num-1                //work bottom-up to not lose the index
281                do
282                        if(seltoDel[ii] == 1)           
283                                        fname = inclFileWave[ii] //RemoveExten(fileWave[ii])
284                        endif
285                        ii-=1
286                while(ii>=0)
287        endif
288       
289        if(cmpstr(fname,"")!=0)
290//              Print "show help for ",RemoveExten(fname)
291//              Print fname[strlen(fname)-11,strlen(fname)-1]
292                if(cmpstr(fname[strlen(fname)-11,strlen(fname)-1],"_Struct.ipf") ==0 )
293                        DisplayHelpTopic "How Form Factors and Structure Factors are Combined"
294                else
295                        DisplayHelpTopic fname
296                endif
297        else
298                DoAlert 0,"Please select a function from the list to display its help file"
299        endif
300       
301        return(0)
302End
303
304//closes the panel when done
305Function FileListDoneButtonProc(ctrlName) : ButtonControl
306        String ctrlName
307
308        //kill the panel
309        DoWindow/K Procedure_List
310        return(0)
311End
312
313//reads in the list of procedures
314// (in practice, the list will be part of the experiment)
315// but this can be used to easily update the list if
316// new models are added, or if a custom list is desired
317// - these lists could also be stored in the template
318//
319Function FileList_GetListButtonProc(ctrlName) : ButtonControl
320        String ctrlName
321       
322        String list=""
323
324        if(Exists("root:FileList:SANS_Model_List") != 1)
325                SetDataFolder root:FileList
326                LoadWave/A/T
327                WAVE/T w=$(StringFromList(0,S_WaveNames,";"))
328                SetDataFolder root:
329        else
330                WAVE/T w=$("root:FileList:SANS_Model_List")
331        endif
332       
333//      // convert the input wave to a semi-list
334//      SVAR allFiles=root:FileList:allFiles
335//      allFiles=MP_TextWave2SemiList(w)
336        list=MP_TextWave2SemiList(w)
337       
338        //get the list of available files from the specified path
339        String newList="",item=""
340        Variable num=ItemsInList(list,";"),ii
341
342        // remove the items that have already been included
343        Wave/T includedFileWave=$"root:FileList:includedFileWave"
344        Variable numInc=numpnts(includedFileWave)
345        for(ii=0;ii<numInc;ii+=1)
346                list = RemoveFromList(includedFileWave[ii],list,";")
347        endfor
348        list = SortList(list,";",0)
349        num=ItemsInList(list,";")
350        WAVE/T fileWave=$"root:FileList:fileWave"
351        WAVE selWave=$"root:FileList:selWave"
352        Redimension/N=(num) fileWave            //make the waves the proper length
353        Redimension/N=(num) selWave
354        fileWave = StringFromList(p,list,";")           //converts the list to a wave
355        Sort filewave,filewave
356       
357        return(0)
358End
359
360//*******OLD WAY*******
361//*******NOT USED*******
362//gets the list of files in the folder specified by procPathName
363//filters the list to remove some of the procedures that the user does not need to see
364// list is assigned to textbox wave
365Function OLD_FileList_GetListButtonProc(ctrlName) : ButtonControl
366        String ctrlName
367       
368        //make sure that path exists
369        PathInfo procPathName
370        if (V_flag == 0)
371                //Abort "Folder path does not exist - use Pick Path button to set path"
372                //build the path to the User Procedures folder
373                PathInfo Igor
374        //      Print S_Path
375                String UserProcStr=S_path+"User Procedures:"
376                NewPath/O/Q procPathName  UserProcStr
377        Endif
378       
379        String list=""
380//      list=IndexedFile(procPathName,-1,"????")
381
382// new way, to catch all files in all subfolders
383        SVAR allFiles=root:FileList:allFiles
384        allFiles=""             //clear the list
385
386        ListAllFilesAndFolders("procPathName",1,1,0)    //this sets allFiles
387        list = allFiles
388       
389        //get the list of available files from the specified path
390       
391        String newList="",item=""
392        Variable num=ItemsInList(list,";"),ii
393        //remove procedures from the list the are unrelated, or may be loaded by default (Utils)
394        list = RemoveFromList(".DS_Store",list,";")             //occurs on OSX, not "hidden" to Igor
395        list = RemoveFromList("GaussUtils.ipf",list,";" )
396        list = RemoveFromList("PlotUtils.ipf",list,";" )
397        list = RemoveFromList("PlotUtilsMacro.ipf",list,";" )
398        list = RemoveFromList("WriteModelData.ipf",list,";" )
399        list = RemoveFromList("WMMenus.ipf",list,";" )
400        list = RemoveFromList("DemoLoader.ipf",list,";" )
401        // remove the items that have already been included
402        Wave/T includedFileWave=$"root:FileList:includedFileWave"
403        Variable numInc=numpnts(includedFileWave)
404        for(ii=0;ii<numInc;ii+=1)
405                list = RemoveFromList(includedFileWave[ii],list,";")
406        endfor
407        list = SortList(list,";",0)
408        num=ItemsInList(list,";")
409        WAVE/T fileWave=$"root:FileList:fileWave"
410        WAVE selWave=$"root:FileList:selWave"
411        Redimension/N=(num) fileWave            //make the waves the proper length
412        Redimension/N=(num) selWave
413        fileWave = StringFromList(p,list,";")           //converts the list to a wave
414        Sort filewave,filewave
415End
416
417// returns 1 if the file exists, 0 if the file is not there
418// fails miserably if there are aliases in the UP folder, although
419// the #include doesn't mind
420Function CheckFileInUPFolder(fileStr)
421        String fileStr
422
423        Variable err=0
424        String/G root:FileList:allFiles=""
425        SVAR allFiles = root:FileList:allFiles
426       
427        PathInfo Igor
428        String UPStr=S_path+"User Procedures:"
429        NewPath /O/Q/Z UPPath ,UPStr
430        ListAllFilesAndFolders("UPPath",1,1,0)  //this sets allFiles
431        String list = allFiles
432//      err = FindListItem(fileStr, list ,";" ,0)
433//      err = strsearch(list, fileStr, 0,2)             //this is not case-sensitive, but Igor 5!
434        err = strsearch(list, fileStr, 0)               //this is Igor 4+ compatible
435//      Print err
436        if(err == -1)
437                return(0)
438        else
439                return(1)               //name was found somewhere
440        endif
441End
442
443
444Function FileList_InsertButtonProc(ctrlName) : ButtonControl
445        String ctrlName
446       
447        //loop through the selected files in the list...
448        Wave/T fileWave=$"root:FileList:fileWave"
449        Wave sel=$"root:FileList:selWave"
450        //and adjust the included file lists
451        Wave/T includedFileWave=$"root:FileList:includedFileWave"
452        Wave selToDel=$"root:FileList:selToDelWave"
453       
454        Variable numIncl=numpnts(includedFileWave)
455        Variable num=numpnts(sel),ii,ok
456        String fname=""
457
458        //Necessary for every analysis experiment
459        Execute/P "INSERTINCLUDE \"PlotUtilsMacro\""
460        Execute/P "INSERTINCLUDE \"GaussUtils\""
461        Execute/P "INSERTINCLUDE \"WriteModelData\""
462       
463        NVAR doCheck=root:FileList:checkForFiles
464       
465        ii=num-1                //work bottom-up to not lose the index
466        do
467                if(sel[ii] == 1)
468                        //can I make sure the file exists before trying to include it?
469                        if(doCheck)
470                                ok = CheckFileInUPFolder(fileWave[ii])
471                        endif
472                        if(ok || !doCheck)
473                                fname = RemoveExten(fileWave[ii])       
474                                Execute/P "INSERTINCLUDE \""+fname+"\""
475                                // add to the already included list, and remove from the to-include list (and selWaves also)
476                                InsertPoints numpnts(includedFileWave), 1, includedFileWave,selToDel
477                                includedFileWave[numpnts(includedFileWave)-1]=fileWave[ii]
478                               
479                                DeletePoints ii, 1, fileWave,sel
480                        else
481                                DoAlert 0,"File "+fileWave[ii]+" was not found in the User Procedures folder, so it was not included"
482                        endif
483                endif
484                ii-=1
485        while(ii>=0)
486        Execute/P "COMPILEPROCEDURES ";Execute/P/Q/Z "RefreshMenu()"
487       
488        sel=0           //clear the selections
489        selToDel=0
490       
491        return(0)
492End
493
494Function FileList_RemoveButtonProc(ctrlName) : ButtonControl
495        String ctrlName
496       
497        //loop through the selected files in the list...
498        Wave/T includedFileWave=$"root:FileList:includedFileWave"
499        Wave selToDel=$"root:FileList:selToDelWave"
500        // and put the unwanted procedures back in the to-add list
501        Wave/T fileWave=$"root:FileList:fileWave"
502        Wave sel=$"root:FileList:selWave"
503       
504       
505        Variable num=numpnts(selToDel),ii
506        String fname=""
507       
508        ii=num-1                //work backwards
509        do
510                if(selToDel[ii] == 1)
511                        fname = RemoveExten(includedFileWave[ii])
512                        Execute/P "DELETEINCLUDE \""+fname+"\""
513                        //add to the to-include list
514                        InsertPoints numpnts(fileWave), 1, fileWave,sel
515                        fileWave[numpnts(fileWave)-1]=includedFileWave[ii]
516                        //delete the point
517                        DeletePoints ii, 1, includedFileWave,selToDel
518                endif
519                ii-=1
520        while(ii>=0)
521        Execute/P "COMPILEPROCEDURES ";Execute/P/Q/Z "RefreshMenu()"
522       
523        sel=0
524        selToDel=0
525       
526        Sort filewave,filewave
527        return(0)
528End
529
530
531//removes ANY ".ext" extension from the name
532// - wipes out all after the "dot"
533// - procedure files to be included (using quotes) must be in User Procedures folder
534// and end in .ipf?
535Function/S RemoveExten(str)
536        String str
537       
538        Variable loc=0
539        String tempStr=""
540       
541        loc=strsearch(str,".",0)
542        tempStr=str[0,loc-1]
543        return(tempStr)
544End
545
546// function to have user select the path where the procedure files are
547//      - the selected path is set as procPathName
548//
549// setting the path to "igor" does not seem to have the desired effect of
550// bringing up the Igor Pro folder in the NewPath Dialog
551//
552//may also be able to use folder lists on HD - for more sophisticated listings
553Function PickProcPath()
554       
555        //set the global string to the selected pathname
556        PathInfo/S Igor
557       
558        NewPath/O/M="pick the SANS Procedure folder" procPathName
559        return(0)               //no error
560End
561
562
563//my menu, seemingly one item, but really a long string for each submenu
564// if root:MenuItemStr exists
565Menu "SANS Models"
566        StrVarOrDefault("root:FileList:MenuItemStr_def","ModelPicker_Panel")//, RefreshMenu()
567        SubMenu "Unsmeared Models"
568                StrVarOrDefault("root:FileList:MenuItemStr1","ModelPicker_Panel")
569        End
570        SubMenu "Smeared Models"
571                StrVarOrDefault("root:FileList:MenuItemStr2","ModelPicker_Panel")
572        End
573//      SubMenu "Models 3"
574//              StrVarOrDefault("root:MenuItemStr3","ModelPicker_Panel")
575//      End
576End
577
578//wrapper to use the A_ prepended file loader from the dynamically defined menu
579Proc LoadSANSorUSANSData()
580        A_LoadOneDData()
581End
582
583// tweaked to find RPA model which has an extra parameter in the declaration
584Function RefreshMenu()
585
586        String list="",sep=";"
587       
588        //list = "Refresh Menu"+sep+"ModelPicker_Panel"+sep+"-"+sep
589        list = "ModelPicker_Panel"+sep+"-"+sep
590//      list += MacroList("LoadO*",sep,"KIND:1,NPARAMS:0")              //data loader
591        list += "Load SANS or USANS Data;"              //use the wrapper above to get the right loader
592        list += "Reset Resolution Waves;"               // resets the resolution waves used for the calculations
593        list += "Freeze Model;"                                         // freeze a model to compare plots on the same graph
594        list += MacroList("WriteM*",sep,"KIND:1,NPARAMS:4")             //data writer
595        list += "-"+sep
596        String/G root:FileList:MenuItemStr_def = TrimListTo255(list)
597       
598        list = ""
599        list += MacroList("*",sep,"KIND:1,NPARAMS:3")                           //unsmeared plot procedures
600        list += MacroList("Plot*",sep,"KIND:1,NPARAMS:4")                               //RPA has 4 parameters
601        list = RemoveFromList("FreezeModel", list ,";")                 // remove FreezeModel, it's not a model
602        //      list += "-"+sep
603        String/G root:FileList:MenuItemStr1 = TrimListTo255(list)
604
605        list=""
606        list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:1")                   //smeared plot procedures
607        list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:2")                   //smeared RPA has 2 parameters
608        String/G root:FileList:MenuItemStr2 = TrimListTo255(list)
609
610        BuildMenu "SANS Models"
611       
612        return(0)
613End
614
615//if the length of any of the strings is more than 255, the menu will disappear
616Function/S TrimListTo255(list)
617        String list
618       
619        Variable len,num
620        num = itemsinlist(list,";")
621        len = strlen(list)
622        if(len>255)
623                DoAlert 0, "Not all menu items are shown - remove some of the models"
624                do
625                        list = RemoveListItem(num-1, list  ,";" )
626                        len=strlen(list)
627                        num=itemsinlist(list,";")
628                while(len>255)
629        endif
630        return(list)
631End
632
633Function/S MP_TextWave2SemiList(textW)
634        Wave/T textW
635       
636        String list=""
637        Variable num=numpnts(textW),ii=0
638        do
639                list += textw[ii] + ";"
640                ii+=1
641        while(ii<num)
642        return(list)
643End
644
645Function MP_SemiList2TextWave(list,outWStr)
646        String list,outWStr
647       
648        Variable num=itemsinList(list)
649        Make/T/O/N=(num) $outWStr
650        WAVE/T w=$outWStr
651        w = StringFromList(p,list,";")
652        return(0)
653End
654
655//modified to get a list of all files in folder and subfolders
656// passed back through a global variable
657Function ListAllFilesAndFolders(pathName, full, recurse, level)
658        String pathName         // Name of symbolic path in which to look for folders.
659        Variable full                   // True to print full paths instead of just folder name.
660        Variable recurse                // True to recurse (do it for subfolders too).
661        Variable level          // Recursion level. Pass 0 for the top level.
662       
663        Variable ii
664        String prefix
665       
666        SVAR allFiles=root:FileList:allFiles
667        // Build a prefix (a number of tabs to indicate the folder level by indentation)
668        prefix = ""
669        ii = 0
670        do
671                if (ii >= level)
672                        break
673                endif
674                prefix += "\t"                                  // Indent one more tab
675                ii += 1
676        while(1)
677       
678//      Printf "%s%s\r", prefix, pathName
679//      Print IndexedFile($pathName,-1,"????")
680        allFiles += IndexedFile($pathName,-1,"????")
681       
682        String path
683        ii = 0
684        do
685                path = IndexedDir($pathName, ii, full)
686                if (strlen(path) == 0)
687                        break                                                   // No more folders
688                endif
689//              Printf "%s%s\r", prefix, path
690               
691                if (recurse)                                            // Do we want to go into subfolder?
692                        String subFolderPathName = "tempPrintFoldersPath_" + num2istr(level+1)
693                       
694                        // Now we get the path to the new parent folder
695                        String subFolderPath
696                        if (full)
697                                subFolderPath = path    // We already have the full path.
698                        else
699                                PathInfo $pathName              // We have only the folder name. Need to get full path.
700                                subFolderPath = S_path + path
701                        endif
702                       
703                        NewPath/Q/O $subFolderPathName, subFolderPath
704                        ListAllFilesAndFolders(subFolderPathName, full, recurse, level+1)
705                        KillPath/Z $subFolderPathName
706                endif
707               
708                ii += 1
709        while(1)
710End
711
712
713// utility function to get the list of all functions
714// first - select and include all of the models
715//
716Proc GetAllModelFunctions()
717        String str =  FunctionList("*",";","KIND:10,NINDVARS:1")
718        Print itemsinList(str)
719
720        MP_SemiList2TextWave(str,"UserFunctionList")
721        edit UserFunctionList
722end
723
724// allows an easy way to "freeze" a model calculation
725// - duplicates X and Y waves (tags them _q and _i)
726// - kill the dependecy
727// - append it to the top graph
728// - it can later be exported with WriteModelData
729//
730// in Igor 5, you can restrict the WaveList to be just the top graph...
731// SRK  09 JUN 2006
732//
733Proc FreezeModel(xWave,yWave,newNameStr)
734        String xWave,yWave,newNameStr
735        Prompt xwave,"X data",popup,WaveList("*",";","")
736        Prompt ywave,"y data",popup,WaveList("*",";","")
737        Prompt newNameStr,"new name for the waves, _q and _i will be appended"
738       
739        Duplicate/O $xwave,$(newNameStr+"_q")
740        Duplicate/O $ywave,$(newNameStr+"_i")
741        SetFormula $(newNameStr+"_i"), ""
742       
743        AppendToGraph $(newNameStr+"_i") vs $(newNameStr+"_q")
744       
745End
Note: See TracBrowser for help on using the repository browser.