C     Program N_TREOR
C
C     This is a Stand-alone version of N-TREOR  (Version November 2001). 
C
C     REFERENCE:
C           New techniques for indexing: N-TREOR in EXPO
C     J.Appl.Cryst. (2000) 33, 1180-1186
C     by  Angela Altomare, Carmelo Giacovazzo, Antonietta Guagliardi,
C     Anna Grazia Giuseppina  Moliterni,  Rosanna Rizzi  and Per-Erik
C     Werner
C
C     In EXPO N-TREOR is combined with a peak search  procedure and a
C     a program set for structure determination.
C    
C     If you are only interested in the description of how to run the
C     stand-alone version of the program go to the headline:
C               N_TREOR the stand-alone version of N-TREOR
C     
C        N-TREOR is an updated version of TREOR90 described below.
C     The main changes characterizing N-TREOR with respect to TREOR90
C     are:            
C     1) Several decisions  normally made by the user of TREOR90 when
C        a  default run fails or when a  plausible  solution is found 
C        are automatically made by N-TREOR
C     a) If a  plausible solution is found, the program will look for 
C        a better  solution in a  new trial. This may be  achieved by 
C        requiring a higher M20 value or all the first 20 peaks to be        
C        indexed. 
C     b) If  N-TREOR does not give  satisfactory results in a default
C        run it repeats the unit cell search with wider error limits.
C     c) If still no solution is found,  with increased error limits,
C        the maximum (h,k,l)  Miller indices of the  orthorhombic and
C        monoclinic base lines are increased and the error limits are 
C        narrowed to 50 per cent of the default values.  ( The reason 
C        for narrowing the error limits is that a large number of big
C        erroneous unit cells may otherwise be generated in the trial
C        phase,  and  correct  solutions  may  be  eliminated  before
C        refinement. There is always a need for more accurate data if
C        the  unit  cell  is  big.  The  figure-of-merit  tests  will
C        otherwise fail.)
C     2) The   maximum  cell  volume  and  the  maximum  axis  values
C        investigated  by  N-TREOR  are preset to 4000 A**3 and 35 A,
C        respectively,  if the  maximum  observed d value is  greater
C        than 10 A. If the maximum observed d value is less than 10 A
C        the default values are (as shown in the key-word list below)
C        2000 A**3 and 25 A, respectively.  
C     3) The dominant-zone tests in TREOR90 are improved, and if more
C        than the first 6 peaks can be indexed  by a  two-dimensional
C        rectangular cell,but no three-dimensional solution is found,
C        the  first  non-indexed  peak  is  reported  as  a  possible
C        impurity line that may be deleted in a second test. 
C     4) Wavelength  dependence of D1 and D2 ( error tolerances,  see
C        the key-word list below) has been introduced.
C               DX = DXCU*(WAVE/1.560598)**2  where
C        DXCU = D1 and D2, respectively for CuK-alpha1 radiation
C     5) Monoclinic solutions are checked for  possible  rhombohedral
C        symmetry. If  the  symmetry  is  likely to be  rhombohedral, 
C        N-TREOR calculates the possible hexagonal axes.  In general, 
C        however, the user has to check for geometrical  ambiguities.
C        In N_TREOR version  November 2001, the  rhombohedral cell is
C        also calculated and refined by PIRUM.
C     6) Possible zero shifts in the  2theta Bragg angles are tested.
C        This is probably the most serious systematic error in powder 
C        diffractometry.  Although  well  known  internal  as well as
C        external  standard  techniques  exist,  that  can be used to 
C        completely (or almost completely) eliminate such errors, the
C        experience from a large number of  indexing  problems  shows
C        that zero point errors are frequently present in  data  sets
C        used for powder indexing. ( Suprisingly enough  even  modern
C        synchrotron data, with exceptionally high RELATIVE accuracy,
C        have sometimes been found to have large zero point errors.) 
C     7) N-TREOR can suggest more candidate cells. In order to select
C        the best one, a modified  de Wolff  figure of merit M'20 has
C        been introduced, with
C                       M'20 = (7-N-par)*M20    where
C        N-par is the number of cell parameters to be determined  ( 6
C        for triclinic system, 4 for monoclinic,....), and M20 is the
C        original de Wolff figure of merit. Even if M20 is  effective
C        as a tool for  assessing  the  reliability  of the cell, the
C        heuristic relation (M'20=.....) allows the program to prefer 
C        a higher symmetry solution. E.g., of two possible unit cells
C        with  similar  M20  values,  one  monoclinic  and  the other
C        triclinic, the monoclinic is preferred by M'20.
C     8) The program PIRUM,  originally  an  interactive program, has 
C        been suitably modified in order to automatically  refine the
C        unit cell parameters, without any user intervention. N-TREOR
C        performs a statistical study of index parity of the assigned
C        reflections in order to detect the presence of doubled  axes
C        or of additional lattice points (A, B, C, I, R or F centered
C        cell). In these cases the reflection conditions are suitably
C        modified and the unit cell  parameters  are  again  refined.
C        It  may  be  necessary, however, to  check the  analysis  of
C        systematic  extinctions in the  condensed  output  file. The  
C        reason is that mutiple indexed reflections are not analysed.
C        Additional refinement cycles are  performed by  PIRUM  after
C        applying two supplementary origin shifts of +-  one  quarter
C        of the shift value selected by N-TREOR according to  point 6
C        above. See also the keyword LIMIT.
C     9) It is not possible to interrupt the calculations by pressing
C        the key...I....This option is not available any more. 
C    10) It is still possible to use the key-word system as described
C        below. Normally, however, only WAVE, LIMIT, CHOICE and  END*
C        are needed.
C    11) Last corrections: September 2004
C   
C  
C               N_TREOR the stand-alone version of N-TREOR
C
C     Data input file:
C
C     LINE ONE.          TITLE  Any text in col.2-80
C
C
C     LINE SET TWO.      One d-value and optionally INTENSITY on each
C                        line. (Free format)
C                        It is also possible  to  use  other types of 
C                        input data. See keyword CHOICE in  the  key-
C                        word list below. Note that the default value
C                        of CHOICE is 4 in N_TREOR (i.e. d-values).  
C                        The data must be  given  in  order, starting
C                        with the low order lines.Generally the first
C                        20-25 lines should be used.  Remaining lines
C                        (if any) may be used in later  final refine-
C                        ments. (The dialogue version of PIRUM).
C
C                        INTENSITY data is optional. It is never used
C                        by the program. If present, it  will only be
C                        transferred to the output  lists as (max.) 4
C                        digits integers.
C
C
C     STOP LINE FOR LINE SET TWO IS A BLANK LINE 
C
C     The program will ask for file names and Theta-shift.
C     The normal Theta-shift is the step used in the data collection;
C     (Usually =0.01 for Wave=1.5406 A)  i.e. 0.02 deg. in 2theta.
C
C
C     LINE SET THREE.(See general description of this line set below)
C                      
C    Below 4 examples of line set three for N_TREOR are given:
C
C    Example 1.
C        end*
C    Comment:This is the only key-word  needed for a  normal  N_TREOR
C    run if  CuK-alpha1  radiation has  been  used  and  d-values are
C    given.
C
C    Example 2.
C        wave=1.529, end*
C    Comment: Error limits are wave-length dependent. It is therefore
C    important to give the wave-lenght, although the d-values are not
C    wave-lenght dependent. Do not forget the , before next key-word.
C
C     Example 3.
C       limit=1, end*
C    Comment: LIMIT is a new key-word, not present earlier in  TREOR.
C    LIMIT can be any integer between 1 and 10 (default value is 10).
C    The parameter LIMIT can be given a value  less than 10 in  order
C    to reduce the maximum number of zero shifts tested. ( The number
C    of zero shifts applied will be  dependent on the  result  of the
C    the calculations and is therefore usually less than 10).   
C    If you have good reason to  belive that the zero point error  is
C    negligible, you may save a lot of computer time by limit=1
C
C     Example 4.
C      choice=0, limit=1, end*
C    Comment: Input data are sine square  theta  values  derived from
C    an instrument with strictly monochromatic CuK-alpha1  radiation. 
C    About limit=1, see example 3 above.
C
C    WARNINGS:
C    A) In the present version of the program the  automatic tests of
C    index  parity  are  NOT  complete.  See  comments  about  VISUAL
C    INSPECTION in the condensed output list. ( May be  improved in a
C    later program version.) 
C    B) On a PC the  calculations  may be very time consuming. It can
C    be recommended to use LIMIT=1 ( see  Example 3 above) in a first
C    test run, at least if you have good  reason to  believe that the
C    zero point error is negligible.
C    C) OBS ! The best solution may be found ANYWHERE in the condesed
C    output file. The reason is that the automatic Pirum run may fail
C    and give more unindexed lines. It is  recommended to  always use
C    a separate Pirum run to check the possible solution/s.     
C    
C    END OF INSTRUCTIONS FOR THE STAND-ALONE VERSION OF N-TREOR
C
C
C
C        TTTTTTT  RRRR     EEEEEE     OOOOO    RRRR       9999    0000   
C           T     R   R    E         O     O   R   R     9    9  0    0
C           T     R   R    E         O     O   R   R     9    9  0    0
C           T     RRRR     EEEEEE    O     O   RRRR       99999  0    0
C           T     R   R    E         O     O   R   R          9  0    0
C           T     R    R   E         O     O   R    R         9  0    0
C           T     R     R  EEEEEE     OOOOO    R     R       9    0000
C
C          This is an autoindexing program and should be used to find a     
C          physically plausible solution to an indexing problem.
C          It is  not a program  for  final refinement of the unit cell
C          dimensions. (c.f. PIRUM or NBS*AIDS83)
C
C          Information for the programmer:
C
C          The TREOR99 version is written in  Microsoft Fortran for PC.
C
C          The interrupt function (..press the letter i) is generally
C          not needed and if you want to use other  compilers  and/or
C          computers whithout any possibility to sense keyboard oper-
C          ations  during the  calculations, you may skip this in the
C          following way
C
C          Skip the include 'flib.fi' and 'flib.fd' 
C          Replace the original  subroutine  chkkey  by the following
C          dummy routine:
C
C          Subroutine chkkey(code)
C          integer*2 code
C          code=0
C          return
C          end
C  
C          End of programmers information
C
C     FEBRUARY 1999
C          Two new keywords, ZEROSET and KREDUCT, are introduced. See
C          keyword list below.  KREDUCT  may be used in order to save 
C          only the best trial solutions.It is presupposed then, that
C          input data is very accurate and a cell axis is expected to
C          be very long (>20 A)  
C          
C          In order to avoid run time errors, a large number of small
C          changes have been made.
C 
C          The earlier  program  versions were somewhat  dependent on 
C          the wave-length used. The parameters: D1, D2 and SSQTL are 
C          now  automatically ( i.e. if SELECT=-1 ,the default value)
C          adjusted for  WAVE. As in earlier program versions one can 
C          forget  about  WAVE if  CHOICE=4,  i.e. if input  data are
C          d-values.
C          If correct  WAVE  is given, also the  correct  diffraction
C          angles are reported in the output lists.
C              
C          Monoclinic solutions are checked for possible rhombohedral
C          symmetry. If several high symmetry solutions are found, it
C          is recommended to decrease the  parameter VOL in  order to  
C          find the smallest monoclinic cell (1/6 of the 'true' hexa-
C          gonal cell). Then treor will check if the true symmetry is
C          likely  to be  rhombohedral  and  calculate  the  possible
C          hexagonal axes.
C     
C     SEPTEMBER 1997
C          (Below 1997 is changed to 1999   (changed february 1999)
C          Keywords (see below)  may be written in upper or lower case.
C
C          The program will run in 1999 mode if the keyword
C          SELECT has the value -1    (default value) 
C
C          The normal TREOR99 run is:
C
C          Title line: Any text in col. 2-80
C          Data lines: Less than 99 lines (Normally 20-25 lines).
C                      Free format.
C                      Only  one value on  each  line is necessary.
C                      Optionally an  intensity  may  be given as a 
C                      second data on the line.  Intensity  data is
C                      not used by the program and only transferred
C                      to the output as max. 4 digits integers
C
C          A blank line: 
C          choice=4,     (if  D-values were used on the data lines)
C                        Do not  forget  the , before next key-word
C                        Key-words may be given in  arbitrary order
C          end*          and on arbitrary lines but the  end*  must
C                        be the last one.
C
C          Usually no other key-words than  CHOICE need to be changed
C          from the default values.
C
C          If a  solution is  found the  program  will  automatically
C          decrease  NIX or increase  MERIT  and rerun the problem in 
C          order to check if a better solution can be found. However,
C          triclinic  tests  will only be made if the  first solution
C          was triclinic.
C
C          If no  solution is found the  program  will  automatically
C          change the parameters  IDIV and the error limits D1 and D2
C          i.e. add 0.0001*(Wave/1.5405981)**2)and rerun the problem. 
C
C          Of course the  TREOR99  mode  may take a  minute more on a
C          Pentium but it is a strongly recommended, simple, safe and
C          powerful procedure. 
C          
C          Powder indexing depends to 95 per cent on the data quality
C          If you are  using a Pentium  processor the  CPU  time will
C          probably never exceed 3 minutes.  ( A PC 486 may be almost
C          ten times slower.)
C
C          It is possible to run the  program in  TREOR4,  TREOR90 or
C          TREOR99 mode
C
C          TREOR4 mode if  VOL=positive value and  SELECT is zero (or
C          more.) 
C          TREOR90 mode if VOL=negative value and  SELECT is zero (or
C          more)
C          TREOR99 mode if  SELECT=-1  (Default)  (Normally preferred
C          mode)
C          If the  TREOR99  mode is used,  you normally  only need to
C          choose the correct CHOICE parameter.
C
C          In  all  modes  most  of  the  key-word  parameters may be
C          changed from the  default  values ( c.f. the key-word list
C          below).
C          Do not change default  values  without  good  reasons. For
C          example do not change  VOL  from the default value, unless
C          you  have  reason  to believe that the unit cell volume is
C          more than 2000 A**3 ( You will not reduce CPU time much if
C          you are using a VOL that is less than 2000 A**3)
C
C          If  TREOR99  finds a plausible solution ( according to the
C          NIX  and  MERIT  parameters) this will be announced on the
C          display  and  the  user may ( although  not  recommended )
C          interrupt the  calculations  and  look  at  the  condensed
C          output list.
C          Interrupt...Press the letter   i   on the keyboard.          
C          If the  program is running on a Pentium there is no reason
C          for doing so.
C          (The interrupt function is at present only available in the
C          PC version.)
C
C          Problem notes:
C
C          A solution that is very  close to a higher  symmetry may be
C          lost in the condensed  output list, although an  acceptable
C          lower symmetry  solution may be reported in the long output   
C          list. This  may  happen  if two cell  dimensions are almost
C          equal.
C
C
C     JUNE 1995
C          Within  this section  JUNE  1995 to  JUNE  1992 a very short   
C          description for the lazy user of  TREOR90 (who does not want  
C          to read the complete documentation file) is given.
C
C          The normal TREOR90 run is: 
C
C          Title line
C          Data lines (20-25 lines, only one d-value, col.1-16, on each 
C          line)
C          A blank line 
C          CHOICE=4,  (if D-values were used on the data lines)
C          SELECT=0,  (to avoid the TREOR99 mode)
C          VOL=-2000, (note the minus sign. --- a treor90 run)
C          END* (stop card)
C    
C          It is now possible to interrupt the  calculations.  This can 
C          be done by the letter  i  on the keyboard. Then the  program
C          will stop soon. The reason  for  this  option  is  that  one 
C          should never hesitate to give  VOL eq. a negative value i.e.
C          the  most  efficient test of all symmetries. One can  always
C          stop for  example  triclinic tests from the keyboard.  (This
C          option is only available on the PC version of the program)
C
C          If  no  solution is found rerun the problem, but include the
C          following keyword line:
C          D1=0.0003, D2=0.0005,
C          (note the , after each keyword value)
C          Another test is to set
C          IDIV=0,
C          which  means  that the first seven lines will not be changed
C          by ( what treor may erronously judge as ) higher order lines 
C          The parameters  MERIT  and  NIX  may  also be changed. ( See 
C          below.) The first accepted solution may not be the best one. 
C          Therefore,  follow  the instructions on the condensed output
C          file.
C          Do not print the long output file.  Use your editor and look
C          for the most promising M-TEST lines. 
C      
C          This  program  should  be  used to find a physical plausible
C          solution of  the  indexing  problem.  The refinement is only
C          preliminar ( not Hess weighted).  Especially  lines  at high
C          diffraction angles may be unindexed by treor. 
C          In  final  refinements all lines, all extinction conditions,
C          Hess weights ( i.e. all  diffraction  angles should be given
C          equal weights)and all knowledge about intensity distribution
C          between overlaps ( if available) should be used.
C          From  this  department a  flexible dialouge program,(version
C          930101 of PIRUM) may be distributed.  
C          Program NBS*AIDS83 is (probably ?) recommended by ICDD.
C
C     JUNE 1992
C          It is strongly recommended to run TREOR90 on a PC/AT using a
C          486 CPU. Otherwise the VAX version  TREOR90V  may  be  used.
C     AUGUST 1990
C     OBS. In the PC/AT and VAX versions  the  subroutines  ORTAL, MAEG
C          and COUNT are not vectorized. Vectorized versions  of  these
C          subroutines are available for CONVEX computers.
C          The original TREOR90 has been written for  a  CONVEX  vector
C          processor. This should be kept in  mind  when  the  comments
C          below are read. The program may be very time-consuming  on a
C          PC (unless a 486 processor is used).
C
C     1) Dominant zone test is added for the orthorhombic symmetry.
C     2) Dominant zone test is added for the triclinic symmetry.
C     3) Higher order lines among the first seven lines ( used  in  the
C        base line sets) are  automatically  excluded  from  the  trial
C        phase of the calculations.
C     4) If a monoclinic or triclinic solution is  found,  the  program 
C        will end with a unit cell reduction followed by  a  conversion
C        of the reduced cell to a conventional cell  according  to  the
C        metric symmetry. The reduction should be valid  unless  syste-
C        matic extinctions are found in the trial cell.
C     5) If a satisfactory solution is found, only the  condensed  out-
C        put file is needed. It contains all relevant  information  and
C        only one indexed list.
C     6) The general output list  (that is normally not needed,  cf. 5)
C        will only list trials where  M20 ( or Mxx if  less  lines  are
C        available) is 6 or more and not more than 3  lines  among  the
C        first 20 (or xx) lines are unindexed.
C     7) If the parameter VOL is given with a negative sign all  symme-
C        tries are tested until a final solution is found- if possible.
C        OBS. This is the normal procedure for TREOR90
C     8) An algoritm for successive reduction of trial-cell volumes  is
C        used in monoclinic and  triclinic  tests  if  a  negative  VOL 
C        parameter is given. It is  based  on  the  input  cell  volume
C        limit and the  number  of  trial  cells  found  with  IQ ( See
C        keyword IQ) or more than IQ indexable lines.
C     9) It is strongly recommended  to  give  only  the  first  ( well 
C        checked and accurately measured ) 25 lines in  the diffraction
C        data list (See LINE SET TWO).
C    10) It is expected that more than 95 per cent  of  monoclinic  and 
C        higher symmetry patterns and probably more than  50  per  cent
C        of triclinic patterns will be  indexed  PRESUPPOSED  the  DATA
C        QUALITY is high ( i.e. average differences between  calculated
C        and observed diffraction angles less than  0.02 deg. and  also
C        the weak lines included in the data). The experience  of  tri-
C        clinic patterns is limited, however. 
C    11) Obs. It is important to check cubic, tetragonal and  hexagonal
C        solutions by a second run with KS=0 and  THS=0  ( See key-word 
C        list.) Do not trust cubic, tetragonal or  hexagonal  solutions
C        without an orthorhombic test.
C    12) The reason for testing the symmetries in correct order  ( from
C        cubic to triclinic) and to START the  orthrhombic,  monoclinic
C        and triclinic tests with dominant zone tests is that  by  this
C        procedure false solutions are avoided. 
C    13) For a normal TREOR90 run only the keywords
C
C             CHOICE=X, (see key-word list) 
C             VOL=-2000, (OBS. The negative sign.)
C             END*
C
C        should be given after the  diffraction  data  list.  Computing
C        times of more than 1 minute is rare for monoclinic  or  higher
C        symmetries on a CONVEX computer. Computing times of more  than
C        5 minutes (on a CONVEX) for a triclinic pattern  has  not  yet
C        been found. For a VAX (Micro VAX II) computing  times  may  be
C        more than 50 times longer. The PC/AT 486 is  faster  than  the 
C        Micro Vax II (but slower than CONVEX. The source code for  VAX
C        is not exactly the same as for CONVEX. There  are  very  small
C        differences between the PC/AT and the  VAX versions,  however.
C        The input of file names and OPEN statements  must  be  changed
C        if you want to run this program on  a  VAX.  Furthermore,  the     
C        VAX version uses a subroutine to measure the CPU-time.
C    14) The input format for LINE SET TWO ( See below) is  changed  in
C        agreement with the output format of the diffraction data  file
C        from  the  Guinier-H{gg  film  scanner  system ( at  Stockholm
C        University). The change is mainly of interest  for  output  of
C        intensities. 
C    15) The original key-word instructions given  below  are  relevant
C        as long as a positive VOL parameter is given. 
C    16) If VOL is given a negative value (see 13 above) the  following
C        key-words are fixed: MONO=135 and MONOSET=7.  Other  key-words
C        may be used as in the description below.
C    17) On the output lists 
C        M-TEST= xx  UNINDEXED IN THE TEST=  y
C        usually means that xx is identical with M(20)  and  y  is  the
C        number of unindexed lines whithin the  first  20  lines ( i.e.
C        used for the MERIT test). If less than 20 lines are  available
C        xx and y refer to the number of lines used.
C 
C
C     November 1988
C
C     29 11 88
C
C     Trial-and-error program for indexing of unknown powder  patterns.
C      
C     Cubic, Tetragonal, Hexagonal, Orthorhombic, Monoclinic and 
C     Triclinic symmetries.
C
C     Version 2  1/9-75 = Version 26/4 plus
C
C                      DENS,EDENS and MOLW.     See Keyword list below.
C
C     Version 3  8/5-80 New output form
C
C     Version 4  2/10-84 = Version 3 plus
C
C                The following new options....
C
C                1. IDIV.          See keyword IDIV below.
C                2. Monoclinic (020)-test
C                   Ref: Smith,G.S. and Kahara,E J.Appl.Cryst.
C                        8 (1975) 681
C                3. SHORT.         See keyword SHORT below.
C                   Short axis test. (Indexing of dominant zones.)
C                4. TRIC.          See keyword TRIC below.
C                   Indexing of triclinic patterns.
C    
C     The source code was modified in order to decrease  the  CPU-times 
C     in September 1988. The changes have no influence on input or out-
C     put from the program, but CPU-time reductions of 20-50  per  cent
C     have been observed.
C
C     Version 5. (=Version November 1988) 29/11 1988
C
C     Dominant zone test introduced  also  for  orthorhombic  symmetry.
C      In version 4 high symmetry short axis solutions were only  found
C      indirectly from the monoclinic tests.
C     Condensed output file.
C      A complete list of observed and calculated lines is  only  given
C      for the solution (if it is found) i.e. for an indexing where the
C      stop limits ( See  keywords  MERIT  and  NIX )  are  fullfilled.    
C      Normally only the condensed output file is needed.         
C     If the stop limits are fullfilled the unit cell is refined  three
C      cycles more. OBS. Final least-squares refinement should be  made
C      by a separate program (for example by  PIRUM). The TREOR program
C      is written in order to FIND a plausible cell, not to produce the
C      ultimate refinement.
C     Only the first part of the difference analysis table  is  printed
C      if no solution is found. (Usually it is not needed as you should
C      rerun the problem after modifications of the input data.)
C
C     If you have any questions, write to....
C
C                        P.-E.Werner
C                        Dept. of Structural Chemistry
C                        Arrhenius Laboratory
C                        Stockholm University
C                        S-106 91 Stockholm,
C                        SWEDEN
C
C
C
C                        TEL: 08 / 16 23 93
C                        FAX: 46-8-15 21 87
C                        EMAIL: PEW@STRUC.SU.SE
C
C
C     It is believed, however, that the following documentation  should
C     be sufficient for all careful readers.
C
C     GOOD LUCK!
C
C
C
C     R E F E R E N C E S
C
C
C     Basic principles. Werner,P.-E., Z.Kristallogr. 120 (1964) 375-387
C
C     TREOR, a semi-exhaustive trial-and-error powder indexing  program
C     for all symmetries. Werner,P.-E.,  Eriksson,L.  and  Westdahl,M.,
C     J. Appl. Crystallogr. 18 (1985) 367-370
C
C     Refinement of unit cell. Werner,P.-E.,Arkiv Kemi 31(1969) 513-516
C
C     Figure of merit. De Wolff,P.M.,J.Appl.Crystallogr. 1(1968)108-113
C
C     Geometrical ambiguities. Mighell, A.D. and  Santoro, A., J. Appl.
C     Crystallogr. 8 (1975) 372
C
C
C     G E N E R A L   C O M M E N T S
C
C     This is a general  trial-and-error  indexing  program  for  X-ray
C     diffraction powder patterns (i.e. all symmetries included).
C
C     Historical information ---- In order to reduce computing times on
C     computers without hardware floating point  processers,  parts  of
C     the program have been written for integer calculations.      
C
C     The parameters given as normal values in the keyword  list  below
C     should be regarded as an important part of the  program. They are
C     based on experience from many successful runs on structures  con-
C     firmed by single crystal data.
C     The parameters VOL and CEM, however,  may  be  selected  for  the
C     actual data set and the symmetry tried.
C     ...For a monoclinic trial the parameter MONO  must  be  non-zero.
C     ...For a triclinic trial the parameter TRIC must be 1.
C     A TREOR99 run (i.e. SELECT=-1) or a TREOR90 run (i.e. VOL= a nega-
C     tive number) will automatically check all symmetries.
C
C     Most of the powder patterns used to check the program have  been
C     obtained by focusing Guinier-Hagg cameras. The photographs  have
C     been measured by....
C      1. The method described by Hagg,G., Rev.Sci.Instr.18 (1947) 371
C     and Westman,S. and Magneli,A.,  Acta Chem. Scand. 11 (1957) 1587
C      2. The method described by Malmros, G. and  Werner, P.-E., Acta
C     Chem. Scand. 27 (1973) 493
C      3. The film scanner system  SCANPI ( written  for  the  Guinier
C     film scanners LS18 and LS20)
C     The program has also been tested on a large number  of  NBS-data
C     sets. (JCPDS data sets.)
C
C     The accurate data obtained by NBS,National Bureau of  Standards,
C     is clearly sufficient for successful indexing (in spite  of  the 
C     fact that they are now usually  obtained  by  powder  diffracto-
C     meters. Unfortunately, however, many  diffractometer  data  sets
C     found in  the  litterature  show  parabolic  deviations  between
C     observed and calculated diffraction angles.)
C
C     The following citations, however, should be emphasized....
C
C     'The  paramount  importance  of  resolution  for  indexing  work
C      explains the high  success  rate  for  focussing  camera  data,
C      especially from Guinier-Hagg instruments, whose resolution  can
C      omly be described as  superb. It is  rather  less  common ( and
C      considerably more expensive) to obtain as good resolution  with
C      diffractometer data.'
C
C     'Powder indexing is not like  structure  analysis,  which  works 
C      well on good data, and will usually get by on poor  data  given
C      a  little  more  time  and  attention.  Powder  indexing  works
C      beautifully on good data, but with poor  data it  will  usually     
C      not work at all'
C
C
C     Ref: Data accuracy for powder indexing.Shirley,R.NBS Spec. Publ.
C         567 (1980)  P.370 and P.362 respectively.
C
C     WARNING!
C     A zero point error is much more serious than statistical  errors
C     of the same magnitude.
C
C     Sigma(Two theta) should be less than 0.02 deg.
C
C
C
C                *******************************************
C                * DO NOT WASTE COMPUTER TIME ON BAD DATA. *
C                *******************************************
C
C     An indexing algorithm cannot be  statet  rigorously  because  of 
C     the unpredictable  distribution  of  unobserved  lines  and  the
C     errors of  measurements. One (or two) impurity lines  may  cause
C     severe problems.More impurity lines may rule out the possibility
C     to index the pattern.  Therefore, it is  expected  that  various
C     methods may be useful for various powder patterns. For  example,
C     a multitude of non-systematic extinctions  may  not  appreciably
C     affect the power of trial-and-error methods.   
C
C     The least-squares refinement of the unit cell dimensions  should
C     normally not be considered as the ultimate refinement. The  main
C     purpose of this program is to FIND the unit  cell.  The  program
C     PIRUM (version 930101) may be  used  for  ultimate  refinements. 
C     PIRUM (version 930101) is a dialouge version of  the  old  PIRUM
C     ( cf. ref. /Refinement of unit cell/ given  above. )  Extinction
C     conditions, Hess weights and max.  accepted  deviations  between
C     observed and calculated 2theta in degrees are normally  used  in
C     version 930101 of PIRUM. In old PIRUM versions, parameters  like
C     D1, D2, and SSQTL (See keyword list below) were used.
C     (cf. also the NBS*AIDS83 program. PIRUM is designed to  be  more
C     user-friendly, however.)
C     
C     A limited number of nonsense cells may be printed on the  output
C     file. You should look for max. De Wolff figure of merit ( not F-
C     index) and min. number of unindexed lines.
C
C     WARNING. You should not accept unindexed lines  unless  you  are 
C     able to explain them. On the other hand, you should not  put  in
C     uncertain (doubtful) lines in this program. They may  be  tested
C     later by a refinement program (ex. PIRUM).    
C
C
C
C
C     I N P U T   D A T A
C
C
C     LINE ONE.          TITLE  Any text in col.2-80
C
C
C     LINE SET TWO.      One SQ and optionally INTENSITY on each line.
C                        (Free format)
C                        SQ (=Sine square theta). It is also possible
C                        to use other types of input data. See keyword
C                        CHOICE
C 
C                        The SQ data must be given in order,  starting
C                        with the low order lines.Generally the  first
C                        20-25 lines should be used. Remainging  lines
C                        (if any) may be used in later  final  refine-
C                        ments. (Program PIRUM).
C
C                        INTENSITY data is optional. It is never  used
C                        by the program. If present, it  will  only be
C                        transferred to the output  lists  as (max.) 4
C                        digits integers.
C
C
C     STOP LINE FOR LINE SET TWO IS A BLANK LINE (OR A NEGATIVE SQ)
C
C
C     LINE SET THREE.    GENERAL INSTRUCTIONS.
C
C     All parameters in line set three have preset values.
C     A preset value is denoted 'NORMAL VALUE 'below.
C     Any 'NORMAL VALUE' may be changed in the following way:
C
C        KEYWORD1=VALUE1, KEYWORD2 = VALUE2,
C        KEYWORD3=VALUE3,   .......,    END* 
C
C     1. The keywords are listed below
C     2. You must not forget =
C     3. The value may be given in  free  format ( integer or real ).
C     4. You must not forget ,
C
C     You may use arbitrary positions on the lines.
C     All blanks are irrelevant.
C     The number of lines is arbitrary. You may give one or more
C     key-word(s) on each line.
C    
C     Line set three must end with the keyword  END*  (OBS. asterisk)
C
C
C
C     S T R A T E G Y
C     Unless SELECT=-1 (i.e. TREOR99 mode) or VOL=(a negative value)
C     (i.e. TREOR90 mode),  the  program will not  differ  much  from
C     earlier program versions.  See the  comments on the top of this
C     list. Then (if VOL=negative value) only parameters such as NIX,
C     MERIT, IDIV and in exeptional cases D1, SSQTL  and/or D2 may be
C     changed if indexing is not successful. Usually the main problem, 
C     however, is the  quality  of  your  diffraction  data.  
C     Therefore, if the  first  run  does  not  give  a  satisfactory
C     solution, it may be recommended to increse D1 and D2 to  0.0003
C     and 0.0005, respectively.
C
C     If the TREOR99 mode is used (i.e. SELECT=-1) the program  will,
C     regardless  a  plausible  solution  is  found or not, rerun the 
C     problem and automatically adjust some parameters. Therefore  it
C     is generally not  necessary for the  user to change the default 
C     values in MERIT, NIX, D1 and/or D2. 
C     
C     If you are not using the normal TREOR99 procedure (i.e. SELECT=
C     -1) or the TREOR90 procedure(i.e. negative VOL) the standard
C     procedure is to start with the higher symmetries:
C     cubic, tetragonal, hexagonal and orthorhombic ( in one run).
C     Next the  monoclinic  symmetry  may be tried. More than one job
C     may be needed..successively increasing the number  of base line
C     sets, and cell volume (See keywords: VOL, CEM and MONOSET)
C
C     If formula weight and density are known, they may be used. (See
C     keywords: DENS, EDENS and MOLW). The CPU-time needed will  then
C     usually be strongly reduced. (Unfortunately  they  are  usually
C     not known and therefore they have not been used very much.)
C
C
C
C     LINE SET THREE EXAMPLES: (TREOR4, not normal TREOR99 or TREOR90
C     examples.)
C      
C     EXAMPLE 1.Next line (except C in col.1) represents a line set 3
C     END*
C
C     Cubic, tetragonal, hexagonal and  orthorhombic  symmetries  are
C     tried. It may be recommended to try a smaller VOL limit even if
C     a solution with acceptable figure of merit has  been  obtained.
C     Sometimes it is difficult to find the necessary transformations
C     between a high symmetry unit cell of too large  dimensions  and
C     the primitive one. 
C
C
C     EXAMPLE 2. Next two line is a line set 3.
C     KS=0,THS=0,OS1=0,
C     CEM=20, V O L = 1000 , MONO=130,END*
C
C     This is an example of a first monoclinic  trial. ( See  keyword
C     MONO). Note that it is irrelevant if  you  give  'CEM=20.0'  or
C     'CEM=20' etc.
C 
C 
C     EXAMPLE 3. Next.....etc.
C     KS=0,THS=0,OS1=0,
C     CEM=20, VOL=1500, MONO=130, END*
C
C     If example 2 is unsuccessful you may increase the VOL parameter
C     to 500
C
C
C     EXAMPLE 4. Next.....etc.
C     KS=0,THS=0,OS1=0,CEM=20,
C     MONOSET=7,LIST=1,
C     DENS=3.123,EDENS=0.2,MOLW=234,
C     END*
C
C     If you have any possibility  to  put  in  density  and  formula
C     weight, the CPU-time will be much reduced.  This  may  also  be
C     tried if you expect that the lattice contains a  dominant  zone
C     i.e. if in a test run you get a large  number  of  trial  cells
C     when using the keyword SHORT=1. 
C
C
C
C     EXAMPLE 5. Next....etc.
C     CEM=20,VOL=700,TRIC=1,MERIT=20,END*
C
C     This is a triclinic test ( OBS. time-consuming) ( See.  keyword
C     TRIC). A de Wolff figure merit of 20 may (sometimes) be  needed
C     for a triclinic cell
C     
C     The examples given above illustrate a  step-wise  strategy  for
C     indexing. However, the VOL parameter may be estimated from  the
C     D-value of the 20th line. (cf. keyword TRIC)
C
C
C     WARNING. If the unit cell  has  a  small  volume,  for  example     
C              250 A**3 and VOL=2000 is used,  the  correct  solution 
C              may be lost in the trial process. The reason is that a
C              large number of  large  trial  cells  may  erroneously
C              index more lines than the correct cell.
C              The problem is less severe in TREOR90  as  a  negative 
C              VOL parameter will cause the program to test ( for all 
C              but the triclinic symmetry) half the maximum volume in   
C              a first step.
C
C     WARNING. Estimation of the unit cell volume from the  relations
C              VOL(monoclinic cell)= 20*D(20)**3  where D(20)= the D-
C              value for line number 20, and VOL(orthorhombic) =
C              31*D(20)**3 are much less reliable than the correspon-
C              ding relation for the triclinic symmetry.
C                         VOL(triclinic)=13.39*D(20)**3
C              Triclinic structures have no  systematic  extinctions!
C              For structures containing atoms with large differences 
C              in scattering  factors ( eg. metal-organic structures)
C              the general rule may fail also in a triclinic case.         
C              Ref: Smith,G.S. J Appl. Crystallogr. 10 (1977) 252
C
C
C     It is usually easy to put in a known ( or expected ) cell  edge
C     into the program. Example: A monoclinic trial with the restric-
C     tion that one cell axis is X.XX A. Add this D-value in line set
C     two. Suppose it will be line number 2.  Then  set MH2=1, MK2=1,
C     ML2=0 and MS2=1. Then the line will be used as A-axis  or ( the
C     unique) B-axis in the monoclinic test.
C     Conclusion: It is usually easy to put in  prior  knowledge  and 
C     constraints -for  example  density-  into  the  program. ( This
C     statement is made because  of  some  misunderstandings  in  the
C     literature.)
C
C
C
C
C     H O W    T O   I N T E R P R E T  T H E   O U T P U T.
C 
C     As in all good detective stories, the solution of  the  problem
C     will usually be given on the last page.....
C     i.e. the output list will be interrupted  as  soon  as  a  unit
C     cell that will satisfy the criteria set  by  the  keywords  NIX
C     and MERIT are fullfilled. The main  rule  is  that if  all  the
C     first 20 lines are indexed and the De  Wolff  figure  of  merit
C     M(20) is greater than  9,  then  the  indexing  problem  is  in
C     principle solved. This does not mean that the cell is  reduced,
C     that a cell axis may not be double etc.,
C     
C
C
C     UNIT CELLS OBTAINED BY THE PROGRAM SHOULD BE CAREFULLY CHECKED
C
C     A. If M(20) is less than 10 or more than one line is  unindexed
C        within the 20 first observed lines the solution is  probably
C        meaningless. Is any low-order line wrong ?
C     B. Check for common factors in the quadratic forms.
C        Example: A teragonal pattern may have H*H + K*K = 5*N
C        i.e. the A-axis is 2.3607 ( square root of 5) times  shorter
C        than given on the output list.
C        Example: If all H, K or L are even, the  corresponding  cell
C        axis should be divided by 2.
C     C. If the unit cell obtained is centered,  derive  a  primitive
C        cell. ( Run program MODCELL or a corresponding NBS  program)
C     D. Reduce the primitive cell and derive the conventional  cell.
C        (Run program REDUCT or a corresponding NBS program)
C     E. Hexagonal and tetragonal  cells  are  sometimes  indexed  as 
C        orthorhombic. Example: A=B*1.7321 i.e. a possible  hexagonal
C        cell.
C     F. Check for geometrical ambiguities. See reference  above.  It
C        is also strongly recommended to chech cubic, tetragonal  and
C        hexagonal solutions by an orthorhombic test.  Put  KS=0  and
C        THS=0 and re-run the problem.
C        There are two reasons for this procedure....
C        1. It may help you to identify geometrical ambiguities.
C        2. It has been found that sometimes very small  orthorhombic
C           unit cells can be indexed  in  an  acceptable  way ( i.e.
C           fullfill the De Wolff criteria) by a larger unit cell  of
C           higher symmetry. Although the unit  cells  are  sometimes
C           related to each other, the relations are often  difficult
C           to detect, and therefore it is often  convenient  to  let
C           the program derive both solutions.
C     G. The De Wolff figure of merits are derived from  the  assump-
C        tion that no systematic extinctions  are  present  and  that
C        all lines are indexed. A high figure of merit has no meaning
C        unless all lines are indexed.  The De Wolff figure of  merit
C        will increase in the  final  refinement  made  with  program
C        PIRUM, where the systematic extinctions can  be  taken  into
C        account.
C     H. If possible, use the density and  formula  weight  to  check 
C        that the unit cell contains an integral  number  of  formula
C        units.
C     I. If a cell axis is more than 20 A....be suspicious!
C        It has been found that the De  Wolff  figure  of  merit  may
C        fail in such cases. (Require M(20) > 20)
C     J. If one cell edge is much shorter than the others..........be
C        suspicious! It may be a dominant zone  problem  and  the  De
C        Wolff test may fail. (This problem is usually not severe  in 
C        TREOR90, where short  axis  tests  are  made  prior  to  the
C        general tests.)
C     K. If a table starts with...NOT REFINED UNIT CELL...
C        two parameters are probably  almost identical ( the symmetry
C        may be higher) and the trial cell  parameters  are  used  to 
C        print the list.
C     L. If no satisfactory solution is found ( See the keywords  NIX
C        and MERIT), the program may end  with  a  small  table  con-
C        taining a difference analysis. The program is  described  in
C        Z. Kristallogr.120 (1964) p.381-382 (Werner,P.-E.)  where it
C        is named I1. The  most  interesting  differences  are  those 
C        that have high multiplicities  (on the top of the list)  and 
C        are not too small (to the right of the list). In the present
C        state of the program, the difference table  is  usually  not
C        needed. 
C     M. Why not solve the crystal structure from your powder  data ?
C        This is the ultimate way to prove the unit cell!
C
C
C
C
C
C
C
C     K E Y W O R D    L I S T
C
C     KEYWORD. NORMAL    COMMENT.
C              VALUE.
C
C
C     KH      =4         Max H for cubic base line.
C     KK      =4         Max K for cubic base line.
C     KL      =4         Max L for cubic base line.
C
C                        OBS. The program will only generate 
C                        H greater than or equal to K and
C                        K greater than or equal to L for
C                        this line.
C
C     KS      =6         Max H+K+L for this line.
C
C                        OBS. If KS=0 cubic test omitted.
C
C                        OBS. The  cubic base lines are (1) and (2).
C
C                        * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     THH     =4         Max H for tetragonal and hexagonal base lines.
C     THK     =4         Max K for tetragonal and hexagonal base lines.
C     THL     =4         Max L for tetragonal and hexagonal base lines.
C
C                        OBS. The program will only generate
C                        H greater than or equal to K for these lines.
C
C     THS     =4         Max H+K+L for these lines.
C
C                        OBS. If THS=0 tetragonal and hexagonal tests
C                             omitted.
C
C                        OBS. The tetragonal and hexagonal base lines 
C                             are (1,2),(1,3) and (2,3)
C
C                        * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     OH1     =2         Max H for the first orthorhombic base line.
C     OK1     =2         Max K for the first orthorhombic base line.
C     OL1     =2         Max L for the first orthorhombic base line.
C
C                        OBS. The program will only generate 
C                             H greater than or equal to K, and
C                             K greater than or equal to L for this line.
C                             This is also valid if the SELECT parameter
C                             is used. (See below).
C
C     OS1     =3         Max H+K+L for this line.
C
C                        OBS. If OS1=0 orthorhombic test omitted.
C
C     OH2     =2         Max H for the second orthorhombic base line.
C     OK2     =2         Max K for the second orthorhombic base line.
C     OL2     =2         Max L for the second orthorhombic base line.
C     OS2     =4         Max H+K+L for this line.
C
C     OH3     =2         Max H for the third orthorhombic base line.
C     OK3     =2         Max K for the third orthorhombic base line.
C     OL3     =2         Max L for the third orthorhombic base line.
C     OS3     =4         Max H+K+L for this line.
C
C                        OBS. The orthorhombic base lines are
C                        (1,2,3) (1,2,4) (1,2,5) (1,3,4) (2,3,4) and (1,2,6)
C                        if SELECT0=0 (See SELECT below)
C
C                        * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     MH1     =2         Max Abs(H) for the first monoclinic base line.
C     MK1     =2         Max K for the first monoclinic base line.
C     ML1     =2         Max L for the first monoclinic base line.
C
C                        OBS. The program will only generate
C                             H greater than or equal to L for this line.
C                             EQ. TO L FOR THIS LINE.
C                             This is also valid if SELECT is used.
C                             (See SELECT below)
C
C     MS1     =2         Max Abs(H)+K+L for this line
C                        The normal (and fast) way to test an expected cell
C                        axis is to put it in as SQ number one (in card set
C                        two) and set MH1=1, MK1=1, ML1=0 and MS1=1    
C
C     MH2     =2         Max Abs(H) for the second monoclinic base line.
C     MK2     =2         Max K for the second monoclinic base line.
C     ML2     =2         Max L for the second monoclinic base line.
C     MS2     =3         Max Abs(H)+K+L for this line.
C
C     MH3     =2         Max Abs(H) for the third monoclinic base line.
C     MK3     =2         Max K for the third monoclinic base line.
C     ML3     =2         Max L for the third monoclinic base line.
C     MS3     =3         Max Abs(H)+K+L for this line.
C
C     MH4     =2         Max Abs(H) for the fourth monoclinic base line.
C     MK4     =2         Max K for the fourth monoclinic base line.
C     ML4     =2         Max L for the fourth monoclinic base line.
C     MS4     =4         Max Abs(H)+K+L for this line.
C
C                        OBS. The monoclinic base lines are
C                        (1,2,3,4) (1,2,3,5) and (1,2,4,5)
C                        If SELECT is less than 6. (See SELECT below)
C
C
C     MONOSET =0         This parameter makes it possible to use more than 3
C                        base line sets in the monoclinic trials.
C                        If MONOSET is:
C                        Greater than 3, base line set (1,3,4,5) will be used
C                        Greater than 4, base line set (1,2,3,6) will be used
C                        Greater than 5, base line set (2,3,4,5) will be used
C                        Greater than 6, base line set (1,2,3,7) will be used
C                        Thus max 7 base line sets can be used.
C                        In N-TREOR (=STREOR), TREOR99 and TREOR90 modes
C                        MONOSET is fixed = 7
C
C     MONOGAM=1          The best 5 (in N-TREOR 10) trial parameter sets      
C                        stored (See IQ) for each base line set will be
C                        refined before next base line set is tested.
C
C                        If MONOGAM=0 all base line sets are tried before
C                        any refinement is made.
C
C                        MONOGAM is only used in monoclinic tests.
C
C                        It is recommended to use MONOGAM=1 because a refined
C                        cell parameter set is always tested for the stop
C                        limits NIX and MERIT. Thus CPU-time may be saved.
C
C     MONO    =0         Max beta angle allowed in a cell.
C                        OBS. No monoclinic test if MONO=0
C                        (See also SHORT)
C                        In N-TREOR (=STREOR), TREOR99 and TREOR90 modes
C                        MONO is fixed = 135
C
C     SHORT   =1         Short axis test.
C                        The parameter is only used for monoclinic tests.
C                        The first six lines are tested for the occurrence
C                        of a common zero index in the six first lines.
C                        If SHORT=0 no short axis test.
C                        If you want to make this test without repeating
C                        other monoclinic tests, you may give MONO a
C                        negative sign.
C                        
C
C
C                        * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     USE     =19       -or equal to the number of input lines if there are
C                        less than 19 lines,
C                       -or equal to the number of lines with sine square
C                        thetas less than 0.327
C                       -USE is the number of lines used in the trial-indexing
C                        part of the calculations.
C
C                        OBS. Max USE=20
C
C                        OBS. If you want to change USE, you should also
C                        change IQ. (See IQ).
C
C     IQ      =USE-3     The number of indexable lines required in the trial-
C                        indexing procedure if the cell should be stored for
C                        ev. least-squares refinement.
C                        These reciprocal cell parameters are printed if 
C                        LIST=1
C
C     LIST    =0         See IQ above.
C
C     SELECT  =-1        In N-TREOR (=STREOR) and TREOR99  SELECT must be -1 
C
C                        If you want to avoid the TREOR99 mode (but why ?..)
C                        set SELECT=0 or...
C                      
C                        if SELECT is positive the orthorhombic base lines
C                        are (SELECT,1,2) (SELECT,1,3) and (SELECT,2,3) or..
C
C                        if SELECT is greater than 5 the monoclinic base lines
C                        are (SELECT,1,2,3) (SELECT,1,2,4) and (SELECT,1,3,4)
C
C                        (Positive SELECT can not be used in TREOR99 mode.)
C
C
C     MERIT   =10        The De Wolff figure of merit required as stop limit.
C                        Ref:   De Wolff,P.M.   J. Appl. Crystallogr.
C                        1 (1968) 108-113
C                        ( For cubic, tetragonal and hexagonal symmetries
C                        are the different quadratic forms as given in
C                        Int. Tabl. of X-Ray Crystallogr. (1968) Vol.2
C                        p.109-145 used in the calculation of the number of
C                        theoretical lines.)
C        
C                        OBS. The figure of merit calculations are not
C                        strictly valid unless all 20 first lines are indexed.
C
C
C     NIX     =1         If a cell after least squares refinemnet has a figure
C                        of merit equal to or greater than MERIT and the
C                        number of not indexable lines among the USE first
C                        lines is less than or equal to NIX, the calculations
C                        are stopped.
C
C                        OBS. Otherwise he calculations will end with a
C                             difference analysis (Program I1.  Werner,P.-E.
C                             Z.Kristallogr. 120 (1964) 375-378)
C                             (Now not very useful list. --'historical')
C
C     IDIV    =1         The 7 first lines are adjusted by (eventually
C                        occurring) higher order lines.
C                        If IDIV=0 no corrections.
C                        Usually the default value 1 is o.k. There are
C                        exeptions, however.   If indexing is not
C                        successful, you may try IDIV=0
C
C     WAVE    =1.5405981 Wave length. (in Angstroem)
C                        As a rule one should not change WAVE
C                        If D-values are used in the input data file (See
C                        CHOICE=4) one can always pretend that WAVE was
C                        1.5405981 A. WAVE is then a formal parameter only
C                        related to D1, SSQTL and D2 (See below).
C
C     VOL     =2000      Max cell volume (in Angstroem**3)
C                        A new option available in TREOR90 is to give a
C                        negative value of VOL, ex. VOL=-2000. 
C                        See comments number 16 on the top of this list.
C                     
C     CEM     =25        Max cell edge (in Angstroem)
C                        The CPU-time depends on VOL and CEM
C
C     D1      =0.0002    (if WAVE=1.5405981) See D2 below.
C
C     SSQTL   =0.05      (if WAVE=1.5405981)  See D2 below.
C
C     D2      =0.0004    (if WAVE=1.5405981)
C                        A line is regarded as indexed if..
C                        sine square theta is less than SSQTL and
C                        Abs(sine square theta observed minus sine square
C                        theta calculated) is less than D1 or...
C                        if sine square theta is greater than SSQTL and
C                        the corresponding difference is less than D2.
C                        D1, SSQTL and D2 are used in the trial indexing
C                        part as well as in the least squares refinements
C                        If SELECT=-1 are D1, SSQTL and D2 automatically 
C                        multiplied by the factor (WAVE/1.5405981)**2
C                        (i.e. D1, SSQTL and D2 depend on WAVE)
C
C
C     CHOICE  =4         Indicator defining SQ on card set two..
C                        CHOICE=0   SQ=Sine square theta
C                              =1   SQ=1/(D*D)    (D-spaceing in Angstroem)
C                              =2   SQ=Theta      (Theta=Bragg angle in deg.)
C                              =3   SQ=2*Theta
C                              =4   SQ=D
C                        OBS next line...
C                        Default value in earlier TREOR-versions was 0 
C
C
C     DENS    =0         Density. (DENS=0 density not used.)
C                        If only an integral number of molecules in the unit
C                        cell is accepted DENS, EDENS and MOLW may be used.
C                        (On your own responsibility)
C                        DENS = density in gram per cm**3
C
C     EDENS   =0         Not used unless DENS equals non zero.
C                        EDENS= Max deviation in DENS.
C                        OBS. DENS and EDENS are used in trial calculations
C                        i.e. they are used on non refined unit cells.
C                        Therefore, do not use too small EDENS
C                        
C     MOLW    =0         Not used unless DENS ( and EDENS ) are non zero.
C                        Mol. weight in A.U. (OBS. Crystal water included.)
C                        It is not recommended to use DENS, EDENS and MOLW
C
C
C     TRIC     =0        No triclinic test. 
C                        If TRIC=1 all higher symmetry tests are omitted and
C                        a triclinic test is made.
C                        It is presupposed that all higher symmetries have
C                        been tried in earlier runs.
C                        Although it is in principle possible to index any
C                        pattern as triclinic, the indexing algorithm used
C                        here is not effective for higher symmetries.
C                        OBS. See comment 7 on the top of this list.
C                        TRIC is not used in N-TREOR (=STREOR), TREOR99 and
C                        TREOR90 modes.
C
C
C     ZEROSET  =0        This keyword may be given as an integer.
C                        ZEROSET*0.005 degrees are added to all theta-
C                        values (i.e. ZEROSET*0.01 deg. to all 2theta). 
C                        Example: If 2theta-zero at 0.05 deg., then set
C                        ZEROSET=-5
C                        In N-TREOR different zero point positions are
C                        automatically tested as explained under the 
C                        key-word LIMIT       
C
C     KREDUCT  =0        If KREDUCT is given, only trial solutions with
C                        IQ=USE-(KREDUCT-1) number of lines indexed may 
C                        be saved for trial-refinements.        
C                        OBS. If KREDUCT=0 (or is not given) IQ=USE-3
C                        (See keyword IQ above) 
C                        These reciprocal cell parameters are printed if
C                        LIST=1
C                        Thus, if KREDUCT=1 only trial-solutions where all
C                        lines are indexed will be saved for further tests.
C                          
C     LIMIT    =10       New key-word for program versions STREOR and NTREOR.
C                        Max. number of origin shifts.
C                        The program will ask for the theta-shift.
C                        Normal theta-shift is 0.01 deg. if wave=1.5406 A
C                        (i.e. 0.02 deg. in 2 theta)
C                        Tests will be made for origin theta-shifts until
C                           (LIMIT-1)*(theta-shift)
C                        Thus, if LIMIT=1, no origin shift will be tested.
C                        If you can expect that zero shift is negligible
C                        you may save a lot of computing time if LIMIT=1
C                        is used.
C                        
C
C     END*               This keyword denotes the end of the parameter list.
C                        (i.e. end of card set three)
C
C
C
C
C     C O M M E N T S   F O R   T H E   P R O G R A M M E R
C
C
C     THE FILES ARE OPENED IN THE MAIN PROGRAM (THE FIRST PROG). 
C     
C     THE LOGICAL UNITS ARE..
C     NUIT=9  THE CONDENSED OUTPUT FILE.
C     IIN=8   THE DATA INPUT FILE.
C     IOUT=7  THE OUTPUT FILE.
C     NDISP=6 OUTPUT (ON DISPLAY) OF TRIAL PARAMETERS IF KEYWORD LIST=1
C             (SEE KEYWORDS IQ AND LIST)
C     LKEY=5  KEY-BOARD.
C     THE LOGICAL UNIT NUMBERS 5,6,7,8 AND 9 ARE GIVEN IN THE MAIN PROGRAM
C     AND MAY BE CHANGED FOR YOUR COMPUTER. THEY NEED NOT BE CHANGED IN
C     ANY OTHER PLACE OF THE PROGRAM, HOWEVER.
C
C
C     THE PROGRAM IS MAINLY WRITTEN IN FORTRAN (II) AND (IV), BUT
C     FORTRAN 77 HAS BEEN USED TO SOME EXTENT. (SEE FOR EXAMPLE SUBROUTINE
C     TWODIM.)-IT IS THE INTENTION, HOWEVER, THAT IT SHOULD NOT BE
C     DIFFICULT TO REWRITE THE FORTRAN 77 STATEMENTS IF ONLY FORTRAN(IV)
C     IS AVAILABLE.
C     It may be recommended to use the WATCOM FORTRAN 77 compiler. 
C
C     VERSION 4 OF THE PROGRAM HAS BEEN DEVELOPED AT
C     STOCKHOLM UNIVERSITY USING A VAX 11/750 COMPUTER.
C     VERSION 5 WAS DEVELOPED FOR CONVEX 210, VAX 11/750 AND IBM PC/AT.
C     VERSION TREOR90 IS WRITTEN FOR CONVEX 210. A NON-VECTORIZED
C     VERSION IS ALSO AVAILABLE. TRICLINIC TESTS
C     MAY BE VERY TIMECONSUMING ON A VAX, HOWEVER. 
C
C     CALLS FROM THE MAIN PROGRAM ARE TO...
C     PWINL.....THE DATA INPUT ROUTINE.
C     TREOB.....THE TRIAL MODULE (THE MOST TIME-CONSUMING PART).
C     TREOC.....PROG. FOR DIFFERENCE ANALYSIS AND ORGANISATION FOR TREOD.
C     TREOD.....LEAST SQUARES REFINEMENTS OF THE BEST TRIAL CELLS.
C
C
........ E N D.........E N D...........E N D..........E N D.........