        PROGRAM DOUBLE
C.....................................................................
C
C     READS IN UNFORMATTED PLOT3D-STYLE MESH (IN DOUBLE PRECISION),
C     CONVERTS IT TO SINGLE PRECISION, AND WRITES OUT THE RESULT
C
C.....................................................................
        
      IMPLICIT NONE
        
      INTEGER            :: NBLOCKS
      INTEGER,ALLOCATABLE:: IL(:),JL(:),KL(:)
      INTEGER            :: I,J,K,L,II,JJ,KK
      INTEGER            :: III,JJJ,KKK,N
      INTEGER            :: IREAD, IWRIT
      REAL*8,ALLOCATABLE :: X(:,:,:,:)
      REAL*4,ALLOCATABLE :: X1(:,:,:,:)
C
C --- ...................................................................      
C
      IREAD      = 18
      IWRIT      = 19
      OPEN (UNIT=IREAD,FILE='MESH.DOUBLE.PREC',FORM='UNFORMATTED')
      OPEN (UNIT=IWRIT,FILE='MESH.SNGL.PREC',FORM='UNFORMATTED')

C
C --- NUMBER OF BLOCKS
C        
      READ (IREAD) NBLOCKS
      WRITE(IWRIT) NBLOCKS
      WRITE(*,*) 'NBLOCKS...', NBLOCKS
C
C --- GRID DIMENSIONS FOR EACH BLOCK
C
      ALLOCATE(IL(NBLOCKS))
      ALLOCATE(JL(NBLOCKS))
      ALLOCATE(KL(NBLOCKS))
      READ(IREAD) (IL(I),JL(I),KL(I),I=1,NBLOCKS)
      WRITE(IWRIT)(IL(I),JL(I),KL(I),I=1,NBLOCKS)
C
C --- HANDLE MESH FOR EACH BLOCK
C        
      DO N=1,NBLOCKS
        II   = IL(N)
        JJ   = JL(N)
        KK   = KL(N)
        ALLOCATE(X(II,JJ,KK,3))
        READ(IREAD)  ((((X(I,J,K,L),I=1,II),J=1,JJ),K=1,KK),L=1,3)     
        ALLOCATE(X1(II,JJ,KK,3))
        X1     = SNGL(X)   ! CONVERT FROM DOUBLE PRECISION TO SINGLE PRECISION
        WRITE(IWRIT) ((((X1(I,J,K,L),I=1,II),J=1,JJ),K=1,KK),L=1,3)   
        DEALLOCATE(X)
        DEALLOCATE(X1)
        WRITE(*,*) 'BLOCK...',N,II,JJ,KK
      END DO 
C
      STOP
      END
