- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I have the following code:
program readtest
implicit none
! Variables
integer::n
real*8,allocatable::th(:)
open(1,file='test.dat')
read(1,*)n
allocate(th(n))
read(1,*,err=1,end=1)th
continue
! Body of readtest
!print *, 'Hello World'
1 &
close(1)
deallocate(th)
stop
end program readtest
The data in 'test.dat' are as follows:
122
0.02,0.06,0.10,0.14,0.18,0.22,0.26,0.30,0.34,0.38,0.42,0.46,0.50,0.54,0.58,
0.62,0.66,0.70,0.74,0.78,0.82,0.86,0.90,0.94,0.98,1.02,1.06,1.10,1.14,1.18,
1.26,1.34,1.42,1.50,1.58,1.66,1.74,1.82,1.90,2.00,2.10,2.20,2.30,2.40,2.50,
2.60,2.70,2.80,2.90,3.00,3.10,3.20,3.30,3.40,3.50,3.60,3.70,3.80,3.90,4.00,
4.20,4.40,4.60,4.80,5.00,5.20,5.40,5.60,5.80,6.00,6.20,6.40,6.60,6.80.7.00,
7.20,7.40,7.60,7.80,8.00,8.20,8.40,8.60,8.80,9.00,9.20,9.40,9.60,9.80.10.0,
10.2,10.4,10.6,10.8,11.0,11.2,11.4,11.6,11.8,12.0,12.2,12.4,12.6,12.8.13.0,
14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,
29.0,30.0
Now the problem is that when running this program the code jump to 1 after read first 73 data, however, there are totally 122 data. Could anyone tell me how to modify the code to let the code read all these data? The environment I tested the program is: Windows 7 64bit + VS2010 + IVF13.1.3.198.
Thanks,
Zhanghong Tang
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Check your data, as you have errors on the end of lines 6,7 and 8. "6.80.7.00" should be "6.80,7.00" etc.
If you import your data into excel, you will see the errors.
It would be good if there was an option something like : READ (unit=11,fmt=*,count=n) array(*). Returning count would give the flexibility to read as many numbers as available in a single record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi John,
Thank you very much for your so quick reply. I got it, thanks.

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