Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

read statement

tropfen
Nouveau contributeur I
2 225 Visites
Hello,

i have written the following test case to ask if both results are standard conform

[fortran]    program Test_read

    implicit none
character(len=1) :: cValue
open(10,file="temp.txt")
write(10,'(a)')"12345678901234567890"
close(10)

open(11,file="temp.txt")
read(11,'(2x,xa1)')cValue
close(11)
write(6,'(a1)')cValue


open(12,file="temp.txt")
read(12,'(2x,x,a1)')cValue
close(12)
write(6,'(a1)')cValue

    end program Test_read[/fortran]



both times the write statement is writting 4. Are both read statements (line 10 and 16 ok?)

I am using IVF 11.1.048

Thanks in advance
Frank
0 Compliments
12 Réponses
mecej4
Contributeur émérite III
2 225 Visites
The formats '(2x,xa1)' and '(2x,x,a1)' are equivalent. You could even have written '(3x,a1)'.

Most compilers do not insist on commas between position edit format items. Why the doubt? What else could have been the output, in your view?
0 Compliments
tropfen
Nouveau contributeur I
2 225 Visites
in my personal view this should be an error during comliation.

Frank
0 Compliments
tropfen
Nouveau contributeur I
2 225 Visites
Hello mercj

if your statement is correct then the interpreation of the format items may be unstable

an examble

[fortran]character(len=10) :: cValue10

real*4 :: rValue



open(13,file="temp2.txt")
write(13,'(a)')"N00001.1"
close(13)

open(14,file="temp2.txt")
read(14,'(a,1f7.1)')cValue10,rValue
close(14)
write(6,'(a10,x,f7.1)')cValue10,rValue


open(14,file="temp2.txt")
read(14,'(a1,f7.1)')cValue10,rValue
close(14)
write(6,'(a10,x,f7.1)')cValue10,rValue


open(14,file="temp2.txt")
read(14,'(a1f7.1)')cValue10,rValue
close(14)
write(6,'(a10,x,f7.1)')cValue10,rValue[/fortran]





the output is:
N00001.1 0.0
N 1.1
N 1.1


In my point of view the compiler should produce at least a warning

Frank
0 Compliments
mecej4
Contributeur émérite III
2 225 Visites
I agree that a warning on a missing width n in the 'nX' specifier would be helpful. Similarly for missing commas.

Your second example, however, confuses the issue. Here, the culprit is not the missing commas or position specifiers, but your use of the '(a,1f7.1)' format in your first READ. Format 'a', with no field width specified, takes the field width to be the length of the corresponding I/O list variable. In your example, this length is 10. Therefore, the second item in the I/O list, rValue, is read from columns 11 onwards in the input line. However, those columns simply contain blanks added as padding, and the read value is zero, in the absence of a BLANK=<'null' | 'zero'> specifier in the file open statement.

To see this, fix all the X format edit descriptors by adding a count and by adding commas. You will still see the same behavior.
0 Compliments
Steven_L_Intel1
Employé
2 225 Visites
If you enable standards checking, you'll get:

t.f90(10): warning #7423: Fortran 2003 requires a count prefix for the X edit descriptor. [x,xa]
read(11,'(2x,xa1)')cValue
-----------^
t.f90(10): warning #6893: In a format list, the required delimiter is missing. This is an extension to Standard F2003. [x,xa]
read(11,'(2x,xa1)')cValue
-----------^
t.f90(16): warning #7423: Fortran 2003 requires a count prefix for the X edit descriptor. [x,x,a]
read(12,'(2x,x,a1)')cValue
-----------^
0 Compliments
tropfen
Nouveau contributeur I
2 225 Visites
Hello Steve,

i am using IVF 11.1.048 without any changes. Do i have to change the settings to have your 'standard checking' or are those 'standard checks' part of a newer IVF version?

Frank
0 Compliments
TimP
Contributeur émérite III
2 225 Visites
11.1 has standards checking flags up through f2003. It's possible in some cases they may not be as strict as the newer versions. If it's not a Visual Studio property menu item, you can add a command line option.
0 Compliments
Steven_L_Intel1
Employé
2 225 Visites
It is a property under Diagnostics > Warn for non-standard Fortran. I have not tried the code under 11.1 to see if it reports these extensions.
0 Compliments
tropfen
Nouveau contributeur I
2 225 Visites
Hello Steve,

you are writting that those test are part of the standard checking. Today i have installed the current ivf version (12.1.1.258). I have tested the above examble. With the standard installation the checking for non standard fortran (Diagnostics > Warn for non-standard Fortran) has not been aktivated.

Frank

0 Compliments
IanH
Contributeur émérite III
2 225 Visites
Are you saying that you needed to set the property from within Visual Studio (I imagine that there are a number of people that don't want standards checking on by default), or that with that property set you didn't see warnings (I see them here)?

0 Compliments
Wendy_Doerner__Intel
Précieux contributeur I
2 225 Visites
Yes Ian is correct, standards checking is not on by default (different customers want different standards to be checked and some do not want standards checking). You will need to set it.

------

Wendy

Attaching or including files in a post

0 Compliments
Steven_L_Intel1
Employé
2 225 Visites
The results I showed were using the 12.1 compiler.
0 Compliments
Répondre