Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: Distingui**...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 15 Topic 8159 of 8774
Post > Topic >>

Re: Distingui****ng between characters and numbers

by Dick Hendrickson <dick.hendrickson@[EMAIL PROTECTED] > Apr 22, 2008 at 12:42 PM

SimonG wrote:
> On Apr 22, 10:12 am, "FX" <coud...@[EMAIL PROTECTED]
> wrote:
>>> I expected the Intel result but perhaps the standard is ambiguous on
>>> this. Is this a g95 bug?
>> I'd have the same expectation that you have, so I guess there's a
>> bugre****t to make (or at least feature request, as lots of other
>> compilers behave the other way).
>>
>>> A second question: how do I enter a '/' character?
>> Well, you have a .co.uk address, so the '/' key should be on the left
of
>> your right ****ft key ;-)
>>
>> Hum, more seriously, you need to change your read's into:
>>
>>      read(5,'(a)') buff
>>      read(buff,'(f20.0)',err=900) x
>>
>> (Oh, and doing that fixes the issue with g95, apparently.)
>>
>> --
>> FX
> 
> Yes, making that change does alter the behaviour - the g95 version
> works as required but the Intel version now interprets '+' as a number
> (as well as '.', ',' and '-'): is that an Intel bug?
> 
> In fact for read(buff,'(f10.0)',err=900) x
> 
> input     g95                     ifort
> +         Command:+               Number:        0.
> -         Command:-               Number:        0.
> *         Command:*               Command:*
> /         Command:/               Command:/
> .         Command:.               Number:        0.
> ,         Command:,               Number:        0.
> 
> 
> and for read(buff,*,err=900) x
> 
> input     g95                     ifort
> +         Number:        0.       Command:+
> -         Number:       -0.       Command:-
> *         Command:*               Command:*
> /         Number:       -0.       Number:        0.
> .         Number:        0.       Command:.
> ,         Number:        0.       Number:        0.
> 
> 
> program ex
>   implicit none
>   real(8) :: x
>   integer :: n, ios
>   character(10) :: buff
> 
>   do
>      write(6,'(a)',advance='no') '> '
>      read(5,'(a10)') buff
>      read(buff,*,err=900) x !!! or read(buff,*,err=900) x
>      write(6,'(a,f10.0)') 'Number:',x
>      cycle
> 900  continue
>      write(6,'(2a)') 'Command:',trim(buff)
> 
>   end do
> 
> end program ex
> 
> 
> So what is the correct behaviour, surely they can't both be right.
> 
> 
> Simon Geard
I believe a plus or minus sign that is not followed by some
digits is an error.

10.6.1.2.1 F editing says
"The input field is either an IEEE exceptional specification or
consists of an optional sign, followed by a string of one or
more digits optionally containing a decimal symbol, including
any blanks interpreted as zeros."

10.9.1 List directed input says
"Input forms acceptable to edit descriptors for a given type are
acceptable for list-directed formatting...."

You need a digit after the sign for it to be suitable for either
F or * input.

Unfortunately, the standard is pretty weak on specifying what is
an error.  There is no list of conditions that require the ERR=
branch to be taken.  In fact, 9.10 Error, end-of-record, and
end-of-file conditions says
"The set of input/output error conditions is processor dependent."

It's arguably standard conforming for a processor to not re****t an
error and instead do [what it thinks is] the right thing.

Think about using the INDEX intrinsic to check for digits in buff,
or compare something like ADJUSTL(TRIM(BUFF)) with "+" rather
than relying on the read statement to detect the right kind of
thing.

Dick Hendrickson
 




 15 Posts in Topic:
Distinguishing between characters and numbers
SimonG <simon@[EMAIL P  2008-04-22 01:53:23 
Re: Distinguishing between characters and numbers
Arjen Markus <arjen.ma  2008-04-22 02:06:39 
Re: Distinguishing between characters and numbers
fj <francois.jacq@[EMA  2008-04-22 02:07:06 
Re: Distinguishing between characters and numbers
"FX" <couder  2008-04-22 09:12:57 
Re: Distinguishing between characters and numbers
"FX" <couder  2008-04-22 09:12:57 
Re: Distinguishing between characters and numbers
SimonG <simon@[EMAIL P  2008-04-22 03:09:19 
Re: Distinguishing between characters and numbers
Gordon Sande <g.sande@  2008-04-22 12:22:53 
Re: Distinguishing between characters and numbers
Gary Scott <garylscott  2008-04-22 07:36:41 
Re: Distinguishing between characters and numbers
Gordon Sande <g.sande@  2008-04-22 14:20:51 
Re: Distinguishing between characters and numbers
glen herrmannsfeldt <g  2008-04-22 10:38:37 
Re: Distinguishing between characters and numbers
Dick Hendrickson <dick  2008-04-22 12:42:17 
Re: Distinguishing between characters and numbers
nospam@[EMAIL PROTECTED]   2008-04-22 08:38:07 
Re: Distinguishing between characters and numbers
glen herrmannsfeldt <g  2008-04-22 08:33:04 
Re: Distinguishing between characters and numbers
Dick Hendrickson <dick  2008-04-23 00:26:24 
Re: Distinguishing between characters and numbers
SimonG <simon@[EMAIL P  2008-04-22 06:18:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 23:38:49 CDT 2008.