Subversion Repositories lagranto.ecmwf

Rev

Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 9
Line 1... Line 1...
1
      PROGRAM datelist
1
date      PROGRAM datelist
2
 
2
 
3
c     **********************************************************************
3
c     **********************************************************************
4
c     * Handling of date lists                                             *
4
c     * Handling of date lists                                             *
5
c     * Michael Sprenger                                                   *
5
c     * Michael Sprenger                                                   *
6
c     **********************************************************************
6
c     **********************************************************************
Line 16... Line 16...
16
      character*80              mode 
16
      character*80              mode 
17
      character*80              startdate
17
      character*80              startdate
18
      character*80              finaldate
18
      character*80              finaldate
19
      character*80              refdate
19
      character*80              refdate
20
      integer                   interval
20
      integer                   interval
-
 
21
      real                      randpercent
21
 
22
 
22
c     Date list
23
c     Date list
23
      integer                   ndates
24
      integer                   ndates
24
      integer,allocatable,dimension(:)    :: year,month,day,hour
25
      integer,allocatable,dimension(:)    :: year,month,day,hour
25
 
26
 
Line 27... Line 28...
27
      integer                     i
28
      integer                     i
28
      integer                     year1,month1,day1,hour1,min1
29
      integer                     year1,month1,day1,hour1,min1
29
      integer                     year2,month2,day2,hour2,min2
30
      integer                     year2,month2,day2,hour2,min2
30
      character                   direction
31
      character                   direction
31
      integer                     date1(5),date2(5)
32
      integer                     date1(5),date2(5)
32
      character*11                datestr
33
      character*11                datestr,datestr1,datestr2
33
      character                   ch
34
      character                   ch
34
      real                        diff
35
      real                        diff
35
      real                        time
36
      real                        time
-
 
37
      character*80                datefile1,datefile2
-
 
38
      integer                     timestamp1,timestamp2
-
 
39
      integer                     oldstamp1 ,oldstamp2
-
 
40
      integer                     state
36
 
41
 
37
c     ---------------------------------------------------------------------
42
c     ---------------------------------------------------------------------
38
c     Preparations
43
c     Preparations
39
c     ---------------------------------------------------------------------
44
c     ---------------------------------------------------------------------
40
 
45
 
Line 52... Line 57...
52
       elseif ( mode.eq.'-totime' ) then             ! Convert to time list
57
       elseif ( mode.eq.'-totime' ) then             ! Convert to time list
53
          read(10,*) refdate
58
          read(10,*) refdate
54
 
59
 
55
       elseif ( mode.eq.'-todate' ) then             ! Convert to date list
60
       elseif ( mode.eq.'-todate' ) then             ! Convert to date list
56
          read(10,*) refdate
61
          read(10,*) refdate
-
 
62
       
-
 
63
       elseif ( mode.eq.'-onlyin1' ) then            ! Dates only in file 1
-
 
64
          read(10,*) datefile1
-
 
65
          read(10,*) datefile2
57
 
66
 
58
       else                                          ! Invalid mode
67
       else                                          ! Invalid mode
59
          print*,' ERROR: invalid mode for datelist'
68
          print*,' ERROR: invalid mode for datelist'
60
          stop
69
          stop
61
       endif
70
       endif
Line 83... Line 92...
83
      
92
      
84
      read(finaldate( 1: 4),*) year2
93
      read(finaldate( 1: 4),*) year2
85
      read(finaldate( 5: 6),*) month2
94
      read(finaldate( 5: 6),*) month2
86
      read(finaldate( 7: 8),*) day2
95
      read(finaldate( 7: 8),*) day2
87
      read(finaldate(10:11),*) hour2
96
      read(finaldate(10:11),*) hour2
88
      read(startdate(12:13),*) min2
97
      read(finaldate(12:13),*) min2
89
 
98
 
90
c     Get direction of the date file
99
c     Get direction of the date file
91
      if (year2.gt.year1) then
100
      if (year2.gt.year1) then
92
         direction = 'f'
101
         direction = 'f'
93
         goto 101
102
         goto 101
Line 211... Line 220...
211
 
220
 
212
c     ---------------------------------------------------------------------
221
c     ---------------------------------------------------------------------
213
c     Convert dates to a list of times
222
c     Convert dates to a list of times
214
c     ---------------------------------------------------------------------
223
c     ---------------------------------------------------------------------
215
 
224
 
216
      if ( mode.ne.'-totime' ) goto 110
225
      if ( mode.ne.'-totime' ) goto 112
217
 
226
 
218
c     Extract reference date
227
c     Extract reference date
219
      read(refdate( 1: 4),*) year1
228
      read(refdate( 1: 4),*) year1
220
      read(refdate( 5: 6),*) month1
229
      read(refdate( 5: 6),*) month1
221
      read(refdate( 7: 8),*) day1
230
      read(refdate( 7: 8),*) day1
Line 257... Line 266...
257
 
266
 
258
 110  continue
267
 110  continue
259
      
268
      
260
c     Close datefile
269
c     Close datefile
261
      close(10)
270
      close(10)
-
 
271
      
-
 
272
c     Exit point      
-
 
273
  112 continue
262
 
274
 
263
c     ---------------------------------------------------------------------
275
c     ---------------------------------------------------------------------
264
c     Convert times to a list of dates 
276
c     Convert times to a list of dates 
265
c     ---------------------------------------------------------------------
277
c     ---------------------------------------------------------------------
266
 
278
 
267
      if ( mode.ne.'-todate' ) goto 120
279
      if ( mode.ne.'-todate' ) goto 122
268
 
280
 
269
c     Extract reference date
281
c     Extract reference date
270
      read(refdate( 1: 4),*) year1
282
      read(refdate( 1: 4),*) year1
271
      read(refdate( 5: 6),*) month1
283
      read(refdate( 5: 6),*) month1
272
      read(refdate( 7: 8),*) day1
284
      read(refdate( 7: 8),*) day1
Line 294... Line 306...
294
 
306
 
295
 120  continue
307
 120  continue
296
      
308
      
297
c     Close datefile
309
c     Close datefile
298
      close(10)
310
      close(10)
-
 
311
      
-
 
312
c     Exit point      
-
 
313
 122  continue
-
 
314
   
-
 
315
c     ---------------------------------------------------------------------
-
 
316
c     Extract all dates which are only in one datefile 
-
 
317
c     ---------------------------------------------------------------------
-
 
318
 
-
 
319
      if ( mode.ne.'-onlyin1' ) goto 134
-
 
320
      
-
 
321
c     Set reference date   
-
 
322
      date1(1) = 1979
-
 
323
      date1(2) = 1
-
 
324
      date1(3) = 1
-
 
325
      date1(4) = 0
-
 
326
      date1(5) = 0
-
 
327
      
-
 
328
c     Open the output file
-
 
329
      if ( datefile.ne.'/dev/stdout') then
-
 
330
         open(30,file=datefile)
-
 
331
      endif
299
 
332
 
-
 
333
c     Loop through the input date files
-
 
334
      open(10,file=datefile1)
-
 
335
      open(20,file=datefile2)
-
 
336
    
-
 
337
c     Loop through both date files
-
 
338
      state     = 0
-
 
339
      oldstamp1 = 0
-
 
340
      oldstamp2 = 0
-
 
341
      
-
 
342
 131  if ( (state.eq.1).or.(state.eq.0) ) then 
-
 
343
         read(10,*,end=133) datestr1
-
 
344
      endif
-
 
345
      if ( (state.eq.2).or.(state.eq.0) ) then 
-
 
346
         read(20,*,end=130) datestr2
-
 
347
      endif
-
 
348
 
-
 
349
c     Get time stamp for both date strings
-
 
350
      if ( (state.eq.1).or.(state.eq.0) ) then 
-
 
351
         read(datestr1( 1: 4),*) year2
-
 
352
         read(datestr1( 5: 6),*) month2
-
 
353
         read(datestr1( 7: 8),*) day2
-
 
354
         read(datestr1(10:11),*) hour2
-
 
355
         date2(1) = year2
-
 
356
         date2(2) = month2
-
 
357
         date2(3) = day2
-
 
358
         date2(4) = hour2 
-
 
359
         date2(5) = 0
-
 
360
         call timediff(date2,date1,diff)
-
 
361
         timestamp1 =  nint( diff )
-
 
362
         if ( timestamp1.lt.oldstamp1 ) then
-
 
363
            print*,' ERROR: datelist must be ordered ',trim(datefile1)
-
 
364
            stop
-
 
365
         else
-
 
366
            oldstamp1 = timestamp1
-
 
367
         endif
-
 
368
      endif
-
 
369
      
-
 
370
      if ( (state.eq.1).or.(state.eq.0) ) then 
-
 
371
         read(datestr2( 1: 4),*) year2
-
 
372
         read(datestr2( 5: 6),*) month2
-
 
373
         read(datestr2( 7: 8),*) day2
-
 
374
         read(datestr2(10:11),*) hour2
-
 
375
         date2(1) = year2
-
 
376
         date2(2) = month2
-
 
377
         date2(3) = day2
-
 
378
         date2(4) = hour2 
-
 
379
         date2(5) = 0
-
 
380
         call timediff(date2,date1,diff)
-
 
381
         timestamp2 =  nint( diff )
-
 
382
         if ( timestamp2.lt.oldstamp2 ) then
-
 
383
            print*,' ERROR: datelist must be ordered ',trim(datefile2)
-
 
384
            stop
-
 
385
         else
-
 
386
            oldstamp2 = timestamp2
-
 
387
         endif
-
 
388
      endif
-
 
389
      
-
 
390
c     Write output and set new state
-
 
391
      if ( timestamp1.gt.timestamp2 ) then
-
 
392
        state = 2
-
 
393
c        print*,trim(datestr1)//'.'//trim(datestr2)//' >'
-
 
394
 
-
 
395
      else if ( timestamp1.lt.timestamp2 ) then
-
 
396
        state = 1
-
 
397
 
-
 
398
        if ( datefile.ne.'/dev/stdout') then
-
 
399
           write(30,*) datestr1
-
 
400
        else
-
 
401
           write(*,*) datestr1
-
 
402
        endif
-
 
403
 
-
 
404
c        print*,trim(datestr1)//'.'//trim(datestr2)//' -> out'
-
 
405
 
-
 
406
      else if (timestamp1.eq.timestamp2 ) then
-
 
407
        state = 0
-
 
408
c        print*,trim(datestr1)//'.'//trim(datestr2)//' ='
-
 
409
 
-
 
410
      endif
-
 
411
 
-
 
412
      goto 131
-
 
413
 
-
 
414
c     Exit point for parallel reading through files
-
 
415
 130  continue
-
 
416
 
-
 
417
c     Write remaining part of datefile 1
-
 
418
 132  continue
-
 
419
        read(10,*,end=133) datestr1
-
 
420
        if ( datefile.ne.'/dev/stdout') then
-
 
421
           write(30,*) datestr1
-
 
422
        else
-
 
423
           write(*,*) datestr1
-
 
424
        endif
-
 
425
      goto 132
-
 
426
 133  continue
-
 
427
      
-
 
428
c     Close datefile
-
 
429
      close(10)
-
 
430
      close(20)
-
 
431
      close(30)
-
 
432
      
-
 
433
c     Exit point      
-
 
434
 134  continue
-
 
435
 
300
c     ---------------------------------------------------------------------
436
c     ---------------------------------------------------------------------
301
c     End
437
c     End
302
c     ---------------------------------------------------------------------
438
c     ---------------------------------------------------------------------
303
 
439
 
304
      end
440
      end