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

      subroutine les_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 "les.cdk"
#include "sor.cdk"
#include "path.cdk"
#include "lun.cdk"
#include "refer.cdk"
*
      integer unnml,pnerrdirf,pnflag1,pnflag2,i,j,k,err,longueur
      real*8 dayfrac
      character*12 nmlname
      namelist /les_cfgs/ gni,gnj,gnk,nktop,Grd_dx,htop,
     $               gnnt,gnnrstrt,grdt,gnnpbl,zt,hord_zspng,
     $               hblen_x,hblen_y,grtf,grtstar,vmh_stime,
     $               gnpvw,grpilver,gnpilver,vmh_ndt,flipit,
     $               grepsi,iscal,blb_zp,blb_xs,blb_zs,blb_xp,
     $               period_x,period_y,les_flo
      namelist /les_cfgs_p/ gni,gnj,gnk,nktop,Grd_dx,htop,
     $               gnnt,gnnrstrt,grdt,gnnpbl,hord_zspng,
     $               hblen_x,hblen_y,grtf,grtstar,vmh_stime,
     $               gnpvw,grpilver,gnpilver,vmh_ndt,flipit,
     $               grepsi,iscal,blb_zp,blb_xs,blb_zs,blb_xp,
     $               period_x,period_y,les_flo
      data unnml /11/
*
      status  = -1
      hx      = 3
      hy      = hx
      nmlname = 'les_cfgs'
*
      if (.not.modrstrt) then
*
*
         flipit     = .true.
         vmh_stime  = 0
         topo_folwing=.false.
*
         grtstar    = 273.15
         iscal(1)   = 1000000
         iscal(2)   = 1000000
         Grd_dx     = 20.
         htop       = 1000.
         gni        = 52
         gnj        = 12
         gnk        = 52
         nk         = gnk-1
         grtf       = 0.05        ! pretty important
*
         hblen_x    = 0
         hblen_y    = 0
         period_x   = .true.
         period_y   = .true.
*
         les_flo  = 10.
         grdt     = 5.0
         gnnt     = 100
         gnnrstrt = 400
         gnpilver = 0
         vmh_ndt  = 1
*
         grepsi   = 0.            ! No decentering of SI scheme
         hord_lnr = 0.            ! No diffusion
         gnmaphy  = 0             ! No physical parameterization
         nofcms   = .false.       ! and .true. Rotation; cartesian coordinates.
         nofcms   = .true.        ! and .false. Rotation; cartesian coordinates.
         flextop  = .false.
         slab     = .false.
*
         nktop    = -1
         gnnohyd  = 1             ! non-hydrostatic
         gnnpbl   = -1
         gnpvw    = 0
*
         do k=1,maxdynlv
            zt(k)=-1.0
         end do
         zt(1)    = 1.
*
         hord_zspng    = 0
         if(.not.topo_folwing) vmh_ndt=1

*---- Added nml parameters for the Color case
*
         blb_zp  = 25.
         blb_xp  = 25
         blb_xs  = 5
         blb_zs  = 3
*
* *** Updating configuration with namelist les_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=les_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)
*
      if(gnj.eq.2) slab=.true.
      if(gnj.eq.2) period_y=.false.
*
      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 = 'P'
      
      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=les_cfgs_p)
         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