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

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

Changed 2D model calculations to use a FIXED 25 integration points in an effort to get the number of integration points out of the fitting coefficient wave.

Added "Freeze Model" back to the SANS Models menu

Added the 2D model functions to the list on the model picker

Minor tweaks to the wrapper

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