Here are my Fortran codes:(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):

program test

implicitnone

integer*4 nxProjPad, cf, numViews, cc, index, indRad, iv, i, INDEX1, d, n

real*4 v4, v5, RSS, S1, F1, gMDL

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

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)

endprogram test

And it is transformed from this short matlab code:

Code (Text):

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 (Text):

test.f90:37:0:

SS1 = SS(1:cf-cc)

1

Error: Unclassifiable statement at (1)

test.f90:38:0:

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

1

Error: Unclassifiable statement at (1)

test.f90:46:0:

RSS = (sum(SSs(1:ubound(SSs)))-cumsum(transpose(SSs))))/numViews

1

Error: Unclassifiable statement at (1)

test.f90:47:19: Error: Expected a right parenthesis in expression at (1)

test.f90:48:47: Error: Expected a right parenthesis in expression at (1)

test.f90:49:24: Error: Expected a right parenthesis in expression at (1)

test.f90:52:21: Error: Syntax error in argument list at (1)

test.f90:53:30: Error: Syntax error in argument list at (1)

test.f90:16:2:

SS = 0.

1

Error: Symbol ‘ss’ 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 corrections are welcome!

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Transforming part of matlab code to Fortran90

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads for Transforming part matlab |
---|

Binary bitstream from QPSK with MATLAB? |

Python How can I run Python by getting values from Matlab |

C/++/# Is Pass-by-Reference part of a Function Signature? |

Python Fit_transform() vs. transform() |

Discrete Fast Fourier transform with FFTW in FORTRAN77 |

**Physics Forums | Science Articles, Homework Help, Discussion**