NCEPLIBS-bufr  12.0.0
invmrg.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Merge parts of data subsets
3 C>
4 C> @author J. Woollen @date 1996-10-09
5 
6 C> This subroutine merges parts of data subsets which have duplicate
7 C> space and time coordinates but different or unique observational data.
8 C>
9 C> @param[in] LUBFI -- integer: Fortran logical unit number for input
10 C> BUFR file
11 C> @param[in] LUBFJ -- integer: Fortran logical unit number for output
12 C> BUFR file
13 C>
14 C> Logical unit LUBFI should have already been opened for input
15 C> operations via a previous call to subroutine openbf().
16 C>
17 C> Logical unit LUBFJ should have already been opened for output
18 C> operations via a previous call to subroutine openbf().
19 C>
20 C> @remarks
21 C> - This subroutine cannot merge parts of data subsets which are
22 C> contained within replication sequences.
23 C>
24 C> @author J. Woollen @date 1996-10-09
25  RECURSIVE SUBROUTINE invmrg(LUBFI,LUBFJ)
26 
27  USE moda_usrint
28  USE moda_tables
29  USE modv_im8b
30 
31  COMMON /mrgcom/ nrpl,nmrg,namb,ntot
32 
33  CHARACTER*128 bort_str
34  LOGICAL herei,herej,missi,missj,samei
35 
36 C-----------------------------------------------------------------------
37 C-----------------------------------------------------------------------
38 
39 C CHECK FOR I8 INTEGERS
40 C ---------------------
41 
42  IF(im8b) THEN
43  im8b=.false.
44 
45  CALL x84(lubfi,my_lubfi,1)
46  CALL x84(lubfj,my_lubfj,1)
47  CALL invmrg(my_lubfi,my_lubfj)
48 
49  im8b=.true.
50  RETURN
51  ENDIF
52 
53  is = 1
54  js = 1
55 
56 C GET THE UNIT POINTERS
57 C ---------------------
58 
59  CALL status(lubfi,luni,il,im)
60  CALL status(lubfj,lunj,jl,jm)
61 
62 C STEP THROUGH THE BUFFERS COMPARING THE INVENTORY AND MERGING DATA
63 C -----------------------------------------------------------------
64 
65  DO WHILE(is.LE.nval(luni))
66 
67 C CHECK TO SEE WE ARE AT THE SAME NODE IN EACH BUFFER
68 C ---------------------------------------------------
69 
70  node = inv(is,luni)
71  nodj = inv(js,lunj)
72  IF(node.NE.nodj) GOTO 900
73 
74  ityp = itp(node)
75 
76 C FOR TYPE 1 NODES DO AN ENTIRE SEQUENCE REPLACEMENT
77 C --------------------------------------------------
78 
79  IF(ityp.EQ.1) THEN
80  IF(typ(node).EQ.'DRB') ioff = 0
81  IF(typ(node).NE.'DRB') ioff = 1
82  iwrds = nwords(is,luni)+ioff
83  jwrds = nwords(js,lunj)+ioff
84  IF(iwrds.GT.ioff .AND. jwrds.EQ.ioff) THEN
85  DO n=nval(lunj),js+1,-1
86  inv(n+iwrds-jwrds,lunj) = inv(n,lunj)
87  val(n+iwrds-jwrds,lunj) = val(n,lunj)
88  ENDDO
89  DO n=0,iwrds
90  inv(js+n,lunj) = inv(is+n,luni)
91  val(js+n,lunj) = val(is+n,luni)
92  ENDDO
93  nval(lunj) = nval(lunj)+iwrds-jwrds
94  jwrds = iwrds
95  nrpl = nrpl+1
96  ENDIF
97  is = is+iwrds
98  js = js+jwrds
99  ENDIF
100 
101 C FOR TYPES 2 AND 3 FILL MISSINGS
102 C -------------------------------
103 
104  IF((ityp.EQ.2).OR.(ityp.EQ.3)) THEN
105  herei = ibfms(val(is,luni)).EQ.0
106  herej = ibfms(val(js,lunj)).EQ.0
107  missi = .NOT.(herei)
108  missj = .NOT.(herej)
109  samei = val(is,luni).EQ.val(js,lunj)
110  IF(herei.AND.missj) THEN
111  val(js,lunj) = val(is,luni)
112  nmrg = nmrg+1
113  ELSEIF(herei.AND.herej.AND..NOT.samei) THEN
114  namb = namb+1
115  ENDIF
116  ENDIF
117 
118 C BUMP THE COUNTERS AND GO CHECK THE NEXT PAIR
119 C --------------------------------------------
120 
121  is = is + 1
122  js = js + 1
123  ENDDO
124 
125  ntot = ntot+1
126 
127 C EXITS
128 C -----
129 
130  RETURN
131 900 WRITE(bort_str,'("BUFRLIB: INVMRG - NODE FROM INPUT BUFR FILE '//
132  . '(",I7,") DOES NOT EQUAL NODE FROM OUTPUT BUFR FILE (",I7,"), '//
133  . 'TABULAR MISMATCH")') node,nodj
134  CALL bort(bort_str)
135  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
integer function ibfms(R8VAL)
Test whether a real*8 data value is "missing".
Definition: ibfms.f:28
recursive subroutine invmrg(LUBFI, LUBFJ)
This subroutine merges parts of data subsets which have duplicate space and time coordinates but diff...
Definition: invmrg.f:26
This module contains array and variable declarations used to store the internal jump/link table.
character *3, dimension(:), allocatable typ
Type indicators corresponding to tag:
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
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...
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 ...
function nwords(N, LUN)
This function adds up the complete length of the delayed replication sequence beginning at index N of...
Definition: nwords.f:16
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 x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19