NCEPLIBS-bufr  12.0.1
readlc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read a long character string (greater than 8 bytes) from
3 C> a data subset.
4 C>
5 C> @authors J. Woollen J. Ator @date 2003-11-04
6 
7 C> Read a long character string (greater than 8 bytes)
8 C> from a data subset.
9 C>
10 C> The data subset should have already been read into internal arrays
11 C> via a previous call to one of the
12 C> [subset-reading subroutines](@ref hierarchy).
13 C>
14 C> If there is more than one occurrence of STR within the data subset
15 C> definition, then each occurrence can be retrieved via a separate call
16 C> to this subroutine, and by appending the ordinal number of the
17 C> occurrence to STR in each case.
18 C>
19 C> For example, if there are 5
20 C> occurrences of mnemonic LSTID within a given data subset definition,
21 C> then 5 separate calls should be made to this subroutine, once each
22 C> with STR set to 'LSTID#1', 'LSTID#2', 'LSTID#3', 'LSTID#4' and
23 C> 'LSTID#5'.
24 C>
25 C> Omitting the ordinal number always defaults to the first occurrence
26 C> of a particular string, so a user could just specify 'LSTID'
27 C> instead of 'LSTID#1'.
28 C>
29 C> @remarks
30 C> - Character strings which are 8 bytes or less in length can be read
31 C> using the real*8 USR array within a call to one of the BUFRLIB
32 C> [values-reading subroutines](@ref hierarchy) and then converting the
33 C> corresponding real*8 value to character format within the
34 C> application program.
35 C> - If STR is not found within the data subset definition, then CHR is
36 C> returned with all bits set to 1, which is the standard WMO BUFR value
37 C> for "missing" data. Any CHR value returned by this subroutine can be
38 C> checked for equivalence to this "missing" value via a call to
39 C> function icbfms().
40 C>
41 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
42 C> @param[out] CHR - character*(*): Value corresponding to STR.
43 C> @param[in] STR - character*(*): Table B mnemonic of long character.
44 C> string to be retrieved, possibly supplemented with an ordinal
45 C> occurrence notation.
46 C>
47 C> @authors J. Woollen J. Ator @date 2003-11-04
48 
49  RECURSIVE SUBROUTINE readlc(LUNIT,CHR,STR)
50 
51  USE moda_usrint
52  USE moda_usrbit
53  USE moda_unptyp
54  USE moda_bitbuf
55  USE moda_tables
56  USE moda_rlccmn
57  USE modv_im8b
58 
59  COMMON /quiet / iprt
60 
61  CHARACTER*(*) chr,str
62  CHARACTER*128 bort_str,errstr
63  CHARACTER*10 ctag
64  CHARACTER*14 tgs(10)
65 
66  DATA maxtg /10/
67 
68 C-----------------------------------------------------------------------
69 C-----------------------------------------------------------------------
70 
71 C CHECK FOR I8 INTEGERS
72 C ---------------------
73  IF(im8b) THEN
74  im8b=.false.
75 
76  CALL x84(lunit,my_lunit,1)
77  CALL readlc(my_lunit,chr,str)
78 
79  im8b=.true.
80  RETURN
81  ENDIF
82 
83  chr = ' '
84  lchr=len(chr)
85 
86 C CHECK THE FILE STATUS
87 C ---------------------
88 
89  CALL status(lunit,lun,il,im)
90  IF(il.EQ.0) GOTO 900
91  IF(il.GT.0) GOTO 901
92  IF(im.EQ.0) GOTO 902
93 
94 C CHECK FOR TAGS (MNEMONICS) IN INPUT STRING (THERE CAN ONLY BE ONE)
95 C ------------------------------------------------------------------
96 
97  CALL parstr(str,tgs,maxtg,ntg,' ',.true.)
98  IF(ntg.GT.1) GOTO 903
99 
100 C Check if a specific occurrence of the input string was requested;
101 C if not, then the default is to return the first occurrence.
102 
103  CALL parutg(lun,0,tgs(1),nnod,kon,roid)
104  IF(kon.EQ.6) THEN
105  ioid=nint(roid)
106  IF(ioid.LE.0) ioid = 1
107  ctag = ' '
108  ii = 1
109  DO WHILE((ii.LE.10).AND.(tgs(1)(ii:ii).NE.'#'))
110  ctag(ii:ii)=tgs(1)(ii:ii)
111  ii = ii + 1
112  ENDDO
113  ELSE
114  ioid = 1
115  ctag = tgs(1)(1:10)
116  ENDIF
117 
118 C LOCATE AND DECODE THE LONG CHARACTER STRING
119 C -------------------------------------------
120 
121  IF(msgunp(lun).EQ.0.OR.msgunp(lun).EQ.1) THEN
122 
123 C The message is uncompressed
124 
125  itagct = 0
126  DO n=1,nval(lun)
127  nod = inv(n,lun)
128  IF(ctag.EQ.tag(nod)) THEN
129  itagct = itagct + 1
130  IF(itagct.EQ.ioid) THEN
131  IF(itp(nod).NE.3) GOTO 904
132  nchr = nbit(n)/8
133  IF(nchr.GT.lchr) GOTO 905
134  kbit = mbit(n)
135  CALL upc(chr,nchr,mbay(1,lun),kbit,.true.)
136  GOTO 100
137  ENDIF
138  ENDIF
139  ENDDO
140  ELSEIF(msgunp(lun).EQ.2) THEN
141 
142 C The message is compressed
143 
144  IF(nrst.GT.0) THEN
145  itagct = 0
146  DO ii=1,nrst
147  IF(ctag.EQ.crtag(ii)) THEN
148  itagct = itagct + 1
149  IF(itagct.EQ.ioid) THEN
150  nchr = irnch(ii)
151  IF(nchr.GT.lchr) GOTO 905
152  kbit = irbit(ii)
153  CALL upc(chr,nchr,mbay(1,lun),kbit,.true.)
154  GOTO 100
155  ENDIF
156  ENDIF
157  ENDDO
158  ENDIF
159  ELSE
160  GOTO 906
161  ENDIF
162 
163 C If we made it here, then we couldn't find the requested string.
164 
165  IF(iprt.GE.0) THEN
166  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
167  errstr = 'BUFRLIB: READLC - MNEMONIC ' // tgs(1) //
168  . ' NOT LOCATED IN REPORT SUBSET - RETURN WITH MISSING' //
169  . ' STRING FOR CHARACTER DATA ELEMENT'
170  CALL errwrt(errstr)
171  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
172  CALL errwrt(' ')
173  ENDIF
174  DO ii=1,lchr
175  CALL ipkm(chr(ii:ii),1,255)
176  ENDDO
177 
178 C EXITS
179 C -----
180 
181 100 RETURN
182 900 CALL bort('BUFRLIB: READLC - INPUT BUFR FILE IS CLOSED, IT MUST'//
183  . ' BE OPEN FOR INPUT')
184 901 CALL bort('BUFRLIB: READLC - INPUT BUFR FILE IS OPEN FOR '//
185  . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
186 902 CALL bort('BUFRLIB: READLC - A MESSAGE MUST BE OPEN IN INPUT '//
187  . 'BUFR FILE, NONE ARE')
188 903 WRITE(bort_str,'("BUFRLIB: READLC - THERE CANNOT BE MORE THAN '//
189  . 'ONE MNEMONIC IN THE INPUT STRING (",A,") (HERE THERE ARE ",'//
190  . 'I3,")")') str,ntg
191  CALL bort(bort_str)
192 904 WRITE(bort_str,'("BUFRLIB: READLC - MNEMONIC ",A," DOES NOT '//
193  . 'REPRESENT A CHARACTER ELEMENT (ITP=",I2,")")') tgs(1),itp(nod)
194  CALL bort(bort_str)
195 905 WRITE(bort_str,'("BUFRLIB: READLC - MNEMONIC ",A," IS A '//
196  . 'CHARACTER STRING OF LENGTH",I4," BUT SPACE WAS PROVIDED '//
197  . 'FOR ONLY",I4, " CHARACTERS")') tgs(1),nchr,lchr
198  CALL bort(bort_str)
199 906 WRITE(bort_str,'("BUFRLIB: READLC - MESSAGE UNPACK TYPE",I3,'//
200  . '" IS NOT RECOGNIZED")') msgunp
201  CALL bort(bort_str)
202  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
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 mbay
Current BUFR message for each internal I/O stream.
This module contains array and variable declarations needed to store information about long character...
integer nrst
Number of long character strings in data subset.
integer, dimension(:), allocatable irnch
Lengths (in bytes) of long character strings.
integer, dimension(:), allocatable irbit
Pointers in data subset to first bits of long character strings.
character *10, dimension(:), allocatable crtag
Table B mnemonics associated with long character strings.
This module contains array and variable declarations used to store the internal jump/link table.
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 from which a BUFR ...
integer, dimension(:), allocatable msgunp
Flag indicating how to unpack data subsets from BUFR message:
This module contains array declarations for internal storage of pointers to BUFR data subset values.
integer, dimension(:), allocatable nbit
Length (in bits) of each packed data value in data subset.
integer, dimension(:), allocatable mbit
Pointer in data subset to first bit of each packed data value.
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.
integer, dimension(:,:), allocatable, target inv
Inventory pointer which links each data value to its corresponding node in the internal jump/link tab...
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 parstr(STR, TAGS, MTAG, NTAG, SEP, LIMIT80)
Parse a string containing one or more substrings into an array of substrings.
Definition: parstr.f:24
subroutine parutg(LUN, IO, UTG, NOD, KON, VAL)
Parse a mnemonic from a character string.
Definition: parutg.f:83
recursive subroutine readlc(LUNIT, CHR, STR)
Read a long character string (greater than 8 bytes) from a data subset.
Definition: readlc.f:50
recursive subroutine status(LUNIT, LUN, IL, IM)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
Definition: status.f:36
subroutine upc(CHR, NCHR, IBAY, IBIT, CNVNULL)
Decode a character string from an integer array.
Definition: upc.f:32
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19