      SUBROUTINE pipe(ijet)

      IMPLICIT NONE

      INCLUDE 'param.txt'
      INCLUDE 'param2.txt'

      INTEGER ijet

      REAL dummy(0:pi1,0:pj1,0:pk1)
      REAL winmax,vinmax,uinmax

      REAL upipe(0:pi1,0:pj1,0:pk1)
      REAL vpipe(0:pi1,0:pj1,0:pk1)
      REAL wpipe(0:pi1,0:pj1,0:pk1)
      REAL drpipe
      INTEGER aup(0:i1)

      COMMON /indata/ upipe,vpipe,wpipe,drpipe,aup

c------------------------------------------------------------------------

      IF(1.EQ.1) THEN

c         OPEN(15,FILE='isopipe.dat',FORM='UNFORMATTED')

c         DO k=0,pkmax-1
c
c            READ(15)
c     $           ( (upipe(i,j,k), j=0,pj1), i=0,ijet),
c     $           ( (vpipe(i,j,k), j=0,pj1), i=0,ijet),
c     $           ( (wpipe(i,j,k), j=0,pj1), i=0,ijet)
c            
c         END DO
c         
c         CLOSE(15)
      upipe=0
      vpipe=0
      wpipe=1

      END IF



c      IF(1.EQ.0)THEN
c
c         OPEN(15,FILE='isopipe.dat')

c         DO k=0,pkmax-1
c            DO j=0,pj1
c               DO i=0,ijet
c
c                  READ(15,10) upipe(i,j,k),vpipe(i,j,k),wpipe(i,j,k)
c 10               FORMAT(3(E16.6))
c
c               END DO
c            END DO
c         END DO
c         
c         CLOSE(15)

c      END IF


      IF(1.EQ.0)THEN

c ************* If in = 0 read data from file ************************


         OPEN(15,FILE='pipe.dat',FORM='unformatted')

         do 100 k=0,pk1

            read(15)
     &           ( (Upipe(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (Vpipe(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (Wpipe(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (dummy(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (dummy(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (dummy(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (dummy(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (dummy(i,j,k) , j=0,pj1) , i=0,pi1),
     &           ( (dummy(i,j,k) , j=0,pj1) , i=0,pi1)

 100     continue
         
         close(15)

         
         winmax=0.0
         vinmax=0.0
         uinmax=0.0
         DO k=0,pk1
            DO j=0,pj1
               DO i=0,pi1
                  if(wpipe(i,j,k) .gt. winmax) winmax=wpipe(i,j,k)
                  if(vpipe(i,j,k) .gt. vinmax) vinmax=vpipe(i,j,k)
                  if(upipe(i,j,k) .gt. uinmax) uinmax=upipe(i,j,k)
               END DO
            END DO
         END DO

         DO k=0,pk1
            DO j=0,pj1
               DO i=0,pi1

                  wpipe(i,j,k) = 3.75*wpipe(i,j,k)/winmax
c               vpipe(i,j,k) = 1.75*vpipe(i,j,k)/winmax
c               upipe(i,j,k) = 1.75*upipe(i,j,k)/winmax

                  vpipe(i,j,k) = 3.75*vpipe(i,j,k)/vinmax
                  upipe(i,j,k) = 3.75*upipe(i,j,k)/uinmax

                  wpipe(i,j,k) = wpipe(i,j,k) + 1.0

               END DO
            END DO
         END DO

      END IF

      RETURN 
      END
