writearray Subroutine

public subroutine writearray(filename, x, fmt)

Write content of real array (rank=1,2) to file.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

file name

real(kind=rk), intent(in) :: x(..)

array to be written

character(len=*), intent(in), optional :: fmt

format specifier (default="es16.5e3")


Calls

proc~~writearray~~CallsGraph proc~writearray pbepack_lib::writearray optval optval proc~writearray->optval to_string to_string proc~writearray->to_string

Contents

Source Code


Variables

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: fmt_
integer, public :: i
integer, public :: funit

Source Code

   subroutine writearray(filename, x, fmt)
   !! Write content of real array (rank=1,2) to file.
      character(*), intent(in) :: filename
         !! file name
      real(rk), intent(in) :: x(..)
         !! array to be written
      character(*), intent(in), optional :: fmt
         !! format specifier (default="es16.5e3")

      character(:), allocatable :: fmt_
      integer :: i, funit

      fmt_ = optval(fmt, "es16.5e3")

      open (newunit=funit, file=filename, status="replace", action="write", position="rewind")

      select rank (x)
      rank (1)
         if (size(x, 1) > 0) then
            do i = 1, size(x, 1)
               write (funit, '('//fmt_//')') x(i)
            end do
         end if
      rank (2)
         if (size(x, 1) > 0 .and. size(x, 2) > 0) then
            do i = 1, size(x, 1)
               write (funit, '('//to_string(size(x, 2))//'('//fmt_//'))') x(i, :)
            end do
         end if
      end select

      close (funit)

   end subroutine writearray