{=================================================================} {Macro's for TEM/SAED Pattern Analysis} { Nestor.J. Zaluzec Electron Microscopy Center for Materials Research Argonne National Laboratory Materials Science Division -Bdlg 212 Argonne, Illinois- 60439 USA Email:Zaluzec@ANLEMC.MSD.ANL.GOV Tel:708-252-5075 Fax:708-252-4798 } {Version 931214003-NJZ} {Define Global Variables, Constants & Strings used in all routines} {=================================================================} {=================================================================} Var wx,wy:Integer; {Window Width x,y} cx,cy:Integer; {center of line in Apple window coordinates} dpcx,dpcy:Integer; {center of DP in stnd coordinates-RHCS} CameraConstant:Real; {Camera Constant for Diffraction Pattern Analysis} Version:String; {This is the Version number of these routines} thl,thu:Integer {Thresholds : lower & Upper for Density Slice} Procedure UnivParams; Begin; Version:='9312140003-NJZ'; end; {#################################################################} Macro 'Integrate Video Signal [F1]' Var numframes:Integer {number of frames to integrate} Begin; numframes := GetNumber('Enter Number of Integration Frames',10); StartCapturing; AverageFrames('Integrate',numframes); exit; {#################################################################} Macro 'Average Video Signal [F2]' Var numframes:Integer {number of frames to integrate} Begin; numframes := GetNumber('Enter Number of Averaged Frames',10); StartCapturing; AverageFrames('Average',numframes); exit; {#################################################################} Macro 'Locate Diffraction Pattern Center [F3]' {this macro is used to find the coordinates of the center of a DP} var x1,x2,y1,y2,top,left,width,height:integer; xcenter,ycenter,radius:integer; begin GetPicSize(WX,WY); GetLine(x1,y1,x2,y2,width); if x1<0 then begin PutMessage('Use the Cord/Line Measurement Tool to identify a diameter from which one can calculate the pattern center'); exit; end; {Now that we know the end points of the line get it's center} xcenter:=x1+(x2-x1)/2; ycenter:=y1+(y2-y1)/2; {Now we convert to the center of the pattern using RHCS} dpcx:=xcenter; dpcy:=(wy-ycenter); {now write this in the values window} ShowMessage ('Center ='dpcx,',',dpcy); End; {#################################################################} Macro 'Measure Camera Constant of Standard [F4]' {This routine is used to measure the Camera Constant from an Image, the user must use the line/cord tool to mark a length on the screen which corresponds to a known d-spacing (diameter) they must also input the accelerating voltage of the TEM } var AccVolt:Integer; {Accelerating Voltage of TEM in kV} Dspace,Lambda,Length:Real; {D-spacing of Reflections in } x1,x2,y1,y2,top,left,width,height:integer; xcenter,ycenter,radius:integer; begin; GetLine(x1,y1,x2,y2,width); if x1<0 then begin; PutMessage('Use the Cord Tool to Measure the Diameter of a Diffraction Ring'); exit; end; {Now that we know the end points of the line get it's center} Length :=sqrt(sqr(x2-x1) + sqr(y2-y1)); xcenter:=x1+(x2-x1)/2; ycenter:=y1+(y2-y1)/2; AccVolt:=GetNumber('Enter Accelerating Voltage in kV',100); Dspace:=GetNumber('Enter D-spacing of Reflection in ',1); {Calculate the wavelength of the electrons} Lambda := (12.26)/sqrt(AccVolt*1000.)/sqrt(1+0.0009788*AccVolt); ShowMessage ('Volt =',Accvolt:5:1,' kV',' Lambda=',lambda:10:9,''); CameraConstant := Dspace*Length/2. ; ShowMessage ('Camera Constant = ', CameraConstant:9:3, ' -pixels'); {now write this in the values window} End; {#################################################################} Macro 'Enter Diffraction Pattern Camera Constant [F5]' begin; CameraConstant:=GetNumber('Enter Camera Constant in -pixels',CameraConstant); end; {#################################################################} Macro 'Analyze, Measure and Tabulate Pattern D-spacings [F6]' {This macro will output the uncalibrated d-spacings of identified reflections in the SAED pattern} Var reflect,Origwindow,:Integer; {Reflection Number} year,month,day,hour,minute,second,dayofweek:Integer CMR,CMRID,mn,dy,yr:string; {some text strings for Identification} begin {First are we in the right version of Image} RequiresVersion(1.52); {Now read in universal/global parameters for these Macros} UnivParams; {Findout which window we are now in} Origwindow:=PicNumber; GetTime(year,month,day,hour,minute,second,dayofweek); {Make up and Label a report} NewTextWindow('Diffraction Pattern Analysis'); SetFont('Monaco'); SetFontSize(12); SetText('RightJustified'); Writeln('Electron Microscopy Center for Materials Research'); {Get some sort of an Id number to label things} CMR:=concat(year,month,day); CMRID:=GetString('Enter an ID# for record keeping: ',CMR); {write out a date/time stamp on the output file} Writeln('Automated Diffraction Pattern Analysis:',Version); Writeln('Sample/Specimen Identification: ',CMRID); Writeln(' '); Writeln('Date: ',month:2:0,' /',day:2:0,' /',year); Writeln('Time: ',hour:2:0,':',minute:2:0':',second:2:0); Writeln(' '); Writeln('Calibrations: Diffraction Pattern Center (x,y) = ','(',dpcx,',',dpcy,')'); if (dpcx=0) and (dpcy=0) then begin Writeln('***********************************************************'); writeln('WARNING: Diffraction Pattern Center NOT Calibrated'); writeln(' - D-spacing Results Invalid'); Writeln('*********************************************************** '); end; Writeln('Calibrations: Effective Camera Constant = ', CameraConstant,' -pixels'); {Check the Camera constant to see that it is not zer0} if (CameraConstant = 0) then begin CameraConstant :=1.0; Writeln('*********************************************************** '); writeln(' WARNING: Camera Constant Invalid Value set to 1.0'); writeln (' - D-spacing Results Invalid'); Writeln('*********************************************************** '); end; Writeln(' '); Writeln(' No. X Y Radius D-spacing'); Writeln(' (pixels) ()'); {Now lets go back to the original window to do the analysis} SelectPic(Origwindow); SelectAll; {Make sure whole pattern is selected} ResetCounter; {Now reset all counters} {Turn on density slicing and check the values Use default if needed} SetDensitySlice(255,255); GetThresholds(thl,thu); if (thl=thu) then begin; PutMessage('Density Slice was not set by User - Defaults will be used'); SetDensitySlice(0,128); {Set the default thresholding for analysis} end; {Now set up some default parameters for the measurements} OutlineParticles(true); LabelParticles(true); IgnoreParticlesTouchingEdge(true); SetParticleSize(4,750); {Need at least 4 touching pixels to be a reflection} SetUser1Label('Radius'); {Label the columns} SetUser2Label('D-spacing ()'); {Tell it what to measure} SetOptions('Area,X-YCenter,User1,User2'); SetPrecision(3,9); {Now do it} AnalyzeParticles; for reflect:=1 to rCount do begin rArea [reflect]:= reflect; rUser1[reflect]:=sqrt(sqr(rx[reflect]-dpcx)+sqr(ry[reflect]-dpcy)); rUser2[reflect]:=CameraConstant/rUser1[reflect]; end; ShowResults; {Now write all the results to the text window} Copy; SelectWindow('Diffraction Pattern Analysis'); SelectAll; SetFont('Monaco'); SetFontSize(12); SetText('RightJustified'); Paste; {Go back to the original window and restore original image} SelectPic(Origwindow); {RevertToSaved;} SelectWindow('Diffraction Pattern Analysis'); end; {#################################################################}