NCEPLIBS-w3emc  2.11.0
w3ymdh4.f
Go to the documentation of this file.
1 C> @file
2 C> @brief 4-byte date word unpacker and packer.
3 C> @author K. F. Brill @date 1998-07-29
4 
5 C> Obtains the components of the nmc date word (ncep y2k
6 C> compliant form), or given its components, forms an nmc type date
7 C> word. The packing is done using base 32.
8 C>
9 C> If the first byte of IDATE is less than 101, then the old
10 C> Office Note 84 packing is assumed. A four-digit year is
11 C> always returned. To pack the "old" way, pass in a 2-digit
12 C> year.
13 C>
14 C> This program will work for the years ranging from A.D. 101
15 C> through 79359.
16 C>
17 C> On unpacking, years less than or equal to 100 are returned
18 C> as follows:
19 C>
20 C> - 0-50 2000--2050
21 C> - 51-100 1951--2000
22 C>
23 C>
24 C> ### Program History Log:
25 C> Date | Programmer | Comment
26 C> -----|------------|--------
27 C> 1998-07-29 | K. F. Brill | Initial.
28 C> 1999-03-15 | Gilbert | Removed Call to W3FS11() and put its processing inline.
29 C> W3FS11 was deleted from the W3LIB.
30 C>
31 C> @param[inout] IDATE Left 4 bytes of integer 64 bit word, or can be
32 C> IDATE(4) or CHARACTER*4 IDATE.
33 C> @param[inout] IYEAR Year (4 digits or 2 digits for on84)
34 C> @param[inout] MONTH Month
35 C> @param[inout] IDAY Day
36 C> @param[inout] IHOUR Hour
37 C> @param[in] NN Code:
38 C> - .eq. 0 pack iyear, month, iday, ihour into idate
39 C> - .ne. 0 unpack idate into iyear, month, iday, ihour
40 C>
41 C> @author K. F. Brill @date 1998-07-29
42  SUBROUTINE w3ymdh4 (IDATE,IYEAR,MONTH,IDAY,IHOUR,NN)
43 C
44  CHARACTER IDATE(4)
45 C
46  IF (nn.NE.0) THEN
47 C
48  itemp = mova2i(idate(1))
49  IF ( itemp .lt. 101 ) THEN
50  iyear = mova2i(idate(1))
51  month = mova2i(idate(2))
52  iday = mova2i(idate(3))
53  ihour = mova2i(idate(4))
54  IF(iyear.LE.100) iyear=2050-mod(2050-iyear,100)
55  RETURN
56  END IF
57  itemp = itemp - 101
58  itemp = itemp * 256 + mova2i(idate(2))
59  itemp = itemp * 256 + mova2i(idate(3))
60  itemp = itemp * 256 + mova2i(idate(4))
61  ihour = mod( itemp, 32 )
62  itemp = itemp / 32
63  iday = mod( itemp, 32 )
64  itemp = itemp / 32
65  month = mod( itemp, 32 )
66  iyear = itemp / 32
67 C
68  ELSE
69 C
70  itemp = iyear
71  IF ( itemp .lt. 101 ) THEN
72  idate(1) = char(iyear)
73  idate(2) = char(month)
74  idate(3) = char(iday)
75  idate(4) = char(ihour)
76  RETURN
77  END IF
78  itemp = itemp * 32 + month
79  itemp = itemp * 32 + iday
80  itemp = itemp * 32 + ihour
81 C*
82  idate(4)=char(mod(itemp,256))
83  itemp = itemp / 256
84  idate(3)=char(mod(itemp,256))
85  itemp = itemp / 256
86  idate(2)=char(mod(itemp,256))
87  itemp = itemp / 256
88  itemp = itemp + 101
89  idate(1)=char(itemp)
90 C
91  ENDIF
92 C
93  RETURN
94  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 w3ymdh4(IDATE, IYEAR, MONTH, IDAY, IHOUR, NN)
Obtains the components of the nmc date word (ncep y2k compliant form), or given its components,...
Definition: w3ymdh4.f:43