- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to use FTELL, FSEEK to re-open an input file and re-position the file pointer to the last read position. However, I found that I have to append a carriage return to the end of the file for it to work properly (FILE2.DAT).
Can someone clarify.
Here is my code:
PROGRAM TEST_FSEEK
USE IFPORT
IMPLICIT NONE
INTEGER, PARAMETER :: RECLEN = 40
CHARACTER (LEN=RECLEN) :: RECORD1 = " "
INTEGER :: FTELL_VAL=0, I, IOS, FLAG, LINE
CHARACTER (LEN=100) :: FILENAME
READ(*,*)FLAG
IF (FLAG==1) THEN
FILENAME='FILE1.DAT'
LINE=1
ELSE IF(FLAG==2) THEN
FILENAME='FILE2.DAT'
LINE=1
ENDIF
OPEN(UNIT=1234, FILE=TRIM(FILENAME), STATUS='OLD')
FTELL_VAL=FTELL(1234)
READ(1234,'(A)')RECORD1
FTELL_VAL=FTELL(1234)
CLOSE(1234)
RECORD1 = " "
OPEN(UNIT=1234, FILE=TRIM(FILENAME), STATUS='OLD')
DO WHILE (.NOT. EOF(1234))
IOS=FSEEK(1234,FTELL_VAL,0)
READ(1234,'(A)')RECORD1
FTELL_VAL=FTELL(1234)
END DO
CLOSE(1234)
END PROGRAM TEST_FSEEK
Regards,
ea0337.
I am trying to use FTELL, FSEEK to re-open an input file and re-position the file pointer to the last read position. However, I found that I have to append a carriage return to the end of the file for it to work properly (FILE2.DAT).
Can someone clarify.
Here is my code:
PROGRAM TEST_FSEEK
USE IFPORT
IMPLICIT NONE
INTEGER, PARAMETER :: RECLEN = 40
CHARACTER (LEN=RECLEN) :: RECORD1 = " "
INTEGER :: FTELL_VAL=0, I, IOS, FLAG, LINE
CHARACTER (LEN=100) :: FILENAME
READ(*,*)FLAG
IF (FLAG==1) THEN
FILENAME='FILE1.DAT'
LINE=1
ELSE IF(FLAG==2) THEN
FILENAME='FILE2.DAT'
LINE=1
ENDIF
OPEN(UNIT=1234, FILE=TRIM(FILENAME), STATUS='OLD')
FTELL_VAL=FTELL(1234)
READ(1234,'(A)')RECORD1
FTELL_VAL=FTELL(1234)
CLOSE(1234)
RECORD1 = " "
OPEN(UNIT=1234, FILE=TRIM(FILENAME), STATUS='OLD')
DO WHILE (.NOT. EOF(1234))
IOS=FSEEK(1234,FTELL_VAL,0)
READ(1234,'(A)')RECORD1
FTELL_VAL=FTELL(1234)
END DO
CLOSE(1234)
END PROGRAM TEST_FSEEK
Regards,
ea0337.
Link Copied
0 Replies
![](/skins/images/D3C0B914909A6564BBB97F4AD1ED1973/responsive_peak/images/icon_anonymous_message.png)
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