NCEPLIBS-bufr 11.7.1
wrtree.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 1994-01-06
3
4C> THIS SUBROUTINE CONVERTS USER NUMBERS INTO SCALED INTEGERS
5C> AND PACKS THE USER ARRAY INTO THE SUBSET BUFFER.
6C>
7C> PROGRAM HISTORY LOG:
8C> 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
9C> 1998-07-08 J. WOOLLEN -- CORRECTED SOME MINOR ERRORS
10C> 1999-11-18 J. WOOLLEN -- THE NUMBER OF BUFR FILES WHICH CAN BE
11C> OPENED AT ONE TIME INCREASED FROM 10 TO 32
12C> (NECESSARY IN ORDER TO PROCESS MULTIPLE
13C> BUFR FILES UNDER THE MPI)
14C> 2000-09-19 J. WOOLLEN -- MAXIMUM MESSAGE LENGTH INCREASED FROM
15C> 10,000 TO 20,000 BYTES
16C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
17C> INTERDEPENDENCIES
18C> 2003-11-04 D. KEYSER -- MAXJL (MAXIMUM NUMBER OF JUMP/LINK ENTRIES)
19C> INCREASED FROM 15000 TO 16000 (WAS IN
20C> VERIFICATION VERSION); UNIFIED/PORTABLE FOR
21C> WRF; ADDED DOCUMENTATION (INCLUDING
22C> HISTORY); REPL. "IVAL(N)=ANINT(PKS(NODE))"
23C> WITH "IVAL(N)=NINT(PKS(NODE))" (FORMER
24C> CAUSED PROBLEMS ON SOME FOREIGN MACHINES)
25C> 2004-03-10 J. WOOLLEN -- CONVERTED PACKING FUNCTION 'PKS' TO REAL*8
26C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
27C> 20,000 TO 50,000 BYTES
28C> 2007-01-19 J. ATOR -- PREVENT OVERFLOW OF CVAL FOR STRINGS LONGER
29C> THAN 8 CHARACTERS; USE FUNCTION IBFMS
30C> 2009-08-03 J. WOOLLEN -- ADDED CAPABILITY TO COPY LONG STRINGS VIA
31C> UFBCPY USING FILE POINTER STORED IN NEW
32C> COMMON UFBCPL
33C> 2012-03-02 J. ATOR -- USE IPKS TO HANDLE 2-03 OPERATOR CASES
34C> 2012-06-04 J. ATOR -- ENSURE "MISSING" CHARACTER FIELDS ARE
35C> PROPERLY ENCODED WITH ALL BITS SET TO 1
36C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
37C> 2022-05-06 J. WOOLLEN -- REPLACE PKB WITH PKB8 FOR 8BYTE INTEGERS
38C>
39C> USAGE: CALL WRTREE (LUN)
40C> INPUT ARGUMENT LIST:
41C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
42C>
43C> REMARKS:
44C> THIS ROUTINE CALLS: IBFMS IPKM PKB8 PKC
45C> IPKS READLC
46C> THIS ROUTINE IS CALLED BY: WRITSA WRITSB
47C> Normally not called by any application
48C> programs.
49C>
50 SUBROUTINE wrtree(LUN)
51
52 USE moda_usrint
53 USE moda_ival
54 USE moda_ufbcpl
55 USE moda_bitbuf
56 USE moda_tables
57
58 CHARACTER*120 LSTR
59 CHARACTER*8 CVAL
60 equivalence(cval,rval)
61 integer(8) ipks
62 real*8 rval
63
64C-----------------------------------------------------------------------
65
66C CONVERT USER NUMBERS INTO SCALED INTEGERS
67C -----------------------------------------
68
69 DO n=1,nval(lun)
70 node = inv(n,lun)
71 IF(itp(node).EQ.1) THEN
72 ival(n) = val(n,lun)
73 ELSEIF(typ(node).EQ.'NUM') THEN
74 IF(ibfms(val(n,lun)).EQ.0) THEN
75 ival(n) = ipks(val(n,lun),node)
76 ELSE
77 ival(n) = -1
78 ENDIF
79 ENDIF
80 ENDDO
81
82C PACK THE USER ARRAY INTO THE SUBSET BUFFER
83C ------------------------------------------
84
85 ibit = 16
86
87 DO n=1,nval(lun)
88 node = inv(n,lun)
89 IF(itp(node).LT.3) THEN
90
91C The value to be packed is numeric.
92
93 CALL pkb8(ival(n),ibt(node),ibay,ibit)
94 ELSE
95
96C The value to be packed is a character string.
97
98 ncr=ibt(node)/8
99 IF ( ncr.GT.8 .AND. luncpy(lun).NE.0 ) THEN
100
101C The string is longer than 8 characters and there was a
102C preceeding call to UFBCPY involving this output unit, so
103C read the long string with READLC and write it into the
104C output buffer using PKC.
105
106 CALL readlc(luncpy(lun),lstr,tag(node))
107 CALL pkc(lstr,ncr,ibay,ibit)
108 ELSE
109 rval = val(n,lun)
110 IF(ibfms(rval).NE.0) THEN
111
112C The value is "missing", so set all bits to 1 before
113C packing the field as a character string.
114
115 numchr = min(ncr,len(lstr))
116 DO jj = 1, numchr
117 CALL ipkm(lstr(jj:jj),1,255)
118 ENDDO
119 CALL pkc(lstr,numchr,ibay,ibit)
120 ELSE
121
122C The value is not "missing", so pack the equivalenced
123C character string. Note that a maximum of 8 characters
124C will be packed here, so a separate subsequent call to
125C BUFR archive library subroutine WRITLC will be needed to
126C fully encode any string longer than 8 characters.
127
128 CALL pkc(cval,ncr,ibay,ibit)
129 ENDIF
130 ENDIF
131
132 ENDIF
133 ENDDO
134
135C RESET UFBCPY FILE POINTER
136C -------------------------
137
138 luncpy(lun)=0
139
140 RETURN
141 END
integer function ibfms(R8VAL)
This function provides a handy way to check whether a real*8 data value returned from a previous call...
Definition: ibfms.f:39
subroutine ipkm(CBAY, NBYT, N)
This subroutine encodes an integer value within a specified number of bytes of a character string,...
Definition: ipkm.f:28
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
This module contains array and variable declarations used to store the internal jump/link table.
Definition: moda_tables.F:13
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
Definition: moda_tables.F:141
character *3, dimension(:), allocatable typ
Type indicators corresponding to tag:
Definition: moda_tables.F:133
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
Definition: moda_tables.F:138
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.
Definition: moda_tables.F:132
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:36
subroutine pkc(CHR, NCHR, IBAY, IBIT)
This subroutine encodes a character string within a specified number of bits of an integer array,...
Definition: pkc.f:41
subroutine readlc(LUNIT, CHR, STR)
This subroutine reads a long character string (greater than 8 bytes) from a data subset.
Definition: readlc.f:59
subroutine wrtree(LUN)
THIS SUBROUTINE CONVERTS USER NUMBERS INTO SCALED INTEGERS AND PACKS THE USER ARRAY INTO THE SUBSET B...
Definition: wrtree.f:51