      PROGRAM infeff                                                    INFE001
c --------------------------------------------------------------------- INFE002
c     makes feff.inp input batch file from infeff.xyz output of sexie   INFE003
c      infeff.xyz is actually written in the subroutine priver.for      INFE004
c               see priver.for for revisions to infeff.xyz              INFE005
c --------------------------------------------------------------------- INFE006
c     VARIABLES:                                                        INFE007
c       nat   =  number of atoms in shell                               INFE008
c       x,y,z =  cartesion coordinates                                  INFE009
c       xnn   =  distance from central atom                             INFE010
c       el    =  element name                                           INFE011
c       iele  =  atomic number                                          INFE012
c       rmax  =  largest permitted radius                               INFE013
c                                                                       INFE014
c       Written by Anne Tabor-Morris - July 1991                        INFE015
c       Update and revison Bernhard Rupp Feb. 1994, 1997                INFE016
c --------------------------------------------------------------------- INFE017
      parameter (iat=20, ims=100, maxats=48)                            INFE018
c --- maximum number of atoms in shell is maxats = 48   (SEXIE limit)   INFE019
c     maximum number of shells to be read in ims = 100  (SEXIE limit)   INFE020
c     maximum number of inequivalent atoms iat   = 20   (SEXIE limit)   INFE021
c     NOTE : SEXIE limits need to be changed in all subroutines !       INFE022
c     (limits should be higher for low symmetry problems)               INFE023
                                                                        INFE024
      character inname*10,outname*9,el*2,revdat*8,icomp*4,ide*4,ipotid*4INFE025
      character doc*60,dc1*60,dc2*60,title*60,titlesg*60,ipotat*2       INFE026
c     character yesno*1                                                 INFE027
      logical exists                                                    INFE028
      dimension x (ims+1,maxats)                                        INFE029
      dimension y (ims+1,maxats)                                        INFE030
      dimension z (ims+1,maxats)                                        INFE031
      dimension ipot(ims+1),ipotat(iat+1),ipotid(iat+1),ipotel(iat+1)   INFE032
      dimension nat(ims+1),xnn(ims+1),ide(ims+1),ielec(ims+1),el(ims+1) INFE033
      inname='infeff.xyz'                                               INFE034
      outname='feff.inp'                                                INFE035
                                                                        INFE036
c --- revision comments and date here ----                              INFE037
c       revised 1/13/93 ATM                                             INFE038
c       revised 5/5/93  ATM add RMAX                                    INFE039
c       revised 12/93, 1/94   ATM clean up format                       INFE040
c       Checked 2/10/94, made consistent with SEXIE utilities BR        INFE041
      revdat='06/06/97'                                                 INFE042
                                                                        INFE043
c --- look for SEXIE configuration file and read the computer type --   INFE044
      inquire (file='SEXIE.CFG',exist=exists)                           INFE045
      if (exists) then                                                  INFE046
         open (4,file='SEXIE.CFG',status='old')                         INFE047
         do 8808 i=1,7                                                  INFE048
 8808       read (4,'(8x,a4)') icomp                                    INFE049
         read(4,'(8x,a4)')   icomp                                      INFE050
         call upstrg (icomp,4)                                          INFE051
         close(4,status='keep')                                         INFE052
      else                                                              INFE053
         write (*,'(/a)') '  Cannot find configuration file SEXIE.CFG'  INFE054
         write (*,*) ' Resume with 7-bit TTY terminal character set'    INFE055
         icomp  = '7BIT'                                                INFE056
      end if                                                            INFE057
                                                                        INFE058
c --- Initalize ----                                                    INFE059
      do 4 i=1,ims+1                                                    INFE060
          ipot(i)=0                                                     INFE061
          ielec(i)=0                                                    INFE062
          xnn(i)=0.                                                     INFE063
          nat(i)=0                                                      INFE064
          if(i.le.(iat+1)) then                                         INFE065
            ipotat(i)='  '                                              INFE066
            ipotid(i)='    '                                            INFE067
          end if                                                        INFE068
          do 1 j=1,maxats                                               INFE069
            x(i,j)=0.                                                   INFE070
            y(i,j)=0.                                                   INFE071
            z(i,j)=0.                                                   INFE072
1         continue                                                      INFE073
4     continue                                                          INFE074
                                                                        INFE075
c --- header ------                                                     INFE076
                                                                        INFE077
      call infhed (revdat,icomp)                                        INFE078
                                                                        INFE079
c --- initialize and inquire radius of cluster ---                      INFE080
c --- the maximum radius should be set higher depending of FEFF limits -INFE081
      rmax = 12.0                                                       INFE082
 9010 write (*,'(/a,f4.1,a$)')                                          INFE083
     &      ' Please enter maximum cluster radius [limit RMAX = ',rmax, INFE084
     &      ' Angstroms] : '                                            INFE085
      read(*,*,err=9010) rrmax                                          INFE086
      if (rrmax.gt.rmax) then                                           INFE087
         write (*,'(a,f4.1)') ' Rmax exceeds limit - reduced to ',rmax  INFE088
      else                                                              INFE089
         rmax=rrmax                                                     INFE090
      end if                                                            INFE091
c --- SHELL GAME for those who prefer to be asked how many shells  ---  INFE092
c      ims=3                                                            INFE093
c      print 90,'Are 3 shells sufficient? [y or n] '                    INFE094
c      read(*,*) yesno                                                  INFE095
c      if (yesno.eq.' ') yesno='y'                                      INFE096
c      if (yesno.eq.'n') then                                           INFE097
c        write(*,'(a)')' How many shells do you want? [Max='12] '       INFE098
c        read(*,*) ims                                                  INFE099
c        if (ims.gt.12) ims=12                                          INFE100
c      endif                                                            INFE101
c --- END SHELL GAME ---                                                INFE102
                                                                        INFE103
c --- read file infeff.xyz ---------------                              INFE104
      open (5,file=inname,status='old')                                 INFE105
      read (5,'(a60)') dc1                                              INFE106
      read (5,'(a60)') title                                            INFE107
      read (5,'(a60)') titlesg                                          INFE108
c --- loop over all shells up to ims +1 ---                             INFE109
      do 44 i=1,ims+1                                                   INFE110
         read (5,'(a60)',end=45,err=9009) doc                           INFE111
         read (5,'(a60)',end=45,err=9009) dc2                           INFE112
c ---    read how many atoms in this shell ----                         INFE113
         read (5,*) nat(i)                                              INFE114
c ---    loop over all atoms in this shell ----                         INFE115
         do 11 j=1,nat(i)                                               INFE116
            read (5,*)x(i,j)                                            INFE117
            read (5,*)y(i,j)                                            INFE118
            read (5,*)z(i,j)                                            INFE119
11       continue                                                       INFE120
         read (5,*) xnn(i)                                              INFE121
         read (5,'(1x,a2,1x,a4)') el(i),ide(i)                          INFE122
         read (5,*) ielec(i)                                            INFE123
                                                                        INFE124
c ---    sort the atom kinds for potential ----                         INFE125
c        if element and crystallographic position equivalent, then      INFE126
c        assign the same potential flag                                 INFE127
         ihits=0                                                        INFE128
         if (i.le.2) then                                               INFE129
c           put first and second shell in potential list                INFE130
            ipot(i)=i                                                   INFE131
            ipotat(i)=el(i)                                             INFE132
            ipotid(i)=ide(i)                                            INFE133
            ipotel(i)=ielec(i)                                          INFE134
            ipots=2                                                     INFE135
         else                                                           INFE136
c           check if we have new atom already in potential list         INFE137
            do 0012 ii=2,ipots                                          INFE138
               if((el(i).eq.ipotat(ii)).and.(ide(i).eq.ipotid(ii)))then INFE139
                 ihits=1                                                INFE140
                 ipot(i)=ii                                             INFE141
               end if                                                   INFE142
0012       continue                                                     INFE143
           if (ihits.eq.0) then                                         INFE144
              ipots=ipots+1                                             INFE145
              ipot(i)=ipots                                             INFE146
              ipotat(ipots)=el(i)                                       INFE147
              ipotid(ipots)=ide(i)                                      INFE148
              ipotel(ipots)=ielec(i)                                    INFE149
           end if                                                       INFE150
         end if                                                         INFE151
         if (xnn(i).gt.rmax) goto 45                                    INFE152
44    continue                                                          INFE153
45    close (5)                                                         INFE154
c --- decrement loop counter ---                                        INFE155
      imax=i-1                                                          INFE156
c --- screen output ----                                                INFE157
      write (*,'(/a,i3)')' Number of shells read (incl.cental atom) : ',INFE158
     &                    imax                                          INFE159
      write (*,'(a,f7.4)') ' Radius of last shell read : ',xnn(i-1)     INFE160
      write (*,'(a,i2/)') ' Number of inequivalent potentials found : ',INFE161
     &                     ipots                                        INFE162
                                                                        INFE163
c --- write output file                                                 INFE164
      open (6,file=outname, status='unknown')                           INFE165
      write (6,*)'***************************************************'  INFE166
      write (6,*)'*       FEFF input file generated by SEXIE        *'  INFE167
      write (6,*)'***************************************************'  INFE168
      write (6,'(a9,a2,a1,a2,a1,a2,a1,I2,a,f4.1)') ' TITLE   ',         INFE169
     &   el(1),'-',el(2),'-',el(3),' ',imax-1,' shells FEFF Rmax -',rmaxINFE170
      write (6,*)'TITLE  ',title                                        INFE171
      write (6,*)'TITLE  ',titlesg                                      INFE172
      write (6,*)'RMAX  ',rmax,'            Max. radial distance'       INFE173
      write (6,*)'HOLE      1     1.0              ihole(1=K), s02'     INFE174
      write (6,*)'*NOGEOM                          Use own geom.dat'    INFE175
      write (6,*)'*DEBYE    0     0                T(K), Debye-Temp'    INFE176
      write (6,*)'*** (or change Debye-Waller factors in files.dat &)'  INFE177
      write (6,*)'***    CONTROL   0      0      0      1'              INFE178
      write (6,*)'CONTROL   1      1      1      1'                     INFE179
      write (6,*)'*PRINT    0      0      0      0'                     INFE180
      write (6,*)'*      mphase  mpath  mfeff  mchi'                    INFE181
      write (6,*)'* '                                                   INFE182
      write (6,*)'*KLIMIT  0     15                Default k=0-20'      INFE183
      write (6,*)'*NLEG          8                 (2=single sc.only)'  INFE184
      write (6,*)'*RMULTIPLIER   1.0               Mult atomic coord.'  INFE185
      write (6,*)'*CRITERIA      6.0  3.0          Curve 6%, Plane 3%'  INFE186
      write (6,*)'* '                                                   INFE187
      write (6,*)' '                                                    INFE188
c --- potential list ---                                                INFE189
      write (6,*)'POTENTIALS'                                           INFE190
      write (6,*)'*  ipot    Z    atom    atom_Id '                     INFE191
      do 0013 i=1,ipots                                                 INFE192
         write(6,'(4x,i2,4x,i3,4x,A,6x,a)') i-1,ipotel(i),ipotat(i),    INFE193
     &                                      ipotid(i)                   INFE194
 0013 continue                                                          INFE195
      write (6,*) ' '                                                   INFE196
c --- atom list ---                                                     INFE197
      write (6,*)'ATOMS '                                               INFE198
      write (6,*)                                                       INFE199
     &'*       x       y        z      ipot   atom    dist     atom_Id' INFE200
      write (6,*)' '                                                    INFE201
c --- loop over all shells                                              INFE202
      do 444 i=1,imax                                                   INFE203
c --- and print all atoms of the shell                                  INFE204
        do 111 j=1,nat(i)                                               INFE205
           write (6,'(4x,3f8.4,4x,i2,6x,A,3x,f8.4,4x,a4)')              INFE206
     &            x(i,j),y(i,j),z(i,j),ipot(i)-1,el(i),xnn(i),ide(i)    INFE207
111     continue                                                        INFE208
444   continue                                                          INFE209
      write (6,*) 'END'                                                 INFE210
      close (6)                                                         INFE211
      stop                                                              INFE212
 9009 write (*,'(/a,a,a/)') ' Error reading ', inname,' - please check' INFE213
      end                                                               INFE214
      subroutine infhed(revdat,icomp)                                   INFH001
c ----------------------------------------------------------------------INFH002
c     cranks out a header box page for INFEFF                           INFH003
c ----------------------------------------------------------------------INFH004
c     This program module is part of the PhysiSoft X-ray Library        INFH005
c     and may not be sold or reproduced for commercial purposes.        INFH006
c     Although it has been tested carefully, there is no warranty       INFH007
c     regarding accuracy or freedom from side-effects.                  INFH008
c                   (C) 1986-1990 Bernhard Rupp                         INFH009
c ----------------------------------------------------------------------INFH010
      parameter (ipr=6)                                                 INFH011
                                                                        INFH012
      character lv,revdat*8,icomp*4                                     INFH013
                                                                        INFH014
      if (icomp.eq.'IBM ') then                                         INFH015
         lv=char(179)                                                   INFH016
      else                                                              INFH017
         lv='|'                                                         INFH018
      end if                                                            INFH019
                                                                        INFH020
      call frames (ipr,1,icomp)                                         INFH021
      write(ipr,'(1x,a1,25x,a,25x,a1)')lv,'P R O G R A M   I N F E F F',INFH022
     &     lv                                                           INFH023
      call frames (ipr,2,icomp)                                         INFH024
      write(ipr,'(1x,a1,9x,a,a,9x,a1)')lv,'Creates input file for FEFF',INFH025
     & ' calculation of EXAFS scattering',lv                            INFH026
      write(ipr,'(1x,a1,11x,a,a,12x,a1)')lv,'from structural output de',INFH027
     & 'coded by SEXIE 5.3(C) 1988-97',lv                               INFH028
      write(ipr,'(1x,a1,24x,a,24x,a1)')lv,                              INFH029
     &  'Anne Tabor-Morris and B. Rupp',lv                              INFH030
      write(ipr,'(1x,a1,20x,a,a,a,21x,a1)')                             INFH031
     & lv,icomp,' Version 5.3 , Revision ',revdat,lv                    INFH032
      call frames (ipr,2,icomp)                                         INFH033
      write(ipr,'(1x,a1,24x,a,25x,a1)')                                 INFH034
     &  lv,' Interactive Input Routine  ',lv                            INFH035
      call frames (ipr,3,icomp)                                         INFH036
      return                                                            INFH037
      end                                                               INFH038
