Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / external / bufr / irev.for
blobfd0ab62208775e1f73a8c41effd19c2d962c6b9c
1 FUNCTION IREV(N)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 C SUBPROGRAM: IREV
6 C PRGMMR: WOOLLEN ORG: NP20 DATE: 1994-01-06
8 C ABSTRACT: THIS FUNCTION WILL, WHEN THE LOCAL MACHINE IS "LITTLE-
9 C ENDIAN" (I.E., USES A RIGHT TO LEFT SCHEME FOR NUMBERING THE BYTES
10 C WITHIN A MACHINE WORD), RETURN A COPY OF AN INPUT INTEGER WORD WITH
11 C THE BYTES REVERSED. ALTHOUGH, BY DEFINITION (WITHIN WMO MANUAL
12 C 306), A BUFR MESSAGE IS A STREAM OF INDIVIDUAL OCTETS (I.E., BYTES)
13 C THAT IS INDEPENDENT OF ANY PARTICULAR MACHINE REPRESENTATION, THE
14 C BUFR ARCHIVE LIBRARY SOFTWARE OFTEN NEEDS TO INTERPRET ALL OR PARTS
15 C OF TWO OR MORE ADJACENT BYTES IN ORDER TO CONSTRUCT AN INTEGER
16 C WORD. BY DEFAULT, THE SOFTWARE USES THE "BIG-ENDIAN" (LEFT TO
17 C RIGHT) SCHEME FOR NUMBERING BYTES. BY REVERSING THE BYTES, IREV
18 C ALLOWS THE INTEGER WORD TO BE PROPERLY READ OR WRITTEN (DEPENDING
19 C ON WHETHER INPUT OR OUTPUT OPERATIONS, RESPECTIVELY, ARE BEING
20 C PERFORMED) ON LITTLE-ENDIAN MACHINES. IF THE LOCAL MACHINE IS
21 C BIG-ENDIAN, IREV SIMPLY RETURNS A COPY OF THE SAME INTEGER THAT WAS
22 C INPUT.
24 C PROGRAM HISTORY LOG:
25 C 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
26 C 2003-11-04 J. ATOR -- ADDED DOCUMENTATION
27 C 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
28 C INTERDEPENDENCIES
29 C 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED HISTORY
30 C DOCUMENTATION
31 C 2007-01-19 J. ATOR -- BIG-ENDIAN VS. LITTLE-ENDIAN IS NOW
32 C DETERMINED AT COMPILE TIME AND CONFIGURED
33 C WITHIN BUFRLIB VIA CONDITIONAL COMPILATION
34 C DIRECTIVES
36 C USAGE: IREV (N)
37 C INPUT ARGUMENT LIST:
38 C N - INTEGER: INTEGER WORD WITH BYTES ORDERED ACCORDING TO
39 C THE "BIG-ENDIAN" NUMBERING SCHEME
41 C OUTPUT ARGUMENT LIST:
42 C IREV - INTEGER: INTEGER WORD WITH BYTES ORDERED ACCORDING TO
43 C THE NUMBERING SCHEME OF THE LOCAL MACHINE (EITHER
44 C "BIG-ENDIAN" OR "LITTLE-ENDIAN", IF "BIG-ENDIAN THEN
45 C THIS IS JUST A DIRECT COPY OF N)
47 C REMARKS:
48 C THIS ROUTINE CALLS: None
49 C THIS ROUTINE IS CALLED BY: IPKM IUPM PKB PKC
50 C UPBB
51 C Normally not called by any application
52 C programs.
54 C ATTRIBUTES:
55 C LANGUAGE: FORTRAN 77
56 C MACHINE: PORTABLE TO ALL PLATFORMS
58 C$$$
60 COMMON /HRDWRD/ NBYTW,NBITW,IORD(8)
62 CHARACTER*8 CINT,DINT
63 EQUIVALENCE(CINT,INT)
64 EQUIVALENCE(DINT,JNT)
66 C----------------------------------------------------------------------
67 C----------------------------------------------------------------------
69 #ifdef BIG_ENDIAN
70 IREV = N
71 #else
72 INT = N
73 DO I=1,NBYTW
74 DINT(I:I) = CINT(IORD(I):IORD(I))
75 ENDDO
76 IREV = JNT
77 #endif
79 RETURN
80 END