source: sans/Release/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Packages/ModelPicker/SANSModelPicker_v40.ipf @ 381

Last change on this file since 381 was 381, checked in by srkline, 14 years ago

Merging Dev/trunk revision 374+ into Release/trunk for version 6.004

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