GOTO Question
Author Message
GOTO Question

Hi, all.

I am no fortran expert, but I thought I had a pretty good grasp of the
language. However, I recently came across a line of code that has me

I am trying to translate a LAPACK routine (ILAENV) into "C".

One of the parameters passed into ILAENV is named ISPEC, which had been
assigned the value 1 by the program calling ILAENV.

One of the first executable statements within ILAENV is the following
line:

GO TO ( 100, 100, 100, 400, 500, 600, 700, 800, 900, 1000,
\$        1100 ) ISPEC

(Remember: ISPEC = 1) Somebody please tell me what this line does. I
have seen GOTO statements before with three entries, that depend upon
whether or not a variable is less than, equal to, or greater than 0.
However, this is the first time I have seen a GOTO statement with 11
jump points within it. How are conditions determined? And why is the
"100" jump point repeated three times?

(Unfortunately, I donated all my FORTRAN textbooks from my college days
to the local library).

Michael

Tue, 22 Jul 2008 01:15:59 GMT
GOTO Question
Hello,

<snip>

Quote:
> One of the first executable statements within ILAENV is the following
> line:

> GO TO ( 100, 100, 100, 400, 500, 600, 700, 800, 900, 1000,
>      \$        1100 ) ISPEC

> (Remember: ISPEC = 1) Somebody please tell me what this line does. I
> have seen GOTO statements before with three entries, that depend upon
> whether or not a variable is less than, equal to, or greater than 0.
> However, this is the first time I have seen a GOTO statement with 11
> jump points within it. How are conditions determined? And why is the
> "100" jump point repeated three times?

This is a depreciated "computed goto" with meaning

if( ispec == 1) goto 100
if( ispec == 2) goto 100
if( ispec == 3) goto 100
if( ispec == 4) goto 400
...
if( ispec == 11) goto 1100

<snip>

It may be translated into a C switch,
or maybe not, depending upon how much jumping
happens after the labels above.

HTH

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.

Tue, 22 Jul 2008 01:24:27 GMT
GOTO Question

Quote:

> Hi, all.

> I am no FORTRAN expert, but I thought I had a pretty good grasp of the
> language. However, I recently came across a line of code that has me

> I am trying to translate a LAPACK routine (ILAENV) into "C".

> One of the parameters passed into ILAENV is named ISPEC, which had been
> assigned the value 1 by the program calling ILAENV.

> One of the first executable statements within ILAENV is the following
> line:

> GO TO ( 100, 100, 100, 400, 500, 600, 700, 800, 900, 1000,
>      \$        1100 ) ISPEC

This is called a "computed goto".  It examines the
value of ISPEC, call it "N", and goes to the Nth statement
label in the sequence.  If N is 1, 2, or 3, it will jump to
100, 4 goes to 400, ... 11 goes to 1100.  If N < 1 or
greater than > 11, the statement acts as a do nothing
and falls through to the next statement.  There's no
requirement that the statement labels have a relation to
ISPEC, the last label could as well have been 41936,
although that's maybe not as self documenting ;).

The three way "GOTO" you remember is actually a three
way IF statement.  The syntax is
IF( expression) 1,2,3
it will jump to 1 if the expression is < 0, 2 if it
is exactly 0, and 3 if it is > 0.  Again, the actual labels
are arbitrary.  You'd often see
IF (expression) 1,1,2
as a way to do   expression <= 0, etc.

It's hard to say why the 100 is repeated 3 times.  It covers
the cases where ISPEC is either 1, 2, or 3.  It really was
the programmers choice, there's nothing in the language
syntax that requires this.

Dick Hendrickson

- Show quoted text -

Quote:

> (Remember: ISPEC = 1) Somebody please tell me what this line does. I
> have seen GOTO statements before with three entries, that depend upon
> whether or not a variable is less than, equal to, or greater than 0.
> However, this is the first time I have seen a GOTO statement with 11
> jump points within it. How are conditions determined? And why is the
> "100" jump point repeated three times?

> (Unfortunately, I donated all my FORTRAN textbooks from my college days
> to the local library).

> Michael

Tue, 22 Jul 2008 01:28:05 GMT
GOTO Question

Quote:

> Hi, all.

> I am no FORTRAN expert, but I thought I had a pretty good grasp of the
> language. However, I recently came across a line of code that has me

> I am trying to translate a LAPACK routine (ILAENV) into "C".

> One of the parameters passed into ILAENV is named ISPEC, which had been
> assigned the value 1 by the program calling ILAENV.

> One of the first executable statements within ILAENV is the following
> line:

> GO TO ( 100, 100, 100, 400, 500, 600, 700, 800, 900, 1000,
>      \$        1100 ) ISPEC

> (Remember: ISPEC = 1) Somebody please tell me what this line does. I
> have seen GOTO statements before with three entries, that depend upon
> whether or not a variable is less than, equal to, or greater than 0.
> However, this is the first time I have seen a GOTO statement with 11
> jump points within it. How are conditions determined? And why is the
> "100" jump point repeated three times?

> (Unfortunately, I donated all my FORTRAN textbooks from my college days
> to the local library).

> Michael

The others have said most of it; I would merely add that there is an
optional comma after the close parenthesis.

Dave Flower

Tue, 22 Jul 2008 01:41:56 GMT
GOTO Question
Thank-you, all.

That clears things up.

-- Michael

Tue, 22 Jul 2008 06:16:07 GMT
GOTO Question

Quote:

> This is a depreciated "computed goto"...

where, to quibble standard-speak words, the formal term is "obsolescent"
instead of "deprecated". Early drafts of f90 also had a category of
deprecated features, but that category was deleted. (I was tempted to
say that deprecation was deprecated, but that would not be be quite
accurate; close though. :-))

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain

Tue, 22 Jul 2008 06:38:03 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages
 10. goto?