Title                  :THE DIFFRACTION SUITE
Keywords               :CBED, HOLZ, KINEMATICAL APPROXIMATION
Computer               :DEC VAX 11/730-785, DEC PDP 11/2-11/73
Operating System       :VAXVMS
Programming Language   :Fortran 77
Hardware Requirements  :TEKTRONICS 4010 TERMINAL OR SUITABLE EMULATOR
Author(s)              :JOHN F. MANSFIELD (919)-248-1800
Correspondence Address :THE MICROELECTRONICS CENTER OF NORTH CAROLINA
                       :PO BOX 12889, RESEARCH TRIANGLE PARK, N.C. 27709.
Abstract:
	This set of software routines will calculate a data file of reciprocal 
lattice vectors for any crystal, when supplied with the lattice parameters and
the lattice type, and then plot simulated convergent beam electron diffraction
zone axis patterns (CBED ZAPs).  The simulations are currently limited to
plots of the zero layer discs, plots of the bright field deficiency higher
order laue zone lines and both of the above simultaneously.
	The manual for this suite of routines was written on an apple macintosh
using "macwrite", with examples of actual plots "pasted" into the text from the
terminal emulation program "versaterm".  A copy of the text of the manual 
resides in the emmpdl under the title "diffractionsuite.doc.
to receive a complete copy including figures, please send a blank macintosh
disk the author.
------------------------------------------------------------------------------



Title                  :THE DIFFRACTION SUITE
Keywords               :CBED, HOLZ, KINEMATICAL APPROXIMATION
Computer               :DEC VAX 11/730-785, DEC PDP 11/2-11/73
Operating System       :VAXVMS
Programming Language   :Fortran 77
Hardware Requirements  :TEKTRONICS 4010 TERMINAL OR SUITABLE EMULATOR
Author(s)              :JOHN F. MANSFIELD (919)-248-1800
Correspondence Address :THE MICROELECTRONICS CENTER OF NORTH CAROLINA
                       :PO BOX 12889, RESEARCH TRIANGLE PARK, N.C. 27709.
Documentation          :
_____________________________________________________________________________








                             THE DIFFRACTION SUITE

             THE ELECTRON MICROSCOPY CENTRE FOR MATERIALS RESEARCH
                     DIFFRACTION PATTERN PLOTTING ROUTINES

                                       BY

                               JOHN F. MANSFIELD


               ELECTRON MICROSCOPY CENTRE FOR MATERIALS RESEARCH
                           MATERIALS SCIENCE DIVISION
                          ARGONNE NATIONAL LABORATORY
                            ARGONNE, ILLINOIS  60439

                         FOR CURRENT ADDRESS SEE ABOVE

















---------------
* Work supported in part by the U.S.  Department of  Energy,  BES-Materials
  Sciences, under Contract W-3l-l09-Eng-38.



                                 CONTENTS

     1       INTRODUCTION . . . . . . . . . . . . . . . . . . . . 1
     2       USING THE DIFFRACTION SUITE  . . . . . . . . . . . . 2
     2.1       Creating The Phase File  . . . . . . . . . . . . . 2
     2.2       Listing The Data In The Phase File . . . . . . . . 4
     2.3       Plotting Zero Layer Zone Axis Patterns . . . . . . 5
     2.4       Plotting Direct Disc HOLZ Lines Only . . . . . . . 7
     2.5       Plotting HOLZ Lines And Zero Layer Together  . . . 9
     2.6       Choosing The Terminal Type . . . . . . . . . . .  12
     2.7       Using The Printer Option And Labelling The HOLZ 
               Lines  . . . . . . . . . . . . . . . . . . . . .  13
     2.8       Performing Repeated Plots  . . . . . . . . . . .  15
     2.9       Obtaining Hardcopy Of The Plots  . . . . . . . .  15


     APPENDIX A      GENERAL CRYSTALLOGRAPHIC FORMULAE


     APPENDIX B      THE EMPTY LATTICE CONSTRUCTION


     APPENDIX C      LISTING OF THE DATA FILE TERMIN.DAT


     APPENDIX D      PROGRAM LISTING


     APPENDIX E      CONVERSION MATRIX FOR RECIPROCAL LATTICE VECTORS


     APPENDIX F      A SELECTED BIBLIOGRAPHY OF CONVERGENT-BEAM
		     DIFFRACTION


     APPENDIX G      SOURCE CODE COMPILATION AND LINKING

                                                                Page 1


     1  INTRODUCTION

          This program plots simulated electron diffraction patterns of any
     general  triclinic  crystal.   It  is  designed  primarily  to aid the
     analysis of convergent  beam  electron  diffraction  (CBED)  patterns.
     There  are  three  ways which the program may plot patterns.  The zero
     order Laue zone may be  plotted  alone,  either  as  discs  or  spots,
     depending upon the convergence angle (second condenser aperture size).
     The  zero  layer  can  be  plotted  together  with  the  bright  field
     deficiency  Higher  Order  Laue  Zone (HOLZ) lines to illustrate their
     relative orientation to each other.  Finally, a  higher  magnification
     plot  of  the  direct  disc  HOLZ lines is possible to aid indexing of
     actual CBED patterns.

          The program is split into six sections,  each  of  which  may  be
     accessed  from  a  menu.   The first section covers the generation and
     storage of a "Phase File" in which reciprocal lattice data  is  stored
     for  use  in  subsequent plotting routines.  The creation of the Phase
     File means that frequently used  values  can  be  stored  and  quickly
     accessed  by  the  program  to avoid repeatedly calculating them.  The
     next two sections of the program allow the phase file  to  be  printed
     out,  either  on the user's terminal or on a system line-printer.  The
     Phase File is stored as ASCII text and can be typed or  read  into  an
     editor  if it is suspected that the data within it has been corrupted.
     The last three sections of the program are plotting routines and  plot
     zero  layer  zone  axis  patterns  (ZAPs), direct disc HOLZ deficiency
     lines and both zero layer discs and direct disc HOLZ detail  together.
     For a more detailed introduction and description of CBED patterns, the
     reader is directed to a  number  of  excellent  reviews  and  teaching
     articles  that  have  been  published.  A selected bibliography can be
     found in Appendix F.

          The Diffraction  Suite  of  programs  currently  resides  on  the
     Materials  Science  Division  Electron  Microscopy  Centre  (EMC)  DEC
     VAX11/785, where it is accessible by members of the division  and  via
     the EMC/EMSA Bulletin Public Domain Library (EMMPDL).  All of the code
     is  written  in  DEC  VAX  FORTRAN77,  although  with  a  few   simple
     modifications  it can be run on a wide variety of mini-computers.  For
     graphics output a Tektronics 4010 terminal  or  suitable  emulator  is
     required.   Since  the  plotting  sections  of  the code employ Nestor
     Zaluzec's Graphics Libraries then any Tek4010-type  terminal  that  he
     currently  supports can be used.  A current listing of these terminals
     can be found in Appendix C.

          The programs are all executed in interactive  mode  from  a  main
     menu.   Upon selection of a specific routine, the user is prompted for
     input when it is required.  The code has been written to minimise  the
     need to read manuals such as this, however, this manual is designed to
     clarify any areas  of  confusion  and  to  explain  the  theories  and
     approximations used in the programs.

          The remainder of this manual is a guided tour of the capabilities
     of  the  whole  package.  Several examples are used to illustrate both
     the operator supplied input that is required and the output generated.
     The  appendices  outline  how  the program operates and the models and
                                                                Page 2


     approximations which  are  used.   Listings  of  useful  formulae  and
     information  which may be of use in the analysis of both CBED patterns
     and electron diffraction patterns in general are  included,  as  is  a
     complete listing of the program source code.



     2  USING THE DIFFRACTION SUITE

          This section will assume that you are using the  program  on  the
     EMCVAX.   If you are using another ANL computer or have obtained these
     programs from the EMMPDL, you may need to configure the  software  for
     your  own  particular  computer system.  Details of the required files
     and installation instructions for certain  systems  can  be  found  in
     Appendices C and G.

          You  may  run  The  Diffraction  Suite  from  any  directory   or
     sub-directory  on  the  EMCVAX, however, you may find it convenient to
     create a special sub-directory in your directory space  to  store  all
     data  etc.  concerned with diffraction patterns.  Wherever this manual
     reproduces output from the EMCVAX the output is  in  uppercase  Geneva
     font  (eg.   EMCVAX:)  ,  input  typed by the user is in the same font
     except it is in quotes.  The manual is written in New  York  font  and
     notes  explaining the input and output will be in both upper and lower
     case.

          When logged onto a standard user account of the EMCVAX you should
     see a prompt like this:

     EMCVAX:

     To run The Diffraction Suite, type as follows:

     EMCVAX:  "RUN DIFFRACTIONSUITE  <RETURN>"  

     The  terminal  screen  then  scrolls  up one page and the main menu is
     printed.



     2.1  CREATING THE PHASE FILE

     Let us first examine  the  creation  of  the  Phase  File  from  which
     subsequent software routines will extract data.  From the menu, select
     option A.

         THE DIFFRACTION SUITE


       A: CALCULATION OF RECIPROCAL LATTICE VECTORS

       B: LISTING OF RECIPROCAL LATTICE VECTORS (TERMINAL) 

       C: LISTING OF RECIPROCAL LATTICE VECTORS (PRINTER) 

       D: PLOT [UVW] ZERO LAYER ZONE AXIS PATTERN (TERMINAL) 

                                                                Page 3


       E: PLOT DIRECT DISC HOLZ LINES (TERMINAL) 

       F: PLOT ZERO LAYER WITH HOLZ LINES (TERMINAL) 

       G: EXIT FROM SUITE

          SELECT ONE OF A TO G AND <RETURN>:  "A <RETURN>"

          In this first example we shall select A  to  generate  the  Phase
     Data  File.  After pressing <RETURN> the screen clears and the program
     asks for a phase identifier which will be used as the file  name.   In
     this example we shall use the element Aluminum and represent it by its
     chemical symbol, although the whole name may be used.

     ENTER 8-CHARACTER PHASE SYMBOL/NAME:  "AL <RETURN>"

     The program then needs to know the lattice parameters.

     ENTER A0,B0,C0 IN ANGSTROMS:  "4.0496,4.0496,4.0496 <RETURN>"
     ENTER ALPHA, BETA, AND  GAMMA  IN  DEGREES  (EG.   90.0)  "90.,90.,90.
     <RETURN>"

     Then you can enter up to 80 characters of information to remind you in
     future  where you obtained the lattice data.  Simply pressing <RETURN>
     will store a blank line and is perfectly acceptable.

     ENTER LITERATURE REFERENCE; 80 CHARACTER MAXIMUM:
     "BARRETT MASSALSKI, THE STRUCTURE OF METALS <RETURN>"

     The program then gives you the file name and its extension (.DAT), and
     requests  the  type of lattice.  Entering the lattice type enables the
     program to calculate only the allowed reflections (reciprocal  lattice
     vectors).

     THE NAME OF THE FILE IS AL      .DAT 

     CHOOSE LATTICE TYPE:
         PRIMITIVE (P)
         BASE CENTRED ALONG THE A-AXIS (A)
         BASE CENTRED ALONG THE B-AXIS (B) 
         BASE CENTRED ALONG THE C-AXIS (C)
         FACE CENTRED (F)  
         BODY CENTRED (I)    
         HEXAGONAL (H) 
         RHOMBOHEDRAL (R)
         ENTER TYPE (DEFAULT=P):  "F <RETURN>"

     The next input selects the range of HKL values that are  searched  and
     stored in the data file.  It is advisable to use 4 or 5 here, this may
     be overkill but it does mean that you will be able to  plot  the  zero
     layer of some very low order zone axes.

     INPUT N WHERE N SETS  THE  RANGE  -N,-N,-N  TO  N,N,N:   "4  <RETURN>"
     SORTING...ANY ADDITIONAL FORBIDDEN REFLECTIONS?  [N]
     (CONSULT INTERNATIONAL TABLES PART A):  "<RETURN>"
                                                                Page 4


     If you reply Y or YES to this question then the program will  ask  you
     to  specify  a formulae to specify the forbidden reflections or search
     through each reciprocal lattice vector and determine whether it is  an
     allowed  reflection  or  not.   This  part of the program is meant for
     future development and is not  fully  implemented.   It  is  advisable
     always  to  answer N or NO to this question, or merely hit <RETURN> to
     select the default negative answer.  The program will then  revert  to
     the main menu.



     2.2  LISTING THE DATA IN THE PHASE FILE

          In this section is an illustration  of  the  output  provided  by
     options  B  and  C  of  the  main  menu.   Note  that there is no real
     difference between option B and C, only a change in  logical  unit  in
     the FORTRAN code.  The way the program is set up on the EMCVAX is that
     the FORTRAN logical unit number  FOR002  is  assigned  to  the  system
     line-printer,  hence any output from section C of the program, or from
     the printer options in sections D to F,  is  directed  to  the  system
     printer queue.

         THE DIFFRACTION SUITE 


       A: CALCULATION OF RECIPROCAL LATTICE VECTORS 

       B: LISTING OF RECIPROCAL LATTICE VECTORS (TERMINAL) 

       C: LISTING OF RECIPROCAL LATTICE VECTORS (PRINTER) 

       D: PLOT [UVW] ZERO LAYER ZONE AXIS PATTERN (TERMINAL) 

       E: PLOT DIRECT DISC HOLZ LINES (TERMINAL) 

       F: PLOT ZERO LAYER WITH HOLZ LINES (TERMINAL) 

       G: EXIT FROM SUITE 

          SELECT ONE OF A TO G AND <RETURN>:  "B <RETURN>"

     Upon selection of B or C the  program  will  ask  the  same  question,
     namely:

     FILENAME?  "AL <RETURN>"

     The data is read in from the specified Phase File and printed  out  in
     the following format:

     PHASE = AL

        188  G VECTORS IN THE FILE 

     REFERENCE:
     BARRETT & MASSALSKI, THE STRUCTURE OF METALS
                                                                Page 5



              A         B         C     ALPHA      BETA     GAMMA 
         4.0500    4.0500    4.0500      90.0      90.0 90.0

         SINALP    SINBET    SINGAM    COSALP    COSBET    COSGAM
         1.0000    1.0000       1.0000    0.0000    0.0000    0.0000

        A*        B*        C*     CALST    CBETST    CGAMST
         0.2469    0.2469       0.2469    0.0000    0.0000    0.0000

     F LATTICE

            G MODULUS  H K L     H MODULUS     K MODULUS     L MODULUS FBN 
       1 4.277100E-01  1-1 1  2.469379E-01 -2.469379E-01  2.469379E-01   0
       2 4.277100E-01  1 1-1  2.469379E-01  2.469379E-01 -2.469379E-01   0   
       3 4.277100E-01  1-1-1  2.469379E-01 -2.469380E-01 -2.469379E-01   0   
       4 4.277100E-01 -1-1 1 -2.469379E-01 -2.469379E-01  2.469379E-01   0   
       5 4.277100E-01 -1 1 1 -2.469379E-01  2.469380E-01  2.469379E-01   0   
       6 4.277100E-01 -1 1-1 -2.469379E-01  2.469379E-01 -2.469379E-01   0   
       7 4.277100E-01  1 1 1  2.469380E-01  2.469380E-01  2.469379E-01   0   
       8 4.277100E-01 -1-1-1 -2.469380E-01 -2.469380E-01 -2.469379E-01   0 
       9 4.938800E-01 -2 0 0 -4.938759E-01  0.000000E+00  0.000000E+00   0  
      10 4.938800E-01  0-2 0 -2.158800E-08 -4.938759E-01  0.000000E+00   0


          The listing contains a note on the total number of  G-vectors  in
     the  file, the reference data requested in the file-generation section
     A, the lattice parameters , and  the  lattice  type.   The  sines  and
     cosines  of the interaxial angles are also included, together with the
     reciprocal lattice  parameters  and  the  cosines  of  the  reciprocal
     lattice  angles.   Although  certain  of  these values may be zero for
     cubic systems, they are not generally so for a triclinic  system,  and
     these  programs are designed to cope with any general crystallographic
     lattice.  The remainder of  the  data  in  the  file  is  a  list,  in
     ascending  order,  of  the  G-vectors.   Listed  is the modulus of the
     length of each one, the Miller indices  of  each,  the  X,  Y,  and  Z
     coordinates  of  each  vector,  and  an  integer value which indicates
     whether the reflection is forbidden or not.  This  last  value  has  a
     default  of  zero  for allowed reflections and only changes if, in the
     generation of the Phase File, extra forbidden reflections were  added.
     The  value  of FBN for a forbidden reflection is one.  Upon completion
     of the listing the program will return to the main menu.



     2.3  PLOTTING ZERO LAYER ZONE AXIS PATTERNS

          This section will illustrate the plotting of zero layer  patterns
     alone.   These  are the same as selected area patterns except that the
     diffraction orders are represented by discs rather than spots.

         THE DIFFRACTION SUITE 


       A: CALCULATION OF RECIPROCAL LATTICE VECTORS 
                                                                Page 6



       B: LISTING OF RECIPROCAL LATTICE VECTORS (TERMINAL) 

       C: LISTING OF RECIPROCAL LATTICE VECTORS (PRINTER) 

       D: PLOT [UVW] ZERO LAYER ZONE AXIS PATTERN (TERMINAL) 

       E: PLOT DIRECT DISC HOLZ LINES (TERMINAL) 

       F: PLOT ZERO LAYER WITH HOLZ LINES (TERMINAL) 

       G: EXIT FROM SUITE 

          SELECT ONE OF A TO G AND <RETURN>:  "D <RETURN>"

          The discs are plotted using the data stored  in  option  A.   The
     disc  size  is scaled by the value of condenser aperture that is input
     by the operator.  The program is internally set to  plot  patterns  in
     proportion  to those recorded on a Philips EM420T, in which the use of
     a  200  mm  aperture  yields  a   half   angle   of   convergence   of
     ~7.3milliradians.

          Upon selection of option D, the default characteristics  for  the
     terminal  and plotter will be displayed; these are from the subroutine
     TERMIN of the NGRAPH graphics package.  For  information  on  changing
     the terminal and/or the hardcopy unit, see section 2.6 and Appendix C.
     In each of the initial demonstrations of the program we  shall  assume
     that the terminal type is set as required.


     -------------------------
     Terminal Characteristics:
     -------------------------
     The Current Terminal Device is:
     TEKTRONICS  4010-1,4014-1  Terminal

     The Current Hardcopy Device is:
     No Graphics Hard Copy                          

     The  Current  Baud   Rate  is :   9600


     Change Definitions [N]?  "<RETURN>"


          You will next be asked  whether  you  want  relevant  information
     about  the  phase  and  zone  axis pattern to be printed on the system
     printer.  We will assume in these initial  examples  that  no  printer
     output  is  desired.   See  section  2.7 for an example of the printer
     output.

     DO YOU WANT PRINTER OUTPUT HOLZ LINE LABELS?  [N] "<RETURN>"

                                                                Page 7


          The program then asks for  the  phase  file,  and  upon  pressing
     <RETURN>  the  header  information  in  the phase file is displayed to
     allow you to check that you have the correct file.

     FILENAME?  "AL <RETURN>"
        188 G-VECTORS IN THIS FILE
     REFERENCE:
     BARRETT & MASSALSKI, THE STRUCTURE OF METALS                           
              A         B         C     ALPHA     BETA     GAMMA
         4.0496    4.0496    4.0496      90.0     90.0      90.0

     Enter CONTinue to resume.
     EMCVAX:  "CONT <RETURN>"


          The program then asks several questions which pertain to the zone
     axis pattern.

     ZONE AXIS?  ENTER U,V,W:  "3,1,0 <RETURN>"

     NUMBER OF REFLECTIONS?  "8 <RETURN>"

     SECOND CONDENSER APERTURE?  (50-600 MICRON) "200 <RETURN>"

     The number of reflections that will be plotted does  not  include  the
     direct disc.

          The screen is then cleared and the pattern is plotted.  The first
     two  discs  that  are  plotted are labelled with their Miller indices.
     The pattern is dated and labelled with the phase file  name  and  zone
     axis.

     31-JUL-89

     AL

     ZONE AXIS= 3 1 0

     MORE?  [Y] "<RETURN>"

     The question which is printed beneath the zone  axis  means,  "Do  you
     want another plot?" In this example we shall assume that the answer is
     no; an example of the output for an affirmative  answer  is  shown  in
     section 2.8.  Entering N will cause the menu to reappear.



     2.4  PLOTTING DIRECT DISC Holz LINES ONLY

          This section deals with the plotting of  the  zero  layer  direct
     disc with the HOLZ deficiency lines.  From the menu select option E.

         THE DIFFRACTION SUITE 


                                                                Page 8


       A: CALCULATION OF RECIPROCAL LATTICE VECTORS 

       B: LISTING OF RECIPROCAL LATTICE VECTORS (TERMINAL) 

       C: LISTING OF RECIPROCAL LATTICE VECTORS (PRINTER) 

       D: PLOT [UVW] ZERO LAYER ZONE AXIS PATTERN (TERMINAL) 

       E: PLOT DIRECT DISC HOLZ LINES (TERMINAL) 

       F: PLOT ZERO LAYER WITH HOLZ LINES (TERMINAL) 

       G: EXIT FROM SUITE 

          SELECT ONE OF A TO G AND <RETURN>:  "E <RETURN>"


          Upon selection of option E, the default characteristics  for  the
     terminal  and plotter will be displayed; these are from the subroutine
     TERMIN of the NGRAPH graphics package.  For  information  on  changing
     the terminal and/or the hardcopy unit, see section 2.6 and Appendix C.
     In this demonstration of the program we shall assume that the terminal
     type is set as required.


     -------------------------
     Terminal Characteristics:
     -------------------------
     The Current Terminal Device is:
     TEKTRONICS  4010-1,4014-1  Terminal

     The Current Hardcopy Device is:
     No Graphics Hard Copy                          

     The  Current  Baud   Rate  is :   9600


     Change Definitions [N]?  "<RETURN>"


          You will next be asked  whether  you  want  relevant  information
     about  the phase and HOLZ pattern to be printed on the system printer.
     We will assume in this example that no printer output is desired.  See
     section 2.7 for an example of the printer output.

     DO YOU WANT PRINTER OUTPUT HOLZ LINE LABELS?  [N] "<RETURN>"


          The program then asks for  the  phase  file,  and  upon  pressing
     <RETURN>  the  header  information  in  the phase file is displayed to
     allow you to check that you have the correct file.

     FILENAME?  "AL <RETURN>"
        188 G-VECTORS IN THIS FILE
     REFERENCE:
                                                                Page 9


     BARRETT & MASSALSKI, THE STRUCTURE OF METALS                           
              A         B         C     ALPHA     BETA     GAMMA
         4.0496    4.0496    4.0496      90.0     90.0      90.0

     Enter CONTinue to resume.
     EMCVAX:  "CONT <RETURN>"


          The program then asks several questions which pertain to the HOLZ
     pattern.

     ZONE AXIS?  ENTER U,V,W:  "3,1,0 <RETURN>"

     SECOND CONDENSER APERTURE?  (50-600 MICRON) "200 <RETURN>"

     ENTER ACCELERATING VOLTAGE IN KV:  "119 <RETURN>"

     INPUT N, WHERE N SETS RANGE OF G-VECTORS
     FROM (-N,-N,-N) TO (N,N,N):  "12 <RETURN>"

     ENTER ORDER(S) OF DESIRED HOLZ REFLECTIONS
     WHERE 1=FOLZ, 2=SOLZ, 3=TOLZ, 4=40LZ, 5=5OLZ, ETC.
     UP TO 5 VALUES PERMISSABLE (eg.  1,2,3,4,5 or 1,2,0,0,0).
     "1,0,0,0,0 <RETURN>"

     ENTER MAXIMUM MODULUS OF G (GGMAX):  "99 <RETURN>"

          The accelerating  voltage  is  an  adjustable  parameter  in  the
     program.   Since  the  code is based on a kinematic approximation, the
     voltage is adjusted to make the  computer  generated  patterns  fit  a
     standard  experimental  pattern.   Unknown  patterns of similar atomic
     number and  structure  can  then  be  analysed  using  the  determined
     voltage.  119kV has been determined to give good fits for Si at 120kV.

          The value N determines the range of Miller indices through  which
     the  program  searches  to  find allowed HOLZ reflections.  Also, five
     different layers of the  reciprocal  lattice  can  be  searched.   The
     nomenclature is fairly standard:  FOLZ = First Order Laue Zone, SOLZ =
     Second Order Laue Zone.  Since the letter F has already been used, 4th
     and  5th  orders  are  designated with numbers.  This is somewhat less
     standard, but it is not often that such high orders are used  so  that
     one  is  not  likely to come across too many different definitions for
     these layers.

          The value GGMAX is the modulus of  the  product  G.G  and  it  is
     designed to limit the area of k-space that the program searches.

          The screen of the  terminal  is  cleared  and  the  HOLZ  pattern
     plotted,  after which the pattern is labelled with the date, the phase
     file name, and the zone axis.  The HOLZ lines are labelled only if the
     printer option is selected.  The reasons for this will become apparent
     in the section "Using the Printer Option".

    
                                                               Page 10


     31-JUL-89

     AL

     ZONE AXIS= 3 1 0

     MORE?  [Y] "<RETURN>"

     The question which is printed beneath the zone  axis  means,  "Do  you
     want another plot?" In this example we shall assume that the answer is
     no; an example of the output for an affirmative  answer  is  shown  in
     section 2.8.  Entering N will cause the menu to reappear.



     2.5  PLOTTING Holz LINES AND ZERO LAYER TOGETHER

          If the HOLZ lines need to be seen in relation to the  zero  layer
     pattern, then choose option F from the main menu.

         THE DIFFRACTION SUITE 


       A: CALCULATION OF RECIPROCAL LATTICE VECTORS 

       B: LISTING OF RECIPROCAL LATTICE VECTORS (TERMINAL) 

       C: LISTING OF RECIPROCAL LATTICE VECTORS (PRINTER) 

       D: PLOT [UVW] ZERO LAYER ZONE AXIS PATTERN (TERMINAL) 

       E: PLOT DIRECT DISC HOLZ LINES (TERMINAL) 

       F: PLOT ZERO LAYER WITH HOLZ LINES (TERMINAL) 

       G: EXIT FROM SUITE 

          SELECT ONE OF A TO G AND <RETURN>:  "F <RETURN>"


          Upon selection of option F, the default characteristics  for  the
     terminal  and plotter will be displayed; these are from the subroutine
     TERMIN of the NGRAPH graphics package.  For  information  on  changing
     the terminal and/or the hardcopy unit, see section 2.6 and Appendix C.
     In this demonstration of the program we shall assume that the terminal
     type is set as required.


     -------------------------
     Terminal Characteristics:
     -------------------------
     The Current Terminal Device is:
     TEKTRONICS  4010-1,4014-1  Terminal

     The Current Hardcopy Device is:
     No Graphics Hard Copy                          

                                                               Page 11


     The  Current  Baud   Rate  is :   9600


     Change Definitions [N]?  "<RETURN>"

          You will next be asked  whether  you  want  relevant  information
     about  the phase and CBED pattern to be printed on the system printer.
     We will assume in this example that no printer output is desired.  See
     section  2.7 for an example of the printer output.  Due to the size of
     the HOLZ plot  in  this  option  and  the  line  density,  it  is  not
     recommended  to  use  the printer option since the labels for the HOLZ
     lines will totally obscure the pattern.

     DO YOU WANT PRINTER OUTPUT HOLZ LINE LABELS?  [N] "<RETURN>"


          The program then asks for  the  phase  file,  and  upon  pressing
     <RETURN>  the  header  information  in  the phase file is displayed to
     allow you to check that you have the correct file.

     FILENAME?  "AL <RETURN>"
        188 G-VECTORS IN THIS FILE
     REFERENCE:
     BARRETT & MASSALSKI, THE STRUCTURE OF METALS                           
              A         B         C     ALPHA     BETA     GAMMA
         4.0496    4.0496    4.0496      90.0     90.0      90.0

     Enter CONTinue to resume.
     EMCVAX:  "CONT <RETURN>"


          The program then asks several questions which pertain to the zero
     layer and HOLZ patterns.

     ZONE AXIS?  ENTER U,V,W:  "3,1,0 <RETURN>"

     NUMBER OF REFLECTIONS?  "8 <RETURN>"

     SECOND CONDENSER APERTURE?  (50-600 MICRON) "200 <RETURN>"

     ENTER ACCELERATING VOLTAGE IN KV:  "119 <RETURN>"

     INPUT N, WHERE N SETS RANGE OF G-VECTORS
     FROM (-N,-N,-N) TO (N,N,N):  "12 <RETURN>"

     ENTER ORDER(S) OF DESIRED HOLZ REFLECTIONS
     WHERE 1=FOLZ, 2=SOLZ, 3=TOLZ, 4=40LZ, 5=5OLZ, ETC.
     UP TO 5 VALUES PERMISSABLE (eg.  1,2,3,4,5 or 1,2,0,0,0).
     "1,0,0,0,0 <RETURN>"

     ENTER MAXIMUM MODULUS OF G (GGMAX):  "99 <RETURN>"

          The number of reflections that will be plotted does  not  include
     the direct disc.
                                                               Page 12


          The accelerating  voltage  is  an  adjustable  parameter  in  the
     program.   Since  the  code is based on a kinematic approximation, the
     voltage is adjusted to make the  computer  generated  patterns  fit  a
     standard  experimental  pattern.   Unknown  patterns of similar atomic
     number and  structure  can  then  be  analysed  using  the  determined
     voltage.  119kV has been determined to give good fits for Si at 120kV.

          The value N determines the range of Miller indices through  which
     the  program  searches  to  find allowed HOLZ reflections.  Also, five
     different layers of the  reciprocal  lattice  can  be  searched.   The
     nomenclature is fairly standard:  FOLZ = First Order Laue Zone, SOLZ =
     Second Order Laue Zone.  Since the letter F has already been used, 4th
     and  5th  orders  are  designated with numbers.  This is somewhat less
     standard, but it is not often that such high orders are used  so  that
     one  is  not  likely to come across too many different definitions for
     these layers.

          The value GGMAX is the modulus of  the  product  G.G  and  it  is
     designed to limit the area of k-space that the program searches.

          The screen is then cleared, the zero layer is plotted, the  first
     two discs are labelled with their Miller indices, and the HOLZ pattern
     is plotted.  The HOLZ lines are labelled only if the printer option is
     selected.   Then  the  plot  is labelled with the date, the phase file
     name, and the zone axis.

     31-JUL-89

     AL

     ZONE AXIS= 3 1 0

     MORE?  [Y] "<RETURN>"

     The question which is printed beneath the zone  axis  means,  "Do  you
     want another plot?" In this example we shall assume that the answer is
     no; an example of the output for an affirmative  answer  is  shown  in
     section 2.8.  Entering N will cause the menu to reappear.



     2.6  CHOOSING THE TERMINAL TYPE

          In the previous examples we have seen only the default values for
     the  terminal  and hardcopy units.  Data indicating the terminal, hard
     copy unit, and baud rate should  be  stored  in  a  data  file  called
     TERMIN.DAT  on  your unit 2 (FOR002).  If the file is not found by the
     program then the secondary default values shown below  are  used,  and
     you are queried whether you wish to change the definitions.


     -------------------------
     Terminal Characteristics:
     -------------------------
     The Current Terminal Device is:
                                                               Page 13


     TEKTRONICS  4010-1,4014-1  Terminal

     The Current Hardcopy Device is:
     No Graphics Hard Copy                          

     The  Current  Baud   Rate  is :   9600


     Change Definitions [N]?  "Y <RETURN>"

          Entering a "Yes" answer  to  the  query  causes  the  program  to
     provide  a  list  of  terminals  and hardcopy devices (i.e., plotters)
     which it supports through  NGRAPH.   You  should  answer  its  further
     queries according to the hardware which you are using.

      Terminal Definitions :
      ----------------------
     -3 = ASCII Terminal   Width = 32  Column
     -2 = ASCII Terminal   Width = 80  Column
     -1 = ANSI x3.64  Non-Graphics   Terminal
      0 = TEKTRONICS  4010-1,4014-1  Terminal
      1 = TEKTRONICS  4006  ,4010    Terminal
      2 = LSI  ADM-3A/5A   RG-512    Terminal
      3 = PERITEK VCG-512   Bit-Map   Monitor
      4 = TEKTRONICS  4027   Color   Terminal
      5 = HP  7470A   Hardcopy    X-Y    Plot
      6 = LA100/LA50  Hardcopy  Graphics Plot
      7 = INTECOLOR  VT-100/TEK4010  Terminal
      8 = INTECOLOR  VT-100/TEK4027  Terminal
      9 = DEC VT-220 /  TEK4010-1,   Terminal
     10 = TEKTRONICS 4105/07/09/4010 Terminal
     11 = PLESSEY    VT-100/TEK4010  Terminal
     12 = ESPRIT     VT-100/TEK4010  Terminal
     13 = TEKTRONICS 4010-1 Hardcopy Versatec
     14 = TEK 4105/07/09 Hardcopy to TEK 4695

     Enter Terminal Device :  "9 <RETURN>"
     Enter Baud Rate (<CR> = Save Old):  "<RETURN>"
     Enter New Hardcopy Device (<CR> = Save Old):  "5 <RETURN>"

          The answers to the three questions posed above have indicated  to
     the  program  that  the  terminal is a DEC VT-220, the baud rate stays
     unchanged at 9600, and the harcopy unit is a HP-7470A  plotter.   Then
     the program displays your choices and asks for more changes:


     -------------------------
     Terminal Characteristics:
     -------------------------
     The Current Terminal Device is:
     DEC VT-220 /  TEK4010-1,   Terminal

     The Current Hardcopy Device is:
     HP  7470A   Hardcopy    X-Y    Plot

                                                               Page 14


     The  Current  Baud   Rate  is :   9600


     Change Definitions [N]?  "<RETURN>"

     DO YOU WANT PRINTER OUTPUT HOLZ LINE LABELS?  [N] "<RETURN>"

     DO YOU WANT
                 T TERMINAL PLOT ONLY
                 H HP PLOT ONLY
                 B BOTH
                 (DEFAULT= T):  "<RETURN>"

          The last question is asked only  if  the  hardcopy  device  is  a
     HP-7470A  plotter.   The  program  then  continues  according  to  the
     previous examples.



     2.7  USING THE PRINTER OPTION AND LABELLING THE HOLZ LINES

          The HOLZ lines are not labelled  unless  the  printer  option  is
     selected.

          The reason for this is that the plots  become  very  untidy  when
     labelled.   Hence a clean, uncluttered plot may be produced as well as
     a labelled copy.  The printer output also reproduces some of the  data
     in the phase file and also lists the input parameters of the user.

          An affirmative answer to the first  question  below  may  produce
     another.   A multi-coloured plot can be produced on some of the colour
     terminals, but the question is asked only if  NGRAPH  supports  colour
     changes for your terminal type.  It is sometimes of use when there are
     a large number of HOLZ lines and the user is  experiencing  difficulty
     in  identifying them.  The colour change bears no relation to symmetry
     or to the zone from which the line comes;  it  is  merely  an  aid  to
     indexing.

     DO YOU WANT PRINTER OUTPUT HOLZ LINE LABELS?  [N] "Y <RETURN>"

     DO YOU WANT THE MULTI-COLOURED PLOT?  [N] "<RETURN>"

          The program continues after this section, requesting more  input.
     When  it  does plot, the HOLZ lines are labelled with an integer which
     is positioned one quarter of the way along their length.   Positioning
     the  numbers  at  the  ends  or the centres of the lines produces very
     confusing and messy labels.  There is sometimes  a  problem  with  the
     numbers  overlapping  even  with  the  current  system.   It  is often
     necessary to produce a hardcopy plot and then  do  several  successive
     screen  plots  to  determine  the  integers for each line, marking the
     integers on the hardcopy by hand.  One can halt the  plots  and  erase
     the  screen  of the terminal if the overlap becomes too severe.  For a
     small number of lines, however, there is little problem.
                                                               Page 15


          The integers on the plots correspond to the indices listed on the
     printer  output.  The VAX system will submit the printout to the print
     queue as soon as you answer the "MORE?  [Y]"question after the plot is
     completed.  An example of the printout corresponding to a plot of HOLZ
     lines is seen below.

     PHASE=AL      
     REFERENCE:
     BARRETT & MASSALSKI, THE STRUCTURE OF METALS                           
              A         B         C     ALPHA      BETA     GAMMA
         4.0496    4.0496    4.0496      90.0      90.0      90.0

     ZONE AXIS=  4  1  1

     CAMERA LENGTH =  350mm
     C2 APERTURE =  200.um    (C2 DIAMETER =  91.60)
     VOLTAGE = 119.0000kV    WAVELENGTH = 0.033635 Angstroms

     HOLZ LINES FROM LAYERS   1  2  0  0 AND   0
     RANGE OF HOLZ INDICES -N,-N,-N TO N,N,N =  12
     MAX MODULUS OF G.G(HOLZ) =       10.
      1. -3  3 11
      2. -3  5  9
      3. -3  7  7
      4. -3  9  5
      5. -3 11  3
      6. -2  0 10
      7. -2 10  0
      8.  0 -6  8
      9.  0  8 -6
     10.  1 -9  7
     11.  1  7 -9
     12.  2-10  4
     13.  2  4-10
     14.  3-11  1
     15.  3  1-11
     16.  4-10 -4
     17.  4 -8 -6
     18.  4 -6 -8
     19.  4 -4-10


          If the printer option is selected with  the  zero-layer-only-plot
     then the following data will be printed:

     PHASE=AL      
     REFERENCE:
     BARRETT & MASSALSKI, THE STRUCTURE OF METALS                           
              A         B         C     ALPHA      BETA     GAMMA
         4.0496    4.0496    4.0496      90.0      90.0      90.0

     ZONE AXIS=  4  1  1 

     CAMERA LENGTH =  350mm
     C2 APERTURE =  200.um    (C2 DIAMETER =  91.60)
                                                               Page 16


     VOLTAGE = 119.0000kV    WAVELENGTH = 0.033635 Angstroms

     FIRST G DIRECTION =  1 -1  1    SECOND G DIRECTION =  1  1 -1



     2.8  PERFORMING REPEATED PLOTS

          If one replies "Y <RETURN>" or simply  "<RETURN>"  to  the  "MORE
     [Y]?" prompt that appears on the terminal screen after the plotting is
     completed, then there is a slightly different  sequence  of  questions
     asked  by  the  program  in order to produce another plot.  The screen
     will be cleared and the program will ask (the answers  serve  only  as
     examples):

     DO YOU WANT ZERO LAYER (Z), HOLZ (H), OR BOTH (B)?  "H <RETURN>"

     DO YOU WANT PRINTER OUTPUT HOLZ LINE LABELS?  [N] "<RETURN>"

          If you have a HP-7470A plotter and  have  properly  recorded  its
     presence  (see section 2.6), the program will then ask you whether you
     wish to use it for the current plot.

     DO YOU WANT
                 T TERMINAL PLOT ONLY
                 H HP PLOT ONLY
                 B BOTH
                 (DEFAULT= T):  "<RETURN>"

     ANOTHER PHASE FILE?  [N] "<RETURN>"

          The  answer  to  the  last  question  above  will  suppress   the
     subsequent  display  of  the  phase  file  data  on the terminal.  The
     program will then  progress  in  a  manner  similar  to  that  already
     detailed in the previous sections.



     2.9  OBTAINING HARDCOPY OF THE PLOTS

          There several alternatives available here.  They can  be  divided
     into essentially two groups:

     a.  Hardware controlled plots.

     b.  Software controlled plots.




     2.9.1  HARDWARE CONTROLLED PLOTS

          This section covers some of the ways of producing  hard  copy  of
     the  diffraction plots that are totally independent of the Diffraction
     Suite.  Certain terminals,  e.g.   the  Tektronics  4010/14  and  4100
                                                               Page 17


     series have the capability of dumping the contents of their screens to
     a printer under keyboard control.  Some terminals can be connected  to
     a  Video  Printer  such  as the Polaroid Model 48 Videoprinter and the
     screen image can  be  recorded  on  on  a  photographic  medium,  e.g.
     polaroid  prints/film  or 35mm film.  Apple MacIntosh users who employ
     the VersaTerm software can capture and store plots on floppy disk  and
     subsequently  plot  them  on  either  a  dot-matrix  printer  or laser
     printer.

          If desired, when the plots  have  been  viewed  on  the  terminal
     screen,  the  program  can  be rerun and the output directed to a data
     file which may then be directed to a hardcopy device that will  accept
     TEK4010  graphics  commands,  e.g.   the  DEC LN01 Laser printer.  The
     plots are directed to logical unit number 7 in the  FORTRAN  code  and
     therefore  that  number  will  need to be assigned to a file to employ
     this technique.

          The method of obtaining hardcopy without  using  the  program  is
     essentially left to the choice of the operator.



     2.9.2  SOFTWARE CONTROLLED PLOTS

          The  Diffraction  Suite  currently  supports  three  methods  for
     producing hardcopies of the diffraction plots.  Two of these are based
     on host control of Tektronics terminals connected  to  screen  copiers
     (e.g.   the  Tektronics 4601 printers, the Versatec and the Tektronics
     4695 colour ink-jet  printer).   The  third  involves  the  use  of  a
     Hewlett-Packard 7470A or compatible x-y plotter.

          In the case of the screen copiers, if you are using a  Tektronics
     4010  or  similar  terminal  with  a  connected Tektronics 4601 screen
     copier or  Versatec  copier  or  a  Tektronics  4100  series  terminal
     connected  to  a  Tek  4695  colour  copier then you should select the
     Tektronics Screen Copier option in the terminal listing  as  described
     in  section  2.6  above.  The program will then ask, when the plot has
     been completed on the terminal,  if  you  would  like  hardcopy.   The
     question  is  abbreviated to avoid obscuring the plot.  The default is
     affirmative.  If you type N, the question "MORE?  [Y]" will appear and
     you may make another or exit to the main menu.

          If you choose to make a plot, then the program sends the  correct
     escape codes to the terminal to activate the printing process.  In the
     case of the TEK4100 series terminals the program will first  ask:   "S
     OR L?  [S]".

          Selection of S will result in a small fast plot (usually about  a
     minute  of  plotting time) and L will yield a full size plot that will
     take up to eight minutes.  Both of these times assume that you do  not
     have  a  buffer  between  the  terminal  and  the printer.  During the
     printing the terminal is locked and when  completed  the  the  program
     will  print  "MORE?   [Y]" as usual.  If you do have a printer buffer,
     then the data will be dumped to the buffer and you  will  be  able  to
     continue plotting while the printer produces you pattern.
                                                               Page 18


          If you are using a Hewlett-Packard 7470A or  similar  device  for
     hardcopy  plots,  you  will  need  to  have this device connected to a
     separate port of the computer.  The software will not  cope  with  the
     x-y  plotter  in  loop-through  mode.   To  use this option select the
     number for the  HP  plotter  from  the  device  number  list  that  is
     generated when the response "Y<RETURN>" is given to the prompt "Change
     Definitions [N]?".

          Choosing a HP plotter as the hardcopy  unit  will  require  extra
     information  from  the user.  After questioning the user as to whether
     he/she desires printer output, the program will ask:

     DO YOU WANT
                 T TERMINAL PLOT ONLY
                 H HP PLOT ONLY
                 B BOTH
                                  <
                 (DEFAULT= T):  H <RETURN>

          This option is fairly self explanatory.  The preferred method for
     producing  plots  on  the x-y plotter is to first view the patterns on
     the terminal and then produce a plot on the HP plotter.

          If the logical unit FOR080 is assigned to a file then  the  plots
     can be written to a disk file and output at a later date.

     NOTE:  The HP plotting routine will label the first two discs, but  it
     does  not support labelling the patterns with the phase name, the zone
     axis, the date, or the HOLZ line indices.  Therefore, if  the  printer
     option  is  selected, a printout will be generated and the labels will
     appear on the video terminal but not on the hard copy.












                                APPENDIX A

                     GENERAL CRYSTALLOGRAPHIC FORMULAE



          These are some of the general formulae used in the programs, both
     to create the Phase File and to plot the patterns.
     Lattice parameters a,b,c and a,b,g where
                a^b = g , etc

     Volume of the unit cell V:

                V = abc(1 - cos2a - cos2b - cos2g + 2cosacosbcosg)1/2

     Volume of the reciprocal lattice unit cell:

                V* = V-1

                a* = bxc/V = bcsina/V,  b* = casina/V,  c* = absing/V

                cosa* = (cosbcosg - cosa)/sinbsing
                cosb* = (cosgcosa - cosb)/singsina
                cosg* = (cosacosb - cosg)/sinasinb

     If the angle between two real vectors U1 and U2 is f then:

                         U1.U2      
                cosf =  --------
                        |U1||U2| 

     where
                U1.U2 = (u1a + v1b + w1c).(u2a + v2b + w2c)
                      = u1u2a2 + v1v2b2 + w1w2c2 + (v1w2 + v2w1)bccosa
                               + (w1u2 + w2u1)cacosb + (u1v2 + u2v1)abcosg
     and
                U2= U.U = u2a2 + v2b2 + w2c2 + 2vwbccosa
                               + 2wucacosb + 2uvabcosg

     The angle between two reciprocal lattice vectors is given by:

                         g1.g2       
                cosf =  --------
                        |g1||g2|

     The formula is identical to the previous expression for cosf except that
GENERAL CRYSTALLOGRAPHIC FORMULAE                             Page A-2


     uvw is substituted by hkl and a,b,g by a*,b*,g*.

     The angle between a real vector and a reciprocal vector is given by:

                        g.U          
                cosf =  ------
                        |g||U|

     where
                g.U = (ha* + kb* + lc*).(ua + vb + wc)
                    = (hu + kv+ lw)

                [a.a* = 1, a.b* = 0, or generally ai.aj* = dij]



          The zero layer plotting section of the  program  uses  the  Phase
     File  that  was  created using the formulae above to plot the discs or
     spots of the zero order Laue zone.

          The phase file is searched and dot products calculated  for  each
     G-vector  and  the  chosen  zone  axis  U.  If the product is zero the
     vector is plotted, the number of vectors  plotted  is  chosen  by  the
     operator and a convenient number must be determined empirically.












                                APPENDIX B

                      THE EMPTY LATTICE CONSTRUCTION



          Editor's Note:  This appendix was written assuming the  inclusion
     of figures which could not be stored in the Public Domain Library.  If
     the user desires to  have  the  figures,  he/she  should  contact  the
     author.

          Author's Note:  It is not possible to construct the  diagrams  in
     this  appendix  to  scale  and  have them still be useful.  The reader
     should be aware that the Ewald sphere constructions shown have a  much
     smaller radius than they should.

          The main approximation for the simulation  and  plotting  of  the
     HOLZ  deficiency lines in bright field disc is the kinematic or 'empty
     lattice' construction.  The procedure for this is outlined below.




                                   Figure B1
                         The Empty Lattice Construction


          Draw a sphere of radius k about all g vectors,  where  k  is  the
     reciprocal  wavelength  of  the  incident electron beam.  An origin is
     chosen in the reciprocal lattice and the intersections of the  various
     spheres  with  the  sphere drawn about the origin give the loci of the
     Bragg reflection conditions.  These are equivalent to  two  cones  for
     1g, projecting on to a plane through the origin as hyperbolae at large
     angles.  For small angles these lines appear to  be  straight.   These
     lines  are  the HOLZ deficiency lines, in this program we shall assume
     that they are straight.  For high energy electron  this  approximation
     is excellent for angles less than ~10!.

          For a more ideal calculation the sphere about the origin would be
     replaced  by  a  zero  layer dispersion surface which usually exhibits
     less curvature, however mapping on to a sphere in this case  will  not
     affect  the geometries of the line intersections and is sufficient for
     the purpose here.  The case of most interest is when  we  are  looking
     down  a  zone axis of the crystal U, i.e.  the electron is parallel to
     the zone axis.     
THE EMPTY LATTICE CONSTRUCTION                                Page B-2


          To determine where the  intersecting  spheres  project  onto  the
     diffraction  plane we need to know the magnitude of the angle f in the
     plane containing the zone axis and the reciprocal  lattice  vector  g.
     From figure B1 we can see:

                       f = 90 - qg - (90 - qB) = qB - qg

     ( f positive implies that the line will lie in the  opposite  quadrant
     of the projection to g ).

          We can obtain qB and qg from the following:

                sinqB = gl/2    sinqg = g.U/|g||U|


          The program cycles through the HOLZ g vector (gH) range specified
     by  the  operator  and checks to see if U.gH=n, where n is the desired
     number of the Laue layer.  If n is one of  the  chosen  integers,  the
     program  calculates  the  angle f and assumes that the deficiency HOLZ
     line projects into the diffraction plane as a straight line  which  is
     perpendicular  to  the  projection  of the HOLZ g vector into the same
     plane.  The distance from the origin of  the  diffraction  pattern  is
     represented  by  f,  if f is greater than the convergence of the probe
     then it will not be seen, as it will be outside the  second  condenser
     aperture The ends of the HOLZ line are determined by calculating where
     the line will intersect with a circle drawn to  represent  the  second
     aperture.




                                   Figure B2
              Plan View of the Intersection of One Pair of Spheres
                          Projected onto the x-y Plane


          Figure B2 is  a  plan  view  of  the  projection  of  one  sphere
     intersection  on  to  the  plane  perpendicular to the zone axis.  The
     circle represents the condenser aperture of the  microscope.   In  the
     program  the condenser aperture is essentially a window about the zone
     axis of N radians and  sphere  intersections  that  lie  outside  that
     window are not visible in the pattern.

          The program checks that the value of f is less than  that  of  N.
     If  this  is  the case then OP is f radians and AB is the deficit HOLZ
     line.  To determine where to plot this line we need to find the  value
     of  w the angle between OP and the x-axis.  The horizontal axis (x) is
     defined by using the Phase File, it is the shortest reciprocal lattice
     vector  that is perpendicular to the given zone axis U, let us call it
     gx.  To define the vertical axis (y), the vector for the x axis, which
     is  in  reciprocal  units,  is  converted  to real units and the cross
     product taken with U to produce a reciprocal lattice vector, gy  which
     is perpendicular to both U and the x axis.  The matrix used to convert
     the vector is included in Appendix E.
THE EMPTY LATTICE CONSTRUCTION                                Page B-3


                                   Figure B3
              Projection of the HOLZ Vector g on to the x-y Plane.


          Once we  have  the  axes  defined,  then  we  may  determine  the
     magnitudes  and signs of OX and OY (see figure B3), the projections of
     the HOLZ lattice vector g onto the x and y axes.  We need these values
     to  determine where within the C2 apeture we will see the line Knowing
     OX and OY means we  can  calculate  w,  both  the  magnitude  and  the
     quadrant in which it lies.

          Figure B2 shows w as an obtuse  angle  in  the  second  quadrant,
     whereas  figure  B3  shows it as an acute angle in the first quadrant,
     this was done simply as a  matter  of  convenience  when  drawing  the
     diagrams.

          OP determines the distance of the HOLZ line from  the  centre  of
     the zone axis pattern:
                OP = -f = -qB + qg = -sin-1(gl/2) + sin-1(g.U/|g||U|)

          When we know OP, then we can use it together with the convergence
     angle  defined by the C2 aperture to calculate the value of angle v as
     seen in figure B4:
                       cosv = OP/N

          w is determined from the projections g on to the  x  and  y  axes
     (see figure B3):

                       projection of g along x = g .  gx/|g|
                       projection of g along y = g .  gy/|g|

                       w = tan-1( g .  gx/|g| / g.  gy/|g|)

     The signs of the x and y projections of g indicate in which quadrant w
     is located.




                                   Figure B4
              Plan View of How The Intersections of The HOLZ Line
              With The Field Limiting C2 Aperture Are Calculated.


          The HOLZ lines are plotted by drawing a line between the points A
     and  B  in  figure  B4.   The size of the plot is designed to fill the
     screen of the terminal in the HOLZ-only case.  In the case of HOLZ and
     zero  layer  there is a scale factor built into the program that fills
     the screen of the terminal when about 12 orders of the zero layer of a
     silicon <100> pattern is plotted.

          The program is designed to search a volume of  reciprocal  space,
     with  certain user defined limits and draw all lines which fall within
     a designated window (ie.  inside the C2 aperture).  The  user  defined
     limits can be:
THE EMPTY LATTICE CONSTRUCTION                                Page B-4


     1.  Searching from -h,-k,-l to h,k,l

     2.  Setting a maximum value of |g2|

     3.  Calling a subroutine that checks for allowed reflections  for  the
         reciprocal lattice in question.

     4.  Setting several maximum and minimum values for g.U, to search  for
         several layers of the reciprocal lattice













                                APPENDIX C

                    LISTING OF THE DATA FILE TERMIN.DAT



          Note that in this example the terminal is  set  to  a  Tektronics
     4100  series  and  the hardcopy unit is one the ink-jet screen copiers
     available for that unit.  Only the first  three  lines  are  required.
     Please  note that the comments beginning each of the first three lines
     are both spacers as well  as  reminders  about  the  function  of  the
     parameters on each line.

     GRAPHICS TERMINAL TYPE:10
     BAUD RATE FOR GRAPHICS:9600
     HARDCOPY  DEVICE  TYPE:11
     C  --------------------------------------------------------
     C  TERMINAL DEFINITIONS:
     C  ---------------------
     C -3 = ASCII TERMINAL: NO GRAPHICS, & NO VT-100 compatibility & <32
     C        COLUMNS
     C -2 = ASCII TERMINAL: NO GRAPHICS, & NO VT-100 compatibility
     C -1 = ANSI X3.4 ASCII TERMINAL: NO GRAPHICS, VT-100 compatible
     C  0 = TEKTRONICS 4010-1,4014-1 (WITH HARDWARE CURSOR)
     C  1 = TEKTRONICS 4006  ,4010   (NO HARDWARE CURSOR)
     C  2 = LEAR SIEGLER ADM-3,ADM-5 (WITH RETROGRAPHICS RG-512)
     C  3 = PERITEK VCG-512 BIT MAP COLOR GRAPHICS
     C  4 = TEKTRONICS 4027
     C  5 = HP 7470A/7475A HARDCOPY PLOTTER
     C  6 = LA100/LA50 HARDCOPY GRAPHICS
     C  7 = INTECOLOR VT-100 with 4010-1,4014-1 mode
     C  8 = INTECOLOR VT-100 with 4027 mode
     C  9 = DEC VT-200 with 4010-1,4014-1 mode
     C 10 = TEKTRONICS 4105/4107 with VT-100 compatibility mode
     C 11 = PLESSEY VT-100/TEK 4010-1
     C 12 = ESPIRIT VT-100/TEK 4010-1
     C 13 = TEKTRONICS 4010-1 HARDCOPY VIDEO TO VERSATEC
     C 14 = TEKTRONICS 4695 Color Copier
     C  --------------------------------------------------------
     C  BAUD RATE RANGE FOR GRAPHICS (110 - 19200)
     C  --------------------------------------------------------
     C  
     C  
     C  
     C
     C  THE FOLLOWING ARE THE NECESSARY COMMON BLOCKS FOR
LISTING OF THE DATA FILE TERMIN.DAT                           Page C-2


     C  NGRAPH WHICH SHOULD BE INCLUDED IN ALL USER PROGRAMS.
     C
     C  COMMON /CRTLST/ XMIN,DX,YMIN,DY,OFFX,OFFY,XL,YL
     C  COMMON /TERMIN/ ITERM,IBAUD,IPLOT,ICOLOR,IMODE,IHARD
     C  DIMENSION ILX(7),ILY(7)
     C  COMMON /LABEL/ ILX,ILY,NILX,NILY
     C
     C  DEFAULT LABELS FOR X & Y AXIS ARE DEFINED HERE.
     C  THESE MAY BE CHANGED AS APPROPRIATE BY THE USER.
     C  NOTE THAT THE DIMENSIONS OF ILX AND ILY MUST CHANGE WITH
     C  THE SIZE OF THE LABEL DESIRED.
     C
     C
     C  ILX= LABEL OF XAXIS STORED AS TWO CHARACTERS PER BYTE.
     C  ILY= LABEL OF YAXIS STORED AS ONE CHARACTER PER BYTE.
     C  NILX= TOTAL NUMBER OF CHARACTERS IN XAXIS LABEL 
     C  INCLUDING SPACES.
     C  NILY=TOTAL NUMBER OF CHARACTERS IN YAXIS LABEL INCLUDING
     C          SPACES.
     C
     C  HERE IS A TYPICAL LABEL: X AXIS = Energy (eV), Y AXIS = Counts
     C
     C  DATA ILX /'En','er','gy',' (','eV',') ','  '/
     C  DATA ILY /'C ','o ','u ','n ','t ','s ','  '/
     C  NILX=14         
     C  NILY=7
     C
     C
     C

          NOTE 1:  The information commented below the terminal data is for
     XEDS and EELS spectra plotting with Nestor Zaluzec's Graphics Package;
     it can be ignored in this case.

          NOTE 2:  The baud rate listed is not the actual  baud  rate  that
     the data is transmitted to the terminal.  It is a value institiuted by
     Nestor to allow  for  the  speed  of  response  of  various  different
     terminals and interconnection systems.  Increasing the number actually
     decreases the speed of data transmission as a delay loop time  is  set
     from it.












                                APPENDIX D

                              PROGRAM LISTING



          This is the source code section.  In the EMMPDL the source is  in
     a separate file.












                                APPENDIX E

             CONVERSION MATRIX FOR RECIPROCAL LATTICE VECTORS



          This section lists the conversion of a reciprocal lattice  vector
     to an identical vector expressed in real space units.

                g=ha*+kb*+lc*=ra+sb+tc

     We need a matrix P such that:

                f  P11  P12  P13  v     f h     v       f r     v
                g  P21  P22  P23  w     g k     w   =   g s     w
                h  P31  P32  P33  x     h l     x       h t     x
     and
                a* = P11a + P12b + P13c         i
                b* = P21a + P22b + P23c         ii
                c* = P31a + P32b + P33c         iii

                a.a*=1,  b.a*=0,  c.a*=o        iv

     If we substitute i into iv then we get:

                P11a2      +    P21abcosg   +   P32accosb  =    1
                P11abcosg  +    P21b2       +   P31bccosa  =    0
                P11accosb  +    P21bccosa   +   P31c2      =    0
     or
                f  a2   abcosg  accosb  v       f P11 v         f 1 v
                g  abcosg   b2  bccosa  w       g P21 w   =     g 0 w
                h  accosb  bccosa   c2  x       h P31 x         h 0 x

     Write the matrix as M.
     (Note that det M = a2b2c2(1 - cos2a - cos2b - cos2g + 2cosacosbcosg) = V2)

     Then
                     f P11 v    f 1 v           f P11 v         f 1 v
                M =  g P21 w  = g 0 w    and    g P21 w  = M-1  g 0 w
                     h P31 x    h 0 x           h P31 x         h 0 x

     So,
                P11 = M11-1 = adj M11/det M
                P21 = M21-1 = adj M21/det M
                P21 = M31-1 = adj M31/det M

CONVERSION MATRIX FOR RECIPROCAL LATTICE VECTORS              Page E-2


                P11 = b2c2(1 - cos2a)/V2 = b2c2sin2a/V2
                P21 = abc2(cosacosb - cosg)/V2
                P31 = ab2c(cosacosg - cosb)/V2

     The other components of Matrix P can be written down by rotation of 
     a,b,c & a,b,g:

               f   b2c2sin2a      abc2(cosacosb-cosg)  ab2c(cosacosg-cosb)   v
     P = 1/V2  g   abc2(cosacosb-cosg)  a2c2sin2b      a2bc(cosbcosg-cosa)   w 
               h   ab2c(cosacosg-cosb)  a2bc(cosbcosg-cosa)      a2b2sin2g   x 

     or 

                   f   sin2a/a2   (cosacosb-cosg)/ab   (cosacosg-cosb)/ac   v
     P = (abc/V)2  g   (cosacosb-cosg)/ab   sin2b/b2   (cosbcosg-cosa)/bc   w 
                   h   (cosacosg-cosb)/ac   (cosbcosg-cosa)/bc   sin2g/c2   x 

                (Note that cosacosb - cosg = sinasinbsing*, etc.)

     The inverse matrix P-1,which converts a real vector U to reciprocal
     indices, is obtained by adding stars to every parameter above.


     For an orthorhombic cell:

                        f       1/a2    -       -       v
                P =     g       -       1/b2    -       w 
                        h       -       -       1/c2    x 

     Then ha* + kb* + lc* = (h/a2)a + (k/b2)b + (l/c2)c .


     For a hexagonal cell:
     a,b=90!, g=120!, cosg=-1/2, sing=3/2 V=a2cV3/2, (abc/V)2=4/3

                        f       1/a2    1/2a2   -       v
                P =     g       1/2a2   1/a2    -       w 
                        h       -       -       3/4a2   x 


     For a monoclinic cell:
                V2 = a2b2c2(1 - cos2b), (abc/V)2 = 1/sin2b

                        f       1/a2    -       cosb/ac         v
                P =     g       -       sin2b/b22       -       w 
                        h       -cosb/ac        -       1/c2    x 












                                APPENDIX F

          A SELECTED BIBLIOGRAPHY OF CONVERGENT-BEAM DIFFRACTION




     The first CBED paper:

          "Elektroneninterferenzen im Konvergenten Bundel", W.  Kossel  and
          G.  Mollenstedt, Ann.  Phys.  36 (1939) 113-140.


     Books:

          "Convergent-Beam  Electron  Diffraction",  M.   Tanaka   and   M.
          Terauchi (J.E.O.L., Tokyo, 1985), 192 pp.

          "Convergent Beam  Electron  Diffraction  of  Alloy  Phases",  the
          Bristol  Group  under  the  direction of John Steeds, compiled by
          John Mansfield (Adam Hilger, Bristol, 1984), 105 pp.


     Books with useful sections on CBED:

          "Electron Beam Analysis of Materials", M.  H.   Loretto  (Chapman
          and Hall, London, 1984) 210 pp.

          "Practical Analytical Electron Microscopy in Materials  Science",
          D.   B.   Williams (Verlag Chemie International, Deerfield Beach,
          1984) 153 pp.


     Review Articles:

          "Convergent  Beam  Electron   Diffraction",   J.W.    Steeds   in
          "Introduction  to  Analytical Electron Microscopy" , Eds.  J.  J.
          Hren, J.  I.  Goldstein and D.  C.  Joy (Plenum, New York,  1979)
          387-422.

          "Electron  Crystallography",  J.W.    Steeds   in   "Quantitative
          Electron  Microscopy",  Eds.   J.  N.  Chapman and A.  J.  Craven
          (Scottish Universities Summer School in Physics,  Edinburgh,1984)
          49-96.

          "Electron Microdiffraction",  J.   C.   H.   Spence  and  R.   W.
A SELECTED BIBLIOGRAPHY OF CONVERGENT-BEAM DIFFRACTION        Page F-2


          Carpenter  the  second  edition  of  "Introduction  to Analytical
          Electron Microscopy"  (see  above)  to  be  published.   [In  the
          meantime  see  R.   W.   Carpenter  and  J.   C.   H.  Spence, J.
          Microsc.  136 (1984)165-178].

          "Convergent-Beam Techniques in Transmission Electron Microscopy",
          J.  A.  Eades, Appl.  Surface Science (in press).


     Tutorial Paper:

          "How To Get A Convergent Beam Electron  Diffraction  Pattern  And
          How  To Recognize What You See", J.A.  Eades, Norelco Reporter 32
          (1985) 22-37 (based on an EMSA tutorial available on videotape).












                                APPENDIX G

                    SOURCE CODE COMPILATION AND LINKING



     To compile the source code, use the following command file on a VAX:

$ FORTRAN/EXTEND/F77 DIFFRACTIONSUITE
$ FORTRAN/EXTEND/F77 NGRAPH
$ LINK/MAP/NOTRACEBACK/EXE=DIFFRACT.EXE,DIFFRACTIONSUITE,NGRAPH

     The resulting executable image is DIFFRACT.EXE .

     Note:  Ngraph is Nestor Zaluzec's graphics package, which is available
in the EMMPDL.

     This is the command file that assigns all the devices for running  the
DIFFRACTION SUITE:

$ !
$ ASSIGN YOUR_DISK: FOR030
$ ASSIGN YOUR_DISK: FOR006
$ ASSIGN YOUR_DISK: FOR008
$ ASSIGN YOUR_DISK: FOR011
$ ASSIGN TT:  FOR001
$ ASSIGN TT:  FOR004
$ ASSIGN TT:  FOR007
$ ASSIGN TT:  FOR005
$ ASSIGN YOUR_XY_PLOTTER:  FOR080
$ ASSIGN YOUR_DISK: DAT:
$ ASSIGN YOUR_PRINTER: FOR002

     Where the devices labelled "YOUR..."  are  those  on  your  particular
system.
C Title                  :THE DIFFRACTION SUITE
C Keywords               :CBED, HOLZ, KINEMATICAL APPROXIMATION
C Computer               :DEC VAX 11/730-785, DEC PDP 11/2-11/73
C Operating System       :VAXVMS
C Programming Language   :Fortran 77
C Hardware Requirements  :TEKTRONICS 4010 TERMINAL OR SUITABLE EMULATOR
C Author(s)              :JOHN F. MANSFIELD (919)-248-1800
C Correspondence Address :THE MICROELECTRONICS CENTER OF NORTH CAROLINA
C                        :PO BOX 12889, RESEARCH TRIANGLE PARK, N.C. 27709.
C Source:
C -------------------------------------------------------------------------
C#######################################################################
C#                                                                     #
C#  THIS FILE CONTAINS A LISTING OF THE DIFFRACTION SUITE SOURCE CODE, #  
C#  IT DOES NOT CONTAIN THE GRAPHICS SOURCE.                           #
C#                                                                     #
C#######################################################################	
C
C***********************************************************************
C*  THIS CODE IS A MIXTURE OF SEVERAL PEOPLES ROUTINES IN ADDITION     *
C*  TO MY OWN                                                          * 
C*	MY THANKS GO TO THE FOLLOWING FOR SHOWING ME HOW THEY          *
C*	DO IT AND NOT MINDING IF I BASTARDIZE THEIR ROUTINES           *
C*	AND INCORPORATE THEM INTO MINE.                                *
C*	ROGER VINCENT                                                  *
C*	HAMISH FRASER                                                  *
C*	DAVID WILLIAMS                                                 *
C*	WAYNE KING                                                     *
C*	AND ANYONE ELSE WHO SAYS "HEY, HE STOLE THAT IDEA FROM ME!"    *
C***********************************************************************
C	THIS CODE WAS EDITED BY THE EMMPDL LIBRARIAN IN JULY 1989.
C	PRIOR TO THAT TIME, AN OLD VERSION OF THIS PROGRAM RESIDED IN
C	THE EMMPDL.
C***********************************************************************
CTHIS IS THE MENU ROUTINE WHICH CALLS ALL OF THE OTHER ROUTINES.    
C***********************************************************************
	PROGRAM DIFMENU
C
C
          CHARACTER*1 MENU_CHOICE
           INTEGER ITERATIONS_THRU
C
C
C
C	INCLUDE THE CONTROL/C ROUTINE FROM THE VAX FORTRAN
C 	MANUAL
C
C
	INCLUDE '($SYSSRVNAM)'
	INTEGER*4 TT_CHAN
	COMMON TT_CHAN
	ISTAT = SYS$ASSIGN ('TT',TT_CHAN,,)
	IF (.NOT. ISTAT) CALL LIB$STOP(%VAL(ISTAT))
	CALL ENABLE_CTRLC
C
C
C
C
C
C	DO A FORM FEED TO CLEAR THE SCREEN
C
	CALL TOUT(12)
C
C
C
C	SET FLAG FOR LATER QUESTIONS
C
C
 5    ITERATIONS_THRU=0
      WRITE(7,10)
 10   FORMAT(5X,'THE DIFFRACTION SUITE',///,3X,
     C'A: CALCULATION OF RECIPROCAL LATTICE VECTORS',//,3X,
     C'B: LISTING OF RECIPROCAL LATTICE VECTORS (TERMINAL)',//,3X,
     C'C: LISTING OF RECIPROCAL LATTICE VECTORS (PRINTER)',//,3X,
     C'D: PLOT [UVW] ZERO LAYER ZONE AXIS PATTERN (TERMINAL)',//,3X,
     C'E: PLOT DIRECT DISC HOLZ LINES (TERMINAL)',//,3X,
     C'F: PLOT ZERO LAYER WITH HOLZ LINES (TERMINAL)',//,3X,
     C'G: EXIT FROM SUITE',//,$,6X,
     C'SELECT ONE OF A TO G AND <RETURN>:  ')
      READ(5,'(A)')MENU_CHOICE
      IF(MENU_CHOICE.EQ.'A') CALL GVEC(MENU_CHOICE,ITERATIONS_THRU)
      IF(MENU_CHOICE.EQ.'B') CALL GPRINT(MENU_CHOICE,ITERATIONS_THRU)
      IF(MENU_CHOICE.EQ.'C') CALL GPRINT(MENU_CHOICE,ITERATIONS_THRU)
      IF(MENU_CHOICE.EQ.'D') CALL ZERO(MENU_CHOICE,ITERATIONS_THRU)
      IF(MENU_CHOICE.EQ.'E') CALL ZERO(MENU_CHOICE,ITERATIONS_THRU)
      IF(MENU_CHOICE.EQ.'F') CALL ZERO(MENU_CHOICE,ITERATIONS_THRU)
      IF(MENU_CHOICE.EQ.'G') GO TO 30
      GO TO 5
 30   CONTINUE
	CALL VT100
      WRITE(7,40) 
 40   FORMAT(2X,'EXITING.......')
 50   END
C
C***********************************************************************
C	ENABLE CTRL/C TRAPPING AND SPECIFY CTRLC_ROUT
C	AS ROUTINE TO BE CALLED WHEN A CTRL/C OCCURS
C***********************************************************************
C
C
C----------------------------------------------------------------------------
	SUBROUTINE ENABLE_CTRLC
C----------------------------------------------------------------------------
	INTEGER*4 TT_CHAN
	COMMON TT_CHAN
	EXTERNAL CTRLC_ROUT
	INCLUDE '($IODEF)'
	INCLUDE '($SYSSRVNAM)'
	ISTAT = SYS$QIOW(,%VAL(TT_CHAN),
     1  %VAL(IO$_SETMODE .OR. IO$M_CTRLCAST),
     1  ,,,CTRLC_ROUT,,%VAL(3),,,)
	IF (.NOT. ISTAT) CALL LIB$STOP(%VAL(ISTAT))
	RETURN 
	END
C
C***********************************************************************
C PART OF THE CONTROL-C HANDLING ROUTINE.
C***********************************************************************
C
C----------------------------------------------------------------------------
	SUBROUTINE CTRLC_ROUT
C----------------------------------------------------------------------------
	PRINT *, 'INTERUPTED BY CTRL-C....WAIT'
	CALL DELAY(500)
	CALL CODE
C	STOP
	RETURN
	END
C
C***********************************************************************
C ANOTHER PART OF THE CONTROL-C HANDLING ROUTINE.
C***********************************************************************
C
C----------------------------------------------------------------------------
	SUBROUTINE CODE
C----------------------------------------------------------------------------
C
C
C
	IF(ITERM.NE.10) THEN
	CALL ENDCRT
	RETURN
	ENDIF
C
C
C
C	THIS PROGRAM CLEARS THE SCREEN THEN
C	CONVERTS THE TEK 4107 TO EDIT MODE
C	
C
C
C	G ERAS
C
	CALL TOUTPT(27)		!ES
	CALL TOUTPT(12)		!FF
C
C      
C
C
C
	CALL TOUTPT(27)     	!ESC
	CALL TOUTPT(37)		!%
	CALL TOUTPT(33)	        !!
	CALL TOUTPT(50)		!2
C
C	2 FORM FEEDS
C
	CALL TOUTPT(12)		!FF
	CALL TOUTPT(12)		!FF
	CALL TOUTPT(12)		!FF
C
C
C
	RETURN
	END
C
C***********************************************************************
C	THIS IS THE ROUTINE WHICH CREATES THE "PHASE FILE"
C*********************************************************************** 
C
C
C
C
      SUBROUTINE GVEC(XXX,IPASSF)
      CHARACTER*1 SYM
      INTEGER*4 FN(4)
      INTEGER*4 DAT
      DIMENSION REF(20)
      DIMENSION X(5000),Y(5000),Z(5000)
      DIMENSION R(5000)
      DIMENSION IH1(5000),IK1(5000),IL1(5000)
      DIMENSION IBID(5000),INDEX(5000)
      DATA BLANK/'    '/
      DATA YES,XNO/'Y','N'/
      DATA XC,XA,XB,XF,XI,XP,XH,XR
     C/'C','A','B','F','I','P','H','R'/
      DATA DAT/'.DAT'/
      FN(1)='    '
      FN(2)='    '
      FN(3)=DAT
      FN(4)=0
      DO 10 I=1,20
   10 REF(I)=BLANK
      DO 20 I=1,1200
   20 IBID(I)=0
      PI=4.*ATAN(1.)
   30 WRITE(7,40)
   40 FORMAT(/,$,' ENTER 8-CHARACTER PHASE SYMBOL/NAME:  ')
      READ(5,50)FN(1),FN(2)
   50 FORMAT(2A4)
      WRITE(7,60)
   60 FORMAT(/,$,' ENTER A0,B0,C0 IN ANGSTROMS:  ')
      READ(5,70)A0,B0,C0
   70 FORMAT(3F13.6)
      WRITE(7,80)
   80 FORMAT(/,$,' ENTER ALPHA, BETA, AND GAMMA IN DEGREES
     C (EG. 90.0):  ')
      READ(5,70)ALPHA,BETA,GAMMA
      WRITE(7,90)
   90 FORMAT(/,' ENTER LITERATURE REFERENCE; 80 CHARACTER MAXIMUM:')
      READ(5,100)(REF(I),I=1,20)
  100 FORMAT(20A4)
      ALPHA=ALPHA*PI/180.
      BETA=BETA*PI/180.
      GAMMA=GAMMA*PI/180.
      COSALP=COS(ALPHA)
      COSBET=COS(BETA)
      COSGAM=COS(GAMMA)
      SINALP=SIN(ALPHA)
      SINBET=SIN(BETA)
      SINGAM=SIN(GAMMA)
      V0=SQRT(A0*A0*B0*B0*C0*C0*(1.-COSALP**2-COSBET**2-COSGAM**2
     C+2.*COSALP*COSBET*COSGAM))
      AST=B0*C0*SINALP/V0
      BST=A0*C0*SINBET/V0
      CST=A0*B0*SINGAM/V0
      CALST=(COSBET*COSGAM-COSALP)/(SINBET*SINGAM)
      CBETST=(COSALP*COSGAM-COSBET)/(SINALP*SINGAM)
      CGAMST=(COSALP*COSBET-COSGAM)/(SINALP*SINBET)
      IF(CALST.NE.0.)GO TO 110
      ALST=PI/2.
      GO TO 120
 110  ALST=ATAN(SQRT(1.-CALST**2)/CALST)
 120  IF(CBETST.NE.0.)GO TO 130
      BETST=PI/2.
      GO TO 140
 130  BETST=ATAN(SQRT(1.-CBETST**2)/CBETST)
 140  IF(CGAMST.NE.0.)GO TO 150
      GAMST=PI/2.
      GO TO 160
 150  GAMST=ATAN(SQRT(1.-CGAMST**2)/CGAMST)
 160  SGAMST=SIN(GAMST)
      L=0
      WRITE(7,170)FN(1),FN(2),FN(3),FN(4)
 170  FORMAT(/,' THE NAME OF THE FILE IS ',4A4)
      OPEN(UNIT=6,STATUS='NEW',NAME=FN,FORM='FORMATTED',
     CRECL=180,RECORDTYPE='VARIABLE')
      ALPHA=ALPHA*180./PI
      BETA=BETA*180./PI
      GAMMA=GAMMA*180./PI
      WRITE(7,180)
 180  FORMAT(/,' CHOOSE LATTICE TYPE:',/,4X,' PRIMITIVE (P)',/,4X,
     C' BASE CENTERED ALONG THE A-AXIS (A)',/,4X,
     C' BASE CENTERED ALONG THE B-AXIS (B)',/,4X,
     C' BASE CENTERED ALONG THE C-AXIS (C)',/,4X,
     C' FACE CENTERED (F)',/,4X,
     C' BODY CENTERED (I)',/,4X,' HEXAGONAL (H)',/,4X,
     C' RHOMBOHEDRAL (R)',/,$,4X,' ENTER TYPE (DEFAULT=P):  ')
      READ(5,190)SYM
 190  FORMAT(A1)
	IF(SYM.EQ.' ') SYM='P'
      WRITE(7,200)
 200  FORMAT(/,$,' INPUT N',
     CX,'WHERE N SETS THE RANGE -N,-N,-N TO N,N,N:  ')
      READ(5,210)INN
 210  FORMAT(I3) 
       N=1
 230  DO 240 I=1,(INN*2)+1
      II=I-(INN+1)
      DO 240 J=1,(INN*2)+1
      JJ=J-(INN+1)
      DO 240 K=1,(INN*2)+1
      KK=K-(INN+1)
      IF(((II.EQ.0).AND.(JJ.EQ.0)).AND.(KK.EQ.0))GO TO 240
      X(N)=II
      Y(N)=JJ
      Z(N)=KK
      IH1(N)=II
      IK1(N)=JJ
      IL1(N)=KK
      N=N+1
 240  CONTINUE
      NNN=N-1
      NN=1
      DO 250 I=1,NNN
      IX=X(I)
      IY=Y(I)
      IZ=Z(I)
C
C	CHECK FOR FORBIDDEN REFLECTIONS
C
	CALL CRYSTAL(SYM,IX,IY,IZ,IOK)
C
C
      IF(IOK.EQ.1)GO TO 250
      X(NN)=X(I)
      Y(NN)=Y(I)
      Z(NN)=Z(I)
      IH1(NN)=IH1(I)
      IK1(NN)=IK1(I)
      IL1(NN)=IL1(I)
      NN=NN+1
  250 CONTINUE
      NNN=NN-1
      DO 260 NN=1,NNN
      X(NN)=X(NN)*AST
      Y(NN)=Y(NN)*BST
      Z(NN)=Z(NN)*CST
      X(NN)=X(NN)+(Y(NN))*CGAMST+(Z(NN))*CBETST
      Y(NN)=(Y(NN))*SGAMST+(Z(NN))*(CALST-CBETST*CGAMST)
     C/SGAMST
      Z(NN)=(Z(NN))*SQRT(1-CBETST**2-(CALST**2-2.*CALST*
     CCBETST*CGAMST+CBETST**2*CGAMST**2)/
     C(SGAMST**2))
      R(NN)=SQRT(X(NN)**2+Y(NN)**2+Z(NN)**2)
 260  CONTINUE
	NNN = NNN + 1
	R(NNN) = 5000
       	DO 270 J = 1,NNN
	INDEX(J) = J
270	CONTINUE
	WRITE (1,280)
280	FORMAT (' SORTING...')
	CALL SORT(R,INDEX,NNN)
290   WRITE(7,300)
300   FORMAT(/,' ANY ADDITIONAL FORBIDDEN REFLECTIONS? [Y/N]',/,$,
     C' (CONSULT INTERNATIONAL TABLES PART A):  ') 
      READ(5,310)SW
310   FORMAT(A4)
      IF(SW.EQ.XNO)GO TO 320
      IF(SW.EQ.YES)GO TO 330
      GO TO 290
  330 WRITE(7,340)
  340 FORMAT(/,' 1-ENTER COEFFICIENTS OR ',/,
     C' 2-SEARCH EACH RECIPROCAL LATTICE POINT')
      READ(5,350)IO
  350 FORMAT(I5)
      GO TO (360,320),IO
      GO TO 330
  360 WRITE(7,370)
  370 FORMAT(/,' ENTER COEFFICIENTS A,B,C,D,E IN ORDER...',/,
     C5X,'A * H  +  B * K  +  C * L  =  D * N + E',/)
      READ(5,380)IC1,IC2,IC3,IC4,IC5
  380 FORMAT(5I5)
      DO 390 I=1,NNN
      IM=IH1(INDEX(I))
      IN=IK1(INDEX(I))
      IP=IL1(INDEX(I))
      CALL ADDCON(IC1,IC2,IC3,IC4,IC5,IM,IN,IP,IBID(I))
  390 CONTINUE
      GO TO 290
  320 ITTT=NNN-1
      WRITE(6,400)ITTT
  400 FORMAT(2X,I6)
      WRITE(6,410)A0,B0,C0,ALPHA,BETA,GAMMA,REF
  410 FORMAT(6F13.6,20A4)
      WRITE(6,415)COSALP,COSBET,COSGAM
      WRITE(6,415)SINALP,SINBET,SINGAM
      WRITE(6,415)AST,BST,CST
      WRITE(6,415)CALST,CBETST,CGAMST
  415 FORMAT(3F13.6)
      WRITE(6,417)SYM
  417 FORMAT(4X,A1)
      DO 420 I=1,NNN
      IF(SW.EQ.XNO)GO TO 430
      IF(IBID(I).EQ.1)GO TO 430
      IF(I.EQ.1)GO TO 440
      IF(R(I).NE.R(I-1))GO TO 440
      IBID(I)=IBID(I-1)
      GO TO 430
  440 WRITE(7,450)I,IH1(INDEX(I)),IK1(INDEX(I)),IL1(INDEX(I))
  450 FORMAT(/,$,'+',I4,' - ',3I5,3X,'FORBIDDEN?  ')
      READ(5,460)XMARK
  460 FORMAT(A4)
      IF((XMARK.NE.YES).AND.(XMARK.NE.XNO))GO TO 440
      IF(XMARK.EQ.YES)IBID(I)=1
      IF(XMARK.EQ.XNO)IBID(I)=0
  430 CONTINUE
      WRITE(6,470)R(INDEX(I)),IH1(INDEX(I)),IK1(INDEX(I)),
     CIL1(INDEX(I)),X(INDEX(I)),
     CY(INDEX(I)),Z(INDEX(I)),IBID(INDEX(I))
  470 FORMAT(1PE13.4,3I2,3E13.6,I4)
  420 CONTINUE
  550 CONTINUE
  500 CONTINUE
	CLOSE(UNIT=6,DISPOSE='SAVE')
      END
C
C***********************************************************************
C	THIS ROUTINE PRINTS THE PHASE FILE.
C***********************************************************************
C
C
C
C
      SUBROUTINE GPRINT(XXX,IPASSF)
      CHARACTER*1 XXX
      INTEGER*4 FN(4)
      DIMENSION REF(20)
      DIMENSION R(1460),X(1460),Y(1460),Z(1460)
      DIMENSION IH(1460),IJ(1460),IK(1460)
      DIMENSION IBID(1460)
      DATA FN(1),FN(2),FN(3),FN(4)/'    ','    ','.DAT',0/
      WRITE(7,10)
 10   FORMAT(/,$,' FILENAME?  ')
      READ(5,20)FN(1),FN(2)
 20   FORMAT(2A4)
      OPEN(6,FILE=FN,STATUS='OLD',FORM='FORMATTED',RECL=180,
     CRECORDTYPE='VARIABLE',ERR=90)
C
C     IUNIT=1
C
	
      IF(XXX.EQ.'B') IUNIT=1
      IF(XXX.EQ.'C') IUNIT=2
C
C
      READ(6,30)NNN
 30   FORMAT(2X,I6)
      WRITE(IUNIT,35)FN(1),FN(2)
 35   FORMAT(/,' PHASE = ',2A4)
      WRITE(IUNIT,40)NNN
 40   FORMAT(/,X,I6,'  G VECTORS IN THE FILE ')
      READ(6,50)A0,B0,C0,ALPHA,BETA,GAMMA,REF
 50   FORMAT(6F13.6,20A4)
      READ(6,60)COSALP,COSBET,COSGAM
      READ(6,60)SINALP,SINBET,SINGAM
      READ(6,60)AST,BST,CST
      READ(6,60)CALST,CBETST,CGAMST
 60   FORMAT(3F13.6)    
      READ(6,65)SYM
 65   FORMAT(4X,A1)
      WRITE(IUNIT,70)(REF(I),I=1,20)
 70   FORMAT(/,' REFERENCE:',/,1X,20A4)
      WRITE(IUNIT,80)A0,B0,C0,ALPHA,BETA,GAMMA
 80   FORMAT(/,10X,'A',9X,'B',9X,'C',5X,'ALPHA',6X,'BETA',
     C5X,'GAMMA',/,1X,3F10.4,3F10.1)
C
C
      WRITE(IUNIT,82)SINALP,SINBET,SINGAM,COSALP,COSBET,COSGAM
00082 FORMAT(/,5X,'SINALP',4X,'SINBET',4X,'SINGAM',4X,'COSALP',
     C4X,'COSBET',4X,'COSGAM',/,X,6F10.4)
C
C
      WRITE(IUNIT,85)AST,BST,CST,CALST,CBETST,CGAMST
 85   FORMAT(/,9X,'A*',8X,'B*',8X,'C*',4X,'CALST',4X,'CBETST',
     C4X,'CGAMST',/,X,6F10.4)
      WRITE(IUNIT,87)SYM
 87   FORMAT(/,X,A1,' LATTICE',//,9X,'G MODULUS  H K L',5X,'H MODULUS',
     C5X,'K MODULUS',5X,'L MODULUS FBN')
      DO 90 J=1,NNN
      READ(6,100)R(J),IH(J),IJ(J),IK(J),X(J),Y(J),Z(J),IBID(J)
  100 FORMAT(1PE13.6,3I2,3E13.6,I4)
      WRITE(IUNIT,110)J,R(J),IH(J),IJ(J),IK(J),X(J),Y(J),Z(J),IBID(J)
  110 FORMAT(X,I3,X,1PE13.6,X,3I2,X,E13.6,X,E13.6,X,E13.6,I4)
  90  CONTINUE
C
C
      CLOSE(UNIT=6,DISPOSE='SAVE')
      IF(IUNIT.EQ.2) CLOSE(2,DISP='PRINT/DELETE')
C
C	
      RETURN
      END
C
C***********************************************************************
C	THIS ROUTINE ASKS FOR ALL THE INFO FOR PLOTTING AND PLOTS THE
C	 ZERO LAYER IF REQUIRED.
C***********************************************************************
C
C
C
C
	SUBROUTINE ZERO(MENU_CHOICE,ITERATIONS_THRU)
C
C
C
C
C THIS ROUTINE ASKS FOR ALL THE DATA FOR THE ZERO AND HOLZ PLOTTING
C IT ACCESSES A DATA FILE "PHASE".DAT FOR A0,B0,C0,ALPHA,BETA,GAMMA
C & GVECTORS THAT IT NEEDS . THE FILE MUST HAVE BEEN CREATED BY THE 
C ROUTINE GVECTOR. THE INFORMATION ON THE CRYSTAL IS STORED IN A COMMON
C BLOCK SO IT CAN BE ACCESSED BY THE HOLZ SECTION 
C
C
C
C
C
      CHARACTER*1 REPEAT_ANSWER,CLANSWER
      CHARACTER*1 HARDCOPY_ANSWER,MENU_CHOICE,PHASE_CHANGE,SYM
      CHARACTER*1 PLOT_CHOICE,PRINTER_ANSWER,COLOUR_CHANGE,TEK_COPY_ANSWER
      INTEGER*4 FN(4)
      DIMENSION IHOLZ(5),IAXIS(3)
      DIMENSION DAT(3),PC(3,3)
      DIMENSION REF(20)
      DIMENSION IH(1200),IJ(1200),IK(1200)
      DIMENSION RIH(1200),RIJ(1200),RIK(1200)
      DIMENSION IBID(1200)
      INTEGER IH1,IJ1,IK1,IH2,IJ2,IK2
      INTEGER FBIA,FBIB
      PARAMETER (PI = 3.14159)
C     DATA D,E,F/'D','E','F'/
C     DATA XZ,B,HO/'Z   ','B   ','HO  '/
C     DATA YES,XNO/'Y','N'/
C
C
C	COMMON BLOCKS FOR HOLZ
C
      COMMON/CHARACTERS/COLOUR_CHANGE,HARDCOPY_ANSWER
      COMMON/IBASVEC/IH1,IJ1,IK1,IH2,IJ2,IK2
      COMMON/BASVEC/RIH1,RIJ1,RIK1,RIH2,RIJ2,RIK2
      COMMON/LATTICE/A0,B0,C0,COSALP,COSBET,COSGAM
      COMMON/SINE/SINALP,SINBET,SINGAM
      COMMON/RELATT/AST,BST,CST,CALPST,CBETST,CGAMST
      COMMON/IZONE/IU,IV,IW
      COMMON/ZONE/RIU,RIV,RIW
      COMMON/PARAM/SYM,IHOLZ,INN,WAVE,GGMAX,PRINTER_ANSWER,PLOT_CHOICE
      COMMON/AXES/GX,GY
C
C
C COMMON BLOCKS FOR TERMIN
C
      COMMON /TERMIN/ ITERM,IBAUD,IPLOT,ICOLOR,IMODE,IHARD,ILP(3)
	COMMON /PLOTTER/ ITEMPORARY
C
C
      DATA FN(1),FN(2),FN(3),FN(4)/'    ','    ','.DAT',0/
C---------------------------------------------------------------------
C	THE NEXT FEW LINES SET UP THE TERMINAL FOR PLOTTING USING
C	NESTOR ZALUZEC'S GRAPHICS PACKAGE.  THIS PROGRAM WILL PLOT ON 
C	A TEKTRONIX 4010 TYPE TERMINAL OR A SUITABLE EMULATOR.  DO NOT
C	CHOOSE ANY OF THE HARDCOPY UNITS FOR THE BASE TERMINAL SINCE
C	YOU WILL GET GARBAGE PLOTS.
C
      CALL TERMIN
C
C	SCREEN CENTRE APPROX FOR PATTERN CENTRE
C
      XOFF=512.
      YOFF=390.
C--------------------------------------------------------------------
      CLFACTOR=1.0	!INITIAL VALUE.  USED TO ADJUST CAMERA LENGTH.
C
C
C	NOW STARTS THE HEAVILY INTERACTIVE PART OF THE PROGRAM FOR 
C	READING THE OPERATOR'S DESIRED PARAMETERS.
C
C
C	IF FIRST PASS, SET PLOT BY PARAMETER FROM MENU.
C
      IF(ITERATIONS_THRU.EQ.0) THEN
      IF(MENU_CHOICE.EQ.'D') PLOT_CHOICE='Z'
      IF(MENU_CHOICE.EQ.'E') PLOT_CHOICE='H'
      IF(MENU_CHOICE.EQ.'F') PLOT_CHOICE='B'
      GO TO 00030
      ENDIF
C
C
C	IF NOT FIRST PASS, ASK FOR TYPE OF PLOT.
C
00005 WRITE(7,00010)
00010 FORMAT(/,$,' DO YOU WANT ZERO LAYER(Z),HOLZ(H), OR BOTH(B)?  ')
      READ(5,'(A)',ERR=00005)PLOT_CHOICE
      IF((PLOT_CHOICE.NE.'Z').AND.(PLOT_CHOICE.NE.'H').AND.
     C(PLOT_CHOICE.NE.'B')) GO TO 00005
C
C
C	PRINTER OUTPUT? THIS WILL PRINT INFORMATION FROM
C	THE PHASE FILE, DATA ENTERED FROM THE TERMINAL,
C	LABELS OF HOLZ LINES, (AND ZONE AXIS X AND Y DIRECTIONS).
C
00030 WRITE(7,00035)
00035 FORMAT(/,$,' DO YOU WANT PRINTER OUTPUT &
     C HOLZ LINE LABELS? [N]  ')
      READ(5,'(A)',ERR=00030)PRINTER_ANSWER
      IF(PRINTER_ANSWER.NE.'Y') PRINTER_ANSWER='N'
C
C
C IF THE PRINTER OUTPUT IS REQUESTED AND THE USER HAS A COLOUR TERMINAL
C SUPPORTED BY NGRAPH, THEN IT IS ADVANTAGEOUS IN THE PLOTTING OF HOLZ
C LINES THAT THE TERMINAL COLOUR CHANGES EACH TIME A LINE IS PLOTTED.
C IT LOOKS A MESS BUT IT EASES THE IDENTIFICATION OF THE LINES.
C ASK THE USER IF HE WANTS COLOUR CHANGE.
C
      IF((PRINTER_ANSWER.EQ.'Y').AND.(PLOT_CHOICE.EQ.'H').AND.
     C((ITERM.EQ.3).OR.(ITERM.EQ.4).OR.(ITERM.EQ.8).OR.
     C(ITERM.EQ.10))) THEN
      WRITE(7,40014)
40014 FORMAT(/,$,' DO YOU WANT THE TERMINAL MULTI-COLOURED PLOT? [N]  ')
      READ(5,'(A)')COLOUR_CHANGE
      IF(COLOUR_CHANGE.NE.'Y') COLOUR_CHANGE='N'
      ENDIF
C
C
C   IF THE HP IS THE HARD COPY UNIT, THEN ASK IF IT IS TO BE USED.
C
      IF(IHARD.EQ.5) THEN
40020 WRITE(7,40030)
40030 FORMAT(/,' DO YOU WANT',/,
     C13X,'T TERMINAL PLOT ONLY',/,
     C13X,'H HP PLOT ONLY      ',/,
     C13X,'B BOTH              ',/,$
     C13X'(DEFAULT= T):          ')
40040 READ(5,'(A)')HARDCOPY_ANSWER
	IF(HARDCOPY_ANSWER.EQ.' ') HARDCOPY_ANSWER='T'
	ENDIF
C
C
C	SET A VALUE TO DETERMINE WHETHER THE PHASE FILE IS OPEN
C	AND IF IT NEEDS TO BE CHANGED.	ASK WHICH FILE IS WANTED:
C	OPEN A NEW ONE OR CONTINUE WITH THE PRESENT ONE.
C
	IF(ITERATIONS_THRU.GT.0) THEN 
88883	WRITE(7,88888)
88888	FORMAT(/,$,' ANOTHER PHASE FILE ? [N]  ')
	READ(5,'(A)',ERR=88883)PHASE_CHANGE
	IF(PHASE_CHANGE.NE.'Y') PHASE_CHANGE='N'
	ENDIF
	IF((ITERATIONS_THRU.EQ.0).OR.(PHASE_CHANGE.EQ.'Y')) THEN
00050 		  WRITE(7,00060)
00060	          FORMAT(/,$,' FILENAME?  ')
		  READ(5,00070,ERR=00050)FN(1),FN(2)
00070             FORMAT(2A4)
	ENDIF
C
C
C  READS IN THEN WRITES SOME OF THE DATA IN THE FILE PHASE.DAT 
C  TO THE TERMINAL AS A CHECK ON THE DATA.
C  IF SECOND OR MORE PASS-THRU, OMIT THE WRITE-OUT.
C
00075 OPEN(6,FILE=FN,STATUS='OLD',FORM='FORMATTED',
     CRECL=180,RECORDTYPE='VARIABLE',ERR=00450)
C
      READ(6,00080)NNN
00080 FORMAT(2X,I6)
      READ(6,00100)A0,B0,C0,ALPHA,BETA,GAMMA,REF
00100 FORMAT(6F13.6,20A4)
      READ(6,00110)COSALP,COSBET,COSGAM
C
C
C	MOD ADDED 18TH FEB 1986. CHANGE ALL DATA FILES
C	CREATED BEFORE THIS.
C
      READ(6,00110)SINALP,SINBET,SINGAM
C
      READ(6,00110)AST,BST,CST
      READ(6,00110)CALPST,CBETST,CGAMST
00110 FORMAT(3F13.6)
      READ(6,00120)SYM
00120 FORMAT(4X,A1)
C
C
C	THIS IS THE SECTION THAT WRITES PHASE INFO TO TERMINAL.
C
      IF(PHASE_CHANGE.EQ.'N') GO TO 00141
      WRITE(7,00090)NNN
00090 FORMAT(/,X,I6,' G-VECTORS IN THIS FILE')
      WRITE(7,00130)(REF(I),I=1,20)
00130 FORMAT(' REFERENCE:',/,1X,20A4)
      WRITE(7,00140)A0,B0,C0,ALPHA,BETA,GAMMA
00140 FORMAT(1X,9X,'A',9X,'B',9X,'C',5X,'ALPHA',6X,'BETA',
     C5X,'GAMMA',/,1X,3F10.4,3F10.1,/,/)
      PAUSE 'Enter CONTinue to resume.'
C
C
00141 CONTINUE
C
C
C MORE DATA INPUT . THE CAMERA LENGTH AND C2 APERTURE ARE SCALED TO GIVE 
C THE CORRECT SCALING OF THE PATTERNS AS THEY WOULD APPEAR IN THE MICROSCOPE.
C IN HOLZ MODE THE ZERO LAYER DISC IS MUCH MAGNIFIED TO SHOW MAXIMUM DETAIL.
C
00149 WRITE(7,00150)
00150 FORMAT(/,$,' ZONE AXIS?  ENTER U,V,W:  ')
      READ(5,00170,ERR=00149)IU,IV,IW
      IF(PLOT_CHOICE.NE.'H') THEN
	WRITE(7,00160)
00160   FORMAT(/,$,' NUMBER OF REFLECTIONS?  ')
        READ(5,00171,ERR=00149)IMAX
00171   FORMAT(I3)
      ENDIF
00170 FORMAT(4I2)
C
C
C	CONVERT TO REAL
C
      RIU=FLOAT(IU)
      RIV=FLOAT(IV)
      RIW=FLOAT(IW)
C
C
00179 WRITE(7,00180)
00180 FORMAT(/,$,' SECOND CONDENSER APERTURE? (50-600 MICRON)  ')
      READ(5,00190,ERR=179)C2AP
00190 FORMAT(F10.0)
      C2DIA=C2AP*0.458*CLFACTOR		! 0.458 FROM MEASURING NEGS
      MAG=350*CLFACTOR			! CAMERA LENGTH
      IF(PLOT_CHOICE.EQ.'Z') GO TO 00260
00199 WRITE(7,00200)
00200 FORMAT(/,$,' ENTER ACCELERATING VOLTAGE IN KV:  ')
      READ(5,00210,ERR=199)VVV
00210 FORMAT(F10.0)
C
C
C ELECTRON WAVELENGTH (SEE HIRSCH, ET AL., PAGE 85).  THIS MUST BE ADJUSTED
C USING A KNOWN CRYSTAL.  THE PROGRAM ASSUMES THE KINEMATICAL APPROXIMATION.
C THE VOLTAGE IS TREATED AS AN ADJUSTABLE FREE PARAMETER.
C
      VVV=VVV*(10**3)
      WAVE=VVV*(1+9.788*(10.0**-7)*VVV)
      WAVE=12.26/SQRT(WAVE) 
00219 WRITE(7,00220)
00220 FORMAT(/,' INPUT N, WHERE N SETS THE RANGE OF G-VECTORS',/,$,
     C' FROM (-N,-N,-N) TO (N,N,N):  ')
      READ(5,00230,ERR=00219)INN
00230 FORMAT(I2)
C
C
C GGMAX IS THE MAX MODULUS OF THE HOLZ REFLECTION. IT CAN BE SET TO LIMIT THE 
C SEARCH OF THE HOLZ LINES SO THAT LINES THAT WOULD NOT EVER BE VISIBLE CAN
C BE IGNORED.
C
      IHOLZ(1)=0
      IHOLZ(2)=0
      IHOLZ(3)=0
      IHOLZ(4)=0
      IHOLZ(5)=0
C
C
00239 WRITE(7,00240)
00240 FORMAT(/,' ENTER ORDER(S) OF DESIRED HOLZ REFLECTIONS,',/,
     C' WHERE 1=FOLZ, 2=SOLZ, 3=TOLZ, 4=40LZ, 5=5OLZ, ETC.',/,
     C' UP TO 5 VALUES PERMISSABLE (e.g. 1,2,3,4,5 or
     C 1,2,0,0,0 etc.).')
      READ(5,00250,ERR=239)IHOLZ(1),IHOLZ(2),IHOLZ(3),IHOLZ(4),
     CIHOLZ(5)
00250 FORMAT(5I2)
      WRITE(7,252)
00252 FORMAT(/,$,' ENTER MAXIMUM MODULUS OF G (GGMAX):  ')
      READ(5,251)GGMAX
00251 FORMAT(F10.0)
C
C
00260 CONTINUE
C
C
C	SET UP GRAPHICS ON TERMINAL AND CLEAR SCREEN
C	BEEP AND SET COLOUR.
C
       CALL ERASE
       CALL COLOR(1)
C
C
C DATA IS READ IN FROM PHASE.DAT TO PLOT THE ZERO LAYER DISCS.
C FIRST, TWO DIRECTIONS ARE FOUND THAT ARE ORTHOGONAL SO THAT
C THEY CAN BE USED AS AXIS DIRECTIONS FOR THE PLOTTING.
C
C THE FIRST AXIS IS THE FIRST VALUE OF G THAT IS PERPENDICULAR
C TO [UVW] (I.E., G.[UVW]=0);  THIS AXIS IS GX.  THE VALUES OF G 
C ARE STORED IN ASCENDING ORDER IN THE PHASE FILE, SO GX IS THE
C SHORTEST VECTOR.  THE OTHER VECTOR IS FOUND BY GX x [UVW].  GX IS
C CONVERTED TO REAL SPACE BY USING THE MATRIX COURTESY ROGER VINCENT,
C U. OF BRISTOL, 1984. 
C
      DO 00270 J=1,NNN
      READ(6,00280)DUM0,IH(J),IJ(J),IK(J),DUM1,DUM2,DUM3,IBID(J)
00280 FORMAT(1PE13.4,3I2,3E13.6,I4)
      IF(IU*IH(J)+IV*IJ(J)+IW*IK(J).NE.0) GO TO 00270
      IH1=IH(J)
      IJ1=IJ(J)
      IK1=IK(J)
      JJ=J	!INDEX FOR FIRST G-VECTOR.
C
C	CONVERT GX TO REAL INDICES TO GET GY AXIS.
C	GET ALPST, ETC FOR LATER USE.
C
      RIH1=FLOAT(IH1)
      RIJ1=FLOAT(IJ1)
      RIK1=FLOAT(IK1)
      FBIA=IBID(J)
      ALPST=ACOS(CALPST)
      BETST=ACOS(CBETST)
      GAMST=ACOS(CGAMST)
C
C
C	WORK OUT THE VOLUME OF THE UNIT CELL.
C
      ULOV=A0*B0*C0
      VOLUME=ULOV*SQRT(1-COSALP**2-COSBET**2-COSGAM**2+2
     C*COSALP*COSBET*COSGAM)
C
C
C	THIS IS ESSENTIALLY THE MATRIX NEEDED TO CONVERT
C	FROM RECIPROCAL SPACE TO REAL SPACE
C
      SSS=(A0*B0*C0/VOLUME)**2
      PC(1,1)=(SINALP/A0)**2
      PC(1,2)=(COSALP*COSBET-COSGAM)/(A0*B0)
      PC(1,3)=(COSALP*COSGAM-COSBET)/(A0*C0)
      PC(2,1)=PC(1,2)
      PC(2,2)=(SINBET/B0)**2
      PC(2,3)=(COSBET*COSGAM-COSALP)/(B0*C0)
      PC(3,1)=PC(1,3)
      PC(3,2)=PC(2,3)
      PC(3,3)=(SINGAM/C0)**2
C
C
C	THIS IS THE CONVERSION
C
      RRIH1=SSS*(PC(1,1)*RIH1+PC(1,2)*RIJ1+PC(1,3)*RIK1)
      RRIJ1=SSS*(PC(2,1)*RIH1+PC(2,2)*RIJ1+PC(2,3)*RIK1)
      RRIK1=SSS*(PC(3,1)*RIH1+PC(3,2)*RIJ1+PC(3,3)*RIK1)
C
      RIH2=RIV*RRIK1-RRIJ1*RIW
      RIJ2=RRIH1*RIW-RIU*RRIK1
      RIK2=RIU*RRIJ1-RRIH1*RIV
      IH2=INT(RIH2)
      IJ2=INT(RIJ2)
      IK2=INT(RIK2)
C
      CALL DOT(RIH1,RIJ1,RIK1,RIH1,RIJ1,RIK1,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GX)
      CALL DOT(RIH2,RIJ2,RIK2,RIH2,RIJ2,RIK2,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GY)
      GX=SQRT(GX)     
      GY=SQRT(GY)
      GO TO 00290
00270 CONTINUE
C
C
00290 CONTINUE
C
C
C THIS IS THE PRINT-OUT IF THE LINE PRINTER OPTION IS SELECTED.
C	NOTE THAT IT IS DIRECTED TO LOGICAL UNIT 2.
C	HENCE A PRINT OUT FILE MAY BE DEFINED IF REQUIRED.
C	PRINT STATEMENTS FOR HOLZ HAVE BEEN MOVED TO SUBROUTINE HOLZ.
C	MORE OUTPUT OCCURS AS THE ZERO LAYER DISCS ARE PLOTTED.
C
      IF(PRINTER_ANSWER.EQ.'Y') THEN
      WRITE(2,00300)FN(1),FN(2)
00300 FORMAT(' PHASE = ',2A4)
      WRITE(2,00130)(REF(I),I=1,20)
      WRITE(2,00140)A0,B0,C0,ALPHA,BETA,GAMMA
      WRITE(2,00311)IU,IV,IW
00311 FORMAT(' ZONE AXIS=',3I3)
      WRITE(2,00320)MAG,C2AP,C2DIA,VVV/1000,WAVE
00320 FORMAT(/,' CAMERA LENGTH =',I5,'mm',/,' C2 APERTURE =',F6.0,
     C'um',4X,'(C2 DIAMETER =',F7.2,')',/,' VOLTAGE =',F9.4,
     C'kV    WAVELENGTH =',F9.6,' Angstroms')
      ENDIF
C
C
C IF HOLZ ONLY THEN SKIP TO HOLZ ROUTINE AND THEN TO THE END OF THIS 
C ROUTINE TO STOP OR DO FURTHER PLOTS
C
      IF(PLOT_CHOICE.EQ.'H') THEN
	CALL HOLZ(C2AP)
        GO TO 00420
      ENDIF
C
C
C PLOTTING THE DIRECT DISC
C
      IFLAG=0
      IF((IHARD.NE.5).OR.((HARDCOPY_ANSWER.EQ.'B').OR.
     C(HARDCOPY_ANSWER.EQ.'T')))  THEN
      CALL STRTCRT
      CALL ERASE
      CALL SYMBOL(XOFF,YOFF,C2DIA*2,8)
      ENDIF
C
      IF((IHARD.EQ.5).AND.(HARDCOPY_ANSWER.NE.'T')) THEN
      CALL SETHP
      CALL STRTHP
      CALL SYMBOL(XOFF,YOFF,C2DIA*2,8)
      CALL DELAY(20)
      CALL RESETERMINAL
      ENDIF
C
C
C NOW THE DISCS ARE PLOTTED UNTIL IFLAG EQUALS THE NUMBER
C SPECIFIED BY IMAX.
C
      BACKSPACE 6	!REPOSITION PHASE.DAT TO PRECEEDING RECORD.
      DO 380 J=JJ,NNN
      READ(6,00280)DUM0,IH(J),IJ(J),IK(J),DUM1,DUM2,DUM3,IBID(J)
      IF(IU*IH(J)+IV*IJ(J)+IW*IK(J).NE.0)GO TO 380
      RIH(J)=FLOAT(IH(J))
      RIJ(J)=FLOAT(IJ(J))
      RIK(J)=FLOAT(IK(J))
C
      CALL DOT(RIH(J),RIJ(J),RIK(J),RIH(J),RIJ(J),RIK(J),
     CAST,BST,CST,CALPST,CBETST,CGAMST,GG)
      GGMOD=SQRT(ABS(GG))
      CALL DOT(RIH(J),RIJ(J),RIK(J),RIH1,RIJ1,RIK1,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GGX)
      CALL DOT(RIH(J),RIJ(J),RIK(J),RIH2,RIJ2,RIK2,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GGY)
C
      DX=GGX/GX
      DY=GGY/GY
      X1=XOFF+MAG*DX
      Y1=YOFF+MAG*DY
C
C
C THE ALLOWED SPOTS ARE OPEN CIRCLES & FORBIDDEN REFLECTIONS ARE STARS.
C
C FIRST, THE TERMINAL PLOT.
C
      IF((IHARD.NE.5).OR.((HARDCOPY_ANSWER.EQ.'B').OR.
     C(HARDCOPY_ANSWER.EQ.'T')))  THEN
      IF(IBID(J).EQ.0) CALL SYMBOL(X1,Y1,C2DIA*2,8)
      IF(IBID(J).EQ.1) CALL SYMBOL(X1,Y1,C2DIA*2,7)
C
C LABEL THE FIRST TWO DISCS AND RECORD THE FIRST TWO G-VECTORS ON THE
C PRINTER, IF SELECTED.
C
      IF((IFLAG.EQ.0).OR.(IFLAG.EQ.1)) THEN
      CALL COLOR(2)
      CALL MOVE(X1,Y1)
      IF((SYM.EQ.'H').OR.(SYM.EQ.'R')) THEN
      WRITE(7,00360)IH(J),IJ(J),-(IH(J)+IJ(J)),IK(J)
00360 FORMAT('+',4I2)
      IF((IFLAG.EQ.1).AND.(PRINTER_ANSWER.EQ.'Y')) WRITE(2,374)IH(JJ),
     CIJ(JJ),-(IH(JJ)+IJ(JJ)),IK(JJ),IH(J),IJ(J),-(IH(J)+IJ(J)),IK(J)
00374 FORMAT(X,' FIRST G-VECTOR =',4I3,/
     C,X,' SECOND G-VECTOR =',4I3)
      ENDIF
      IF((SYM.NE.'H').AND.(SYM.NE.'R')) THEN
      WRITE(7,00370)IH(J),IJ(J),IK(J)
00370 FORMAT('+',3I2)
      IF((IFLAG.EQ.1).AND.(PRINTER_ANSWER.EQ.'Y')) WRITE(2,376)IH(JJ),
     CIJ(JJ),IK(JJ),IH(J),IJ(J),IK(J)
00376 FORMAT(/,' FIRST G-VECTOR =',3I3,6X,'SECOND G-VECTOR =',3I3)
      ENDIF
      CALL COLOR(1)
      ENDIF
      ENDIF
C
C NOW THE HP PLOT, IF SELECTED.
C 
      IF((IHARD.EQ.5).AND.(HARDCOPY_ANSWER.NE.'T')) THEN
      CALL SETHP
      IF(IBID(J).EQ.0) CALL SYMBOL(X1,Y1,C2DIA*2,8)
      IF(IBID(J).EQ.1) CALL SYMBOL(X1,Y1,C2DIA*2,7)
C
C LABEL THE FIRST TWO DISCS.
C
      IF((IFLAG.EQ.0).OR.(IFLAG.EQ.1)) THEN
      CALL CHP7470(1)
      CALL MOVE(X1,Y1)
      IF((SYM.NE.'H').AND.(SYM.NE.'R')) WRITE(80,385)IH(J),IJ(J),IK(J)
385   FORMAT(' CP -3.,-.5; LB',3I2)
      IF((SYM.EQ.'H').OR.(SYM.EQ.'R')) WRITE(80,386)IH(J),IJ(J),
     C-(IH(J)+IJ(J)),IK(J)
386   FORMAT(' CP -3.,-.5; LB',4I2)
      CALL CHP7470(2)
      ENDIF
C
      CALL DELAY(20)
      CALL RESETERMINAL
      ENDIF
C
C
      IFLAG=IFLAG+1
      IF(IFLAG.EQ.IMAX) GO TO 00390
00380 CONTINUE
00390 CONTINUE
C
C
C IF THE HOLZ LINES NEED TO BE SEEN IN RELATIONSHIP TO THE ZERO LAYER 
C THEN '(B)OTH' HAS BEEN SELECTED AND THE HOLZ ROUTINE IS CALLED
C
      IF(PLOT_CHOICE.EQ.'B') CALL HOLZ(C2AP)
C
C
C LABELS TERMINAL PLOT WITH THE DATE, THE PHASE NAME (I.E. THE NAME
C OF THE DATA FILE), AND THE ZONE AXIS.
C
00420 CALL DATE(DAT)
      WRITE(7,00400)DAT
00400 FORMAT(X,3A4)
      WRITE(7,00410)FN(1),FN(2)
00410 FORMAT(/,' ',2A4)
      WRITE(7,405)IU,IV,IW
405   FORMAT(/,' ZONE AXIS= ',3I3)
C
C----------------------------------------------------------------------
C	HARDCOPY OPTION
C	THIS ONLY RUNS IF THE TERMINAL IS A TEK 4100 SERIES
C	WITH A COLOUR SCREEN COPIER
C
C
70000   IF(ITERM.EQ.10) THEN
99991	WRITE(7,99998)
99998	FORMAT($,' HARDCOPY? [N]  ')
	READ(5,'(A)',ERR=99991)TEK_COPY_ANSWER
	IF(TEK_COPY_ANSWER.EQ.' ') TEK_COPY_ANSWER ='N'
C
C
C	SCREEN DUMP TO TEK 4105/7/9
C
C
	IF((TEK_COPY_ANSWER.EQ.'Y')) THEN
99993	WRITE(7,99996)
99996	FORMAT(/,$,' S OR L? [S]  ')
	READ(5,'(A)',ERR=99993)COPYSIZE
	IF(COPYSIZE.EQ.' ') COPYSIZE='S'
	CALL HCSCRN(COPYSIZE)
	ENDIF
	ENDIF
C----------------------------------------------------
C
10444   CONTINUE
C
C
C IF ANOTHER PLOT IS DESIRED THE THE SCREEN IS CLEARED AND THE ROUTINE 
C RESTARTED.  IF NOT, THEN THE PROGRAM RETURNS TO THE MAIN MENU.
C
00425 WRITE(7,00430)
00430 FORMAT(/,$,' MORE? [Y]  ')
      READ(5,'(A)',ERR=00425)REPEAT_ANSWER 
      IF(REPEAT_ANSWER .EQ.' ') REPEAT_ANSWER ='Y'
	IF(REPEAT_ANSWER .EQ.'N') THEN
		CALL ERASE
                CLOSE(UNIT=6,DISPOSE='SAVE')
                CALL ENDCRT
		CLOSE(2,DISP='PRINT/DELETE')
		RETURN
		ENDIF
        IF(REPEAT_ANSWER .EQ.'Y') THEN 
                CALL ERASE
                CLOSE(UNIT=6,DISPOSE='SAVE')
	        CALL ENDCRT
                ITERATIONS_THRU=ITERATIONS_THRU+1
C
C	CHANGE THE CAMERA LENGTH?
C
		WRITE(7,500)
500		FORMAT(/,$,' CAMERA LENGTH OK (Y/N)?  ')
		READ(7,'(A)')CLANSWER
		IF(CLANSWER.EQ.'N') THEN
		WRITE(7,501)
501		FORMAT(/,$,' ENTER CAMERA LENGTH FACTOR:  ')
		READ(7,*)CLFACTOR_NEW
		CLFACTOR=CLFACTOR*CLFACTOR_NEW
		CLOSE(2,DISP='DELETE')
		GO TO 00005
		ENDIF
	CLOSE(2,DISP='PRINT/DELETE')
	GO TO 00005 
	ENDIF
      IF((REPEAT_ANSWER .NE.'Y').AND.(REPEAT_ANSWER .NE.'N'))GO TO 00425
00450 RETURN
      END
C
C***********************************************************************
C	THIS ROUTINE PLOTS THE HOLZ LINES.
C***********************************************************************
C
C
C
      SUBROUTINE HOLZ(C2AP)
C
C
C
      DIMENSION X(2),Y(2)
      DIMENSION RIHOLZ(5)
      DIMENSION IHOLZ(5),ILAB(3)
      INTEGER*4 SEQUENCE
      CHARACTER*1 HARDCOPY_ANSWER,MENU_CHOICE,PHASE_CHANGE,SYM
      CHARACTER*1 PLOT_CHOICE,PRINTER_ANSWER,COLOUR_CHANGE,TEK_COPY_ANSWER
C
C
C COMMON BLOCKS
C
      COMMON /CHARACTERS/COLOUR_CHANGE,HARDCOPY_ANSWER
      COMMON /FLAGS/ITERATIONS_THRU
      COMMON /LATTICE/A0,B0,C0,COSALP,COSBET,COSGAM
      COMMON /RELATT/AST,BST,CST,CALPST,CBETST,CGAMST
      COMMON /SINE/SINALP,SINBET,SINGAM
      COMMON /IBASVEC/IH1,IJ1,IK1,IH2,IJ2,IK2
      COMMON /BASVEC/RIH1,RIJ1,RIK1,RIH2,RIJ2,RIK2
      COMMON /IZONE/IU,IV,IW
      COMMON /ZONE/RIU,RIV,RIW
      COMMON /PARAM/SYM,IHOLZ,INN,WAVE,GGMAX,PRINTER_ANSWER,PLOT_CHOICE
      COMMON /AXES/GX,GY
C
C
C COMMON BLOCKS FOR TERMIN
C
      COMMON /TERMIN/ ITERM,IBAUD,IPLOT,ICOLOR,IMODE,IHARD,ILP(3)
      COMMON /PLOTTER/ ITEMPORARY
C
      PARAMETER( PI=3.141592654)
C
C
C PRINTER OUTPUT (TRANSFERRED FROM SUBROUTINE ZERO)
C
      IF(PRINTER_ANSWER.EQ.'Y') WRITE(2,00310)IHOLZ(1),
     CIHOLZ(2),IHOLZ(3),IHOLZ(4),IHOLZ(5),INN,GGMAX
00310 FORMAT(/,' HOLZ LINES FROM LAYERS ',4I3,' AND ',I3,/,
     C' RANGE OF HOLZ INDICES -N,-N,-N TO N,N,N =',I4,/,
     C' MAX MODULUS OF G.G(HOLZ) =',F10.0)
C
      CALL DOT(RIU,RIV,RIW,RIU,RIV,RIW,
     CA0,B0,C0,COSALP,COSBET,COSGAM,UU)
      UUMOD=SQRT(UU)
C
      QQ=1.0
      XOFF=512.
      YOFF=390.
C
C
C	DEBUGGING STATEMENT HERE
C
C	WRITE(8,13000)UUMOD,GX,GY
C13000 FORMAT(X,'UUMOD=',F13.6,' GX=',F13.6,' GY=',F13.6,///)
C
C
C D IS THE APERTURE SIZE IE THE WINDOW ON THE HOLZ PATTERN
C
C
      D=C2AP*0.0073/150.
      IF(PLOT_CHOICE.EQ.'H') C2DIA=350.
      IF(PLOT_CHOICE.NE.'H') C2DIA=C2AP*0.458 ! NUMBER FROM MEASURING NEGS
C
C
C      IF(A.EQ.'H') CALL ERASE
C   
C	SET COLOR
C
	CALL COLOR(3)
C
C
C	CONVERT THE HOLZ INTEGERS TO REAL FOR COMPARISON
C       WITH G DOT U 
C
C
	DO 34443 JJJJ=1,5,1
	RIHOLZ(JJJJ)=FLOAT(IHOLZ(JJJJ))
34443   CONTINUE
C
C
	RIHOLZM1=RIHOLZ(1)-0.01
	RIHOLZP1=RIHOLZ(1)+0.01
	RIHOLZM2=RIHOLZ(2)-0.01
	RIHOLZP2=RIHOLZ(2)+0.01
	RIHOLZM3=RIHOLZ(3)-0.01
	RIHOLZP3=RIHOLZ(3)+0.01
	RIHOLZM4=RIHOLZ(4)-0.01
	RIHOLZP4=RIHOLZ(4)+0.01
	RIHOLZM5=RIHOLZ(5)-0.01
	RIHOLZP5=RIHOLZ(5)+0.01

C
C THIS IS TO ENSURE THE PROPER INDICES ARE SEARCHED FOR 
C RHOMBOHEDRAL AND HEXAGONAL LATTICES SINCE I INSIST ON WORKING IN MILLER
C INDICES ONLY.
C
      IF((SYM.EQ.'H').OR.(SYM.EQ.'R')) INN=INN*2    
C
C
C
	LINE_NUMBER1=1
	LINE_NUMBER2=1
      DO 70 IHH=-INN,INN,1
      DO 71 IJJ=-INN,INN,1
      DO 72 IKK=-INN,INN,1
C
C
C
      IF(((SYM.EQ.'H').OR.(SYM.EQ.'R')).AND.
     C(ABS(IHH+IJJ).GT.INN))  GO TO 72
       IF(((IHH.EQ.0).AND.(IJJ.EQ.0)).AND.(IKK.EQ.0)) GO TO 72
       IF(((IHH.EQ.-(IU)).AND.(IJJ.EQ.-(IV))).AND.
     C(IKK.EQ.-(IW))) GO TO 72
C
C
C	DEBUGGING STATEMENT
C
C	WRITE(8,11001)IHH,IJJ,IKK
C11001  FORMAT(X,' H=',I3,' K=',I3,' L=',I3)
C
C
C
C
C
C	DETERMINE ALLOWED AND FORBIDDEN REFLECTIONS
C	IF IOK=0 ALLOWED
C	IF IOK=1 FORBIDDEN
C
C     	
	CALL CRYSTAL(SYM,IHH,IJJ,IKK,IOK)
C
C
      IF(IOK.EQ.1) GO TO 72
      IGDOTU=IU*IHH+IV*IJJ+IW*IKK
      IF(IGDOTU.EQ.0) GO TO 72
      RIGU=REAL(IGDOTU)
C
C
C
C	WRITE(7,55555)IGU
C
C55555	FORMAT(X,I10)
C
C
C
      IF(((RIGU.LE.RIHOLZM1).OR.(RIGU.GT.RIHOLZP1)).AND.
     C((RIGU.LE.RIHOLZM2).OR.(RIGU.GT.RIHOLZP2)).AND.
     C((RIGU.LE.RIHOLZM3).OR.(RIGU.GT.RIHOLZP3)).AND.
     C((RIGU.LE.RIHOLZM4).OR.(RIGU.GT.RIHOLZP4)).AND.
     C((RIGU.LE.RIHOLZM5).OR.(RIGU.GT.RIHOLZP5))) GO TO 72
C
C
C
C
C
C	CONVERT INDICES OF G TO REAL FOR DOT PRODUCT
C
C
	RIHH=FLOAT(IHH)
	RIJJ=FLOAT(IJJ)
	RIKK=FLOAT(IKK)
C
C
      CALL DOT(RIHH,RIJJ,RIKK,RIHH,RIJJ,RIKK,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GG)
      GGMOD=SQRT(ABS(GG))
      CALL DOT(RIHH,RIJJ,RIKK,RIH1,RIJ1,RIK1,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GGX)
      CALL DOT(RIHH,RIJJ,RIKK,RIH2,RIJ2,RIK2,
     CAST,BST,CST,CALPST,CBETST,CGAMST,GGY)
      IF(GGMOD.GT.GGMAX) GO TO 72
	THETAB=GGMOD*WAVE/2
	THETAG=RIGU/(UUMOD*GGMOD)
C
C
C	DEBUGGING STATEMENT HERE
C
C
C	WRITE(8,13001)IGDOTU,RIGU,GGMOD,GGX,GGY,IHH,IJJ,IKK,THETAB,THETAG
C13001	FORMAT(X,' IGDOTU=',I10,' RIGU=',F13.6,' GGMOD=',F13.6,/
C     C,X,' GGX=',F13.6,' GGY=',F13.6,/,X,' H=',I3,' K=',I3,' L=',I3,/,X,
C     C' THETAB=',F13.6,' THETAG=',F13.6,//)
C 
C
C

      IF((THETAB).GT.1.0) THETAB=1.0
      IF((THETAG).GT.1.0) THETAG=1.0
      TH=-ASIN(THETAB)+ASIN(THETAG)
C
C
C 	WRITE(8,13002)TH,D,TH/D
C13002	FORMAT(X,'TH=',F13.6,' D=',F13.6,' TH/D=',F13.6,/)
C
C	
      IF(ABS(TH).GE.D) GO TO 72
      W=ACOS(TH/D)
      IF(GGX.EQ.0) GO TO 1000
      IF(GGY.EQ.0) GO TO 1000
      DX=ATAN(ABS(GGY*GX/(GGX*GY)))
      DY=ATAN(ABS(GGX*GY/(GGY*GX)))
C
C	MORE DEBUGGING STATEMENTS
C
C
C	WRITE(8,13005)W,DX,DY
C13005	FORMAT(X,' W=',F13.6,' DX=',F13.6,' DY=',F13.6,//)
C
C
C

      IF((GGY.GT.0.0).AND.(GGX.GT.0.0)) DX=DX+PI
      IF((GGY.GT.0.0).AND.(GGX.LT.0.0)) DX=2.0*PI-DX
      IF((GGY.LT.0.0).AND.(GGX.LT.0.0)) DX=DX
      IF((GGY.LT.0.0).AND.(GGX.GT.0.0)) DX=PI-DX
1000  IF((GGY.EQ.0.0).AND.(GGX.GT.0.0)) DX=PI
      IF((GGY.EQ.0.0).AND.(GGX.LT.0.0)) DX=0.0
      IF((GGY.GT.0.0).AND.(GGX.EQ.0.0)) DX=3.0*PI/2.0
      IF((GGY.LT.0.0).AND.(GGX.EQ.0.0)) DX=PI/2.0
C
C
C
C
C	WRITE(8,13005)W,DX,DY
110   X(1)=XOFF+(C2DIA)*1.1*COS(DX-W)
      Y(1)=YOFF+(C2DIA)*1.1*SIN(DX-W)
      X(2)=XOFF+(C2DIA)*1.1*COS(DX+W)
      Y(2)=YOFF+(C2DIA)*1.1*SIN(DX+W)
C	WRITE(8,13105)X(1),Y(1),X(2),Y(2)
C13105 FORMAT(X,' X1=',F13.6,' Y1=',F13.6,' X2=',F13.6,' Y2=',F13.6) 
C
C
C
	IF((IHARD.NE.5).OR.((HARDCOPY_ANSWER.EQ.'B').OR.
     C(HARDCOPY_ANSWER.EQ.'T')))  THEN
	IF(LINE_NUMBER1.EQ.1) THEN
	CALL STRTCRT
	IF(PLOT_CHOICE.EQ.'H') CALL ERASE
	LINE_NUMBER1=LINE_NUMBER1+1
	ENDIF
	CALL VECTOR(X(1),Y(1),X(2),Y(2))
	ENDIF
	IF((IHARD.EQ.5).AND.(HARDCOPY_ANSWER.NE.'T')) THEN
	CALL SETHP
	IF(LINE_NUMBER2.EQ.1) THEN
	CALL STRTHP
	LINE_NUMBER2=LINE_NUMBER2+1
	ENDIF
	CALL VECTOR(X(1),Y(1),X(2),Y(2))
	CALL DELAY(20)
	CALL RESETERMINAL
	ENDIF
C
C
C
	IF(COLOUR_CHANGE.EQ.'Y'.OR.COLOUR_CHANGE.EQ.' ') THEN
	SEQUENCE=SEQUENCE+1
	IF(SEQUENCE.EQ.7) SEQUENCE=0
	CALL COLOR(SEQUENCE)
	ENDIF
      IF((PRINTER_ANSWER.EQ.'N').OR.(ITERM.EQ.5))  GO TO 11112
	XQUARTER=((3*X(1)+X(2))/4)
	YQUARTER=((3*Y(1)+Y(2))/4) 
77780 CONTINUE
      CALL MOVE(XQUARTER,YQUARTER)
      WRITE(7,11110)INT(QQ)
11110 FORMAT('+',I2)
C
C
C OUTPUT FOR LINE PRINTER
C
11112 IF(PRINTER_ANSWER.EQ.'Y') THEN
      IF((SYM.EQ.'H').OR.(SYM.EQ.'R')) THEN
      WRITE(2,11111)QQ,IHH,IJJ,-(IHH+IJJ),IKK
11111 FORMAT(F4.0,4I3)
      ENDIF
      IF((SYM.NE.'H').AND.(SYM.NE.'R')) THEN
      WRITE(2,11121)QQ,IHH,IJJ,IKK
11121 FORMAT(F4.0,3I3)
      ENDIF
      ENDIF
C
      QQ=QQ+1.0
72	CONTINUE
71	CONTINUE
70    CONTINUE
	IF((IHARD.NE.5).OR.((HARDCOPY_ANSWER.EQ.'B').OR.
     C(HARDCOPY_ANSWER.EQ.'T')))  THEN
	CALL SYMBOL(XOFF,YOFF,C2DIA*2,8)
	ENDIF
	IF((IHARD.EQ.5).AND.(HARDCOPY_ANSWER.NE.'T')) THEN
	CALL SETHP
	CALL SYMBOL(XOFF,YOFF,C2DIA*2,8)
	CALL DELAY(20)
	CALL RESETERMINAL
	ENDIF	
	CALL COLOR(1)
	IF((IHARD.EQ.5).AND.(HARDCOPY_ANSWER.NE.'T')) THEN
	CALL SETHP
	CALL ENDHP
	CALL RESETERMINAL
	ENDIF
      RETURN
      END
C
C
C***********************************************************************
C ROUTINE FOR HP PLOTTER HANDLING.
C***********************************************************************
C
C
	SUBROUTINE SETHP
C
C	THIS ROUTINE SETS THE TERMINAL TO A HP PLOTTER 
C	FOR HARD COPY PLOTTING. NESTOR'S GRAPHICS CHECK TO SEE
C	WHICH TERMINAL TYPE THAT YOU ARE USING AND SEND THE REQUIRED
C	COMMANDS.
C
C
        COMMON /TERMIN/ ITERM,IBAUD,IPLOT,ICOLOR,IMODE,IHARD,ILP(3)
	COMMON /PLOTTER/ ITEMPORARY
	ITEMPORARY=ITERM
	ITERM=IHARD
	RETURN
	END
C
C***********************************************************************
C ROUTINE TO RETURN TO TERMINAL AFTER HP PLOTTING.
C***********************************************************************
C
C
C	
	SUBROUTINE RESETERMINAL
C
C	THIS ROUTINE TURNS THE VIDEO TERMINAL BACK ON AFTER
C	IT HAS BEEN TURNED OFF WITH SUBROUTINE SETHP
C
C
C
        COMMON /TERMIN/ ITERM,IBAUD,IPLOT,ICOLOR,IMODE,IHARD,ILP(3)
	COMMON /PLOTTER/ ITEMPORARY
	ITERM=ITEMPORARY
	REWIND 80	!DUMP HP BUFFER IF SIMULTANEOUS MODE WILL NOT
	RETURN		!WORK IF DATA IS BEING STORED TO A FILE
	END		!AS THIS WILL ERASE THE FILE MAY CURE JFM HEADACHE
C
C
C***********************************************************************
C	THIS ROUTINE DETERMINES ALLOWED REFLECTIONS FOR EACH 
C	LATTICE TYPE.
C***********************************************************************
C
C
C
	SUBROUTINE CRYSTAL(LATTICE_TYPE,IH,IK,IL,IOK)
C
C	DECLARATIONS
C
C
	CHARACTER*1 LATTICE_TYPE
	REAL*4 AQ,BQ,CQ,DQ,EQ,FQ,GQ,HQ
	REAL*4 RHOM1,RHOM2
	REAL*4 	EQAQ,FQBQ,GQCQ,HQDQ,RHOM21
	INTEGER IH,IK,IL,IOK,IN
C
	DATA XA,XB,XC,XF,XI,XP,XH,XR
     C/'A','B','C','F','I','P','H','R'/
C
C	SORTS OUT THE REFLECTIONS FOR THE NON PRIMITIVE LATTICES
C
C
	IOK=0
C
C
	AQ=ABS(INT((IK+IL)/2))
	BQ=ABS(INT((IH+IL)/2))
	CQ=ABS(INT((IH+IK)/2))
	DQ=ABS(INT((IH+IK+IL)/2))
	RHOM1=ABS(INT((IH-IK+IL)/3))
C
C
	EQ=ABS((FLOAT(IK)+FLOAT(IL))/2)
	FQ=ABS((FLOAT(IH)+FLOAT(IL))/2)
	GQ=ABS((FLOAT(IH)+FLOAT(IK))/2)
	HQ=ABS((FLOAT(IH)+FLOAT(IK)+FLOAT(IL))/2)
	RHOM2=((FLOAT(IH)-FLOAT(IK)+FLOAT(IL))/3)
C
C
	EQAQ=EQ-AQ
	FQBQ=FQ-BQ
	GQCQ=GQ-CQ
	HQDQ=HQ-DQ
	RHOM21=RHOM2-RHOM1
C
C	PRIMITIVE, SIMPLY RETURN IOK=0
C	ALL ALLOWED
C
	IF(LATTICE_TYPE.EQ.'P') RETURN
C
C	A CENTRED
C
	IF(LATTICE_TYPE.EQ.'A') THEN
	IF((EQAQ).GT.0.15) IOK=1
	RETURN
	ENDIF
C
C	B CENTRED
C
	IF(LATTICE_TYPE.EQ.'B') THEN
	IF((FQBQ).GT.0.15) IOK=1
	RETURN
	ENDIF
C
C	C CENTRED
C
	IF(LATTICE_TYPE.EQ.'C') THEN
	IF((GQCQ).GT.0.15) IOK=1
	RETURN
	ENDIF
C
C	F CENTRED
C
	IF(LATTICE_TYPE.EQ.'F') THEN
	IF(((GQCQ).LT.0.15).AND.((EQAQ).LT.0.15)) RETURN
	IOK=1
	RETURN
	ENDIF
C
C	BODY (I) CENTRED
C
	IF(LATTICE_TYPE.EQ.'I') THEN
	IF((HQDQ).GT.0.15) IOK=1
	RETURN
	ENDIF
C
C	HEXAGONAL
C	CHECK WHETHER IL IS ODD AND WHETHER THE SUM
C	IH+2*IK IS A MULTIPLE OF 3.
C
	IF(LATTICE_TYPE.EQ.'H') THEN
	IF((IL/2*2 -IL).EQ.0) GO TO 20
	DO 10 IN=0,10
	IF(ABS(IH+2*IK).EQ.(3*IN)) THEN
	IOK=1
	GO TO 20
	ENDIF
10	CONTINUE
20	RETURN
	ENDIF
C
C	RHOMBOHEDRAL
C
	IF(LATTICE_TYPE.EQ.'R') THEN
        IF(RHOM21.GT.0.15) IOK=1
	RETURN
	ENDIF
C
	END
C
C	ROUTINE FOR CALCULATING THE DOT PRODUCTS
C	BETWEEN TWO VECTORS IN REAL OR RECIPROCAL SPACE
C
C
C***********************************************************************
C	THIS ROUTINE CALCULATES DOT PRODUCTS.
C***********************************************************************
C
C
C
C
      SUBROUTINE DOT(AAAX,AAAY,AAAZ,AAX,AAY,AAZ,
     CA,B,C,AAA,BBB,CCC,RES)
C
C	DECLARATIONS
C
C
	REAL*4 AAAX,AAAY,AAAZ,AAX,AAY,AAZ,A,B,C,AAA,BBB,CCC,RES
C
C
      RES=AAAX*AAX*(A**2)+AAAY*AAY*(B**2)+AAAZ*AAZ*(C**2)+(AAAX*AAY+
     CAAX*AAAY)*A*B*CCC+(AAAX*AAZ+AAAZ*AAX)*A*C*BBB+
     C(AAAY*AAZ+AAY*AAAZ)*B*C*AAA
      RETURN
      END
C
C***********************************************************************
C	THIS IS WAYNE'S EXTRA REFLECTION ROUTINE
C***********************************************************************
C
C
      SUBROUTINE ADDCON(IA,IB,IC,ID,IE,IH,IK,IL,IFBID)
C
C	DECLARATIONS
C
	INTEGER IA,IB,IC,ID,IE,IH,IK,IL
      BYTE IFBID
	INTEGER ITEST,JTEST
C
C

      ITEST=IA*IH+IB*IK+IC*IL-IE
      JTEST=(ITEST/ID)
      IF(ITEST.NE.(JTEST*ID))IFBID=1
      RETURN
      END
C
C
C***********************************************************************
C	THIS IS RICH HOLTON'S SORT CODE AND IT'S PRETTY QUICK TOO.
C***********************************************************************
C
C
	SUBROUTINE SORT (KEYS,INDEX,N)
C
C	ROUTINE TO SORT A KEYED ARRAY, USING THE QUICKSORT METHOD.
C
	REAL KEYS(N)
C
	INTEGER TOP,L,R,N,M,KEY,STACK(2,20),CODE,INDEX(N)
C
	COMMON /STACK/ STACK,TOP
C
	M = 4
	TOP = 0
	L = 1
	R = N
10	IF ( R-L .LT. M) GOTO 100
	I = L
	J = R
	KEY = INDEX(L)
20	IF (KEYS(KEY) .GE. KEYS(INDEX(J))) GOTO 30
		J = J - 1
		GOTO 20
C
30	IF ( J .LE. I ) GOTO 70
	INDEX(I) = INDEX(J)
	I = I + 1
40	IF ( KEYS(INDEX(I)) .GE. KEYS(KEY)) GOTO 50
		I = I + 1
		GOTO 40
C
50	IF ( J .LE. I ) GOTO 60
	INDEX(J) = INDEX(I)
	J = J - 1
	GOTO 20
C
60	INDEX(J) = KEY
	I = J
	GOTO 80
C
70	INDEX(I) = KEY
C
80	IF ( R-I .GE. I-L ) GOTO 90
		CALL PUSH (L,I-1)
		L = I + 1
		GOTO 10
C
90	CALL PUSH (I+1,R)
	R = I - 1
	GOTO 10
C
100	LL = L + 1
	DO 130  J = LL, R
		KEY = INDEX(J)
		I = J - 1
110		IF ( KEYS(INDEX(I)) .LE. KEYS(KEY) ) GOTO 120
			INDEX(I+1) = INDEX(I)
			I = I - 1
			GOTO 110
120		INDEX(I+1) = KEY
130		CONTINUE
C
	CALL POP(L,R,CODE)
	IF (CODE.EQ.0) GOTO 10
C
	RETURN
	END
C
C
C***********************************************************************
C	THIS IS PART OF THE SORT CODE.
C***********************************************************************
C
C
C
	SUBROUTINE PUSH (I,J)
C
	INTEGER I,J,STACK(2,20),TOP
C
	COMMON /STACK/ STACK,TOP
C
	TOP = TOP + 1
	STACK(1,TOP) = I
	STACK(2,TOP) = J
	RETURN
	END
C
C
C
C***********************************************************************
C	THIS IS PART OF THE SORT CODE.
C***********************************************************************
C
C
	SUBROUTINE POP (I, J , CODE)
C
	INTEGER I,J,STACK(2,20),TOP,CODE
C
	COMMON /STACK/ STACK,TOP
C
	CODE = 0
	IF (TOP .EQ. 0) GOTO 10
	I = STACK (1,TOP)
	J = STACK (2,TOP)
	TOP = TOP - 1
	RETURN
C
10	CODE = 1
	RETURN
	END