read_cells Subroutine

private subroutine read_cells(filename, m)

Reads cell definitions from cells.dat.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
type(mesh_t), intent(inout) :: m

Source Code

   subroutine read_cells(filename, m)
      character(len=*), intent(in) :: filename
      type(mesh_t), intent(inout) :: m

      integer :: unit_id, ios, i, id
      integer :: nodes(8)
      real(rk) :: cx, cy, cz, volume

      open(newunit=unit_id, file=trim(filename), status='old', action='read', iostat=ios)
      if (ios /= 0) call fatal_error('mesh_io', 'could not open '//trim(filename))

      read(unit_id, *, iostat=ios) m%ncells
      if (ios /= 0 .or. m%ncells <= 0) call fatal_error('mesh_io', 'invalid cells header')

      allocate(m%cells(m%ncells))
      do i = 1, m%ncells
         read(unit_id, *, iostat=ios) id, nodes, cx, cy, cz, volume
         if (ios /= 0) call fatal_error('mesh_io', 'failed reading cell')
         if (id < 1 .or. id > m%ncells) call fatal_error('mesh_io', 'cell id out of range')
         if (volume <= 0.0_rk) call fatal_error('mesh_io', 'cell volume must be positive')
         m%cells(id)%id = id
         m%cells(id)%nodes = nodes
         m%cells(id)%center = [cx, cy, cz]
         m%cells(id)%volume = volume
      end do

      close(unit_id)
   end subroutine read_cells