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