#pragma rtGlobals=1 // Use modern global access method. #pragma IgorVersion=6.1 // 07 JAN 05 SRK // updated procedures (from SS 2002) to be used as a package // with the SANS analysis routines // // need to: // - verify accuracy (see John) // this is the main entry point for the panel Proc Make_Invariant_Panel() DoWindow/F Invariant_Panel if(V_flag==0) //create global variables in root:myGlobals:invariant Init_Invariant() Invariant_Panel() endif //pop the file menu Inv_FilePopMenuProc("",1,"") End //create the globals Proc Init_Invariant() NewDataFolder/O root:Packages NewDataFolder/O root:Packages:NIST NewDataFolder/O/S root:Packages:NIST:invariant Variable/G gNumLow=10 Variable/G gNumHigh=10 Variable/G gInvMeas=0 Variable/G gInvLowQ=0 Variable/G gInvHighQ=0 Variable/G gInvTotal=0 String/G gDataPopList = "none" Variable/G gIsSlitSmeared=0 Variable/G gDqv = 0.117 //default value for USANS slit height (re-read from file) // new July 2008 Variable/G gSlopeVal = -4 SetDataFolder root: End // for testing - compare to the "perfect" value. This macro // calculates the invariant based on the contrast and volume fraction // - the extrapolated/integrated value should match this... Macro PrintModelInvariant(delta_rho,phi) Variable delta_rho=3e-6,phi=0.1 Prompt delta_rho,"Contrast (1/A^2)" Prompt phi,"Volume fraction" // delta_rho [=] 1/A^2 Variable inv inv = 2*pi*pi*delta_rho*delta_rho*phi*(1-phi)*1e8 Printf "The model invariant is %g A^-3 cm^-1\r\r",inv End // for testing - compare to the "perfect" value. This macro // calculates the invariant based on the contrast and volume fraction // - the extrapolated/integrated value should match this... Macro SolveForVolumeFraction(invariant,delta_rho) Variable invariant,delta_rho=6e-6 Prompt invariant,"Invariant [=] cm^-1 A^-3" Prompt delta_rho,"Contrast (1/A^2)" // delta_rho [=] 1/A^2 Variable phi1,phi2,arg arg = 1 - 4*invariant*(1e-8)/2/pi/pi/delta_rho/delta_rho phi1 = (1 - sqrt(arg))/2 phi2 = (1 + sqrt(arg))/2 Printf "The two solutions for phi are: %8.6f\t and %8.6f\r\r",phi1,phi2 End //integrates only over the given q-range, does no interpolation Function Invariant(qw,iw) Wave qw,iw Variable num,invar Duplicate/O qw integrand integrand = qw*qw*iw // integrand /= 1e8 //convert 1/cm to 1/A num = numpnts(qw) invar = areaXY(qw,integrand,qw[0],qw[num-1]) return(invar) //units of A^-3 cm^-1 End //integrates only over the given q-range, does no interpolation // function is for slit smeared data Function Invariant_SlitSmeared(qw,iw) Wave qw,iw Variable num,invar NVAR dQv = root:Packages:NIST:invariant:gDqv Duplicate/O qw integrand integrand = qw*iw // integrand /= 1e8 //convert 1/cm to 1/A num = numpnts(qw) invar = areaXY(qw,integrand,qw[0],qw[num-1]) invar *= dQv //correct for the effects of slit-smearing return(invar) //units of A^-3 cm^-1 End Function Guinier_Fit(w,x) : FitFunc Wave w Variable x //fit data to I(q) = A*exp(B*q^2) // (B will be negative) //two parameters Variable a,b,ans a=w[0] b=w[1] ans = a*exp(b*x*x) return(ans) End //pass the wave with the q-values Function SetExtrWaves(w) Wave w Variable num_extr=100 Make/O/D/N=(num_extr) extr_hqq,extr_hqi,extr_lqq,extr_lqi extr_lqi=1 extr_hqi=1 //default values //set the q-range Variable qmax,qmin,num qmax=10 qmin=1e-5 num=numpnts(w) extr_hqq = w[num-1] + x * (qmax-w[num-1])/num_extr extr_lqq = qmin + x * (w[0]-qmin)/num_extr return(0) End Function DoExtrapolate(qw,iw,sw,nbeg,nend) Wave qw,iw,sw Variable nbeg,nend Wave extr_lqi=extr_lqi Wave extr_lqq=extr_lqq Wave extr_hqi=extr_hqi Wave extr_hqq=extr_hqq Variable/G V_FitMaxIters=300 Variable num=numpnts(iw) Make/O/D G_coef={100,-100} //input FuncFit Guinier_Fit G_coef iw[0,(nbeg-1)] /I=1 /X=qw /W=sw /D extr_lqi= Guinier_Fit(G_coef,extr_lqq) Printf "I(q=0) = %g (1/cm)\r",G_coef[0] Printf "Rg = %g (A)\r",sqrt(-3*G_coef[1]) Make/O/D P_coef={0,1,-4} //input //(set background to zero and hold fixed) CurveFit/H="100" Power kwCWave=P_coef iw[(num-1-nend),(num-1)] /I=1 /X=qw /W=sw /D extr_hqi=P_coef[0]+P_coef[1]*extr_hqq^P_coef[2] Printf "Power law exponent = %g\r",P_coef[2] Printf "Pre-exponential = %g\r",P_coef[1] return(0) End //plot based on the wave selelctions Function Plot_Inv_Data(ctrlName) : ButtonControl String ctrlName //access the global strings representing the last data file read in SVAR QWave = root:Packages:NIST:invariant:QWave SVAR IWave = root:Packages:NIST:invariant:IWave SVAR SWave = root:Packages:NIST:invariant:SWave Wave qw=$QWave Wave iw=$IWave Wave sw=$SWave String str="",item="" Variable num=0,ii //not used - just kill and re-draw //remove everything from the graph and graph it again // str = TraceNameList("",";",1) // num=ItemsInList(str) // for(ii=0;ii 0) cleanLastFileName = CleanupName(newStr,0) else cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0) endif String dataStr = "root:"+cleanLastFileName+":" // keep global copies of the names rather than reading from the popup tempName=dataStr + cleanLastFileName+"_q" String/G root:Packages:NIST:invariant:QWave=tempName tempName=dataStr + cleanLastFileName+"_i" String/G root:Packages:NIST:invariant:IWave=tempName tempName=dataStr + cleanLastFileName+"_s" String/G root:Packages:NIST:invariant:SWave=tempName //Plot, and adjust the scaling to match the axis scaling set by the popups Plot_Inv_Data("") //if the slit-smeared box is checked, try to read the slit height // - if can't find it, maybe not really smeared data, so put up the Alert ControlInfo/W=Invariant_Panel check0 if(V_Value==1) SlitSmearedCheckProc("",1) endif End Proc InvDoneButton(ctrlName): ButtonControl String ctrlName DoWindow/K Invariant_Graph DoWindow/K Invariant_Panel end //get the slit height if the data is slit-smeared //set the globals as needed Function SlitSmearedCheckProc(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared // SVAR fileStr=root:Packages:NIST:gLastFileName //reset the global to the checkbox state isSlitSmeared = checked //==0 if the data is not slit smeared if(checked) //get the smearing info ControlInfo/W=Invariant_Panel ywave String folderStr=CleanupName(S_value,0) NVAR dQv=root:Packages:NIST:invariant:gDqv NVAR/Z loaded_dQv = $("root:"+folderStr+":USANS_dQv") if(NVAR_Exists(loaded_dQv)) dQv = loaded_dQv Print "Data is slit-smeared, dqv = ",dQv else DoAlert 0,"Can't find the slit height from the data. Enter the value manually if the data is truly slit-smeared, or uncheck the box." endif endif return(0) End