Skip to main content
  1. About
  2. For Teams
Asked
Viewed 342 times
1

I am opening a file which has to be deleted at the end. The following command complains about using dispose.

f = "espy.tmp";  h = "formatted";  r = "read" 
Open (newunit=u, file=f, form=h, action=r,  &
  status="old", dispose="delete")

lib/core.f:177:21:

     status="old", dispose="delete")
                 1
Error: Syntax error in OPEN statement at (1)
2
  • I'm wondering whether you're using an oder version of gfortran which doesn't yet know the newunit option. For example: I can't recreate this because mine doesn't know it yet.
    chw21
    –  chw21
    2015-05-06 10:22:51 +00:00
    Commented May 6, 2015 at 10:22
  • I am using gcc-5.00. It is a nice feature. newunit is not what is causing the problem.
    Zeus
    –  Zeus
    2015-05-06 11:02:00 +00:00
    Commented May 6, 2015 at 11:02

1 Answer 1

5

Dispose is a non-standard compiler extension (and not supported by your compiler). As described in this answer, the standard way to do this is to delete the file on closure:

f = "espy.tmp";  h = "formatted";  r = "read" 
Open (newunit=u, file=f, form=h, action=r,  &
  status="old")

close(u, status='delete')

Or, you could use temporary/scratch files (no filename):

f = "espy.tmp";  h = "formatted";  r = "read" 
Open (newunit=u, form=h, action=r,  &
  status="old", status='scratch')
Sign up to request clarification or add additional context in comments.

1 Comment

I cannot use internal files as the file already exists and need to read it. Your first solution works as I need it to.

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.