- Timestamp:
- Jun 4, 2014 4:01:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Packages/Wrapper_v40.ipf
r914 r941 1600 1600 1601 1601 1602 // this does the setup 1603 Function fChiMap(paramNum,percent) 1604 Variable paramNum,percent 1605 1606 String folderStr,funcStr,coefStr 1607 Variable useCursors,useResol=0,pt1,pt2,minIndex 1608 1609 ControlInfo/W=WrapperPanel popup_0 1610 folderStr=S_Value 1611 1612 ControlInfo/W=WrapperPanel popup_1 1613 funcStr=S_Value 1614 1615 ControlInfo/W=WrapperPanel popup_2 1616 coefStr=S_Value 1617 1618 ControlInfo/W=WrapperPanel check_0 1619 useCursors=V_Value 1620 1621 1622 // first, figure out where we are... 1623 String suffix=getModelSuffix(funcStr) 1624 1625 SetDataFolder $("root:"+folderStr) 1626 if(!exists(coefStr)) 1627 // must be unsmeared model, work in the root folder 1628 SetDataFolder root: 1629 if(!exists(coefStr)) //this should be fine if the coef filter is working, but check anyhow 1630 DoAlert 0,"the coefficient and data sets do not match" 1631 return 0 1632 endif 1633 endif 1634 1635 WAVE cw=$(coefStr) 1636 1637 1638 // test for smeared function 1639 if(stringmatch(funcStr, "Smear*")) // if it's a smeared function, need a struct 1640 useResol=1 1641 endif 1642 1643 // fill a struct instance whether I need one or not 1644 String DF="root:"+folderStr+":" 1645 1646 // Struct ResSmearAAOStruct fs 1647 // WAVE/Z resW = $(DF+folderStr+"_res") //these may not exist, if 3-column data is used 1648 // WAVE/Z fs.resW = resW 1649 WAVE yw=$(DF+folderStr+"_i") 1650 WAVE xw=$(DF+folderStr+"_q") 1651 WAVE sw=$(DF+folderStr+"_s") 1652 // Wave fs.coefW = cw 1653 // Wave fs.yW = yw 1654 // Wave fs.xW = xw 1655 1656 if(useCursors) 1657 if(pcsr(A) > pcsr(B)) 1658 pt1 = pcsr(B) 1659 pt2 = pcsr(A) 1660 else 1661 pt1 = pcsr(A) 1662 pt2 = pcsr(B) 1663 endif 1664 else 1665 //if cursors are not being used, find the first and last points of the data set, and pass them 1666 pt1 = 0 1667 pt2 = numpnts(yw)-1 1668 endif 1669 1670 minIndex = chi2gen(funcStr,folderStr,xw,yw,sw,cw,paramNum,percent,pt1,pt2,useResol) 1671 1672 WAVE chi2_map=chi2_map 1673 cw[paramNum] = pnt2x(chi2_map, minIndex) 1674 1675 return(0) 1676 End 1677 1602 1678 // this does the math for a single value of "whichParam" 1603 1679 Function chi2gen(funcStr,folderStr,xw,yw,sw,cw,whichParam,searchArea,lhs,rhs,useResol) … … 1610 1686 variable originalvalue = cw[whichparam] 1611 1687 variable range = originalValue * searchArea/100 1612 variable ii,err 1688 variable ii,err,minIndex 1613 1689 1614 1690 duplicate/o yw, :theoretical_data, :chi2_data 1615 1691 Wave theoretical_data, chi2_data 1616 1692 1617 make/o/n= 200/d chi2_map1618 setscale/I x, originalvalue - range /2, originalvalue + range/2, chi2_map1693 make/o/n=50/d chi2_map 1694 setscale/I x, originalvalue - range, originalvalue + range, chi2_map 1619 1695 1620 1696 String DF="root:"+folderStr+":" … … 1666 1742 Label bottom parW[whichParam] 1667 1743 1744 WaveStats/Q chi2_map 1745 minIndex = V_minRowLoc 1746 Print "minimum at: ", minIndex,chi2_map[minIndex] 1747 1668 1748 1669 1749 killwaves/z theoretical_data, chi2_data 1670 End 1671 1672 1673 // this does the setup 1674 Function fChiMap(paramNum,percent) 1675 Variable paramNum,percent 1676 1750 return(minIndex) 1751 End 1752 1753 1754 ////////////////////////////////// 1755 // this is based on a snippet from Andy Nelson, posted at the Igor Exchange web site. 1756 // -- modified to do "manual fitting" - mapping out chi-squared along one or two directions 1757 ////////////////////////////////// 1758 1759 Proc OpenManualFitPanel() 1760 1761 DoWindow/F ManualFitPanel 1762 if(V_flag==0) 1763 init_manualFit() 1764 ManualFitPanel() 1765 Endif 1766 1767 End 1768 1769 Function init_manualFit() 1770 1771 Variable/G root:gNumManualParam=0 1772 Variable/G root:gNumManualParam2=1 1773 Variable/G root:gCurrentChiSq=0 1774 Variable/G root:gNumManualSteps=50 1775 1776 Make/O/D/N=1 root:chi2_map,root:testVals 1777 Make/O/D/N=(1,1) root:chi2D 1778 1779 return(0) 1780 end 1781 1782 Window ManualFitPanel() : Panel 1783 PauseUpdate; Silent 1 // building window... 1784 NewPanel /W=(1170,44,1842,412) /K=1 1785 ModifyPanel cbRGB=(51664,44236,58982) 1786 DoWindow/C ManualFitPanel 1787 1788 // ShowTools/A 1789 SetVariable setvar0,pos={25,10},size={150,15},title="Parameter number" 1790 SetVariable setvar0,limits={0,inf,1},value=root:gNumManualParam,disable=0 1791 SetVariable setvar3,pos={25,30},size={150,15},title="Parameter number" 1792 SetVariable setvar3,limits={0,inf,1},value=root:gNumManualParam2,disable=2 1793 1794 CheckBox check0,pos={200,10},size={37,15},value=0,title="2D?",proc=Vary2DCheck 1795 1796 Button button0,pos={25,55},size={100,20},title="Vary 100 %",proc=VaryPCTButton 1797 Button button1,pos={25,80},size={100,20},title="Vary 25 %",proc=VaryPCTButton 1798 Button button2,pos={25,105},size={100,20},title="Vary 5 %",proc=VaryPCTButton 1799 Button button3,pos={25,130},size={100,20},title="Vary 1 %",proc=VaryPCTButton 1800 SetVariable setvar1,pos={31,196},size={200,15},title="Current Chi-Squared" 1801 SetVariable setvar1,limits={0,0,0},value=root:gCurrentChiSq 1802 SetVariable setvar2,pos={31,222},size={200,15},title="Number of steps" 1803 SetVariable setvar2,limits={5,500,1},value=root:gNumManualSteps 1804 1805 // 1806 Display/W=(259,23,643,346)/HOST=# root:chi2_map vs root:testVals 1807 RenameWindow #,G0 1808 ModifyGraph mode=4,msize=1,rgb=(65535,0,0) 1809 ModifyGraph tick=2,mirror=1 1810 // Label left "Chi-squared" 1811 // Label bottom "degrees" 1812 SetActiveSubwindow ## 1813 1814 EndMacro 1815 1816 1817 Function Vary2DCheck(ctrlName,checked) 1818 String ctrlName 1819 Variable checked 1820 1821 ControlInfo check0 1822 Variable isChecked = V_Value 1823 1824 Wave chi2D=chi2D 1825 Wave chi2_map=chi2_map 1826 wave testVals=testVals 1827 1828 if(isChecked) 1829 SetVariable setvar0,disable=0 1830 SetVariable setvar3,disable=0 1831 1832 // 1833 RemoveFromGraph/W=ManualFitPanel#G0 chi2_map 1834 1835 // Display/W=(259,23,643,346)/HOST=# 1836 AppendImage/W=ManualFitPanel#G0 chi2D 1837 SetActiveSubwindow ManualFitPanel#G0 1838 ModifyImage chi2D ctab= {*,*,ColdWarm,0} 1839 Label left "par" 1840 Label bottom "par2" 1841 SetActiveSubwindow ## 1842 1843 else 1844 SetVariable setvar0,disable=0 1845 SetVariable setvar3,disable=2 1846 1847 // 1848 RemoveImage/W=ManualFitPanel#G0 chi2D 1849 1850 AppendToGraph/W=ManualFitPanel#G0 root:chi2_map vs root:testVals 1851 SetActiveSubwindow ManualFitPanel#G0 1852 // Display/W=(259,23,643,346)/HOST=# root:chi2_map vs root:testVals 1853 ModifyGraph mode=4,msize=1,rgb=(65535,0,0) 1854 ModifyGraph tick=2,mirror=1 1855 Label left "Chi-squared" 1856 // Label bottom "degrees" 1857 SetActiveSubwindow ## 1858 1859 1860 endif 1861 1862 return(0) 1863 End 1864 1865 1866 Function getParamFromWrapper() 1867 1868 Variable parNum 1869 1870 GetSelection table, WrapperPanel#T0, 1 1871 parNum = V_startRow 1872 return(parNum) 1873 End 1874 1875 1876 Function VaryPCTButton(ctrlName) : ButtonControl 1877 String ctrlName 1878 1879 Variable percent 1880 strswitch(ctrlName) // string switch 1881 case "button0": 1882 percent = 105 1883 break 1884 case "button1": 1885 percent = 25 1886 break 1887 case "button2": 1888 percent = 5 1889 break 1890 case "button3": 1891 percent = 1 1892 break 1893 default: 1894 percent = 10 1895 endswitch 1896 1897 ControlInfo check0 1898 Variable isChecked = V_Value 1899 1900 // get the necessary info about parameters, etc. 1677 1901 String folderStr,funcStr,coefStr 1678 Variable useCursors,useResol=0,pt1,pt2 1902 Variable useCursors,useResol=0,pt1,pt2,minIndex 1679 1903 1680 1904 ControlInfo/W=WrapperPanel popup_0 … … 1687 1911 coefStr=S_Value 1688 1912 1689 ControlInfo/W=WrapperPanel check_01690 useCursors=V_Value1691 1913 // ControlInfo/W=WrapperPanel check_0 1914 // useCursors=V_Value 1915 // 1692 1916 1693 1917 // first, figure out where we are... … … 1705 1929 1706 1930 WAVE cw=$(coefStr) 1707 1931 SetDataFolder root: 1932 1933 1934 Variable loLim,hiLim,minChiSq 1935 1936 NVAR numStep = root:gNumManualSteps 1937 make/o/n=(numStep)/D root:testVals 1938 Wave testVals = root:testVals 1939 WAVE chi2_map = root:chi2_map 1940 Make/O/D/N=(numStep,numStep) root:chi2D 1941 WAVE chi2D = root:chi2D 1942 1943 1944 // then do either a 1D or 2D map of the chi squared 1945 if(isChecked) 1946 1947 NVAR par = root:gNumManualParam 1948 NVAR par2 = root:gNumManualParam2 1949 1950 Variable ii,jj,saveVal2 1951 saveVal2 = cw[par2] //initial value of par2 1952 1953 //steps in par2 direction 1954 make/o/n=(numStep)/D root:testVals2 1955 Wave testVals2 = root:testVals2 1956 loLim = cw[par2] - percent*cw[par2]/100 1957 hiLim = cw[par2] + percent*cw[par2]/100 1958 testVals2 = loLim + x*(hiLim-loLim)/numStep 1959 1960 SetScale/I x LoLim,HiLim,"", chi2D 1961 1962 //steps in par1 direction 1963 if(cw[par] != 0) 1964 loLim = cw[par] - percent*cw[par]/100 1965 hiLim = cw[par] + percent*cw[par]/100 1966 else 1967 loLim = -1 1968 hiLim = 1 1969 endif 1970 testVals = loLim + x*(hiLim-loLim)/numStep 1971 SetScale/I y LoLim,HiLim,"", chi2D 1972 1973 1974 for(ii=0;ii<numStep;ii+=1) 1975 cw[par2] = testVals2[ii] //set the value for par2, vary par 1976 1977 fChiMap_new(par,percent,cw,testVals) //the wave chi2_map is generated 1978 1979 chi2D[ii][] = chi2_map[q] 1980 1981 endfor 1982 1983 // set the new minimum value 1984 WaveStats/Q chi2D 1985 // now with scaled dimensions of Chi2D, the reported values are the values, not the point index 1986 cw[par] = V_MinColLoc 1987 cw[par2] = V_MinRowLoc 1988 1989 // the minimum chi_squared along this path is at: -- is it better? 1990 minChiSq = V_Min 1991 1992 NVAR curChi2=root:gCurrentChiSq 1993 curChi2 = minChiSq 1994 1995 //V_min*1.01 = the 1% neighborhood around the solution 1996 ModifyImage/W=ManualFitPanel#G0 chi2D ctab= {(V_min*1.01),*,ColdWarm,0} 1997 ModifyImage/W=ManualFitPanel#G0 chi2D minRGB=(0,65535,0),maxRGB=(0,65535,0) 1998 1999 else 2000 NVAR par = root:gNumManualParam 2001 par = getParamFromWrapper() 2002 2003 if(cw[par] != 0) 2004 loLim = cw[par] - percent*cw[par]/100 2005 hiLim = cw[par] + percent*cw[par]/100 2006 else 2007 loLim = -1 2008 hiLim = 1 2009 endif 2010 testVals = loLim + x*(hiLim-loLim)/numStep 2011 2012 2013 fChiMap_new(par,percent,cw,testVals) //the wave chi2_map is generated 2014 2015 // set the new minimum value 2016 WaveStats/Q chi2_map 2017 minIndex = V_minRowLoc 2018 cw[par] = testVals[minIndex] 2019 2020 // the minimum chi_squared along this path is at: -- is it better? 2021 minChiSq = chi2_map[minIndex] 2022 2023 NVAR curChi2=root:gCurrentChiSq 2024 curChi2 = minChiSq 2025 endif 2026 2027 2028 return(0) 2029 End 2030 2031 2032 Proc mMapChiSquared_Pct(paramNum,percent) 2033 Variable paramNum=0,percent=50 2034 Prompt paramNum, "Enter parameter number: " 2035 Prompt percent, "Enter percent variation:" 2036 2037 fChiMap_new(paramNum,percent) 2038 End 2039 2040 //Macro mMapChiSquared(paramNum,loLim,hiLim) 2041 // Variable paramNum=0,loLim=0,hiLim=1 2042 // Prompt paramNum, "Enter parameter number: " 2043 // Prompt loLim, "Enter lower value:" 2044 // Prompt hiLim, "Enter higher value:" 2045 // 2046 // fChiMap_new(paramNum,loLim,hiLim) 2047 //End 2048 2049 2050 // this does the setup 2051 Function fChiMap_new(paramNum,percent,cw,testVals) 2052 Variable paramNum,percent 2053 Wave cw,testVals 2054 2055 //Function fChiMap_new(paramNum,percent) 2056 // Variable paramNum,percent 2057 2058 2059 String folderStr,funcStr,coefStr 2060 Variable useCursors,useResol=0,pt1,pt2,minIndex 2061 2062 ControlInfo/W=WrapperPanel popup_0 2063 folderStr=S_Value 2064 2065 ControlInfo/W=WrapperPanel popup_1 2066 funcStr=S_Value 2067 2068 ControlInfo/W=WrapperPanel popup_2 2069 coefStr=S_Value 2070 2071 ControlInfo/W=WrapperPanel check_0 2072 useCursors=V_Value 2073 2074 // coefficent wave cw is passed in 1708 2075 1709 2076 // test for smeared function … … 1712 2079 endif 1713 2080 1714 // fill a struct instance whether I need one or not2081 // wave references for the data (to pass) 1715 2082 String DF="root:"+folderStr+":" 1716 2083 1717 // Struct ResSmearAAOStruct fs1718 // WAVE/Z resW = $(DF+folderStr+"_res") //these may not exist, if 3-column data is used1719 // WAVE/Z fs.resW = resW1720 2084 WAVE yw=$(DF+folderStr+"_i") 1721 2085 WAVE xw=$(DF+folderStr+"_q") 1722 2086 WAVE sw=$(DF+folderStr+"_s") 1723 // Wave fs.coefW = cw 1724 // Wave fs.yW = yw 1725 // Wave fs.xW = xw 1726 2087 1727 2088 if(useCursors) 1728 2089 if(pcsr(A) > pcsr(B)) … … 1738 2099 pt2 = numpnts(yw)-1 1739 2100 endif 1740 1741 1742 1743 chi2gen(funcStr,folderStr,xw,yw,sw,cw,paramNum,percent,pt1,pt2,useResol) 1744 1745 1746 End 1747 1748 //////////////////////////////////// 1749 // Modification from Matt Wasbrough to allow rescaling of the 1750 // axes while plotting and fitting. allows export of the rescaled 1751 // data and of the rescaled model 1752 // Nov 2012 1753 /// 1754 1755 Function UseRescaleAxisCheckProc(cba) : CheckBoxControl 1756 STRUCT WMCheckboxAction &cba 1757 1758 switch( cba.eventCode ) 1759 case 2: // mouse up 1760 Variable checked = cba.checked 1761 if(checked) 1762 Execute "OpenAxisPanel()" 1763 else 1764 if(exists("RescaleAxisPanel") !=0) 1765 DoWindow/K RescaleAxisPanel 1766 endif 1767 endif 1768 break 1769 endswitch 1770 1771 return 0 1772 End 1773 1774 Proc OpenAxisPanel() 1775 If(WinType("RescaleAxisPanel") == 0) 1776 //create the necessary data folder 1777 NewDataFolder/O root:Packages 1778 NewDataFolder/O root:Packages:NIST 1779 NewDataFolder/O root:Packages:NIST:RescaleAxis 1780 //initialize the values 1781 Variable/G root:Packages:NIST:RescaleAxis:gRAExpA = 1 1782 Variable/G root:Packages:NIST:RescaleAxis:gRAExpB = 1 1783 Variable/G root:Packages:NIST:RescaleAxis:gRAExpC = 1 1784 RescaleAxisPanel() 1785 else 1786 //window already exists, just bring to front for update 1787 DoWindow/F RescaleAxisPanel 1788 endif 1789 End 1790 1791 Window RescaleAxisPanel() 1792 PauseUpdate; Silent 1 // building window... 1793 NewPanel /W=(461,46,735,195)/K=1 1794 ModifyPanel cbRGB=(49360,30954,64507), fixedSize=1 1795 SetDrawLayer UserBack 1796 PopupMenu ymodel,pos={20,10},size={76,19},title="y-axis" 1797 PopupMenu ymodel,help={"This popup selects how the y-axis will be linearized based on the chosen data"} 1798 PopupMenu ymodel,mode=1,value= #"\"I;log(I);ln(I);1/I;I^a;Iq^a;I^a q^b;1/sqrt(I);ln(Iq);ln(Iq^2)\"" 1799 Button GoRescale,pos={50,80},size={70,20},proc=RescalePlot,title="Rescale" 1800 Button GoRescale,help={"This button will rescale the axis using the selections in this panel"} 1801 Button DoneButton,pos={170,80},size={70,20},proc=RADoneButton,title="Done" 1802 Button DoneButton,help={"This button will close the panel"} 1803 Button ExportData, pos={100,110}, size={90,20}, proc=ExportData, title="Export Data" 1804 Button ExportData, help={"This button will export data from the top graph"} 1805 SetVariable expa,pos={13,45},size={80,17},title="pow \"a\"" 1806 SetVariable expa,help={"This sets the exponent \"a\" for some y-axis formats. The value is ignored if the model does not use an adjustable exponent"} 1807 SetVariable expa,limits={-2,10,0},value= root:Packages:NIST:RescaleAxis:gRAExpA 1808 SetVariable expb,pos={98,45},size={80,17},title="pow \"b\"" 1809 SetVariable expb,help={"This sets the exponent \"b\" for some x-axis formats. The value is ignored if the model does not use an adjustable exponent"} 1810 SetVariable expb,limits={0,10,0},value= root:Packages:NIST:RescaleAxis:gRAExpB 1811 PopupMenu xmodel,pos={155,10},size={79,19},title="x-axis" 1812 PopupMenu xmodel,help={"This popup selects how the x-axis will be linearized given the chosen data"} 1813 PopupMenu xmodel,mode=1,value= #"\"q;log(q);q^2;q^c\"" 1814 SetVariable expc,pos={182,45},size={80,17},title="pow \"c\"" 1815 SetVariable expc,help={"This sets the exponent \"c\" for some x-axis formats. The value is ignored if the model does not use \"c\" as an adjustable exponent"} 1816 SetVariable expc,limits={-10,10,0},value= root:Packages:NIST:RescaleAxis:gRAExpC 1817 Button RAHelp, pos={220,110}, size={20,20}, proc=RAHelpButtonProc, title="?" 1818 EndMacro 1819 1820 Proc RADoneButton(ctrlName): ButtonControl 1821 String ctrlName 1822 DoWindow/K RescaleAxisPanel 1823 DoWindow/F WrapperPanel 1824 CheckBox check_8 value=0 1825 end 1826 1827 Function RAHelpButtonProc(ba) : ButtonControl 1828 STRUCT WMButtonAction &ba 1829 1830 switch( ba.eventCode ) 1831 case 2: // mouse up 1832 // click code here 1833 DisplayHelpTopic/Z/K=1 "Rescaled Axis" 1834 if(V_flag !=0) 1835 DoAlert 0,"The Rescaled Axis Help file could not be found" 1836 endif 1837 break 1838 endswitch 1839 1840 return 0 1841 End 1842 1843 Proc ExportData(ctrlName): ButtonControl 1844 string ctrlName 1845 WriteRescaledData() 1846 End 1847 1848 1849 Function RescalePlot (ctrlName): ButtonControl 1850 String ctrlName 2101 2102 Variable loLim,hiLim,minChiSq 2103 1851 2104 SetDataFolder root: 1852 String topGraph= WinName(0,1) //this is the topmost graph 1853 if(strlen(topGraph)==0) 1854 Abort "There is no graph" 1855 endif 1856 1857 DoWindow/F $topGraph 1858 GetWindow/Z $topGraph, wavelist 1859 wave/t W_Wavelist 1860 SetDataFolder root:Packages:NIST:RescaleAxis 1861 if (exists("W_WaveList")==1) 1862 KillWaves/Z root:Packages:NIST:RescaleAxis:W_WaveList 1863 endif 1864 MoveWave root:W_WaveList, root:Packages:NIST:RescaleAxis:W_WaveList 1865 SetDataFolder root:Packages:NIST:RescaleAxis 1866 variable i,j,k 1867 string DF,DF1,temp, temp2, t1 1868 for (i=0; i < numpnts(W_WaveList)/3; i+=1) 1869 temp = W_WaveList[i][1] 1870 if (stringmatch(temp, "*_i") || stringmatch(temp, "*_i_RA")) 1871 temp = W_WaveList[i][0] 1872 if(stringmatch(temp, "*_i")) 1873 temp = removeending(temp, "_i") 1874 elseif(stringmatch(temp, "*_i_RA")) 1875 temp = removeending(temp, "_i_RA") 1876 endif 1877 Make/T/O $temp/Wave=tempWave 1878 DF = ReplaceString(W_Wavelist[i][0],W_Wavelist[i][1],"") 1879 if (strlen(DF) ==0) 1880 DF = ":" 1881 endif 1882 DF1 = "root"+DF 1883 tempWave[0] = DF1 1884 k = 1 1885 for(j=0;j<numpnts(W_WaveList)/3; j+=1) 1886 if (stringmatch(W_WaveList[j][1], "*"+temp+"*")) 1887 tempWave[k] = W_WaveList[j][0] 1888 k = k+1 1889 endif 1890 endfor 1891 redimension/N=(k) tempWave 1892 elseif(stringmatch(temp, "*ywave*")) 1893 temp = W_WaveList[i][0] 1894 if(stringmatch(temp, "*_RA")) 1895 temp = removeending(temp, "_RA") 1896 endif 1897 Make/T/O $temp/Wave=tempWave 1898 DF = ReplaceString(W_Wavelist[i][0],W_Wavelist[i][1],"") 1899 if (strlen(DF) ==0) 1900 DF = ":" 1901 endif 1902 DF1 = "root"+DF 1903 tempWave[0] = DF1 1904 temp2 = replacestring("ywave", temp, "") 1905 k = 1 1906 for(j=0;j<numpnts(W_WaveList)/3; j+=1) 1907 t1 = W_Wavelist[j][1] 1908 if (stringmatch(W_WaveList[j][1], "*wave"+temp2+"*")) 1909 tempWave[k] = W_WaveList[j][1] 1910 k = k+1 1911 endif 1912 endfor 1913 redimension/N=(k) tempWave 1914 endif 2105 2106 NVAR numStep = root:gNumManualSteps 2107 make/o/n=(numStep)/D root:chi2_map 2108 Wave chi2_map = root:chi2_map 2109 // Wave testVals = root:testVals 2110 2111 //the testVals are genereated and passed by the calling routine 2112 2113 minIndex = chi2gen_new(funcStr,folderStr,xw,yw,sw,cw,paramNum,pt1,pt2,useResol,chi2_map,testVals) 2114 2115 return(0) 2116 End 2117 2118 2119 // this does the math for a single value of "whichParam" 2120 Function chi2gen_new(funcStr,folderStr,xw,yw,sw,cw,whichParam,lhs,rhs,useResol,chi2_map,testVals) 2121 String funcStr,folderStr 2122 Wave xw,yw,sw,cw // x data, y data, error wave, and coefficient wave 2123 variable whichParam //which of the parameters to you want to vary, how far from the original value do you want to search (%) 2124 variable lhs, rhs //specify a region of interest in the data using a left hand side and right hand side. 2125 variable useResol // =1 if smeared used 2126 Wave chi2_map,testVals 2127 2128 variable originalvalue = cw[whichparam] 2129 // variable range = originalValue * searchArea/100 2130 variable ii,err,minIndex 2131 2132 duplicate/o yw, :theoretical_data, :chi2_data 2133 Wave theoretical_data, chi2_data 2134 2135 String DF="root:"+folderStr+":" 2136 String suffix=getModelSuffix(funcStr) 2137 2138 // fill a struct instance whether it is needed or not 2139 Struct ResSmearAAOStruct fs 2140 WAVE/Z resW = $(DF+folderStr+"_res") //these may not exist, if 3-column data is used 2141 WAVE/Z fs.resW = resW 2142 // WAVE yw=$(DF+folderStr+"_i") //these are passed in 2143 // WAVE xw=$(DF+folderStr+"_q") 2144 // WAVE sw=$(DF+folderStr+"_s") 2145 Wave fs.coefW = cw 2146 Wave fs.yW = theoretical_data 2147 Wave fs.xW = xw 2148 2149 2150 2151 for(ii=0 ; ii < numpnts(chi2_map) ; ii+=1) 2152 cw[whichparam] = testVals[ii] 2153 2154 if(useResol) 2155 FUNCREF SANSModelSTRUCT_proto func1=$funcStr 2156 err = func1(fs) 2157 else 2158 FUNCREF SANSModelAAO_proto func2=$funcStr 2159 func2(cw,theoretical_data,xw) 2160 endif 2161 2162 chi2_data = (yw-theoretical_data)^2 2163 2164 chi2_data /= sw^2 2165 2166 Wavestats/q/R=[lhs, rhs] chi2_data 2167 2168 chi2_map[ii] = V_avg * V_npnts 1915 2169 endfor 1916 KillWaves/Z W_Wavelist 1917 string listWave = Wavelist("*", ";", "TEXT:1") 1918 string WaveToRescale, WaveDataFolder,xwave, ywave, swave 1919 1920 for (i = 0; i < ItemsInList(listWave,";"); i+=1) 1921 temp = StringFromList(i,listWave,";") 1922 Wave/T WaveString = $temp 1923 for (j=1; j < numpnts(WaveString); j+=1) 1924 WaveToRescale = Wavestring[j] 1925 if (stringmatch(WaveToRescale, "*_RA")) 1926 WaveToRescale = RemoveEnding(WaveToRescale, "_RA") 1927 endif 1928 WaveDataFolder = WaveString[0] 1929 SetDataFolder $WaveDataFolder 1930 if (stringmatch(WaveToRescale, "*_q")) 1931 xwave = WaveToRescale 1932 XRescale(xwave) 1933 elseif (stringmatch(WaveToRescale, "*_i")) 1934 ywave = WaveToRescale 1935 xwave = RemoveEnding(WaveToRescale, "_i")+"_q" 1936 YRescale(ywave, xwave) 1937 elseif (stringmatch(WaveToRescale, "*_s")) 1938 swave = WaveToRescale 1939 ywave = RemoveEnding(WaveToRescale, "_s")+"_i" 1940 xwave = RemoveEnding(WaveToRescale, "_s")+"_q" 1941 ERescale(swave, ywave, xwave) 1942 elseif (stringmatch(WaveToRescale, "xwave_*")) 1943 xwave=WaveToRescale 1944 XRescale(xwave) 1945 elseif (stringmatch(WaveToRescale, "ywave_*")) 1946 ywave = WaveToRescale 1947 xwave= ReplaceString("ywave", WaveToRescale, "xwave") 1948 YRescale(ywave, xwave) 1949 elseif(stringmatch(WaveToRescale, "*_qvals")) 1950 xwave = WaveToRescale 1951 XRescale(xwave) 1952 elseif(stringmatch(WaveToRescale, "smeared*") && stringmatch(WaveToRescale, "!*_qvals")) 1953 ywave = WaveToRescale 1954 for (k=1; k < numpnts(WaveString); k+=1) 1955 if (stringmatch(Wavestring[k], "*_qvals")) 1956 xwave = Wavestring[k] 1957 endif 1958 endfor 1959 YRescale(ywave, xwave) 1960 else 1961 ywave = WaveToRescale 1962 for (k=1; k < numpnts(WaveString); k+=1) 1963 if (stringmatch(Wavestring[k], "*_q")) 1964 xwave = Wavestring[k] 1965 endif 1966 endfor 1967 YRescale(ywave,xwave) 1968 string yAxis = ywave+"_RA" 1969 wave yAxisWave = $yAxis 1970 SetFormula yAxisWave, "YRescale(ywave,xwave)" 1971 endif 1972 SetDataFolder root:Packages:NIST:RescaleAxis 1973 endfor 1974 endfor 1975 1976 string oldywave, xstr, ystr 1977 for (i = 0; i < ItemsInList(listWave,";"); i+=1) 1978 temp = StringFromList(i,listWave,";") 1979 Wave/T WaveString = $temp 1980 for (j=1; j < numpnts(WaveString); j+=1) 1981 WaveToRescale = Wavestring[j] 1982 WaveDataFolder = WaveString[0] 1983 SetDataFolder $WaveDataFolder 1984 ControlInfo/W=RescaleAxisPanel yModel 1985 ystr = S_Value 1986 ControlInfo/W=RescaleAxisPanel xModel 1987 xstr = S_Value 1988 if(cmpstr("I",ystr)==0 && cmpstr("q",xstr)==0) 1989 if(stringmatch(WaveToRescale, "*_i_RA")) 1990 oldywave = WaveToRescale 1991 ywave = RemoveEnding(WaveToRescale,"_RA") 1992 xwave = RemoveEnding(WaveToRescale, "_i_RA")+"_q" 1993 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 1994 replacewave/X/W=$topGraph trace=$ywave, $xwave 1995 swave = RemoveEnding(WaveToRescale, "_i_RA")+"_s" 1996 if(exists(swave)==1) 1997 ErrorBars/T=0/W=$topGraph $ywave, Y wave=($swave,$swave) 1998 endif 1999 elseif (stringmatch(WaveToRescale, "smeared*")) 2000 if(stringmatch(WaveToRescale,"*_RA") && stringmatch(WaveToRescale,"!*_qvals*") ) 2001 oldywave = WaveToRescale 2002 ywave = RemoveEnding(WaveToRescale,"_RA") 2003 xwave = "smeared_qvals" 2004 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2005 replacewave/X/W=$topGraph trace=$ywave, $xwave 2006 endif 2007 elseif(stringmatch(WaveToRescale,"ywave*") && stringmatch(WaveToRescale,"*_RA")) 2008 oldywave = WaveToRescale 2009 ywave = RemoveEnding(WaveToRescale,"_RA") 2010 xwave = ReplaceString("ywave",ywave,"xwave") 2011 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2012 replacewave/X/W=$topGraph trace=$ywave, $xwave 2013 elseif(stringmatch(WaveToRescale, "*FitYw*") && stringmatch(WaveToRescale, "*_RA")) 2014 oldywave = WaveToRescale 2015 ywave = RemoveEnding(WaveToRescale,"_RA") 2016 for (k=1; k < numpnts(WaveString); k+=1) 2017 if (stringmatch(Wavestring[k], "*_q")) 2018 xwave = Wavestring[k] 2019 endif 2020 endfor 2021 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2022 replacewave/X/W=$topGraph trace=$ywave, $xwave 2023 endif 2024 elseif(stringmatch(WaveToRescale, "*_RA")) 2025 elseif (stringmatch(WaveToRescale, "*_i")) 2026 DoWindow/F topGraph 2027 oldywave = WaveToRescale 2028 xwave = RemoveEnding(WaveToRescale, "_i")+"_q_RA" 2029 ywave = WaveToRescale + "_RA" 2030 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2031 replacewave/X/W=$topGraph trace=$ywave, $xwave 2032 ModifyGraph log=0 2033 swave = RemoveEnding(WaveToRescale, "_i")+"_s_RA" 2034 if(exists(swave)==1) 2035 ErrorBars/T=0/W=$topGraph $ywave, Y wave=($swave,$swave) 2036 endif 2037 DoUpdate 2038 elseif(stringmatch(WaveToRescale, "smeared*") && stringmatch(WaveToRescale, "!*_qvals")) 2039 oldywave = WaveToRescale 2040 ywave = WaveToRescale + "_RA" 2041 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2042 xwave = "smeared_qvals_RA" 2043 replacewave/X/W=$topGraph trace=$ywave, $xwave 2044 elseif(stringmatch(WaveToRescale,"ywave*")) 2045 oldywave = WaveToRescale 2046 ywave = WaveToRescale + "_RA" 2047 xwave = ReplaceString("ywave",ywave,"xwave") 2048 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2049 replacewave/X/W=$topGraph trace=$ywave, $xwave 2050 elseif(stringmatch(WaveToRescale, "*FitYw*")) 2051 oldywave = WaveToRescale 2052 ywave = WaveToRescale+"_RA" 2053 for (k=1; k < numpnts(WaveString); k+=1) 2054 if (stringmatch(Wavestring[k], "*_q")) 2055 xwave = Wavestring[k]+"_RA" 2056 endif 2057 endfor 2058 replacewave/Y/W=$topGraph trace=$oldywave, $ywave 2059 replacewave/X/W=$topGraph trace=$ywave, $xwave 2060 endif 2061 SetDataFolder root:Packages:NIST:RescaleAxis 2062 DoUpdate 2063 endfor 2064 endfor 2065 KillWaves/A/Z 2066 2067 string ylabel, xlabel 2068 ControlInfo/W=RescaleAxisPanel yModel 2069 ystr = S_Value 2070 ControlInfo/W=RescaleAxisPanel xModel 2071 xstr = S_Value 2072 2073 if(cmpstr("I",ystr)==0 && cmpstr("q",xstr)==0) 2074 modifygraph log=1 2075 else 2076 modifygraph log=0 2077 endif 2078 2079 Variable pow_a,pow_b,pow_c 2080 ControlInfo/W=RescaleAxisPanel expa 2081 pow_a = V_value 2082 ControlInfo/W=RescaleAxisPanel expb 2083 pow_b = V_value 2084 ControlInfo/W=RescaleAxisPanel expc 2085 pow_c = V_value 2086 2087 If (cmpstr("I",ystr) == 0) 2088 ylabel = "I(q)" 2089 elseif (cmpstr("ln(I)",ystr) == 0) 2090 ylabel = "ln(I)" 2091 elseif (cmpstr("log(I)",ystr) == 0) 2092 ylabel = "log(I)" 2093 elseif (cmpstr("1/I",ystr) == 0) 2094 ylabel = "1/I" 2095 elseif (cmpstr("I^a",ystr) == 0) 2096 ylabel = "I\S"+num2str(pow_a)+"\M" 2097 elseif (cmpstr("Iq^a",ystr) == 0) 2098 ylabel = "Iq\S"+num2str(pow_a)+"\M" 2099 elseif (cmpstr("I^a q^b",ystr) == 0) 2100 ylabel = "I\S"+num2str(pow_a)+"\Mq\S"+num2str(pow_b)+"\M" 2101 elseif (cmpstr("1/sqrt(I)",ystr) == 0) 2102 ylabel = "1/sqrt(I)" 2103 elseif (cmpstr("ln(Iq)",ystr) == 0) 2104 ylabel = "ln(Iq)" 2105 elseif (cmpstr("ln(Iq^2)",ystr) == 0) 2106 ylabel = "ln(Iq\S2\M)" 2107 endif 2108 2109 If (cmpstr("q",xstr) == 0) 2110 xlabel = "q (A\S-1\M)" 2111 elseif (cmpstr("q^2",xstr) == 0) 2112 xlabel = "q\S2\M" 2113 elseif (cmpstr("log(q)",xstr) == 0) 2114 xlabel = "log(q)" 2115 elseif (cmpstr("q^c",xstr) == 0) 2116 xlabel = "q\S"+num2str(pow_c)+"\M" 2117 endif 2118 2119 SetAxis/A 2120 Label left ylabel 2121 Label bottom xlabel 2122 2123 SetDataFolder root: 2124 End 2125 2126 Function YRescale(ywave, xwave) 2127 String ywave,xwave 2128 2129 Wave yw = $ywave 2130 Wave xw = $xwave 2131 2132 //Scaling exponents and background value 2133 Variable pow_a,pow_b,pow_c 2134 ControlInfo/W=RescaleAxisPanel expa 2135 pow_a = V_value 2136 ControlInfo/W=RescaleAxisPanel expb 2137 pow_b = V_value 2138 ControlInfo/W=RescaleAxisPanel expc 2139 pow_c = V_value 2140 2141 //check for physical limits on exponent values 2142 // if bad values found, alert, and reset to good values so the rescaling can continue 2143 NVAR gA = root:Packages:NIST:RescaleAxis:gRAExpA 2144 NVAR gB = root:Packages:NIST:RescaleAxis:gRAExpB 2145 NVAR gC = root:Packages:NIST:RescaleAxis:gRAExpC 2146 if((pow_a < -2) || (pow_a > 10)) 2147 DoAlert 0,"Exponent a must be in the range (-2,10) - the exponent a has been reset to 1" 2148 gA = 1 2149 endif 2150 if((pow_b < 0) || (pow_b > 10)) 2151 DoAlert 0,"Exponent b must be in the range (0,10) - the exponent b has been reset to 1" 2152 gB = 1 2153 endif 2154 //if q^c is the x-scaling, c must be be within limits and also non-zero 2155 ControlInfo/W=RescaleAxisPanel xModel 2156 If (cmpstr("q^c",S_Value) == 0) 2157 if(pow_c == 0) 2158 DoAlert 0,"Exponent c must be non-zero, c has been reset to 1" 2159 gC = 1 2160 endif 2161 if((pow_c < -10) || (pow_c > 10)) 2162 DoAlert 0,"Exponent c must be in the range (-10,10), c has been reset to 1" 2163 gC = 1 2164 endif 2165 endif 2166 2167 //variables set for each model to control look of graph 2168 String ystr, yAxis 2169 //check for proper y-scaling selection, make the necessary waves 2170 // Wave yAxisWave 2171 2172 ControlInfo/W=RescaleAxisPanel yModel 2173 ystr = S_Value 2174 2175 do 2176 If (cmpstr("I",S_Value) == 0) 2177 yAxis = ywave+"_RA" 2178 if (exists(yAxis)== 0) 2179 Duplicate yw $yAxis 2180 endif 2181 SetScale d 0,0,"1/cm",$yAxis 2182 wave yAxisWave = $yAxis 2183 yAxisWave = yw 2184 break 2185 endif 2186 If (cmpstr("ln(I)",S_Value) == 0) 2187 yAxis = ywave+"_RA" 2188 if (exists(yAxis)== 0) 2189 Duplicate yw $yAxis 2190 endif 2191 SetScale d 0,0,"",$yAxis 2192 wave yAxisWave = $yAxis 2193 yAxisWave = ln(yw) 2194 break 2195 endif 2196 If (cmpstr("log(I)",S_Value) == 0) 2197 yAxis = ywave+"_RA" 2198 if (exists(yAxis)== 0) 2199 Duplicate yw $yAxis 2200 endif 2201 SetScale d 0,0,"",$yAxis 2202 wave yAxisWave = $yAxis 2203 yAxisWave = log(yw) 2204 break 2205 endif 2206 If (cmpstr("1/I",S_Value) == 0) 2207 yAxis = ywave+"_RA" 2208 if (exists(yAxis)== 0) 2209 Duplicate yw $yAxis 2210 endif 2211 SetScale d 0,0,"",$yAxis 2212 wave yAxisWave = $yAxis 2213 yAxisWave = 1/(yw) 2214 break 2215 endif 2216 If (cmpstr("I^a",S_Value) == 0) 2217 yAxis = ywave+"_RA" 2218 if (exists(yAxis)== 0) 2219 Duplicate yw $yAxis 2220 endif 2221 SetScale d 0,0,"",$yAxis 2222 wave yAxisWave = $yAxis 2223 yAxisWave = yw^pow_a 2224 break 2225 endif 2226 If (cmpstr("Iq^a",S_Value) == 0) 2227 yAxis = ywave+"_RA" 2228 if (exists(yAxis)== 0) 2229 Duplicate yw $yAxis 2230 endif 2231 SetScale d 0,0,"",$yAxis 2232 wave yAxisWave = $yAxis 2233 yAxisWave = yw*xw^pow_a 2234 break 2235 endif 2236 If (cmpstr("I^a q^b",S_Value) == 0) 2237 yAxis = ywave+"_RA" 2238 if (exists(yAxis)== 0) 2239 Duplicate yw $yAxis 2240 endif 2241 SetScale d 0,0,"",$yAxis 2242 wave yAxisWave = $yAxis 2243 yAxisWave = yw^pow_a*xw^pow_b 2244 break 2245 endif 2246 If (cmpstr("1/sqrt(I)",S_Value) == 0) 2247 yAxis = ywave+"_RA" 2248 if (exists(yAxis)== 0) 2249 Duplicate yw $yAxis 2250 endif 2251 SetScale d 0,0,"",$yAxis 2252 wave yAxisWave = $yAxis 2253 yAxisWave = 1/sqrt(yw) 2254 break 2255 endif 2256 If (cmpstr("ln(Iq)",S_Value) == 0) 2257 yAxis = ywave+"_RA" 2258 if (exists(yAxis)== 0) 2259 Duplicate yw $yAxis 2260 endif 2261 SetScale d 0,0,"",$yAxis 2262 wave yAxisWave = $yAxis 2263 yAxisWave = ln(xw*yw) 2264 break 2265 endif 2266 If (cmpstr("ln(Iq^2)",S_Value) == 0) 2267 yAxis = ywave+"_RA" 2268 if (exists(yAxis)== 0) 2269 Duplicate yw $yAxis 2270 endif 2271 SetScale d 0,0,"",$yAxis 2272 wave yAxisWave = $yAxis 2273 yAxisWave = ln(xw*xw*yw) 2274 break 2275 endif 2276 //more ifs for each case 2277 2278 // if selection not found, abort 2279 DoAlert 0,"Y-axis scaling incorrect. Aborting" 2280 Abort 2281 while(0) 2282 End 2283 2284 Function XRescale(xwave) 2285 String xwave 2286 2287 Wave xw = $xwave 2288 2289 //Scaling exponents and background value 2290 Variable pow_a,pow_b,pow_c 2291 ControlInfo/W=RescaleAxisPanel expa 2292 pow_a = V_value 2293 ControlInfo/W=RescaleAxisPanel expb 2294 pow_b = V_value 2295 ControlInfo/W=RescaleAxisPanel expc 2296 pow_c = V_value 2297 2298 //check for physical limits on exponent values 2299 // if bad values found, alert, and reset to good values so the rescaling can continue 2300 NVAR gA = root:Packages:NIST:RescaleAxis:gRAExpA 2301 NVAR gB = root:Packages:NIST:RescaleAxis:gRAExpB 2302 NVAR gC = root:Packages:NIST:RescaleAxis:gRAExpC 2303 if((pow_a < -2) || (pow_a > 10)) 2304 DoAlert 0,"Exponent a must be in the range (-2,10) - the exponent a has been reset to 1" 2305 gA = 1 2306 endif 2307 if((pow_b < 0) || (pow_b > 10)) 2308 DoAlert 0,"Exponent b must be in the range (0,10) - the exponent b has been reset to 1" 2309 gB = 1 2310 endif 2311 //if q^c is the x-scaling, c must be be within limits and also non-zero 2312 ControlInfo/W=RescaleAxisPanel xModel 2313 If (cmpstr("q^c",S_Value) == 0) 2314 if(pow_c == 0) 2315 DoAlert 0,"Exponent c must be non-zero, c has been reset to 1" 2316 gC = 1 2317 endif 2318 if((pow_c < -10) || (pow_c > 10)) 2319 DoAlert 0,"Exponent c must be in the range (-10,10), c has been reset to 1" 2320 gC = 1 2321 endif 2322 endif 2323 2324 //variables set for each model to control look of graph 2325 String xstr, xAxis 2326 //check for proper y-scaling selection, make the necessary waves 2327 // Wave xAxisWave 2328 2329 ControlInfo/W=RescaleAxisPanel xModel 2330 xstr = S_Value 2331 do 2332 // make the new yaxis wave 2333 If (cmpstr("q",S_Value) == 0) 2334 xAxis = xwave+"_RA" 2335 if (exists(xAxis)== 0) 2336 Duplicate xw $xAxis 2337 endif 2338 SetScale d 0,0,"A^-1",$xAxis 2339 wave xAxisWave = $xAxis 2340 xAxisWave = xw 2341 break 2342 endif 2343 If (cmpstr("q^2",S_Value) == 0) 2344 xAxis = xwave+"_RA" 2345 if (exists(xAxis)== 0) 2346 Duplicate xw $xAxis 2347 endif 2348 SetScale d 0,0,"A^-2",$xAxis 2349 wave xAxisWave = $xAxis 2350 xAxisWave = xw*xw 2351 break 2352 endif 2353 If (cmpstr("log(q)",S_Value) == 0) 2354 xAxis = xwave+"_RA" 2355 if (exists(xAxis)== 0) 2356 Duplicate xw $xAxis 2357 endif 2358 SetScale d 0,0,"",$xAxis 2359 wave xAxisWave = $xAxis 2360 xAxisWave = log(xw) 2361 break 2362 endif 2363 If (cmpstr("q^c",S_Value) == 0) 2364 xAxis = xwave+"_RA" 2365 if (exists(xAxis)== 0) 2366 Duplicate xw $xAxis 2367 endif 2368 SetScale d 0,0,"", $xAxis 2369 wave xAxisWave = $xAxis 2370 xAxisWave = xw^pow_c 2371 break 2372 endif 2373 2374 //more ifs for each case 2375 // if selection not found, abort 2376 DoAlert 0,"X-axis scaling incorrect. Aborting" 2377 Abort 2378 while(0) //end of "case" statement for x-axis scaling 2379 End 2380 2381 Function ERescale(swave, ywave, xwave) 2382 String swave, ywave, xwave 2383 2384 Wave ew = $swave 2385 Wave yw = $ywave 2386 Wave xw = $xwave 2387 2388 //Scaling exponents and background value 2389 Variable pow_a,pow_b,pow_c 2390 ControlInfo/W=RescaleAxisPanel expa 2391 pow_a = V_value 2392 ControlInfo/W=RescaleAxisPanel expb 2393 pow_b = V_value 2394 ControlInfo/W=RescaleAxisPanel expc 2395 pow_c = V_value 2396 2397 //check for physical limits on exponent values 2398 // if bad values found, alert, and reset to good values so the rescaling can continue 2399 NVAR gA = root:Packages:NIST:RescaleAxis:gRAExpA 2400 NVAR gB = root:Packages:NIST:RescaleAxis:gRAExpB 2401 NVAR gC = root:Packages:NIST:RescaleAxis:gRAExpC 2402 if((pow_a < -2) || (pow_a > 10)) 2403 DoAlert 0,"Exponent a must be in the range (-2,10) - the exponent a has been reset to 1" 2404 gA = 1 2405 endif 2406 if((pow_b < 0) || (pow_b > 10)) 2407 DoAlert 0,"Exponent b must be in the range (0,10) - the exponent b has been reset to 1" 2408 gB = 1 2409 endif 2410 //if q^c is the x-scaling, c must be be within limits and also non-zero 2411 ControlInfo/W=RescaleAxisPanel xModel 2412 If (cmpstr("q^c",S_Value) == 0) 2413 if(pow_c == 0) 2414 DoAlert 0,"Exponent c must be non-zero, c has been reset to 1" 2415 gC = 1 2416 endif 2417 if((pow_c < -10) || (pow_c > 10)) 2418 DoAlert 0,"Exponent c must be in the range (-10,10), c has been reset to 1" 2419 gC = 1 2420 endif 2421 endif 2422 2423 //variables set for each model to control look of graph 2424 String ystr, eWave 2425 //check for proper y-scaling selection, make the necessary waves 2426 // Wave yErrWave 2427 2428 ControlInfo/W=RescaleAxisPanel yModel 2429 ystr = S_Value 2430 do 2431 2432 If (cmpstr("I",S_Value) == 0) 2433 eWave = swave+"_RA" 2434 if (exists(eWave) == 0) 2435 Duplicate ew $eWave 2436 endif 2437 wave yErrWave = $eWave 2438 yErrWave = ew 2439 break 2440 endif 2441 If (cmpstr("ln(I)",S_Value) == 0) 2442 eWave = swave+"_RA" 2443 if (exists(eWave) == 0) 2444 Duplicate ew $eWave 2445 endif 2446 wave yErrWave = $eWave 2447 yErrWave = ew/yw 2448 break 2449 endif 2450 If (cmpstr("log(I)",S_Value) == 0) 2451 eWave = swave+"_RA" 2452 if (exists(eWave) == 0) 2453 Duplicate ew $eWave 2454 endif 2455 wave yErrWave = $eWave 2456 yErrWave = ew/(2.30*yw) 2457 break 2458 endif 2459 If (cmpstr("1/I",S_Value) == 0) 2460 eWave = swave+"_RA" 2461 if (exists(eWave) == 0) 2462 Duplicate ew $eWave 2463 endif 2464 wave yErrWave = $eWave 2465 yErrWave = ew/(yw^2) 2466 break 2467 endif 2468 If (cmpstr("I^a",S_Value) == 0) 2469 eWave = swave+"_RA" 2470 if (exists(eWave) == 0) 2471 Duplicate ew $eWave 2472 endif 2473 wave yErrWave = $eWave 2474 yErrWave = ew*abs(pow_a*(yw^(pow_a-1))) 2475 break 2476 endif 2477 If (cmpstr("Iq^a",S_Value) == 0) 2478 eWave = swave+"_RA" 2479 if (exists(eWave) == 0) 2480 Duplicate ew $eWave 2481 endif 2482 wave yErrWave = $eWave 2483 yErrWave = ew*xw^pow_a 2484 break 2485 endif 2486 If (cmpstr("I^a q^b",S_Value) == 0) 2487 eWave = swave+"_RA" 2488 if (exists(eWave) == 0) 2489 Duplicate ew $eWave 2490 endif 2491 wave yErrWave = $eWave 2492 yErrWave = ew*abs(pow_a*(yw^(pow_a-1)))*xw^pow_b 2493 break 2494 endif 2495 If (cmpstr("1/sqrt(I)",S_Value) == 0) 2496 eWave = swave+"_RA" 2497 if (exists(eWave) == 0) 2498 Duplicate ew $eWave 2499 endif 2500 wave yErrWave = $eWave 2501 yErrWave = 0.5*ew*yw^(-1.5) 2502 break 2503 endif 2504 If (cmpstr("ln(Iq)",S_Value) == 0) 2505 eWave = swave+"_RA" 2506 if (exists(eWave) == 0) 2507 Duplicate ew $eWave 2508 endif 2509 wave yErrWave = $eWave 2510 yErrWave =ew/yw 2511 break 2512 endif 2513 If (cmpstr("ln(Iq^2)",S_Value) == 0) 2514 eWave = swave+"_RA" 2515 if (exists(eWave) == 0) 2516 Duplicate ew $eWave 2517 endif 2518 wave yErrWave = $eWave 2519 yErrWave = ew/yw 2520 break 2521 endif 2522 //more ifs for each case 2523 2524 // if selection not found, abort 2525 DoAlert 0,"Y-axis scaling incorrect. Aborting" 2526 Abort 2527 while(0) //end of "case" statement for y-axis scaling 2528 2529 End 2530 2531 /////////////////////////// 2532 2170 2171 cw[whichparam] = originalvalue 2172 2173 2174 WaveStats/Q chi2_map 2175 minIndex = V_minRowLoc 2176 // Print "minimum at: ", minIndex,chi2_map[minIndex] 2177 2178 killwaves/z theoretical_data, chi2_data 2179 return(minIndex) 2180 End 2181 2182 //////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.