I am trying to read an external formatted input file. The first column of data in the file contains a representation of the date using a combination of numbers '-' and '/' and then follows a set of columns with data in unknown, and possibly variable, format. For example, a line in the file may look something like:
2010-10/12 12.3 45678.90
It is possible that the first field (the date) can change in width in the file.
Unfortunately, because of the '/' in the date, the line does not seem to be easily read in using FMT='*' in a READ statement. Therefore, the approach I have been taking is:
- read each line in using FMT='(A)'
- work out how many characters (n) there are in the date
- BACKSPACE
- read only the date using FMT='(An)', and ADVANCE='no'
- read the data in the rest of the line using another READ statement with FMT='*', and ADVANCE='yes'
Assume that I have a subroutine width_date that takes a character input determines how wide the date is, and outputs a format statement, then the code is as follows:
READ (UNIT=iin,FMT='(A)',ERR=1,END=2) c
CALL width_date (c,cfmt)
BACKSPACE (UNIT=iin)
READ (UNIT=iin,FMT=cfmt,ADVANCE='no',ERR=1,END=2) cdate
READ (UNIT=iin,FMT=*,ADVANCE='yes',ERR=1)
The above works fine except that when I have a very wide input file, the BACKSPACE does not seem to take me back to the beginning of the line. I'm not quite sure how wide the file needs to be in order for the procedure to stop working, but I have a file that is >23000 columns wide that fails to backspace properly.
Of course, if I made LEN(c) in the first line large enough I would not need to backspace in the file and could change the units in the last two read statements as UNIT=c. But if I don't know how wide the file is, there is a possibility that I may set LEN(c) too small; hence the rather complicated procedure above.
So, my question is: is there any reason why BACKSPACE may not be working as expected if the input file is exceedingly wide?
I can provide an example short program and problem input file to illustrate the problem if anyone needs, but you would have to let me know how best to make these available.