copyright (C) 2001  MSC-RPN COMM  %%%MC2%%%
*

      subroutine brook_cfg (prout,status) 1,3
      implicit none
*
      logical prout
      integer status
*
#include "lcldim.cdk"
#include "rec.cdk"
#include "grd.cdk"
#include "cdate.cdk"
#include "levels.cdk"
#include "nesting.cdk"
#include "yomdyn.cdk"
#include "yomdyn1.cdk"
#include "filename.cdk"
#include "physcom.cdk"
#include "tracers.cdk"
#include "nbcpu.cdk"
#include "nestpnt.cdk"
#include "brook.cdk"
#include "path.cdk"
#include "lun.cdk"
#include "solver.cdk"
#include "sor.cdk"
*
      integer unnml,pnerrdirf,pnflag1,pnflag2,i,j,k,err,longueur
      real*8 dayfrac
      character*12 nmlname
      namelist /brook_cfgs/ gni,gnj,nk,nktop,Grd_dx,htop,
     $               gnnt,gnnrstrt,grdt,gnnpbl,zt,hord_zspng,
     $               hblen_x, hblen_y,gnpvw,grpilver,gnpilver,
     $               grepsi,bump_hwx,bump_hwy,bump_xpos,bump_ypos,
     $               bump_heigth,brook_flo,brook_thrate,precond,
     $               grtstar,vmh_stime,vmh_ndt,flipit,flextop,
     $               blb_zp,blb_xs,blb_zs,blb_xp,
     $               period_x,period_y
      data unnml /11/
*
      status  = -1
      hx      = 3
      hy      = hx
      nmlname = 'brook_cfgs'
*
      if (.not.modrstrt) then
*
* make sure you keep jacobi as a preconditionner
* make sure your basic state is isothermal
*
         precond    = 'JACOBI'
         grtstar    = 273.15
         iscal(1)   = 1000000
         iscal(2)   = 1000000
         htop       = 1.
         gni        = 82
         gnj        = 2           ! requires slab=.true.
         gnk        = 21
         nk         = gnk-1
         bump_hwx   = 5
         bump_hwy   = 3
         bump_xpos  = 41
         bump_ypos  = 1
         brook_thrate = 2.
*
*   CASE 1: FROUDE # < 1.
*
         Grd_dx  = 4.
         brook_flo  = 2.
*
*   CASE 2: FROUDE # > 1.
*
c        Grd_dx  = 8.
c        brook_flo  = 4.
*
         gnnt       = 600
         bump_heigth=0.01
         grdt     = 1.0
         gnnt     = 600
         gnpilver = 0
         grpilver = 1.
*
         grepsi   = 0.
         hord_lnr = 0.            ! No diffusion
         gnmaphy  = 0             ! No physical parameterization
         slab     = .true.        ! Slab-symmetry in y-direction.
         ctebcs   = .true.        ! Fixed boundary conditions.
         nofcms   = .true.        ! No rotation; cartesian coordinates.
         flextop  = .true.
*
         nktop    = -1
         gnnohyd  = 1             ! non-hydrostatic
         gnnrstrt = 12000
         gnnpbl   = -1
         gnpvw    = 0
         do k=1,maxdynlv
            zt(k)=-1.0
         end do
         zt(1)    = 1.
*
         hblen_x   = 15
         hblen_y   = 0
         hord_zspng= 0
         vmh_stime = 0
         vmh_ndt   = 90
         flipit    = .true.

*---- Added nml parameters for the Color case
         blb_zp  = 9000.
         blb_xp  = 25
         blb_xs  = 5
         blb_zs  = 3
*
* *** Updating configuration with namelist brook_cfgs
*
         open (unnml,file=nml,access='SEQUENTIAL',
     $         form='FORMATTED',status='OLD',iostat=pnerrdirf)
         if (pnerrdirf.ne.0) then
            print '(/,2x,a/2x,3a/)', '==> ABORT -- ABORT <==',
     $            'FILE ',nml(1:longueur(nml)),' NOT FOUND'
            goto 9991
         endif
*
         rewind ( unnml )
         read (unnml, nml=brook_cfgs, end=6121)   
         write (6,601) nmlname
         goto 603
 6121    write (6,602) nmlname
*
 603     close (unnml)
      else
*
         print '(1x,a/1x,3a)', 'WARNING --  RESTART MODE',
     $         'USING CONFIGURATION OF PREVIOUS RUN (',nmlname,')'
         stop
*
      endif
*
      status = 1
      goto 9991
 9120 write (6, 9150) nmlname,nml
 9991 continue
#if defined (NEC) || defined (HPPA)
      call flush (6)
#endif
*
      if (period_x) then
         hblen_x = 0
      endif
      if (period_y) then
         hblen_y = 0
      endif
      hblen_x  = min(max(hblen_x,0),(gni/2-1))
      hblen_y  = min(max(hblen_y,0),(gnj/2-1))
      nktop = min(gnk-1,max(0,nktop))
      hord_zspng = min(gnk-2,max(0,hord_zspng))
      if (hord_zspng.gt.0) hord_zspng=max(4,hord_zspng)
*
      gcrunstrt = "19980101.000000"
      gcjobstrt = gcrunstrt
      dayfrac=(gnnt*grdt)/86400.0
      call  incdatsd(gcjobend,gcrunstrt,dayfrac)
      gcrunend = gcjobend
      call datp2f (gnidate,gcrunstrt)
      Grd_ni = gni
      Grd_nj = gnj
      Grd_proj_S = 'X'
      
      call hpalloc (paxp ,gni*2    , err,1)
      call hpalloc (payp ,gnj*2    , err,1)
*
      xref = 1000000.
      yref = 1005000.
      Grd_dgrw  = 0.
*
      gnstepno= 0
*
      call gllvls (gnk)
*      
      Pil_nesdt = 0
c     trpil(1) = 'BU  '
      do i=1,maxntrpil
         trpil(i) = '@#@#'
      end do
*
      if (prout) then
*
*        Print control parameters
*
         print*
         write (6, nml=brook_cfgs)
         print*
      endif
*
 601  format (' CONFIGURATION UPDATED again WITH NAMELIST ',a)
 602  format (' NAMELIST ',a,' NOT FOUND - USING DEFAULT CONFIGURATION')
 9150 format (/,2x,'==> ABORT -- ABORT <=='/2x,'NAMELIST ',a,
     $             ' NOT FOUND ON FILE ',a/)
*
      return
      end