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 read_options(options_file,
     &     atm_profile,uan,ref_choice,
     &     ai,fullRT)
      implicit none
      include 'max.inc'
c
c     Purpose: to read the options file for program 'ppart.exe'
c
c     Input:
c       + options_file: name of the options file
c
c     Output:
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       + ai: true if angular integration is enabled
c       + fullRT: if true, full NER are computed; if false, only gas-space NERs are computed
c
c     I/O
      character*(Nchar_mx) options_file
      integer atm_profile
      integer uan
      integer ref_choice
      logical ai
      logical fullRT
c     temp
      integer ios,i
c     label
      integer strlen
      character*(Nchar_mx) label
      label='subroutine read_options'
      
      open(10,file=options_file(1:strlen(options_file)),
     &     status='old',iostat=ios)
      if (ios.ne.0) then        ! file not found
         call error(label)
         write(*,*) 'File could not be found:'
         write(*,*) options_file(1:strlen(options_file))
         stop
      else
c     Read options
         do i=1,6
            read(10,*)
         enddo                  ! i
         read(10,*) atm_profile
         read(10,*)
         read(10,*) ref_choice
         read(10,*)
         read(10,*) uan
         do i=1,5
            read(10,*)
         enddo                  ! i
         read(10,*) ai
         read(10,*)
         read(10,*) fullRT
      endif
      close(10)

      return
      end
