!-------------------------------------- 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 v4d_config
*
#include "model_macros_f.h"
*

      integer function v4d_config () 1,2
*
      use v4dz, only: V4dz_degree,V4dzge_degree,V4dzga_degree 
*
      implicit none
*
*author
*     M. Desgagne    - Summer 2006
*
*revision
* v3_30 - Desgagne M. - initial version 
* v3_31 - Tanguay  M. - Control BC
*
*object
*
#include "out3.cdk"
#include "lun.cdk"
#include "step.cdk"
#include "path.cdk"
#include "init.cdk"
#include "schm.cdk"
#include "v4dg.cdk"
#include "tr3d.cdk"
#include "v4dj.cdk"
#include "v4dm.cdk"
#include "v4dr.cdk"
#include "v4dg_bc.cdk"
#include "v4d_nml.cdk"
*
      integer fnom
      external fnom
*
      integer err
*
*-------------------------------------------------------------------
*
      v4d_config = -1
      if ( V4dg_conf.ne.0.and.Step_total.lt.Init_dfnp-1.and.Init_balgm_L ) then
           if (lun_out.gt.0) write(Lun_out,9400)
           return
      endif
      if ( V4dg_conf.ne.0.and.Schm_theoc_L) then
           if (lun_out.gt.0) write(Lun_out,9401)
           return
      endif
      if ((V4dg_conf/100.ne.1) .and.
     $    (V4dg_sensib_L.or.V4dg_twin_L.or.V4dg_4dvar_L.or.V4dg_sgvc_L))
     $     then
         if (lun_out.gt.0) write(Lun_out,9300)
         return
      endif
*
      if (V4dg_conf.ne.0) then
         call v4d_init()
         Out3_ndigits = 6
         Schm_wload_L  = .false.
      endif
      if ((V4dg_conf/100.eq.1.and.V4dg_sensib_L).or.
     $   ((V4dg_conf/100.eq.4.or.V4dg_conf/100.eq.5).and.V4dg_anincr_L)) then
        V4dg_lun_obs_s=trim(Path_input_S)//'/v4d_obsfile_std'
        V4dg_lun_obs = 0
        err = fnom (V4dg_lun_obs,V4dg_lun_obs_s,'RND+OLD', 0)
      endif
*
      if ((V4dg_conf.ne.0).and.(lun_out.gt.0)) write (lun_out,nml=var4d)
*
      v4d_config = 1
*
 9300 format (/,' sensib_L twin_L 4dvar_L sgvc_L when V4dg_conf/100=1 only'/)  
 9400 format (/,' Step_total lt Init_dfnp-1 and Init_balgm_L  when V4dg_conf.ne.0 NOT VALID '/)
 9401 format (/,' Schm_theoc_L when V4dg_conf.ne.0 NOT VALID '/)
*
*-------------------------------------------------------------------
*
      end