-1
  INTEGER,PARAMETER :: nlv=6
   INTEGER,DIMENSION(nlv) :: aa,bb,cc,dd,ee,ff,gg
   INTEGER::rec,irec

OPEN(50,FILE=test.txt',FORM='formatted',ACCESS='sequential',STATUS='old',ACTION='READ')

OPEN(60,FILE='test.bin',FORM='unformatted',ACCESS='direct',STATUS='unknown',recl=6*4,ACTION='WRITE')

DO K=1,6

  READ(50,76,err=97)aa(k),bb(k),cc(k),dd(k),ee(k),ff(k),gg(k)

76 FORMAT(i2,1x,i5,1x,i6,1x,i5,1x,i5,1x,i5,1x,i5)

  END DO


  WRITE(60,rec=irec)dd

  irec=irec+1

97 WRITE(* *)ERROR FOUND while reading data

  WRITE(*,*)"End of file found"

  CLOSE (50)
Deva
  • 1
  • 2
  • Tidy up your code so we can understand it more easily. Make sure that it is a [mcve]. And tell us exactly what error message(s) you get. – High Performance Mark Sep 04 '19 at 12:48
  • please explain my problem – Deva Sep 06 '19 at 06:09
  • If anyone knows the answer, please respond. – Deva Sep 06 '19 at 11:48
  • 2
    @Deva You should first make the effort to tidy up your question. Half of your code is formatted as code, the other half is not. But foremost, you cannot just say *"it I am also getting error"*. You **must** give us the error message. You must exactly describe your problem. Now people are just guessing and that is not the right thing to do. – Vladimir F Героям слава Sep 09 '19 at 09:20

1 Answers1

0

I am guessing that when you use direct access, the size of the record has to match or be bigger the size of data you are writing. You claim record length=6 (in bytes?), but you are writing 6*4bytes=24bytes.

Akhdiyor
  • 41
  • 4
  • Several compilers indicate the record size in words, not in bytes https://stackoverflow.com/questions/43898711/how-to-access-a-single-record-with-fortran-unformatted-direct-access-when-the-ap – Vladimir F Героям слава Sep 09 '19 at 09:18
  • yes, you are right, looks Intel FORTRAN goes with 4 byte and with assume byterecl compiler option for 1 byte. I use gfortran (f95), tested it, write works if record length>23. So for gfortran it is 1 byte. – Akhdiyor Sep 09 '19 at 10:12