source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Packages/ModelPicker/SANSModelPicker_v40.ipf @ 1010

Last change on this file since 1010 was 1010, checked in by srkline, 6 years ago

adding conditional compile checks to be sure that the XOPs are present for the version of Igor that is running. If XOPs are not present, user is notified.

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