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