!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
***s/r var4d_nml
*
#include "model_macros_f.h"
*

      integer function var4d_nml (F_namelistf_S) 3,1
      use v4dz, only: V4dz_degree,V4dzge_degree,V4dzga_degree 
*
      implicit none
*
      character* (*) F_namelistf_S
*
*
*author
*     M. Desgagne    - Summer  2006
*
*revision
* v3_30 - Desgagne M.       - initial version
* v3_31 - Tanguay M.        - Control BC
*
*object
*  Default configuration and reading namelist var4d
*
*implicits
#include "lun.cdk"
#include "step.cdk"
#include "path.cdk"
#include "tr3d.cdk"
#include "v4dg.cdk"
#include "v4dj.cdk"
#include "v4dm.cdk"
#include "v4dr.cdk"
#include "v4dg_bc.cdk"
#include "v4d_nml.cdk"
*
      integer  fnom
      external fnom
*
      integer nrec,unf
*
*-------------------------------------------------------------------
*
      var4d_nml = -1
*
      if ((F_namelistf_S.eq.'print').or.(F_namelistf_S.eq.'PRINT')) then
         var4d_nml = 0
         if ((V4dg_conf.ne.0).and.(Lun_out.gt.0)) 
     $      write (Lun_out  ,nml=var4d)
         return
      endif
*
* Defaults values for var4d namelist variables
*
      V4dg_conf     = 0
      V4dg_output_L = .true.
      V4dg_sensib_L = .false.
      V4dg_twin_L   = .false.
      V4dg_4dvar_L  = .false.
      V4dg_sgvc_L   = .false.
      V4dj_mask_L   = .false.     
      V4dg_sgvc_dt0 = 0
      V4dg_chum_s   = 'LQ'
*
      V4dr_redotr_L = .false.
*
      V4dg_stepob   = Step_total
      V4dg_inv      = 1
      V4dg_incore_L = .true.
*
      V4dg_identity_L = .false.
*
      V4dg_pruv_L     = .true.
*
      V4dz_degree     = 1
      V4dzge_degree   = 1
      V4dzga_degree   = 1
*
      V4dg_anincr_L = .false.
*
      V4dm_itmax    = 2 
      V4dm_simax    = 2 
*
      V4dg_bc_variant = 0 
*
      if (F_namelistf_S .ne. '') then
*
         unf = 0
         if (fnom (unf, F_namelistf_S, 'SEQ' , nrec) .ne. 0) goto 6666
         rewind(unf)
         read (unf, nml=var4d   , end = 6655, err=9140)
*
 6655    call fclos (unf)

      endif
*
 6666 var4d_nml = 1
      goto 9999
*
 9140 call fclos (unf)
      if (Lun_out.gt.0) then
         write (Lun_out, 9350)
         write (Lun_out, 8000)
      endif
*
 8000 format (/,'========= ABORT IN S/R var4d_nml.f ============='/)
 9350 format (/,' NAMELIST var4d    INVALID IN FILE: model_settings '/)
*
*-------------------------------------------------------------------
*
 9999 return
      end