Subversion Repositories lagranto.icon

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 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
      integer                   interval
20
 
21
c     Date list
22
      integer                   ndates
23
      integer,allocatable,dimension(:)    :: year,month,day,hour
24
 
25
c     Auxiliary variables
26
      integer                     i
27
      integer                     year1,month1,day1,hour1,min1
28
      integer                     year2,month2,day2,hour2,min2
29
      character                   direction
30
      integer                     date1(5),date2(5)
31
      character*11                datestr
32
      character                   ch
33
      real                        diff
34
 
35
c     ---------------------------------------------------------------------
36
c     Preparations
37
c     ---------------------------------------------------------------------
38
 
39
c     Read parameter file
40
      open(10,file='datelist.param')
41
 
42
       read(10,*) datefile                           ! General parameters
43
       read(10,*) mode
44
 
45
       if ( mode.eq.'-create' ) then                 ! Create date list
46
          read(10,*) startdate
47
          read(10,*) finaldate
48
          read(10,*) interval
49
 
50
       else                                          ! Invalid mode
51
          print*,' ERROR: invalid mode for datelist'
52
          stop
53
       endif
54
 
55
      close(10)
56
 
57
c     ---------------------------------------------------------------------
58
c     Create a date list (-create)
59
c     ---------------------------------------------------------------------
60
 
61
      if ( mode.ne.'-create' ) goto 100
62
 
63
c     Check whether interval is ok
64
      if ( ( interval.le.0 ).or.(interval.gt.24) ) then
65
         print*,'Interval must be between 1 h and 24 h... Stop'
66
         stop
67
      endif
68
 
69
c     Extract dates and times
70
      read(startdate( 1: 4),*) year1
71
      read(startdate( 5: 6),*) month1
72
      read(startdate( 7: 8),*) day1
73
      read(startdate(10:11),*) hour1
74
      read(startdate(12:13),*) min1
75
 
76
      read(finaldate( 1: 4),*) year2
77
      read(finaldate( 5: 6),*) month2
78
      read(finaldate( 7: 8),*) day2
79
      read(finaldate(10:11),*) hour2
80
      read(finaldate(12:13),*) min2
81
 
82
c     Get direction of the date file
83
      if (year2.gt.year1) then
84
         direction = 'f'
85
         goto 101
86
      elseif (year2.lt.year1) then
87
         direction = 'b'
88
         goto 101
89
      endif
90
 
91
      if (month2.gt.month1) then
92
         direction = 'f'
93
         goto 101
94
      elseif (month2.lt.month1) then
95
         direction = 'b'
96
         goto 101
97
      endif
98
 
99
      if (day2.gt.day1) then
100
         direction = 'f'
101
         goto 101
102
      elseif (day2.lt.day1) then
103
         direction = 'b'
104
         goto 101
105
      endif
106
 
107
      if (hour2.gt.hour1) then
108
         direction = 'f'
109
         goto 101
110
      elseif (hour2.lt.hour1) then
111
         direction = 'b'
112
         goto 101
113
      endif
114
 
115
      if (min2.gt.min1) then
116
         direction = 'f'
117
         goto 101
118
      elseif (min2.lt.min1) then
119
         direction = 'b'
120
         goto 101
121
      endif
122
 
123
      direction = 'f'
124
 
125
 101  continue
126
 
127
c     Set the interval step depending on the direction
128
      if ( direction.eq.'b' ) then
129
         interval = -interval
130
      endif
131
 
132
c     Save the dates in arrays
133
      date1(1) = year1
134
      date1(2) = month1
135
      date1(3) = day1
136
      date1(4) = hour1 
137
      date1(5) = 0
138
 
139
      date2(1) = year2
140
      date2(2) = month2
141
      date2(3) = day2
142
      date2(4) = hour2 
143
      date2(5) = 0
144
 
145
 
146
c     Get starting and ending date for the date list
147
      if ( direction.eq.'f' ) then
148
 
149
         do while ( mod(date1(4),interval) .ne. 0 )
150
            date1(4) = date1(4) - 1
151
         enddo
152
 
153
         if (min2.ne.0) call newdate(date2,1.,date2)
154
 
155
         do while ( mod(date2(4),interval) .ne. 0 )
156
            date2(4) = date2(4) + 1
157
         enddo
158
 
159
      else
160
 
161
         if (min1.ne.0) call newdate(date1,1.,date1)
162
 
163
         do while ( mod(date1(4),interval) .ne. 0 )
164
            date1(4) = date1(4) + 1
165
         enddo
166
 
167
         do while ( mod(date2(4),interval) .ne. 0 )
168
            date2(4) = date2(4) - 1
169
         enddo
170
 
171
      endif
172
 
173
c     Create and write the datefile
174
      if ( datefile.ne.'/dev/stdout') then
175
         open(10,file=datefile)
176
      endif
177
 
178
 102  continue
179
 
180
       call datestring(datestr,date1(1),date1(2),date1(3),date1(4) )
181
 
182
       if ( datefile.ne.'/dev/stdout') then
183
          write(10,*) datestr
184
       else
185
          write(*,*) datestr
186
       endif
187
 
188
       if ( ( date1(1).ne.date2(1) ).or.
189
     >      ( date1(2).ne.date2(2) ).or.
190
     >      ( date1(3).ne.date2(3) ).or.
191
     >      ( date1(4).ne.date2(4) ) ) 
192
     > then
193
          diff = real(interval)
194
          call newdate(date1,diff,date1)
195
          goto 102
196
       endif
197
 
198
      if ( datefile.ne.'/dev/stdout') then
199
         close(10)
200
      endif
201
 
202
 100  continue
203
 
204
 
205
c     ---------------------------------------------------------------------
206
c     End
207
c     ---------------------------------------------------------------------
208
 
209
      end
210