I would like to have a class this:
class block {
public:
int NX,NY;
int A[][]; // I want the the dimension of A is from 1 to NX and 1 to NY, how do I do that?
};
actually, I already have the corresponding FORTRAN code, I want to have it in c++, I believe with proper use of constructor, I will be able to easily to create and copy object, instead of copy each components of the object like FORTRAN does. Please teach me how to do this! thanks!
module LinearSolution
type LAE
integer::N
double precision,dimension(:,:),allocatable::A
double precision,dimension( :),allocatable::B
contains
procedure,nopass::RowReduction
end type LAE
contains
subroutine RowReduction
double precision::C
do k=1,N
do i=k+1,N
if(A(k,k)/=0) then
C=A(i,k)/A(k,k)
B(i)=B(i)-B(k)*C !error: Statement Function is recursive
do j=k+1,N
A(i,j)=A(i,j)-A(k,j)*C !error: Statement Function is recursive
end do
end if
end do
end do
do k=N,1,-1
do i=k-1,1,-1
if(A(k,k)/=0) then
C=A(i,k)/A(k,k)
B(i)=B(i)-B(k)*C !error: Statement Function is recursive
end if
end do
end do
do k=1,N
if(A(k,k)/=0) then
B(k)=B(k)/A(k,k) !error: Statement Function is recursive
end if
end do
end subroutine RowReduction
end module LinearSolution
program TestLAE
use LinearSolution !fatal error: cant open module file LinearSolution.mod for reading
type(LAE)::LAE1
LAE1%N=3
allocate(LAE1%B(1:N))
allocate(LAE1%A(1:N,1:N))
LAE1%B=(/1,1,1/)
LAE1%A=(/2,0,0,0,2,0,0,0,2/)
call LAE1%RowReduction
print*, LAE1%B(1),LAE1%B(2),LAE1%B(3)
end program