source: User Procedures/Irena/IR1_Main.ipf @ 6

Last change on this file since 6 was 6, checked in by ilavsky, 9 years ago

Initial commit - beta version 2.51

File size: 94.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=2.51
3
4
5//*************************************************************************\
6//* Copyright (c) 2005 - 2013, Argonne National Laboratory
7//* This file is distributed subject to a Software License Agreement found
8//* in the file LICENSE that is included with this distribution.
9//*************************************************************************/
10
11//2.51 added Guinier-Porod model (beta version of the tool)
12//2.50 major update, added uncertainity estimation to Sizes and Modeling II. Reflectivity changes.
13//2.49 Minor fixes
14//2.48 Fixed GUI font/size issues on WIndows 7, Plotting tool I 3D upgrades, moved Modeling I to "Other tools"
15//2.47 New mailing list, movie & 3D graphs in Plotting tool I and other many fixes.
16//2.46 lots of small fixes, added easy access to scripting tool and few other changes.
17//2.45 Added features to Data manipulation II and Reflectivity. Updated manual.
18//2.44 minor fix Modeling II, Addition of controls of Modeling II to Scripting tool, other fixes.
19//2.43 add functions to handle modified panels between updates.
20//2.41 and 2.42, minor updates
21//2.40 added Unified level as Form factor and other fixes and improvements
22//2.39 added license for ANL
23
24
25// from version 2.26 I skipped numbers to match the current Irena version number (2.38)
26
27//This macro file is part of Igor macros package called "Irena",
28//the full package should be available from www.uni.aps.anl.gov/~ilavsky
29//this package contains
30// Igor functions for modeling of SAS from various distributions of scatterers...
31
32//Jan Ilavsky, February 2010
33
34//please, read Readme in the distribution zip file with more details on the program
35//report any problems to: ilavsky@aps.anl.gov
36
37
38//main functions.
39//Comment for me: Limit yourself to less than 30 items in the menu, Windows are limited to 30 items. Note: "---" counts as one item!
40
41//define manul date
42constant CurrentManualDateInSecs=  3439748159                   //this is mod date for Manual version 2.50
43constant CurrentVersionNumber = 2.50
44
45
46Menu "SAS"
47        help = {"Irena SAS modeling macros, version 2.50 released 1/4/2013 by Jan Ilavsky"}
48        Submenu "Data import & export"
49                "Import ASCII data", IR1I_ImportDataMain()
50                help={"Import data from ASCII file into Igor for use with macros"}
51                "Import XML data", CS_XMLGUIImportDataMain(defaultType="QRS",defaultQUnits="1/A")
52                help={"Import data from CanSAS 1.0 conforming data sets"}
53                "Export ASCII data", IR2E_UniversalDataExport()
54                help = {"This is tool for export of any 2-3 column data sets as ASCII."}
55        End
56        "---"
57        Submenu "Data Manipulation"
58                "Data manipulation I [one or two data sets]",  IR1D_DataManipulation()
59                help={"Merge data sets, rebin for same Q, etc..."}
60                "Data manipulation II [many data sets]", IR3M_DataManipulationII()
61                help={"Manipulate - for now only average - many data sets"}
62                "Data mining", IR2M_GetDataMiner()
63                help={"Data miner to find various data and plot various waves"}
64        end
65        "---"
66        "Plotting I", IR1P_GeneralPlotTool()
67        help = {"Plotting tool with wide functionality, hopefully"}
68        "Plotting II", IR2D_DWSPlotToolMain()
69        help = {"Plotting tool which controls any top graph"}
70                SubMenu "Support Tools for plots"
71                "Draw Line Of Any Slope", IR2P_DrawLineOfAnySlope()
72                "Draw Line Of -4 Slope",  IR2P_DrawLineOf4Slope()
73                "Draw Line Of -3 Slope",  IR2P_DrawLineOf3Slope()
74                "Draw Line Of -2 Slope",  IR2P_DrawLineOf2Slope()
75                "Make log-log graph decade limits", IR2P_MakeLogLogGraphDecLim()
76                "--"
77                "Fit Line With Cursors", IR2P_FitLineWithCursors()
78                "Fit Power Law with Cursors", IR2P_FitPowerLawWithCursors()
79                End
80        "---"
81        "Unified Fit", IR1A_UnifiedModel()
82        help = {"Modeling of SAS by modeling Guinier and Power law dependecies, based on Unified model by Gregg Beaucage"}
83        "Size Distribution", IR1R_Sizes()
84        help = {"SAS evaluation by regularization and maximum entropy fitting using spheroids"}
85        "Modeling II",IR2L_Main()
86        help = {"Complicated modeling of SAS with Least square fitting or genetic optimization, allows multiple data input and is much more flexible than LSqF. Much more complicated also!)"}
87        "Gunier Porod Fit", IR3GP_Main()
88        help = {"Modeling of SAS as Guinier and Power law dependecies, based on Gunier-Porod model by Bualem Hammouda"}
89        "Fractals model", IR1V_FractalsModel()
90        help = {"Modeling of SAS by combining mass and surface fractal dependecies, based on model by Andrew Allen"}
91        "Analytical models", IR2H_GelsMainFnct()
92        help={"Debye-Bueche, Teubner-Strey model"}
93        "Small-Angle Diffraction", IR2D_MainSmallAngleDiff()
94        help={"Modeling of small angle diffraction - up to 6 peaks and Powerlaw background"}
95        "Pair distance dist. fnct.", IR2Pr_MainPDDF()
96        help={"Calculate pair distribution function using various methods"}
97        "Reflectivity", IR2R_ReflectivitySimpleToolMain()
98        help={"Simple reflectivity model using Parrat's recursive code."}
99        "---"
100        "Scattering contrast calculator", IR1K_ScattCont2()
101        help={"Calculator for scattering contrast. Both X rays and neutrons. Anomalous effects available."}
102        "Configure default fonts and names",IR2C_ConfigMain()
103        help={"Configure default values for GUI Panels and Graph common items, such as font sizes and font types"}
104                SubMenu "Support and Older tools"
105                        "Evaluate Size Distributions", IR1G_EvaluateONESample()
106                        help = {"Not fully finished GUI to evaluate results from methods producing size distributions"}
107                        "Scripting tool",  IR2S_ScriptingTool()
108                        help = {"Scripting tool enabes to run some tools on multiple data sets."}
109                        "Modeling I", IR1S_LSQF_StandardModelsMain()
110                        help = {"Modeling of SAS by modeling distributions (Gauss, LogNormal) of scatterers (spheroids, spheres,cylinders,tubes' core-shell). Uses Least Squuare fitting or Genetic optimization."}
111                        "Modeling I, user models", IR1U_LSQF_UserModelsMain()
112                        help = {"Modeling of SAS with user provided distributions (probability/diameter) for scatterers (spheroids, spheres,cylinders, tubes, core-shell). Uses Least square fitting. "}
113                end
114                SubMenu "Other tools"
115                        "Desmearing", IR1B_DesmearingMain()
116                        help={"Remove slit smearing using Lake method"}
117                        "Show Results notebook", IR1_CreateResultsNbk()
118                        help={"Shows notebook in which tools can create record of the results with graphs"}
119                        "Create QRS folder structure", IR1F_CreateFldrStrctMain()
120                        help={"Create folder structure for users with QRS data in one folder, so Irena can work well"}
121                        "Show SAS logbook", IR1_PullUpLoggbook()
122                        help = {"Some of these macros make ongoing record of what is done, you'll find it here..."}
123                        "Export To XLS File Panel", ExportToXLSFilePanel()
124                        help={"This is tool for Unified fit, made by Gragg Beaucage. For help, contact him..."}
125                End
126                Submenu "Help, About, Manuals, Remove Irena"
127                        "About", IR1_AboutPanel()
128                        help={"Get Panel with info about this release of Irena macros"}
129                        "Open Irena pdf manual", IR2_OpenIrenaManual()
130                        help={"Opens your pdf reader (Acrobat) with Irena manual in it"}
131                        "Open Form and Structure Factor description", IR2T_LoadFFDescription()
132                        help={"Opens Description of included form factors and structure factors"}
133                        "Open Irena manuscript", IR2_GetIrenaManuscript()
134                        help={"Open or download using ftp and open Irena J. Appl. Cryst manuscript"}
135                        "---"
136                        "Irena Mailing list signup and options", IR2_SignUpForMailingList()
137                        help={"Opens web page in the browser where you can sing up or control options for Irena_users mailing list."}
138                        "Open Web page with help movies", IR2_OpenHelpMoviePage()
139                        help={"Opens web page in the browser where different movies showing use of Irena can be downloaded"}
140                        "Open Irena Web page ", IR2_OpenIrenaPage()
141                        help={"Opens Irena web page in the browser "}
142                        "Submit e-mail with bug or feature request", IR2C_SendEMailBugReport()
143                        help={"This will open your e-mail browser with some info and address. Use to submit info to me. "}
144                        "---"
145                        "Kill all Irena panels and graphs", IR1_KillGraphsAndPanels()
146                        help = {"If you have just too much mess with many open panels and graphs, this will close them all..."}
147                        "Remove Irena Package", IR1_RemoveSASMac()
148                        help={"Removes Irena macros from current Igor experiment"}
149                end
150end
151
152
153
154//****************************************************************************************
155//****************************************************************************************
156//****************************************************************************************
157
158static Function AfterCompiledHook( )                    //check if all windows are up to date to match their code
159
160        //these are tools which have been upgraded to this functionality
161        //Modeling II = LSQF2_MainPanel
162        string WindowProcNames="LSQF2_MainPanel=IR2L_MainCheckVersion;IR2H_ControlPanel=IR2H_MainCheckVersion;DataMiningTool=IR2M_MainCheckVersion;DataManipulationII=IR3M_MainCheckVersion;"
163        WindowProcNames+="IR1I_ImportData=IR1I_MainCheckVersion;IR2S_ScriptingToolPnl=IR2S_MainCheckVersion;IR1R_SizesInputPanel=IR1R_MainCheckVersion;IR1A_ControlPanel=IR1A_MainCheckVersion;"
164        WindowProcNames+="IR1P_ControlPanel=IR1P_MainCheckVersion;IR2R_ReflSimpleToolMainPanel=IR2R_MainCheckVersion;IR3DP_MainPanel=IR3GP_MainCheckVersion;"
165        WindowProcNames+="IR1V_ControlPanel=IR1V_MainCheckVersion;IR2D_ControlPanel=IR2D_MainCheckVersion;IR2Pr_ControlPanel=IR2Pr_MainCheckVersion;UnivDataExportPanel=IR2E_MainCheckVersion;"
166        WindowProcNames+="IR1D_DataManipulationPanel=IR1D_MainCheckVersion;"
167       
168        IR2C_CheckWIndowsProcVersions(WindowProcNames)
169
170end
171//****************************************************************************************
172//****************************************************************************************
173
174Function IR2C_CheckWIndowsProcVersions(WindowProcNames)
175        string WindowProcNames
176       
177        variable i 
178        string PanelName
179        String ProcedureName
180        For(i=0;i<ItemsInList(WindowProcNames);i+=1)
181                PanelName = StringFromList(0, StringFromList(i, WindowProcNames, ";")  , "=")
182                ProcedureName = StringFromList(1, StringFromList(i, WindowProcNames, ";")  , "=")
183                DoWIndow $(PanelName)
184                if(V_Flag)
185                        Execute (ProcedureName+"()")
186                endif
187        endfor
188       
189end
190///////////////////////////////////////////
191//****************************************************************************************
192//              Default variables and strings
193//
194//      these are known at this time:
195//              Variables=LegendSize;TagSize;AxisLabelSize;
196//              Strings=FontType;
197//
198//      how to use:
199//      When needed insert font size through lookup function - e.g., IR2C_LkUpDfltVar("LegendSize")
200//      or for font type IR2C_LkUpDfltStr("FontType")
201//      NOTE: Both return string values, because that is what is generally needed!!!!
202// further variables and strings can be added, but need to be added to control panel too...
203//      see example in : IR1_LogLogPlotU()  in this procedure file...
204
205
206Function/S IR2C_LkUpDfltStr(StrName)
207        string StrName
208
209        string result
210        string OldDf=getDataFolder(1)
211        SetDataFolder root:
212        if(!DataFolderExists("root:Packages:IrenaConfigFolder"))
213                IR2C_InitConfigMain()
214        endif
215        SetDataFolder root:Packages
216        setDataFolder root:Packages:IrenaConfigFolder
217        SVAR /Z curString = $(StrName)
218        if(!SVAR_exists(curString))
219                IR2C_InitConfigMain()
220                SVAR curString = $(StrName)
221        endif   
222        result =        "'"+curString+"'"
223        setDataFolder OldDf
224        return result
225end
226
227Function/S IR2C_LkUpDfltVar(VarName)
228        string VarName
229
230        string result
231        string OldDf=getDataFolder(1)
232        SetDataFolder root:
233        if(!DataFolderExists("root:Packages:IrenaConfigFolder"))
234                IR2C_InitConfigMain()
235        endif
236        SetDataFolder root:Packages
237        setDataFolder root:Packages:IrenaConfigFolder
238        NVAR /Z curVariable = $(VarName)
239        if(!NVAR_exists(curVariable))
240                IR2C_InitConfigMain()
241                NVAR curVariable = $(VarName)
242        endif   
243        if(curVariable>=10)
244                result = num2str(       curVariable)
245        else
246                result = "0"+num2str(   curVariable)
247        endif
248        setDataFolder OldDf
249        return result
250end
251//***********************************************************
252//***********************************************************
253//***********************************************************
254//***********************************************************
255//***********************************************************
256Function UpdatePanelVersionNumber(panelName, CurentProcVersion)
257        string panelName
258        variable CurentProcVersion
259        DoWIndow $panelName
260        if(V_Flag)
261                SetWindow $(panelName), note="IrenaProcVersion:"+num2str(CurentProcVersion)+";"
262//              print "Saved To panel note ;    "+"IrenaProcVersion:"+num2str(CurentProcVersion)+";"
263        endif
264end
265
266Function CheckPanelVersionNumber(panelName, CurentProcVersion)
267        string panelName
268        variable CurentProcVersion
269
270        DoWIndow $panelName
271        if(V_Flag)     
272                GetWindow $(panelName), note
273//              print "Found :     "+S_Value
274                if(stringmatch(stringbyKey("IrenaProcVersion",S_value),num2str(CurentProcVersion))) //matches
275                        return 1
276                else
277                        return 0
278                endif
279        else
280                return 1
281        endif
282end
283
284//***********************************************************
285//***********************************************************
286//***********************************************************
287//***********************************************************
288//***********************************************************
289
290Function IR2C_ConfigMain()              //call configuration routine
291
292        //this is main configuration utility...
293        IR2C_InitConfigMain()
294        DoWindow IR2C_MainConfigPanel
295        if(!V_Flag)
296                Execute ("IR2C_MainConfigPanel()")
297        else
298                DoWindow/F IR2C_MainConfigPanel
299        endif
300        IR2C_ReadIrenaGUIPackagePrefs()
301end
302
303//***********************************************************
304//***********************************************************
305//***********************************************************
306//***********************************************************
307//***********************************************************
308structure IrenaPanelDefaults
309        uint32 version                                  // Preferences structure version number. 100 means 1.00.
310        uchar LegendFontType[50]                //50 characters for legend font name
311        uchar PanelFontType[50]         //50 characters for panel font name
312        uint32 defaultFontSize                  //font size as integer
313        uint32 LegendSize                               //font size as integer
314        uint32 TagSize                                  //font size as integer
315        uint32 AxisLabelSize                    //font size as integer
316        int16 LegendUseFolderName               //font size as integer
317        int16 LegendUseWaveName         //font size as integer
318        uint32 reserved[100]                    // Reserved for future use
319       
320endstructure
321
322//***********************************************************
323//***********************************************************
324//***********************************************************
325//***********************************************************
326//***********************************************************
327
328Function IR2C_ReadIrenaGUIPackagePrefs()
329
330        struct  IrenaPanelDefaults Defs
331        IR2C_InitConfigMain()
332        SVAR DefaultFontType=root:Packages:IrenaConfigFolder:DefaultFontType
333        NVAR DefaultFontSize=root:Packages:IrenaConfigFolder:DefaultFontSize
334        NVAR LegendSize=root:Packages:IrenaConfigFolder:LegendSize
335        NVAR TagSize=root:Packages:IrenaConfigFolder:TagSize
336        NVAR AxisLabelSize=root:Packages:IrenaConfigFolder:AxisLabelSize
337        NVAR LegendUseFolderName=root:Packages:IrenaConfigFolder:LegendUseFolderName
338        NVAR LegendUseWaveName=root:Packages:IrenaConfigFolder:LegendUseWaveName
339        SVAR FontType=root:Packages:IrenaConfigFolder:FontType
340        LoadPackagePreferences /MIS=1   "Irena" , "IrenaDefaultPanelControls.bin", 0 , Defs
341        if(V_Flag==0)           
342                //print Defs
343                print "Read Irena Penals and graphs preferences from local machine and applied them. "
344                print "Note that this may have changed font size and type selection originally saved with the existing experiment."
345                print "To change them please use \"Configure default fonts and names\""
346                if(Defs.Version==1)             //Lets declare the one we know as 1
347                        DefaultFontType=Defs.PanelFontType
348                        DefaultFontSize = Defs.defaultFontSize
349                        if (stringMatch(IgorInfo(2),"*Windows*"))               //Windows
350                                DefaultGUIFont /Win   all= {DefaultFontType, DefaultFontSize, 0 }
351                        else
352                                DefaultGUIFont /Mac   all= {DefaultFontType, DefaultFontSize, 0 }
353                        endif
354                        //and now recover the stored other parameters, no action on these...
355                         LegendSize=Defs.LegendSize
356                         TagSize=Defs.TagSize
357                         AxisLabelSize=Defs.AxisLabelSize
358                         LegendUseFolderName=Defs.LegendUseFolderName
359                         LegendUseWaveName=Defs.LegendUseWaveName
360                         FontType=Defs.LegendFontType
361                else
362                        DoAlert 1, "Old version of GUI and Graph Fonts (font size and type preference) found. Do you want to update them now? These are set once on a computer and can be changed in \"Configure default fonts and names\""
363                        if(V_Flag==1)
364                                Execute("IR2C_MainConfigPanel() ")
365                        else
366                        //      SavePackagePreferences /Kill   "Irena" , "IrenaDefaultPanelControls.bin", 0 , Defs      //does not work below 6.10
367                        endif
368                endif
369        else            //problem loading package defaults
370                DoAlert 1, "GUI and Graph defaults (font size and type preferences) are not set. Do you want to set them now? These are set once on a computer and can be changed in \"Configure default fonts and names\" dialog"
371                if(V_Flag==1)
372                        Execute("IR2C_MainConfigPanel() ")
373                endif   
374        endif
375end
376//***********************************************************
377//***********************************************************
378//***********************************************************
379//***********************************************************
380//***********************************************************
381Function IR2C_SaveIrenaGUIPackagePrefs(KillThem)
382        variable KillThem
383       
384        struct  IrenaPanelDefaults Defs
385        IR2C_InitConfigMain()
386        SVAR DefaultFontType=root:Packages:IrenaConfigFolder:DefaultFontType
387        NVAR DefaultFontSize=root:Packages:IrenaConfigFolder:DefaultFontSize
388        NVAR LegendSize=root:Packages:IrenaConfigFolder:LegendSize
389        NVAR TagSize=root:Packages:IrenaConfigFolder:TagSize
390        NVAR AxisLabelSize=root:Packages:IrenaConfigFolder:AxisLabelSize
391        NVAR LegendUseFolderName=root:Packages:IrenaConfigFolder:LegendUseFolderName
392        NVAR LegendUseWaveName=root:Packages:IrenaConfigFolder:LegendUseWaveName
393        SVAR FontType=root:Packages:IrenaConfigFolder:FontType
394
395        Defs.Version                    =               1
396        Defs.PanelFontType              =               DefaultFontType
397        Defs.defaultFontSize    =               DefaultFontSize
398        Defs.LegendSize                         =               LegendSize
399        Defs.TagSize                    =               TagSize
400        Defs.AxisLabelSize              =               AxisLabelSize
401        Defs.LegendUseFolderName =      LegendUseFolderName
402        Defs.LegendUseWaveName =                LegendUseWaveName
403        Defs.LegendFontType     =               FontType
404       
405        if(KillThem)
406        //      SavePackagePreferences /Kill   "Irena" , "IrenaDefaultPanelControls.bin", 0 , Defs              //does nto work below 6.10
407        //      IR2C_ReadIrenaGUIPackagePrefs()
408        else
409                SavePackagePreferences /FLSH=1   "Irena" , "IrenaDefaultPanelControls.bin", 0 , Defs
410        endif
411end
412//***********************************************************
413//***********************************************************
414//***********************************************************
415//***********************************************************
416//***********************************************************
417
418Function IR2C_InitConfigMain()
419
420        //initialize lookup parameters for user selected items.
421        string OldDf=getDataFolder(1)
422        SetDataFolder root:
423        NewDataFolder/O/S root:Packages
424        NewDataFolder/O/S root:Packages:IrenaConfigFolder
425       
426        string ListOfVariables
427        string ListOfStrings
428        //here define the lists of variables and strings needed, separate names by ;...
429        ListOfVariables="LegendSize;TagSize;AxisLabelSize;LegendUseFolderName;LegendUseWaveName;DefaultFontSize;"
430        ListOfStrings="FontType;ListOfKnownFontTypes;DefaultFontType;"
431        variable i
432        //and here we create them
433        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
434                IN2G_CreateItem("variable",StringFromList(i,ListOfVariables))
435        endfor         
436                                                                               
437        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
438                IN2G_CreateItem("string",StringFromList(i,ListOfStrings))
439        endfor 
440        //Now set default values
441        String VariablesDefaultValues
442        String StringsDefaultValues
443        if (stringMatch(IgorInfo(2),"*Windows*"))               //Windows
444                VariablesDefaultValues="LegendSize:8;TagSize:8;AxisLabelSize:8;LegendUseFolderName:0;LegendUseWaveName:0;"
445        else
446                VariablesDefaultValues="LegendSize:10;TagSize:10;AxisLabelSize:10;LegendUseFolderName:0;LegendUseWaveName:0;"
447        endif
448        StringsDefaultValues="FontType:"+StringFromList(0, IR2C_CreateUsefulFontList() ) +";"
449
450        variable CurVarVal
451        string CurVar, CurStr, CurStrVal
452        For(i=0;i<ItemsInList(VariablesDefaultValues);i+=1)
453                CurVar = StringFromList(0,StringFromList(i, VariablesDefaultValues),":")
454                CurVarVal = numberByKey(CurVar, VariablesDefaultValues)
455                NVAR temp=$(CurVar)
456                if(temp==0)
457                        temp = CurVarVal
458                endif
459        endfor
460        For(i=0;i<ItemsInList(StringsDefaultValues);i+=1)
461                CurStr = StringFromList(0,StringFromList(i, StringsDefaultValues),":")
462                CurStrVal = stringByKey(CurStr, StringsDefaultValues)
463                SVAR tempS=$(CurStr)
464                if(strlen(tempS)<1)
465                        tempS = CurStrVal
466                endif
467        endfor
468       
469        SVAR ListOfKnownFontTypes=ListOfKnownFontTypes
470        ListOfKnownFontTypes=IR2C_CreateUsefulFontList()
471        setDataFolder OldDf
472end
473
474//***********************************************************
475//***********************************************************
476//***********************************************************
477//***********************************************************
478//***********************************************************
479Function IR2C_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl
480        String ctrlName
481        Variable popNum
482        String popStr
483       
484        if (cmpstr(ctrlName,"LegendSize")==0)
485                NVAR LegendSize=root:Packages:IrenaConfigFolder:LegendSize
486                LegendSize = str2num(popStr)
487        endif
488        if (cmpstr(ctrlName,"TagSize")==0)
489                NVAR TagSize=root:Packages:IrenaConfigFolder:TagSize
490                TagSize = str2num(popStr)
491        endif
492        if (cmpstr(ctrlName,"AxisLabelSize")==0)
493                NVAR AxisLabelSize=root:Packages:IrenaConfigFolder:AxisLabelSize
494                AxisLabelSize = str2num(popStr)
495        endif
496        if (cmpstr(ctrlName,"FontType")==0)
497                SVAR FontType=root:Packages:IrenaConfigFolder:FontType
498                FontType = popStr
499        endif
500        if (cmpstr(ctrlName,"DefaultFontType")==0)
501                SVAR DefaultFontType=root:Packages:IrenaConfigFolder:DefaultFontType
502                DefaultFontType = popStr
503                IR2C_ChangePanelCOntrolsStyle()
504        endif
505        if (cmpstr(ctrlName,"DefaultFontSize")==0)
506                NVAR DefaultFontSize=root:Packages:IrenaConfigFolder:DefaultFontSize
507                DefaultFontSize = str2num(popStr)
508                IR2C_ChangePanelCOntrolsStyle()
509        endif
510        IR2C_SaveIrenaGUIPackagePrefs(0)
511End
512//***********************************************************
513//***********************************************************
514//***********************************************************
515//***********************************************************
516//***********************************************************
517Function IR2C_KillPrefsButtonProc(ba) : ButtonControl
518        STRUCT WMButtonAction &ba
519
520        switch( ba.eventCode )
521                case 2: // mouse up
522                        // click code here
523                        if(stringmatch(ba.ctrlName,"OKBUtton"))
524                                DoWIndow/K IR2C_MainConfigPanel
525                        elseif(stringmatch(ba.ctrlName,"DefaultValues"))
526                                string defFnt
527                                variable defFntSize
528                                if (stringMatch(IgorInfo(2),"*Windows*"))               //Windows
529                                        defFnt=stringFromList(0,IR2C_CreateUsefulFontList())
530                                        defFntSize=12
531                                else
532                                        defFnt="Geneva"
533                                        defFntSize=9
534                                endif
535                                SVAR ListOfKnownFontTypes=root:Packages:IrenaConfigFolder:ListOfKnownFontTypes
536                                SVAR DefaultFontType=root:Packages:IrenaConfigFolder:DefaultFontType
537                                DefaultFontType = defFnt
538                                NVAR DefaultFontSize=root:Packages:IrenaConfigFolder:DefaultFontSize
539                                DefaultFontSize = defFntSize
540                                IR2C_ChangePanelCOntrolsStyle()
541                                IR2C_SaveIrenaGUIPackagePrefs(0)
542                                PopupMenu DefaultFontType,win=IR2C_MainConfigPanel, mode=(1+WhichListItem(defFnt, ListOfKnownFontTypes))
543                                PopupMenu DefaultFontSize,win=IR2C_MainConfigPanel, mode=(1+WhichListItem(num2str(defFntSize), "8;9;10;11;12;14;16;18;20;24;26;30;"))
544                        endif
545                        break
546        endswitch
547        return 0
548End
549
550//***********************************************************
551//***********************************************************
552//***********************************************************
553//***********************************************************
554//***********************************************************
555
556Function IR2C_ChangePanelControlsStyle()
557
558        SVAR DefaultFontType=root:Packages:IrenaConfigFolder:DefaultFontType
559        NVAR DefaultFontSize=root:Packages:IrenaConfigFolder:DefaultFontSize
560
561        if (stringMatch(IgorInfo(2),"*Windows*"))               //Windows
562                DefaultGUIFont /Win   all= {DefaultFontType, DefaultFontSize, 0 }
563        else
564                DefaultGUIFont /Mac   all= {DefaultFontType, DefaultFontSize, 0 }
565        endif
566
567end
568//***********************************************************
569//***********************************************************
570//***********************************************************
571//***********************************************************
572//***********************************************************
573
574Proc IR2C_MainConfigPanel()
575        PauseUpdate; Silent 1           // building window...
576        NewPanel /K=1/W=(282,48,707,356) as "Configure default fonts and names"
577        DoWindow /C IR2C_MainConfigPanel
578        SetDrawLayer UserBack
579        SetDrawEnv fsize= 14,fstyle= 1,textrgb= (0,0,52224)
580        DrawText 10,25,"Irena panels and graphs default fonts and names"
581        SetDrawEnv fsize= 14,fstyle= 3, textrgb= (63500,4369,4369)
582        DrawText 30,53,"Panel and controls font type & size (preference)"
583        SetDrawEnv fsize= 14,fstyle= 3,textrgb= (63500,4369,4369)
584        DrawText 30,150,"Graph text elements"
585//      SVAR ListOfKnownFontTypes=root:Packages:IrenaConfigFolder:ListOfKnownFontTypes
586
587        PopupMenu DefaultFontType,pos={35,65},size={113,21},proc=IR2C_PopMenuProc,title="Panel Controls Font"
588        PopupMenu DefaultFontType,mode=(1+WhichListItem(root:Packages:IrenaConfigFolder:DefaultFontType, root:Packages:IrenaConfigFolder:ListOfKnownFontTypes))
589        PopupMenu DefaultFontType, popvalue=root:Packages:IrenaConfigFolder:DefaultFontType,value= #"IR2C_CreateUsefulFontList()"
590        PopupMenu DefaultFontSize,pos={35,95},size={113,21},proc=IR2C_PopMenuProc,title="Panel Controls Font Size"
591        PopupMenu DefaultFontSize,mode=(1+WhichListItem(num2str(root:Packages:IrenaConfigFolder:DefaultFontSize), "8;9;10;11;12;14;16;18;20;24;26;30;"))
592        PopupMenu DefaultFontSize popvalue=num2str(root:Packages:IrenaConfigFolder:DefaultFontSize),value= #"\"8;9;10;11;12;14;16;18;20;24;26;30;\""
593        Button DefaultValues title="Default",pos={290,70},size={120,20}
594        Button DefaultValues proc=IR2C_KillPrefsButtonProc
595
596        PopupMenu LegendSize,pos={35,165},size={113,21},proc=IR2C_PopMenuProc,title="Legend Size"
597        PopupMenu LegendSize,mode=(1+WhichListItem(num2str(root:Packages:IrenaConfigFolder:LegendSize), "8;9;10;11;12;14;16;18;20;24;26;30;"))
598        PopupMenu LegendSize, popvalue=num2str(root:Packages:IrenaConfigFolder:LegendSize),value= #"\"8;9;10;11;12;14;16;18;20;24;26;30;\""
599//LegendUseFolderName:1;LegendUseWaveName
600        CheckBox LegendUseFolderName,pos={195,165},size={25,16},noproc,title="Legend use Folder Names?"
601        CheckBox LegendUseFolderName,variable= root:Packages:IrenaConfigFolder:LegendUseFolderName, help={"Check to use folder names in legends?"}
602        CheckBox LegendUseWaveName,pos={195,205},size={25,16},noproc,title="Legend use Wave Names?"
603        CheckBox LegendUseWaveName,variable= root:Packages:IrenaConfigFolder:LegendUseWaveName, help={"Check to use wave names in legends?"}
604        PopupMenu TagSize,pos={49,195},size={96,21},proc=IR2C_PopMenuProc,title="Tag Size"
605        PopupMenu TagSize,mode=(1+WhichListItem(num2str(root:Packages:IrenaConfigFolder:TagSize), "8;9;10;11;12;14;16;18;20;24;26;30;"))
606        PopupMenu TagSize,popvalue=num2str(root:Packages:IrenaConfigFolder:TagSize),value= #"\"8;9;10;11;12;14;16;18;20;24;26;30;\""
607        PopupMenu AxisLabelSize,pos={46,225},size={103,21},proc=IR2C_PopMenuProc,title="Label Size"
608        PopupMenu AxisLabelSize,mode=(1+WhichListItem(num2str(root:Packages:IrenaConfigFolder:AxisLabelSize), "8;9;10;11;12;14;16;18;20;24;26;30;"))
609        PopupMenu AxisLabelSize,popvalue=num2str(root:Packages:IrenaConfigFolder:AxisLabelSize),value= #"\"8;9;10;11;12;14;16;18;20;24;26;30;\""
610        PopupMenu FontType,pos={48,255},size={114,21},proc=IR2C_PopMenuProc,title="Font type"
611        PopupMenu FontType,mode=(1+WhichListItem(root:Packages:IrenaConfigFolder:FontType, root:Packages:IrenaConfigFolder:ListOfKnownFontTypes))
612        PopupMenu FontType,popvalue=root:Packages:IrenaConfigFolder:FontType,value= #"root:Packages:IrenaConfigFolder:ListOfKnownFontTypes"
613        Button OKButton title="OK",pos={290,270},size={120,20}
614        Button OKButton proc=IR2C_KillPrefsButtonProc
615
616
617EndMacro
618//***********************************************************
619//***********************************************************
620//***********************************************************
621//***********************************************************
622//***********************************************************
623
624Function/S IR2C_CreateUsefulFontList()
625
626        string SystemFontList=FontList(";")
627        string PreferredFontList="Tahoma;Times;Arial;Geneva;Palatino;Times New Roman;TImes Roman;Book Antiqua;"
628        PreferredFontList+="Courier;Lucida;Vardana;Monaco;Courier CE;System;Verdana;"
629       
630        variable i
631        string UsefulList="", tempList=""
632        For(i=0;i<ItemsInList(PreferredFontList);i+=1)
633                tempList=stringFromList(i,PreferredFontList)
634                if(stringmatch(SystemFOntList, "*"+tempList+";*" ))
635                        UsefulList+=tempList+";"
636                endif
637        endfor
638        return UsefulList
639end
640
641//***********************************************************
642//***********************************************************
643//***********************************************************
644//***********************************************************
645//***********************************************************
646
647Function IR2C_SendEMailBugReport()
648
649        string url, separator
650        if(stringmatch(StringByKey("OS", IgorInfo(3) , ":" , ";"), "*Macintosh*" ))
651                separator="\n"
652        else
653                separator="%0A"
654        endif
655        url="mailto:ilavsky@aps.anl.gov?subject=Irena ver "+num2str(CurrentVersionNumber)+" bug or user comment"
656        url+="&body=The problem or bug occurred on "+separator
657        url+="IgorInfo(0) = "+IgorInfo(0)+separator
658        url+="IgorInfo(3) = "+IgorInfo(3)+separator+separator
659        url+="Please attach notes about the bug or request for new features. If necessary attach your Igor experiment. Thank You J.I."+separator
660        BrowseURL url
661end
662
663//***********************************************************
664//***********************************************************
665//***********************************************************
666//***********************************************************
667//***********************************************************
668///////////////////////////////////////////
669
670Proc IR2P_FitLineWithCursors()
671
672        string destwavename="fit_"+CsrWave(A)
673        CurveFit line CsrWaveRef(A)(xcsr(A),xcsr(B)) /X=CsrXWaveRef(A) /D
674        Tag/C/N=Curvefitres/F=0/A=MC $destwavename, 0.5*numpnts($destwavename), "\Z09Linear fit parameters are: \ry="+num2str(W_coef[0])+"+ x *"+num2str(W_coef[1])
675end
676
677Proc IR2P_FitPowerLawWithCursors()
678
679        string olddf=GetDataFolder(1)
680       
681        if (!DataFolderExists("root:Packages:FittingData:"))
682                NewDataFolder root:Packages:FittingData         //create Desmear folder, if it does not exist
683        endif
684
685        setDataFolder root:Packages:FittingData
686       
687        string name="MyFitWave"
688        string LegendName="Curvefitres"
689       
690        variable freeDestNum=IR2P_FindFreeDestWaveNumber(name)
691        name=name +num2istr(freeDestNum)
692        LegendName=LegendName+num2istr(freeDestNum)
693        Make/D/O/N=(numpnts($(getWavesDataFolder(CsrWaveRef(A),2)))) LogYFitData, $name
694        $name=NaN
695        Make/D/O/N=(numpnts($(getWavesDataFolder(CsrXWaveRef(A),2)))) LogXFitData
696        LogXFitData=log($(getWavesDataFolder(CsrXWaveRef(A),2)))
697        LogYFitData=log($(getWavesDataFolder(CsrWaveRef(A),2)))
698        CurveFit line LogYFitData(xcsr(A),xcsr(B)) /X=LogXFitData /D=$name
699               
700        IR2P_LogPowerWithNaNsRetained($name)
701       
702        //here we will try to figure out, if the data are plotted wrt to leftor right axis...
703        string YwvName=CsrWave(A)
704        string AxType=StringByKey("AXISFLAGS", TraceInfo("",YwvName,0) )//this checks only for first occurence of the wave with this name
705        //this needs to be made more clever, other axis and other occurenc es of the wave with the name...
706        if (cmpstr(AxType,"/R")==0)
707                Append/R $name vs CsrXWaveRef(A)
708        else
709                Append $name vs CsrXWaveRef(A)
710        endif
711        Modify lsize($name)=2
712        String pw=num2str(K1),pr=num2str(10^K0),DIN=num2str((V_siga*10^K0)/2.3026),ca=num2str(pcsr(A)),cb=num2str(pcsr(B)),gf=num2str(V_Pr),DP=num2str(V_sigb)
713        Tag/C/N=$LegendName/F=0/A=MC  $name, (pcsr(A)+pcsr(B))/2, "\Z10Power Law Slope= "+pw+"\Z10 ± "+DP+"\Z08\rPrefactor= "+pr+"\Z08 cm\S-1\M\Z08 ± "+DIN+"\Z08\rx Cursor A::B= "+ca+"\Z08 :: "+cb+"\Z08\rGoodness of fit= "+gf
714
715        KillWaves/Z LogYFitData, LogXFitData
716
717        SetDataFolder $olddf
718end
719
720Function IR2P_FindFreeDestWaveNumber(name)
721        string name
722       
723        variable i=0
724        Do
725                if (exists(name+num2istr(i))==0)
726                        return i
727                endif
728        i+=1
729        while (i<50)
730end
731
732Function IR2P_LogPowerWithNaNsRetained(MyFitWave)
733        wave MyFitWave
734       
735        variable PointsNumber=numpnts(MyFitWave)
736        variable i=0
737        Do
738                if (numtype(MyFitWave[i])==0)
739                        MyFitWave[i]=10^(MyFitWave[i])
740                endif
741        i+=1
742        while (i<PointsNumber)
743end
744//*****************************************
745
746Function IR2P_DrawLineOf3Slope()
747        IR2P_DrawLineOfRequiredSlope(3,3,1,"-3")
748End
749
750//*****************************************
751
752Function IR2P_DrawLineOf2Slope()
753        IR2P_DrawLineOfRequiredSlope(2,2,1,"-2")
754End
755//*****************************************
756
757Function IR2P_DrawLineOf4Slope()
758        IR2P_DrawLineOfRequiredSlope(4,4,1,"-4")
759End
760//*****************************************
761Function IR2P_DrawLineOfAnySlope()
762
763        Variable lineslope,YourNumber,qlabel
764        string label1
765        Prompt lineslope, "Enter slope of line, or select Your number",Popup,"M1;M2;M3;M4;M5;M3.5;M4.5;M2.5;M1.5;Your Number;Vertical;Horizontal;5/3"
766        Prompt YourNumber,"If Your number above selected, enter here a number for the slope:"
767        Prompt qlabel,"Add a Label?",popup,"Power From Above;My own;No"
768        Prompt label1,"If Yes, then here type your label?"
769
770        DoPrompt "Draw line of any slope, select parameters", lineslope, Yournumber, qlabel, label1
771        if (V_Flag)
772                        Abort
773        endif
774        Silent 1
775        do
776                if(lineslope==12)
777                        lineslope=0
778                        break
779                endif
780                if(lineslope==10)
781                        lineslope=YourNumber
782                        break
783                endif
784                if(lineslope==6)
785                        lineslope=3.5
786                        break
787                endif
788                if(lineslope==7)
789                        lineslope=4.5
790                        break
791                endif
792                if(lineslope==8)
793                        lineslope=2.5
794                        break
795                endif
796                if(lineslope==9)
797                        lineslope=1.5
798                        break
799                endif
800                if(lineslope==13)
801                        lineslope=5/3
802                        break
803                endif
804                break
805        while(1)
806
807        IR2P_DrawLineOfRequiredSlope(LineSlope,YourNumber,qLabel,label1)
808end
809
810
811Function IR2P_DrawLineOfRequiredSlope(LineSlope,YourNumber,qLabel,label1)
812        Variable lineslope,YourNumber,qlabel
813        string label1
814       
815        SetDrawEnv xcoord= bottom,ycoord= left,save
816        variable X_start, Y_start
817        getAxis bottom
818        X_start=ceil((floor(log(V_max))+floor(log(V_min)))/2)
819        getAxis left
820        Y_start=ceil((ceil(log(V_max))+ceil(log(V_min)))/2)
821        if(lineslope==11)                                                                                                               //Vertical
822                drawline 10^(X_start),10^(Y_start),10^(X_start+1),10^(Y_start)
823        else
824                drawline 10^(X_start),10^(Y_start),10^(X_start+1),10^(Y_start-lineslope)
825        endif
826        if(qlabel==2)
827                SetDrawEnv fname= "Times",fstyle= 1;DelayUpdate
828                DrawText 10^(X_start),10^(Y_start-1),Label1
829        else
830                if(qlabel==1)//use power from above
831                        SetDrawEnv fname= "Times",fstyle= 1;DelayUpdate
832                        DrawText 10^(X_start),10^(Y_start-1),("-"+num2str(lineslope))
833                endif
834        endif
835EndMacro
836
837
838
839//*****************************************************************************************************************
840//*****************************************************************************************************************
841//*****************************************************************************************************************
842Function IR2_GetIrenaManuscript()
843
844                string WhereIsManuscript
845                string WhereAreProcedures=RemoveEnding(FunctionPath(""),"IR1_Main.ipf")
846                String ManuscriptPath = ParseFilePath(5,"IrenaManuscript.pdf","*",0,0)
847        String cmd
848        print "Irena manuscript reference: "
849        print "Jan Ilavsky and Pete R. Jemian, Irena: tool suite for modeling and analysis of small-angle scattering"
850        print "Journal of Applied Crystallography (2009), 42, 347-353"
851        variable refnum
852        GetFileFolderInfo/Z=1/Q WhereAreProcedures+ManuscriptPath
853        variable foundIt=V_Flag
854        if(foundIt!=0)
855        NewPath/O/Q tempPath, WhereAreProcedures
856                DoAlert 1,  "Local copy of manuscript not found. Should Igor try to download from APS public web site?"
857                if(V_Flag==1)
858                        string url="ftp://ftp.xor.aps.anl.gov/pub/usaxs/IrenaManuscript.pdf"
859                        FTPDownload /O/V=7/P=tempPath/Z url, "IrenaManuscript.pdf"     
860                        if(V_flag!=0)   //ftp failed...
861                                Abort "ftp of manuscript failed, please send e-mail to author to get your copy"
862                        endif
863                else
864                        abort
865                endif
866                killPath tempPath
867        endif
868       
869       
870        if (stringmatch(IgorInfo(2), "*Macintosh*"))
871               sprintf cmd "tell application \"Finder\" to open \"%s\"",WhereAreProcedures+ManuscriptPath
872               ExecuteScriptText cmd
873                if (strlen(S_value)>2)
874//                      DoAlert 0, S_value
875                endif
876
877        else
878                WhereAreProcedures=ParseFilePath(5,WhereAreProcedures,"*",0,0)
879                WhereIsManuscript = "\"" + WhereAreProcedures+ManuscriptPath+"\""
880                NewNotebook/F=0 /N=NewBatchFile
881                Notebook NewBatchFile, text=WhereIsManuscript//+"\r"
882                SaveNotebook/O NewBatchFile as SpecialDirPath("Temporary", 0, 1, 0 )+"StartManual.bat"
883                DoWindow/K NewBatchFile
884                ExecuteScriptText "\""+SpecialDirPath("Temporary", 0, 1, 0 )+"StartManual.bat\""
885        endif
886
887
888end
889
890//*****************************************************************************************************************
891//*****************************************************************************************************************
892Function IR2_OpenIrenaManual()
893        //this function writes batch file and starts the manual.
894        //we need to write following batch file: "C:\Program Files\WaveMetrics\Igor Pro Folder\User Procedures\Irena\Irena manual.pdf"
895        //on Mac we just fire up the Finder with Mac type path...
896       
897        //check where we run...
898                //string WhereIsIgor
899                //pathInfo Igor
900                string WhereIsManual
901                string WhereAreProcedures=RemoveEnding(FunctionPath(""),"IR1_Main.ipf")
902                String manualPath = ParseFilePath(5,"Irena Manual.pdf","*",0,0)
903        String cmd
904       
905        variable refnum
906        GetFileFolderInfo/Z=1/Q WhereAreProcedures+manualPath
907        variable foundIt=V_Flag
908        variable ManualModDate=V_modificationDate
909        //printf "The current manual date is: %+015.4f\r", V_modificationDate
910        if(ManualModDate>0)
911                //print  V_modificationDate
912                print "Found version of Manual is from : " + secs2Date(ManualModDate,1)
913        endif
914        if(foundIt!=0 || ManualModDate<CurrentManualDateInSecs)
915        NewPath/O/Q tempPath, WhereAreProcedures
916                DoAlert 1,  "Local copy of manual not found or is obsolete. Should Igor try to download from APS public web site?"
917                if(V_Flag==1)
918                        string url="ftp://ftp.xor.aps.anl.gov/pub/usaxs/Irena Manual.pdf"
919                        FTPDownload /O/V=7/P=tempPath/Z url, "Irena Manual.pdf"
920                        if(V_flag!=0)   //ftp failed...
921                                Abort "ftp of manual failed, please download the manual from web site and place into ..\Irena folder with the macros."
922                        endif
923                else
924                        abort
925                endif
926                killPath tempPath
927        endif
928       
929        if (stringmatch(IgorInfo(2), "*Macintosh*"))
930             //  manualPath = "User Procedures:Irena:Irena manual.pdf"
931               sprintf cmd "tell application \"Finder\" to open \"%s\"",WhereAreProcedures+manualPath
932               ExecuteScriptText cmd
933                if (strlen(S_value)>2)
934//                      DoAlert 0, S_value
935                endif
936
937        else
938                //manualPath = "User Procedures\Irena\Irena manual.pdf"
939                //WhereIsIgor=WhereIsIgor[0,1]+"\\"+IN2G_ChangePartsOfString(WhereIsIgor[2,inf],":","\\")
940                WhereAreProcedures=ParseFilePath(5,WhereAreProcedures,"*",0,0)
941                whereIsManual = "\"" + WhereAreProcedures+manualPath+"\""
942                NewNotebook/F=0 /N=NewBatchFile
943                Notebook NewBatchFile, text=whereIsManual//+"\r"
944                SaveNotebook/O NewBatchFile as SpecialDirPath("Temporary", 0, 1, 0 )+"StartManual.bat"
945                DoWindow/K NewBatchFile
946                ExecuteScriptText "\""+SpecialDirPath("Temporary", 0, 1, 0 )+"StartManual.bat\""
947        endif
948end
949//*****************************************************************************************************************
950//*****************************************************************************************************************
951Function IR2_OpenHelpMoviePage()
952        DoAlert 1,"Your web browser will open page with help movies. OK? (You must have QuickTime installed)"
953        if(V_flag==1)
954                BrowseURL "http://usaxs.xor.aps.anl.gov/staff/ilavsky/IrenaHelpMovies.html"
955        endif
956End
957
958Function IR2_OpenIrenaPage()
959        DoAlert 1,"Your web browser will Irena home page. OK?"
960        if(V_flag==1)
961                BrowseURL "http://usaxs.xor.aps.anl.gov/staff/ilavsky/irena.html"
962        endif
963End
964
965Function IR2_SignUpForMailingList()
966        DoAlert 1,"Your web browser will open page with the page where you can control your maling list options. OK?"
967        if(V_flag==1)
968                BrowseURL "http://www.aps.anl.gov/mailman/listinfo/irena_users"
969        endif
970End
971
972
973
974//*****************************************************************************************************************
975//*****************************************************************************************************************
976//*****************************************************************************************************************
977
978
979Function IR1_AboutPanel()
980        DoWindow About_Irena_1_Macros
981        if(V_Flag)
982                DoWindow/K About_Irena_1_Macros
983        endif
984
985//      PauseUpdate; Silent 1           // building window...
986        NewPanel/K=1 /W=(173.25,50,580,460) as "About_Irena_1_Macros"
987        DoWindow/C About_Irena_1_Macros
988        SetDrawLayer UserBack
989        SetDrawEnv fsize= 20,fstyle= 1,textrgb= (16384,28160,65280)
990        DrawText 23,30,"Irena macros for Igor Pro >=6.22A"
991        SetDrawEnv fsize= 16,textrgb= (16384,28160,65280)
992        DrawText 100,60,"@ ANL, 2013"
993        DrawText 10,80,"release "+num2str(CurrentVersionNumber)
994        DrawText 11,100,"To get help please contact: ilavsky@aps.anl.gov"
995        SetDrawEnv textrgb= (0,0,65535)
996        DrawText 11,120,"http://usaxs.xor.aps.anl.gov/staff/ilavsky/irena.htm"
997        SetDrawEnv fsize= 14, fstyle=1
998        DrawText 11,148,"Reference: Jan Ilavsky and Pete R. Jemian"
999        SetDrawEnv fsize= 14, fstyle=1
1000        DrawText 11,168,"J Appl Crystallogr (2009), 42, 347-353"
1001
1002        DrawText 11,195,"Size distribution by Pete Jemian: jemian@anl.gov"
1003        DrawText 11,215,"Unified model by Gregg Beaucage: gbeaucag@uceng.uc.edu"
1004        DrawText 11,230," Beaucage, G. (1995). J Appl Crystallogr 28, 717-728."
1005        DrawText 11,250," Fractals model by Andrew Allen: Andrew.Allen@nist.gov"
1006        DrawText 11,265," Allen, A. J. (2005). J Am Ceram Soc 88, 1367-1381. "
1007        DrawText 11,285," Reflectivity & Genetic Optimization by Andrew Nelson "
1008        DrawText 11,300," (Australian Nuclear Science and Technology Organisation) "
1009        DrawText 11,315,"             Nelson, A. (2006). J Appl Crystallogr 39, 273-276."
1010        DrawText 11,330,"             andyfaff@gmail.com"
1011        DrawText 11,350,"Selected Structure & Form Factors refs: "
1012        DrawText 11,365,"       Kline, S. R. (2006). J Appl Crystallogr 39, 895-900"
1013        DrawText 11,380,"http://www.ncnr.nist.gov/programs/sans/data/data_red.html"
1014// (). 
1015end
1016
1017//*****************************************************************************************************************
1018//*****************************************************************************************************************
1019//*****************************************************************************************************************
1020//*****************************************************************************************************************
1021//*****************************************************************************************************************
1022
1023
1024Function IR1_RemoveSASMac()
1025                Execute/P "IR1_KillGraphsAndPanels()"
1026                Execute/P "DELETEINCLUDE \"IR1_Loader\""
1027                SVAR strChagne=root:Packages:SASItem1Str
1028                strChagne= "Load Irena SAS Modeling Macros"
1029                BuildMenu "SAS"
1030                Execute/P "COMPILEPROCEDURES "
1031end
1032
1033
1034
1035//*****************************************************************************************************************
1036//*****************************************************************************************************************
1037//*****************************************************************************************************************
1038//*****************************************************************************************************************
1039//*****************************************************************************************************************
1040
1041Function IR1S_LSQF_StandardModelsMain()
1042
1043        IN2G_CheckScreenSize("height",670)
1044
1045        DoWindow IR1S_ControlPanel
1046        if (V_Flag)
1047                DoWindow/K IR1S_ControlPanel   
1048        endif
1049        DoWindow IR1_LogLogPlotLSQF
1050        if (V_Flag)
1051                DoWindow/K IR1_LogLogPlotLSQF   
1052        endif
1053        DoWindow IR1_IQ4_Q_PlotLSQF
1054        if (V_Flag)
1055                DoWindow/K IR1_IQ4_Q_PlotLSQF   
1056        endif
1057        DoWindow IR1_Model_Distributions
1058        if (V_Flag)
1059                DoWindow/K IR1_Model_Distributions     
1060        endif
1061        DoWindow IR1S_InterferencePanel
1062        if (V_Flag)
1063                DoWindow/K IR1S_InterferencePanel
1064        endif
1065        IR1T_InitFormFactors()
1066        IR1S_Initialize()
1067        IR1_CreateLoggbook()
1068        //IR1_KillGraphsAndPanels()     
1069        Execute ("IR1S_ControlPanel()")
1070end
1071
1072
1073//*****************************************************************************************************************
1074//*****************************************************************************************************************
1075//*****************************************************************************************************************
1076//*****************************************************************************************************************
1077//*****************************************************************************************************************
1078
1079Function IR1S_Initialize()
1080        //function, which creates the folder for SAS modeling and creates the strings and variables
1081       
1082        string oldDf=GetDataFolder(1)
1083       
1084        NewDataFolder/O/S root:Packages
1085        NewdataFolder/O/S root:Packages:SAS_Modeling
1086       
1087        string ListOfVariables
1088        string ListOfStrings
1089       
1090        //here define the lists of variables and strings needed, separate names by ;...
1091       
1092        ListOfVariables="UseIndra2Data;UseQRSdata;NumberOfDistributions;DisplayVD;DisplayND;CurrentTab;UseInterference;UseLSQF;UseGenOpt;"
1093        ListOfVariables+="Dist1NumberOfPoints;Dist1Contrast;Dist1Location;Dist1Scale;Dist1Shape;Dist1Mean;Dist1Median;Dist1Mode;Dist1LocHighLimit;Dist1LocLowLimit;Dist1ScaleHighLimit;Dist1ScaleLowLimit;"
1094        ListOfVariables+="Dist1ShapeHighLimit;Dist1ShapeLowLimit;Dist1LocStep;Dist1ShapeStep;Dist1ScaleStep;Dist1FitShape;Dist1FitLocation;Dist1FitScale;Dist1VolFraction;"
1095        ListOfVariables+="Dist1VolHighLimit;Dist1VolLowLimit;Dist1FitVol;Dist1NegligibleFraction;Dist1ScatShapeParam1;Dist1ScatShapeParam2;Dist1ScatShapeParam3;Dist1FWHM;"
1096        ListOfVariables+="Dist2NumberOfPoints;Dist2Contrast;Dist2Location;Dist2Scale;Dist2Shape;Dist2Mean;Dist2Median;Dist2Mode;Dist2LocHighLimit;Dist2LocLowLimit;Dist2ScaleHighLimit;Dist2ScaleLowLimit;"
1097        ListOfVariables+="Dist2ShapeHighLimit;Dist2ShapeLowLimit;Dist2LocStep;Dist2ShapeStep;Dist2ScaleStep;Dist2FitShape;Dist2FitLocation;Dist2FitScale;Dist2VolFraction;"
1098        ListOfVariables+="Dist2VolHighLimit;Dist2VolLowLimit;Dist2FitVol;Dist2NegligibleFraction;Dist2ScatShapeParam1;Dist2ScatShapeParam2;Dist2ScatShapeParam3;Dist2FWHM;"
1099        ListOfVariables+="Dist3NumberOfPoints;Dist3Contrast;Dist3Location;Dist3Scale;Dist3Shape;Dist3Mean;Dist3Median;Dist3Mode;Dist3LocHighLimit;Dist3LocLowLimit;Dist3ScaleHighLimit;Dist3ScaleLowLimit;"
1100        ListOfVariables+="Dist3ShapeHighLimit;Dist3ShapeLowLimit;Dist3LocStep;Dist3ShapeStep;Dist3ScaleStep;Dist3FitShape;Dist3FitLocation;Dist3FitScale;Dist3VolFraction;"
1101        ListOfVariables+="Dist3VolHighLimit;Dist3VolLowLimit;Dist3FitVol;Dist3NegligibleFraction;Dist3ScatShapeParam1;Dist3ScatShapeParam2;Dist3ScatShapeParam3;Dist3FWHM;"
1102        ListOfVariables+="Dist4NumberOfPoints;Dist4Contrast;Dist4Location;Dist4Scale;Dist4Shape;Dist4Mean;Dist4Median;Dist4Mode;Dist4LocHighLimit;Dist4LocLowLimit;Dist4ScaleHighLimit;Dist4ScaleLowLimit;"
1103        ListOfVariables+="Dist4ShapeHighLimit;Dist4ShapeLowLimit;Dist4LocStep;Dist4ShapeStep;Dist4ScaleStep;Dist4FitShape;Dist4FitLocation;Dist4FitScale;Dist4VolFraction;"
1104        ListOfVariables+="Dist4VolHighLimit;Dist4VolLowLimit;Dist4FitVol;Dist4NegligibleFraction;Dist4ScatShapeParam1;Dist4ScatShapeParam2;Dist4ScatShapeParam3;Dist4FWHM;"
1105        ListOfVariables+="Dist5NumberOfPoints;Dist5Contrast;Dist5Location;Dist5Scale;Dist5Shape;Dist5Mean;Dist5Median;Dist5Mode;Dist5LocHighLimit;Dist5LocLowLimit;Dist5ScaleHighLimit;Dist5ScaleLowLimit;"
1106        ListOfVariables+="Dist5ShapeHighLimit;Dist5ShapeLowLimit;Dist5LocStep;Dist5ShapeStep;Dist5ScaleStep;Dist5FitShape;Dist5FitLocation;Dist5FitScale;Dist5VolFraction;"
1107        ListOfVariables+="Dist5VolHighLimit;Dist5VolLowLimit;Dist5FitVol;Dist5NegligibleFraction;Dist5ScatShapeParam1;Dist5ScatShapeParam2;Dist5ScatShapeParam3;Dist5FWHM;"
1108        ListOfVariables+="SASBackground;SASBackgroundStep;FitSASBackground;UseNumberDistribution;UseVolumeDistribution;UpdateAutomatically;"
1109        ListOfVariables+="SASBackgroundError;Dist1LocationError;Dist1ScaleError;Dist1ShapeError;Dist1VolFractionError;"
1110        ListOfVariables+="Dist1LocationError;Dist1ScaleError;Dist1ShapeError;Dist1VolFractionError;"
1111        ListOfVariables+="Dist2LocationError;Dist2ScaleError;Dist2ShapeError;Dist2VolFractionError;"
1112        ListOfVariables+="Dist3LocationError;Dist3ScaleError;Dist3ShapeError;Dist3VolFractionError;"
1113        ListOfVariables+="Dist4LocationError;Dist4ScaleError;Dist4ShapeError;Dist4VolFractionError;"
1114        ListOfVariables+="Dist5LocationError;Dist5ScaleError;Dist5ShapeError;Dist5VolFractionError;"
1115        ListOfVariables+="Dist1UseInterference;Dist1InterferencePhi;Dist1InterferenceEta;Dist1InterferencePhiLL;Dist1InterferencePhiHL;Dist1InterferenceEtaLL;Dist1InterferenceEtaHL;"
1116        ListOfVariables+="Dist2UseInterference;Dist2InterferencePhi;Dist2InterferenceEta;Dist2InterferencePhiLL;Dist2InterferencePhiHL;Dist2InterferenceEtaLL;Dist2InterferenceEtaHL;"
1117        ListOfVariables+="Dist3UseInterference;Dist3InterferencePhi;Dist3InterferenceEta;Dist3InterferencePhiLL;Dist3InterferencePhiHL;Dist3InterferenceEtaLL;Dist3InterferenceEtaHL;"
1118        ListOfVariables+="Dist4UseInterference;Dist4InterferencePhi;Dist4InterferenceEta;Dist4InterferencePhiLL;Dist4InterferencePhiHL;Dist4InterferenceEtaLL;Dist4InterferenceEtaHL;"
1119        ListOfVariables+="Dist5UseInterference;Dist5InterferencePhi;Dist5InterferenceEta;Dist5InterferencePhiLL;Dist5InterferencePhiHL;Dist5InterferenceEtaLL;Dist5InterferenceEtaHL;"
1120        ListOfVariables+="Dist1FitInterferencePhi;Dist2FitInterferencePhi;Dist3FitInterferencePhi;Dist4FitInterferencePhi;Dist5FitInterferencePhi;"
1121        ListOfVariables+="Dist1FitInterferenceETA;Dist2FitInterferenceETA;Dist3FitInterferenceETA;Dist4FitInterferenceETA;Dist5FitInterferenceETA;"
1122        ListOfVariables+="Dist1InterferencePhiError;Dist1InterferenceEtaError;Dist2InterferencePhiError;Dist2InterferenceEtaError;"
1123        ListOfVariables+="Dist3InterferencePhiError;Dist3InterferenceEtaError;Dist4InterferencePhiError;Dist4InterferenceEtaError;"
1124        ListOfVariables+="Dist5InterferencePhiError;Dist5InterferenceEtaError;"
1125        ListOfVariables+="UseSlitSmearedData;SlitLength;"       
1126        //Ok add chance to fit the shape parameters
1127        ListOfVariables+="Dist1FitScatShapeParam1;Dist1ScatShapeParam1LowLimit;Dist1ScatShapeParam1HighLimit;Dist1FitScatShapeParam2;Dist1ScatShapeParam2LowLimit;Dist1ScatShapeParam2HighLimit;Dist1FitScatShapeParam3;Dist1ScatShapeParam3LowLimit;Dist1ScatShapeParam3HighLimit;"
1128        ListOfVariables+="Dist2FitScatShapeParam1;Dist2ScatShapeParam1LowLimit;Dist2ScatShapeParam1HighLimit;Dist2FitScatShapeParam2;Dist2ScatShapeParam2LowLimit;Dist2ScatShapeParam2HighLimit;Dist2FitScatShapeParam3;Dist2ScatShapeParam3LowLimit;Dist2ScatShapeParam3HighLimit;"
1129        ListOfVariables+="Dist3FitScatShapeParam1;Dist3ScatShapeParam1LowLimit;Dist3ScatShapeParam1HighLimit;Dist3FitScatShapeParam2;Dist3ScatShapeParam2LowLimit;Dist3ScatShapeParam2HighLimit;Dist3FitScatShapeParam3;Dist3ScatShapeParam3LowLimit;Dist3ScatShapeParam3HighLimit;"
1130        ListOfVariables+="Dist4FitScatShapeParam1;Dist4ScatShapeParam1LowLimit;Dist4ScatShapeParam1HighLimit;Dist4FitScatShapeParam2;Dist4ScatShapeParam2LowLimit;Dist4ScatShapeParam2HighLimit;Dist4FitScatShapeParam3;Dist4ScatShapeParam3LowLimit;Dist4ScatShapeParam3HighLimit;"
1131        ListOfVariables+="Dist5FitScatShapeParam1;Dist5ScatShapeParam1LowLimit;Dist5ScatShapeParam1HighLimit;Dist5FitScatShapeParam2;Dist5ScatShapeParam2LowLimit;Dist5ScatShapeParam2HighLimit;Dist5FitScatShapeParam3;Dist5ScatShapeParam3LowLimit;Dist5ScatShapeParam3HighLimit;"
1132        ListOfVariables+="Dist1ScatShapeParam4;Dist1ScatShapeParam5;"
1133        ListOfVariables+="Dist2ScatShapeParam4;Dist2ScatShapeParam5;"
1134        ListOfVariables+="Dist3ScatShapeParam4;Dist3ScatShapeParam5;"
1135        ListOfVariables+="Dist4ScatShapeParam4;Dist4ScatShapeParam5;"
1136        ListOfVariables+="Dist5ScatShapeParam4;Dist5ScatShapeParam5;"
1137        ListOfVariables+="Dist1ScatShapeParam1Error;Dist1ScatShapeParam2Error;Dist1ScatShapeParam3Error;"
1138        ListOfVariables+="Dist2ScatShapeParam1Error;Dist2ScatShapeParam2Error;Dist2ScatShapeParam3Error;"
1139        ListOfVariables+="Dist3ScatShapeParam1Error;Dist3ScatShapeParam2Error;Dist3ScatShapeParam3Error;"
1140        ListOfVariables+="Dist4ScatShapeParam1Error;Dist4ScatShapeParam2Error;Dist4ScatShapeParam3Error;"
1141        ListOfVariables+="Dist5ScatShapeParam1Error;Dist5ScatShapeParam2Error;Dist5ScatShapeParam3Error;WallThicknessSpreadInFract;"
1142        ListOfVariables+="Dist1UserFFParam1;Dist1UserFFParam2;Dist1UserFFParam3;Dist1UserFFParam4;Dist1UserFFParam5;"
1143        ListOfVariables+="Dist2UserFFParam1;Dist2UserFFParam2;Dist2UserFFParam3;Dist2UserFFParam4;Dist2UserFFParam5;"
1144        ListOfVariables+="Dist3UserFFParam1;Dist3UserFFParam2;Dist3UserFFParam3;Dist3UserFFParam4;Dist3UserFFParam5;"
1145        ListOfVariables+="Dist4UserFFParam1;Dist4UserFFParam2;Dist4UserFFParam3;Dist4UserFFParam4;Dist4UserFFParam5;"
1146        ListOfVariables+="Dist5UserFFParam1;Dist5UserFFParam2;Dist5UserFFParam3;Dist5UserFFParam4;Dist5UserFFParam5;"
1147
1148        ListOfStrings="DataFolderName;IntensityWaveName;QWavename;ErrorWaveName;"
1149        ListOfStrings+="Dist1ShapeModel;Dist1DistributionType;Dist1UserFormFactorFnct;Dist1UserVolumeFnct;"
1150        ListOfStrings+="Dist2ShapeModel;Dist2DistributionType;Dist2UserFormFactorFnct;Dist2UserVolumeFnct;"
1151        ListOfStrings+="Dist3ShapeModel;Dist3DistributionType;Dist3UserFormFactorFnct;Dist3UserVolumeFnct;"
1152        ListOfStrings+="Dist4ShapeModel;Dist4DistributionType;Dist4UserFormFactorFnct;Dist4UserVolumeFnct;"
1153        ListOfStrings+="Dist5ShapeModel;Dist5DistributionType;Dist5UserFormFactorFnct;Dist5UserVolumeFnct;"
1154       
1155        String/g GaussEquation="P(x)=(1/(Width*sqrt(2*pi)) * exp(-(x-Mean)^2/(2*Width^2))"
1156        String/g LogNormalEquation="P(x)=(1/((x-Min)*Mean*sqrt(2*pi)) * exp(-ln((x-Mean)/sdev)^2/(2*sdev^2))"
1157        String/g LSWEquation="P(x)=A*(loc^2*exp(-loc/(1.5-loc)))/((1.5-loc)^(11/3)*(3+loc)^(7/3))"
1158        String/g PowerLawEquation="P(x)= x ^ -(1+(6-slope))"
1159       
1160        variable i
1161        //and here we create them
1162        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
1163                IN2G_CreateItem("variable",StringFromList(i,ListOfVariables))
1164        endfor         
1165                               
1166        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
1167                IN2G_CreateItem("string",StringFromList(i,ListOfStrings))
1168        endfor 
1169        //cleanup after possible previous fitting stages...
1170        Wave/Z CoefNames=root:Packages:SAS_Modeling:CoefNames
1171        Wave/Z CoefficientInput=root:Packages:SAS_Modeling:CoefficientInput
1172        KillWaves/Z CoefNames, CoefficientInput
1173       
1174        IR1S_SetInitialValues()
1175end
1176
1177
1178//*****************************************************************************************************************
1179//*****************************************************************************************************************
1180//*****************************************************************************************************************
1181//*****************************************************************************************************************
1182//*****************************************************************************************************************
1183
1184Function IR1S_SetInitialValues()
1185        //and here set default values...
1186
1187        string OldDf=getDataFolder(1)
1188        setDataFolder root:Packages:SAS_Modeling
1189        NVAR UseQRSData=root:Packages:SAS_Modeling:UseQRSData
1190        NVAR UseIndra2data=root:Packages:SAS_Modeling:UseIndra2data
1191        NVAR NumberOfDistributions=root:Packages:SAS_Modeling:NumberOfDistributions
1192        NVAR DisplayND=root:Packages:SAS_Modeling:DisplayND
1193        NVAR DisplayVD=root:Packages:SAS_Modeling:DisplayVD
1194        NVAR FitSASBackground=root:Packages:SAS_Modeling:FitSASBackground
1195        NVAR UseNumberDistribution=root:Packages:SAS_Modeling:UseNumberDistribution
1196        NVAR UseVolumeDistribution=root:Packages:SAS_Modeling:UseVolumeDistribution                                             
1197        NVAR UpdateAutomatically=root:Packages:SAS_Modeling:UpdateAutomatically
1198       
1199        if (UseQRSData)
1200                UseIndra2data=0
1201        endif
1202        NumberOfDistributions=0
1203        DisplayND=0
1204        DisplayVD=1
1205       
1206        if (FitSASBackground==0)
1207                FitSASBackground=1
1208        endif
1209       
1210        if (UseNumberDistribution==0 && UseVolumeDistribution==0)
1211                 UseVolumeDistribution=1
1212                 UseNumberDistribution=0
1213        endif
1214               
1215        NVAR UseLSQF
1216        NVAR UseGenOpt
1217        if(UseLSQF+UseGenOpt!=1)
1218                UseLSQF=1
1219                UseGenOpt=0
1220        endif
1221       
1222        UpdateAutomatically=0
1223
1224        //and here we set distribution specific parameters....
1225       
1226        IR1S_SetInitialValuesForAdist(1)        //dist 1
1227        IR1S_SetInitialValuesForAdist(2)        //dist 2
1228        IR1S_SetInitialValuesForAdist(3)        //dist 3
1229        IR1S_SetInitialValuesForAdist(4)        //dist 4
1230        IR1S_SetInitialValuesForAdist(5)        //dist 5
1231
1232        setDataFolder oldDF
1233       
1234end     
1235
1236
1237//*****************************************************************************************************************
1238//*****************************************************************************************************************
1239//*****************************************************************************************************************
1240//*****************************************************************************************************************
1241//*****************************************************************************************************************
1242
1243Function IR1S_SetInitialValuesForAdist(distNum)
1244        variable distNum
1245        //default values for distribution 1
1246        string OldDf=GetDataFolder(1)
1247       
1248        setDataFOlder root:Packages:SAS_Modeling
1249       
1250        SVAR testStr =$("Dist"+num2str(distNum)+"UserFormFactorFnct")
1251        if(strlen(testStr)<1)
1252                testStr = "IR1T_ExampleSphereFFPoints"
1253        endif
1254        SVAR testStr =$("Dist"+num2str(distNum)+"UserVolumeFnct")
1255        if(strlen(testStr)<1)
1256                testStr = "IR1T_ExampleSphereVolume"
1257        endif
1258       
1259        NVAR testVar=$("Dist"+num2str(distNum)+"NumberOfPoints")
1260        if (testVar==0)
1261                 testVar=50
1262        endif
1263        NVAR testVar=$("Dist"+num2str(distNum)+"ScatShapeParam1")
1264        if(testVar==0)
1265                 testVar=1
1266        endif
1267        NVAR testVar=$("Dist"+num2str(distNum)+"ScatShapeParam2")
1268        if (testVar==0)
1269                 testVar=1
1270        endif
1271        NVAR testVar=$("Dist"+num2str(distNum)+"ScatShapeParam3")
1272        if (testVar==0)
1273                 testVar=1
1274        endif
1275       
1276        NVAR testVar=$("Dist"+num2str(distNum)+"NegligibleFraction")
1277        if (testVar==0)
1278                 testVar=0.01
1279        endif
1280        NVAR testVar=$("Dist"+num2str(distNum)+"VolHighLimit")
1281        if (testVar==0)
1282                 testVar=0.99
1283        endif
1284        NVAR testVar=$("Dist"+num2str(distNum)+"VolLowLimit")
1285        if (testVar==0)
1286                 testVar=0.00001
1287        endif
1288        NVAR testVar=$("Dist"+num2str(distNum)+"VolFraction")
1289        if (testVar==0)
1290                 testVar=0.05
1291        endif
1292        NVAR testVar=$("Dist"+num2str(distNum)+"FitVol")
1293        if (testVar==0)
1294                 testVar=1
1295        endif
1296        NVAR testVar=$("Dist"+num2str(distNum)+"FitShape")
1297        if (testVar==0)
1298                 testVar=1
1299        endif
1300        NVAR testVar=$("Dist"+num2str(distNum)+"FitLocation")
1301        if (testVar==0)
1302                 testVar=0
1303        endif
1304        NVAR testVar=$("Dist"+num2str(distNum)+"FitScale")
1305        if (testVar==0)
1306                 testVar=1
1307        endif
1308        NVAR testVar=$("Dist"+num2str(distNum)+"Contrast")
1309        if (testVar==0)
1310                 testVar=100
1311        endif
1312        NVAR testVar=$("Dist"+num2str(distNum)+"Scale")
1313        if (testVar==0)
1314                if (distNum==1)
1315                                 testVar=100
1316                endif
1317                if (distNum==2)
1318                                 testVar=400
1319                endif
1320                if (distNum==3)
1321                                 testVar=800
1322                endif
1323                if (distNum==4)
1324                                 testVar=1600
1325                endif
1326                if (distNum==5)
1327                                 testVar=3200
1328                endif
1329        endif
1330        NVAR testVar=$("Dist"+num2str(distNum)+"Location")
1331        if (testVar==0)
1332                 testVar=0
1333        endif
1334        NVAR testVar=$("Dist"+num2str(distNum)+"Shape")
1335        if (testVar==0)
1336                 testVar=0.5
1337        endif
1338        NVAR testVar=$("Dist"+num2str(distNum)+"LocHighLimit")
1339        if (testVar==0)
1340                 testVar=1000000
1341        endif
1342        NVAR testVar=$("Dist"+num2str(distNum)+"LocLowLimit")
1343        if (testVar==0)
1344                 testVar=10
1345        endif
1346        NVAR testVar=$("Dist"+num2str(distNum)+"ScaleHighLimit")
1347        if (testVar==0)
1348                 testVar=100000
1349        endif
1350        NVAR testVar=$("Dist"+num2str(distNum)+"ScaleLowLimit")
1351        if (testVar==0)
1352                 testVar=5
1353        endif
1354        NVAR testVar=$("Dist"+num2str(distNum)+"ShapeHighLimit")
1355        if (testVar==0)
1356                 testVar=0.9
1357        endif
1358        NVAR testVar=$("Dist"+num2str(distNum)+"ShapeLowLimit")
1359        if (testVar==0)
1360                 testVar=0.1
1361        endif
1362        NVAR testVar=$("Dist"+num2str(distNum)+"LocStep")
1363        if (testVar==0)
1364                 testVar=50
1365        endif
1366        NVAR testVar=$("Dist"+num2str(distNum)+"ShapeStep")
1367        if (testVar==0)
1368                 testVar=0.1
1369        endif
1370        NVAR testVar=$("Dist"+num2str(distNum)+"ScaleStep")
1371        if (testVar==0)
1372                 testVar=10
1373        endif
1374        SVAR testStr=$("Dist"+num2str(distNum)+"ShapeModel")
1375        if(strlen(testStr)==0)
1376                testStr="spheroid"
1377        endif
1378        SVAR testStr=$("Dist"+num2str(distNum)+"DistributionType")
1379        if(strlen(testStr)==0)
1380                testStr="LogNormal"
1381        endif
1382       
1383        NVAR testVar=$("Dist"+num2str(distNum)+"FitScatShapeParam1")
1384        if (testVar==0)
1385                 testVar=0
1386        endif
1387        NVAR testVar=$("Dist"+num2str(distNum)+"FitScatShapeParam2")
1388        if (testVar==0)
1389                 testVar=0
1390        endif
1391        NVAR testVar=$("Dist"+num2str(distNum)+"FitScatShapeParam3")
1392        if (testVar==0)
1393                 testVar=0
1394        endif
1395        NVAR testVar=$("Dist"+num2str(distNum)+"UseInterference")
1396        if (testVar==0)
1397                 testVar=0
1398        endif
1399        NVAR testVar=$("Dist"+num2str(distNum)+"InterferencePhi")
1400        if (testVar==0)
1401                 testVar=1
1402        endif
1403        NVAR testVar=$("Dist"+num2str(distNum)+"InterferencePhiHL")
1404        if (testVar==0)
1405                 testVar=8
1406        endif
1407        NVAR testVar=$("Dist"+num2str(distNum)+"InterferenceEta")
1408        if (testVar==0)
1409                 testVar=200
1410        endif
1411        NVAR testVar=$("Dist"+num2str(distNum)+"InterferenceEtaLL")
1412        if (testVar==0)
1413                 testVar=0
1414        endif
1415        NVAR testVar=$("Dist"+num2str(distNum)+"InterferenceEtaHL")
1416        if (testVar==0)
1417                 testVar=10000
1418        endif
1419
1420        setDataFolder oldDf
1421end
1422
1423
1424//*****************************************************************************************************************
1425//*****************************************************************************************************************
1426//*****************************************************************************************************************
1427//*****************************************************************************************************************
1428//*****************************************************************************************************************
1429
1430Function IR1_GraphMeasuredData(Package)
1431        string Package  //tells me, if this is called from Unified or LSQF
1432        //this function graphs data into the various graphs as needed
1433       
1434        string oldDf=GetDataFolder(1)
1435        setDataFolder root:Packages:SAS_Modeling
1436        SVAR DataFolderName
1437        SVAR IntensityWaveName
1438        SVAR QWavename
1439        SVAR ErrorWaveName
1440        variable cursorAposition, cursorBposition
1441       
1442        //fix for liberal names
1443        IntensityWaveName = PossiblyQuoteName(IntensityWaveName)
1444        QWavename = PossiblyQuoteName(QWavename)
1445        ErrorWaveName = PossiblyQuoteName(ErrorWaveName)
1446       
1447        WAVE/Z test=$(DataFolderName+IntensityWaveName)
1448        if (!WaveExists(test))
1449                abort "Error in IntensityWaveName wave selection"
1450        endif
1451        cursorAposition=0
1452        cursorBposition=numpnts(test)-1
1453        WAVE/Z test=$(DataFolderName+QWavename)
1454        if (!WaveExists(test))
1455                abort "Error in QWavename wave selection"
1456        endif
1457        WAVE/Z test=$(DataFolderName+ErrorWaveName)
1458        if (!WaveExists(test))
1459                abort "Error in ErrorWaveName wave selection"
1460        endif
1461        Duplicate/O $(DataFolderName+IntensityWaveName), OriginalIntensity
1462        Duplicate/O $(DataFolderName+QWavename), OriginalQvector
1463        Duplicate/O $(DataFolderName+ErrorWaveName), OriginalError
1464        Redimension/D OriginalIntensity, OriginalQvector, OriginalError
1465        wavestats /Q OriginalQvector
1466        if(V_min<0)
1467                OriginalQvector = OriginalQvector[p]<=0 ? NaN : OriginalQvector[p]
1468        endif
1469        IN2G_RemoveNaNsFrom3Waves(OriginalQvector,OriginalIntensity, OriginalError)
1470        NVAR/Z SubtractBackground=root:Packages:SAS_Modeling:SubtractBackground
1471        if(NVAR_Exists(SubtractBackground) && (cmpstr(Package,"Unified")==0))
1472                OriginalIntensity =OriginalIntensity - SubtractBackground
1473        endif
1474        NVAR/Z UseSlitSmearedData=root:Packages:SAS_Modeling:UseSlitSmearedData
1475        if(NVAR_Exists(UseSlitSmearedData) && (cmpstr(Package,"LSQF")==0))
1476                if(UseSlitSmearedData)
1477                        NVAR SlitLength=root:Packages:SAS_Modeling:SlitLength
1478                        variable tempSL=NumberByKey("SlitLength", note(OriginalIntensity) , "=" , ";")
1479                        if(numtype(tempSL)==0)
1480                                SlitLength=tempSL
1481                        endif
1482                endif
1483        endif
1484        NVAR/Z UseSMRData=root:Packages:SAS_Modeling:UseSMRData
1485        if(NVAR_Exists(UseSMRData) && (cmpstr(Package,"Unified")==0))
1486                if(UseSMRData)
1487                        NVAR SlitLengthUnif=root:Packages:SAS_Modeling:SlitLengthUnif
1488                        variable tempSL1=NumberByKey("SlitLength", note(OriginalIntensity) , "=" , ";")
1489                        if(numtype(tempSL1)==0)
1490                                SlitLengthUnif=tempSL1
1491                        endif
1492                endif
1493        endif
1494       
1495       
1496        if (cmpstr(Package,"Unified")==0)               //called from unified
1497                DoWindow IR1_LogLogPlotU
1498                if (V_flag)
1499                        Dowindow/K IR1_LogLogPlotU
1500                endif
1501                Execute ("IR1_LogLogPlotU()")
1502        elseif (cmpstr(Package,"LSQF")==0)
1503                DoWindow IR1_LogLogPlotLSQF
1504                if (V_flag)
1505                        cursorAposition=pcsr(A,"IR1_LogLogPlotLSQF")
1506                        cursorBposition=pcsr(B,"IR1_LogLogPlotLSQF")
1507                        Dowindow/K IR1_LogLogPlotLSQF
1508                endif
1509                Execute ("IR1_LogLogPlotLSQF()")
1510                cursor/P/W=IR1_LogLogPlotLSQF A, OriginalIntensity,cursorAposition
1511                cursor/P/W=IR1_LogLogPlotLSQF B, OriginalIntensity,cursorBposition
1512        endif
1513       
1514        Duplicate/O $(DataFolderName+IntensityWaveName), OriginalIntQ4
1515        Duplicate/O $(DataFolderName+QWavename), OriginalQ4
1516        Duplicate/O $(DataFolderName+ErrorWaveName), OriginalErrQ4
1517        Redimension/D OriginalIntQ4, OriginalQ4, OriginalErrQ4
1518        wavestats /Q OriginalQ4
1519        if(V_min<0)
1520                OriginalQ4 = OriginalQ4[p]<=0 ? NaN : OriginalQ4[p]
1521        endif
1522        IN2G_RemoveNaNsFrom3Waves(OriginalQ4,OriginalIntQ4, OriginalErrQ4)
1523
1524        if(NVAR_Exists(SubtractBackground) && (cmpstr(Package,"Unified")==0))
1525                OriginalIntQ4 =OriginalIntQ4 - SubtractBackground
1526        endif
1527       
1528        OriginalQ4=OriginalQ4^4
1529        OriginalIntQ4=OriginalIntQ4*OriginalQ4
1530        OriginalErrQ4=OriginalErrQ4*OriginalQ4
1531
1532        if (cmpstr(Package,"Unified")==0)               //called from unified
1533                DoWindow IR1_IQ4_Q_PlotU
1534                if (V_flag)
1535                        Dowindow/K IR1_IQ4_Q_PlotU
1536                endif
1537                Execute ("IR1_IQ4_Q_PlotU()")
1538        elseif (cmpstr(Package,"LSQF")==0)
1539                DoWindow IR1_IQ4_Q_PlotLSQF
1540                if (V_flag)
1541                        Dowindow/K IR1_IQ4_Q_PlotLSQF
1542                endif
1543                Execute ("IR1_IQ4_Q_PlotLSQF()")
1544        endif
1545        setDataFolder oldDf
1546end
1547
1548
1549//*****************************************************************************************************************
1550//*****************************************************************************************************************
1551//*****************************************************************************************************************
1552//*****************************************************************************************************************
1553//*****************************************************************************************************************
1554
1555Proc  IR1_IQ4_Q_PlotLSQF()
1556        PauseUpdate; Silent 1           // building window...
1557        String fldrSav= GetDataFolder(1)
1558        SetDataFolder root:Packages:SAS_Modeling:
1559        Display /W=(283.5,228.5,761.25,383)/K=1  OriginalIntQ4 vs OriginalQvector as "IQ4_Q_Plot"
1560        DoWindow/C IR1_IQ4_Q_PlotLSQF
1561        ModifyGraph mode(OriginalIntQ4)=3
1562        ModifyGraph msize(OriginalIntQ4)=1
1563        ModifyGraph log=1
1564        ModifyGraph mirror=1
1565        Label left "Intensity * Q^4"
1566        Label bottom "Q [A\\S-1\\M]"
1567        ErrorBars/Y=1 OriginalIntQ4 Y,wave=(OriginalErrQ4,OriginalErrQ4)
1568        TextBox/C/N=DateTimeTag/F=0/A=RB/E=2/X=2.00/Y=1.00 "\\Z07"+date()+", "+time()   
1569        TextBox/C/N=SampleNameTag/F=0/A=LB/E=2/X=2.00/Y=1.00 "\\Z07"+DataFolderName+IntensityWaveName   
1570        //and now some controls
1571//      ControlBar 30
1572//      Button SaveStyle size={80,20}, pos={50,5},proc=IR1U_StyleButtonCotrol,title="Save Style"
1573//      Button ApplyStyle size={80,20}, pos={150,5},proc=IR1U_StyleButtonCotrol,title="Apply Style"
1574        SetDataFolder fldrSav
1575        Execute/P("AutoPositionWindow/M=1 /R=IR1_LogLogPlotLSQF IR1_IQ4_Q_PlotLSQF")
1576        Execute/P("Dowindow/F IR1_LogLogPlotLSQF")
1577EndMacro
1578
1579
1580//*****************************************************************************************************************
1581//*****************************************************************************************************************
1582//*****************************************************************************************************************
1583//*****************************************************************************************************************
1584//*****************************************************************************************************************
1585
1586//Window IR1_IQ4_Q_PlotLSQF() : Graph
1587//      PauseUpdate; Silent 1           // building window...
1588//      String fldrSav= GetDataFolder(1)
1589//      SetDataFolder root:Packages:SAS_Modeling:
1590//      Display /W=(295.5,237.5,753.75,421.25)/K=1  OriginalIntQ4 vs OriginalQvector as "IQ4_Q_Plot"
1591//      SetDataFolder fldrSav
1592//      ModifyGraph mode=3
1593//      ModifyGraph msize=1
1594//      ModifyGraph log=1
1595//      ModifyGraph mirror=1
1596//      Label left "Intensity * Q^4"
1597//      Label bottom "Q [A\\S-1\\M]"
1598//      Legend/W=IR1_IQ4_Q_Plot/N=text0/J/F=0/A=MC/X=-29.74/Y=37.76 "\\s(OriginalIntQ4) Experimental intensity * Q^4"
1599//      ErrorBars/Y=1 OriginalIntQ4 Y,wave=(:Packages:SAS_Modeling:OriginalErrQ4,:Packages:SAS_Modeling:OriginalErrQ4)
1600//      //and now some controls
1601//      ControlBar 30
1602//      Button SaveStyle size={80,20}, pos={50,5},proc=IR1U_StyleButtonCotrol,title="Save Style"
1603//      Button ApplyStyle size={80,20}, pos={150,5},proc=IR1U_StyleButtonCotrol,title="Apply Style"
1604//EndMacro
1605
1606
1607//*****************************************************************************************************************
1608//*****************************************************************************************************************
1609//*****************************************************************************************************************
1610//*****************************************************************************************************************
1611//*****************************************************************************************************************
1612
1613Proc  IR1_LogLogPlotLSQF()
1614        PauseUpdate; Silent 1           // building window...
1615        String fldrSav= GetDataFolder(1)
1616        SetDataFolder root:Packages:SAS_Modeling:
1617        Display /W=(282.75,37.25,759.75,208.25)/K=1  OriginalIntensity vs OriginalQvector as "LogLogPlot"
1618        DoWindow/C IR1_LogLogPlotLSQF
1619        ModifyGraph mode(OriginalIntensity)=3
1620        ModifyGraph msize(OriginalIntensity)=1
1621        ModifyGraph log=1
1622        ModifyGraph mirror=1
1623        ShowInfo
1624        Label left "Intensity [cm\\S-1\\M]"
1625        Label bottom "Q [A\\S-1\\M]"
1626        Legend/W=IR1_LogLogPlotLSQF/N=text0/J/F=0/A=MC/X=32.03/Y=38.79 "\\s(OriginalIntensity) Experimental intensity"
1627        ErrorBars/Y=1 OriginalIntensity Y,wave=(OriginalError,OriginalError)
1628        //and now some controls
1629        TextBox/C/N=DateTimeTag/F=0/A=RB/E=2/X=2.00/Y=1.00 "\\Z07"+date()+", "+time()   
1630        TextBox/C/N=SampleNameTag/F=0/A=LB/E=2/X=2.00/Y=1.00 "\\Z07"+DataFolderName+IntensityWaveName   
1631//      ControlBar 30
1632//      Button SaveStyle size={80,20}, pos={50,5},proc=IR1U_StyleButtonCotrol,title="Save Style"
1633//      Button ApplyStyle size={80,20}, pos={150,5},proc=IR1U_StyleButtonCotrol,title="Apply Style"
1634        SetDataFolder fldrSav
1635        Execute /P("AutoPositionWindow/M=0 /R=IR1S_ControlPanel IR1_LogLogPlotLSQF")
1636EndMacro
1637
1638
1639//*****************************************************************************************************************
1640//*****************************************************************************************************************
1641//*****************************************************************************************************************
1642//*****************************************************************************************************************
1643//*****************************************************************************************************************
1644
1645Function IR1_CopyDataBackToFolder(StandardOrUser)
1646        string StandardOrUser
1647        //here we need to copy the final data back to folder
1648        //before that we need to also attach note to teh waves with the results
1649       
1650        string OldDf=getDataFOlder(1)
1651        setDataFolder root:Packages:SAS_Modeling
1652       
1653        Wave Distdiameters=root:Packages:SAS_Modeling:Distdiameters
1654        Wave TotalNumberDist=root:Packages:SAS_Modeling:TotalNumberDist
1655        Wave TotalVolumeDist=root:Packages:SAS_Modeling:TotalVolumeDist
1656        Wave DistModelIntensity=root:Packages:SAS_Modeling:DistModelIntensity
1657        Wave ModelQvector=root:Packages:SAS_Modeling:ModelQvector
1658       
1659        NVAR NumberOfDistributions=root:Packages:SAS_Modeling:NumberOfDistributions
1660        SVAR DataFolderName=root:Packages:SAS_Modeling:DataFolderName
1661       
1662        string UsersComment, ExportSeparateDistributions
1663        UsersComment="Result from Modeling "+date()+"  "+time()
1664        ExportSeparateDistributions="No"
1665        Prompt UsersComment, "Modify comment to be saved with these results"
1666        Prompt ExportSeparateDistributions, "Export separately populations data", popup, "No;Yes"
1667        DoPrompt "Need input for saving data", UsersComment, ExportSeparateDistributions
1668        if (V_Flag)
1669                abort
1670        endif
1671
1672        Duplicate/O Distdiameters, tempDistdiameters
1673        Duplicate/O TotalNumberDist, tempTotalNumberDist
1674        Duplicate/O TotalVolumeDist, tempTotalVolumeDist
1675        Duplicate/O DistModelIntensity, tempDistModelIntensity
1676        Duplicate/O ModelQvector, tempModelQvector
1677        string ListOfWavesForNotes="tempDistdiameters;tempTotalNumberDist;tempTotalVolumeDist;tempDistModelIntensity;tempModelQvector;"
1678
1679        IR1_AppendWaveNote(ListOfWavesForNotes,StandardOrUser)          //append wave notes
1680       
1681        variable j,i
1682        If(cmpstr(ExportSeparateDistributions,"Yes")==0)
1683                for(j=1;j<=NumberOfDistributions;j+=1)          //copy local populations
1684                        Wave tempDia=$("Dist"+num2str(j)+"diameters")           
1685                        Wave tempNumDis=$("Dist"+num2str(j)+"NumberDist")               
1686                        Wave tempVolDist=$("Dist"+num2str(j)+"VolumeDist")     
1687                        Duplicate/O tempDia, $("tempDist"+num2str(j)+"diameters")               
1688                        Duplicate/O tempNumDis, $("tempDist"+num2str(j)+"NumberDist")           
1689                        Duplicate/O tempVolDist, $("tempDist"+num2str(j)+"VolumeDist") 
1690                        ListOfWavesForNotes="tempDist"+num2str(j)+"diameters;tempDist"+num2str(j)+"NumberDist;tempDist"+num2str(j)+"VolumeDist;"
1691                        IR1_AppendWNOfDist(j,ListOfWavesForNotes, StandardOrUser)
1692                endfor
1693        endif
1694
1695        //need to change direction if user uses modeling here...
1696        if(stringmatch(DataFolderName,"root:Packages*"))
1697                string NewDataFolderStr="root:SASModels:"
1698                string tempNewDatFldrName=""
1699                Prompt NewDataFolderStr, "Trying to save model to Packages folder, suggest change the folder"
1700                DoPrompt "Override the data saving target",  NewDataFolderStr
1701                if(V_Flag)
1702                        abort
1703                endif
1704                SetDataFolder root:
1705                if(!Stringmatch(NewDataFolderStr[Strlen(NewDataFolderStr)-1],":"))
1706                        NewDataFolderStr+=":"
1707                endif   
1708                for(i=0;i<ItemsInList(NewDataFolderStr,":");i+=1)
1709                        if(!StringMatch(StringFromList(i,NewDataFolderStr,":"),"root"))
1710                                NewDataFolder/O/S $(StringFromList(i,NewDataFolderStr,":"))
1711                        endif
1712                        tempNewDatFldrName+=possiblyQuoteName(StringFromList(i,NewDataFolderStr,":"))+":"
1713                endfor
1714                setDataFolder $tempNewDatFldrName
1715        else
1716                setDataFolder $DataFolderName   
1717        endif
1718        string tempname
1719        variable ii=0
1720        For(ii=0;ii<1000;ii+=1)
1721                tempname="ModelingDiameters_"+num2str(ii)
1722                if (checkname(tempname,1)==0)
1723                        break
1724                endif
1725        endfor
1726        Duplicate /O tempDistdiameters, $tempname
1727        Wave MytempWave=$tempname
1728        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1729        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1730        IN2G_AppendorReplaceWaveNote(tempname,"Units","A")
1731        Redimension/D MytempWave
1732       
1733        tempname="ModelingNumberDistribution_"+num2str(ii)
1734        Duplicate /O tempTotalNumberDist, $tempname
1735        Wave MytempWave=$tempname
1736        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1737        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1738        IN2G_AppendorReplaceWaveNote(tempname,"Units","1/cm3")
1739        Redimension/D MytempWave
1740       
1741        tempname="ModelingVolumeDistribution_"+num2str(ii)
1742        Duplicate /O tempTotalVolumeDist, $tempname
1743        Wave MytempWave=$tempname
1744        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1745        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1746        IN2G_AppendorReplaceWaveNote(tempname,"Units","fraction")
1747        Redimension/D MytempWave
1748       
1749        tempname="ModelingIntensity_"+num2str(ii)
1750        Duplicate /O tempDistModelIntensity, $tempname
1751        Wave MytempWave=$tempname
1752        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1753        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1754        IN2G_AppendorReplaceWaveNote(tempname,"Units","cm-1")
1755        Redimension/D MytempWave
1756       
1757        tempname="ModelingQvector_"+num2str(ii)
1758        Duplicate /O tempModelQvector, $tempname
1759        Wave MytempWave=$tempname
1760        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1761        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1762        IN2G_AppendorReplaceWaveNote(tempname,"Units","A-1")
1763        Redimension/D MytempWave
1764
1765        If(cmpstr(ExportSeparateDistributions,"Yes")==0)
1766                for(j=1;j<=NumberOfDistributions;j+=1)          //copy local populations
1767                        Wave tempDia=$("root:Packages:SAS_Modeling:tempDist"+num2str(j)+"diameters")           
1768                        Wave tempNumDis=$("root:Packages:SAS_Modeling:tempDist"+num2str(j)+"NumberDist")               
1769                        Wave tempVolDist=$("root:Packages:SAS_Modeling:tempDist"+num2str(j)+"VolumeDist")       
1770       
1771                        tempname="ModelingDia_Pop"+num2str(j)+"_"+num2str(ii)
1772                        Duplicate/O tempDia, $tempname
1773                        Wave MytempWave=$tempname
1774                        IN2G_AppendorReplaceWaveNote(tempname,"DataFolderInIgor",DataFolderName)
1775                        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1776                        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1777                        IN2G_AppendorReplaceWaveNote(tempname,"Units","A-1")
1778                        Redimension/D MytempWave
1779                               
1780                        tempname="ModelingNumDist_Pop"+num2str(j)+"_"+num2str(ii)
1781                        Duplicate/O tempNumDis, $tempname
1782                        Wave MytempWave=$tempname
1783                        IN2G_AppendorReplaceWaveNote(tempname,"DataFolderInIgor",DataFolderName)
1784                        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1785                        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1786                        IN2G_AppendorReplaceWaveNote(tempname,"Units","1/cm3")
1787                        Redimension/D MytempWave
1788       
1789                        tempname="ModelingVolDist_Pop"+num2str(j)+"_"+num2str(ii)
1790                        Duplicate/O tempVolDist, $tempname
1791                        Wave MytempWave=$tempname
1792                        IN2G_AppendorReplaceWaveNote(tempname,"DataFolderInIgor",DataFolderName)
1793                        IN2G_AppendorReplaceWaveNote(tempname,"UsersComment",UsersComment)
1794                        IN2G_AppendorReplaceWaveNote(tempname,"Wname",tempname)
1795                        IN2G_AppendorReplaceWaveNote(tempname,"Units","fraction")
1796                        Redimension/D MytempWave
1797                       
1798                        KillWaves/Z tempVolDist, tempNumDis, tempDia
1799                endfor
1800        endif
1801        setDataFolder root:Packages:SAS_Modeling
1802
1803        Killwaves/Z tempDistdiameters,tempTotalNumberDist,tempTotalVolumeDist, tempDistModelIntensity, tempModelQvector
1804        setDataFolder OldDf
1805end
1806
1807
1808//*****************************************************************************************************************
1809//*****************************************************************************************************************
1810//*****************************************************************************************************************
1811//*****************************************************************************************************************
1812//*****************************************************************************************************************
1813
1814Function IR1_AppendWaveNote(ListOfWavesForNotes, StandardOrUser)
1815        string ListOfWavesForNotes, StandardOrUser
1816       
1817        string oldDf=GetDataFolder(1)
1818        setDataFolder root:Packages:SAS_Modeling
1819
1820        NVAR NumberOfDistributions=root:Packages:SAS_Modeling:NumberOfDistributions
1821
1822        NVAR SASBackground=root:Packages:SAS_Modeling:SASBackground
1823        NVAR FitSASBackground=root:Packages:SAS_Modeling:FitSASBackground
1824        NVAR UseNumberDistribution=root:Packages:SAS_Modeling:UseNumberDistribution
1825        NVAR UseInterference=root:Packages:SAS_Modeling:UseInterference
1826        NVAR UseSlitSmearedData=root:Packages:SAS_Modeling:UseSlitSmearedData
1827        NVAR SlitLength=root:Packages:SAS_Modeling:SlitLength
1828        SVAR DataFolderName=root:Packages:SAS_Modeling:DataFolderName
1829        string ExperimentName=IgorInfo(1)
1830        variable i, cursorAposition, cursorBposition
1831        For(i=0;i<ItemsInList(ListOfWavesForNotes);i+=1)
1832
1833                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"IgorExperimentName",ExperimentName)
1834                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"DataFolderinIgor",DataFolderName)
1835               
1836                if (cmpstr(StandardOrUser,"standard")==0)
1837                        if (UseNumberDistribution)
1838                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"DistributionTypeModelled", "Number distribution")   
1839                        else
1840                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes), "DistributionTypeModelled", "Volume distribution") 
1841                        endif   
1842                else
1843                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes), "DistributionTypeModelled","User defined distributions used, modified volume and diameters")                       
1844                endif
1845                //handle the cursors
1846                CursorAPosition=pcsr(A, "IR1_LogLogPlotLSQF")
1847                CursorBPosition=pcsr(B, "IR1_LogLogPlotLSQF")
1848                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"CursorAPosition",num2str(CursorAPosition))
1849                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"CursorBPosition",num2str(CursorBPosition))
1850               
1851                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"NumberOfModelledDistributions",num2str(NumberOfDistributions))
1852                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"UseInterference",num2str(UseInterference))
1853                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"UseSlitSmearedData",num2str(UseSlitSmearedData))
1854                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"SlitLength",num2str(SlitLength))
1855
1856                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"SASBackground",num2str(SASBackground))
1857                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"FitSASBackground",num2str(FitSASBackground))
1858        endfor
1859
1860        For(i=1;i<=NumberOfDistributions;i+=1)
1861                IR1_AppendWNOfDist(i,ListOfWavesForNotes, StandardOrUser)
1862        endfor
1863
1864        setDataFolder oldDF
1865
1866end
1867
1868
1869//*****************************************************************************************************************
1870//*****************************************************************************************************************
1871//*****************************************************************************************************************
1872//*****************************************************************************************************************
1873//*****************************************************************************************************************
1874
1875Function IR1_AppendWNOfDist(DistNum,ListOfWavesForNotes, StandardOrUser)
1876        variable DistNum
1877        string ListOfWavesForNotes, StandardOrUser
1878       
1879        string oldDf=GetDataFolder(1)
1880        setDataFolder root:Packages:SAS_Modeling
1881
1882        NVAR DistVolFraction=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"VolFraction")
1883        NVAR DistVolFractionError=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"VolFractionError")
1884        NVAR DistScatShapeParam1=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ScatShapeParam1")
1885        NVAR DistScatShapeParam2=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ScatShapeParam2")
1886        NVAR DistScatShapeParam3=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ScatShapeParam3")
1887        NVAR DistScatShapeParam4=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ScatShapeParam4")
1888        NVAR DistScatShapeParam5=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ScatShapeParam5")
1889        SVAR DistShapeModel=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ShapeModel")
1890
1891        if (cmpstr(StandardOrUser,"standard")==0)
1892                NVAR DistNumberOfPoints=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"NumberOfPoints")
1893                NVAR DistContrast=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"Contrast")
1894                NVAR DistLocation=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"Location")
1895                NVAR DistScale=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"Scale")
1896                NVAR DistShape=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"Shape")
1897                NVAR DistLocationError=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"LocationError")
1898                NVAR DistScaleError=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ScaleError")
1899                NVAR DistShapeError=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"ShapeError")
1900                SVAR DistDistributionType=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"DistributionType")
1901                NVAR DistNegligibleFraction= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"NegligibleFraction")
1902                NVAR DistUseInterference= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"UseInterference")
1903                NVAR DistInterferencePhi= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"InterferencePhi")
1904                NVAR DistInterferenceEta= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"InterferenceEta")
1905                NVAR DistInterferencePhiError= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"InterferencePhiError")
1906                NVAR DistInterferenceEtaError= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"InterferenceEtaError")
1907                NVAR DistFitInterferencePhi= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"FitInterferencePhi")
1908                NVAR DistFitInterferenceEta= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"FitInterferenceEta")
1909                NVAR DistFitShape= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"FitShape")
1910                NVAR DistFitLocation= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"FitLocation")
1911                NVAR DistFitScale= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"FitScale")
1912                NVAR DistFitVol= $("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"FitVol")
1913        else
1914                NVAR DistDiamAddition=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"DiamAddition")
1915                NVAR DistDiamMulitplier=$("root:Packages:SAS_Modeling:Dist"+num2str(DistNum)+"DiamMulitplier")
1916        endif           
1917       
1918        SVAR GaussEquation=root:Packages:SAS_Modeling:GaussEquation
1919        SVAR LogNormalEquation=root:Packages:SAS_Modeling:LogNormalEquation
1920        SVAR LSWEquation=root:Packages:SAS_Modeling:LSWEquation
1921        SVAR PowerLawEquation=root:Packages:SAS_Modeling:PowerLawEquation
1922       
1923        variable i
1924        For(i=0;i<ItemsInList(ListOfWavesForNotes);i+=1)
1925                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ShapeModel",DistShapeModel)
1926                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ScatShapeParam1",num2str(DistScatShapeParam1))
1927                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ScatShapeParam2",num2str(DistScatShapeParam2))
1928                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ScatShapeParam3",num2str(DistScatShapeParam3))
1929                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ScatShapeParam4",num2str(DistScatShapeParam4))
1930                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ScatShapeParam5",num2str(DistScatShapeParam5))
1931
1932                if (cmpstr(StandardOrUser,"standard")==0)
1933                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"DistributionType",DistDistributionType)
1934                        if (cmpstr(DistDistributionType,"Gauss")==0)
1935                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Formula",GaussEquation)             
1936                        endif
1937                        if (cmpstr(DistDistributionType,"LSW")==0)
1938                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Formula",LSWEquation)               
1939                        endif
1940                        if (cmpstr(DistDistributionType,"LogNormal")==0)
1941                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Formula",LogNormalEquation)         
1942                        endif
1943                        if (cmpstr(DistDistributionType,"PowerLaw")==0)
1944                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Formula",PowerLawEquation)         
1945                        endif
1946                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"NegligibleFraction",num2str(DistNegligibleFraction))
1947
1948                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"FitShape",num2str(DistFitShape))
1949                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"FitLocation",num2str(DistFitLocation))
1950                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"FitScale",num2str(DistFitScale))
1951                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"FitVol",num2str(DistFitVol))
1952                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"VolFraction",num2str(DistVolFraction))
1953                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Location",num2str(DistLocation))
1954                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Scale",num2str(DistScale))
1955                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Shape",num2str(DistShape))
1956                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"VolFractionError",num2str(DistVolFractionError))
1957                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"LocationError",num2str(DistLocationError))
1958                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ScaleError",num2str(DistScaleError))
1959                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"ShapeError",num2str(DistShapeError))
1960                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"NumberOfPoints",num2str(DistNumberOfPoints))
1961                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"Contrast",num2str(DistContrast))
1962                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"DistributionType",DistDistributionType)
1963                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"UseInterference",num2str(DistUseInterference))
1964                        if (DistUseInterference)
1965                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"InterferencePhi",num2str(DistInterferencePhi))
1966                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"InterferenceEta",num2str(DistInterferenceEta))
1967                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"InterferencePhiError",num2str(DistInterferencePhiError))
1968                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"InterferenceEtaError",num2str(DistInterferenceEtaError))
1969                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"FitInterferencePhi",num2str(DistFitInterferencePhi))
1970                                IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"FitInterferenceEta",num2str(DistFitInterferenceEta))
1971                        endif
1972                else
1973                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"VolFraction",num2str(DistVolFraction))
1974                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"DiamAddition",num2str(DistDiamAddition))
1975                        IN2G_AppendorReplaceWaveNote(stringFromList(i,ListOfWavesForNotes),"Dist"+num2str(DistNum)+"DiamMultiplier",num2str(DistDiamMulitplier))
1976                endif
1977        endfor
1978
1979        setDataFolder OldDf
1980end
1981
1982
1983//*****************************************************************************************************************
1984//*****************************************************************************************************************
1985//*****************************************************************************************************************
1986//*****************************************************************************************************************
1987//*****************************************************************************************************************
1988
1989Function IR1_ExportASCIIResults(standardOrUser)
1990        string standardOrUser                   //"standard" or "User", depending where called from...
1991
1992        //here we need to copy the export results out of Igor
1993        //before that we need to also attach note to teh waves with the results
1994       
1995        string OldDf=getDataFOlder(1)
1996        setDataFolder root:Packages:SAS_Modeling
1997       
1998        Wave Distdiameters=root:Packages:SAS_Modeling:Distdiameters
1999        Wave TotalNumberDist=root:Packages:SAS_Modeling:TotalNumberDist
2000        Wave TotalVolumeDist=root:Packages:SAS_Modeling:TotalVolumeDist
2001       
2002        NVAR NumberOfDistributions=root:Packages:SAS_Modeling:NumberOfDistributions
2003        SVAR DataFolderName=root:Packages:SAS_Modeling:DataFolderName
2004       
2005        Duplicate/O Distdiameters, tempDistdiameters
2006        Duplicate/O TotalNumberDist, tempTotalNumberDist
2007        Duplicate/O TotalVolumeDist, tempTotalVolumeDist
2008        string ListOfWavesForNotes="tempDistdiameters;tempTotalNumberDist;tempTotalVolumeDist;"
2009       
2010        IR1_AppendWaveNote(ListOfWavesForNotes, standardOrUser)
2011       
2012        string Comments="Record of Data evaluation with Irena SAS modeling macros;" +note(tempDistdiameters)+"diameters[A]\t\tNumberDist[1/cm3]\t\tVolumeDist[cm3/cm3]\r"
2013        variable pos=0
2014        variable ComLength=strlen(Comments)
2015        Do
2016                pos=strsearch(Comments, ";", pos+5)
2017                Comments=Comments[0,pos-1]+"\r#\t"+Comments[pos+1,inf]
2018        while (pos>0)
2019
2020        string filename1
2021        filename1=StringFromList(ItemsInList(DataFolderName,":")-1, DataFolderName,":")+"_SAS_model.txt"
2022        variable refnum
2023
2024        Open/D/T=".txt"/M="Select file to save data to" refnum as filename1
2025        filename1=S_filename
2026        if (strlen(filename1)==0)
2027                abort
2028        endif
2029
2030       
2031        String nb = "Notebook0"
2032        NewNotebook/N=$nb/F=0/V=0/K=0/W=(5.25,40.25,558,408.5) as "ExportData"
2033        Notebook $nb defaultTab=20, statusWidth=238, pageMargins={72,72,72,72}
2034        Notebook $nb font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0)
2035        Notebook $nb text=Comments[1,strlen(Comments)-2]       
2036       
2037       
2038        SaveNotebook $nb as filename1
2039        DoWindow /K $nb
2040        Save/A/G/M="\r\n" tempDistdiameters,tempTotalNumberDist,tempTotalVolumeDist as filename1         
2041       
2042
2043
2044        Killwaves/Z tempDistdiameters,tempTotalNumberDist,tempTotalVolumeDist
2045        setDataFolder OldDf
2046end
2047       
2048
Note: See TracBrowser for help on using the repository browser.