1 |
C $Header: /u/gcmpack/MITgcm/pkg/cal/cal_fulldate.F,v 1.4 2012/04/07 16:21:05 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CAL_OPTIONS.h" |
5 |
|
6 |
SUBROUTINE CAL_FULLDATE( |
7 |
I yymmdd, |
8 |
I hhmmss, |
9 |
O date, |
10 |
I myThid ) |
11 |
|
12 |
C ================================================================== |
13 |
C SUBROUTINE cal_FullDate |
14 |
C ================================================================== |
15 |
C |
16 |
C o Set a date array given the year, month, day, hour, minute, |
17 |
C and second. Check the input for errors. |
18 |
C |
19 |
C started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
20 |
C changed: Christian Eckert eckert@mit.edu 29-Dec-1999 |
21 |
C - restructured the original version in order to have a |
22 |
C better interface to the MITgcmUV. |
23 |
C Christian Eckert eckert@mit.edu 03-Feb-2000 |
24 |
C - Introduced new routine and function names, cal_<NAME>, |
25 |
C for verion 0.1.3. |
26 |
C |
27 |
C ================================================================== |
28 |
C SUBROUTINE cal_FullDate |
29 |
C ================================================================== |
30 |
|
31 |
IMPLICIT NONE |
32 |
|
33 |
C == global variables == |
34 |
#include "EEPARAMS.h" |
35 |
#include "cal.h" |
36 |
|
37 |
C == routine arguments == |
38 |
C myThid - thread number for this instance of the routine. |
39 |
INTEGER yymmdd |
40 |
INTEGER hhmmss |
41 |
INTEGER date(4) |
42 |
INTEGER myThid |
43 |
|
44 |
C == functions == |
45 |
INTEGER cal_IsLeap |
46 |
EXTERNAL cal_IsLeap |
47 |
|
48 |
C == local variables == |
49 |
INTEGER theyear |
50 |
INTEGER numberOfDays(4) |
51 |
INTEGER calerr |
52 |
LOGICAL valid |
53 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
54 |
C == end of interface == |
55 |
|
56 |
date(1) = yymmdd |
57 |
date(2) = hhmmss |
58 |
date(3) = 1 |
59 |
date(4) = 1 |
60 |
|
61 |
IF ( cal_setStatus .LT. 1 ) THEN |
62 |
WRITE( msgBuf,'(A,2(A,I9))') 'CAL_FULLDATE: ', |
63 |
& 'yymmdd=',yymmdd,' , hhmmss=',hhmmss |
64 |
CALL PRINT_ERROR( msgBuf, myThid ) |
65 |
WRITE( msgBuf,'(2A,I2,A)') 'CAL_FULLDATE: ', |
66 |
& 'called too early (cal_setStatus=',cal_setStatus,' )' |
67 |
CALL PRINT_ERROR( msgBuf, myThid ) |
68 |
STOP 'ABNORMAL END: S/R CAL_FULLDATE' |
69 |
ENDIF |
70 |
|
71 |
C Check the input for obvious errors. |
72 |
CALL CAL_CHECKDATE( date, valid, calerr, myThid ) |
73 |
IF ( calerr.NE.0 ) THEN |
74 |
WRITE( msgBuf,'(A,2(A,I9))') 'CAL_FULLDATE: ', |
75 |
& 'yymmdd=',yymmdd,' , hhmmss=',hhmmss |
76 |
CALL PRINT_ERROR( msgBuf, myThid ) |
77 |
CALL CAL_PRINTERROR( calerr, myThid ) |
78 |
ENDIF |
79 |
|
80 |
IF (valid) THEN |
81 |
C Determine whether we are in a leap year or not. |
82 |
theyear = yymmdd/10000 |
83 |
date(3) = cal_IsLeap( theyear, myThid ) |
84 |
|
85 |
C Determine the day of the week. |
86 |
CALL CAL_TIMEPASSED( refDate, date, numberOfDays, myThid ) |
87 |
IF ( numberOfDays(1).LT.0 ) THEN |
88 |
C- when numberOfDays < 0 , TIMEPASSED output is not very logical (print); |
89 |
C in addition, in this case, formula below is wrong (skipped). |
90 |
WRITE(errorMessageUnit,'(2A,4I9)') ' in CAL_FULLDATE: ', |
91 |
& 'refDate=', refDate(1), refDate(2), refDate(3), refDate(4) |
92 |
WRITE(errorMessageUnit,'(2A,4I9)') ' in CAL_FULLDATE: ', |
93 |
& ' date=', date(1), date(2), date(3), date(4) |
94 |
WRITE(errorMessageUnit,'(2A,4I9)') ' in CAL_FULLDATE: ', |
95 |
& 'numDays=', numberOfDays(1), numberOfDays(2), |
96 |
& numberOfDays(3), numberOfDays(4) |
97 |
ELSE |
98 |
date(4) = MOD(numberOfDays(1),7)+1 |
99 |
ENDIF |
100 |
ELSE |
101 |
WRITE( msgBuf,'(2A)') 'CAL_FULLDATE: ', |
102 |
& 'fatal error from cal_CheckDate' |
103 |
CALL PRINT_ERROR( msgBuf, myThid ) |
104 |
STOP 'ABNORMAL END: S/R CAL_FULLDATE' |
105 |
ENDIF |
106 |
|
107 |
RETURN |
108 |
END |