I was puzzled by how read (..,*) would read character strings.
It appears that it is fairly (very) flexible:
commas can seperate numbers or strings
blanks can also be used as a delimiter
blanks are a delimiter for strings.
strings can be enclosed in quotes, such as 'this is a single string'
records can span multiple lines.
The following program and sample data file demonstrate these
IMPLICIT NONE
IMPLICIT NONE
DOUBLE PRECISION e(8760),x(8760),y(8760),z(8760)
character*1000 C(8760),D(8760)
character in_file*100, out_file*100
in_file = 'C:\\Users\\Estanislao\\Desktop\\bristol chanel\\wind data\\wind.txt'
out_file = 'C:\\Users\\Estanislao\\Desktop\\bristol chanel\\wind data\\wind4.txt'
in_file = 'sample.dat'
out_file = 'sample.new'
OPEN (UNIT=22, FILE=in_file, STATUS='OLD', ACTION='READ')
OPEN (UNIT=23, FILE=out_file, STATUS='UNKNOWN')
!
DO I=1,8760
!z READ (22,*) C(I),D(I),x(I),y(I),z(I)
READ (22,*,iostat=iostat) x(I),y(I),z(I), C(I),D(I)
write (*,*) i, iostat
if (iostat/=0) exit
!
write (*,fmt='(3f10.3,' |',a15,'|',a)') x(I),y(I),z(I), trim(C(I)), trim(D(I))
!
e(I)=y(I)*0.5144
write (23,10) e(I),z(I)
END DO
10 FORMAT(2f10.4)
!
close(22)
close(23)
!
end
<sample.dat>
1,22,33,'aaaa','bbbb'
2,22,33,'aaaa','bbbb'
3,22,33,'aaaa bbbb ccc ','eeee fff ggg '
4,22,33,'aaaa bbbb ccc ','eeee fff ggg '
5,22,33,'aaaa bbbb ccc ','eeee fff ggg '
6,2,3,this is a text string outside quotes blanks appear to be a text delimiter
7,2,3,'this is a text string inside quotes', blanks still appear to be a text delimiter
8,33,4.5,'first string','this is a good format as second string reads ok'
9 22 33 'first string' 'this record uses blanks'
10 12 15 'extra spaces' 'this still works'
11 12
13
'next line' 'an example of info over three lines'
12, 22, 33, 'leading blanks between the comma field ', 'multiple blanks are a single delimiter '
13 , 22 , 33 , ' extra blanks ' , 'an example with blanks between the comma '
14, 1, 1, 'first comment' 'test of basic .csv data format'
15, 1, 1, 'last line' 'test of basic data format'
Based on this your original read order could work, if the two text strings are like
' text 1' 'text 2' 11 22 33
I've learnt something today.