ENDIAN_UTILITY.F90 Subprograms

Last modified: Fri Feb 11 14:23:42 2005.


List of Subprograms


Subprogram Descriptions

BIG_ENDIAN

[Next Subprogram] [List of Subprograms]
 NAME:
       Big_Endian

 PURPOSE:
       Function to determine if current platform is big-endian.

 CATEGORY:
       Utility

 LANGUAGE:
       Fortran-95

 CALLING SEQUENCE:
       Result = Big_Endian()

 INPUT ARGUMENTS:
       None.

 OPTIONAL INPUT ARGUMENTS:
       None.

 OUTPUT ARGUMENTS:
       None.

 OPTIONAL OUTPUT ARGUMENTS:
       None.

 FUNCTION RESULT:
       Result:    The return value is a logical value indicating whether
                  the current platform is big-endian or not
                  .TRUE.  - it is a big-endian platform.
                  .FALSE. - it is NOT a big-endian platform.
                  UNITS:      N/A
                  TYPE:       LOGICAL
                  DIMENSION:  Scalar

 CALLS:
       None.

 CONTAINS:
       None.

 SIDE EFFECTS:
       None

 RESTRICTIONS:
       None

 PROCEDURE:
       Uses the Fortran90/95 intrinsics TRANSFER and IACHAR to test
       if a 2-byte integer (value 1) retains that value when
       transferred to a single-byte character representation. If
       it does, the platform is little-endian. If not, it is big-
       endian. This method was suggested by Clive Page, University
       of Leicester, UK.

 EXAMPLE:
       USE Endian_Utility
         .....
       WRITE( *, '( 5x, "Platform is " )', ADVANCE = 'NO' )
       IF ( Big_Endian() ) THEN
         WRITE( *, '( "big-endian." )' )
       ELSE
         WRITE( *, '( "litle-endian." )' )
       END IF

(See Endian_Utility.f90)


SWAP_ENDIAN

[Previous Subprogram] [List of Subprograms]
 NAME:
       Swap_Endian

 PURPOSE:
       Function to byte-swap input data.

 CATEGORY:
       Utility

 LANGUAGE:
       Fortran-95

 CALLING SEQUENCE:
       Result = Swap_Endian( Input )

 INPUT ARGUMENTS:
       Input:       Data object to be byte swapped.
                    UNITS:      N/A
                    TYPE:       Any of the following:
                                  INTEGER( Short )
                                  INTEGER( Long  )  [ == default integer]
                                  INTEGER( LLong )
                                  REAL( Single )   [ == default real]
                                  REAL( Double )
                                  COMPLEX( Single )
                                  COMPLEX( Double )
                    DIMENSION:  Scalar, or any allowed rank array.
                    ATTRIBUTES: INTENT( IN )

 OPTIONAL INPUT ARGUMENTS:
       None.

 OUTPUT ARGUMENTS:
       None.

 OPTIONAL OUTPUT ARGUMENTS:
       None.

 FUNCTION RESULT:
       Result:      The return value is the byte swapped value
                    UNITS:      N/A
                    TYPE:       Same as Input
                    DIMENSION:  Same as Input

 CALLS:
       None.

 CONTAINS:
       None.

 SIDE EFFECTS:
       None

 RESTRICTIONS:
       None.

 PROCEDURE:
       The TRANSFER intrinsic is used to rearrange the bytes by accessing
       the data with a subscript triplet having a negative stride.

       This method can be slow, not because of the TRANSFER function itself,
       but the negative stride of the array access. It depends on the 
       quality of implementation.

       The byte-swap for the complex data types are only slightly
       different in that each half of the total number representation
       in bytes is swapped rather than the whole thing (i.e. real and
       imaginary are swapped separately).

(See Endian_Utility.f90)