SURFEX v8.1
General documentation of Surfex
get_prep_interp.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 SUBROUTINE get_prep_interp(KNP_IN,KNP_OUT,PVEGTYPE,PPATCH_IN,PPATCH_OUT,KMASK_IN)
6 !
7 USE modd_data_cover_par, ONLY : nvegtype
8 !
9 USE modi_vegtype_to_patch
10 !
11 USE yomhook ,ONLY : lhook, dr_hook
12 USE parkind1 ,ONLY : jprb
13 !
14 IMPLICIT NONE
15 !
16 INTEGER, INTENT(IN) :: KNP_IN
17 INTEGER, INTENT(IN) :: KNP_OUT
18 REAL, DIMENSION(:,:), INTENT(IN) :: PVEGTYPE
19 REAL, DIMENSION(:,:), INTENT(IN) :: PPATCH_IN
20 REAL, DIMENSION(:,:), INTENT(OUT) :: PPATCH_OUT
21 INTEGER, DIMENSION(:,:), INTENT(IN), OPTIONAL :: KMASK_IN
22 !
23 INTEGER, DIMENSION(SIZE(PPATCH_OUT,1),SIZE(PPATCH_IN,2)) :: IMASK_IN
24 REAL, DIMENSION(SIZE(PPATCH_OUT,1),SIZE(PPATCH_OUT,2)) :: ZPATCH_OUT
25 INTEGER :: JP, JVEG, IP_I, IP_O, JI, IMASK, JP2
26 !
27 REAL(KIND=JPRB) :: ZHOOK_HANDLE
28 !
29 IF (lhook) CALL dr_hook('GET_PREP_INTERP',0,zhook_handle)
30 !
31 
32 IF (PRESENT(kmask_in)) THEN
33  imask_in(:,:) = kmask_in(:,:)
34 ELSE
35  DO ji = 1,SIZE(imask_in,1)
36  imask_in(ji,:) = ji
37  ENDDO
38 ENDIF
39 !
40 zpatch_out(:,:) = 0.
41 !
42 ! if NPATCH (in) == NVEGTYPE, the arrays of patches is this of vegtypes
43 IF (knp_in==nvegtype) THEN
44  !
45  DO jveg = 1,nvegtype
46  ! mask of the output patch in which is this vegtype
47  ip_o = vegtype_to_patch(jveg,knp_out)
48  DO ji = 1,SIZE(imask_in,1)
49  imask = imask_in(ji,ip_o)
50  IF (imask/=0) zpatch_out(imask,jveg) = pvegtype(ji,jveg)
51  ENDDO
52  ENDDO
53  !
54 ! if there is the same number of patches before / after, patch_out = patch_in
55 ELSEIF (knp_in==knp_out) THEN
56  !
57  ! the mask can be applied to the patches before and after
58  DO jp2 = 1,SIZE(imask_in,2)
59  DO ji = 1,SIZE(imask_in,1)
60  imask = imask_in(ji,jp2)
61  IF (imask/=0) zpatch_out(imask,jp2) = ppatch_in(ji,jp2)
62  ENDDO
63  ENDDO
64  !
65 ! less patches before than after
66 ELSEIF (knp_in<knp_out) THEN
67  !
68  ! to which input patch contributes each output patch?
69  DO jp = 1,knp_out
70  ! which vegtype is in this output patch?
71  DO jveg = 1,nvegtype
72  ! output patch in which is this vegtype
73  ip_o = vegtype_to_patch(jveg,knp_out)
74  ! input patch in which is this vegtype
75  ip_i = vegtype_to_patch(jveg,knp_in)
76  !
77  ! if VEG is in JP
78  IF (ip_o==jp) THEN
79  ! the input patch takes the contribution of the output patch
80  DO ji = 1,SIZE(imask_in,1)
81  ! the mask is this of the current output patch
82  imask = imask_in(ji,ip_o)
83  IF (imask/=0) zpatch_out(imask,ip_i) = zpatch_out(imask,ip_i) + ppatch_in(ji,ip_o)
84  ENDDO
85  ! just one time if several vegtypes are in this patch JP
86  EXIT
87  ENDIF
88  ENDDO
89  ENDDO
90  !
91 ! more patches before than after
92 ELSEIF (knp_in>knp_out) THEN
93  !
94  ! for each input patch, what is the corresponding output patch?
95  DO jp = 1,knp_in
96  ! which vegtype is in this output patch?
97  DO jveg = 1,nvegtype
98  ! input patch in which is this vegtype
99  ip_i = vegtype_to_patch(jveg,knp_in)
100  ! output patch in which is this vegtype
101  ip_o = vegtype_to_patch(jveg,knp_out)
102  !
103  ! if VEG is in JP
104  IF (ip_i==jp) THEN
105  ! this input patch gets the value of the corresponding output patch
106  DO ji = 1,SIZE(imask_in,1)
107  imask = imask_in(ji,ip_o)
108  IF (imask/=0) zpatch_out(imask,ip_i) = ppatch_in(ji,ip_o)
109  ENDDO
110  ! just one time because another vegtype of IP_I will be also in IP_O
111  EXIT
112  ENDIF
113  ENDDO
114  ENDDO
115  !
116 ENDIF
117 !
118 ppatch_out(:,:) = zpatch_out(:,:)
119 !
120 IF (lhook) CALL dr_hook('GET_PREP_INTERP',1,zhook_handle)
121 !
122 END SUBROUTINE get_prep_interp
subroutine get_prep_interp(KNP_IN, KNP_OUT, PVEGTYPE, PPATCH_IN, PPATCH_OUT, KMASK_IN)
integer function vegtype_to_patch(IVEGTYPE, INPATCH)
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15