NCEPLIBS-bufr 11.7.1
iupbs01.f
Go to the documentation of this file.
1C> @file
2C> @brief Read a data value from Section 0 or Section 1 of a BUFR
3C> message.
4
5C> This function returns a specified value from within Section 0 or
6C> Section 1 of a BUFR message.
7C>
8C> <p>This function will work on any BUFR message encoded using BUFR
9C> edition 2, 3, or 4. It is similar to function iupvs01(), except
10C> that it operates on a BUFR message passed in via a memory array,
11C> whereas iupvs01() operates on the BUFR message that was read into
12C> internal arrays via the most recent call to any of the other
13C> [message-reading subroutines](@ref hierarchy) for a specified
14C> Fortran logical unit.
15C>
16C> @author J. Ator
17C> @date 2005-11-29
18C>
19C> @param[in] MBAY -- integer(*): BUFR message
20C> @param[in] S01MNEM -- character*(*): Value to be read from
21C> Section 0 or Section 1 of MBAY
22C> - 'LENM' = Length (in bytes) of BUFR message
23C> - 'LEN0' = Length (in bytes) of Section 0
24C> - 'LEN1' = Length (in bytes) of Section 1
25C> - 'BEN' = BUFR edition number
26C> - 'BMT' = BUFR master table
27C> - 'OGCE' = Originating center
28C> - 'GSES' = Originating subcenter
29C> - 'USN' = Update sequence number
30C> - 'ISC2' = Flag indicating absence/presence of
31C> (optional) Section 2 in BUFR message:
32C> - 0 = Section 2 absent
33C> - 1 = Section 2 present
34C> - 'MTYP' = Data category
35C> - 'MSBTI' = Data subcategory (international)
36C> - 'MSBT' = Data subcategory (local)
37C> - 'MTV' = Version number of master table
38C> - 'MTVL' = Version number of local tables
39C> - 'YCEN' = Year of century (1-100)
40C> - 'CENT' = Century (e.g., 20 for years 1901-2000,
41C> 21 for years 2001-2100)
42C> - 'YEAR' = Year (4-digit)
43C> - 'MNTH' = Month
44C> - 'DAYS' = Day
45C> - 'HOUR' = Hour
46C> - 'MINU' = Minute
47C> - 'SECO' = Second
48C> @returns iupbs01 -- integer: Value corresponding to S01MNEM
49C> - -1 = S01MNEM was invalid for the edition of BUFR
50C> message in MBAY, or some other error
51C> occurred
52C>
53C> @remarks
54C> - The start of the BUFR message (i.e. the string 'BUFR') must be
55C> aligned on the first 4 bytes of MBAY.
56C> - Values corresponding to S01MNEM = 'GSES' can only be read from
57C> BUFR messages encoded using BUFR edition 3 or 4.
58C> - Values corresponding to S01MNEM = 'YCEN' or 'CENT' can only be
59C> read from BUFR messages encoded using BUFR edition 2 or 3.
60C> - When reading from BUFR messages encoded using BUFR edition 2
61C> or 3, values corresponding to S01MNEM = 'YEAR' will be
62C> calculated internally using the values for 'YCEN' and 'CENT',
63C> or inferred using a windowing technique
64C> - Values corresponding to S01MNEM = 'SECO' or 'MSBTI' can only
65C> be read from BUFR messages encoded using BUFR edition 4.
66C>
67C> <b>Program history log:</b>
68C> | Date | Programmer | Comments |
69C> | -----|------------|----------|
70C> | 2005-11-29 | J. Ator | Original author |
71C> | 2006-04-14 | J. Ator | Added options for 'YCEN' and 'CENT'; restructured logic |
72C>
73 FUNCTION iupbs01(MBAY,S01MNEM)
74
75 dimension mbay(*)
76
77 character*(*) s01mnem
78
79 logical ok4cent
80
81C-----------------------------------------------------------------------
82C This statement function checks whether its input value contains
83C a valid century value.
84
85 ok4cent(ival) = ((ival.GE.19).AND.(ival.LE.21))
86C-----------------------------------------------------------------------
87
88C Call subroutine WRDLEN to initialize some important information
89C about the local machine, just in case subroutine OPENBF hasn't
90C been called yet.
91
92 CALL wrdlen
93
94C Handle some simple requests that do not depend on the BUFR
95C edition number.
96
97 IF(s01mnem.EQ.'LENM') THEN
98 iupbs01 = iupb(mbay,5,24)
99 RETURN
100 ENDIF
101
102 len0 = 8
103 IF(s01mnem.EQ.'LEN0') THEN
104 iupbs01 = len0
105 RETURN
106 ENDIF
107
108C Get the BUFR edition number.
109
110 iben = iupb(mbay,8,8)
111 IF(s01mnem.EQ.'BEN') THEN
112 iupbs01 = iben
113 RETURN
114 ENDIF
115
116C Use the BUFR edition number to handle any other requests.
117
118 CALL gets1loc(s01mnem,iben,isbyt,iwid,iret)
119 IF(iret.EQ.0) THEN
120 iupbs01 = iupb(mbay,len0+isbyt,iwid)
121 IF(s01mnem.EQ.'CENT') THEN
122
123C Test whether the returned value was a valid
124C century value.
125
126 IF(.NOT.ok4cent(iupbs01)) iupbs01 = -1
127 ENDIF
128 ELSE IF( (s01mnem.EQ.'YEAR') .AND. (iben.LT.4) ) THEN
129
130C Calculate the 4-digit year.
131
132 iyoc = iupb(mbay,21,8)
133 icen = iupb(mbay,26,8)
134
135C Does ICEN contain a valid century value?
136
137 IF(ok4cent(icen)) THEN
138
139C YES, so use it to calculate the 4-digit year. Note that,
140C by international convention, the year 2000 was the 100th
141C year of the 20th century, and the year 2001 was the 1st
142C year of the 21st century
143
144 iupbs01 = (icen-1)*100 + iyoc
145 ELSE
146
147C NO, so use a windowing technique to determine the
148C 4-digit year from the year of the century.
149
150 iupbs01 = i4dy(mod(iyoc,100)*1000000)/10**6
151 ENDIF
152 ELSE
153 iupbs01 = -1
154 ENDIF
155
156 RETURN
157 END
subroutine gets1loc(S1MNEM, IBEN, ISBYT, IWID, IRET)
THIS SUBROUTINE RETURNS THE LOCATION (I.E.
Definition: gets1loc.f:81
function i4dy(IDATE)
This function converts a date-time with a 2-digit year (YYMMDDHH) to a date-time with a 4-digit year ...
Definition: i4dy.f:32
function iupb(MBAY, NBYT, NBIT)
THIS FUNCTION UNPACKS AND RETURNS A BINARY INTEGER WORD CONTAINED WITHIN NBIT BITS OF A BUFR MESSAGE ...
Definition: iupb.f:37
function iupbs01(MBAY, S01MNEM)
This function returns a specified value from within Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:74
subroutine wrdlen
This subroutine figures out some important information about the local machine on which the BUFRLIB s...
Definition: wrdlen.F:36