Open filename for writing a serialized stream, replacing any
existing file.
access='stream' is Fortran 2003 and is the right tool here: it gives
byte addressable, record marker free output, so the file layout is
exactly the one documented above rather than one decorated with
compiler specific record length markers.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | filename |
Path of the file to create. |
||
| integer(kind=default_int), | intent(out) | :: | unit |
Newly opened unit number, -1 when the open failed. |
||
| type(error_t), | intent(inout) | :: | err |
Error state, |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | ios |
subroutine serialize_open_write(filename, unit, err) !! Open `filename` for writing a serialized stream, replacing any !! existing file. !! !! `access='stream'` is Fortran 2003 and is the right tool here: it gives !! byte addressable, record marker free output, so the file layout is !! exactly the one documented above rather than one decorated with !! compiler specific record length markers. character(len=*), intent(in) :: filename !! Path of the file to create. integer(default_int), intent(out) :: unit !! Newly opened unit number, -1 when the open failed. type(error_t), intent(inout) :: err !! Error state, `ERROR_IO` if the file cannot be created. integer(default_int) :: ios unit = -1_default_int open (newunit=unit, file=filename, form="unformatted", access="stream", & action="write", status="replace", iostat=ios) call check_io(ios, "cannot open '"//filename//"' for writing", err) end subroutine serialize_open_write