!-------------------------------------- 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 --------------------------------------

module v4d_prof  16
!_________________________________________________________________
!                                                                 |
! Parameters associated to exchange with 3D-Var using PROF files  | 
!_________________________________________________________________|
!
!author N. Ek
!
!revision
! v3_00 - N. Ek          - initial MPI version
! v3_00 - M. Tanguay     - adapt to Simon's exchange
! v3_11 - M. Tanguay     - correct relationship between stepob and timestep 
!                        - add option for profiles done on U-V grids for winds 
!
      implicit none
!
  save
!
!     Parameters linked to the event  
!     ------------------------------
      integer Pr_nevent
!
!     Parameters linked to PROF files  
!     -------------------------------
      logical Pr_llfrm_L 
      character*4 Pr_mode_S
      real*8 Pr_dsnooze_8
      integer Pr_ihdlin,Pr_ihdlout
      character*256 Pr_type2file_S,Pr_type3file_S 
!
      logical Pr_read_L, Pr_wopen_L, Pr_ropen_L
!
!     Parameters for extra 0-3hr TRAJ run  
!     -----------------------------------
      logical Pr_traj0to9_L
!
!     Parameters linked to simulation numbers  
!     ---------------------------------------
      integer Pr_nsim4d 
!
!     Parameters linked to profiles identification  
!     --------------------------------------------
      integer, parameter :: Pr_nvars = 5  ! UU, VV, TT, PS, (SPHU)
      character*2,dimension(Pr_nvars) :: Pr_varname
      integer,    dimension(Pr_nvars) :: Pr_varindx  ! initialized in v4d_setting
!
      integer, parameter :: Pr_maxnmv    = 31        ! Max. number of variables
      integer, parameter :: Pr_upperbin  = 12        ! Upper limit on number of bins
      integer Pr_ibin0                               ! Timestep of the first bin 
!
      type real2dptr
       real, pointer :: ptr                          ! Profile elements
      end type real2dptr 
!
      type modelprof
       sequence
       integer :: nprof                           ! Number of profiles
       integer, pointer, dimension(:)  :: obstag  ! Observations' tags
       integer, pointer, dimension(:)  :: mdltag  ! Model variables' tags
       real,    pointer, dimension(:)  :: px      ! Longitudes in model units (Z grid)
       real,    pointer, dimension(:)  :: py      ! Latitudes  in model units (Z grid)
       real,    pointer, dimension(:)  :: pxu     ! Longitudes in model units (U grid)
       real,    pointer, dimension(:)  :: pyv     ! Latitudes  in model units (V grid)
       real,    pointer, dimension(:,:):: fprof   ! Profiles of the variable               
      end type modelprof
!
!     Define structure l_mv
!     ---------------------
      type (modelprof), dimension(Pr_maxnmv,Pr_upperbin) :: Pr_l_mv
!
!     Array of pointers to real array
!     -------------------------------
      type (real2dptr), dimension(:,:,:), pointer :: Pr_mlprof
!
!     Bin associated to each model tag 
!     --------------------------------
      integer, pointer, dimension(:)  :: Pr_bintag ! Bin of mdltag 
!
!     Statistics for profiles  
!     -----------------------
      integer  Pr_maxbin                          ! number of bins   
      integer  Pr_maxprof                         ! number of profiles in lalo PROF file  
      integer  Pr_nobproc                         ! number of profiles in local processor  
      integer, pointer, dimension(:)  :: Pr_nob   ! number of profiles by bin in local proc.  
      integer, pointer, dimension(:)  :: Pr_doobs ! 1 if profiles in any proc. at this timestep       
!
      end module v4d_prof