[comp.lang.fortran] insidious access violation

matthias@mpx2.lampf.lanl.gov (Matthias, Bjorn E.) (09/13/90)

Any suggestions to solve the following would be much appreciated:
In a medium sized piece of code (executable of about 200 blocks)
there is a very simple subroutine that I put in to cause things to wait
until <RETURN> is hit; this to allow looking at a plot on the screen.

	subroutine look
	character*1 answ
	write(6,'(/,/,''$Hit <RETURN> to continue ...'')')
	read(5,'(a)') answ
	return
	end

SOMETIMES the READ statement bombs with an access violation, sometimes not.
I'm stumped.  Ideas?
Thanks very much in advance!

---
Bjorn E. Matthias                       MATTHIAS@LAMPF  (BITNET)
    matthias@mpx0.lampf.lanl.gov  or  matthias@mpx1.lampf.lanl.gov (internet)

BOYDJ@QUCDN.QueensU.CA (Jeff Boyd) (09/13/90)

Have you tried using the PAUSE statement ?
Eg.

       PAUSE 'Press ENTER to continue'

If your Fortran supports PAUSE, the action is to suspend the program
until the console receives a carriage return. The message is optional,
and is written to the console screen.

matthias@mpx2.lampf.lanl.gov (Matthias, Bjorn E.) (09/13/90)

In article <62748@lanl.gov>, matthias@mpx2.lampf.lanl.gov I wrote :
#SOMETIMES the READ statement bombs with an access violation, sometimes not.

I apologize to everyone for forgetting to add that I am using VAX FORTRAN
under VMS 5.2.

---
Bjorn E. Matthias                       MATTHIAS@LAMPF  (BITNET)
    matthias@mpx0.lampf.lanl.gov  or  matthias@mpx1.lampf.lanl.gov (internet)

matthias@mpx2.lampf.lanl.gov (Matthias, Bjorn E.) (09/15/90)

In article <62855@lanl.gov>, matthias@mpx2.lampf.lanl.gov , I wrote
##SOMETIMES the READ statement bombs with an access violation, sometimes not.

The trouble turned out to be addressing an array out of bounds in the routine
just before.  "Elementary, my dear Watson."
Sorry for troubling you all with this, and thanks to all who responded: you
did help me solve this quickly!
Regards,
---
Bjorn E. Matthias                       MATTHIAS@LAMPF  (BITNET)
    matthias@mpx0.lampf.lanl.gov  or  matthias@mpx1.lampf.lanl.gov (internet)

bam@bnlux0.bnl.gov (Bruce A. Martin) (09/19/90)

In article <90256.090818BOYDJ@QUCDN.BITNET> BOYDJ@QUCDN.QueensU.CA (Jeff Boyd) writes:
>
>Have you tried using the PAUSE statement ?
>Eg.
>
>       PAUSE 'Press ENTER to continue'
>
>If your Fortran supports PAUSE, the action is to suspend the program
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>until the console receives a carriage return. The message is optional,
	   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>and is written to the console screen.
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

First of all, all Fortrans support PAUSE.  
If it don't do PAUSE then it ain't Fortran.

However, I disagree with this advice because:

	1.  The standard does NOT say that the PAUSE message
	is "written to the console screen" and you cannot count
	on this behavior (particularly on systems which have
	no such thing as a "console").  

	2.  On some processors (e.g. Control Data), the PAUSE
	message will go to the operator who probably will not
	know what to do with it.  Even if the Fortran program 
	was running interactively at a terminal, some systems
	use PAUSE to contact the operator (for tape hanging,
	checkpointing, shutdowns, etc.) and the terminal user
	doesn't see it!

	3.  Processors also vary as to how the paused job is resumed.
	A "carriage return" from the console does not necessarily
	resume the job.  (Some processors require a specific
	command to resume.)
	
	4.  In fact, the standard is deliberately vague as to
	what happens to the optional stuff following the keyword
	of a STOP or PAUSE statement.  Sections 11.12 and 11.13
	merely say that the stuff is "accessible".  Section notes
	(Appendx B) says that some processors use it for documentation
	only while others display or record it.

	5.  Fortran 90 designates PAUSE as an "obsolescent" feature,
	and it will probably be deleted in future revisions (since
	nobody supports its preservation (other than for convenience
	in using existing code).

	6.  The POSIX Fortran binding provides portable equivalent
	functionality via system calls whose effects are defined
	consistently across implementations.  Other systems do
	likewise.  Altho the use of a system call may not be portable
	to a different system, at least its effects are well defined
	and it will probably work in a predictable way or not at all.
	This is not true of PAUSE.

	7.  If you have standard input and standard output (or 
	whatever your system calls them) connected to keyboard and
	screen, then the WRITE/READ sequence of the original posting
	will work just fine.

There are probably a few more good reasons to avoid the PAUSE statement,
but I've already beaten the deprecated thing to death so I think I'd better
CALL EXIT;
STOP 'already';
END
_______________________

BAM		     			     -/s/-
    (bam@bnlux0.bnl.gov)		 Bruce A. Martin	
[Address given for identification only.] Grumman Space Systems
[Every conceivable disclaimer applies!!] c/o National Synchrotron Light Source
[Opinions are mine only, & will change,] Bldg. 725C, Brookhaven National Lab. 
[without notice, whenever appropriate!!] Upton, NY  11973	(516) 282-3712	
     
[DISCLAIMER:  The statements made herein do not necessarily reflect those of 
any other individual, group, organization, corporation, or government agency.  
My work on X3J3 does not in any way represent official policies or positions
of my past or present employers nor those of any other sponsor or affiliate.]