1 |
C $Header: /u/u3/gcmpack/MITgcm/pkg/cal/cal_checkdate.F,v 1.3.2.2 2003/10/07 20:46:37 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CAL_OPTIONS.h" |
5 |
|
6 |
subroutine cal_CheckDate( |
7 |
I date, |
8 |
O valid, |
9 |
O calerr, |
10 |
I mythid |
11 |
& ) |
12 |
|
13 |
c ================================================================== |
14 |
c SUBROUTINE cal_CheckDate |
15 |
c ================================================================== |
16 |
c |
17 |
c o Check whether the array date conforms with the required format. |
18 |
c |
19 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
20 |
c |
21 |
c changed: Christian Eckert eckert@mit.edu 29-Dec-1999 |
22 |
c |
23 |
c - restructured the original version in order to have a |
24 |
c better interface to the MITgcmUV. |
25 |
c |
26 |
c Christian Eckert eckert@mit.edu 03-Feb-2000 |
27 |
c |
28 |
c - Introduced new routine and function names, cal_<NAME>, |
29 |
c for verion 0.1.3. |
30 |
c |
31 |
c 21-Sep-2003: fixed check_sign logic to work with |
32 |
c negative intervals (menemenlis@jpl.nasa.gov) |
33 |
c |
34 |
c ================================================================== |
35 |
c SUBROUTINE cal_CheckDate |
36 |
c ================================================================== |
37 |
|
38 |
implicit none |
39 |
|
40 |
c == global variables == |
41 |
|
42 |
#include "cal.h" |
43 |
|
44 |
c == routine arguments == |
45 |
|
46 |
integer date(4) |
47 |
logical valid |
48 |
integer calerr |
49 |
integer mythid |
50 |
|
51 |
c == local variables == |
52 |
|
53 |
integer yy,mm,dd |
54 |
integer nsecs |
55 |
integer lp,wd |
56 |
integer hhmmss |
57 |
integer yymmdd |
58 |
integer fac |
59 |
_RL check_sign |
60 |
|
61 |
c == end of interface == |
62 |
|
63 |
valid = .true. |
64 |
hhmmss = 0 |
65 |
calerr = 0 |
66 |
fac = 1 |
67 |
|
68 |
check_sign = 1 |
69 |
if ( ( (date(1).lt.0) .and. date(2).gt.0 ) .or. |
70 |
& ( (date(1).gt.0) .and. date(2).lt.0 ) ) |
71 |
& check_sign = -1 |
72 |
|
73 |
if (date(4) .le. 0) then |
74 |
if (date(4) .ne. -1) then |
75 |
calerr = 1801 |
76 |
else |
77 |
if (date(3) .ne. 0) then |
78 |
calerr = 1802 |
79 |
else |
80 |
if (check_sign .lt. 0) then |
81 |
calerr = 1803 |
82 |
else |
83 |
call cal_ConvDate(date,yy,mm,dd,nsecs,lp,wd,mythid) |
84 |
if (nsecs .lt. 0) fac = -1 |
85 |
hhmmss = fac*nsecs/secondsperminute |
86 |
hhmmss = hhmmss/minutesperhour*10000 + |
87 |
& mod(hhmmss,minutesperhour)*100 + |
88 |
& mod(fac*nsecs,secondsperminute) |
89 |
hhmmss = fac*hhmmss |
90 |
if (date(2) .ne. hhmmss) then |
91 |
calerr = 1804 |
92 |
endif |
93 |
endif |
94 |
endif |
95 |
endif |
96 |
else |
97 |
if (date(4) .gt. 8) then |
98 |
calerr = 1805 |
99 |
else |
100 |
if ((date(3) .ne. 1) .and. |
101 |
& (date(3) .ne. 2)) then |
102 |
calerr = 1806 |
103 |
else |
104 |
if (check_sign .lt. 0) then |
105 |
calerr = 1803 |
106 |
else |
107 |
call cal_ConvDate( date,yy,mm,dd,nsecs,lp,wd,mythid ) |
108 |
if (date(1) .lt. refdate(1)) then |
109 |
calerr = 1807 |
110 |
else |
111 |
hhmmss = nsecs/secondsperminute |
112 |
hhmmss = hhmmss/minutesperhour*10000 + |
113 |
& mod(hhmmss,minutesperhour)*100 + |
114 |
& mod(nsecs,secondsperminute) |
115 |
endif |
116 |
if (date(2) .ne. hhmmss) then |
117 |
calerr = 1804 |
118 |
endif |
119 |
yymmdd = yy*10000 + mm*100 + dd |
120 |
if (date(1) .ne. yymmdd) then |
121 |
calerr = 1808 |
122 |
endif |
123 |
endif |
124 |
endif |
125 |
endif |
126 |
endif |
127 |
|
128 |
if (calerr .ne. 0) valid = .not. valid |
129 |
|
130 |
return |
131 |
end |
132 |
|