Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transforming part of matlab code to Fortran90 (my errors include “Unclassifiable statement” etc.)

Status
Not open for further replies.

ianchenmu

Technical User
Jul 6, 2016
3
US
Here are my Fortran codes:

Code:
program test
implicit none

integer*4 nxProjPad, cf, numViews, cc, index, indRad, iv, i, INDEX1, d, n
real*4 v4, v5, SS, SS1, RSS, S1, F1, gMDL

real*4, dimension(:), allocatable :: array, sum, cumsum, transpose, log

nxProjPad=185
numViews=180

allocate(array(numViews*nxProjPad))

v4 = 0.
v5 = 0.
SS = 0.
cc = 5.

indRad = 1
index = 1

cf = NINT(nxProjPad/2.)

do  iv = 1, numViews
do i = 1, nxProjPad
v4 = v4 + array(index)

v5 = v5 + array(indRad)
SS = SS + (array(index))**2

indRad = indRad + 1

index = index + 1
enddo
enddo

SS1 = SS(1:cf-cc)
SS1 = SS1 + SS(ubound(SS1):cf+cc)

CALL KB08AD( SS1, nxProjPad, INDEX1 )

SSs = SS1
d = size(SSs)
n = nxProjPad

RSS = (sum(SSs(1:ubound(SSs)))-cumsum(transpose(SSs))))/numViews
S1  = RSS / (n-2*(1:d))
F1  = (cumsum(transpose(SSs))/numViews) / (2*(1:d)*S1)
gMDL = log(S1) + 0.5*((1:d)/n)*log(F1)

do  iv = 1, numViews
array(cc-1+INDEX1(d+1:ubound(INDEX1))) = 0
array(size(C, 1)-cc-INDEX1(d+1:ubound(INDEX1))) = 0
enddo

deallocate(array)
end program test


And it is transformed from this short matlab code:
Code:
cf = round(size(C, 1)/2);
SS = sum(abs(C).^2, 2);

cc  = 5;
SS1 = SS(1:cf-cc);
SS1 = SS1 + SS(end:-1:cf+cc);

[SSs,id] = sort(SS1, 'descend'); 

d       = length(SSs);
n       = size(y, 1);

RSS = (sum(SSs) - cumsum(SSs'))/length(theta);
S1  = RSS ./ (n-2*(1:d));
F1  = (cumsum(SSs')/length(theta)) ./ (2*(1:d).*S1);
gMDL = log(S1) + 0.5*((1:d)/n).*log(F1);
[~, d] = min(gMDL(1:round(d/2)));

C1(cc-1+id(d+1:end), :) = 0; 
C1(size(C, 1)-cc-id(d+1:end), :) = 0;

The errors I got are:
Code:
test.f90:44:0:

 SS1 = SS(1:cf-cc)
 1
Error: Unclassifiable statement at (1)
test.f90:45:0:

 SS1 = SS1 + SS(ubound(SS1):cf+cc)
 1
Error: Unclassifiable statement at (1)
test.f90:53:14:

 RSS = (sum(SSs(1:ubound(SSs)))-cumsum(transpose(SSs))))/numViews
          1
Error: Invalid form of array reference at (1)
test.f90:54:19: Error: Expected a right parenthesis in expression at (1)
test.f90:55:47: Error: Expected a right parenthesis in expression at (1)
test.f90:56:24: Error: Expected a right parenthesis in expression at (1)
test.f90:59:21: Error: Syntax error in argument list at (1)
test.f90:60:30: Error: Syntax error in argument list at (1)
test.f90:49:3:

 SSs = SS1
   1
Error: Symbol ‘sss’ at (1) has no IMPLICIT type


I think you can notice which parts I am trying to transform. So how should I make my Fortran code correct and the same functionality as in matlab?

Any suggestion or answer, even corrections are welcome!
 
What is SS1 meant to be in matlab: a value or an array?

What does this statement do in matlab?
Code:
SS1 = SS(1:cf-cc)
Does it sum up all the values in SS between 1 and cf-cc and put it in SS1?
 
SS1 is an array and it is an array made of the first 1 to cf-cc value from SS (SS is also an array).
 
Anything that is an array has to be declared as an array. The compiler is complaining because you are assigning an array to a variable. You will probably need to make it allocatable and allocate size cf-cc.
 
Can you help me make corrections on my codes? Thank you!!
 
Basically, all you need to do is to declare the arrays as allocatable arrays: not as real*4. Allocate them to whatever size you deem necessary and that's about it.

I have no idea what
Code:
RSS = (sum(SSs(1:ubound(SSs)))-cumsum(transpose(SSs))))/numViews
is meant to do. transpose has been declared as an array but SSs hasn't. This has to be broken down into more steps - you can't use a real as an index to an array.

Note that in Fortran, there are functions called sum and transpose and they do not return arrays.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top