New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
daymod.F90 in trunk/NEMO/OPA_SRC – NEMO

source: trunk/NEMO/OPA_SRC/daymod.F90 @ 68

Last change on this file since 68 was 68, checked in by opalod, 20 years ago

CT : BUGFIX042 : Correction of the problem when using no-leap years option

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1MODULE daymod
2   !!======================================================================
3   !!                       ***  MODULE  daymod  ***
4   !! Ocean        :  calendar
5   !!=====================================================================
6
7   !!----------------------------------------------------------------------
8   !!   day        : calendar
9   !!----------------------------------------------------------------------
10   !! * Modules used
11   USE dom_oce         ! ocean space and time domain
12   USE phycst          ! physical constants
13   USE in_out_manager  ! I/O manager
14
15   IMPLICIT NONE
16   PRIVATE
17
18   !! * Routine accessibility
19   PUBLIC day        ! called by step.F90
20
21   !! * Shared module variables
22   INTEGER , PUBLIC ::   &  !:
23      nyear     ,   &  !: current year
24      nmonth    ,   &  !: current month
25      nday      ,   &  !: current day of the month
26      nday_year ,   &  !: curent day counted from jan 1st of the current year
27      ndastp           !: time step date in year/month/day aammjj
28   REAL(wp), PUBLIC ::   &  !:
29       adatrj   ,   &  !: number of elapsed days since the begining of the run
30       adatrj0         !: value of adatrj at nit000-1 (before the present run).
31       !               !  it is the accumulated duration of previous runs
32       !               !  that may have been run with different time steps.
33   !!----------------------------------------------------------------------
34   !!  OPA 9, LODYC-IPSL (2004)
35   !!----------------------------------------------------------------------
36
37CONTAINS
38
39   SUBROUTINE day( kt )
40      !!----------------------------------------------------------------------
41      !!                      ***  ROUTINE day  ***
42      !!
43      !! ** Purpose :   Compute the date with a day iteration IF necessary.
44      !!
45      !! ** Method  : - ???
46      !!
47      !! ** Action  : - nyear     : current year
48      !!              - nmonth    : current month of the year nyear
49      !!              - nday      : current day of the month nmonth
50      !!              - nday_year : current day of the year nyear
51      !!              - ndastp    : =nyear*10000+nmonth*100+nday
52      !!              - adatrj    : date in days since the beginning of the run
53      !!
54      !! History :
55      !!        !  94-09  (M. Pontaud M. Imbard)  Original code
56      !!        !  97-03  (O. Marti)
57      !!        !  97-05  (G. Madec)
58      !!        !  97-08  (M. Imbard)
59      !!   9.0  !  03-09  (G. Madec)  F90 + nyear, nmonth, nday
60      !!        !  04-01  (A.M. Treguier) new calculation based on adatrj
61      !!----------------------------------------------------------------------     
62      !! * Arguments
63      INTEGER, INTENT( in ) ::   kt      ! ocean time-step indices
64
65      !! * Local declarations
66      INTEGER  ::   js                   ! dummy loop indice
67      INTEGER  ::   iend, iday0, iday1   ! temporary integers
68      REAL(wp) :: zadatrjn, zadatrjb     ! adatrj at timestep kt-1 and kt-2
69      !!----------------------------------------------------------------------
70
71      ! 0.  initialization of adatrj0 and nday, nmonth,nyear, nday_year.
72      !     ndastp has been initialized in domain.F90 or restart.F90
73      !-----------------------------------------------------------------
74
75      IF( kt == nit000 ) THEN
76
77         IF( .NOT.ln_rstart )   adatrj0 = 0.e0      ! adatrj0 initialized in rst_read when restart
78
79         adatrj  = adatrj0
80         nyear   =   ndastp / 10000
81         nmonth  = ( ndastp - (nyear * 10000) ) / 100
82         nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
83
84         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
85         nday_year =  nday
86         !                               ! accumulates days of previous months of this year
87         DO js = 1, nmonth-1
88            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
89               nday_year = nday_year + nbiss(js)
90            ELSE
91               nday_year = nday_year + nobis(js)
92            ENDIF
93         END DO
94
95      ENDIF
96
97      ! I.  calculates adatrj, zadatrjn, zadatrjb.
98      ! ------------------------------------------------------------------
99
100      adatrj    = adatrj0 + ( kt - nit000 + 1 ) * rdttra(1) / rday
101      zadatrjn  = adatrj0 + ( kt - nit000     ) * rdttra(1) / rday
102      zadatrjb  = adatrj0 + ( kt - nit000 - 1 ) * rdttra(1) / rday
103
104
105      ! II.  increment the date.  The date corresponds to 'now' variables (kt-1),
106      !      which is the time step of forcing fields.
107      !      Do not do this at nit000  unless nrstdt= 2
108      !      In that case ndastp (read in restart) was for step nit000-2
109      ! -------------------------------------------------------------------
110
111      iday0 = INT( zadatrjb )
112      iday1 = INT( zadatrjn )
113
114      IF( iday1 - iday0 >= 1 .AND. ( kt /= nit000 .OR. nrstdt == 2 ) ) THEN
115
116         ! increase calendar
117         nyear  =   ndastp / 10000
118         nmonth = ( ndastp - (nyear * 10000) ) / 100
119         nday   =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
120         nday = nday + 1
121         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
122            iend = nbiss(nmonth)
123         ELSEIF( nleapy > 1 ) THEN
124            iend = nleapy
125         ELSE
126            iend = nobis(nmonth)
127         ENDIF
128         IF( nday == iend + 1 ) THEN
129            nday  = 1
130            nmonth = nmonth + 1
131            IF( nmonth == 13 ) THEN
132               nmonth  = 1
133               nyear = nyear + 1
134            ENDIF
135         ENDIF
136         ndastp = nyear * 10000 + nmonth * 100 + nday
137
138         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
139         nday_year =  nday
140         !                                ! accumulates days of previous months of this year
141         DO js = 1, nmonth-1
142            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
143               nday_year = nday_year + nbiss(js)
144            ELSE
145               nday_year = nday_year + nobis(js)
146            ENDIF
147         END DO
148
149         IF(lwp) WRITE(numout,*)' ==============>> time-step =', kt, ' New day, DATE= ',   &
150            &                   nyear, '/', nmonth, '/', nday, 'nday_year:', nday_year
151      ENDIF
152
153      IF(l_ctl) WRITE(numout,*)' kt =', kt, 'd/m/y =', nday, nmonth, nyear
154
155   END SUBROUTINE day
156
157   !!======================================================================
158END MODULE daymod
Note: See TracBrowser for help on using the repository browser.