NCEPLIBS-bufr  12.0.1
wrtree.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Pack a BUFR data subset.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Pack a BUFR data subset.
7 C>
8 C> This subroutine converts user numbers from the val array into scaled
9 C> integers and packs them into bit strings in the ibay array.
10 C>
11 C> @param[in] lun - integer: file ID.
12 C>
13 C> @author J. Woollen @date 1994-01-06
14 
15  SUBROUTINE wrtree(LUN)
16 
17  USE moda_usrint
18  USE moda_ival
19  USE moda_ufbcpl
20  USE moda_bitbuf
21  USE moda_tables
22 
23  CHARACTER*120 LSTR
24  CHARACTER*8 CVAL
25  equivalence(cval,rval)
26  integer(8) ipks
27  real*8 rval
28 
29 C-----------------------------------------------------------------------
30 
31 C CONVERT USER NUMBERS INTO SCALED INTEGERS
32 C -----------------------------------------
33 
34  DO n=1,nval(lun)
35  node = inv(n,lun)
36  IF(itp(node).EQ.1) THEN
37  ival(n) = nint(val(n,lun))
38  ELSEIF(typ(node).EQ.'NUM') THEN
39  IF(ibfms(val(n,lun)).EQ.0) THEN
40  ival(n) = ipks(val(n,lun),node)
41  ELSE
42  ival(n) = -1
43  ENDIF
44  ENDIF
45  ENDDO
46 
47 C PACK THE USER ARRAY INTO THE SUBSET BUFFER
48 C ------------------------------------------
49 
50  ibit = 16
51 
52  DO n=1,nval(lun)
53  node = inv(n,lun)
54  IF(itp(node).LT.3) THEN
55 
56 C The value to be packed is numeric.
57 
58  CALL pkb8(ival(n),ibt(node),ibay,ibit)
59  ELSE
60 
61 C The value to be packed is a character string.
62 
63  ncr=ibt(node)/8
64  IF ( ncr.GT.8 .AND. luncpy(lun).NE.0 ) THEN
65 
66 C The string is longer than 8 characters and there was a
67 C preceeding call to UFBCPY involving this output unit, so
68 C read the long string with READLC and write it into the
69 C output buffer using PKC.
70 
71  CALL readlc(luncpy(lun),lstr,tag(node))
72  CALL pkc(lstr,ncr,ibay,ibit)
73  ELSE
74  rval = val(n,lun)
75  IF(ibfms(rval).NE.0) THEN
76 
77 C The value is "missing", so set all bits to 1 before
78 C packing the field as a character string.
79 
80  numchr = min(ncr,len(lstr))
81  DO jj = 1, numchr
82  CALL ipkm(lstr(jj:jj),1,255)
83  ENDDO
84  CALL pkc(lstr,numchr,ibay,ibit)
85  ELSE
86 
87 C The value is not "missing", so pack the equivalenced
88 C character string. Note that a maximum of 8 characters
89 C will be packed here, so a separate subsequent call to
90 C BUFR archive library subroutine WRITLC will be needed to
91 C fully encode any string longer than 8 characters.
92 
93  CALL pkc(cval,ncr,ibay,ibit)
94  ENDIF
95  ENDIF
96 
97  ENDIF
98  ENDDO
99 
100 C RESET UFBCPY FILE POINTER
101 C -------------------------
102 
103  luncpy(lun)=0
104 
105  RETURN
106  END
integer function ibfms(R8VAL)
Test whether a real*8 data value is "missing".
Definition: ibfms.f:28
recursive subroutine ipkm(CBAY, NBYT, N)
Encode an integer value within a character string.
Definition: ipkm.f:22
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer, dimension(:), allocatable ibay
Current data subset.
integer ibit
Bit pointer within IBAY.
This module contains a declaration for an array used to pack or unpack all of the values of a BUFR da...
integer(8), dimension(:), allocatable ival
BUFR data subset values.
This module contains array and variable declarations used to store the internal jump/link table.
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
character *3, dimension(:), allocatable typ
Type indicators corresponding to tag:
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
This module contains an array declaration used to store, for each I/O stream index,...
integer, dimension(:), allocatable luncpy
Logical unit numbers used to copy long character strings between BUFR data subsets.
This module contains declarations for arrays used to store data values and associated metadata for th...
integer, dimension(:), allocatable nval
Number of data values in BUFR data subset.
real *8, dimension(:,:), allocatable, target val
Data values.
integer, dimension(:,:), allocatable, target inv
Inventory pointer which links each data value to its corresponding node in the internal jump/link tab...
subroutine pkb8(nval, nbits, ibay, ibit)
This subroutine encodes an 8-byte integer value within a specified number of bits of an integer array...
Definition: pkb8.f:28
subroutine pkc(CHR, NCHR, IBAY, IBIT)
Encode a character string within an integer array.
Definition: pkc.f:31
recursive subroutine readlc(LUNIT, CHR, STR)
Read a long character string (greater than 8 bytes) from a data subset.
Definition: readlc.f:50
subroutine wrtree(LUN)
Pack a BUFR data subset.
Definition: wrtree.f:16