- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
i have written the following test case to ask if both results are standard conform
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
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
Link Copied
12 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
in my personal view this should be an error during comliation.
Frank
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello mercj
if your statement is correct then the interpreation of the format items may be unstable
an examble
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
-----------^
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
-----------^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The results I showed were using the 12.1 compiler.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page