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

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

Template is now aware of the utilities for 2D fitting, and the Cylinder_2D model is on the list of functions that can be included from the Picker.

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