      SUBROUTINE REAPAR(cbinflag, cnetflag, AEFFA,
     &                  BETAMI,BETAMX,
     &                  CALPHA,CDIEL,CFLEPS,CFLPAR,CMDSOL,CMDFFT,CSHAPE,
     &                  CMDTRQ,CXE01,CXE02,
     &                  DEGRAD,
     &                  ICTHM,IDVERR,IDVOUT,INIT,IOPAR,IORTH,IPHM,
     &                  IWRKSC,
     &                  MXBETA,MXCOMP,MXMEM,MXPHI,MXRAD,MXSCA,MXTHET,
     &                  MXWAV,
     &                  NBETA,NCOMP,NPHI,NRAD,NSCA,NTHETA,NWAV,
     &                  PHIMIN,PHIMAX,PHIN,
     &                  THETAN,THETMI,THETMX,TOL,
     &                  WAVEA,SHPAR)
C***********************************************************************
C Subroutine REAPAR handles the reading of input parameters from the
C "ddscat.par" file, as well as elementary processing with those input
C parameters to generate arrays.
C Original version created by P.J.Flatau, Colorado State Univ.
C Modified by B.T.Draine, Princeton Univ. Obs.
C History:
C 90.11.09 (BTD): Modified so as to remove sensitivity to errors
C                 in sign of entered value of DTHETA.
C 90.11.30 (BTD): Added test to compare CMDFFT and MXMEM
C 90.12.14 (BTD): Changed option MKRECT to RCTNGL
C 91.01.03 (BTD): Added MXBETA,MXPHI,MXTHET to argument list
C                 and added checking of NBETA,NPHI,NTHETA
C 91.05.08 (BTD): Added CALPHA to allow choice of prescription
C                 for polarizabilities
C 91.05.08 (BTD): Some rewriting done.
C 91.05.14 (BTD): Added separate options LDRXYZ and LDRAVG
C 91.05.15 (BTD): Added new option LDR000
C 91.05.23 (BTD): Added variable IWRKSC to argument list and
C                 added code to read IWRKSC
C 91.05.30 (BTD): Changed LDRXYZ->LDR100
C                 Added option LDR111
C 91.11.13 (BTD): Now three options: DRAI88, GOBR88, LATTDR
C                 (subroutine ALPHA now allows for directional
C                 dependence for LATTDR option)
C 92.05.14 (BTD): Allow for experimental option LDRISO
C 92.09.21 (BTD): Allow for option ANIELL (ellipsoid of anisotropic
C                 material); change option GRPHIT -> UNICYL (cylinder
C                 of uniaxial material)
C 93.01.07 (BTD): Allow for options TWOELL and TWOAEL (two touching
C                 ellipsoids, each either isotropic or anisotropic)
C 93.03.11 (BTD): Deleted all code associated with variable CMACHN
C                 which previously was used to identify machine/OS
C                 This information was not used or needed.
C 93.12.15 (BTD): Added code to check for compatibility of NCOMP
C                 when CSHAPE=TWOELL,THRELL,TWOAEL,or THRAEL
C 94.01.27 (BTD): Replaced SHPAR1,SHPAR2,SHPAR3 by SHPAR(1-6)
C                 Added CONELL (two concentric ellipsoids) as target
C                 option.
C 94.06.20 (PJF): Added code to handle NEWTMP
C 94.12.02 (BTD): Added options 
C                    LB1991 (Dungey-Bohren 1991 polarizability)
C                    LR1994 (Lumme-Rahola 1994 polarizability)
C 95.05.26 (BTD): Corrected construction of orthogonal polarization
C                 state for case where E01 is complex (e.g.,
C                 circular polarization)
C 95.06.14 (BTD): Added code to check that user is not requesting
C                 f_ml when illuminating target with other then
C                 linearly polarized light
C 95.06.19 (BTD): Added argument CMDSOL to allow selection of
C                 different CCG methods
C                 Added argument CMDTRQ to allow torque calculations
C                 to be skipped.
C 96.01.05 (BTD): Added shape options BLOCKS and DW1996
C 96.01.25 (BTD): Added shape option TWOSPH
C 96.01.25 (BTD): Disable code added 95.06.14 so that user can
C                 calculate f_ml even when illuminating target with
C                 elliptically polarized light.
C 96.10.18 (BTD): Changed option NEWTMP to GPFAFT (Generalized Prime
C                 Factor Algorithm for Fourier Transform).
C 96.11.06 (BTD): Added provision to 
C                 (1) produce fatal error if CXE01(1).NE.(0.,0.)
C                 (2) normalize CXE01 if necessary
C 96.11.14 (PJF): cbinflag for binary file
C 96.11.15 (PJF): netCDF netflag
C 96.11.21 (BTD): modified handling of CBINFLAG and CNETFLAG to
C                 be consistent with other option flags
C 98.12.21 (BTD): changed dimension of CFLPAR from CHARACTER*40 to
C                 CHARACTER*60 to allow longer file names
C                 (also changed in DDSCAT.f and dielec.f)
C end history
C Copyright (C) 1993,1994,1995,1996 B.T. Draine and P.J. Flatau
C This code is covered by the GNU General Public License.
C***********************************************************************
C
C Arguments:
      CHARACTER
     &   CALPHA*(*),CDIEL*(*),CFLPAR*(*),CMDSOL*(*),CMDFFT*(*),
     &   CMDTRQ*(*),CSHAPE*(*), cbinflag*(*), cnetflag*(*)
      INTEGER
     &   ICTHM,IDVERR,IDVOUT,INIT,IOPAR,IORTH,IPHM,IWRKSC,
     &   MXBETA,MXCOMP,MXMEM,MXPHI,MXRAD,MXSCA,MXTHET,MXWAV,
     &   NBETA,NCOMP,NPHI,NRAD,NSCA,NWAV,NTHETA
      CHARACTER*60 CFLEPS(MXCOMP)
      REAL
     &   BETAMI,BETAMX,DEGRAD,PHIMIN,PHIMAX,THETMI,THETMX,TOL
      REAL
     &   AEFFA(MXRAD),PHIN(MXSCA),SHPAR(6),THETAN(MXSCA),WAVEA(MXWAV)
      COMPLEX CXE01(3),CXE02(3)
C
C Local variables:
      CHARACTER CDIVID*3,CLINE*70,CMSGNM*70
      INTEGER J,NSCA0
      REAL
     &   AEFEND,AEFINI,DELTA,DTHETA,E1,PHI1,THETA1,THETA2,
     &   WAVEND,WAVINI
C
C External routines:
      EXTERNAL DIVIDE,ERRMSG,WRIMSG
C
C***********************************************************************
      OPEN (UNIT=IOPAR,FILE=CFLPAR,STATUS='OLD')
C***********************************************************************
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG('REAPAR',CLINE)
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
C
C    Specify whether torques are to be calculated:
C
C    CMDTRQ*6 = 'DOTORQ' -  calculate torque on grain
C             = 'NOTORQ' -  do not calculate torque on grain
C
      READ(IOPAR,FMT=*,ERR=40)CMDTRQ
      IF(CMDTRQ.EQ.'dotorq')CMDTRQ='DOTORQ'
      IF(CMDTRQ.EQ.'notorq')CMDTRQ='NOTORQ'
      IF(CMDTRQ.EQ.'DOTORQ')THEN
         WRITE(CMSGNM,FMT='(A,A)')CMDTRQ,' - compute torques '
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSEIF(CMDTRQ.EQ.'NOTORQ')THEN
         WRITE(CMSGNM,FMT='(A,A)')CMDTRQ,' - do not compute torques '
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' wrong definition of CMDTRQ')
      ENDIF
C
C    Define method used for iterative solution of complex linear equations
C
C    CMDSOL*6 = 'PETRKP' -  Petravic & Kuo-Petravic method
C             = 'PBCGST' -  PIM BiConjugate Gradient with Stabilization
C
      READ(IOPAR,FMT=*,ERR=40)CMDSOL
      IF(CMDSOL.EQ.'petrkp')CMDSOL='PETRKP'
      IF(CMDSOL.EQ.'pbcgst')CMDSOL='PBCGST'
      IF(CMDSOL.EQ.'PETRKP'.OR.
     &   CMDSOL.EQ.'PBCGST')THEN
         WRITE(CMSGNM,FMT='(A,A)')CMDSOL,' - CCG Method  '
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' wrong definition of CMDSOL')
      ENDIF
C
C    Define FFT method:
C
C    CMDFFT*6 = 'BRENNR' -  Use Brenner's FOURX FFT routine.
C             = 'TMPRTN' -  Use Temperton's FFT routine.
C             = 'GPFAFT' -  GPFA code of Temperton
C             = 'CONVEX' -  Use native Convex veclib routine C3DFFT.
C
      READ(IOPAR,FMT=*,ERR=40)CMDFFT
      IF(CMDFFT.EQ.'BRENNR'.OR.
     &   CMDFFT.EQ.'TMPRTN'.OR.
     &   CMDFFT.EQ.'CONVEX'.OR.
     &   CMDFFT.EQ.'GPFAFT')THEN
         WRITE(CMSGNM,FMT='(A,A)')CMDFFT,' - Solution Method  '
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' wrong definition of CMDFFT')
      ENDIF
C*** Check whether compiled with enough memory for TMPRTN option:
      IF(CMDFFT.EQ.'TMPRTN'.AND.MXMEM.EQ.0)THEN
         CALL ERRMSG('FATAL','REAPAR',
     &   ' Must recompile with MXMEM=1 to use TMPRTN option')
      ENDIF
      IF(CMDFFT.NE.'TMPRTN'.AND.MXMEM.EQ.1)THEN
         CALL ERRMSG('WARNING','REAPAR',
     &   ' You do not need MXMEM=1 with BRENNR,CONVEX, or GPFAFT')
      ENDIF
C***********************************************************************
C
C    Define prescription for computing polarizabilities:
C
C    CALPHA*6 = 'DRAI88' - Draine (1988) prescription
C             = 'GOBR88' - Goedecke & Obrien (1988) prescription
C             = 'LATTDR' - Lattice Dispersion Relation
C             = 'LDRISO' - Isotropized Lattice Dispersion Relation
C             = 'DB1991' - Dungey & Bohren (1991) prescription
C             = 'LR1994' - Lumme & Rahola (1994) prescription
C
      READ(IOPAR,FMT=*,ERR=40)CALPHA
      IF(CALPHA.EQ.'DRAI88')THEN
         CALL WRIMSG('REAPAR',
     &               'DRAI88 - Draine (1988) prescription for alpha')
      ELSEIF(CALPHA.EQ.'GOBR88')THEN
         CALL WRIMSG('REAPAR',
     &      'GOBR88 - Goedecke & OBrien (1988) prescription for alpha')
      ELSEIF(CALPHA.EQ.'LATTDR')THEN
         CALL WRIMSG('REAPAR',
     &      'LATTDR - Lattice Dispersion Relation for alpha')
      ELSEIF(CALPHA.EQ.'LDRISO')THEN
         CALL WRIMSG('REAPAR',
     &     'LATTDR - Isotropized Lattice Dispersion Relation for alpha')
      ELSEIF(CALPHA.EQ.'DB1991')THEN
         CALL WRIMSG('REAPAR',
     &     'DB1991 - Dungey & Bohren (1991) prescription for alpha')
      ELSEIF(CALPHA.EQ.'LR1994')THEN
         CALL WRIMSG('REAPAR',
     &     'LR1994 - Lumme & Rahola (1994) prescription for alpha')
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' wrong definition of CALPHA')
      ENDIF
C
C binary file flag
      READ(IOPAR,FMT=*,ERR=40)CBINFLAG
      IF(CBINFLAG.EQ.'allbin')CBINFLAG='ALLBIN'
      IF(CBINFLAG.EQ.'oribin')CBINFLAG='ORIBIN'
      IF(CBINFLAG.EQ.'notbin')CBINFLAG='NOTBIN'
      IF(CBINFLAG.EQ.'ALLBIN'
     &   .OR.CBINFLAG.EQ.'ORIBIN'
     &   .OR.CBINFLAG.EQ.'NOTBIN')THEN
         WRITE(CMSGNM,FMT='(A,A)')CBINFLAG,
     &                            ' - Unformatted binary dump option'
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' Wrong definition of CBINFLAG')
      ENDIF
C
C binary file flag
      READ(IOPAR,FMT=*,ERR=40)CNETFLAG
      IF(CNETFLAG.EQ.'allcdf')CNETFLAG='ALLCDF'
      IF(CNETFLAG.EQ.'oricdf')CNETFLAG='ORICDF'
      IF(CNETFLAG.EQ.'notcdf')CNETFLAG='NOTCDF'
      IF(CNETFLAG.EQ.'ALLCDF'  
     &   .OR.CNETFLAG.EQ.'ORICDF' 
     &   .OR.CNETFLAG.EQ.'NOTCDF')THEN
         WRITE(CMSGNM,FMT='(A,A)')CNETFLAG,
     &                            ' - netCDF file option'
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' Wrong definition of CNETFLAG')
      ENDIF
C
C***********************************************************************
C
C    Define shape:
C
C    CSHAPE*6 = 'FRMFIL'     read shape data from file
C             = 'RCTNGL'     make rectangular solid
C             = 'ELLIPS'     make ellipsoidal solid
C             = 'CYLNDR'     make cylindrical solid
C             = 'HEXGON'     make hexagonal prism
C             = 'TETRAH'     make regular tetrahedron
C             = 'UNICYL'     make cylinder of unixaxial material
C             = 'ANIELL'     make ellipsoid of anisotropic material
C             = 'TWOELL'     make two touching ellipsoids of materials 1,2
C             = 'TWOAEL'     make two touching anisotropic ellipsoids of
C                            materials 1-6
C             = 'THRELL'     make three touching isotropic ellipsoids of
C                            materials 1,2,3
C             = 'THRAEL'     make three touching anisotropic ellipsoids of
C                            materials 1-9
C             = 'CONELL'     make two concentric ellipsoids of
C                            materials 1,2
C             = 'BLOCKS'     make target out of cubic blocks defined by
C                            data in file 'blocks.par'
C             = 'DW1996'     make 13-cube target used by Draine &
C                            Weingartner 1996
C             = 'TWOSPH'     make two touching spheroids with symmetry axes at
C                            specified angle
C
      READ(IOPAR,FMT=*,ERR=40)CSHAPE
      IF(    CSHAPE.EQ.'FRMFIL'
     &   .OR.CSHAPE.EQ.'RCTNGL'
     &   .OR.CSHAPE.EQ.'ELLIPS'
     &   .OR.CSHAPE.EQ.'CYLNDR'
     &   .OR.CSHAPE.EQ.'HEXGON'
     &   .OR.CSHAPE.EQ.'TETRAH'
     &   .OR.CSHAPE.EQ.'UNICYL'
     &   .OR.CSHAPE.EQ.'ANIELL'
     &   .OR.CSHAPE.EQ.'TWOELL'
     &   .OR.CSHAPE.EQ.'TWOAEL'
     &   .OR.CSHAPE.EQ.'THRELL'
     &   .OR.CSHAPE.EQ.'THRAEL'
     &   .OR.CSHAPE.EQ.'CONELL'
     &   .OR.CSHAPE.EQ.'BLOCKS'
     &   .OR.CSHAPE.EQ.'DW1996'
     &   .OR.CSHAPE.EQ.'TWOSPH')THEN
         WRITE(CMSGNM,FMT='(A,A)')CSHAPE,' - Shape definition '
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' Wrong shape directive ')
      ENDIF
C
C Read shape parameters
C Need 3 shape parameters for all options except 
C      FRMFIL (here skip a line, later read target from file)
C      TETRAH, DW1996 (1 shape parameter)
C      CYLNDR, HEXGON, UNICYL (2 shape parameters)
C      TWOSPH (5 shape parameters)
C      CONELL (6 shape parameters)
C
      IF(CSHAPE.EQ.'FRMFIL')THEN
         READ(IOPAR,FMT=*,ERR=40)
      ELSEIF(
     &   CSHAPE.EQ.'TETRAH'.OR.
     &   CSHAPE.EQ.'DW1996')THEN
         READ(IOPAR,FMT=*,ERR=40)SHPAR(1)
      ELSEIF(
     &   CSHAPE.EQ.'CYLNDR'.OR.
     &   CSHAPE.EQ.'HEXGON'.OR.
     &   CSHAPE.EQ.'UNICYL')THEN
         READ(IOPAR,FMT=*,ERR=40)SHPAR(1),SHPAR(2)
      ELSEIF(CSHAPE.EQ.'TWOSPH')THEN
         READ(IOPAR,FMT=*,ERR=40)SHPAR(1),SHPAR(2),SHPAR(3),
     &                           SHPAR(4),SHPAR(5)
      ELSEIF(CSHAPE.EQ.'CONELL')THEN
         READ(IOPAR,FMT=*,ERR=40)SHPAR(1),SHPAR(2),SHPAR(3),
     &                           SHPAR(4),SHPAR(5),SHPAR(6)
      ELSE
         READ(IOPAR,FMT=*,ERR=40)SHPAR(1),SHPAR(2),SHPAR(3)
      ENDIF
C***********************************************************************
C
C   Obtain names of file(s) containing dielectric function(s)
C   NCOMP = number of different dielectric functions
C   CFLEPS(1-NCOMP) = names of files containing dielectric functions
C
      READ(IOPAR,FMT=*,ERR=40)NCOMP
C
C*** Check that MXCOMP is large enough *********************************
      IF(NCOMP.GT.MXCOMP)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP > MXCOMP: must increase MXCOMP in DDSCAT')
C
C*** Check that NCOMP=2 if CSHAPE=UNICYL *******************************
C                     3           ANIELL
C                     2           TWOELL
C                     3           THRELL
C                     6           TWOAEL
C                     9           THRAEL
C                     2           CONELL
C                     2           TWOSPH
      IF(CSHAPE.EQ.'UNICYL'.AND.NCOMP.NE.2)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 2 for option UNICYL')
      IF(CSHAPE.EQ.'ANIELL'.AND.NCOMP.NE.3)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 3 for option ANIELL')
      IF(CSHAPE.EQ.'TWOELL'.AND.NCOMP.NE.2)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 2 for option TWOELL')
      IF(CSHAPE.EQ.'THRELL'.AND.NCOMP.NE.3)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 3 for option THRELL')
      IF(CSHAPE.EQ.'TWOAEL'.AND.NCOMP.NE.6)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 6 for option TWOAEL')
      IF(CSHAPE.EQ.'THRAEL'.AND.NCOMP.NE.9)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 9 for option THRAEL')
      IF(CSHAPE.EQ.'CONELL'.AND.NCOMP.NE.2)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 2 for option CONELL')
      IF(CSHAPE.EQ.'TWOSPH'.AND.NCOMP.NE.2)
     &   CALL ERRMSG('FATAL','REAPAR',
     &   'NCOMP must be 2 for option TWOSPH')
C***********************************************************************
      READ(IOPAR,FMT=*,ERR=40)CDIEL
      IF(CDIEL.EQ.'TABLES')THEN
         DO 1000 J=1,NCOMP
             READ(IOPAR,FMT=*,ERR=40)CFLEPS(J)
 1000    CONTINUE
      ELSEIF(CDIEL.EQ.'H2OICE'.OR.CDIEL.EQ.'H2OLIQ')THEN
         IF(NCOMP.GT.1)CALL ERRMSG('FATAL','REAPAR',
     &                              'H2OICE/LIQ with NCOMP>1?')
      ELSE
         CALL ERRMSG('FATAL','REAPAR','Unrecognized option for CDIEL')
      ENDIF
C***********************************************************************
C
C    Define INITIALIZATION:
C
C    INIT = 0 to start with |X0>=0
C           1 to obtain |X0> from 4th-order expansion in polarizability
C           2 to read |X0> from file solvp.in
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
      READ(IOPAR,FMT=*,ERR=40)INIT
      IF(INIT.EQ.0)THEN
         CALL WRIMSG('REAPAR',
     &               'INIT=0 to start with |X0>=0 (CCG method)')
      ELSEIF(INIT.EQ.1)THEN
         CALL WRIMSG('REAPAR',
     &         'INIT=1 to obtain |X0> from 4th-order expansion (CCG)')
      ELSEIF(INIT.EQ.2)THEN
         CALL WRIMSG('REAPAR',
     &        'INIT=2 to read |X0> from file solvp.in')
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' Wrong value of INIT')
      ENDIF
C***********************************************************************
C
C    Define error tolerance:
C
C    TOL= maximum acceptable value of |Ax-E|/|E|
C
      READ(IOPAR,FMT=*,ERR=40)TOL
      IF(TOL.GT.1.E-15.AND.TOL.LT.1.E-1)THEN
         WRITE(CMSGNM,FMT='(1P,E10.3,A)')TOL,
     &         ' = TOL = max. acceptable normalized residue |Ax-E|/|E|'
         CALL WRIMSG('REAPAR',CMSGNM)
      ELSE
         CALL ERRMSG('WARNING','REAPAR',' Strange value of TOL ')
      ENDIF
C***********************************************************************
C
C    Define NUMBER OF THETA AND PHI VALUES FOR EVALUATION OF CSCA AND G
C
C    ICTHM = number of thetan values to use in evaluation of CSCA, G
C            (must be odd; recommend ICTHM=33)
C    IPHM  = number of phin values to use in evaluation of CSCA, G
C            (even or odd; recommend IPHM=12 or more)
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
      READ(IOPAR,FMT=*)ICTHM
      IF((ICTHM+1)/2*2 .NE. (ICTHM+1))THEN
         CALL ERRMSG('FATAL','REAPAR',' ICTHM SHOULD BE ODD ')
      ELSE
         WRITE(CMSGNM,FMT='(I4,A)')ICTHM,
     &' - ICTHM; number of THETAN values for calc.of g and Qsca by SCAT'
         CALL WRIMSG('REAPAR',CMSGNM)
      ENDIF
      READ(IOPAR,FMT=*)IPHM
      WRITE(CMSGNM,FMT='(I4,A)')IPHM,
     &' - IPHM; number of PHIN values for calc. of g and Qsca by SCAT'
      CALL WRIMSG('REAPAR',CMSGNM)
C***********************************************************************
C
C    Define WAVELENGTH :
C
C    WAVINI = first wavelength (physical units)
C    WAVEND = last wavelength (physical units)
C    NWAV   = number of wavelengths
C    CDIVID = 'LIN', 'LOG', or 'INV' for equal increments in
C             wavelength, log(wavelength), or frequency
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
      READ(IOPAR,FMT=*,ERR=40)WAVINI,WAVEND,NWAV,CDIVID
      WRITE(CMSGNM,FMT='(I3,A,F7.4,A,F7.4)')
     &      NWAV,' wavelengths from ',WAVINI,' to ',WAVEND
      CALL WRIMSG('REAPAR',CMSGNM)
      CALL DIVIDE(CDIVID,WAVINI,WAVEND,NWAV,MXWAV,WAVEA)
C***********************************************************************
C
C    Define AEFF = radius of equal-volume sphere (physical units)
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
      READ(IOPAR,FMT=*)AEFINI,AEFEND,NRAD,CDIVID
      WRITE(CMSGNM,FMT='(I3,A,F7.4,A,F7.4)')
     &      NRAD,' eff. radii from ',AEFINI,' to ',AEFEND
      CALL WRIMSG('REAPAR',CMSGNM)
      CALL DIVIDE(CDIVID,AEFINI,AEFEND,NRAD,MXRAD,AEFFA)
C***********************************************************************
C
C    Define incident polarizations (in Lab Frame)
C    It is assumed that incident radiation is along x axis in Lab Frame
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
C Read complex polarization vector CXE01=e01 (normalize if necessary).
      READ(IOPAR,FMT=*,ERR=40)CXE01
      E1=SQRT(CXE01(1)*CONJG(CXE01(1)))
      IF(E1.NE.0.)THEN
         CALL ERRMSG('FATAL','REAPAR',' CXE01(1) must be zero!')
      ENDIF
C Normalize:
      E1=SQRT(CXE01(2)*CONJG(CXE01(2))+CXE01(3)*CONJG(CXE01(3)))
      CXE01(2)=CXE01(2)/E1
      CXE01(3)=CXE01(3)/E1
C Construct orthogonal normalized polarization vector CXE02=e02
C using xhat cross e01* = e02
C 
      CXE02(1)=(0.,0.)
      CXE02(2)=-CONJG(CXE01(3))
      CXE02(3)=CONJG(CXE01(2))
C
C IORTH=1 to calculate only for single polarization
C      =2 to also calculate for orthogonal polarization
      READ(IOPAR,FMT=*,ERR=40)IORTH
C
C***********************************************************************
C
C    Specify whether or not to write ".sca" files
C
C IWRKSC=0 to NOT write ".sca" file for each target orientation
C       =1 to write ".sca" file for each target orientation
      READ(IOPAR,FMT=*,ERR=40)IWRKSC
C
C***********************************************************************
C
C    Read information determining target rotations
C
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
      READ(IOPAR,FMT=*)BETAMI,BETAMX,NBETA
      READ(IOPAR,FMT=*)THETMI,THETMX,NTHETA
      READ(IOPAR,FMT=*)PHIMIN,PHIMAX,NPHI
C
C*** Check that values of NBETA,NTHETA,NPHI are OK:
      IF(NBETA.GT.MXBETA)
     &   CALL ERRMSG('FATAL','REAPAR',' NBETA>MXBETA: must recompile')
      IF(NPHI.GT.MXPHI)
     &   CALL ERRMSG('FATAL','REAPAR',' NPHI>MXPHI: must recompile')
      IF(NTHETA.GT.MXTHET)
     &   CALL ERRMSG('FATAL','REAPAR',' NTHETA>MXTHET: must recompile')
C
C If NPHI>1, then set IORTH=2 regardless of value input.
      IF(IORTH.EQ.1.AND.NPHI.GT.1)THEN
         IORTH=2
         CALL WRIMSG('REAPAR',
     &               'Set IORTH=2 since NPHI>1 ')
      ENDIF
C
      IF(IORTH.EQ.1)THEN
         CALL WRIMSG('REAPAR',
     &               'Calculate only for single polarization ')
      ELSEIF(IORTH.EQ.2)THEN
         CALL WRIMSG('REAPAR',
     &               'Do orthogonal polarization for each case ')
      ELSE
         CALL ERRMSG('FATAL','REAPAR',' WRONG VALUE OF IORTH ')
      ENDIF
      WRITE(CMSGNM,FMT='(2F7.2,A,I4)')BETAMI,BETAMX,
     &  ' Range of BETA values ; NBETA =',NBETA
      CALL WRIMSG('REAPAR',CMSGNM)
      WRITE(CMSGNM,FMT='(2F7.2,A,I4)')THETMI,THETMX,
     &  ' Range of THETA values; NTHETA=',NTHETA
      CALL WRIMSG('REAPAR',CMSGNM)
      WRITE(CMSGNM,FMT='(2F7.2,A,I4)')PHIMIN,PHIMAX,
     &  ' Range of PHI values ;   NPHI =',NPHI
      CALL WRIMSG('REAPAR',CMSGNM)
C Convert from degrees to radians
      BETAMI=BETAMI/DEGRAD
      BETAMX=BETAMX/DEGRAD
      THETMI=THETMI/DEGRAD
      THETMX=THETMX/DEGRAD
      PHIMIN=PHIMIN/DEGRAD
      PHIMAX=PHIMAX/DEGRAD
C***********************************************************************
C
C    Specify scattering directions to be calculated
C    THETAN,PHIN = Direction of n from n0 in calculation of the
C                  scattering matrix; cos(THETAN) is n0 \dot n
C                  and PHIN is azimuthal angle of n from Lab xy plane
C                  Note: THETA1, THETA2, and PHI for each scattering
C                  plane are entered in degrees, and immediately 
C                  converted to radians.  Arbitrary number
C                  of scattering planes may be considered.
C
      NSCA=0
      READ(IOPAR,FMT=*,ERR=40)CLINE
      CALL WRIMSG(' ',CLINE)
 22   READ(IOPAR,FMT=*,ERR=40,END=25)PHI1,THETA1,THETA2,DTHETA
      WRITE(CMSGNM,FMT='(3F7.1,A)')PHI1,THETA1,THETA2,
     &  ' = phi, theta_min, theta_max for scattering plane'
      CALL WRIMSG('REAPAR',CMSGNM)
C Convert to radians:
      PHI1=PHI1/DEGRAD
      THETA1=THETA1/DEGRAD
      THETA2=THETA2/DEGRAD
      DTHETA=DTHETA/DEGRAD
C Allow for possibility that user did not enter correct sign for
C DTHETA (if I did it, others will too...)
      IF(THETA2.LT.THETA1)DTHETA=-ABS(DTHETA)
C compute theta values for this scattering plane
      NSCA0=1
      DELTA=THETA2-THETA1
      IF(DELTA.NE.0)NSCA0=1+INT(DELTA/DTHETA+0.5)
C Check that there is enough storage space:
      IF((NSCA+NSCA0).GT.MXSCA)THEN
         WRITE(IDVOUT,FMT='(I6,I6,A)')MXSCA,NSCA0,
     &         ' =MXSCA,NSCA0 (dirs in this scatt. plane)'
         CALL ERRMSG('FATAL','REAPAR',
     &               'MXSCA too small in DDSCAT')
      ENDIF
      THETAN(NSCA+1)=THETA1
      IF(NSCA0.GT.2)THEN
         DO 23 J=2,NSCA0-1
            THETAN(NSCA+J)=THETA1+(J-1)*DTHETA
 23      CONTINUE
      ENDIF
      THETAN(NSCA+NSCA0)=THETA2
      DO 24 J=1,NSCA0
         PHIN(NSCA+J)=PHI1
 24   CONTINUE
      NSCA=NSCA+NSCA0
      WRITE(CMSGNM,FMT='(I4,A)')NSCA0,
     &  ' = number of scattering angles in this scattering plane'
      CALL WRIMSG('REAPAR',CMSGNM)
      GOTO 22
 25   CONTINUE
C
C Check that if user has requested computation of f_ml, user has
C also requested linearly-polarized incident radiation.
C 96.01.25 (BTD) We have disabled this "protection".  So long as user
C is aware that when using elliptical incident polarization the
C f_ml are not the "usual" ones with index l referring to linearly
C polarized incident modes, there is not reason not to allow user
C to calculate f_ml for the the scattered radiation.
C
C      IF(NSCA.GT.0)THEN
C         DO 26 J=1,3
C            IF(AIMAG(CXE01(J)).NE.0.)CALL ERRMSG('FATAL','REAPAR',
C     &      'pol. vector E01 is complex: DDSCAT cannot compute f_ml, so 
C     &do not ask it to!')
C 26      CONTINUE
C      ENDIF
C
      CLOSE (IOPAR)
      RETURN
   40 CONTINUE
      CALL ERRMSG('FATAL','REAPAR',' Error reading ddscat.par file')
      RETURN
      END
