- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When the below command executes, it read the file content ( 35) where all the spaces are ignored and it reads only the numbers in that case the size of the number is only 2 bytes, but we are trying to read 8 byte number which throws the exception.
FORMAT(I8)
IF I use FORMAT(I2) then there is no exception
program test
INTEGER(4) IRATE
OPEN(4,file='C:\Srini\Files\Arat51',status='OLD',access='DIRECT',
& form='FORMATTED',recl=8)
Read(4,200,rec=2)IRATE
CLOSE(4)
200 FORMAT(I8)
STOP
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With your data file, the following program works correctly if I specify RECL=10 in the OPEN statement, with the data file containing CR+LF at end-of-line. Similarly, with the datafile using LF for EOL, using RECL=9 in the OPEN statement gives correct output.
program test INTEGER(4) IRATE,i ! OPEN(4,file='Arat51',status='OLD',access='DIRECT', & form='FORMATTED',recl=10) i=2 DO while(i .le.16) Read(4,200,rec=i)IRATE write(*,*)i,irate i=i*2 end do CLOSE(4) 200 FORMAT(I8) STOP end
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Shrinivassan,
If you are processing data files produced elsewhere, you should be made aware that depending on the system where the file was written, and how the open declared the file, that the record delimiters can differ. In the first case you had CR+LF, a Linux/Unix system may use just LF, and other systems may have: {byte count}data here{byte count},{byte count}data here{byte count},...
and there are several other variations on this.
For your program to be universal, in accepting formats written by various other systems you may need write a piece of code that determines the specific format.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For a direct access file, you do indeed need to account for any metadata. As far as I know, if ifort writes a formatted, direct access file, it doesn't add any line delimiters (but I could be mistaken). If the file was created by something else, all bets are off.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Ret.) wrote:
For a direct access file, you do indeed need to account for any metadata. As far as I know, if ifort writes a formatted, direct access file, it doesn't add any line delimiters (but I could be mistaken). If the file was created by something else, all bets are off.
I can confirm that direct access files produced with ifort do not include metadata. I read direct access files generated by ifort with MS C++ in a very transparent mode. One can also browse any file using an editor which allows hexadecimal view of each byte (e.g. the old IBM/SPF).

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »