Opens a file
MPI-I/O mapping mpi_file_open
STREAM-I/O mapping OPEN
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | groupid |
message passing environment identifier |
||
integer, | intent(out) | :: | fh |
file handle (file storage unit) |
||
character(len=*), | intent(in) | :: | filepath |
path to the file |
||
integer, | intent(in) | :: | amode_status |
access mode |
||
integer, | intent(in), | optional | :: | info |
info object |
SUBROUTINE mp_file_open(groupid, fh, filepath, amode_status, info)
!! Opens a file
!!
!! MPI-I/O mapping mpi_file_open
!!
!! STREAM-I/O mapping OPEN
INTEGER, INTENT(IN) :: groupid
!! message passing environment identifier
INTEGER, INTENT(OUT) :: fh
!! file handle (file storage unit)
CHARACTER(LEN=*), INTENT(IN) :: filepath
!! path to the file
INTEGER, INTENT(IN) :: amode_status
!! access mode
INTEGER, INTENT(IN), OPTIONAL :: info
!! info object
INTEGER :: ierr, istat
#if defined(__parallel)
INTEGER :: my_info
#else
CHARACTER(LEN=10) :: fstatus, fposition
INTEGER :: amode
LOGICAL :: exists, is_open
#endif
ierr = 0
istat = 0
#if defined(__parallel)
my_info = mpi_info_null
IF (PRESENT(info)) my_info = info
CALL mpi_file_open(groupid, filepath, amode_status, my_info, fh, ierr)
CALL mpi_file_set_errhandler(fh, MPI_ERRORS_RETURN, ierr)
IF (ierr .NE. 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ mp_file_open")
#else
MARK_USED(groupid)
MARK_USED(info)
amode = amode_status
IF (amode .GT. file_amode_append) THEN
fposition = "APPEND"
amode = amode - file_amode_append
ELSE
fposition = "REWIND"
END IF
IF ((amode .EQ. file_amode_create) .OR. &
(amode .EQ. file_amode_create + file_amode_wronly) .OR. &
(amode .EQ. file_amode_create + file_amode_wronly + file_amode_excl)) THEN
fstatus = "UNKNOWN"
ELSE
fstatus = "OLD"
END IF
! Get a new unit number
DO fh = 1, 999
INQUIRE (UNIT=fh, EXIST=exists, OPENED=is_open, IOSTAT=istat)
IF (exists .AND. (.NOT. is_open) .AND. (istat == 0)) EXIT
END DO
OPEN (UNIT=fh, FILE=filepath, STATUS=fstatus, ACCESS="STREAM", POSITION=fposition)
#endif
END SUBROUTINE mp_file_open