[net.lang.f77] Internal READ Problems

jme@wdl1.UUCP (Joseph M. Earley) (03/20/84)

My 4.1 BSD documentation says that I can do an internal read.  The ANSI
standard says I can do an internal read.  So why does the following code
give me the following result?

	program test
	read ( unit='300 ', fmt='(bn,i4)', iostat=ierror ) ispeed
	if ( ierror .eq. 0 ) then
		write ( *, '(''ispeed = '',i6)' )  ispeed
	else
		write ( *, '(''ierror = '',i6)' )  ierror
	end if
	end

ierror =  20488


Why does the following change result in an error code so different from the 
first example?

	program test
	character buffer*4
	buffer = '300 '
	read ( unit=buffer, fmt='(bn,i4)', iostat=ierror ) ispeed
	if ( ierror .eq. 0 ) then
		write ( *, '(''ispeed = '',i6)' )  ispeed
	else
		write ( *, '(''ierror = '',i6)' )  ierror
	end if
	end

ierror =  30616




Thanks for any insite that may be provided.  Send your responses to me at...;
nah, what the heck, post your responses to net.lang.f77.  I feel like being
made a fool of in public.

Joe Earley, Ford Aerospace, Palo Alto

ARPA    jme@ford-wdl1
UUCP    ...!fortune!wdl1!jme

brown@kpno.UUCP (03/21/84)

   The default I/O library is rather buggy as I'm sure you are finding out.
The optional -lI77uc is much more predictable/bug free than the default.
We have gone so far to make -lI77uc the default f77 library here.  Dave
Wasley at Berkeley did a nice job.

>	program test
>	read ( unit='300 ', fmt='(bn,i4)', iostat=ierror ) ispeed
>	if ( ierror .eq. 0 ) then
>		write ( *, '(''ispeed = '',i6)' )  ispeed
>	else
>		write ( *, '(''ierror = '',i6)' )  ierror
>	end if
>	end
>
>ierror =  20488

If you use -lI77uc to load the I/O routines the example will work correctly,
ie.  the example will print "ispeed = 300"

>Why does the following change result in an error code so different from the 
>first example?
>
>	program test
>	character buffer*4
>	buffer = '300 '
>	read ( unit=buffer, fmt='(bn,i4)', iostat=ierror ) ispeed
>	if ( ierror .eq. 0 ) then
>		write ( *, '(''ispeed = '',i6)' )  ispeed
>	else
>		write ( *, '(''ierror = '',i6)' )  ierror
>	end if
>	end
>
>ierror =  30616

Using -lI77uc you get the same result as the previous example..."ispeed = 300"

	regards,
	Mike Brown	National Solar Observatory
			Tucson, Arizona			(602) 325-9249	

UUCP:	{akgua,allegra,arizona,decvax,hao,ihnp4,lbl-csam,
	 sdcarl,sdcsvax,seismo,trwspf,unc,utastronomy,ut-sally}	!kpno!brown
ARPA:	kpno!brown@LBL-CSAM.ARPA
CSNET:	brown@arizona

phipps@fortune.UUCP (Clay Phipps) (03/29/84)

To paraphrase from the FORTRAN 77 standard,
a unit for an internal file must take the form of 
a character variable, a character array element, a character substring,
or a character array which represents the internal file.

Note that there is no mention of character literals,
which is what was used in the first example in the original posting.
The second example does use a character variable;
predictably enough, that is the example that "works"
(I'm not convinced that it does what it should, by the way).

-- Clay Phipps

-- 
   {allegra  amd70  cbosgd  decwrl!amd70  harpo  hplabs!hpda  
    ihnp4  megatest  nsc  oliveb  sri-unix  ucbvax!amd70  varian}
   !fortune!phipps