SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
interpol_sst_mth.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 ! #########
6  SUBROUTINE interpol_sst_mth (S, &
7  kyear,kmonth,kday,hflag,pout)
8 ! #######################################################
9 !
10 !!**** *INTERPOL_SST_MTH* - Interpolation of monthly SST, SSS, SIT or SIC
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !!
16 !!** METHOD
17 !! ------
18 !!
19 !!
20 !! EXTERNAL
21 !! --------
22 !!
23 !! IMPLICIT ARGUMENTS
24 !! ------------------
25 !!
26 !! REFERENCE
27 !! ---------
28 !!
29 !! AUTHOR
30 !! ------
31 !!
32 ! B.Decharme Meteo-France
33 !!
34 !! MODIFICATIONS
35 !! -------------
36 !! Original 28/01/10
37 !! Modified 02/2014 S. Senesi : allow to work on SSS, SIT and SIC fields
38 !! Modified 07/2015 B. Decharme : new linear interpolation
39 !-------------------------------------------------------------------------------
40 !
41 !* 0. DECLARATIONS
42 ! ------------
43 !
44 USE modd_seaflux_n, ONLY : seaflux_t
45 !
46 USE modi_abor1_sfx
47 !
48 USE yomhook ,ONLY : lhook, dr_hook
49 USE parkind1 ,ONLY : jprb
50 !
51 IMPLICIT NONE
52 !
53 !* 0.1 Declaration of arguments
54 !------------------------
55 !
56 !
57 TYPE(seaflux_t), INTENT(INOUT) :: s
58 !
59 INTEGER, INTENT(IN) :: kyear ! year of date
60 INTEGER, INTENT(IN) :: kmonth ! month of date
61 INTEGER, INTENT(IN) :: kday ! day of date
62  CHARACTER(LEN=1), INTENT(IN) :: hflag ! 'T' for SST, 'S' for SSS, 'H' for SIT, 'C' for SIC
63 !
64 REAL, DIMENSION(:), INTENT(OUT) :: pout ! Sea surface temperature or salinity, or SIC or SIT at time t
65 !
66 !* 0.2 Declaration of local variables
67 ! ------------------------------
68 !
69 REAL :: zdat ! current day in the current month
70 REAL :: zndat ! number of days in the current month
71 INTEGER :: imth0 ! previous month
72 INTEGER :: imth1 ! current month
73 INTEGER :: imth2 ! next month
74 INTEGER :: indays ! number of days in KMONTH
75 !
76 INTEGER :: idelta
77 !
78 REAL(KIND=JPRB) :: zhook_handle
79 !-------------------------------------------------------------------------------
80 !
81 !* 1. Number of days in a month
82 ! -------------------------
83 !
84 IF (lhook) CALL dr_hook('INTERPOL_SST_MTH',0,zhook_handle)
85 IF ( (hflag/='S') .AND. (hflag/='T') .AND. (hflag/='H') .AND. (hflag/='C') )THEN
86  CALL abor1_sfx('FATAL ERROR in INTERPOL_SST_MTH : HFLAG not S nor T nor C nor H. !')
87 ENDIF
88 SELECT CASE (kmonth)
89  CASE(4,6,9,11)
90  indays=30
91  CASE(1,3,5,7:8,10,12)
92  indays=31
93  CASE(2)
94  IF( ((mod(kyear,4)==0).AND.(mod(kyear,100)/=0)) .OR. (mod(kyear,400)==0))THEN
95  indays=29
96  ELSE
97  indays=28
98  ENDIF
99 END SELECT
100 !
101 !
102 !-------------------------------------------------------------------------------
103 !
104 !* 2. SST or SSS Interpolation using previous, current and next month
105 ! --------------------------------------------------------
106 !
107 zdat = REAL(kday)
108 zndat= REAL(indays)
109 !
110 ! The current month correspond to the indice 2 (or 3 if next month)
111 !
112 IF (kmonth==s%TZTIME%TDATE%MONTH) THEN
113  idelta=0
114 ELSE
115  idelta=1
116 END IF
117 !
118 imth0=1+idelta
119 imth1=2+idelta
120 imth2=3+idelta
121 !
122 IF (hflag =='T') THEN
123  CALL interpol_local(s%CINTERPOL_SST,s%XSST_MTH(:,imth0),s%XSST_MTH(:,imth1),s%XSST_MTH(:,imth2))
124 ELSEIF (hflag =='S') THEN
125  CALL interpol_local(s%CINTERPOL_SSS,s%XSSS_MTH(:,imth0),s%XSSS_MTH(:,imth1),s%XSSS_MTH(:,imth2))
126  pout(:) = max(0.0,pout(:))
127 ELSEIF (hflag =='H') THEN
128  CALL interpol_local(s%CINTERPOL_SIT,s%XSIT_MTH(:,imth0),s%XSIT_MTH(:,imth1),s%XSIT_MTH(:,imth2))
129  pout(:) = max(0.0,pout(:))
130 ELSEIF (hflag =='C') THEN
131  CALL interpol_local(s%CINTERPOL_SIC,s%XSIC_MTH(:,imth0),s%XSIC_MTH(:,imth1),s%XSIC_MTH(:,imth2))
132  pout(:) = max(0.0,min(1.0,pout(:)))
133 ENDIF
134 !
135 IF (lhook) CALL dr_hook('INTERPOL_SST_MTH',1,zhook_handle)
136 !
137 !=======================================================================================
138 !
139  CONTAINS
140 !
141 !=======================================================================================
142 !
143 SUBROUTINE interpol_local(HMETHOD,PMTH0,PMTH1,PMTH2)
144 !
145 USE modi_interpol_quadra
146 USE modi_interpol_linear
147 !
148 IMPLICIT NONE
149 !
150  CHARACTER(LEN=6), INTENT(IN) :: hmethod
151 REAL, DIMENSION(:) , INTENT(IN) :: pmth0
152 REAL, DIMENSION(:) , INTENT(IN) :: pmth1
153 REAL, DIMENSION(:) , INTENT(IN) :: pmth2
154 !
155 REAL(KIND=JPRB) :: zhook_handle
156 !
157 IF (lhook) CALL dr_hook('INTERPOL_SST_MTH:INTERPOL_LOCAL',0,zhook_handle)
158 !
159 IF(hmethod=='QUADRA')THEN
160  CALL interpol_quadra(zdat,zndat,pmth0,pmth1,pmth2,pout)
161 ELSEIF(hmethod=='LINEAR')THEN
162  CALL interpol_linear(zdat,zndat,pmth0,pmth1,pmth2,pout)
163 ELSEIF(hmethod=='UNIF')THEN
164  pout(:) = pmth1(:)
165 ELSE
166  CALL abor1_sfx('INTERPOL_SST_MTH:INTERPOL_LOCAL: interpolation method not supported')
167 ENDIF
168 !
169 IF (lhook) CALL dr_hook('INTERPOL_SST_MTH:INTERPOL_LOCAL',1,zhook_handle)
170 !
171 END SUBROUTINE interpol_local
172 !
173 !-------------------------------------------------------------------------------
174 !
175 END SUBROUTINE interpol_sst_mth
subroutine interpol_quadra(PDAT, PNDAT, PVAL0, PVAL1, PVAL2, POUT)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine interpol_sst_mth(S, KYEAR, KMONTH, KDAY, HFLAG, POUT)
subroutine interpol_linear(PDAT, PNDAT, PVAL0, PVAL1, PVAL2, POUT)
subroutine interpol_local(HMETHOD, PMTH0, PMTH1, PMTH2)