serialize_open_write Subroutine

public 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.

Arguments

Type IntentOptional 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, ERROR_IO if the file cannot be created.


Calls

proc~~serialize_open_write~~CallsGraph proc~serialize_open_write serialize_open_write proc~check_io check_io proc~serialize_open_write->proc~check_io interface~to_char to_char proc~check_io->interface~to_char proc~error_set error_t%error_set proc~check_io->proc~error_set proc~to_char_char to_char_char interface~to_char->proc~to_char_char proc~to_char_dp to_char_dp interface~to_char->proc~to_char_dp proc~to_char_int32 to_char_int32 interface~to_char->proc~to_char_int32 proc~to_char_int64 to_char_int64 interface~to_char->proc~to_char_int64 proc~to_char_logical to_char_logical interface~to_char->proc~to_char_logical proc~to_char_matrix_dp to_char_matrix_dp interface~to_char->proc~to_char_matrix_dp proc~to_char_matrix_int32 to_char_matrix_int32 interface~to_char->proc~to_char_matrix_int32 proc~to_char_matrix_int64 to_char_matrix_int64 interface~to_char->proc~to_char_matrix_int64 proc~to_char_matrix_sp to_char_matrix_sp interface~to_char->proc~to_char_matrix_sp proc~to_char_sp to_char_sp interface~to_char->proc~to_char_sp proc~to_char_vector_dp to_char_vector_dp interface~to_char->proc~to_char_vector_dp proc~to_char_vector_int32 to_char_vector_int32 interface~to_char->proc~to_char_vector_int32 proc~to_char_vector_int64 to_char_vector_int64 interface~to_char->proc~to_char_vector_int64 proc~to_char_vector_sp to_char_vector_sp interface~to_char->proc~to_char_vector_sp

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: ios

Source Code

   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