• Re: Read from scratch file

    From gah4@21:1/5 to Beliavsky on Sat Mar 12 10:05:09 2022
    On Saturday, March 12, 2022 at 9:59:24 AM UTC-8, Beliavsky wrote:
    How do you read from a scratch file you have created? Running the program

    program scratch_file
    implicit none
    integer, parameter :: inu = 10, outu = 11
    integer :: i
    open (unit=inu,status="scratch",action="write")
    write (inu,*) 42
    ! close (inu) ! activating this line does not help
    open (unit=outu,status="scratch",action="read",position="rewind")
    read (outu,*) i
    print*,"i =",i
    end program scratch_file

    Tradition is that when you close a scratch file, it goes away.
    You get a new one next time you open one.

    Otherwise:

    WRITE, REWIND, READ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Beliavsky@21:1/5 to All on Sat Mar 12 09:59:21 2022
    How do you read from a scratch file you have created? Running the program

    program scratch_file
    implicit none
    integer, parameter :: inu = 10, outu = 11
    integer :: i
    open (unit=inu,status="scratch",action="write")
    write (inu,*) 42
    ! close (inu) ! activating this line does not help
    open (unit=outu,status="scratch",action="read",position="rewind")
    read (outu,*) i
    print*,"i =",i
    end program scratch_file

    I get a run-time error with gfortran of

    At line 9 of file xscratch.f90 (unit = 11, file = 'C:\Users\myname\AppData\Local\Temp\gfortrantmpsHeKcN')
    Fortran runtime error: End of file

    and something similar for Intel Fortran.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Beliavsky@21:1/5 to All on Sat Mar 12 10:14:02 2022
    On Saturday, March 12, 2022 at 1:05:12 PM UTC-5, gah4 wrote:

    Tradition is that when you close a scratch file, it goes away.
    You get a new one next time you open one.

    Otherwise:

    WRITE, REWIND, READ

    Got it, thanks. The following program works:

    program scratch_file
    implicit none
    integer, parameter :: iu = 10, n = 25
    integer :: i,isq(n)
    open (unit=iu,status="scratch")
    write (iu,"(i0)") (10*i**2,i=1,n)
    rewind (iu)
    read (iu,*) isq
    print*,isq([1,n]) ! 10 6250
    end program scratch_file

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to Beliavsky on Sat Mar 12 11:25:47 2022
    On Saturday, March 12, 2022 at 1:14:04 PM UTC-5, Beliavsky wrote:
    On Saturday, March 12, 2022 at 1:05:12 PM UTC-5, gah4 wrote:

    Tradition is that when you close a scratch file, it goes away.
    You get a new one next time you open one.

    Otherwise:

    WRITE, REWIND, READ
    Got it, thanks. The following program works:

    program scratch_file
    implicit none
    integer, parameter :: iu = 10, n = 25
    integer :: i,isq(n)
    open (unit=iu,status="scratch")
    write (iu,"(i0)") (10*i**2,i=1,n)
    rewind (iu)
    read (iu,*) isq
    print*,isq([1,n]) ! 10 6250
    end program scratch_file

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to All on Sat Mar 12 11:28:57 2022
    If you are planning on making extensive use of scratch files, there are some additional details at

    https://fortranwiki.org/fortran/show/Scratch+Files

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)