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_data(data_file,
     &     fband,lband,mu,pidx)
      implicit none
      include 'max.inc'
c
c     Purpose: to read the "data.in" input file
c
c     Input:
c       + data_file: name of the data file to read
c
c     Output:
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
      character*(Nchar_mx) data_file
      integer fband
      integer lband
      double precision mu
      integer pidx
c     temp
      integer i,ios
c     label
      integer strlen
      character*(Nchar_mx) label
      label='subroutine read_data'

      open(10,file=data_file(1:strlen(data_file)),
     &     status='old',iostat=ios)
      if (ios.ne.0) then        ! file not found
         call error(label)
         write(*,*) 'File could not be found:'
         write(*,*) data_file(1:strlen(data_file))
         stop
      else
         do i=1,3
            read(10,*)
         enddo                  ! i
         read(10,*) fband
         read(10,*)
         read(10,*) lband
         read(10,*)
         read(10,*) mu
         read(10,*)
         read(10,*) pidx
      endif
      close(10)

      return
      end

