SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
add_forecast_to_date_surf.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 add_forecast_to_date_surf(KYEAR,KMONTH,KDAY,PSEC)
7 ! #######################################################
8 !
9 !!**** *ADD_FORECAST_TO_DATE* - finds the current date and hour of a forecast
10 !!
11 !! PURPOSE
12 !! -------
13 !!
14 !! WARNING
15 !!
16 !! -----> Only correct for dates between 19900301 and 21000228 <-----
17 !!
18 !! The correct test should be:
19 !! IF( ((MOD(KYEAR,4)==0).AND.(MOD(KYEAR,100)/=0)) .OR. (MOD(KYEAR,400)==0))THEN
20 !!
21 !!** METHOD
22 !! ------
23 !!
24 !! A recursive method is used, adding one day ofter the other.
25 !!
26 !! EXTERNAL
27 !! --------
28 !!
29 !! IMPLICIT ARGUMENTS
30 !! ------------------
31 !!
32 !! REFERENCE
33 !! ---------
34 !!
35 !! Book 2
36 !!
37 !! AUTHOR
38 !! ------
39 !!
40 ! V.Masson Meteo-France
41 !!
42 !! MODIFICATIONS
43 !! -------------
44 !! Original 01/09/95
45 !-------------------------------------------------------------------------------
46 !
47 !* 0. DECLARATIONS
48 ! ------------
49 !
50 !
51 USE yomhook ,ONLY : lhook, dr_hook
52 USE parkind1 ,ONLY : jprb
53 !
54 IMPLICIT NONE
55 !
56 !* 0.1 Declaration of arguments
57 ! ------------------------
58 INTEGER, INTENT(INOUT) :: kyear ! year of date
59 INTEGER, INTENT(INOUT) :: kmonth ! month of date
60 INTEGER, INTENT(INOUT) :: kday ! day of date
61 REAL, INTENT(INOUT) :: psec ! number of seconds since date at 00 UTC
62 !
63 !* 0.2 Declaration of local variables
64 ! ------------------------------
65 !
66 INTEGER :: idays ! number of days in KMONTH
67 REAL(KIND=JPRB) :: zhook_handle
68 !-------------------------------------------------------------------------------
69 !
70 !* 1. Return condition: less than one day to add
71 ! ------------------------------------------
72 !
73 IF (lhook) CALL dr_hook('ADD_FORECAST_TO_DATE_SURF',0,zhook_handle)
74 DO
75  IF (86400.-psec > 1.e-6) EXIT
76 !
77 !-------------------------------------------------------------------------------
78 !
79 !* 2. Adding one day
80 ! --------------
81 !
82  psec=psec-86400.
83 !
84 !* 2.1 Number of days in a month
85 ! -------------------------
86 !
87  SELECT CASE (kmonth)
88  CASE(4,6,9,11)
89  idays=30
90  CASE(1,3,5,7:8,10,12)
91  idays=31
92  CASE(2)
93  IF( ((mod(kyear,4)==0).AND.(mod(kyear,100)/=0)) .OR. (mod(kyear,400)==0))THEN
94  idays=29
95  ELSE
96  idays=28
97  ENDIF
98  END SELECT
99 !
100 !* 2.2 Last day of the month
101 ! ---------------------
102 !
103  IF (kday==idays) THEN
104  IF (kmonth==12) THEN
105  kday=1
106  kmonth=1
107  kyear=kyear+1
108  ELSE
109  kday=1
110  kmonth=kmonth+1
111  ENDIF
112 !
113 !* 2.3 Other days
114 ! ----------
115  ELSE
116  kday=kday+1
117  ENDIF
118 !
119 !-------------------------------------------------------------------------------
120 !
121 !* 3. Recursive call
122 ! --------------
123 !
124 ENDDO
125 IF (lhook) CALL dr_hook('ADD_FORECAST_TO_DATE_SURF',1,zhook_handle)
126 !
127 !-------------------------------------------------------------------------------
128 !
129 END SUBROUTINE add_forecast_to_date_surf
subroutine add_forecast_to_date_surf(KYEAR, KMONTH, KDAY, PSEC)