      subroutine getinp (title,elemt,ide,x,y,z,cel,iatom,igr,isearc,    GETI001
     &iwater,conang,condis,dmax,ispa,icalc,foc,bf,iat,disoct,iano,lambda      GETI002
     &,izell,lo,hi,loang,hiang,omit,bump,ipakin,ifiwnr,ipower,icharg,
     &jobnam)                                                           GETI003
                                                                        GETI004
c ----------------------------------------------------------------------GETI005
c     This program module is part of the author's X-ray Library         GETI006
c     and may not be sold or reproduced for commercial purposes.        GETI007
c     Although it has been tested carefully, there is no warranty       GETI008
c     regarding accuracy or freedom from side-effects.                  GETI009
c                   (C) 1986-1994 Bernhard Rupp                         GETI010
c ----------------------------------------------------------------------GETI011
c     GETINP reads the input cards from SEXIE.INP                       GETI012
c ----------------------------------------------------------------------GETI013
c     REVISION 4.0 : charge included in input data , format atom lines  GETI014
c     changed (A4,A4,4f8.5,I3)                                          GETI015
c     REVISION 4.1 : comment lines preceded with asterix allowed now    GETI016
c     REVISION 5.0 : format of atom lines is A22xa4,5f8.5,i3            GETI017
c                    iwater 0 : normal, no additional parameter line    GETI018
c                    follows                                            GETI019
c                    iwater 1 : water calculation, addtl. line follows  GETI020
c                    iwater 2 : read for crystal field calculation      GETI021
c                    iwater 3   structure factor calculation to follow  GETI022
c ----------------------------------------------------------------------GETI023
                                                                        GETI024
      character elemt*2,ide*4,title*60,star,jobnam*60                   GETI025
      logical exists                                                    GETI026
      real hi,lo,hiang,loang,omit,lambda                                GETI027
      dimension elemt(iat),ide(iat),x(iat),y(iat),z(iat),igr(36),cel(6) GETI028
      dimension icalc(iat),bf(iat),foc(iat)                             GETI029
                                                                        GETI030
      inquire(file='sexie.inp', err=7002,exist=exists)                  GETI031
c --- if not exists alarm ---                                           GETI032
      if (.not.exists) then                                             GETI033
         print*,' I can''t find a file SEXIE.INP - tilt'                GETI034
         stop 1                                                         GETI035
      end if                                                            GETI036
                                                                        GETI037
c --- open datafile for input - IBM  --                                 GETI038
      open (5,file='sexie.inp',err=7002,status='old')                   GETI039
                                                                        GETI040
c --- title -                                                           GETI041
 0001 read (5,'(a1)') star                                              GETI042
      if (star.eq.'*') then                                             GETI043
         goto 0001                                                      GETI044
      else                                                              GETI045
         backspace(5)                                                   GETI046
         read (5,'(a)') title                                           GETI047
      end if                                                            GETI048
                                                                        GETI049
c --- control parameters -                                              GETI050
      iwater=0
      iano=0
      lambda=0.0                                                        GETI051
 0002 read (5,'(a1)') star                                              GETI052
      if (star.eq.'*') then                                             GETI053
         goto 0002                                                      GETI054
      else                                                              GETI055
         backspace(5)                                                   GETI056
         read (5,*,err=9001) dmax,condis,isearc,conang,disoct,iwater    GETI057
      end if                                                            GETI058
                                                                        GETI059
c --- if iwater is set, read corresponding extra line --                GETI060
      if (iwater.eq.1) then                                             GETI061
 0102    read (5,'(a1)') star                                           GETI062
         if (star.eq.'*') then                                          GETI063
            goto 0102                                                   GETI064
         else                                                           GETI065
            backspace(5)                                                GETI066
            read (5,*,err=9001) izell,lo,hi,loang,hiang,omit,bump,ipakinGETI067
         end if                                                         GETI068
c --- this one for crystal field calculation ---                        GETI069
      elseif (iwater.eq.2) then                                         GETI070
 0112    read (5,'(a1)') star                                           GETI071
         if (star.eq.'*') then                                          GETI072
            goto 0112                                                   GETI073
         else                                                           GETI074
            backspace(5)                                                GETI075
            read (5,*,err=9001) ipower, icharg                          GETI076
            omit=dmax                                                   GETI077
            izell=1                                                     GETI078
            bump=1.2                                                    GETI079
         end if                                                         GETI080
      elseif (iwater.eq.3) then                                         GETI081
 0113    read (5,'(a1)') star                                           GETI082
         if (star.eq.'*') then                                          GETI083
            goto 0113                                                   GETI084
         else                                                           GETI085
            backspace(5)                                                GETI086
            read (5,'(2i7,1x,f8.6,1x,a)',err=9001) 
     &              iano,izell,lambda,jobnam                            PDB2186
            omit=dmax                                                   GETI088
            bump=1.2                                                    GETI090
         end if                                                         GETI091
      else                                                              GETI092
         ipower=2                                                       GETI093
         icharg=0                                                       GETI094
         omit=dmax                                                      GETI095
         izell=1                                                        GETI096
         bump=1.2                                                       GETI097
      end if                                                            GETI098
                                                                        GETI099
c --- cell constants -                                                  GETI100
 0003 read (5,'(a1)') star                                              GETI101
      if (star.eq.'*') then                                             GETI102
         goto 0003                                                      GETI103
      else                                                              GETI104
         backspace(5)                                                   GETI105
         read (5,*,err=9002) (cel(i),i=1,6)                             GETI106
      end if                                                            GETI107
                                                                        GETI108
c --- space group -                                                     GETI109
 0004 read (5,'(a1)') star                                              GETI110
      if (star.eq.'*') then                                             GETI111
         goto 0004                                                      GETI112
      else                                                              GETI113
         backspace(5)                                                   GETI114
         read (5,'(10a1,1x,i3)') (igr(i),i=1,10),ispa                   GETI115
      end if                                                            GETI116
      ibravl=ibrav(igr(1))                                              GETI117
                                                                        GETI118
                                                                        GETI119
c --- atom cards -  (A2,2x,A4,5f8.5,I3) - allow for 100 extra com lines GETI120
      iatom=0                                                           GETI121
c --- ifiwat defines first water encountered ---                        GETI122
      ifiwat=1                                                          GETI123
      do 0006 i=1,iat+100                                               GETI124
 0005    continue                                                       GETI125
         read (5,'(a1)',end=0007) star                                  GETI126
         if (star.eq.'*') then                                          GETI127
            goto 0005                                                   GETI128
         else                                                           GETI129
            backspace(5)                                                GETI130
            iatom=iatom+1                                               GETI131
c ---       generic read : x,y,z,foc always the same                    GETI132
c                          bf is either bfactor (iwater=3)              GETI133
c                                       charge  (iwater=2)              GETI134
            read (5,'(a2,2x,a4,5f8.5,i3)',end=0007,err=9003)            GETI135
     &      elemt(iatom),ide(iatom),x(iatom),y(iatom),z(iatom),         GETI136
     &      foc(iatom),bf(iatom),icalc(iatom)                           GETI137
c            write(*,'(1x,a2,2x,a4,5f8.5,i3)')                          GETI138
c     &      elemt(iatom),ide(iatom),x(iatom),y(iatom),z(iatom),        GETI139
c     &      foc(iatom),bf(iatom),icalc(iatom)                          GETI140
            if ((elemt(iatom).eq.'OH').and.(ifiwat.eq.1)) then          GETI141
               ifiwat=0                                                 GETI142
               read(ide(iatom),'(i4)') ifiwnr                           GETI143
               ifiwnr=ifiwnr-1                                          GETI144
            end if                                                      GETI145
            if ((ipakin.eq.1).and.(ifiwat.eq.0)) then                   GETI146
               read(ide(iatom),'(i4)') iresid                           GETI147
               iresid=iresid-ifiwnr                                     GETI148
               write(ide(iatom),'(i4)') iresid                          GETI149
            end if                                                      GETI150
c ---       make coordinates positive -                                 GETI151
            if (x(iatom).lt.0.0) x(iatom)=x(iatom)+1.0                  GETI152
            if (y(iatom).lt.0.0) y(iatom)=y(iatom)+1.0                  GETI153
            if (z(iatom).lt.0.0) z(iatom)=z(iatom)+1.0                  GETI154
c ---       check for coordinates outside the unit box --               GETI155
            if (x(iatom).gt.1.0) x(iatom)=x(iatom)-1.0                  GETI156
            if (y(iatom).gt.1.0) y(iatom)=y(iatom)-1.0                  GETI157
            if (z(iatom).gt.1.0) z(iatom)=z(iatom)-1.0                  GETI158
         end if                                                         GETI159
 0006 continue                                                          GETI160
 0007 continue                                                          GETI161
      close (unit=5,status='keep')                                      GETI162
      return                                                            GETI163
                                                                        GETI164
 7002 print*,'Cannot open input file SEXIE.INP - tilt'                  GETI165
      goto 9999                                                         GETI166
 9001 print*,'Error reading input - check control parameters card 2'    GETI167
      goto 9999                                                         GETI168
 9002 print*,'Error reading input - check cell constants card 3'        GETI169
      goto 9999                                                         GETI170
 9003 print*,'Error reading input - check atom cards and parameters'    GETI171
                                                                        GETI172
 9999 close (unit=5,status='keep')                                      GETI173
      stop                                                              GETI174
      end                                                               GETI175
