-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.f90
99 lines (76 loc) · 1.67 KB
/
misc.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module misc
use precision, only : prec
implicit none
private
public toUPPER,swap,pack_vector,unpack_vector
interface swap
module procedure swap_int,swap_log,swap_real
end interface swap
contains
subroutine toUPPER(string)
implicit none
integer,parameter :: codea = iachar('a'), codez = iachar('z')
integer,parameter :: offset = iachar('A') - iachar('a')
character(*),intent(inout) :: string
integer :: i,code
do i=1,len_trim(string)
code = iachar(string(i:i))
if(code>=codea .and. code<=codez) string(i:i) = achar(code + offset)
enddo
end subroutine toUPPER
elemental subroutine swap_int(v1,v2)
implicit none
integer,intent(inout) :: v1,v2
integer :: tmp
tmp = v1
v1 = v2
v2 = tmp
end subroutine swap_int
elemental subroutine swap_log(v1,v2)
implicit none
logical,intent(inout) :: v1,v2
logical :: tmp
tmp = v1
v1 = v2
v2 = tmp
end subroutine swap_log
elemental subroutine swap_real(v1,v2)
implicit none
real(prec),intent(inout) :: v1,v2
real(prec) :: tmp
tmp = v1
v1 = v2
v2 = tmp
end subroutine swap_real
subroutine pack_vector(vecS,n,vecL,mask)
implicit none
real(prec),intent(out) :: vecS(:)
integer,intent(in) :: n
real(prec),intent(in) :: vecL(:)
logical,intent(in) :: mask(:)
integer :: iS,iL
vecS = 0._prec
iS = 0
do iL=1,n
if(mask(iL)) then
iS = iS + 1
vecS(iS) = vecL(iL)
endif
enddo
end subroutine pack_vector
subroutine unpack_vector(vecS,n,vecL,mask)
implicit none
real(prec),intent(in) :: vecS(:)
integer,intent(in) :: n
real(prec),intent(inout) :: vecL(:)
logical,intent(in) :: mask(:)
integer :: iS,iL
iS = 0
do iL=1,n
if(mask(iL)) then
iS = iS + 1
vecL(iL) = vecS(iS)
endif
enddo
end subroutine unpack_vector
end module misc