      SUBROUTINE rtoi(real_v, int_v, n)
C                                                                               
C**** SUBROUTINE rtoi - To convert from 64-bit REAL to INTEGER
C                                                                               
C        S.Saarinen     ECMWF     27/6/95                                  
C                                                                               
C**   INTERFACE                                                                 
C     ---------                                                                 
C                                                                               
C        CALL rtoi(real_v, int_v, n)
C     WHERE:
C           real_v = 64-bit REAL-vector (INPUT) of n elements
C                    each holding one integer value
C           int_v  = Integer vector (OUTPUT) of n elements:
C                    Only 32-bit range is accepted i.e.
C                    [-2147483648 ... 2147483647] which is the same as
C                    [-2**31 ... 2**31 - 1]
C           n      = length of the vectors
C                                                                               
C                                                                               
C-----------------------------------------------------------------------        
C                                                                               
      implicit none
      integer n
c-- The following MUST be 64-bit REALs [i.e. REAL(8) on Fortran-90]
      real  real_v(n)
      integer int_v(n)
      integer i

      do i=1,n
!J       int_v(i) = min(max(-2147483647,int(real_v(i))),2147483647)
         int_v(i) = int(min(max(-2000000000.0,real_v(i)),2000000000.0))
      enddo

      return
      END
