NCEPLIBS-w3emc  2.11.0
w3fs15.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Updating office note 85 date/time word.
3 C> @author Ralph Jones @date 1987-02-09
4 
5 C> Updates or backdates a fullword date/time word (o.n. 84) by a specified
6 C> number of hours.
7 C>
8 C> ### Program History Log:
9 C> Date | Programmer | Comments
10 C> -----|------------|---------
11 C> Unknown | Robert Allard | Initial.
12 C> 1987-02-19 | Ralph Jones | Clean up code
13 C> 1987-02-19 | Ralph Jones | Change to microsoft fortran 4.10
14 C> 1989-05-12 | Ralph Jones | Correct order of bytes in date word for pc
15 C> 1989-08-04 | Ralph Jones | Clean up code, get rid of assign, correction for memory set to indefinite.
16 C> 1989-10-25 | Ralph Jones | Change to cray cft77 fortran
17 C> 1995-11-15 | Ralph Jones | Add save statement
18 C> 2002-10-15 | Boi Vuong | Replaced function ichar with mova2i
19 C>
20 C> @param[in] IDATE Packed binary date/time as follows:
21 C> Byte | Variable | Range
22 C> -----|----------|------
23 C> Byte 1 | is year of century | 00-99
24 C> Byte 2 | is month | 01-12
25 C> Byte 3 | is day of month | 01-31
26 C> Byte 4 | is hour | 00-23
27 C> Subroutine takes advantage of fortran address passing, IDATE and NDATE may
28 C> be a character*1 array of four, the left 32 bits of 64 bit integer word.
29 C> An office note 85 label can be stored in 4 integer words. If integer the
30 C> 2nd word is used. Output is stored in left 32 bits. for a office note 84
31 C> label the 7th word is in the 4th cray 64 bit integer, the left 32 bits.
32 C> @param[in] JTAU Number of hours to update (if positive) or backdate (if negative)
33 C> @param[out] NDATE New date/time word returned in the same format as 'IDATE'.
34 C> 'NDATE' and 'IDATE' may be the same variable.
35 C>
36 C> @note This routine is valid only for the 20th century.
37 C>
38 C> @note The format of the date/time word is the same as the seventh word of
39 C> the packed data field label (see o.n. 84) and the third word of a binary
40 C> data set label (see o.n. 85).
41 C>
42 C> Exit states: An error found by out of range tests on the given date/time
43 C> information will be indicated by returning a binary zero word in 'NDATE'.
44 C>
45 C> @author Ralph Jones @date 1987-02-09
46  SUBROUTINE w3fs15(IDATE,JTAU,NDATE)
47 C
48  INTEGER ITABYR(13)
49  INTEGER LPTB(13)
50  INTEGER NOLPTB(13)
51 C
52  CHARACTER*1 IDATE(4)
53  CHARACTER*1 NDATE(4)
54 C
55  SAVE
56 C
57  DATA lptb /0000,0744,1440,2184,2904,3648,4368,5112,
58  & 5856,6576,7320,8040,8784/
59  DATA nolptb/0000,0744,1416,2160,2880,3624,4344,5088,
60  & 5832,6552,7296,8016,8760/
61  DATA icenty/1900/
62 C
63 C ...WHERE ICENTY IS FOR THE 20TH CENTURY ASSUMED FOR THE GIVEN
64 C ... YEAR WITHIN THE CENTURY
65 C
66  iyr = mova2i(idate(1))
67  imonth = mova2i(idate(2))
68  iday = mova2i(idate(3))
69  ihour = mova2i(idate(4))
70 C
71  IF (iyr .GT. 99) GO TO 1600
72  IF (imonth .LE. 0) GO TO 1600
73  IF (imonth .GT. 12) GO TO 1600
74  IF (iday .LE. 0) GO TO 1600
75  IF (iday .GT. 31) GO TO 1600
76  IF (ihour .LT. 0) GO TO 1600
77  IF (ihour .GT. 24) GO TO 1600
78  IF (jtau .NE. 0) GO TO 100
79 C
80  ndate(1) = idate(1)
81  ndate(2) = idate(2)
82  ndate(3) = idate(3)
83  ndate(4) = idate(4)
84  RETURN
85 C
86  100 CONTINUE
87  jahr = iyr + icenty
88  kabul = 1
89  GO TO 900
90 C
91 C ...WHERE 900 IS SUBROUTINE TO INITIALIZE ITABYR
92 C ...AND RETURN THRU KABUL
93 C
94  200 CONTINUE
95  ihryr = ihour + 24 * (iday - 1) + itabyr(imonth)
96  ihryr2 = ihryr + jtau
97 C
98 C ...TO TEST FOR BACKDATED INTO PREVIOUS YEAR...
99 C
100  300 CONTINUE
101  IF (ihryr2 .LT. 0) GO TO 700
102 C
103  DO 400 m = 2,13
104  IF (ihryr2 .LT. itabyr(m)) GO TO 600
105  400 CONTINUE
106 C
107 C ...IF IT FALLS THRU LOOP TO HERE, IT IS INTO NEXT YEAR...
108 C
109  jahr = jahr + 1
110  ihryr2 = ihryr2 - itabyr(13)
111  kabul = 2
112  GO TO 900
113 C
114  600 CONTINUE
115  monat = m - 1
116  ihrmo = ihryr2 - itabyr(monat)
117  nodays = ihrmo / 24
118  itag = nodays + 1
119  iuhr = ihrmo - nodays * 24
120  GO TO 1500
121 C
122 C ...ALL FINISHED. RETURN TO CALLING PROGRAM.......................
123 C ...COMES TO 700 IF NEG TOTAL HRS. BACK UP INTO PREVIOUS YEAR
124 C
125  700 CONTINUE
126  jahr = jahr - 1
127  kabul = 3
128  GO TO 900
129 C
130 C ...WHICH IS CALL TO INITIALIZE ITABYR AND RETURN THRU KABUL
131 C
132  800 CONTINUE
133  ihryr2 = itabyr(13) + ihryr2
134  GO TO 300
135 C
136 C ...SUBROUTINE INITYR...
137 C ...CALLED BY GO TO 900 AFTER ASSIGNING RETURN NO. TO KABUL...
138 C ...ITABYR HAS MONTHLY ACCUMULATING TOTAL HRS REL TO BEGIN OF YR.
139 C ...DEPENDS ON WHETHER JAHR IS LEAP YEAR OR NOT.
140 C
141  900 CONTINUE
142  iquot = jahr / 4
143  irmndr = jahr - 4 * iquot
144  IF (irmndr .NE. 0) GO TO 1000
145 C
146 C ...WAS MODULO 4, SO MOST LIKELY A LEAP YEAR,
147 C
148  iquot = jahr / 100
149  irmndr = jahr - 100 * iquot
150  IF (irmndr .NE. 0) GO TO 1200
151 C
152 C ...COMES THIS WAY IF A CENTURY YEAR...
153 C
154  iquot = jahr / 400
155  irmndr = jahr - 400 * iquot
156  IF (irmndr .EQ. 0) GO TO 1200
157 C
158 C ...COMES TO 1000 IF NOT A LEAP YEAR...
159 C
160  1000 CONTINUE
161  DO 1100 i = 1,13
162  itabyr(i) = nolptb(i)
163  1100 CONTINUE
164  GO TO 1400
165 C
166 C ...COMES TO 1200 IF LEAP YEAR
167 C
168  1200 CONTINUE
169  DO 1300 i = 1,13
170  itabyr(i) = lptb(i)
171  1300 CONTINUE
172 C
173  1400 CONTINUE
174  GO TO (200,300,800) kabul
175 C
176  1500 CONTINUE
177  jahr = mod(jahr,100)
178  ndate(1) = char(jahr)
179  ndate(2) = char(monat)
180  ndate(3) = char(itag)
181  ndate(4) = char(iuhr)
182  RETURN
183 C
184  1600 CONTINUE
185  ndate(1) = char(0)
186  ndate(2) = char(0)
187  ndate(3) = char(0)
188  ndate(4) = char(0)
189 C
190 C ...WHICH FLAGS AN ERROR CONDITION ...
191 C
192  RETURN
193  END
integer function mova2i(a)
This Function copies a bit string from a Character*1 variable to an integer variable.
Definition: mova2i.f:25
subroutine w3fs15(IDATE, JTAU, NDATE)
Updates or backdates a fullword date/time word (o.n.
Definition: w3fs15.f:47