UPP v11.0.0
Loading...
Searching...
No Matches
native_endianness.f
Go to the documentation of this file.
1
12
25
26
27 use kinds, only: i_byte,i_long
28 implicit none
29
30 private
31
32 public byte_swap
33 public is_little_endian
34
35 logical byte_swap
36
37 contains
38
39 logical function is_little_endian()
40
48 implicit none
49
50 integer(i_byte) :: i1
51 integer(i_long) :: i2
52
53 i1 = 1
54 i2 = 0
55 i2 = transfer(i1,i2)
56
57 is_little_endian = (i1 == i2)
58
59 end function is_little_endian
60
61 end module native_endianness
62
63!----------------------------------------------------------------------
64! convert 4-byte integer scalar from big-endian to native-endian
65!----------------------------------------------------------------------
66
67 subroutine to_native_endianness_i4(i4,num)
68
81 use kinds, only: i_byte,i_long,i_llong
82 implicit none
83
84 integer(i_llong), intent(in) :: num
85 integer(i_long), intent(inout) :: i4(num)
86
87 integer(i_byte), dimension(4) :: byte_arr, byte_arr_tmp
88 integer(i_long) :: i,n
89
90 do n=1,num
91 byte_arr_tmp = transfer(i4(n), byte_arr)
92 byte_arr(1)=byte_arr_tmp(4)
93 byte_arr(2)=byte_arr_tmp(3)
94 byte_arr(3)=byte_arr_tmp(2)
95 byte_arr(4)=byte_arr_tmp(1)
96 i4(n) = transfer(byte_arr, i4(n))
97 end do
98
99 return
100
101 end subroutine to_native_endianness_i4
logical function, public is_little_endian()