c===============================================================================
c
c	WAVE_FORMAT
c
c	reads and reformats "wave.dat"
c	reads sizf and nchunks now from
c	wave_format6.in !!!
c
c===============================================================================

	IMPLICIT NONE

	REAL*8 WAVEN(99,9999),WAVEL(99,9999)

	INTEGER i,j,k
	INTEGER sizf,nchunks
	INTEGER count
	CHARACTER*3 dummi

c================================================================================

	OPEN(42,file='wave_format6.in')
	READ(42,*) sizf
	READ(42,*) nchunks
	CLOSE(42)

	WRITE(*,*)'--- wave_format6: sizf= ',sizf
	WRITE(*,*)'--- wave_format6: nchunks= ',nchunks

c	sizf=475
c	nchunks=42
	count=0

	OPEN(01,file='wave.dat',type='old')

	DO i=1,nchunks

		DO j=1,sizf	

		READ(01,119) dummi,WAVEN(i,j),WAVEL(i,j) 
		count=count+1	
		END DO

	END DO

	CLOSE(01)

       WRITE(*,*) count,' wavenumbers & wavelengths read...'    

	count=0

	OPEN(02,file='wave2.dat')

	DO i=1,nchunks
 
                DO j=sizf,1,-1
 		count=count+1
                WRITE(02,129) count,WAVEN(i,j),WAVEL(i,j)
		
                END DO
 
        END DO

	CLOSE(02)
	WRITE(*,*) count,' wavenumbers & wavelengths written...'

c================================================================================
 119    FORMAT(A3,1X,E25.15,1X,E25.15)    
 129	FORMAT(I5,1X,E25.15,1X,E25.15)

	END
