s3_write_line Subroutine

public subroutine s3_write_line(unit, line, iostat)

Write a line to an open S3 file.

Appends a line to the file buffer. A newline character is automatically added. The file must be opened in write mode. Content is uploaded when s3_close() is called.

@param[in] unit The unit number to write to @param[in] line The line content to write @param[out] iostat Status code: 0 on success, -1 on error

Example

call s3_write_line(unit, 'temperature,pressure', iostat)
call s3_write_line(unit, '25.3,1013.2', iostat)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
character(len=*), intent(in) :: line
integer, intent(out) :: iostat

Source Code

    subroutine s3_write_line(unit, line, iostat)
        integer, intent(in) :: unit
        character(len=*), intent(in) :: line
        integer, intent(out) :: iostat
        character(len=:), allocatable :: new_buffer

        iostat = 0

        if (unit < 1 .or. unit > MAX_FILES) then
            iostat = -1
            return
        end if

        if (.not. files(unit)%is_open .or. .not. files(unit)%is_write) then
            iostat = -1
            return
        end if

        ! Append line to buffer
        if (.not. allocated(files(unit)%buffer)) then
            files(unit)%buffer = trim(line) // new_line('')
        else
            new_buffer = files(unit)%buffer // trim(line) // new_line('')
            files(unit)%buffer = new_buffer
        end if
    end subroutine s3_write_line