!-------------------------------------- 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 --------------------------------------
copyright (C) 2001  MSC-RPN COMM  %%%MC2%%%
*** e_sfile_3df - to open a new 3DF file 
*
#include "model_macros_f.h"
*

      subroutine e_sfile_3df (datev,msg,gid, gif, gjd, gjf, nvar,rootfn) 1,1
      implicit none
*
      character* (*) datev, msg, rootfn
      integer  gid, gif, gjd, gjf, nvar

*author  M. Desgagne 2001 (MC2 out_sfile_3df)
*
*revision
* v3_30 - Lee. V - modified to open a 3DF file for data extracted
*                  from analysis input
*
#include "e_anal.cdk"
#include "e_grids.cdk"
#include "grdc.cdk"
#include "e_tr.cdk"
#include "path.cdk"
*
      integer idg,jdg,mode,ntr
      character*2  md
      character*15 startindx
      character*512 filen
*
*------------------------------------------------------------------
*
*     Set the unit for cascade output
      unf_casc = 201
      idg=1
      jdg=1
      mode=2
      ntr=1+E_tr3d_ntr ! for HU
*
      write (md,'(i2.2)') mode
      write (startindx,'((i7.7),a1,(i7.7))') idg,'-',jdg
      filen= '3df'//md//'_'//trim(datev)//'_'//startindx
      filen= trim(rootfn)//trim(filen)

      open (unf_casc,file=filen,access='SEQUENTIAL',form='UNFORMATTED',
     $                                          position='APPEND')
      call wrgeo_3df (xg_8(gid),gif-gid+1,yg_8(gjd),gjf-gjd+1,
     $                z_8,pia,pibb,lv,nvar,ntr,unf_casc)
      write (unf_casc) msg,nvar+ntr,mode
*
*------------------------------------------------------------------
      return
      end