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

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

Modifications to SumSANSModels to make it data folder aware

Modifications to SumSANSModels and SANSPicker to bury their folders in :myGlobals

New (3.01) template that uses these folder structures
Removed (3.00) template

File size: 23.6 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 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=62 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 
184  ///end paste here
185End
186
187//another way to add a single procedure name to the list
188// (only in the current experiment!)
189// not a permanent add to the template, unless you re-save the
190// template
191Proc AddProcedureToList(ProcedureName)
192        String ProcedureName
193       
194        SetDataFolder root:myGlobals:FileList
195        Variable num
196        num=numpnts(fileWave)
197        Redimension/N=(num+1) fileWave
198        fileWave[num] = ProcedureName
199        num=numpnts(selWave)
200        Redimension/N=(num+1) selWave
201        selWave[num] = 0
202       
203        SetDataFolder root:
204End
205/////////////////////////////////////////////////////////////
206
207
208Proc doCheck(val)
209        Variable val
210        // a switch for me to turn off file checking
211        root:myGlobals:FileList:checkForFiles=val       //0==no check, 1=check 
212End
213
214
215Function MakeMenu_ButtonProc(ctrlName) : ButtonControl
216        String ctrlName
217
218        RefreshMenu()
219End
220
221//procedure for drawing the simple panel to pick and compile selected models
222//
223Proc Procedure_List()
224        PauseUpdate; Silent 1           // building window...
225        NewPanel /W=(582,44,920,263) /K=2
226        DoWindow/C Procedure_List
227        ModifyPanel fixedSize=1
228        ListBox fileList,pos={4,3},size={200,100},listWave=root:myGlobals:FileList:fileWave
229        ListBox fileList,selWave=root:myGlobals:FileList:selWave,mode= 4
230        ListBox inclList,pos={4,110},size={200,100}
231        ListBox inclList,listWave=root:myGlobals:FileList:includedFileWave
232        ListBox inclList,selWave=root:myGlobals:FileList:selToDelWave,mode= 4
233        Button button0,pos={212,77},size={110,20},proc=FileList_InsertButtonProc,title="Include File(s)"
234        Button button0,help={"Includes the selected procedures, functions appear under the SANS Models menu"}
235        Button button5,pos={212,187},size={110,20},proc=FileList_RemoveButtonProc,title="Remove File(s)"
236        Button button5,help={"Removes selected procedures from the experiment"}
237        Button PickerButton,pos={212,12},size={90,20},proc=FileList_HelpButtonProc,title="Picker Help"
238        Button PickerButton,help={"If you need help understanding what a help button does, you really need help"}
239        Button button1,pos={212,35},size={100,20},proc=FileList_HelpButtonProc,title="Function Help"
240        Button button1,help={"If you need help understanding what a help button does, you really need help"}
241EndMacro
242
243//button function to prompt user to select path where procedures are located
244Function FL_PickButtonProc(ctrlName) : ButtonControl
245        String ctrlName
246
247        PickProcPath()
248End
249
250//bring the help notebook to the front
251Function FileList_HelpButtonProc(ctrlName) : ButtonControl
252        String ctrlName
253
254        if(cmpstr(ctrlName,"PickerButton")==0)          //PickerButton is the picker help
255                DisplayHelpTopic "SANS Model Picker"
256                return(0)
257        endif
258       
259        //otherwise, show the help for the selected function   
260        //loop through the selected files in the list...
261        //
262        Wave/T fileWave=$"root:myGlobals:FileList:fileWave"
263        Wave sel=$"root:myGlobals:FileList:selWave"
264       
265        Variable num=numpnts(sel),ii
266        String fname=""
267       
268//      NVAR doCheck=root:myGlobals:FileList:checkForFiles
269        ii=num-1                //work bottom-up to not lose the index
270        do
271                if(sel[ii] == 1)               
272                                fname = fileWave[ii] //RemoveExten(fileWave[ii])
273                endif
274                ii-=1
275        while(ii>=0)
276       
277        // nothing selected in the list to include,
278        //try the list of already-included files
279        if(cmpstr(fname,"")==0)
280                Wave/T inclFileWave=$"root:myGlobals:FileList:includedFileWave"
281                Wave seltoDel=$"root:myGlobals:FileList:selToDelWave"
282                num=numpnts(seltoDel)
283                ii=num-1                //work bottom-up to not lose the index
284                do
285                        if(seltoDel[ii] == 1)           
286                                        fname = inclFileWave[ii] //RemoveExten(fileWave[ii])
287                        endif
288                        ii-=1
289                while(ii>=0)
290        endif
291       
292        if(cmpstr(fname,"")!=0)
293//              Print "show help for ",RemoveExten(fname)
294//              Print fname[strlen(fname)-11,strlen(fname)-1]
295                if(cmpstr(fname[strlen(fname)-11,strlen(fname)-1],"_Struct.ipf") ==0 )
296                        DisplayHelpTopic "How Form Factors and Structure Factors are Combined"
297                else
298                        DisplayHelpTopic fname
299                endif
300        else
301                DoAlert 0,"Please select a function from the list to display its help file"
302        endif
303       
304        return(0)
305End
306
307//closes the panel when done
308Function FileListDoneButtonProc(ctrlName) : ButtonControl
309        String ctrlName
310
311        //kill the panel
312        DoWindow/K Procedure_List
313        return(0)
314End
315
316//reads in the list of procedures
317// (in practice, the list will be part of the experiment)
318// but this can be used to easily update the list if
319// new models are added, or if a custom list is desired
320// - these lists could also be stored in the template
321//
322Function FileList_GetListButtonProc(ctrlName) : ButtonControl
323        String ctrlName
324       
325        String list=""
326
327        if(Exists("root:myGlobals:FileList:SANS_Model_List") != 1)
328                SetDataFolder root:myGlobals:FileList
329                LoadWave/A/T
330                WAVE/T w=$(StringFromList(0,S_WaveNames,";"))
331                SetDataFolder root:
332        else
333                WAVE/T w=$("root:myGlobals:FileList:SANS_Model_List")
334        endif
335       
336//      // convert the input wave to a semi-list
337//      SVAR allFiles=root:myGlobals:FileList:allFiles
338//      allFiles=MP_TextWave2SemiList(w)
339        list=MP_TextWave2SemiList(w)
340       
341        //get the list of available files from the specified path
342        String newList="",item=""
343        Variable num=ItemsInList(list,";"),ii
344
345        // remove the items that have already been included
346        Wave/T includedFileWave=$"root:myGlobals:FileList:includedFileWave"
347        Variable numInc=numpnts(includedFileWave)
348        for(ii=0;ii<numInc;ii+=1)
349                list = RemoveFromList(includedFileWave[ii],list,";")
350        endfor
351        list = SortList(list,";",0)
352        num=ItemsInList(list,";")
353        WAVE/T fileWave=$"root:myGlobals:FileList:fileWave"
354        WAVE selWave=$"root:myGlobals:FileList:selWave"
355        Redimension/N=(num) fileWave            //make the waves the proper length
356        Redimension/N=(num) selWave
357        fileWave = StringFromList(p,list,";")           //converts the list to a wave
358        Sort filewave,filewave
359       
360        return(0)
361End
362
363//*******OLD WAY*******
364//*******NOT USED*******
365//gets the list of files in the folder specified by procPathName
366//filters the list to remove some of the procedures that the user does not need to see
367// list is assigned to textbox wave
368Function OLD_FileList_GetListButtonProc(ctrlName) : ButtonControl
369        String ctrlName
370       
371        //make sure that path exists
372        PathInfo procPathName
373        if (V_flag == 0)
374                //Abort "Folder path does not exist - use Pick Path button to set path"
375                //build the path to the User Procedures folder
376                PathInfo Igor
377        //      Print S_Path
378                String UserProcStr=S_path+"User Procedures:"
379                NewPath/O/Q procPathName  UserProcStr
380        Endif
381       
382        String list=""
383//      list=IndexedFile(procPathName,-1,"????")
384
385// new way, to catch all files in all subfolders
386        SVAR allFiles=root:myGlobals:FileList:allFiles
387        allFiles=""             //clear the list
388
389        ListAllFilesAndFolders("procPathName",1,1,0)    //this sets allFiles
390        list = allFiles
391       
392        //get the list of available files from the specified path
393       
394        String newList="",item=""
395        Variable num=ItemsInList(list,";"),ii
396        //remove procedures from the list the are unrelated, or may be loaded by default (Utils)
397        list = RemoveFromList(".DS_Store",list,";")             //occurs on OSX, not "hidden" to Igor
398        list = RemoveFromList("GaussUtils.ipf",list,";" )
399        list = RemoveFromList("PlotUtils.ipf",list,";" )
400        list = RemoveFromList("PlotUtilsMacro.ipf",list,";" )
401        list = RemoveFromList("WriteModelData.ipf",list,";" )
402        list = RemoveFromList("WMMenus.ipf",list,";" )
403        list = RemoveFromList("DemoLoader.ipf",list,";" )
404        // remove the items that have already been included
405        Wave/T includedFileWave=$"root:myGlobals:FileList:includedFileWave"
406        Variable numInc=numpnts(includedFileWave)
407        for(ii=0;ii<numInc;ii+=1)
408                list = RemoveFromList(includedFileWave[ii],list,";")
409        endfor
410        list = SortList(list,";",0)
411        num=ItemsInList(list,";")
412        WAVE/T fileWave=$"root:myGlobals:FileList:fileWave"
413        WAVE selWave=$"root:myGlobals:FileList:selWave"
414        Redimension/N=(num) fileWave            //make the waves the proper length
415        Redimension/N=(num) selWave
416        fileWave = StringFromList(p,list,";")           //converts the list to a wave
417        Sort filewave,filewave
418End
419
420// returns 1 if the file exists, 0 if the file is not there
421// fails miserably if there are aliases in the UP folder, although
422// the #include doesn't mind
423Function CheckFileInUPFolder(fileStr)
424        String fileStr
425
426        Variable err=0
427        String/G root:myGlobals:FileList:allFiles=""
428        SVAR allFiles = root:myGlobals:FileList:allFiles
429       
430        PathInfo Igor
431        String UPStr=S_path+"User Procedures:"
432        NewPath /O/Q/Z UPPath ,UPStr
433        ListAllFilesAndFolders("UPPath",1,1,0)  //this sets allFiles
434        String list = allFiles
435//      err = FindListItem(fileStr, list ,";" ,0)
436//      err = strsearch(list, fileStr, 0,2)             //this is not case-sensitive, but Igor 5!
437        err = strsearch(list, fileStr, 0)               //this is Igor 4+ compatible
438//      Print err
439        if(err == -1)
440                return(0)
441        else
442                return(1)               //name was found somewhere
443        endif
444End
445
446
447Function FileList_InsertButtonProc(ctrlName) : ButtonControl
448        String ctrlName
449       
450        //loop through the selected files in the list...
451        Wave/T fileWave=$"root:myGlobals:FileList:fileWave"
452        Wave sel=$"root:myGlobals:FileList:selWave"
453        //and adjust the included file lists
454        Wave/T includedFileWave=$"root:myGlobals:FileList:includedFileWave"
455        Wave selToDel=$"root:myGlobals:FileList:selToDelWave"
456       
457        Variable numIncl=numpnts(includedFileWave)
458        Variable num=numpnts(sel),ii,ok
459        String fname=""
460
461        //Necessary for every analysis experiment
462        Execute/P "INSERTINCLUDE \"PlotUtilsMacro\""
463        Execute/P "INSERTINCLUDE \"GaussUtils\""
464        Execute/P "INSERTINCLUDE \"WriteModelData\""
465       
466        NVAR doCheck=root:myGlobals:FileList:checkForFiles
467       
468        ii=num-1                //work bottom-up to not lose the index
469        do
470                if(sel[ii] == 1)
471                        //can I make sure the file exists before trying to include it?
472                        if(doCheck)
473                                ok = CheckFileInUPFolder(fileWave[ii])
474                        endif
475                        if(ok || !doCheck)
476                                fname = RemoveExten(fileWave[ii])       
477                                Execute/P "INSERTINCLUDE \""+fname+"\""
478                                // add to the already included list, and remove from the to-include list (and selWaves also)
479                                InsertPoints numpnts(includedFileWave), 1, includedFileWave,selToDel
480                                includedFileWave[numpnts(includedFileWave)-1]=fileWave[ii]
481                               
482                                DeletePoints ii, 1, fileWave,sel
483                        else
484                                DoAlert 0,"File "+fileWave[ii]+" was not found in the User Procedures folder, so it was not included"
485                        endif
486                endif
487                ii-=1
488        while(ii>=0)
489        Execute/P "COMPILEPROCEDURES ";Execute/P/Q/Z "RefreshMenu()"
490       
491        sel=0           //clear the selections
492        selToDel=0
493       
494        return(0)
495End
496
497Function FileList_RemoveButtonProc(ctrlName) : ButtonControl
498        String ctrlName
499       
500        //loop through the selected files in the list...
501        Wave/T includedFileWave=$"root:myGlobals:FileList:includedFileWave"
502        Wave selToDel=$"root:myGlobals:FileList:selToDelWave"
503        // and put the unwanted procedures back in the to-add list
504        Wave/T fileWave=$"root:myGlobals:FileList:fileWave"
505        Wave sel=$"root:myGlobals:FileList:selWave"
506       
507       
508        Variable num=numpnts(selToDel),ii
509        String fname=""
510       
511        ii=num-1                //work backwards
512        do
513                if(selToDel[ii] == 1)
514                        fname = RemoveExten(includedFileWave[ii])
515                        Execute/P "DELETEINCLUDE \""+fname+"\""
516                        //add to the to-include list
517                        InsertPoints numpnts(fileWave), 1, fileWave,sel
518                        fileWave[numpnts(fileWave)-1]=includedFileWave[ii]
519                        //delete the point
520                        DeletePoints ii, 1, includedFileWave,selToDel
521                endif
522                ii-=1
523        while(ii>=0)
524        Execute/P "COMPILEPROCEDURES ";Execute/P/Q/Z "RefreshMenu()"
525       
526        sel=0
527        selToDel=0
528       
529        Sort filewave,filewave
530        return(0)
531End
532
533
534//removes ANY ".ext" extension from the name
535// - wipes out all after the "dot"
536// - procedure files to be included (using quotes) must be in User Procedures folder
537// and end in .ipf?
538Function/S RemoveExten(str)
539        String str
540       
541        Variable loc=0
542        String tempStr=""
543       
544        loc=strsearch(str,".",0)
545        tempStr=str[0,loc-1]
546        return(tempStr)
547End
548
549// function to have user select the path where the procedure files are
550//      - the selected path is set as procPathName
551//
552// setting the path to "igor" does not seem to have the desired effect of
553// bringing up the Igor Pro folder in the NewPath Dialog
554//
555//may also be able to use folder lists on HD - for more sophisticated listings
556Function PickProcPath()
557       
558        //set the global string to the selected pathname
559        PathInfo/S Igor
560       
561        NewPath/O/M="pick the SANS Procedure folder" procPathName
562        return(0)               //no error
563End
564
565
566//my menu, seemingly one item, but really a long string for each submenu
567// if root:MenuItemStr exists
568Menu "SANS Models"
569        StrVarOrDefault("root:myGlobals:FileList:MenuItemStr_def","ModelPicker_Panel")//, RefreshMenu()
570        SubMenu "Unsmeared Models"
571                StrVarOrDefault("root:myGlobals:FileList:MenuItemStr1","ModelPicker_Panel")
572        End
573        SubMenu "Smeared Models"
574                StrVarOrDefault("root:myGlobals:FileList:MenuItemStr2","ModelPicker_Panel")
575        End
576//      SubMenu "Models 3"
577//              StrVarOrDefault("root:MenuItemStr3","ModelPicker_Panel")
578//      End
579End
580
581//wrapper to use the A_ prepended file loader from the dynamically defined menu
582Proc LoadSANSorUSANSData()
583        A_LoadOneDData()
584End
585
586// tweaked to find RPA model which has an extra parameter in the declaration
587Function RefreshMenu()
588
589        String list="",sep=";"
590       
591        //list = "Refresh Menu"+sep+"ModelPicker_Panel"+sep+"-"+sep
592        list = "ModelPicker_Panel"+sep+"-"+sep
593//      list += MacroList("LoadO*",sep,"KIND:1,NPARAMS:0")              //data loader
594        list += "Load SANS or USANS Data;"              //use the wrapper above to get the right loader
595        list += "Reset Resolution Waves;"               // resets the resolution waves used for the calculations
596        list += "Freeze Model;"                                         // freeze a model to compare plots on the same graph
597        list += MacroList("WriteM*",sep,"KIND:1,NPARAMS:4")             //data writer
598        list += "-"+sep
599        String/G root:myGlobals:FileList:MenuItemStr_def = TrimListTo255(list)
600       
601        list = ""
602        list += MacroList("*",sep,"KIND:1,NPARAMS:3")                           //unsmeared plot procedures
603        list += MacroList("Plot*",sep,"KIND:1,NPARAMS:4")                               //RPA has 4 parameters
604        list = RemoveFromList("FreezeModel", list ,";")                 // remove FreezeModel, it's not a model
605        //      list += "-"+sep
606        String/G root:myGlobals:FileList:MenuItemStr1 = TrimListTo255(list)
607
608        list=""
609        list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:1")                   //smeared plot procedures
610        list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:2")                   //smeared RPA has 2 parameters
611        String/G root:myGlobals:FileList:MenuItemStr2 = TrimListTo255(list)
612
613        BuildMenu "SANS Models"
614       
615        return(0)
616End
617
618//if the length of any of the strings is more than 255, the menu will disappear
619Function/S TrimListTo255(list)
620        String list
621       
622        Variable len,num
623        num = itemsinlist(list,";")
624        len = strlen(list)
625        if(len>255)
626                DoAlert 0, "Not all menu items are shown - remove some of the models"
627                do
628                        list = RemoveListItem(num-1, list  ,";" )
629                        len=strlen(list)
630                        num=itemsinlist(list,";")
631                while(len>255)
632        endif
633        return(list)
634End
635
636Function/S MP_TextWave2SemiList(textW)
637        Wave/T textW
638       
639        String list=""
640        Variable num=numpnts(textW),ii=0
641        do
642                list += textw[ii] + ";"
643                ii+=1
644        while(ii<num)
645        return(list)
646End
647
648Function MP_SemiList2TextWave(list,outWStr)
649        String list,outWStr
650       
651        Variable num=itemsinList(list)
652        Make/T/O/N=(num) $outWStr
653        WAVE/T w=$outWStr
654        w = StringFromList(p,list,";")
655        return(0)
656End
657
658//modified to get a list of all files in folder and subfolders
659// passed back through a global variable
660Function ListAllFilesAndFolders(pathName, full, recurse, level)
661        String pathName         // Name of symbolic path in which to look for folders.
662        Variable full                   // True to print full paths instead of just folder name.
663        Variable recurse                // True to recurse (do it for subfolders too).
664        Variable level          // Recursion level. Pass 0 for the top level.
665       
666        Variable ii
667        String prefix
668       
669        SVAR allFiles=root:myGlobals:FileList:allFiles
670        // Build a prefix (a number of tabs to indicate the folder level by indentation)
671        prefix = ""
672        ii = 0
673        do
674                if (ii >= level)
675                        break
676                endif
677                prefix += "\t"                                  // Indent one more tab
678                ii += 1
679        while(1)
680       
681//      Printf "%s%s\r", prefix, pathName
682//      Print IndexedFile($pathName,-1,"????")
683        allFiles += IndexedFile($pathName,-1,"????")
684       
685        String path
686        ii = 0
687        do
688                path = IndexedDir($pathName, ii, full)
689                if (strlen(path) == 0)
690                        break                                                   // No more folders
691                endif
692//              Printf "%s%s\r", prefix, path
693               
694                if (recurse)                                            // Do we want to go into subfolder?
695                        String subFolderPathName = "tempPrintFoldersPath_" + num2istr(level+1)
696                       
697                        // Now we get the path to the new parent folder
698                        String subFolderPath
699                        if (full)
700                                subFolderPath = path    // We already have the full path.
701                        else
702                                PathInfo $pathName              // We have only the folder name. Need to get full path.
703                                subFolderPath = S_path + path
704                        endif
705                       
706                        NewPath/Q/O $subFolderPathName, subFolderPath
707                        ListAllFilesAndFolders(subFolderPathName, full, recurse, level+1)
708                        KillPath/Z $subFolderPathName
709                endif
710               
711                ii += 1
712        while(1)
713End
714
715
716// utility function to get the list of all functions
717// first - select and include all of the models
718//
719Proc GetAllModelFunctions()
720        String str =  FunctionList("*",";","KIND:10,NINDVARS:1")
721        Print itemsinList(str)
722
723        MP_SemiList2TextWave(str,"UserFunctionList")
724        edit UserFunctionList
725end
726
727// allows an easy way to "freeze" a model calculation
728// - duplicates X and Y waves (tags them _q and _i)
729// - kill the dependecy
730// - append it to the top graph
731// - it can later be exported with WriteModelData
732//
733// in Igor 5, you can restrict the WaveList to be just the top graph...
734// SRK  09 JUN 2006
735//
736Proc FreezeModel(xWave,yWave,newNameStr)
737        String xWave,yWave,newNameStr
738        Prompt xwave,"X data",popup,WaveList("*",";","")
739        Prompt ywave,"y data",popup,WaveList("*",";","")
740        Prompt newNameStr,"new name for the waves, _q and _i will be appended"
741       
742        Duplicate/O $xwave,$(newNameStr+"_q")
743        Duplicate/O $ywave,$(newNameStr+"_i")
744        SetFormula $(newNameStr+"_i"), ""
745       
746        AppendToGraph $(newNameStr+"_i") vs $(newNameStr+"_q")
747       
748End
Note: See TracBrowser for help on using the repository browser.