## 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:

And it is transformed from this short matlab code:

The errors I got are:

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!

#### 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!

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

What does this statement do in matlab?

## CODE

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

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

I have no idea what

## CODE

Note that in Fortran, there are functions called sum and transpose and they do not return arrays.