0
votes

I was trying to test my cryptography algorithm by [diehard tests] (http://stat.fsu.edu/pub/diehard/), that I realized my input file must be an unformatted and direct access file. So I tried to write a simple program in Fortran to read from a file and write it to another.

First of all, is it the only way to make an unformatted or direct access file ?

If it is so, I've got this Error

     open(unit=2, file='unf.BIN',RECL=rl , form='UNFORMATTED', access='direct')
                                                                 1

Error: Syntax error in OPEN statement at (1)

I use RECL because of some missing RECL parameter in Open statement errors.(Fortran 90, Compiling program: Error messages)

Here is my Fortran code:

    program BinaryWriter
    implicit none

    integer :: i
    integer :: p

    open(unit=1,file='encout')
    open(unit=2, file='unf.BIN',RECL=rl , form='UNFORMATTED', access='direct')

    do i=1 ,256
        read (8,'(i1)') p
        write(*,*) p
    end do

    close(1)
    close(2)

    end program BinaryWriter
1
Is your file free form or fixed form, and what is the extension of the filename? My guess is that you have fixed form source, and the line with the open statement is too long. - IanH
You're right, @IanH -- that would explain the weird position of the 1 to. - chw21

1 Answers

1
votes

Two things:

1) Please stop using unit numbers less than 10. Virtually all modern Fortran compilers do now have the newunit identifier, which, instead of the old unit actually picks an unused value, so always use a variable there. But even if you want to use unit, set it to a value of 10 or more.

2) For direct access, the program needs the record length. So if you have access="direct", you also need an recl=<some integer value> to tell the compiler where a new record starts.

Now in your case, you have a RECL=rl entry in the open statement, but I can't see what rl is. It needs to be a positive integer.

Edit to add: As @IanH pointed out in a comment below your question, it is possible that you are using fixed form fortran. This might be caused by the file extension of your source code file being .f or .f77. In that case, you'd have to wrap your lines manually:

      program dir
      implicit none
      integer :: rl

      open(unit=20, file='delme.bin', recl=<the record length>, 
     &     form='unformatted', access='direct')
      close(20)
      end program dir

Note that the & is in the 6th position of the line. Fortran 77 code usually uses a + there, but & is also compatible with newer Fortran versions, that's why I prefer it. F77 standard is just any character in that 6th spot.