#pragma rtGlobals=1 // Use modern global access method. #pragma version = 1.4 #pragma ModuleName=Refinement #include "Indexing", version>=1.3 #include "Triangulate", version>=2.1 Static Constant hc = 1.239841857 // keV-nm Menu "micro" SubMenu "Refinement" "Fill Refinement Data from Indexing", FillGeoRefineDataFromIndexing($"",$"") "Edit Data for Refinement...", EditGeoRefinementData(NaN) "Refine Geometry...",MakeRefinePanel() "Refine Lattice --> get strain",doLatticeRefinement($"") End SubMenu("Tables") "Refinement Data", EditGeoRefinementData(NaN) help={"Show/edit the data used for Refinement"} End End Function MeasuredToIndexedField(scale) // draw vector distortion arrows from measured to indexed spots Variable scale // scale factor for arrow length (about 200) scale = numtype(scale) ? 200 : scale Wave RefineData=RefineData if (!WaveExists(RefineData)) Abort "cannot find 'RefineData'" endif STRUCT microGeometry geo if (FillGeometryStructDefault(geo)) Abort "need to read the geometry" endif STRUCT crystalLattice xtal if (FillLatticeStructDefault(xtal)) Abort "need to read an xtal" endif printf "Draw vectors from measured spots to calculated (i.e. indexed) spots, exagerated by x %g\r",scale Wave qvec = $microGeo#MakeUnique3Vector($"") Variable/C pz Variable px,py,h,k,l Variable dx, dy Variable i, N=DimSize(RefineData,0) printf " hkl\r" for (i=0;i1e-12) sprintf dilationStr, " \tdilation = %.1e",MatrixTrace(strainTensor)/3 // dilation endif printf "StrainTensor=\t%+.6f \t%+.6f \t%+.6f \tmax strain = %.1e\r",strainTensor[0][0],strainTensor[0][1],strainTensor[0][2],maxStrain printf "\t\t\t\t%+.6f \t%+.6f \t%+.6f%s\r",strainTensor[1][0],strainTensor[1][1],strainTensor[1][2],dilationStr printf "\t\t\t\t%+.6f \t%+.6f \t%+.6f\r",strainTensor[2][0],strainTensor[2][1],strainTensor[2][2] if (V_flag) printf "Optimize ended with error code = %d\r",V_flag endif return V_flag End // // Function totalErrorLatticeDev(w,as0,as1,as2, bs0,bs1,bs2, cs0,cs1) // just deviatoric strain Wave w Variable as0,as1,as2 // componenets of a* Variable bs0,bs1,bs2 // componenets of b* Variable cs0,cs1 // componenets of c* (except for last one) Variable cs2, Vsc = NumberByKey("Vsc",note(w),"=") // Vsc = ((a*)x(b*))„(c*) cs2 = (Vsc - (as1*bs2-as2*bs1)*cs0 - (as2*bs0-as0*bs2)*cs1) / (as0*bs1-as1*bs0) return totalErrorLattice(w, as0,as1,as2, bs0,bs1,bs2, cs0,cs1,cs2) End // // Optimization function (we want to minimize this) // for each measured data point, the following information may be available // if a piece of info was not measured, then set it to NaN, and it will be ignored // e.g. if you know only one energy, then most of the w[i][6] will be NaN // w[i][0] h qhat is direction of a spot computed strictly from the recip x hkl // w[i][1] k // w[i][2] l // w[i][3] measured x-pixel position (full chip & unbinned) // w[i][4] measured y-pixel position (full chip & unbinned) // w[i][5] weighting for use with x-y part // w[i][6] measured energy (keV) // w[i][7] weighting for this reflection (only used with energy) // Function totalErrorLattice(w, as0,as1,as2, bs0,bs1,bs2, cs0,cs1,cs2) Wave w // parameters, including measured data Variable as0,as1,as2 // componenets of a* Variable bs0,bs1,bs2 // componenets of b* Variable cs0,cs1,cs2 // componenets of c* Wave qvec=root:Packages:geometry:totalError_qvec // a Q vector, not normalized STRUCT microGeometry geo FillGeometryStructDefault(geo) Variable theta2pixel = (2*geo.dd/(geo.dpsy/geo.NyCCD)) // scales theta to pixels Variable d // d-spacing (nm) Variable i, N=DimSize(w,0) // number of hkl points measured Variable/C pz Variable err=1e-322 // really small, but not exactly zero Variable weight, thetaSpot, dSpot Variable h,k,l for (i=0;i=0 && WhichListItem("dpsx",fitList,",")>=0 && WhichListItem("dpsy",fitList,",")>=0) DoAlert 0, "Invalid combination, cannot fit height (dd) and the ccd size (dpsx & dpsy)" return 1 endif if (!WaveExists(RefineData)) if (stringmatch(WaveListClass("RefinementData","*",""),"RefineData;")) Wave RefineData = :RefineData // RefineData exists, and it is the only one else String RefineDataStr = SelectString(WaveExists(RefineData),"",NameOfWave(RefineData)) Prompt RefineDataStr,"Indexed Peak List",popup,WaveListClass("RefinementData","*","") DoPrompt/Help="3D-Xray Diffraction[Indexing]" "Refinement data",RefineDataStr if (V_flag) return 1 endif Wave RefineData=$RefineDataStr endif if (!WaveExists(RefineData)) return 1 endif printf "„doGeoRefinement(%s,\"%s\")\r",NameOfWave(RefineData),hstr printf "starting refinement using data from '%s'\r",NameOfWave(RefineData) endif String funcName = "totalErrorGeo"+num2istr(Nopt)// form function name from number of fitted parameters if (exists(funcName)!=6) DoAlert 0,"bad choice of optimizing parameters, no such function '"+funcName+"'" return 1 endif if (strlen(FindTableWithWave(RefineData))) DoAlert 0, "You must close the table with Refinement Data before you can refine" return 1 endif String wnote = note(RefineData), valList Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") sprintf valList,"xalfd=%g;xbetd=%g;xbet=%g;xgam=%g;dd=%g;xc=%g;yc=%g;dpsx=%g;dpsy=%g",xalfd,xbetd, xbet,xgam, dd, xc,yc,dpsx,dpsy Make/N=3/O/D root:Packages:geometry:totalError_ki,root:Packages:geometry:totalError_qhat Make/N=(Nopt)/O/D RefineGeo_typXWave, RefineGeo_xWave Wave typXWave=RefineGeo_typXWave, xWave=RefineGeo_xWave for(i=0;i=0 || WhichListItem("dpsy",fitList,",")>=0) dd = geo.dd dpsx = geo.dpsx dpsy = geo.dpsy print " or" Variable scale = round((dpsx+dpsy)/2)/((dpsx+dpsy)/2) printf " dd = %.4f\r",dd*scale printf " dpsx = %.4f dpsy = %.4f\r",dpsx*scale,dpsy*scale print " or" scale = round(50)/dpsx printf " dd = %.4f\r",dd*scale printf " dpsx = %.4f dpsy = %.4f\r",dpsx*scale,dpsy*scale endif if (foundGeo) String strStruct // need a string version to pass to MakeGeometryParametersPanel() StructPut/S/B=2 geo, strStruct // put back into string so I can pass it Variable/G root:Packages:geometry:PanelValues:dirty=0 DoWindow/K GeometrySet // ensure a new windwo MakeGeometryParametersPanel(strStruct) endif KillWaves/Z W_OptGradient KillWaves/Z M_Lower,M_Upper,W_LUPermutation,M_x KillWaves/Z RefineGeo_typXWave, RefineGeo_xWave return 0 End // Function totalErrorGeo1(w,x1) Wave w Variable x1 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String item,list = StringByKey("fitParameters",wnote,"=") item = StringFromList(0,list,",") setParameterValue(item,x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo2(w,x1,x2) Wave w Variable x1,x2 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=") setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo3(w,x1,x2,x3) Wave w Variable x1,x2,x3 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo4(w,x1,x2,x3,x4) Wave w Variable x1,x2,x3,x4 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(3,list,","),x4,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo5(w,x1,x2,x3,x4,x5) Wave w Variable x1,x2,x3,x4,x5 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(3,list,","),x4,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(4,list,","),x5,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo6(w,x1,x2,x3,x4,x5,x6) Wave w Variable x1,x2,x3,x4,x5,x6 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(3,list,","),x4,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(4,list,","),x5,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(5,list,","),x6,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo7(w,x1,x2,x3,x4,x5,x6,x7) Wave w Variable x1,x2,x3,x4,x5,x6,x7 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(3,list,","),x4,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(4,list,","),x5,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(5,list,","),x6,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(6,list,","),x7,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo8(w,x1,x2,x3,x4,x5,x6,x7,x8) Wave w Variable x1,x2,x3,x4,x5,x6,x7,x8 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(3,list,","),x4,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(4,list,","),x5,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(5,list,","),x6,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(6,list,","),x7,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(7,list,","),x8,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Function totalErrorGeo9(w,x1,x2,x3,x4,x5,x6,x7,x8,x9) Wave w Variable x1,x2,x3,x4,x5,x6,x7,x8,x9 String wnote = note(w) Variable xalfd=NumberByKey("xalfd",wnote,"="), xbetd=NumberByKey("xbetd",wnote,"=") Variable xbet=NumberByKey("xbet",wnote,"="), xgam=NumberByKey("xgam",wnote,"=") Variable dd=NumberByKey("dd",wnote,"=") Variable xc=NumberByKey("xcent",wnote,"="), yc=NumberByKey("ycent",wnote,"=") Variable dpsx=NumberByKey("dpsx",wnote,"="), dpsy=NumberByKey("dpsy",wnote,"=") String list = StringByKey("fitParameters",wnote,"=" ) setParameterValue(StringFromList(0,list,","),x1,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(1,list,","),x2,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(2,list,","),x3,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(3,list,","),x4,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(4,list,","),x5,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(5,list,","),x6,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(6,list,","),x7,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(7,list,","),x8,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) setParameterValue(StringFromList(8,list,","),x9,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) return totalErrorGeo(w,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) End // Static Function setParameterValue(item,xx,xalfd,xbetd,xbet,xgam,dd,xc,yc,dpsx,dpsy) String item // name of a variable to pass Variable xx Variable &xalfd,&xbetd,&xbet,&xgam,&dd,&xc,&yc,&dpsx,&dpsy // variable values strswitch(item) case "xalfd": xalfd = xx break case "xbetd": xbetd = xx break case "xbet": xbet = xx break case "xgam": xgam = xx break case "dd": dd = xx break case "xc": xc = xx break case "yc": yc = xx break case "dpsx": dpsx = xx break case "dpsy": dpsy = xx break default: Abort "unknown fit parameter '"+item+"'" endswitch return 0 End // //Static Function/S Wave2str(w,m) // Wave w // wave // Variable m // number of places // if (!WaveExists(w)) // return "{}" // endif // String num,fmt,str="{" // sprintf fmt,"%%.%dg",m // Variable i,N=min(numpnts(w),15) // at most 15 terms // for (i=0;i15,"",",...") // return str+"}" //End // Optimization function (we want to minimize this) // for each measured data point, the following information may be available // if a piece of info was not measured, then set it to NaN, and it will be ignored // e.g. if you know only one energy, then most of the w[i][6] will be NaN // w[i][0] qhat, x qhat is direction of a spot computed strictly from the recip x hkl // w[i][1] qhat, y NOTE, qhat is assumed to be normalized // w[i][2] qhat, z // w[i][3] measured x-pixel position (full chip & unbinned) // w[i][4] measured y-pixel position (full chip & unbinned) // w[i][5] weighting for use with x-y part // w[i][6] measured energy (keV) // w[i][7] weighting for this reflection (only used with energy) // w[i][8] theta pre-computed from measured energy and known d-spacing (radian) // Function totalErrorGeo(w,xalfd, xbetd,xbet, xgam,dd,xc, yc, dpsx, dpsy) Wave w // parameters, including measured data Variable xalfd, xbetd // variables to fit Variable xbet, xgam Variable dd Variable xc, yc Variable dpsx, dpsy Wave qhat=root:Packages:geometry:totalError_qhat // holds q-vector for a reflection Wave ki=root:Packages:geometry:totalError_ki // incident beam direction String strStruct=StrVarOrDefault(":geoStructStr","") // set to values in current directory if (strlen(strStruct)<1) strStruct=StrVarOrDefault("root:Packages:geometry:geoStructStr","") // try the default values endif STRUCT microGeometry geo StructGet/S/B=2 geo, strStruct // load geometry geo.xalfd = xalfd // set local structure to contain the input values being fitted geo.xbetd = xbetd geo.xbet = xbet geo.xgam = xgam geo.dd = dd geo.xcent = xc geo.ycent = yc geo.dpsx = dpsx geo.dpsy = dpsy GeometryUpdateCalc(geo) Variable validXtal=0 STRUCT crystalLattice xtal strStruct = StrVarOrDefault(":xtalStructStr","") if (strlen(strStruct)) StructGet/S/B=2 xtal, strStruct validXtal = 1 endif Variable theta2pixel = (2*geo.dd/(geo.dpsy/geo.NyCCD)) // scales theta to pixels Variable i, N=DimSize(w,0) // number of hkl points measured Variable thetaIndex // Bragg angle of a point from indexation (radian) Variable thetaEne // Bragg angle from energy & known d (radian) Variable/C pz Variable err=1e-322 // really small, but not exactly zero Variable weight for (i=0;i0) && exists("RefineData")!=1) // if wave exits, no need to make one N = 10 Prompt N, "number of data points for refinement" DoPrompt "number of points",N if (V_flag) return 1 endif if (!(N>0)) // invalid size, must be > 0 return 1 endif endif if (exists("RefineData")!=1) Make/N=(N,11)/O/D RefineData RefineData = NaN Note/K RefineData,"waveClass=RefinementData" else N = 0 endif SetDimLabel 1,0,'q^ x',RefineData // RefineData[i][0] qhat, x qhat is direction of spot calculated only from recip x hkl SetDimLabel 1,1,'q^ y',RefineData // RefineData[i][1] qhat, y NOTE, qhat is assumed to be normalized SetDimLabel 1,2,'q^ z',RefineData // RefineData[i][2] qhat, z SetDimLabel 1,3,'x pixel',RefineData // RefineData[i][3] measured x-pixel position (full chip & unbinned) SetDimLabel 1,4,'y pixel',RefineData // RefineData[i][4] measured y-pixel position (full chip & unbinned) SetDimLabel 1,5,'pixel weight',RefineData // RefineData[i][5] weighting for use with x-y part SetDimLabel 1,6,'Energy (keV)',RefineData // RefineData[i][6] measured energy (keV) SetDimLabel 1,7,'Energy weight',RefineData // RefineData[i][7] weighting for this reflection (only used with energy) SetDimLabel 1,8,'theta (rad)',RefineData // RefineData[i][8] theta auto-computed from RefineData[i][6] and known d-spacing SetDimLabel 1,9,'X linearized pixel',RefineData // RefineData[i][9] same as RefineData[i][3], but after distortion correction SetDimLabel 1,10,'Y linearized pixel',RefineData// RefineData[i][10] Variable i SetDimLabel 0,-1,'(hkl)',RefineData for (i=0;i