MODULE moduleMeshOutput0D

  CONTAINS
    SUBROUTINE printOutput0D(self)
      USE moduleMesh
      USE moduleRefParam
      USE moduleSpecies
      USE moduleOutput
      USE moduleCaseParam, ONLY: timeStep
      IMPLICIT NONE

      CLASS(meshParticles), INTENT(in):: self
      INTEGER:: i
      TYPE(outputFormat):: output
      CHARACTER(:), ALLOCATABLE:: fileName

      DO i = 1, nSpecies
        fileName = formatFileName('Output', species(i)%obj%name, 'csv')
        IF (timeStep == 0) THEN
          OPEN(20, file = generateFilePath(fileName), action = 'write')
          WRITE(20, "(*("//fmtColStr//"))")'"t (s)"','"density (m^-3)"',                                               &
                                                     '"velocity (m/s):0"', '"velocity (m/s):1"', '"velocity (m/s):2"', &
                                                     '"pressure (Pa)"',                                                &
                                                     '"temperature (K)"'
          call informFileCreation(fileName)
          CLOSE(20)

        END IF
        
        OPEN(20, file = generateFilePath(fileName), position = 'append', action = 'write')
        CALL calculateOutput(self%nodes(1)%obj%output(i), output, self%nodes(1)%obj%v, species(i)%obj)
        WRITE(20, "(*("//fmtColReal//"))") REAL(timeStep)*tauMin*ti_ref, output%density,    &
                                                                         output%velocity,   &
                                                                         output%pressure,   &
                                                                         output%temperature
        CLOSE(20)

      END DO

    END SUBROUTINE printOutput0D

    SUBROUTINE printColl0D(self)
      USE moduleMesh
      USE moduleRefParam
      USE moduleCaseParam
      USE moduleCollisions
      USE moduleOutput
      IMPLICIT NONE

      CLASS(meshGeneric), INTENT(in):: self
      CHARACTER(:), ALLOCATABLE:: fileName
      INTEGER:: k

      fileName = formatFileName('Output', 'Collisions', 'csv')
      IF (timeStep == tInitial) THEN
        OPEN(20, file = generateFilePath(fileName), action = 'write')
        call informFileCreation(fileName)
        WRITE(20, "(A,A)", advance='no') "t (s)", ','
        do k = 1, nCollPairs-1
          write(20, '(A,A,I3,A,A)', advance='no') '"',"pair", k, '"', ','

        end do
        write(20, "(A,A,I3,A)", advance='no') '"',"pair",k, '"'
        CLOSE(20)

      END IF
      
      OPEN(20, file = generateFilePath(fileName), position = 'append', action = 'write')
      WRITE(20, "("//fmtColReal//", *("//fmtColInt//"))") REAL(timeStep)*tauMin*ti_ref, (self%cells(1)%obj%tallyColl(k)%tally, k=1,nCollPairs)
      CLOSE(20)

    END SUBROUTINE printColl0D

    SUBROUTINE printEM0D(self)
      USE moduleMesh
      USE moduleRefParam
      USE moduleCaseParam
      USE moduleOutput
      IMPLICIT NONE

      CLASS(meshParticles), INTENT(in):: self

    END SUBROUTINE printEM0D

END MODULE moduleMeshOutput0D
