Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fortran to matlab

Subject: fortran to matlab

From: Marios Karaoulis

Date: 3 Nov, 2010 23:24:04

Message: 1 of 13

I can't understand how to transform the "go to" command in matlab.
When if conditions is true, it goes to line 7. Then the inner do loop is calculated again?
How can I do this in matlab?


  do 8 i=1,num_ebc
           .......
              do 7 j=1,num_nodes
                  if ( j.eq.nd(i) ) go to 7
                     .......
7 continue
8 continue

Subject: fortran to matlab

From: dpb

Date: 3 Nov, 2010 23:49:35

Message: 2 of 13

Marios Karaoulis wrote:
> I can't understand how to transform the "go to" command in matlab.
> When if conditions is true, it goes to line 7. Then the inner do loop is
> calculated again?
> How can I do this in matlab?
>
> do 8 i=1,num_ebc
> .......
> do 7 j=1,num_nodes
> if ( j.eq.nd(i) ) go to 7
> .......
> 7 continue
> 8 continue

Straight translation would be

if j == nd(i), continue, end

Of course, in Matlab, one would look at the contents of the loops and
see if vectorization is possible...

--

Subject: fortran to matlab

From: Marios Karaoulis

Date: 4 Nov, 2010 00:19:18

Message: 3 of 13

But if the if statement is correct, then this mean it is done with the
inner loop?

Subject: fortran to matlab

From: James Tursa

Date: 4 Nov, 2010 00:42:03

Message: 4 of 13

Marios Karaoulis <marios.karaoulis@gmail.com> wrote in message <0591b0d3-f8fa-4395-9abe-eb4c193adb3d@w38g2000pri.googlegroups.com>...
> But if the if statement is correct, then this mean it is done with the
> inner loop?

Yes. Since 7 is the ending statement of the do loop, goto 7 means skip to the end of the loop and then do the next iteration of the same loop. It does not mean get out of the inner loop.

James Tursa

Subject: fortran to matlab

From: Walter Roberson

Date: 4 Nov, 2010 00:44:14

Message: 5 of 13

On 03/11/10 7:19 PM, Marios Karaoulis wrote:
> But if the if statement is correct, then this mean it is done with the
> inner loop?

No, in Fortran if you GOTO a label that is the label associated with the
DO loop, then the loop is to continue from the beginning of the next
iteration. In Fortran, if you wanted to escape the loop, you could GOTO
a label that was outside the loop.

Subject: fortran to matlab

From: Marios Karaoulis

Date: 4 Nov, 2010 01:16:04

Message: 6 of 13

If I use Walter edition, I get reasonable results. If I use James edition I do not.
But I can't be sure if this is the problem or somewhere else.

I tried to use f2c (fortran to c converter, but it doesn't work).
I can't even find a fortran 77 compiler.

I would appreciate a more positive answer on this.

Subject: fortran to matlab

From: dpb

Date: 4 Nov, 2010 01:22:38

Message: 7 of 13

Marios Karaoulis wrote:
> But if the if statement is correct, then this mean it is done with the
> inner loop?

No, that would be BREAK...

doc continue
doc break

Or, if you mean the interpretation of the Fortran code, the GOTO doesn't
terminate the DO loop, merely skips the intervening code from the
location of the test to the target line. The CONTINUE is still in the
scope of the relative DO.

--

Subject: fortran to matlab

From: dpb

Date: 4 Nov, 2010 01:29:11

Message: 8 of 13

Marios Karaoulis wrote:
> If I use Walter edition, I get reasonable results. If I use James
> edition I do not. But I can't be sure if this is the problem or
> somewhere else.
>
> I tried to use f2c (fortran to c converter, but it doesn't work).
> I can't even find a fortran 77 compiler.
> I would appreciate a more positive answer on this.

Both Walter and James (and I) said the identical thing, just phrased it
differently (and we're all positive on the interpretation :) ).

If there's something unexpected, it's not in that, assuming the code
snippet pasted is correct.

F95+ compilers are still F77 compilers; it's the beauty of Fortran
stability. Other than a few very arcane features (which most compilers
still support, anyway), F95 is a superset of F77.

There are various compilers available.

--

Subject: fortran to matlab

From: Marios Karaoulis

Date: 4 Nov, 2010 02:11:03

Message: 9 of 13

so if I write it like this in matlab, it is ok?

  for i=1:num_ebc
           .......
              for j=1:num_nodes
                  if j~=nd(i)
                     .......
                  end
              end
  end

Subject: fortran to matlab

From: dpb

Date: 4 Nov, 2010 04:04:01

Message: 10 of 13

Marios Karaoulis wrote:
> so if I write it like this in matlab, it is ok?
>
> for i=1:num_ebc
> .......
> for j=1:num_nodes
> if j~=nd(i)

Excepting for leaving out the "continue" statement to duplicate the
action of the GOTO...

> continue
          ......
> end
> end
> end

It's neater given the intent to write as I did earlier..

if j == nd(i), continue, end

the replacement for the Fortran idiom

if(j.eq.nd(i)) goto 7

--

Subject: fortran to matlab

From: benbarrowes

Date: 5 Nov, 2010 00:13:20

Message: 11 of 13

On Nov 3, 10:11 pm, "Marios Karaoulis" <marios_hellas...@yahoo.gr>
wrote:
> so if I write it like this in matlab, it is ok?
>
>   for  i=1:num_ebc
>            .......
>               for j=1:num_nodes
>                   if j~=nd(i)
>                      .......
>                   end
>               end
>   end

If you have a lot of fortran you want to translate into matlab,
f2matlab can help:
http://www.mathworks.com/matlabcentral/fileexchange/5260
You would need to convert the f77 code to more modern f90 style, then
use f2matlab. It usually does >90% of the work for you.

Subject: fortran to matlab

From: Geico Caveman

Date: 5 Nov, 2010 01:08:48

Message: 12 of 13

On 2010-11-03 18:49:35 -0500, dpb <none@non.net> said:

> Marios Karaoulis wrote:
>> I can't understand how to transform the "go to" command in matlab.
>> When if conditions is true, it goes to line 7. Then the inner do loop
>> is calculated again?
>> How can I do this in matlab?
>>
>> do 8 i=1,num_ebc
>> .......
>> do 7 j=1,num_nodes
>> if ( j.eq.nd(i) ) go to 7
>> .......
>> 7 continue
>> 8 continue
>
> Straight translation would be
>
> if j == nd(i), continue, end
>
> Of course, in Matlab, one would look at the contents of the loops and
> see if vectorization is possible...

As would one in Fortran 95+

Subject: fortran to matlab

From: dpb

Date: 5 Nov, 2010 04:00:19

Message: 13 of 13

Geico Caveman wrote:
> On 2010-11-03 18:49:35 -0500, dpb <none@non.net> said:
>
...

>> Of course, in Matlab, one would look at the contents of the loops and
>> see if vectorization is possible...
>
> As would one in Fortran 95+

But the difference in performance is unlikely to be as worthwhile (and,
depending on what it takes to do so, can be degraded by nonjudicious
choices)...

Saving lines of source code simply for the purpose of doing that isn't
much of a winner in F90+ vis a vis Matlab where it translates generally
to more use of compiled as opposed to interpreted code.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us