/[MITgcm]/MITgcm/pkg/cal/cal_getmonthsrec.F
ViewVC logotype

Annotation of /MITgcm/pkg/cal/cal_getmonthsrec.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (hide annotations) (download)
Fri Apr 13 18:03:11 2012 UTC (12 years, 1 month ago) by jmc
Branch: MAIN
CVS Tags: checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint65o, checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, HEAD
Changes since 1.2: +26 -29 lines
- avoid calling a S/R with 2 time the same arg (FWD: unless both are only used
  as input; and for AD, unless both are not differentiable (e.g., k index))

1 jmc 1.3 C $Header: /u/gcmpack/MITgcm/pkg/cal/cal_getmonthsrec.F,v 1.2 2003/10/09 04:19:19 edhill Exp $
2 edhill 1.2 C $Name: $
3 heimbach 1.1
4 edhill 1.2 #include "CAL_OPTIONS.h"
5 heimbach 1.1
6     subroutine cal_GetMonthsRec(
7     O fac, first, changed,
8     O count0, count1,
9     I mytime, myiter, mythid
10     & )
11    
12     c ==================================================================
13     c SUBROUTINE cal_GetMonthsRec
14     c ==================================================================
15     c
16     c o Given the current model time or iteration number this routine
17     c returns the corrresponding months that will have to be used in
18     c order to interpolate monthly mean fields. The routine derives
19     c from *exf_GetMonthsRec* of the external forcing package.
20     c
21     c started: Christian Eckert eckert@mit.edu 21-Apr-2000
22     c - ported from the external forcing package and slightly
23     c modified (10 --> nmonthyear-2, 12 --> nmonthyear).
24     c
25     c changed: Patrick Heimbach heimbach@mit.edu 15-Jun-2000
26     c - fixed bug for count1 = nmonthyear
27     c
28     c ==================================================================
29     c SUBROUTINE cal_GetMonthsRec
30     c ==================================================================
31    
32     implicit none
33    
34     c == global variables ==
35    
36     #include "cal.h"
37    
38     c == routine arguments ==
39    
40     _RL fac
41     logical first
42     logical changed
43     integer count0
44     integer count1
45     _RL mytime
46     integer myiter
47     integer mythid
48    
49     c == local variables ==
50    
51     integer currentdate(4)
52     integer midtime(4)
53     integer middate(4)
54 jmc 1.3 integer tempDate(4)
55     integer middate0_1, middate0_2
56 heimbach 1.1 integer middate0(4)
57 jmc 1.3 integer middate1_1, middate1_2
58 heimbach 1.1 integer middate1(4)
59     integer prevdate(4)
60     integer shifttime(4)
61 jmc 1.3 integer startofmonth_1, startofmonth_2
62     integer endofmonth_1, endofmonth_2
63 heimbach 1.1 integer startofmonth(4)
64     integer endofmonth(4)
65     integer difftime(4)
66     integer present
67     integer previous
68     integer next
69     integer prevcount
70     integer modelsteptime(4)
71    
72     _RL currentsecs
73     _RL prevsecs
74     _RL midsecs_np
75     _RL diffsecs
76     _RL midsecs
77    
78     c == end of interface ==
79    
80     ce --> Include a check whether the right calendar is used.
81    
82     shifttime(1) = 1
83     shifttime(2) = 0
84     shifttime(3) = 0
85     shifttime(4) = -1
86    
87     call cal_TimeInterval( -modelstep, 'secs', modelsteptime,
88     & mythid )
89    
90     c Determine the current date and the current month.
91     call cal_GetDate( myiter, mytime, currentdate, mythid )
92    
93     present = mod(currentdate(1)/100,100)
94 jmc 1.3 startofmonth_1 = (currentdate(1)/100)*100 + 1
95     startofmonth_2 = 0
96     call cal_FullDate( startofmonth_1, startofmonth_2,
97     & startofmonth, mythid )
98    
99     endofmonth_1 = (currentdate(1)/100)*100 +
100 heimbach 1.1 & ndaymonth(present,currentdate(3))
101 jmc 1.3 endofmonth_2 = 235959
102     call cal_FullDate( endofmonth_1, endofmonth_2,
103 heimbach 1.1 & endofmonth, mythid )
104    
105     c Determine middle of current month.
106     currentsecs = float(
107     & (mod(currentdate(1),100)-1)*secondsperday +
108     & currentdate(2)/10000*secondsperhour +
109     & mod(currentdate(2)/100,100)*secondsperminute +
110     & mod(currentdate(2),100)
111     & )
112     midsecs = float(ndaymonth(present,currentdate(3))*
113     & secondsperday/2)
114    
115     call cal_TimeInterval( midsecs, 'secs', midtime, mythid )
116     call cal_AddTime( startofmonth, midtime, middate, mythid )
117     call cal_AddTime( currentdate, modelsteptime, prevdate, mythid )
118    
119     prevsecs = float(
120     & (mod(prevdate(1),100)-1)*secondsperday +
121     & prevdate(2)/10000*secondsperhour +
122     & mod(prevdate(2)/100,100)*secondsperminute +
123     & mod(prevdate(2),100)
124     & )
125    
126     c-- Set switches for reading new records.
127     first = ((mytime - modelstart) .lt. 0.5*modelstep)
128    
129     if ( first ) then
130     changed = .false.
131     endif
132    
133     if ( currentsecs .lt. midsecs ) then
134    
135     count0 = mod(present+nmonthyear-2,nmonthyear)+1
136     prevcount = count0
137    
138     shifttime(1) = -shifttime(1)
139     call cal_AddTime( startofmonth, shifttime, middate0, mythid )
140 jmc 1.3 middate0_1 = (middate0(1)/100)*100 + 1
141     middate0_2 = 0
142     call cal_FullDate( middate0_1, middate0_2, tempDate,
143 heimbach 1.1 & mythid )
144    
145 jmc 1.3 previous = mod(tempDate(1)/100,100)
146 heimbach 1.1
147 jmc 1.3 midsecs_np = float(ndaymonth(previous,tempDate(3))*
148 heimbach 1.1 & secondsperday/2)
149    
150     call cal_TimeInterval( midsecs_np, 'secs', midtime, mythid )
151 jmc 1.3 call cal_AddTime( tempDate, midtime, middate0, mythid )
152 heimbach 1.1
153     count1 = present
154    
155     middate1(1) = middate(1)
156     middate1(2) = middate(2)
157     middate1(3) = middate(3)
158     middate1(4) = middate(4)
159    
160     else
161    
162     count0 = present
163    
164     if ( prevsecs .lt. midsecs ) then
165     prevcount = mod(present+nmonthyear-2,nmonthyear)+1
166     else
167     prevcount = present
168     endif
169    
170     middate0(1) = middate(1)
171     middate0(2) = middate(2)
172     middate0(3) = middate(3)
173     middate0(4) = middate(4)
174    
175     count1 = mod(present+1,nmonthyear)
176     if ( count1 .EQ. 0 ) count1 = nmonthyear
177    
178     call cal_AddTime( endofmonth, shifttime, middate1, mythid )
179 jmc 1.3 middate1_1 = (middate1(1)/100)*100 + 1
180     middate1_2 = 0
181 heimbach 1.1
182 jmc 1.3 call cal_FullDate( middate1_1, middate1_2, tempDate,
183 heimbach 1.1 & mythid )
184 jmc 1.3 next = mod(tempDate(1)/100,100)
185     midsecs_np = float(ndaymonth(next,tempDate(3))*
186 heimbach 1.1 & secondsperday/2)
187     call cal_TimeInterval( midsecs_np, 'secs', midtime, mythid )
188 jmc 1.3 call cal_AddTime( tempDate, midtime, middate1, mythid )
189 heimbach 1.1
190     endif
191    
192     call cal_SubDates( middate1, middate0, difftime, mythid )
193     call cal_ToSeconds( difftime, diffsecs, mythid )
194    
195     c Set counters, switches, and the linear interpolation factor.
196     if ( (.not. first) .and. (prevcount .ne. count0) ) then
197     changed = .true.
198     else
199     changed = .false.
200     endif
201    
202     if ( currentsecs .lt. midsecs ) then
203     fac = (midsecs - currentsecs)/diffsecs
204     else
205     fac = (2.*midsecs + midsecs_np - currentsecs)/
206     & diffsecs
207     endif
208    
209     return
210     end
211    

  ViewVC Help
Powered by ViewVC 1.1.22