Subversion Repositories lagranto.wrf

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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