!-------------------------------------- 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_rwtraj_sigma - Read (Write) from (on) TRAJ WA file for sigma levels
*
#include "model_macros_f.h"
*

      subroutine v4d_rwtraj_sigma(F_sig, DIST_DIM, Nk) 3,2
*
      implicit none
*
      integer DIST_DIM, Nk
      real F_sig (DIST_SHAPE,Nk)
*
*author
*     Stephane Laroche
*
*revision
* v3_00 - Laroche S.        - initial MPI version (from v4d_rwtraj)
* v3_11 - Tanguay M.        - ADJ of digital filter
* v3_30 - Tanguay M.        - Validation for LAM Nonhyd 
*
*object
*
*     TRAJ for invariant sigma field in simplified physics
*
*arguments
*  Name        I/O                 Description
*----------------------------------------------------------------
* F_sig        I/O                 Sigma field with HALO
* DIST_DIM     I                   Horizontal dim. of F_sig
* Nk           I                   Vertical   dim. of F_sig
*	
*
*implicits
#include "glb_ld.cdk"
#include "lun.cdk"
#include "schm.cdk"
#include "v4dg.cdk"
#include "p4d_simp.cdk"
*
      integer iadd
*
      logical plpr_L
*
*     Work arrays 
*     -----------
      real work(l_ni*l_nj*l_nk)
*
*     ______________________________________________________
*
*     Flag to trace storing and retrieving of trajectory
*     --------------------------------------------------
      plpr_L = .false.
      plpr_L = plpr_L.and.Lun_out.gt.0 
*
      iadd = 1

      if(P4d_sigma_wrt) then

*         -----------------
*         Write SIGM Fields (note: this field is written only once)
*         -----------------
          call v4d_rwfld (F_sig,work,l_ni,l_nj,LDIST_DIM,l_nk,
     %                    V4dg_iunph,iadd,plpr_L,'SIGM',V4dg_ad_L,0,1)
*
          P4d_sigma_wrt  = .false.

      else

*         ----------------
*         Read SIGM Fields 
*         ----------------
          call v4d_rwfld (F_sig,work,l_ni,l_nj,LDIST_DIM,l_nk,
     %                    V4dg_iunph,iadd,plpr_L,'SIGM',V4dg_ad_L,0,-1)
*
      endif
*
      return
      end