FV3 Bundle
type_cv.F90
Go to the documentation of this file.
1 !----------------------------------------------------------------------
2 ! Module: type_cv
3 ! Purpose: control vector derived type
4 ! Author: Benjamin Menetrier
5 ! Licensing: this code is distributed under the CeCILL-C license
6 ! Copyright © 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
7 !----------------------------------------------------------------------
8 module type_cv
9 
10 use tools_kinds, only: kind_real
11 use type_cv_blk, only: cv_blk_type
12 
13 implicit none
14 
15 ! Control vector derived type
16 type cv_type
17  integer :: n ! Total control variable size
18  integer :: nbe ! Number of control variable blocks
19  type(cv_blk_type),allocatable :: blk(:) ! Control variable blocks
20 contains
21  procedure :: pack => cv_pack
22  procedure :: unpack => cv_unpack
23 end type cv_type
24 
25 private
26 public :: cv_type
27 
28 contains
29 
30 !----------------------------------------------------------------------
31 ! Subroutine: cv_pack
32 ! Purpose: pack control variable
33 !----------------------------------------------------------------------
34 subroutine cv_pack(cv,pcv)
35 
36 ! Passed variables
37 class(cv_type),intent(in) :: cv ! Control variable
38 real(kind_real),intent(out) :: pcv(cv%n) ! Packed control variable
39 
40 ! Local variable
41 integer :: ib,offset
42 
43 ! Initialization
44 offset = 0
45 
46 do ib=1,cv%nbe
47  if (cv%blk(ib)%n>0) then
48  ! Pack control variable
49  pcv(offset+1:offset+cv%blk(ib)%n) = cv%blk(ib)%alpha
50 
51  ! Update
52  offset = offset+cv%blk(ib)%n
53  end if
54 end do
55 
56 end subroutine cv_pack
57 
58 !----------------------------------------------------------------------
59 ! Subroutine: cv_unpack
60 ! Purpose: unpack control variable
61 !----------------------------------------------------------------------
62 subroutine cv_unpack(cv,pcv)
63 
64 ! Passed variables
65 class(cv_type),intent(inout) :: cv ! Control variable
66 real(kind_real),intent(in) :: pcv(cv%n) ! Packed control variable
67 
68 ! Local variable
69 integer :: ib,offset
70 
71 ! Initialization
72 offset = 0
73 
74 do ib=1,cv%nbe
75  if (cv%blk(ib)%n>0) then
76  ! Unpack control variable
77  cv%blk(ib)%alpha = pcv(offset+1:offset+cv%blk(ib)%n)
78 
79  ! Update
80  offset = offset+cv%blk(ib)%n
81  end if
82 end do
83 
84 end subroutine cv_unpack
85 
86 end module type_cv
subroutine cv_pack(cv, pcv)
Definition: type_cv.F90:35
subroutine cv_unpack(cv, pcv)
Definition: type_cv.F90:63
integer, parameter, public kind_real