I need to modify the following program to allow the user try 3 attempts to specify the name of a file that should be open. If happen any fail during the two attempts the program should write "The file no exist. Try again.",but in case to happen the third attempt the program should write " file no exist. Program finished."
PROGRAM open_old_file_verify
!Example of use of IOSTAT to verity
!the sucessful of comand OPEN
IMPLICIT none
CHARACTER(len=80) :: file_name, &
first_word
INTEGER, PARAMETER :: &
input_unit = 7, ok = 0
INTEGER :: situation_open
!Ask for the user write the name of a file
PRINT *, "Write the name of file white would be readed"
READ *, file_name
! use IOSTAT to see if OPEN worked
OPEN(unit=input_unit, &
file=file_name, status="old" ,&
iostat=situation_open )
IF( situation_open == ok ) THEN
! See what is inside the file
READ( unit=input_unit, fmt=* )&
first_word
PRINT *,
PRINT *, " The first work on file is : "
PRINT *, first_word
ELSE
PRINT *
PRINT *, " can not open the file"
END IF
END PROGRAM open_old_file_verify
PROGRAM open_old_file_verify
!Example of use of IOSTAT to verity
!the sucessful of comand OPEN
IMPLICIT none
CHARACTER(len=80) :: file_name, &
first_word
INTEGER, PARAMETER :: &
input_unit = 7, ok = 0
INTEGER :: situation_open
!Ask for the user write the name of a file
PRINT *, "Write the name of file white would be readed"
READ *, file_name
! use IOSTAT to see if OPEN worked
OPEN(unit=input_unit, &
file=file_name, status="old" ,&
iostat=situation_open )
IF( situation_open == ok ) THEN
! See what is inside the file
READ( unit=input_unit, fmt=* )&
first_word
PRINT *,
PRINT *, " The first work on file is : "
PRINT *, first_word
ELSE
PRINT *
PRINT *, " can not open the file"
END IF
END PROGRAM open_old_file_verify