      SUBROUTINE REOWAV
     1  (WDATA,QDATA,MEND1,NEND1,JEND1,MNWAV,KWMAX,KQMAX,KWW,KQQ,
     2   KMX2 ,LAG  ,IWORG,INOUT)
C
Crizvi      REAL*4 WDATA(KWMAX,MNWAV), QDATA(KQMAX,MNWAV)
      REAL WDATA(KWMAX,MNWAV), QDATA(KQMAX,MNWAV)
      INTEGER*4 LAG(MEND1,NEND1)
      CHARACTER*4 IWORG,INOUT
C
C  INOUT='IN  '...COPIES FROM WDATA TO QDATA
C        'OUT '...COPIES FROM QDATA TO WDATA
C  IWORG='CLMN'...DOES NOTHING
C        'DGNL'...CHANGES FROM DIAGONAL TO COLUMWISE ORDER
C
      IF(INOUT.EQ.'IN  ') THEN
C
             IF(IWORG.EQ.'CLMN') THEN
        DO 100 K=1,KMX2
        DO 100 L=1,MNWAV
         QDATA(K+KQQ,L)=WDATA(K+KWW,L)
  100   CONTINUE
        ELSE IF(IWORG.EQ.'DGNL') THEN
        L=0
        DO 200 M=1,MEND1
         NMAX=MIN(NEND1,JEND1+1-M)
        DO 200 N=1,NMAX
         L=L+1
         LX=LAG(M,N)
        DO 200 K=1,KMX2
         QDATA(K+KQQ,L)=WDATA(K+KWW,LX)
  200   CONTINUE
        END IF
C
      ELSE IF(INOUT.EQ.'OUT ') THEN
C
        IF(IWORG.EQ.'CLMN') THEN
        DO 300 K=1,KMX2
        DO 300 L=1,MNWAV
         WDATA(K+KWW,L)=QDATA(K+KQQ,L)
  300   CONTINUE
        ELSE IF(IWORG.EQ.'DGNL') THEN
        WRITE(96,*)'SUBR.REOWAV DOES NOT TAKE CARE OF DIAGONAL OUTPUT'
        STOP 9999
        END IF
C
      END IF
C
      RETURN
      END SUBROUTINE REOWAV

