-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsexptran_get_X_array2.f90
More file actions
108 lines (94 loc) · 2.76 KB
/
sexptran_get_X_array2.f90
File metadata and controls
108 lines (94 loc) · 2.76 KB
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
100
101
102
103
104
105
106
107
108
subroutine X1(this,x)
class(sexp), intent(in), pointer :: this
Y, allocatable, intent(out) :: x(:,:)
class(list_t), pointer :: lst,row
integer :: m,n,n2,i,j
character(len=100) :: buf
if (.not. associated(this)) then
allocate(x(0,0))
return
end if
call list_length(this,m,lst)
if (.not. associated(lst)) then
call this%err%set('Cannot get '//Z//' matrix')
return
end if
if (m==0) then
allocate(x(0,0))
return
end if
call list_length(lst%car,n,row)
if (.not. associated(row)) then
write (buf,'("Cannot get first row of ",I0," row ",A," matrix")') m,Z
goto 900
end if
allocate(x(m,n))
do i=1,m
call list_length(lst%car,n2,row)
if (n /= n2) then
write (buf,'("Row ",I0," has abnormal length ",I0," in ",I0," by ",I0," ",A," matrix")') &
i,n2,m,n,Z
goto 900
end if
do j=1,n
call get_value(row%car,x(i,j))
if (erroneous(lst%car%err)) then
write (buf,'("Cannot parse row ",I0," column ",I0," of ",I0," by ",I0," ",A," matrix")') &
i,j,m,n,Z
goto 900
end if
row=>row%cdr
end do
lst=>lst%cdr
end do
return
900 call this%err%set(trim(buf))
deallocate(x)
end subroutine X1
subroutine X2(this,x)
class(sexp), intent(in), pointer :: this
Y, intent(out) :: x(:,:)
class(list_t), pointer :: lst,row
integer :: m,n,n2,i,j
character(len=100) :: buf
if (.not. associated(this)) return
call list_length(this,m,lst)
if (.not. associated(lst)) then
call this%err%set('Cannot get '//Z//' matrix')
return
end if
if (m/=size(x,1)) then
call this%err%set('Incorrect array dimensions (1)')
return
end if
if (m==0) return
call list_length(lst%car,n,row)
if (.not. associated(row)) then
write (buf,'("Cannot get first row of ",I0," row ",A," matrix")') m,Z
goto 900
end if
if (n/=size(x,2)) then
call this%err%set('Incorrect array dimensions (2)')
return
end if
do i=1,m
call list_length(lst%car,n2,row)
if (n /= n2) then
write (buf,'("Row ",I0," has abnormal length ",I0," in ",I0," by ",I0," ",A," matrix")') &
i,n2,m,n,Z
goto 900
end if
do j=1,n
call get_value(row%car,x(i,j))
if (erroneous(lst%car%err)) then
write (buf,'("Cannot parse row ",I0," column ",I0," of ",I0," by ",I0," ",A," matrix")') &
i,j,m,n,Z
goto 900
end if
row=>row%cdr
end do
lst=>lst%cdr
end do
return
900 call this%err%set(trim(buf))
end subroutine X2