Subversion Repositories lagranto.wrf

Rev

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

Rev Author Line No. Line
2 michaesp 1
      program gettidiff
2
C     =================
3
 
4
      implicit none
5
 
11 michaesp 6
       integer  idate(5),irefdat(5)
7
       real      ihdiff
2 michaesp 8
 
9
      integer   iargc
10
      character*(80) arg
11 michaesp 11
      integer	nc1,nc2,flag1,flag2,n,i
12
 
13
 
14
        do i=1,5
15
             idate(i)=0
16
             irefdat(i) = 0
17
        enddo
2 michaesp 18
c     check for sufficient requested arguments
19
      if (iargc().ne.2) then
20
         print*,
21
     >  'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
22
         call exit(1)
23
      endif
24
 
25
c     read and transform input
26
      call getarg(1,arg)
27
      call lenchar(arg,nc1)
28
      call checkchar(arg,'_',flag1)
29
 
11 michaesp 30
 
31
c      print*,'arg: ', arg
32
c      print*,'nc1',nc1
33
c      print*,'flag1',flag1
34
 
2 michaesp 35
      if (flag1.eq.7) then
36
        read(arg(1:2),'(i2)',err=120)idate(1)
37
        read(arg(3:4),'(i2)',err=120)idate(2)
38
        read(arg(5:6),'(i2)',err=120)idate(3)
39
        read(arg(8:9),'(i2)',err=120)idate(4)
40
        if (nc1.eq.11) then
41
          read(arg(10:11),'(i2)',err=120)idate(5)
42
        else if (nc1.ne.9) then
43
          print*,
44
     >   'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
45
          call exit(1)
46
        endif
47
      else if (flag1.eq.9) then
48
        read(arg(1:4),'(i4)',err=120)idate(1)
11 michaesp 49
c        print*,'idate(1): ' ,idate(1)
50
 
2 michaesp 51
        read(arg(5:6),'(i2)',err=120)idate(2)
11 michaesp 52
c        print*,'idate(2): ' ,idate(2)
53
 
2 michaesp 54
        read(arg(7:8),'(i2)',err=120)idate(3)
11 michaesp 55
c        print*,'idate(3): ' ,idate(3)
56
 
2 michaesp 57
        read(arg(10:11),'(i2)',err=120)idate(4)
11 michaesp 58
c        print*,'idate(4): ' ,idate(4)
59
 
2 michaesp 60
        if (nc1.eq.13) then
61
          read(arg(12:13),'(i2)',err=120)idate(5)
62
        else if (nc1.ne.11) then
63
          print*,
64
     >   'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
65
          call exit(1)
66
        endif
67
      else
68
        print*,
69
     > 'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
70
        call exit(1)
71
      endif
72
 
73
      call getarg(2,arg)
74
      call lenchar(arg,nc2)
75
      call checkchar(arg,'_',flag2)
76
      if (flag1.ne.flag2) then
77
        print*,
78
     > 'error: both dates must be in same format (YY)YYMMDD_HH(MM)'
79
        call exit(1)
80
      endif
81
 
82
      if (flag2.eq.7) then
83
        read(arg(1:2),'(i2)',err=120)irefdat(1)
84
        read(arg(3:4),'(i2)',err=120)irefdat(2)
85
        read(arg(5:6),'(i2)',err=120)irefdat(3)
86
        read(arg(8:9),'(i2)',err=120)irefdat(4)
87
        if (nc2.eq.11) then
88
          read(arg(10:11),'(i2)',err=120)irefdat(5)
89
        else if (nc2.ne.9) then
90
          print*,
91
     >   'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
92
          call exit(1)
93
        endif
94
      else if (flag2.eq.9) then
95
        read(arg(1:4),'(i4)',err=120)irefdat(1)
11 michaesp 96
c        print*,'irefdat(1): ' ,irefdat(1)
97
 
2 michaesp 98
        read(arg(5:6),'(i2)',err=120)irefdat(2)
11 michaesp 99
c        print*,'irefdat(2): ' ,irefdat(2)
100
 
2 michaesp 101
        read(arg(7:8),'(i2)',err=120)irefdat(3)
11 michaesp 102
c        print*,'irefdat(3): ' ,irefdat(3)
103
 
2 michaesp 104
        read(arg(10:11),'(i2)',err=120)irefdat(4)
11 michaesp 105
c        print*,'irefdat(4): ' ,irefdat(4)
106
 
2 michaesp 107
        if (nc2.eq.13) then
108
          read(arg(12:13),'(i2)',err=120)irefdat(5)
109
        else if (nc2.ne.11) then
110
          print*,
111
     >   'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
112
          call exit(1)
113
        endif
114
      else
115
        print*,
116
     >   'USAGE: gettidiff date1 date2 (format (YY)YYMMDD_HH(MM))'
117
        call exit(1)
118
      endif
119
 
11 michaesp 120
 
121
c       do i=1,5
122
c         print*,'idate(',i,')',idate(i)
123
c        print*,'irefdat(',i,')',irefdat(i)
124
c       enddo
125
 
2 michaesp 126
      call timediff(idate,irefdat,ihdiff)
11 michaesp 127
c      print*, int(ihdiff)
2 michaesp 128
 
11 michaesp 129
c       print*,'ihdiff',ihdiff
130
 
2 michaesp 131
      if (int(100.*ihdiff).eq.100*int(ihdiff)) then
11 michaesp 132
           print*, ifix(ihdiff)
133
c         write(*,'(f7.2)')ihdiff
134
        else
135
            write(*,'(f7.2)')ihdiff
136
c         write(*,*)ihdiff
137
         endif
2 michaesp 138
 
139
      goto 200
140
 
141
 120  write(*,*)
142
     >"*** error: date must be in format (YY)YYMMDD_HH(MM) ***"
143
 
144
 200  continue
145
      end
146
 
147
      subroutine lenchar(string,lstr)
148
C     ===============================
149
 
150
      character*(*)     string
151
      integer   n,lstr
152
 
153
      do n=1,len(string)
154
        if (string(n:n).eq."") then
155
          lstr=n-1
156
          goto 100
157
        endif
158
      enddo
159
 100  continue
160
      end
161
 
162
      subroutine checkchar(string,char,flag)
163
C     ======================================
164
 
165
      character*(*)     string
166
      character*(1)     char
167
      integer   n,flag
168
 
169
      flag=0
170
      do n=1,len(string)
171
        if (string(n:n).eq.char) then
172
          flag=n
173
          return
174
        endif
175
      enddo
176
      end