NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
copymg.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Copy a BUFR message.
3 
4 C> This subroutine copies a BUFR message from one Fortran logical unit
5 C> to another.
6 C>
7 C> <p>This subroutine is similar to subroutine cpymem(), except that
8 C> it copies a BUFR message from one Fortran logical unit to another,
9 C> whereas cpymem() copies a BUFR message from internal arrays in
10 C> memory to a specified Fortran logical unit.
11 C>
12 C> @author J. Woollen
13 C> @date 1994-01-06
14 C>
15 C> @param[in] LUNIN - integer: Fortran logical unit number for
16 C> source BUFR file
17 C> @param[in] LUNOT - integer: Fortran logical unit number for
18 C> target BUFR file
19 C>
20 C> <p>Logical unit LUNIN should have already been opened for input
21 C> operations via a previous call to subroutine openbf(), and a BUFR
22 C> message should have already been read into internal arrays for
23 C> LUNIN via a previous call to one of the
24 C> [message-reading subroutines](@ref hierarchy).
25 C>
26 C> <p>Logical unit LUNOT should have already been opened for output
27 C> operations via a previous call to subroutine openbf(), but there
28 C> should not be any BUFR message already open for output within the
29 C> internal arrays for LUNOT via a previous call to one of the BUFRLIB
30 C> [message-writing subroutines](@ref hierarchy).
31 C>
32 C> <p>The [DX BUFR Table information](@ref dfbftab) associated with
33 C> each of the logical units LUNIN and LUNOT must contain identical
34 C> definitions for the type of BUFR message to be copied from LUNIN
35 C> to LUNOT.
36 C>
37 C> @remarks
38 C> - This subroutine uses subroutine msgwrt() to write to LUNOT;
39 C> therefore, it can be used to transform a copy of the
40 C> original BUFR message from LUNIN with any or all of the updates
41 C> described in the documentation for subroutine msgwrt().
42 C>
43 C> <b>Program history log:</b>
44 C> - 1994-01-06 J. Woollen -- Original author
45 C> - 1998-07-08 J. Woollen -- Replaced call to Cray library routine ABORT
46 C> with call to new internal routine bort()
47 C> - 1999-11-18 J. Woollen -- The number of BUFR files which can be
48 C> opened at one time increased from 10 to 32
49 C> (necessary in order to process multiple
50 C> BUFR files under the MPI)
51 C> - 2000-09-19 J. Woollen -- Maximum message length increased
52 C> from 10,000 to 20,000 bytes
53 C> - 2004-08-09 J. Ator -- Maximum message length increased
54 C> from 20,000 to 50,000 bytes
55 C> - 2005-11-29 J. Ator -- Use iupbs01()
56 C> - 2009-06-26 J. Ator -- Use iok2cpy()
57 C> - 2014-12-10 J. Ator -- Use modules instead of COMMON blocks
58 C>
59  SUBROUTINE copymg(LUNIN,LUNOT)
60 
61  USE moda_msgcwd
62  USE moda_bitbuf
63  USE moda_tables
64 
65  CHARACTER*8 subset
66 
67 C-----------------------------------------------------------------------
68 C-----------------------------------------------------------------------
69 
70 C CHECK THE FILE STATUSES
71 C -----------------------
72 
73  CALL status(lunin,lin,il,im)
74  IF(il.EQ.0) goto 900
75  IF(il.GT.0) goto 901
76  IF(im.EQ.0) goto 902
77 
78  CALL status(lunot,lot,il,im)
79  IF(il.EQ.0) goto 903
80  IF(il.LT.0) goto 904
81  IF(im.NE.0) goto 905
82 
83 C MAKE SURE BOTH FILES HAVE THE SAME TABLES
84 C -----------------------------------------
85 
86  subset = tag(inode(lin))
87 c .... Given SUBSET, returns MTYP,MSBT,INOD
88  CALL nemtba(lot,subset,mtyp,msbt,inod)
89  IF(inode(lin).NE.inod) THEN
90  IF(iok2cpy(lin,lot).NE.1) goto 906
91  ENDIF
92 
93 C EVERYTHING OKAY, COPY A MESSAGE
94 C -------------------------------
95 
96  mbym = iupbs01(mbay(1,lin),'LENM')
97  CALL msgwrt(lunot,mbay(1,lin),mbym)
98 
99 C SET THE MESSAGE CONTROL WORDS FOR PARTITION ASSOCIATED WITH LUNOT
100 C -----------------------------------------------------------------
101 
102  nmsg(lot) = nmsg(lot) + 1
103  nsub(lot) = msub(lin)
104  msub(lot) = msub(lin)
105  idate(lot) = idate(lin)
106  inode(lot) = inod
107 
108 C EXITS
109 C -----
110 
111  RETURN
112 900 CALL bort('BUFRLIB: COPYMG - INPUT BUFR FILE IS CLOSED, IT MUST'//
113  . ' BE OPEN FOR INPUT')
114 901 CALL bort('BUFRLIB: COPYMG - INPUT BUFR FILE IS OPEN FOR '//
115  . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
116 902 CALL bort('BUFRLIB: COPYMG - A MESSAGE MUST BE OPEN IN INPUT '//
117  . 'BUFR FILE, NONE ARE')
118 903 CALL bort('BUFRLIB: COPYMG - OUTPUT BUFR FILE IS CLOSED, IT '//
119  . 'MUST BE OPEN FOR OUTPUT')
120 904 CALL bort('BUFRLIB: COPYMG - OUTPUT BUFR FILE IS OPEN FOR '//
121  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
122 905 CALL bort('BUFRLIB: COPYMG - ALL MESSAGES MUST BE CLOSED IN '//
123  . 'OUTPUT BUFR FILE, A MESSAGE IS OPEN')
124 906 CALL bort('BUFRLIB: COPYMG - INPUT AND OUTPUT BUFR FILES MUST '//
125  . 'HAVE THE SAME INTERNAL TABLES, THEY ARE DIFFERENT HERE')
126  END
subroutine msgwrt(LUNIT, MESG, MGBYT)
This subroutine performs final checks and updates on a BUFR message before writing it to a specified ...
Definition: msgwrt.f:69
subroutine copymg(LUNIN, LUNOT)
This subroutine copies a BUFR message from one Fortran logical unit to another.
Definition: copymg.f:59
This module contains array and variable declarations used to store the internal jump/link table...
Definition: moda_tables.F:13
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:61
INTEGER function iok2cpy(LUI, LUO)
This function determines whether a BUFR message, or a data subset from within a BUFR message...
Definition: iok2cpy.f:35
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
subroutine nemtba(LUN, NEMO, MTYP, MSBT, INOD)
THIS SUBROUTINE SEARCHES FOR MNEMONIC NEMO WITHIN THE INTERNAL TABLE A ARRAYS HOLDING THE DICTIONARY ...
Definition: nemtba.f:50
function iupbs01(MBAY, S01MNEM)
This function returns a specified value from within Section 0 or Section 1 of a BUFR message...
Definition: iupbs01.f:72