!---------------------------------------------------------------------------
! pmlib_parameters_check.f
!   version: 2D single-core
!---------------------------------------------------------------------------
!                  __    __
!    ___  _ _     / /__ / /
!   | _ \/ ` \ _ / // // _ \
!   | ,_/_,_,_\  \_/\_/\___/
!   |_|                      Mads M. Hejlesen* and Jens H. Walther*^
!                            * Technical University of Denmark
!                            ^ ETH-Zurich
!
!---------------------------------------------------------------------------
! Copyright (c) 2014 Technical University of Denmark, 
!                    Department of Mechanical Engineering
!
! This program 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; either version 2 of the License, or
! (at your option) any later version.
! 
! This program 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/>
!
! Contact: mmhej@mek.dtu.dk or jhwa@mek.dtu.dk
!---------------------------------------------------------------------------
SUBROUTINE pmlib_parameters_check(ierr)

IMPLICIT NONE
!-------------------------------------------------------------------------
! Arguments
!-------------------------------------------------------------------------
  INTEGER, INTENT(OUT) :: ierr

!-------------------------------------------------------------------------
! Local variables
!-------------------------------------------------------------------------
  CHARACTER(LEN=22)                 :: caller = 'pmlib_parameters_check'

!---------------------------------------------------------------------------
! Numerical parameters
!---------------------------------------------------------------------------
  IF( pmlib_poisson_kernel .NE. 1 .AND. & 
    & pmlib_poisson_kernel .NE. 2 )THEN
    ierr = -1
    CALL pmlib_write(caller, & 
        & 'pmlib_poisson_kernel is incorrectly set.')
    GO TO 9999
  END IF

  IF( pmlib_poisson_order .NE. 0 .AND. &
    & pmlib_poisson_order .NE. 2 .AND. &
    & pmlib_poisson_order .NE. 4 .AND. &
    & pmlib_poisson_order .NE. 6 .AND. &
    & pmlib_poisson_order .NE. 8 .AND. &
    & pmlib_poisson_order .NE. 10 )THEN
    ierr = -1
    CALL pmlib_write(caller, &
        & 'pmlib_poisson_order is incorrectly set.')
    GO TO 9999
  END IF

  IF( pmlib_poisson_order .GT. 0 .AND. &
    & pmlib_regularisation_radius .LT. 1.0_MK )THEN
    ierr = -1
    CALL pmlib_write(caller, &
        & 'pmlib_regularisation_radius is incorrectly set.')
    GO TO 9999
  END IF

  IF( pmlib_fd_order .NE. 2 .AND. &
    & pmlib_fd_order .NE. 4 )THEN
    ierr = -1
    CALL pmlib_write(caller, &
        & 'pmlib_fd_order is incorrectly set.')
    GO TO 9999
  END IF

  IF( pmlib_interpolation_order .NE. 3 .AND. &
    & pmlib_interpolation_order .NE. 4 )THEN
    ierr = -1
    CALL pmlib_write(caller, &
        & 'pmlib_interpolation_order is incorrectly set.')
    GO TO 9999
  END IF

  IF( pmlib_time_integration_order .NE. 1 .AND. &
    & pmlib_time_integration_order .NE. 2 .AND. &
    & pmlib_time_integration_order .NE. 3 )THEN
    ierr = -1
    CALL pmlib_write(caller, &
        & 'pmlib_interpolation_order is incorrectly set.')
    GO TO 9999
  END IF

!----------------------------------------------------------------------------
! Return
!----------------------------------------------------------------------------
 9999 CONTINUE
RETURN
END SUBROUTINE pmlib_parameters_check
