×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

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

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

(OP)
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

numViews=180

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

index = 1

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

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

index = index + 1
enddo
enddo

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

SSs = SS1
d = size(SSs)

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);

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:

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!

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

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?

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

(OP)
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).

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

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.

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

(OP)
Can you help me make corrections on my codes? Thank you!!

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

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.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!