I am working on a project to convert a large Fortran77 code into MATLAB. Since Do loops in F77 are equivalent to For loops in MATLAB, a subroutine of F77 when translated into MATLAB is giving error. The F77 subroutine is given in link and my tried MATLAB translated version is as follows
G(1)=1.0;
NH=NS/2;
for i=2:NS
G(i)=G(i-1)*i;
end
HS(1)=2.0/G(NH-1);
for i = 2:NH
FI=i;
if i== NH
HS(i)=FI^(NH)*G(2*i)/(G(i)*G(i-1));
end
HS(i)=FI^(NH)*G(2*i)/(G(NH-i)*G(i)*G(i-1));
end
SN=2*(NH-NH/2*2)-1;
for i=1:NS
V(i)=0.0;
K1=(i+1)/2;
K2=i
if K2 > NH
K2 = NH;
end
for j=K1:K2
if 2*j-i == 0
V(i)=V(i)+HS(j)/(G(i-j));
elseif i == j
V(i)=V(i)+HS(j)/G(2*j-i);
end
end
V(i)=SN*V(i);
SN=-SN;
end
which is giving following error
Attempted to access G(0); index must be a positive integer or logical
HS(i)=FI^(NH)*G(2*i)/(G(NH-i)*G(i)*G(i-1));
I think I am unable to understand complex loop structure present in subroutine of Fortran77.
http://hostcode.sourceforge.net/view/5499