NCEPLIBS-bufr  12.0.1
pkbs1.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Write a data value into Section 1 of a BUFR message.
3 C>
4 C> @authors J. Ator, D. Keyser @date 2005-11-29
5 
6 C> This subroutines writes a specified value into a specified location
7 C> within Section 1 of a BUFR message, overwriting the value previously
8 C> stored in that location.
9 C>
10 C> This subroutine will work on any BUFR message encoded using BUFR
11 C> edition 2, 3, or 4. It is similar to subroutine pkvs01(), except
12 C> that it operates on a BUFR message passed in via a memory array,
13 C> whereas pkvs01() operates on BUFR messages stored internally within
14 C> the software.
15 C>
16 C> @param[in] IVAL -- integer: Value to be stored
17 C> @param[in,out] MBAY -- integer(*): BUFR message
18 C> @param[in] S1MNEM -- character*(*): Location in Section 1 of
19 C> MBAY within which to store IVAL
20 C> - 'BMT' = BUFR master table
21 C> - 'OGCE' = Originating center
22 C> - 'GSES' = Originating subcenter
23 C> - 'USN' = Update sequence number
24 C> - 'MTYP' = Data category
25 C> - 'MSBTI' = Data subcategory (international)
26 C> - 'MSBT' = Data subcategory (local)
27 C> - 'MTV' = Version number of master table
28 C> - 'MTVL' = Version number of local tables
29 C> - 'YCEN' = Year of century (1-100)
30 C> - 'CENT' = Century (e.g., 20 for years 1901-2000,
31 C> 21 for years 2001-2100)
32 C> - 'YEAR' = Year (4-digit)
33 C> - 'MNTH' = Month
34 C> - 'DAYS' = Day
35 C> - 'HOUR' = Hour
36 C> - 'MINU' = Minute
37 C> - 'SECO' = Second
38 C>
39 C> @remarks
40 C> - The start of the BUFR message (i.e. the string 'BUFR') must be
41 C> aligned on the first 4 bytes of MBAY.
42 C> - Values corresponding to S1MNEM = 'GSES' can only be stored within
43 C> BUFR messages encoded using BUFR edition 3 or 4.
44 C> - Values corresponding to S1MNEM = 'YCEN' or 'CENT' can only be stored
45 C> within BUFR messages encoded using BUFR edition 2 or 3.
46 C> - Values corresponding to S1MNEM = 'YEAR', 'SECO' or 'MSBTI' can only
47 C> be stored within BUFR messages encoded using BUFR edition 4.
48 C>
49 C> @authors J. Ator, D. Keyser @date 2005-11-29
50  RECURSIVE SUBROUTINE pkbs1(IVAL,MBAY,S1MNEM)
51 
52  USE modv_im8b
53 
54  dimension mbay(*)
55 
56  CHARACTER*(*) s1mnem
57 
58  CHARACTER*128 bort_str
59 
60 C-----------------------------------------------------------------------
61 C-----------------------------------------------------------------------
62 
63 C Check for I8 integers.
64 
65  IF (im8b) THEN
66  im8b = .false.
67 
68  CALL x84(ival,my_ival,1)
69  CALL pkbs1(my_ival,mbay,s1mnem)
70 
71  im8b = .true.
72  RETURN
73  END IF
74 
75 C Note that the following call to function IUPBS01 will ensure
76 C that subroutine WRDLEN has been called.
77 
78  iben = iupbs01(mbay,'BEN')
79 
80 C Determine where to store the value.
81 
82  CALL gets1loc(s1mnem,iben,isbyt,iwid,iret)
83  IF ( (iret.EQ.0) .AND.
84  . ( (s1mnem.EQ.'USN') .OR. (s1mnem.EQ.'BMT') .OR.
85  . (s1mnem.EQ.'OGCE') .OR. (s1mnem.EQ.'GSES') .OR.
86  . (s1mnem.EQ.'MTYP') .OR. (s1mnem.EQ.'MSBTI') .OR.
87  . (s1mnem.EQ.'MSBT') .OR. (s1mnem.EQ.'MTV') .OR.
88  . (s1mnem.EQ.'MTVL') .OR. (s1mnem.EQ.'YCEN') .OR.
89  . (s1mnem.EQ.'CENT') .OR. (s1mnem.EQ.'YEAR') .OR.
90  . (s1mnem.EQ.'MNTH') .OR. (s1mnem.EQ.'DAYS') .OR.
91  . (s1mnem.EQ.'HOUR') .OR. (s1mnem.EQ.'MINU') .OR.
92  . (s1mnem.EQ.'SECO') ) ) THEN
93 
94 C Store the value.
95 
96  ibit = (iupbs01(mbay,'LEN0')+isbyt-1)*8
97  CALL pkb(ival,iwid,mbay,ibit)
98  ELSE
99  GOTO 900
100  ENDIF
101 
102  RETURN
103 900 WRITE(bort_str,'("BUFRLIB: PKBS1 - CANNOT OVERWRITE LOCATION '//
104  . 'CORRESPONDING TO MNEMONIC (",A,") WITHIN BUFR EDITION '//
105  . '(",I1,")")') s1mnem, iben
106  CALL bort(bort_str)
107  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine gets1loc(S1MNEM, IBEN, ISBYT, IWID, IRET)
This subroutine returns the location of a specified value within Section 1 of a BUFR message.
Definition: gets1loc.f:57
recursive function iupbs01(MBAY, S01MNEM)
Read a data value from Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:69
This module declares and initializes the IM8B variable.
logical, public im8b
Status indicator to keep track of whether all future calls to BUFRLIB subroutines and functions from ...
subroutine pkb(NVAL, NBITS, IBAY, IBIT)
This subroutine encodes an integer value within a specified number of bits of an integer array,...
Definition: pkb.f:28
recursive subroutine pkbs1(IVAL, MBAY, S1MNEM)
This subroutines writes a specified value into a specified location within Section 1 of a BUFR messag...
Definition: pkbs1.f:51
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19