      PROGRAM F13TO15
C
C     COMPILE WITH -r8 OR EQUIVALENT
C
C     CONVERTER TO RECREATE FORT.15
C     FROM FORT.1[34] AFTER RELAXATION (OR DELETION!)
C
C *** AS FORT.13 IS A BINARY FILE, THE EXECUTABLE WILL BE
C            ARCHITECTURE SPECIFIC ***
C
C     INPUT: FORT.13, FORT.14
C            STDIN (NSPEC,NIONS,NKPTS,NBANDS) (AS IN PARAM.INC)
C
C     OUTPUT: fort.15.new
C             STDOUT (FFT GRID, CUT-OFF, NRPLWV)
C
C     MJR 29/9/95
C
      PARAMETER (NSPECMX=10,NIONSMX=20,NKPTMX=30,NBANDMX=50)
C
      DIMENSION DIRC(3,3),RECC(3,3),DIRI(3,3),RECI(3,3)
      DIMENSION POSIOL(3,NIONSMX,NSPECMX)
      DIMENSION POSION(3,NIONSMX,NSPECMX)
      DIMENSION RMOVE (NSPECMX*NIONSMX)
      DIMENSION NIONSP(NSPECMX*NIONSMX)
      DIMENSION ICHARG(NSPECMX*NIONSMX)
      DIMENSION POMASS(NSPECMX*NIONSMX)
      DIMENSION VKPT(3,NKPTMX)
      DIMENSION WTKPT(NKPTMX)
      DIMENSION CELEN(NBANDMX,NKPTMX)
C
C
      WRITE(*,*)' PLEASE INPUT NSPEC'
      READ(*,*)NSPEC
      IF (NSPEC.GT.NSPECMX) STOP 'INCREASE NSPECMX AND RECOMPILE'
C
C WE CAN NOW READ FORT.14, SO LET US DO SO
C
      OPEN (14,FORM='FORMATTED')
      REWIND 14
      READ (14,*) NITER
      READ (14,*) NPRINT
      READ (14,*) ENMAX
      READ (14,*) NLPOT
      READ (14,*) NITMAX
      READ (14,*) NDELAY
      READ (14,*) ISTART
      READ (14,*) ISBROT
      READ (14,*) IOCCUP
      READ (14,*) DELMIN
      READ (14,*) DELMAX
      READ (14,*) NDEL
      READ (14,*) IION
      READ (14,*) IBOX
      READ (14,*) IPRINT
      READ (14,*) NIONCG
      READ (14,*) NITFIX
      READ (14,*) INRAND
      READ (14,*) ICLOCK
      READ (14,*) SITIM
      READ (14,*) SIDAMP
      READ (14,*) SIMASS
      READ (14,*) SIDISP
      READ (14,*) POTIM
      READ (14,*) PODISP
      DO 452 NSP = 1 , NSPEC
        READ (14,*) IDUMMY
        ICHARG(NSP) = IDUMMY
 452  CONTINUE
      DO 454 NSP = 1 , NSPEC
        READ (14,*) DUMMY
        POMASS(NSP) = DUMMY
 454  CONTINUE
      DO 456 NSP = 1 , NSPEC
        READ (14,*) IDUMMY
        NIONSP(NSP) = IDUMMY
 456  CONTINUE
C
C CONSTRUCT SOME GUESSES
C
      NBANDS=0
      NIONS=0
      DO 111,I=1,NSPEC
        NBANDS=NBANDS+ICHARG(I)*NIONSP(I)
        IF (NIONSP(I).GT.NIONS) NIONS=NIONSP(I)
111   CONTINUE
      NBANDS=NBANDS/2
C
      WRITE(*,*)' PLEASE INPUT NIONS - ZERO FOR DEFAULT VALUE OF ',NIONS
      READ(*,*)DUMMY
      IF (DUMMY.NE.0) NIONS=DUMMY
      IF (NIONS.GT.NIONSMX) STOP 'INCREASE NIONSMX AND RECOMPILE'
      WRITE(*,*)' PLEASE INPUT NKPTS'
      READ(*,*)NKPTS
      IF (NKPTS.GT.NKPTMX) STOP 'INCREASE NKPTMX AND RECOMPILE'
      WRITE(*,*)
     &  ' PLEASE INPUT NBANDS - ZERO FOR DEFAULT ANSWER OF ',NBANDS
      READ(*,*)DUMMY
      IF (DUMMY.NE.0) NBANDS=DUMMY
      IF (NBANDS.GT.NBANDMX) STOP 'INCREASE NBANDMX AND RECOMPILE'
C
C=========================================================
C READ IN FORT.13 - ALL OF IT TO ENSURE IT IS LONG ENOUGH
C=========================================================
C
      OPEN (13,FORM='UNFORMATTED')
      REWIND(13)
      READ (13) ((DIRC(I,J), I=1,3), J=1,3)
      READ (13) VOLC
      READ (13) ((RECC(I,J), I=1,3), J=1,3)
      READ (13) ((DIRI(I,J), I=1,3), J=1,3)
      READ (13) (((POSIOL(I,J,K), I=1,3), J=1,NIONS), K=1,NSPEC)
      READ (13) (((POSION(I,J,K), I=1,3), J=1,NIONS), K=1,NSPEC)
      READ (13) (RMOVE(J), J=1,NIONS*NSPEC)
      READ (13) ((CELEN(I,J), I=1,NBANDS), J=1,NKPTS)
      READ (13) ((VKPT(I,J), I=1,3), J=1,NKPTS)
      READ (13) (WTKPT(I),I=1,NKPTS)
      READ (13) ENMAX
      READ (13) NGX,NGY,NGZ,NRPLWV
      READ (13) ((RECI(I,J), I=1,3), J=1,3)
C
C===================
C NOW TO WRITE OUT
C===================
C
      OPEN(17,FILE='fort.15.new')
      REWIND(17)
C
      WRITE(17,1001) DIRC(1,1), DIRC(2,1), DIRC(3,1)
      WRITE(17,1001) DIRC(1,2), DIRC(2,2), DIRC(3,2)
      WRITE(17,1001) DIRC(1,3), DIRC(2,3), DIRC(3,3)
C
      WRITE(17,1001) DIRI(1,1), DIRI(2,1), DIRI(3,1)
      WRITE(17,1001) DIRI(1,2), DIRI(2,2), DIRI(3,2)
      WRITE(17,1001) DIRI(1,3), DIRI(2,3), DIRI(3,3)
C
1001  FORMAT(3F18.13)
C
      NG=1
      DO 10,NSP=1,NSPEC
        DO 20,NI=1,NIONSP(NSP)
          WRITE(17,1002) (POSION(I,NI,NSP), I=1,3), RMOVE(NG)
          NG=NG+1
20      CONTINUE
C
        DO 30,NI=1,NIONSP(NSP)
          WRITE(17,1002) (POSIOL(I,NI,NSP), I=1,3)
30      CONTINUE
C
10    CONTINUE
1002  FORMAT(3F16.11,F5.1)
C
      DO 40,NKPT=1,NKPTS
        WRITE(17,1003)(VKPT(I,NKPT),I=1,3)
40    CONTINUE
1003  FORMAT(3F18.12)
C
      DO 50,NKPT=1,NKPTS
        WRITE(17,1004)WTKPT(NKPT)
50    CONTINUE
1004  FORMAT(F18.12)
C
      WRITE(*,*)' ALL DONE'
      WRITE(*,*)
      WRITE(*,*)' MISCELLANEOUS INFO:'
      WRITE(*,*)' FFT GRID: ',NGX,' x ',NGY,' x ',NGZ
      WRITE(*,*)' CUT-OFF:  ',ENMAX,' eV'
      WRITE(*,*)' NRPLWV:   ',NRPLWV
      STOP
      END
