output Subroutine

subroutine output(action)

Auxiliary routine to save results to file.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: action

parameter to select output action


Calls

proc~~output~~CallsGraph proc~output output to_string to_string proc~output->to_string

Called by

proc~~output~~CalledByGraph proc~output output program~example1_burgers_1d_fv example1_burgers_1d_fv program~example1_burgers_1d_fv->proc~output

Variables

Type Visibility Attributes Name Initial
character(len=*), public, parameter :: folder = ".\output\example1\"
real(kind=rk), public, save :: cpu_start = 0._rk
real(kind=rk), public, save :: cpu_end = 0._rk
integer, public, save :: funit_x = 0
integer, public, save :: funit_u = 0
integer, public :: i

Source Code

   subroutine output(action)
   !! Auxiliary routine to save results to file.
      integer, intent(in) :: action
         !! parameter to select output action
      character(*), parameter :: folder = ".\output\example1\"
      real(rk), save :: cpu_start = 0._rk, cpu_end = 0._rk
      integer, save :: funit_x = 0, funit_u = 0
      integer :: i

      select case (action)

         ! Open files and write headers and grid
      case (1)

         write (stdout, '(1x, a)') "Running example1 ..."
         call cpu_time(cpu_start)

         ! Write grid
         open (newunit=funit_x, file=folder//"x.txt", status="replace", &
               action="write", position="rewind")

         write (funit_x, '(a5, 2(1x, a15))') "i", "x(i)", "dx(i)"
         do i = 1, nc
            write (funit_x, '(i5, 2(1x, es15.5))') i, gx%center(i), gx%width(i)
         end do

         ! Write header u
         open (newunit=funit_u, file=folder//"u.txt", status="replace", &
               action="write", position="rewind")

         write (funit_u, '(a16)', advance="no") "t"
         do i = 1, nc
            write (funit_u, '(1x, a16)', advance="no") "u("//to_string(i)//")"
         end do
         write (funit_u, *) ""

         ! Write values u(x,t)
      case (2)
         write (funit_u, '(es16.5e3)', advance="no") time
         do i = 1, nc
            write (funit_u, '(1x, es16.5e3)', advance="no") u(i)
         end do
         write (funit_u, *) ""

         ! Close files
      case (3)
         close (funit_x)
         close (funit_u)
         call cpu_time(cpu_end)
         write (stdout, '(1x, a, 1x, f6.1)') "Elapsed time (ms) :", 1e3_rk*(cpu_end - cpu_start)

      end select

   end subroutine output