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