# Re: dimensions issue!

On Jan 20, 1:40 am, "Steven G. Kargl"
<s...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On Thu, 19 Jan 2012 17:35:10 -0800, milenko markovic wrote:
I am having problems with one program like this:
do i = 1, c
work1_n = (work_cn(i,:)/work_n)**2
do k=1,s
dvv(i,k) = double_sum(work1_n*(vv(i,k)-x(:,k)))*2.0
end do
end do

Pure Function double_sum(A)
real, intent(in) :: A(:)
real :: double_sum
real(kind(1d0)) :: total
integer :: i
total = 0d0
do i=1, size(A)
total = A(i) + total
end do
double_sum = total
end function double_sum
So if real,dimension(2,2) vv,dvv
real,dimension(8,2)x
How should work1_n be defined?

You did not should us sufficient information for us to
some place in your code for work1_n.  That declaration
is important.

--
steve

Ynks.
Well it has been defiened as allocatable,i am now attaching my code:
program pr1
use ds
implicit none
integer :: i,j,k,c,s,n_data
real,dimension(2) :: work_s
real,dimension(8,2) :: x
real,dimension(2,8) :: work_cn
real,dimension(8) :: work_n,work1_n
real,dimension(2,2) :: vv,dvv
real,dimension(4) :: dv,pp
n_data=8
s=2
c=2
open(10,file='a.dat',status='old')
open(11,file='b.dat',status='old')

do k=1,n_data
end do

vv = reshape(pp, (/ c, s /))
do i = 1, c
do k = 1, n_data
work_s = vv(i,:) - x(k,:)
work_cn(i,k) = 1.0/dot_product(work_s, work_s)
end do
end do
do k=1,n_data
work_n(k) = double_sum(work_cn(:,k))
end do
do i = 1, c
work1_n = (work_cn(i,:)/work_n)**2
do k=1,s
dvv(i,k) = double_sum(work1_n*(vv(i,k)-x(:,k)))*2.0
end do
end do
dv = reshape(dvv, (/ c*s /))
write(*,*)dv
end program
I get this:
forrtl: severe (408): fort: (2): Subscript #2 of the array VV has
value 3 which is greater than the upper bound of 2
.