Re: format with G descriptor
- From: "Kurt Kallblad" <kurt.kallblad@xxxxxxxx>
- Date: Fri, 30 May 2008 21:17:37 +0200
"Roman" <shekht@xxxxxxxxxx> wrote in message news:e7ee8bdf-697a-4298-9808-3d45d580f6aa@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2 format(g)
s = "1.0"
read(s,*) r
write(*,*) r ! output: 1.000000
read(s,2) r
write(*,*) r ! output: 1.000000
s = "1"
read(s,*) r
write(*,*) r ! output: 1.000000
read(s,2) r
write(*,*) r ! output: 1.0000000E-07 !!!!!!!
stop
end program test_format_G
!-------------------------------------------
What happens when you don't obey to the standard depends on the compiler.
Try e.g with "g10.0" and it will work - or way not with "read(s,*) r" if you are using Fortran 90/95 or later,
Cut from one manual:
The full descripor is: Gw.d[Ee] where
w is the field width
m is the minimum number of digits that must be in the field (including zeros).
d is the number of digits to the right of the decimal point
E is the exponent field
e is the number of digits in the exponent
Rules for Input Processing
On input, the G data edit descriptor transfers w characters from an external field and assigns their real value to the corresponding I/O list item. The G descriptor interprets and assigns input data in the same way as the F data edit descriptor.
Rules for Input Processing
On input, the F data edit descriptor transfers w characters from an external field and assigns their real value to the corresponding I/O list item. The external field data must be an integer or real constant.
If the input field contains only an exponent letter or decimal point, it is treated as a zero value.
If the input field does not contain a decimal point or an exponent, it is treated as a real number of w digits, with d digits to the right of the decimal point. (Leading zeros are added, if necessary.)
If the input field contains a decimal point, the location of that decimal point overrides the location specified by the F descriptor.
If the field contains an exponent, that exponent is used to establish the magnitude of the value before it is assigned to the list element.What a compiler does if you don't follow this might be whatever it likes!
Kurt
.
- Follow-Ups:
- Re: format with G descriptor
- From: Roman
- Re: format with G descriptor
- References:
- format with G descriptor
- From: Roman
- format with G descriptor
- Prev by Date: Re: format with G descriptor
- Next by Date: Re: format with G descriptor
- Previous by thread: Re: format with G descriptor
- Next by thread: Re: format with G descriptor
- Index(es):
Relevant Pages
|
|