Subversion Repositories lagranto.wrf

Rev

Rev 11 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 michaesp 1
      PROGRAM datelist
2
 
3
c     **********************************************************************
4
c     * Handling of date lists                                             *
5
c     * Michael Sprenger                                                   *
6
c     **********************************************************************
7
 
8
      implicit none
9
 
10
c     ---------------------------------------------------------------------
11
c     Declaration of variables
12
c     ---------------------------------------------------------------------
13
 
14
c     Parameters
15
      character*80              datefile
16
      character*80              mode 
17
      character*80              startdate
18
      character*80              finaldate
19
      character*80              refdate
20
      integer                   interval
21
 
22
c     Date list
23
      integer                   ndates
24
      integer,allocatable,dimension(:)    :: year,month,day,hour
25
 
26
c     Auxiliary variables
27
      integer                     i
28
      integer                     year1,month1,day1,hour1,min1
29
      integer                     year2,month2,day2,hour2,min2
30
      character                   direction
31
      integer                     date1(5),date2(5)
32
      character*11                datestr
33
      character                   ch
34
      real                        diff
35
      real                        time
36
 
37
c     ---------------------------------------------------------------------
38
c     Preparations
39
c     ---------------------------------------------------------------------
40
 
41
c     Read parameter file
42
      open(10,file='datelist.param')
43
 
44
       read(10,*) datefile                           ! General parameters
45
       read(10,*) mode
46
 
47
       if ( mode.eq.'-create' ) then                 ! Create date list
48
          read(10,*) startdate
49
          read(10,*) finaldate
50
          read(10,*) interval
51
 
52
       elseif ( mode.eq.'-totime' ) then             ! Convert to time list
53
          read(10,*) refdate
54
 
55
       elseif ( mode.eq.'-todate' ) then             ! Convert to date list
56
          read(10,*) refdate
57
 
58
       else                                          ! Invalid mode
59
          print*,' ERROR: invalid mode for datelist'
60
          stop
61
       endif
62
 
63
      close(10)
64
 
65
c     ---------------------------------------------------------------------
66
c     Create a date list (-create)
67
c     ---------------------------------------------------------------------
68
 
69
      if ( mode.ne.'-create' ) goto 100
70
 
71
c     Check whether interval is ok
72
      if ( ( interval.le.0 ).or.(interval.gt.24) ) then
73
         print*,'Interval must be between 1 h and 24 h... Stop'
74
         stop
75
      endif
76
 
77
c     Extract dates and times
78
      read(startdate( 1: 4),*) year1
79
      read(startdate( 5: 6),*) month1
80
      read(startdate( 7: 8),*) day1
81
      read(startdate(10:11),*) hour1
82
      read(startdate(12:13),*) min1
83
 
84
      read(finaldate( 1: 4),*) year2
85
      read(finaldate( 5: 6),*) month2
86
      read(finaldate( 7: 8),*) day2
87
      read(finaldate(10:11),*) hour2
11 michaesp 88
      read(finaldate(12:13),*) min2
2 michaesp 89
 
90
c     Get direction of the date file
91
      if (year2.gt.year1) then
92
         direction = 'f'
93
         goto 101
94
      elseif (year2.lt.year1) then
95
         direction = 'b'
96
         goto 101
97
      endif
98
 
99
      if (month2.gt.month1) then
100
         direction = 'f'
101
         goto 101
102
      elseif (month2.lt.month1) then
103
         direction = 'b'
104
         goto 101
105
      endif
106
 
107
      if (day2.gt.day1) then
108
         direction = 'f'
109
         goto 101
110
      elseif (day2.lt.day1) then
111
         direction = 'b'
112
         goto 101
113
      endif
114
 
115
      if (hour2.gt.hour1) then
116
         direction = 'f'
117
         goto 101
118
      elseif (hour2.lt.hour1) then
119
         direction = 'b'
120
         goto 101
121
      endif
122
 
123
      if (min2.gt.min1) then
124
         direction = 'f'
125
         goto 101
126
      elseif (min2.lt.min1) then
127
         direction = 'b'
128
         goto 101
129
      endif
130
 
131
      direction = 'f'
132
 
133
 101  continue
134
 
135
c     Set the interval step depending on the direction
136
      if ( direction.eq.'b' ) then
137
         interval = -interval
138
      endif
139
 
140
c     Save the dates in arrays
141
      date1(1) = year1
142
      date1(2) = month1
143
      date1(3) = day1
144
      date1(4) = hour1 
145
      date1(5) = 0
146
 
147
      date2(1) = year2
148
      date2(2) = month2
149
      date2(3) = day2
150
      date2(4) = hour2 
151
      date2(5) = 0
152
 
153
 
154
c     Get starting and ending date for the date list
155
      if ( direction.eq.'f' ) then
156
 
157
         do while ( mod(date1(4),interval) .ne. 0 )
158
            date1(4) = date1(4) - 1
159
         enddo
160
 
161
         if (min2.ne.0) call newdate(date2,1.,date2)
162
 
163
         do while ( mod(date2(4),interval) .ne. 0 )
164
            date2(4) = date2(4) + 1
165
         enddo
166
 
167
      else
168
 
169
         if (min1.ne.0) call newdate(date1,1.,date1)
170
 
171
         do while ( mod(date1(4),interval) .ne. 0 )
172
            date1(4) = date1(4) + 1
173
         enddo
174
 
175
         do while ( mod(date2(4),interval) .ne. 0 )
176
            date2(4) = date2(4) - 1
177
         enddo
178
 
179
      endif
180
 
181
c     Create and write the datefile
182
      if ( datefile.ne.'/dev/stdout') then
183
         open(10,file=datefile)
184
      endif
185
 
186
 102  continue
187
 
188
       call datestring(datestr,date1(1),date1(2),date1(3),date1(4) )
189
 
190
       if ( datefile.ne.'/dev/stdout') then
191
          write(10,*) datestr
192
       else
193
          write(*,*) datestr
194
       endif
195
 
196
       if ( ( date1(1).ne.date2(1) ).or.
197
     >      ( date1(2).ne.date2(2) ).or.
198
     >      ( date1(3).ne.date2(3) ).or.
199
     >      ( date1(4).ne.date2(4) ) ) 
200
     > then
201
          diff = real(interval)
202
          call newdate(date1,diff,date1)
203
          goto 102
204
       endif
205
 
206
      if ( datefile.ne.'/dev/stdout') then
207
         close(10)
208
      endif
209
 
210
 100  continue
211
 
212
c     ---------------------------------------------------------------------
213
c     Convert dates to a list of times
214
c     ---------------------------------------------------------------------
215
 
216
      if ( mode.ne.'-totime' ) goto 110
217
 
218
c     Extract reference date
219
      read(refdate( 1: 4),*) year1
220
      read(refdate( 5: 6),*) month1
221
      read(refdate( 7: 8),*) day1
222
      read(refdate(10:11),*) hour1
223
      read(refdate(12:13),*) min1
224
 
225
c     Loop through the date file
226
      open(10,file=datefile)
227
 
228
 111  read(10,*,end=110) datestr
229
 
230
c     Extract date
231
      read(datestr( 1: 4),*) year2
232
      read(datestr( 5: 6),*) month2
233
      read(datestr( 7: 8),*) day2
234
      read(datestr(10:11),*) hour2
235
      min1 = 0
236
 
237
c     Get the time difference
238
      date1(1) = year1
239
      date1(2) = month1
240
      date1(3) = day1
241
      date1(4) = hour1 
242
      date1(5) = 0
243
 
244
      date2(1) = year2
245
      date2(2) = month2
246
      date2(3) = day2
247
      date2(4) = hour2 
248
      date2(5) = 0
249
 
250
      call timediff(date2,date1,diff)
251
 
252
 
253
c     Write it to screen
15 michaesp 254
      write(*,'(i6)') nint(diff)
2 michaesp 255
 
256
      goto 111
257
 
258
 110  continue
259
 
260
c     Close datefile
261
      close(10)
262
 
263
c     ---------------------------------------------------------------------
264
c     Convert times to a list of dates 
265
c     ---------------------------------------------------------------------
266
 
267
      if ( mode.ne.'-todate' ) goto 120
268
 
269
c     Extract reference date
270
      read(refdate( 1: 4),*) year1
271
      read(refdate( 5: 6),*) month1
272
      read(refdate( 7: 8),*) day1
273
      read(refdate(10:11),*) hour1
274
      read(refdate(12:13),*) min1
275
 
276
c     Loop through the date file
277
      open(10,file=datefile)
278
 
279
 121  read(10,*,end=120) time
280
 
281
c     Calculate the new date
282
      date1(1) = year1
283
      date1(2) = month1
284
      date1(3) = day1
285
      date1(4) = hour1 
286
      date1(5) = 0
287
      call newdate(date1,time,date2)
288
      call datestring(datestr,date2(1),date2(2),date2(3),date2(4) )
289
 
290
c     Write it to screen
15 michaesp 291
      write(*,'(a11)') trim(datestr)
2 michaesp 292
 
293
      goto 121
294
 
295
 120  continue
296
 
297
c     Close datefile
298
      close(10)
299
 
300
c     ---------------------------------------------------------------------
301
c     End
302
c     ---------------------------------------------------------------------
303
 
304
      end
305