updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / var / external / bufr / rdmsgb.f
blob08207c157be1b511a831ae82e1ae74c277f502ed
1 SUBROUTINE RDMSGB(LUNIT,MESG,IRET)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 C SUBPROGRAM: RDMSGB
6 C PRGMMR: ATOR ORG: NP12 DATE: 2005-11-29
8 C ABSTRACT: THIS SUBROUTINE READS THE NEXT BUFR MESSAGE FROM LOGICAL
9 C UNIT LUNIT AS AN ARRAY OF BYTES, WHICH ARE THEN TRANSFERRED TO
10 C AN ARRAY OF INTEGER WORDS FOR OUTPUT.
12 C PROGRAM HISTORY LOG:
13 C 2005-11-29 J. ATOR -- ORIGINAL AUTHOR
14 C 2009-03-23 D. KEYSER -- CALLS BORT IN CASE OF MESG OVERFLOW
16 C USAGE: CALL RDMSGB (LUNIT, MESG, IRET)
17 C INPUT ARGUMENT LIST:
18 C LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
20 C OUTPUT ARGUMENT LIST:
21 C MESG - *-WORD ARRAY CONTAINING BUFR MESSAGE READ FROM LUNIT
22 C IRET - INTEGER: RETURN CODE:
23 C 0 = normal return
24 C -1 = end-of-file encountered while reading
25 C from LUNIT
26 C -2 = I/O error encountered while reading
27 C from LUNIT
29 C INPUT FILES:
30 C UNIT "LUNIT" - BUFR FILE
32 C REMARKS:
33 C THIS ROUTINE CALLS: BORT ICHKSTR IUPBS01 LMSG
34 C THIS ROUTINE IS CALLED BY: None
35 C Normally not called by any application
36 C programs.
38 C ATTRIBUTES:
39 C LANGUAGE: FORTRAN 77
40 C MACHINE: PORTABLE TO ALL PLATFORMS
42 C$$$
44 INCLUDE 'bufrlib.prm'
46 COMMON /HRDWRD/ NBYTW,NBITW,IORD(8)
48 DIMENSION MESG(*)
50 CHARACTER*128 BORT_STR
51 CHARACTER*8 SEC0
52 CHARACTER*1 CBAY(8*MXMSGLD4)
53 DIMENSION JBAY(MXMSGLD4)
55 EQUIVALENCE (CBAY(1),JBAY(1),SEC0)
57 C-----------------------------------------------------------------------
58 C-----------------------------------------------------------------------
60 SEC0 = ' '
62 C Read Section 0 from the next message in the file.
64 READ(LUNIT,END=100,ERR=200) SEC0
66 C Confirm that the first 4 bytes contain 'BUFR' encoded in
67 C CCITT IA5 (i.e. ASCII).
69 IF(ICHKSTR('BUFR',CBAY,4).NE.0) GOTO 200
71 C Check the length of the next message to make sure it will fit
72 C within the output array.
74 LNMSG = LMSG(SEC0)
75 IF(LNMSG*NBYTW.GT.MXMSGL) GOTO 900
77 C Read the rest of the message as an array of bytes.
79 READ(LUNIT,END=100,ERR=200) (CBAY(I),I=9,IUPBS01(JBAY,'LENM'))
81 C Transfer the message to the output array.
83 DO I=1,LNMSG
84 MESG(I) = JBAY(I)
85 ENDDO
87 C EXITS
88 C -----
90 IRET = 0
91 RETURN
93 100 IRET = -1
94 RETURN
96 200 IRET = -2
97 RETURN
99 900 WRITE(BORT_STR,'("BUFRLIB: RDMSGB - INPUT BUFR MESSAGE LENGTH (",
100 . I6," BYTES) IS LARGER THAN LIMIT OF ",I6," BYTES")')
101 . LNMSG*NBYTW,MXMSGL
102 CALL BORT(BORT_STR)