1 |
C $Header: /u/u3/gcmpack/MITgcm/pkg/cal/cal_monthsforyear.F,v 1.1.20.2 2003/10/07 20:46:37 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CAL_OPTIONS.h" |
5 |
|
6 |
subroutine cal_MonthsForYear( |
7 |
I iyear, |
8 |
O firstmonth, |
9 |
O lastmonth, |
10 |
O nmonths, |
11 |
I mythid |
12 |
& ) |
13 |
|
14 |
c ================================================================== |
15 |
c SUBROUTINE cal_MonthsForYear |
16 |
c ================================================================== |
17 |
c |
18 |
c o Given the current year of integration this routine returns |
19 |
c the number of months affected by the integration as well as the |
20 |
c first month and the last month in the sequence of the total |
21 |
c number of months that are to be integrated. |
22 |
c |
23 |
c This routine also checks consistency of variables quite |
24 |
c extensively. |
25 |
c |
26 |
c started: Christian Eckert eckert@mit.edu 06-Apr-2000 |
27 |
c |
28 |
c changed: |
29 |
c |
30 |
c ================================================================== |
31 |
c SUBROUTINE cal_MonthsForYear |
32 |
c ================================================================== |
33 |
|
34 |
implicit none |
35 |
|
36 |
c == global variables == |
37 |
|
38 |
#include "cal.h" |
39 |
|
40 |
c == routine arguments == |
41 |
|
42 |
integer iyear |
43 |
integer firstmonth |
44 |
integer lastmonth |
45 |
integer nmonths |
46 |
integer mythid |
47 |
|
48 |
c == local variables == |
49 |
|
50 |
integer ierr |
51 |
integer numyears |
52 |
integer firstyear |
53 |
integer firstmon |
54 |
integer lastyear |
55 |
integer lastmon |
56 |
integer lastday |
57 |
integer lastsecs |
58 |
|
59 |
c == external == |
60 |
|
61 |
integer cal_IntYears |
62 |
external cal_IntYears |
63 |
|
64 |
c == end of interface == |
65 |
|
66 |
numyears = cal_IntYears( mythid ) |
67 |
|
68 |
firstyear = modelstartdate(1)/10000 |
69 |
firstmon = mod(modelstartdate(1)/100,100) |
70 |
lastyear = modelenddate(1)/10000 |
71 |
lastmon = mod(modelenddate(1)/100,100) |
72 |
lastday = mod(modelenddate(1),100) |
73 |
lastsecs = modelenddate(2)/10000*secondsperhour + |
74 |
& mod(modelenddate(2)/100,100)*secondsperminute + |
75 |
& mod(modelenddate(2),100) |
76 |
|
77 |
if ( numyears .eq. 1 ) then |
78 |
c-- Only one calendar year affected by the integration. |
79 |
if ( iyear .eq. 1 ) then |
80 |
if ( firstyear .eq. lastyear ) then |
81 |
if ( (lastday .eq. 1) .and. (lastsecs .eq. 0) ) then |
82 |
c-- Not really next month yet. |
83 |
lastmonth = lastmon - firstmon |
84 |
else |
85 |
c-- The most frequent case. |
86 |
lastmonth = lastmon - firstmon + 1 |
87 |
endif |
88 |
firstmonth = 1 |
89 |
else if ( firstyear+1 .eq. lastyear ) then |
90 |
c-- This is only the case if we end at midnight of 01-Jan |
91 |
c-- of the next year. |
92 |
if ( ( modelenddate(2) .eq. 0) .and. |
93 |
& ( mod(modelenddate(1),100) .eq. 1 ) .and. |
94 |
& mod(modelenddate(1)/100,100) .eq. 1 ) then |
95 |
firstmonth = 1 |
96 |
lastmonth = nmonthyear - firstmon + 1 |
97 |
else |
98 |
c-- Inconsistent modelenddate; check cal_IntYears. |
99 |
ierr = 2804 |
100 |
call cal_PrintError( ierr, mythid ) |
101 |
stop ' stopped in cal_MonthsForYear.' |
102 |
endif |
103 |
else |
104 |
c-- The specification of lastyear is wrong. |
105 |
ierr = 2803 |
106 |
call cal_PrintError( ierr, mythid ) |
107 |
stop ' stopped in cal_MonthsForYear.' |
108 |
endif |
109 |
else |
110 |
c-- The variables numyears and iyear are inconsistent; |
111 |
c-- ( iyear .gt. numyears ). |
112 |
ierr = 2802 |
113 |
call cal_PrintError( ierr, mythid ) |
114 |
stop ' stopped in cal_MonthsForYear.' |
115 |
endif |
116 |
|
117 |
else if ( numyears .gt. 1 ) then |
118 |
c-- More than one year of integration. |
119 |
if ( iyear .eq. 1 ) then |
120 |
firstmonth = 1 |
121 |
lastmonth = nmonthyear - firstmon + 1 |
122 |
else if ( ( iyear .gt. 1 ) .and. |
123 |
& ( iyear .lt. numyears ) ) then |
124 |
c-- Somewhere between first and last year. |
125 |
firstmonth = (nmonthyear - firstmon + 1) + |
126 |
& (iyear - 2)*nmonthyear + 1 |
127 |
lastmonth = (nmonthyear - firstmon + 1) + |
128 |
& (iyear - 2)*nmonthyear + nmonthyear |
129 |
else if ( iyear .eq. numyears ) then |
130 |
c-- The last year of the integration. |
131 |
if ( lastyear .eq. (firstyear + numyears - 1) ) then |
132 |
if ( (lastday .eq. 1) .and. (lastsecs .eq. 0) ) then |
133 |
c-- Not really next month yet. |
134 |
lastmonth = (nmonthyear - firstmon + 1) + |
135 |
& (numyears - 2)*nmonthyear + lastmon - 1 |
136 |
else |
137 |
c-- The most frequent case. |
138 |
lastmonth = (nmonthyear - firstmon + 1) + |
139 |
& (numyears - 2)*nmonthyear + lastmon |
140 |
endif |
141 |
firstmonth = (nmonthyear - firstmon + 1) + |
142 |
& (numyears - 2)*nmonthyear + 1 |
143 |
else if ( lastyear .eq. (firstyear + numyears) ) then |
144 |
c-- This is only the case if we end at midnight of 01-Jan. |
145 |
if ( ( modelenddate(2) .eq. 0) .and. |
146 |
& ( mod(modelenddate(1),100) .eq. 1 ) .and. |
147 |
& mod(modelenddate(1)/100,100) .eq. 1 ) then |
148 |
firstmonth = (nmonthyear - firstmon) + |
149 |
& (numyears - 2)*nmonthyear + 1 |
150 |
lastmonth = (nmonthyear - firstmon) + |
151 |
& (numyears - 2)*nmonthyear + nmonthyear |
152 |
else |
153 |
c-- Inconsistent modelenddate; check cal_IntYears. |
154 |
ierr = 2807 |
155 |
call cal_PrintError( ierr, mythid ) |
156 |
stop ' stopped in cal_MonthsForYear.' |
157 |
endif |
158 |
else |
159 |
c-- The variables lastyear and numyears are inconsistent. |
160 |
ierr = 2806 |
161 |
call cal_PrintError( ierr, mythid ) |
162 |
stop ' stopped in cal_MonthsForYear.' |
163 |
endif |
164 |
else |
165 |
c-- The variables iyear and numyears are inconsistent. |
166 |
ierr = 2805 |
167 |
call cal_PrintError( ierr, mythid ) |
168 |
stop ' stopped in cal_MonthsForYear.' |
169 |
endif |
170 |
|
171 |
else |
172 |
c-- The number of years to integrate is wrong; check cal_IntYears. |
173 |
ierr = 2801 |
174 |
call cal_PrintError( ierr, mythid ) |
175 |
stop ' stopped in cal_MonthsForYear.' |
176 |
endif |
177 |
|
178 |
c-- The number of months to integrate in the given year. |
179 |
nmonths = lastmonth - firstmonth + 1 |
180 |
|
181 |
return |
182 |
end |
183 |
|