****************************************************************************
*  defines grid points and truncation 
****************************************************************************

	INTEGER n_r_max       ! number of radial grid points, 
	                      ! must be of form 4*integer+1
			      ! Possible values for n_r_max:
	 		      !  5,9,13,17,21,25,33,37,41,49,
			      !  61,65,73,81,97,101,121,129,145,161 ...
        PARAMETER( n_r_max=145 )
        INTEGER n_cheb_max    ! max degree-1 of cheb polynomia
        PARAMETER( n_cheb_max=97 )

	INTEGER n_phi_tot     ! number of longitude grid points
	                      ! Possible valus: 
			      ! 16,32,48,64,96,128,192,256,288,320,384,
                              ! 400,512,576,640,768,864,1024
        PARAMETER( n_phi_tot=512 )

        INTEGER n_r_ic_max    ! number of grid points in inner core
        PARAMETER( n_r_ic_max=0 )
        INTEGER n_cheb_ic_max ! number of chebs in inner core
        PARAMETER( n_cheb_ic_max=0 )

	INTEGER minc          ! basic wavenumber, longitude symmetry  
        PARAMETER( minc=1 ) 

	INTEGER nalias        ! controlls dealiasing in latitude and 
		              ! longitude direction, no aliasing for nalias=20
		              !   20 <= nalias <= 30
        PARAMETER( nalias=20 )


c-- Drived quantities:

	INTEGER n_phi_max     ! absolute number of phi grid-points
        PARAMETER( n_phi_max=n_phi_tot/minc ) 

	INTEGER n_theta_max   ! number of theta grid-points
	PARAMETER( n_theta_max=n_phi_tot/2 )

	INTEGER l_max,m_max   ! max degree and order of Plms
        PARAMETER( l_max=(nalias*n_theta_max)/30 )
        PARAMETER( m_max=(l_max/minc)*minc )

	INTEGER n_m_max     ! max number of ms (different oders)
        PARAMETER( n_m_max=m_max/minc+1 )

	INTEGER lm_max         ! number of l/m combinations
        PARAMETER( lm_max=m_max*(l_max+1)/minc - 
     -                m_max*(m_max-minc)/(2*minc)+(l_max+1-m_max) )
	INTEGER lmP_max        ! number of l/m combination 
	                       ! if l runs to l_max+1
        PARAMETER( lmP_max=lm_max+n_m_max )

        INTEGER lm_max_real    ! number of l/m combination 
	                       ! for real representation (cos/sin)
        PARAMETER (lm_max_real=2*lm_max)

	INTEGER nrp,ncp
        PARAMETER( nrp=n_phi_max+2,ncp=nrp/2 )
 
	INTEGER n_r_tot        ! total number of radial grid points
	PARAMETER(n_r_tot=n_r_max+n_r_ic_max)

c--- Now quantities for magnetic fields:
c    Set lMag=0 if you want to save this memory (see c_fields)!
	INTEGER lMagMem
	PARAMETER( lMagMem=1 )
	INTEGER n_r_maxML,n_r_ic_maxML,n_r_totML,l_maxML,lm_maxML
	INTEGER n_r_maxMag,n_r_ic_maxMag,n_r_totMag,l_maxMag,lm_maxMag
	PARAMETER(n_r_maxML=lMagMem*n_r_max,n_r_ic_maxML=lMagMem*n_r_ic_max)
	PARAMETER(n_r_totML=lMagMem*n_r_tot,l_maxML=lMagMem*l_max)
	PARAMETER(lm_maxML=lMagMem*lm_max)
	PARAMETER(n_r_maxMag=MAX0(1,n_r_maxML))
	PARAMETER(n_r_ic_maxMag=MAX0(1,n_r_ic_maxML))
	PARAMETER(n_r_totMag=MAX0(1,n_r_totML))
	PARAMETER(l_maxMag  =MAX0(1,l_maxML))
	PARAMETER(lm_maxMag =MAX0(1,lm_maxML))

c-- Values for averaged fields, only necessary 
c   if average is desired (lAveMem=0).
	INTEGER lAveMem,n_r_max_ave,n_r_ic_max_ave,lm_max_ave
	INTEGER n_r_max_AL,n_r_ic_max_AL,lm_max_AL
	PARAMETER (lAveMem=0)
	PARAMETER (n_r_max_AL   =lAveMem*n_r_max)
	PARAMETER (n_r_ic_max_AL=lAveMem*n_r_ic_max)
	PARAMETER (lm_max_AL    =lAveMem*lm_max)
	PARAMETER (n_r_max_ave   =MAX0(n_r_max_AL,1))
	PARAMETER (n_r_ic_max_ave=MAX0(n_r_ic_max_AL,1))
	PARAMETER (lm_max_ave    =MAX0(lm_max_AL,1))

c-- Movie memory control:
	INTEGER lMovieMem,n_movie_work
	PARAMETER(lMovieMem=1)
	PARAMETER(n_movie_work=2)
	INTEGER ldtBMem,l_max_dtB,lm_max_dtB,n_r_max_dtB,n_r_ic_max_dtB
	INTEGER lmP_max_dtB
	INTEGER l_max_dL,lm_max_dL,lmP_max_dL,n_r_max_dL,n_r_ic_max_dL

c-- Memory control for calculation of RMS (dtB) forces and dynamo action (dtB)
	PARAMETER(ldtBMem=0)
	PARAMETER(l_max_dL     =ldtBMem*l_max)
	PARAMETER(lm_max_dL    =ldtBMem*lm_max)
	PARAMETER(lmP_max_dL   =ldtBMem*lmP_max)
	PARAMETER(n_r_max_dL   =ldtBMem*n_r_max)
	PARAMETER(n_r_ic_max_dL=ldtBMem*n_r_ic_max)
	PARAMETER(l_max_dtB     =MAX0(l_max_dL,1) )
	PARAMETER(lm_max_dtB    =MAX0(lm_max_dL,1) )
	PARAMETER(lmP_max_dtB   =MAX0(lmP_max_dL,1) )
	PARAMETER(n_r_max_dtB   =MAX0(n_r_max_dL,1) )
	PARAMETER(n_r_ic_max_dtB=MAX0(n_r_ic_max_dL,1) )
        INTEGER nrp_dtB,ncp_dtB,n_phi_max_dL,n_phi_max_dtB
	PARAMETER(n_phi_max_dL=ldtBMem*n_phi_max)
	PARAMETER(n_phi_max_dtB=MAX0(n_phi_max_dL,1))
        PARAMETER(nrp_dtB=n_phi_max_dtB+2,ncp_dtB=nrp_dtB/2 )

c--- Factor for mapping old data on new grid
c       memory for old data = n_map_fac * memory for new data
c       n_map_fac must be >= 1!
	INTEGER n_map_fac
	PARAMETER(n_map_fac=1)

c--- Memory control for stress output:
	INTEGER lStressMem
	PARAMETER(lStressMem=0)
	INTEGER n_r_maxStr,n_theta_maxStr,n_phi_maxStr
	INTEGER n_r_maxSL,n_theta_maxSL,n_phi_maxSL
	PARAMETER(n_r_maxSL     =lStressMem*n_r_max)
	PARAMETER(n_theta_maxSL =lStressMem*n_theta_max)
	PARAMETER(n_phi_maxSL   =lStressMem*n_phi_max)
	PARAMETER(n_r_maxStr    =MAX0(n_r_maxSL,1))
	PARAMETER(n_theta_maxStr=MAX0(n_theta_maxSL,1))
	PARAMETER(n_phi_maxStr  =MAX0(n_phi_maxSL,1))

c--- Memory control for Geotrophys output:
        INTEGER lGeos
        PARAMETER(lGeos=0)
        INTEGER n_r_maxGeos,lm_maxGeos,nrpGeos,ncpGeos
	INTEGER n_r_maxGL,lm_maxGL,nrpGL
        PARAMETER(n_r_maxGL  =lGeos*n_r_max)
        PARAMETER(lm_maxGL   =lGeos*lm_max)
        PARAMETER(nrpGL      =lGeos*nrp)
        PARAMETER(n_r_maxGeos=MAX0(n_r_maxGL,2))
        PARAMETER(lm_maxGeos =MAX0(lm_maxGL,2))
        PARAMETER(nrpGeos    =MAX0(nrpGL,2))
        PARAMETER(ncpGeos    =nrpGeos/2 )

c--- Memory control for vorticity output in s_outPV3.f
c    Set this to lPV=1 and then chose nSmax0 in s_outPV3.f
	INTEGER lPV
	PARAMETER(lPV=0)

c--------------------------------------------------------------------------
