c     Copyright (C)
c     2010-2013 Université Bordeaux 1
c     2010-2013 Ecole des Mines d'Albi
c     2014-2018 - Mesostar
c     
c     This program is free software; you can redistribute it and/or modify
c     it under the terms of the GNU General Public License as published by
c     the Free Software Foundation; either version 2, or (at your option)
c     any later version.

c     This program is distributed in the hope that it will be useful,
c     but WITHOUT ANY WARRANTY; without even the implied warranty of
c     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c     GNU General Public License for more details.

c     You should have received a copy of the GNU General Public License
c     along with this program; if not, write to the Free Software
c     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
c     USA.
c
      subroutine check_inconsistencies(atm_profile,uan,
     &     ref_choice,fullRT,
     &     Nb,fband,lband,mu,pidx)
      implicit none
      include 'max.inc'
c
c     Purpose: to check input data and options for inconsistencies
c
c     Input:
c       + atm_profile: 1 for a standard atmospheric profile
c                      2 for a user-defined atmospheric profile
c       + uan: 1 when using every narrowband where data is defined
c              2 when using only selected narrowbands (whose indexes are defined in data.in)
c       + ref_choice: 1 for a specular reflexion at ground
c                     2 for a diffuse reflexion at ground
c       + fullRT: if true, full NER are computed; if false, only gas-space NERs are computed
c       + Nb: number of narrowbands
c       + fband: index of the first narrowband to use
c       + lband: index of the last narrowband to use
c       + mu: cos(theta) if angular integration has been disabled (0-1)
c       + pidx: index of the standard atmospheric profile to use
c
c     I/O
      integer atm_profile
      integer uan
      integer ref_choice
      logical fullRT
      integer Nb
      integer fband
      integer lband
      double precision mu
      integer pidx
c     temp
c     label
      integer strlen
      character*(Nchar_mx) label
      label='subroutine check_inconsistencies'

c     Consistency check for options
      if ((atm_profile.ne.1).and.(atm_profile.ne.2)) then
         call error(label)
         write(*,*) 'atm_profile=',atm_profile
         write(*,*) 'allowed values: 1, 2'
         stop
      endif
      if ((uan.ne.1).and.(uan.ne.2)) then
         call error(label)
         write(*,*) 'uan=',uan
         write(*,*) 'allowed values: 1, 2'
         stop
      endif
      if ((ref_choice.ne.1).and.(ref_choice.ne.2)) then
         call error(label)
         write(*,*) 'ref_choice=',ref_choice
         write(*,*) 'allowed values: 1, 2'
         stop
      endif
      if ((mu.lt.0.0D+0).or.(mu.gt.1.0D+0)) then
         call error(label)
         write(*,*) 'mu=',mu
         write(*,*) 'should be in the [0,1] range'
         stop
      endif
c     Consistency check for data
      if (uan.eq.2) then
         if (fband.lt.1) then
            call error(label)
            write(*,*) 'Incorrect input data:'
            write(*,*) 'fband=',fband
            write(*,*) 'is < 1'
            stop
         endif
         if (fband.gt.Nb) then
            call error(label)
            write(*,*) 'Incorrect input data:'
            write(*,*) 'fband=',fband
            write(*,*) 'is > Nb=',Nb
            stop
         endif
         if (lband.lt.1) then
            call error(label)
            write(*,*) 'Incorrect input data:'
            write(*,*) 'lband=',lband
            write(*,*) 'is < 1'
            stop
         endif
         if (lband.gt.Nb) then
            call error(label)
            write(*,*) 'Incorrect input data:'
            write(*,*) 'lband=',lband
            write(*,*) 'is > Nb=',Nb
            stop
         endif
         if (fband.gt.lband) then
            call error(label)
            write(*,*) 'fband=',fband
            write(*,*) 'is > lband=',lband
            stop
         endif
      endif
      if (atm_profile.eq.1) then
         if ((pidx.lt.1).or.(pidx.gt.5)) then
            call error(label)
            write(*,*) 'pidx=',pidx
            write(*,*) 'allowed values: 1-5'
            stop
         endif
      endif
      
      return
      end
