source: LMDZ6/trunk/libf/phylmd/cal_tools_m.f90 @ 5408

Last change on this file since 5408 was 5268, checked in by abarral, 8 weeks ago

.f90 <-> .F90 depending on cpp key use

File size: 3.3 KB
Line 
1MODULE cal_tools_m
2
3  USE ioipsl, ONLY: ioconf_calendar, ioget_mon_len, lock_calendar,             &
4                     ioget_calendar, ioget_year_len
5
6CONTAINS
7
8!-------------------------------------------------------------------------------
9!
10FUNCTION year_len(y,cal_in)
11!
12!-------------------------------------------------------------------------------
13  IMPLICIT NONE
14!-------------------------------------------------------------------------------
15! Arguments:
16  INTEGER                                :: year_len
17  INTEGER,                    INTENT(IN) :: y
18  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: cal_in
19!-------------------------------------------------------------------------------
20! Local variables:
21  CHARACTER(LEN=20) :: cal_lmdz
22!-------------------------------------------------------------------------------
23  !--- No specified calendar: we need lmdz days number for current year
24  IF(.NOT.PRESENT(cal_in)) THEN; year_len=ioget_year_len(y); RETURN; END IF
25
26  !--- Get the lmdz calendar to reset at the end of the function
27  CALL ioget_calendar(cal_lmdz)
28
29  !--- Unlock calendar and set it to wanted one
30  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
31
32  !--- Get the number of days in this year
33  year_len=ioget_year_len(y)
34
35  !--- Back to original calendar
36  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_lmdz))
37
38END FUNCTION year_len
39!
40!-------------------------------------------------------------------------------
41
42
43!-------------------------------------------------------------------------------
44!
45FUNCTION mid_month(y,cal_in)
46!
47!-------------------------------------------------------------------------------
48  IMPLICIT NONE
49!-------------------------------------------------------------------------------
50! Arguments:
51  INTEGER,                    INTENT(IN) :: y           ! year
52  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: cal_in      ! calendar
53  REAL,                    DIMENSION(14) :: mid_month   ! mid-bins times
54!-------------------------------------------------------------------------------
55! Local variables:
56  CHARACTER(LEN=20)      :: cal_lmdz          ! lmdz current calendar
57  INTEGER, DIMENSION(14) :: tlen              ! months lengths (days)
58  INTEGER                :: m                 ! months counter
59  INTEGER                :: nd                ! number of days
60!-------------------------------------------------------------------------------
61  IF(PRESENT(cal_in)) THEN
62    CALL ioget_calendar(cal_lmdz)             !--- Keep track of lmdz calendar
63    CALL lock_calendar(.FALSE.)               !--- Unlock calendar
64    CALL ioconf_calendar(TRIM(cal_in))        !--- Change calendar to "cal_in"
65  END IF
66
67  !--- Get the length of each month
68  tlen(1 )=ioget_mon_len(y-1,12)
69  DO m=1,12; tlen(m+1)=ioget_mon_len(y,m); END DO
70  tlen(14)=ioget_mon_len(y+1, 1)
71
72  !--- Mid-bins times
73  mid_month(1)=-0.5*REAL(tlen(1))
74  DO m=2,14; mid_month(m)=mid_month(m-1)+0.5*REAL(tlen(m-1)+tlen(m)); END DO
75
76  IF(PRESENT(cal_in)) THEN
77    CALL lock_calendar(.FALSE.)               !--- Unlock calendar
78    CALL ioconf_calendar(TRIM(cal_lmdz))      !--- Restore original calendar
79  END IF
80
81END FUNCTION mid_month
82!
83!-------------------------------------------------------------------------------
84
85
86END MODULE cal_tools_m
87!
88!*******************************************************************************
89
Note: See TracBrowser for help on using the repository browser.