A strange DO loop problem ... 
Author Message
 A strange DO loop problem ...

Hi,

This question pertains to VAX fortran V 5.5-2.
While running a program I encountered the following problem.
The program simply refuses to read/execute all the statements
within a DO loop. For example,

        ....
        open (unit=1, file='file.dat', status='unknown')
        type *, 'test 1'

        do j = 1, 3
                type *, 'test 2'
        enddo
        type *, 'test 3'

        close (1)
        .....

'test 1' and 'test 3' are seen on the screen but not 'test 2'.
No matter what statements I include in the do loop, they get
ignored. Initially, I wanted to write something onto the file
that I opened, but the program was not writing it. So, I tested with
some screen-output messages, which were not seen either.

I tried various things, but could not understand what is going
on. Is there anything that is obvious to somebody, that I am
missing ? Or have anyone faced such problems before ? I have
similar do loop structures elsewhere in the program which do
not have any problem. Only in couple of loops I have this problem.
Ideas, anyone ?

Thanks for any help

Selvaraj.

07 Mar 95.
--
University of Louisville



Sun, 24 Aug 1997 04:54:47 GMT  
 A strange DO loop problem ...



Quote:
> |>
> |> Hi,
> |>
> |> This question pertains to VAX Fortran V 5.5-2.
> |> While running a program I encountered the following problem.
> |> The program simply refuses to read/execute all the statements
> |> within a DO loop. For example,
> |>
> |>      ....
> |>      open (unit=1, file='file.dat', status='unknown')
> |>      type *, 'test 1'
> |>
> |>      do j = 1, 3
> |>              type *, 'test 2'
> |>      enddo
> |>      type *, 'test 3'
> |>
> |>      close (1)
> |>      .....
> |>
> |> 'test 1' and 'test 3' are seen on the screen but not 'test 2'.
> |> No matter what statements I include in the do loop, they get
> |> ignored. Initially, I wanted to write something onto the file
> |> that I opened, but the program was not writing it. So, I tested with
> |> some screen-output messages, which were not seen either.

        It would have helped to have a complete program, but observe the
    following:
-------------------------------------------------------------------------
$ type test.for
        open (unit=1, file='file.dat', status='unknown')
        type *, 'test 1'

        do j = 1, 3
                type *, 'test 2'
        enddo
        type *, 'test 3'

        close (1)
        end
$ fort test
$ link test
$ run test
test 1
test 2
test 2
test 2
test 3
$
-------------------------------------------------------------------------

Quote:
> |> I tried various things, but could not understand what is going
> |> on. Is there anything that is obvious to somebody, that I am
> |> missing ? Or have anyone faced such problems before ? I have
> |> similar do loop structures elsewhere in the program which do
> |> not have any problem. Only in couple of loops I have this problem.
> |> Ideas, anyone ?

        Check for logical name definitions that you hadn't thought about
    (a re-definition of SYS$OUTPUT or TT  for example).  But it would be
    best to post a complete program that demonstrates the problem, along
    with  the compiler version.  My tests were done on VMS 6.0 with  VAX
    Fortran V5.8-155, but I'm confident  I'd  get  the  same  result  on
    earlier and later versions of both the o/s and the compiler...

Quote:
> You might see if you have inadventently redifined the constant "3" or "1" to
> be some other number.  This can easily be done if you pass the constant
> as a subroutine argument, then the called subroutine changes the value.

        Can't happen on the VAX (really VMS) since the constants are put
    in a READ ONLY psect (program section) and an attempt to modify them
    will result in an "access violation", i.e., a program crash...

        -Ken
--

 SLAC, P.O.Box 4349, MS 46  |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
 Stanford, CA   94309       |  Voice:    415-926-2924    FAX: 415-926-3515
 -------------------------------------------------------------------------
 These opinions are mine, not SLAC's, Stanford's, nor the DOE's...



Sun, 24 Aug 1997 06:09:16 GMT  
 A strange DO loop problem ...

|>
|> Hi,
|>
|> This question pertains to VAX Fortran V 5.5-2.
|> While running a program I encountered the following problem.
|> The program simply refuses to read/execute all the statements
|> within a DO loop. For example,
|>
|>   ....
|>   open (unit=1, file='file.dat', status='unknown')
|>   type *, 'test 1'
|>
|>   do j = 1, 3
|>           type *, 'test 2'
|>   enddo
|>   type *, 'test 3'
|>
|>   close (1)
|>   .....
|>
|> 'test 1' and 'test 3' are seen on the screen but not 'test 2'.
|> No matter what statements I include in the do loop, they get
|> ignored. Initially, I wanted to write something onto the file
|> that I opened, but the program was not writing it. So, I tested with
|> some screen-output messages, which were not seen either.
|>
|> I tried various things, but could not understand what is going
|> on. Is there anything that is obvious to somebody, that I am
|> missing ? Or have anyone faced such problems before ? I have
|> similar do loop structures elsewhere in the program which do
|> not have any problem. Only in couple of loops I have this problem.
|> Ideas, anyone ?
|>
|> Thanks for any help
|>
|> Selvaraj.
|>
|> 07 Mar 95.
|> --
|> University of Louisville

You might see if you have inadventently redifined the constant "3" or "1" to
be some other number.  This can easily be done if you pass the constant
as a subroutine argument, then the called subroutine changes the value.

The compiler really generates a variable, and gives it the initial value
of "1" or "3", but it can be changed just like any other variable.

Try passing the conmstants '1' and '3' to a subroutine just before the loop
then look what they really are in the called routine.



Sun, 24 Aug 1997 05:05:46 GMT  
 A strange DO loop problem ...

Quote:
>    Thanks to Greg and Ken. I was able to resolve the above
>    problem. It was again a inadvertant error (silly mistake!).

>    I had the DO loop structured as

>            do j = 1, rr
>            ...
>            enddo

>    I was passing the value of rr (=3) through a COMMON statement
>    to the subroutine. But I did not declare it to be an integer.
>    In MAIN the variable 'rr' was an integer and in the subroutine
>    it was real since I did not declare it. So, it was taking a
>    value of 0.000. So, it was skipping the DO loop.

Very nice example for those who think that the implicit typing system
of Fortran is a good thing :-)

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Mon, 25 Aug 1997 01:04:38 GMT  
 A strange DO loop problem ...


|>This question pertains to VAX Fortran V 5.5-2.
|>While running a program I encountered the following problem.
|>The program simply refuses to read/execute all the statements
|>within a DO loop. For example,
[snip]

I tried the excerpt you showed, and it worked as expected.  I suspect that
your real program has something else which you haven't shown here.  Feel
free to mail me an actual, compilable example and I'll be glad to look at it.
--


DEC Fortran Development           WWW:  http://www.digital.com/info/slionel.html
Digital Equipment Corporation     CompuServe: 75263,3001
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698             "Free advice is worth every cent"




Mon, 25 Aug 1997 03:25:12 GMT  
 A strange DO loop problem ...


writes:

|>
|>You might see if you have inadventently redifined the constant "3" or "1" to
|>be some other number.  This can easily be done if you pass the constant
|>as a subroutine argument, then the called subroutine changes the value.
|>
|>The compiler really generates a variable, and gives it the initial value
|>of "1" or "3", but it can be changed just like any other variable.

Maybe on some other systems, but not on VAX (which is what he was using).  
Constants are allocated in read-only storage and can't be modified.  In this
particular example, the constants are immediate operands in the instruction
stream and are read-only.
--


DEC Fortran Development           WWW:  http://www.digital.com/info/slionel.html
Digital Equipment Corporation     CompuServe: 75263,3001
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698             "Free advice is worth every cent"




Mon, 25 Aug 1997 05:35:59 GMT  
 A strange DO loop problem ...
----------------------

        Thanks to Greg and Ken. I was able to resolve the above
        problem. It was again a inadvertant error (silly mistake!).

        I had the DO loop structured as

                do j = 1, rr
                ...
                enddo

        I was passing the value of rr (=3) through a COMMON statement
        to the subroutine. But I did not declare it to be an integer.
        In MAIN the variable 'rr' was an integer and in the subroutine
        it was real since I did not declare it. So, it was taking a
        value of 0.000. So, it was skipping the DO loop.

        I have corrected this and now it is working fine. Thanks for
        the help.

Quote:
>        It would have helped to have a complete program, but observe the
>    following:

        Ken, I was not able to give the entire program, because this
        whole program is a subroutine called by the SPEEDUP modeling
        software. If you are familiar with this, I was trying to use
        the External Data Interchange (EDI) facility of SPEEDUP to link
        it with a Fortran subroutine.

        Selvaraj.
        08 Mar 95.

Quote:
>> You might see if you have inadventently redifined the constant "3" or "1" to
>> be some other number.  This can easily be done if you pass the constant
>> as a subroutine argument, then the called subroutine changes the value.
>        Can't happen on the VAX (really VMS) since the constants are put
>    in a READ ONLY psect (program section) and an attempt to modify them
>    will result in an "access violation", i.e., a program crash...
>        -Ken

--
University of Louisville


Sun, 24 Aug 1997 22:20:09 GMT  
 A strange DO loop problem ...

Quote:


>>        Thanks to Greg and Ken. I was able to resolve the above
>>        problem. It was again a inadvertant error (silly mistake!).

>>        I had the DO loop structured as

>>                do j = 1, rr
>>                ...
>>                enddo

>>        I was passing the value of rr (=3) through a COMMON statement
>>        to the subroutine. But I did not declare it to be an integer.
>>        In MAIN the variable 'rr' was an integer and in the subroutine
>>        it was real since I did not declare it. So, it was taking a
>>        value of 0.000. So, it was skipping the DO loop.

>Very nice example for those who think that the implicit typing system
>of Fortran is a good thing :-)

This is also an excellent example of when INCLUDE files should be used, rather
than simply cutting and pasting COMMON blocks. The type declarations can easily
be included in the INCLUDE file, thereby eliminating the problem. Of course, the
problem then arises that not all Fortran compilers handle INCLUDE files in the
same manner, but that's another thread. ;-).

Just my $0.02.

--
+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+
Ian Stevenson
Hibbitt, Karlsson & Sorensen, Inc. 1080 Main St.  Pawtucket, RI 02860

+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+



Tue, 26 Aug 1997 05:18:31 GMT  
 A strange DO loop problem ...


Quote:


>  (Selvaraj Ramasamy) writes:

> >>      Thanks to Greg and Ken. I was able to resolve the above
> >>      problem. It was again a inadvertant error (silly mistake!).

> >>      I had the DO loop structured as

> >>              do j = 1, rr
> >>              ...
> >>              enddo

> >>      I was passing the value of rr (=3) through a COMMON statement
> >>      to the subroutine. But I did not declare it to be an integer.
> >>      In MAIN the variable 'rr' was an integer and in the subroutine
> >>      it was real since I did not declare it. So, it was taking a
> >>      value of 0.000. So, it was skipping the DO loop.

> >Very nice example for those who think that the implicit typing system
> >of Fortran is a good thing :-)

> This is also an excellent example of when INCLUDE files should be used, rather
> than simply cutting and pasting COMMON blocks. The type declarations can
> easily be included in the INCLUDE file, thereby eliminating the problem.
> Of course, the problem then arises that not all Fortran compilers handle
> INCLUDE files in the same manner, but that's another thread. ;-).

> Just my $0.02.

And if your compiler doesn't support INCLUDE at all, you could always write
your own pre-processor :-)  Given the headache this sort of problem causes it
would be time well spent.

Robin.

--
Robin Wardle



Wed, 27 Aug 1997 10:03:32 GMT  
 A strange DO loop problem ...

Quote:

>This question pertains to VAX Fortran V 5.5-2.
>While running a program I encountered the following problem.
>The program simply refuses to read/execute all the statements
>within a DO loop. For example,

>       ....
>       open (unit=1, file='file.dat', status='unknown')
>       type *, 'test 1'

>       do j = 1, 3
>         type *, 'test 2'
>       enddo
>       type *, 'test 3'
>       ....
>'test 1' and 'test 3' are seen on the screen but not 'test 2'.
>I tried various things, but could not understand what is going on.
>Is there anything that is obvious to somebody, that I am missing ?
>Or have anyone faced such problems before ?
>I have similar do loop structures elsewhere in the program which do
>not have any problem. Only in couple of loops I have this problem.
>Ideas, anyone ?

If your program has (accidentally) over-written the word in storage
which contained the constant '3', and that new value is a non-positive integer,
then the contents of the 'DO' loop will be skipped.

Add:      call check(3)

right before the 'DO' statement,
and add these lines:

          subroutine check(k)
          write (*,*) 'check:', k
          end

into your source.  What does the 'WRITE' statement produce?



Mon, 08 Sep 1997 08:07:19 GMT  
 A strange DO loop problem ...


Quote:
(Melvin Klassen) writes:

|>If your program has (accidentally) over-written the word in storage
|>which contained the constant '3', and that new value is a non-positive integer,
|>then the contents of the 'DO' loop will be skipped.

The poster of the original inquiry indicated that VAX FORTRAN was being used.
VAX FORTRAN does not allow modification of constants in memory.

The thread is now several weeks old, but my recollection is that the posted
excerpt was not representative of the actual program and that the actual code
had a programming error.
--


DEC Fortran Development           WWW:  http://www.digital.com/info/slionel.html
Digital Equipment Corporation     CompuServe: 75263,3001
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698             "Free advice is worth every cent"




Mon, 08 Sep 1997 23:21:44 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Please take a look at this expect script doing in loop with error checking

2. Problem with loop inside other loop

3. Strange loop behaviour

4. strange rexx 'do' loop effect

5. a strange loop between proximity sensor and viewpoint.

6. Strange loop behaviour in g77

7. Optimizing a strange do loop

8. Strange "for" loop behavior

9. strange infinite loop in connect...

10. strange list.remove behaviour in loops

11. Doing assembly and really doing assembly

12. Doing assembly and really doing assembly

 

 
Powered by phpBB® Forum Software