!-------------------------------------- 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 rdrstrt - Read the restart file
*
#include "model_macros_f.h"
*

      subroutine rdrstrt () 1,5
*
      implicit none
*
*author
*     M. Desgagne - Mars 2000
*
*revision
* v2_00 - Desgagne M.       - initial MPI version
* v2_10 - Desgagne M.       - introduce WA files
* v2_30 - Dugas B.          - call ouvrstrt to open restrart file
* v2_30 - Corbeil L.        - Added reading of pres_surf and pres_top
* v2_31 - Desgagne M.       - Add Tr2d tracers
* v3_00 - Desgagne & Lee    - Lam configuration
* v3_21 - Valcke, S.        - Oasis coupling: Removed waread of c_cplg_step
* v3_21 - Lee V.            - Remove Tr2d tracers
* v3_30 - Desgagne M.       - restart for coupling
* v3_30 - Desgagne & Winger - Read one global binary restart file if existing
* v3_31 - Lee V.            - bugfix for restart for LAM BCS
* v3_31 - Desgagne M.       - new coupling interface to OASIS
* v3_31 - Desgagne M.       - restart with physics BUSPER
*
*object
*	
*arguments
*	none
*
*implicits
#include "lun.cdk"
#include "init.cdk"
#include "rstr.cdk"
#include "lctl.cdk"
#include "schm.cdk"
#include "itf_phy_buses.cdk"
#include "itf_cpl.cdk"
#include "glb_ld.cdk"
#include "pres.cdk"
#include "lam.cdk"
#include "itf_chm_bus.cdk"
#include "bcsmem.cdk"
#include "ifd.cdk"
*
**
      integer adr,ier,dim,current_nest,errft(3),unf
      integer fclos,ouvrstrt,wkoffit,bcs_ftype
      external fclos,ouvrstrt,wkoffit,bcs_ftype
      logical nav_L
*
*     ---------------------------------------------------------------
*
      Rstri_sdon = 0
      Lctl_step  = 0
      current_nest = 0
*
      if (Rstri_rstn_L) then
*
         if (wkoffit('../restart_glbphy.bin').eq.10 .or.
     &       wkoffit('../restart_glbchm.bin').eq.10 .or.
     &       wkoffit('../restart_glbcpl.bin').eq.10) then
*
*           Read one set of binary files for the whole domain
*
            call rd1rstrt ()
*
         else
*
*           Read one wa-file per tile
*
            if (Lun_rstrt .le. 0) Lun_rstrt = ouvrstrt( )
*
            call waopen (Lun_rstrt)
            call waread (Lun_rstrt,Lctl_step   ,1,1)
            call waread (Lun_rstrt,Rstri_idon_L,2,1)
            adr = 3
*
            call waread (Lun_rstrt,dim,adr,1)
            adr = adr + 1
            if (dim.gt.0) then
               if ( .not. associated ( Chm_busper3D ) ) 
     $                    allocate   ( Chm_busper3D (dim) )
               call waread (Lun_rstrt, Chm_busper3D,adr,dim)
               adr = adr + dim
            endif
*
            if (G_lam) then 
               call waread (Lun_rstrt,BCS_values,adr,BCS_siz_tot)
               adr = adr + bcs_siz_tot         
            endif
*
            call waread (Lun_rstrt, pres_surf ,adr, 1)
            adr = adr + 1
            call waread (Lun_rstrt, pres_top  ,adr, 1)
            adr = adr + 1
            call waread (Lun_rstrt, current_nest  ,adr, 1)
            adr = adr + 1 
*
            call waread (Lun_rstrt,dim,adr,1)
            adr = adr + 1
            if (dim>0) then
               if ( .not. associated ( atm_busin ) ) 
     $                    allocate   ( atm_busin (G_ni,dim) )
               call waread (Lun_rstrt, atm_busin ,adr, G_ni*dim)
               adr = adr + G_ni*dim
            endif
*
            call waclos(Lun_rstrt)
            ier = fclos(Lun_rstrt)  
         endif
*
         call datf2p (Lam_current_S,current_nest)
         errft = 0
         unf = 76
         nav_L = .false.
         ier = bcs_ftype (ifd_ftype,errft,Lam_current_S, nav_L, unf)
*
      endif
*
      call rdrstrt_phy ()
*
*     ---------------------------------------------------------------
*      
      return
      end