! Submodule : range_sm
! Purpose   : Factory routines for range_m
!
! Copyright 2022 Rich Townsend & The MSG Team
!
! This file is part of MSG. MSG is free software: you can redistribute
! it and/or modify it under the terms of the GNU General Public
! License as published by the Free Software Foundation, version 3.
!
! MSG is distributed in the hope that it will be useful, but WITHOUT
! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
! License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program.  If not, see <http://www.gnu.org/licenses/>.

#:include 'forum.inc'

submodule(range_m) range_sm

   ! Uses

   use forum_m

   use comp_range_m
   use lin_range_m
   use log_range_m
   use tab_range_m

   use ISO_FORTRAN_ENV

   ! No implicit typing

   implicit none

contains

   function range_t_type_(type) result(range)

      character(*), intent(in)    :: type
      class(range_t), allocatable :: range

      ! Construct range by allocating with the indicated type

      select case(type)
      case('comp_range_t')
         allocate(comp_range_t::range)
      case('lin_range_t')
         allocate(lin_range_t::range)
      case ('log_range_t')
         allocate(log_range_t::range)
      case('tab_range_t')
         allocate(tab_range_t::range)
      case default
         @:ABORT('invalid type')
      end select

      ! Finish

      return

   end function range_t_type_
         
end submodule range_sm
