#pragma rtGlobals=1 // Use modern global access method. #pragma version=3.00 #pragma IgorVersion=6.0 //Functions for doing USANS Slit smearing by method of weight matrix //Routines originally from J Barker fortran code //Translated to IGOR by M-H Kim //Updated to use IGOR features and integrated into SANS Macros by A J Jackson // // AJJ // July 26 2007 - Modified functions to work with new SANS Analysis Macros // - pass basestr to functions to determine wave names and avoid globals // - pass dQv to functions to avoid globals // - pass N to CalcR to avoid globals // Function USANS_CalcWeights(basestr, dQv) String basestr Variable dQv Variable/G USANS_N=numpnts(\$(basestr+"_q")) Variable/G USANS_dQv = dQv String/G USANS_basestr = basestr Make/D/O/N=(USANS_N,USANS_N) \$(basestr+"_res") Make/D/O/N=(USANS_N,USANS_N) W1mat Make/D/O/N=(USANS_N,USANS_N) W2mat Make/D/O/N=(USANS_N,USANS_N) Rmat Wave weights = \$(basestr+"_res") //Variable/G USANS_m = EnterSlope(baseStr) Variable/G USANS_m = -4 Variable/G USANS_slope_numpnts = 10 EnterSlope(basestr) print USANS_m if (USANS_m == 999) KillWaves/Z \$(basestr+"_res"),W1Mat,W2mat,Rmat return(1) endif Variable tref = startMSTimer print "Calculating W1..." W1mat = (p <= q ) && (q <= USANS_N-2) ? CalcW1(p,q) : 0 print "Calculating W2..." W2mat = (p+1 <= q ) && (q <= USANS_N-1) ? CalcW2(p,q) : 0 print "Calculating Remainders..." Rmat = (q == USANS_N-1) ? CalcR(p) : 0 // print "Summing weights..." weights = W1mat + W2mat + Rmat print "Done" Variable ms = stopMSTimer(tref) print "Time elapsed = ", ms/1e6, "s" //return Weights End Function EnterSlope(baseStr) String baseStr // Variable slope=-4 // Prompt slope "Enter a slope for the file \""+ baseStr + "\"" // DoPrompt "Enter Slope", slope // If (V_Flag) // return (999) //return a bogus slope if the user canceled // Endif // print "slope=", slope // return slope NewPanel /K=1/W=(1141,543,1548,910)/N=USANS_Slope as "USANS Slope Extrapolation" SetDrawLayer UserBack Button button_OK,pos={294,317},size={100,20},title="Accept Slope",font="Geneva" Button button_OK,proc=USANS_Slope_ButtonProc Button button_Cancel,pos={233,317},size={55,20},title="Cancel",font="Geneva" Button button_Cancel,proc=USANS_Slope_ButtonProc SetVariable setvar_numpnts, pos={43,350}, size={150,19}, title="# Points",fSize=13 SetVariable setvar_numpnts, value= USANS_slope_numpnts SetVariable setvar_Slope,pos={43,321},size={100,19},title="Slope",fSize=13 SetVariable setvar_Slope,limits={-inf,inf,0},value= USANS_m Display/W=(9,6,402,305)/HOST=USANS_Slope \$(basestr+"_i") vs \$(basestr+"_q") RenameWindow #,SlopePlot ModifyGraph log=1 SetActiveSubwindow ## Print GetDataFolder(1) PauseForUser USANS_Slope Print GetDataFolder(1) // return slope End Function USANS_Slope_ButtonProc(ctrlName) : ButtonControl String ctrlName NVAR USANS_m strswitch (ctrlName) case "button_OK": ControlUpdate/W=USANS_Slope setvar_Slope DoWindow/K USANS_Slope break case "button_Cancel": DoWindow/K USANS_Slope USANS_m = 999 break endswitch End Function CalcW1(i,j) Variable i,j SVAR USANS_basestr NVAR dQv = USANS_dQv Variable UU,UL,dqj,rU,rL,wU,wL,dqw Wave Qval = \$(USANS_basestr+"_q") UU =sqrt(Qval[j+1]^2-Qval[i]^2) UL = sqrt(Qval[j]^2-Qval[i]^2) dqw = Qval[j+1]-Qval[j] rU = sqrt(UU^2+Qval[i]^2) rL = sqrt(UL^2+Qval[i]^2) wU = (1.0/dQv)*(Qval[j+1]*UU/dqw - 0.5*UU*rU/dqw - 0.5*Qval[i]^2*ln(UU+rU)/dqw ) wL = (1.0/dQv)*(Qval[j+1]*UL/dqw - 0.5*UL*rL/dqw - 0.5*Qval[i]^2*ln(UL+rL)/dqw ) Return wU-wL End Function CalcW2(i,j) Variable i,j SVAR USANS_basestr NVAR dQv = USANS_dQv variable UU,UL,dqw,rU,rL,wU,wL Wave Qval = \$(USANS_basestr+"_q") UU = sqrt(Qval[j]^2-Qval[i]^2) UL = sqrt(Qval[j-1]^2-Qval[i]^2) dqw = Qval[j]-Qval[j-1] rU = sqrt(UU^2+Qval[i]^2) rL = sqrt(UL^2+Qval[i]^2) wU = (1.0/dQv)*( -Qval[j-1]*UU/dqw + 0.5*UU*rU/dqw + 0.5*Qval[i]^2*ln(UU+rU)/dqw ) wL = (1.0/dQv)*( -Qval[j-1]*UL/dqw + 0.5*UL*rL/dqw + 0.5*Qval[i]^2*ln(UL+rL)/dqw ) Return wU-wL End Function CalcR(i) Variable i SVAR USANS_basestr NVAR m = USANS_m NVAR N = USANS_N NVAR dQv = USANS_dQv Variable retval Wave Qval = \$(USANS_basestr+"_q") Wave Ival = \$(USANS_basestr+"_i") Variable/G USANS_intQpt = Qval[i] Variable lower = sqrt(qval[N-1]^2-qval[i]^2) Variable upper = dQv if (i == N) lower = 0 endif retval = Integrate1D(Remainder,lower,upper) retval *= 1/dQv Return retval End Function Remainder(i) Variable i SVAR USANS_basestr NVAR m = USANS_m NVAR qi = USANS_intQpt NVAR N = USANS_N WAVE Qval = \$(USANS_basestr+"_q") Variable retVal retVal=Qval[N-1]^(-m)*(i^2+qi^2)^(m/2) return retval End Window USANS_Slope() : Panel PauseUpdate; Silent 1 // building window... NewPanel /K=1/W=(1141,543,1548,910) as "USANS Slope Extrapolation" SetDrawLayer UserBack Button button_OK,pos={294,317},size={100,20},title="Accept Slope",font="Geneva" Button button_Cancel,pos={233,317},size={55,20},title="Cancel",font="Geneva" SetVariable setvar_Slope,pos={43,321},size={100,19},title="Slope",fSize=13 SetVariable setvar_Slope,limits={-inf,inf,0},value= USANS_m Display/W=(9,6,402,305)/HOST=# RenameWindow #,G0 SetActiveSubwindow ## EndMacro