      subroutine rdtables(ifm,success)
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c     author
c       colin seftor
c
c     date
c       15-nov-2001
c
c     modification
c       19-jan-2003  - change Input logical device 24 --> 27
c			to avoid conflicts in main program
c       19-jan-2003  - add input/output parameters
c
c     purpose
c       read in tables
c     input variables
c       name       type     description            valid values 
c       ----       ----     -----------
c       ifm        int      TOMS flight model #    1 (N7) or 3(EP)
c     output variables
c       name       type     description            valid values 
c       ----       ----     -----------
c       success  logical                        .true. or .false.
c
c     include files
c       minref                contains minimum surface ref table
c       tab                   contains lambert equiv ref table
c       uvflux                contains individual wavelength and
c                             erythemally weighted flux tables
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c  
      include 'minref.inc'
      include 'tab.inc'
      include 'uvflux.inc'
      logical success
c     -- minimum surface reflectivity table
      open (21,file='MINREF.DAT',status='old',form='unformatted')
      read (21) mref
      close (21)
c     -- individual wavelength flux table
      open (22,file='TABLE.FLUX',status='old',form ='unformatted')
      read (22) uvflux
      close (22)
c     -- erythemally weighted flux table
      open (23,file='TABLE.ERY',status='old',form ='unformatted')
      read (23) eryflx
      close (23)
c     -- reflectivity and residue table: differ for N7(ifm=1) and EP(ifm=3):
c     open (24,file='TABLE.REF',status='old',form = 'unformatted')

        success=.true. 
      if (ifm.eq.1) then
        write(6,*) 'rdtables: N7/TOMS data'
      open (27,file='TABLE.REFN7',status='old',form = 'unformatted')
      else if(ifm.eq.2) then
        write(6,*) ' No M3/TOMS Tables'
        success=.false.
        RETURN
      else if(ifm.eq.3) then
        write(6,*) 'rdtables: EP/TOMS data'
      open (27,file='TABLE.REFEP',status='old',form = 'unformatted')
      else if(ifm.eq.4) then
        write(6,*) 'rdtables: NO ADEOS/TOMS tables'
        success=.false.
        RETURN
      else
         write(6, *)  'rdtables: INPUT ERROR.  Selected ifm=', ifm
         success=.false.
         RETURN

      endif

      read (27) logi0, z1i0, z2i0, ti0, sb
      read (27) logi0r, z1i0r, z2i0r, ti0r, sbr
      close (27)
c     -- initialize ccf routines
      call ld_ccftabl(success)
      call ld_radlow(success)
      call ld_radhigh(success)
      if (.not.success) then 
        write (6,*) 'rdtables: ccf tables not successfully read in'
        stop
      endif
      return
      end
