- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm trying to read a .txt file containing a 247 by 200 matrix. These are commands I used:
open(6, file = 'yfortran.txt', status = 'old', form = 'formatted', action = 'read')
do i = 1, 247
read(6, *) (y(i, j), j = 1, 200)
end do
close(6)
I kept getting error msg: ...has triggered a breakpoint
Could anyone give me some suggestions? One more question: how can I read an array with unknown size?
Thanks,
Siva
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The real error message is in the console window which you are not seeing. Look in the Windows taskbar tray for the icon for the console window and click on it to bring it to the top.
You can't read an array with unknown size - you have to figure out what its size is first. You can read the size from the file and use an ALLOCATABLE array which allows you to ALLOCATE it to the desired size as the program is run.
You may also be able to use END= or IOSTAT= to detect when you have reached the end of the file. I don't know your application so can't say which approach is best.
You can't read an array with unknown size - you have to figure out what its size is first. You can read the size from the file and use an ALLOCATABLE array which allows you to ALLOCATE it to the desired size as the program is run.
You may also be able to use END= or IOSTAT= to detect when you have reached the end of the file. I don't know your application so can't say which approach is best.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot. The console window shows:
forrtl: severe (408): fort: (10): subscript #2 of the array Y has value 1 which is greater than the upper bound of -1.
I guess this is because the file I am trying to load is atab-delimited text file, not really an array... What shall I do if I want to read it as a matrix?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
I modified my code to
integer, parameter :: p = 15372, n = 247, s = 200
real, dimension(:,:), allocatable :: x, y
integer :: i, j
allocate (estb(p, s), x(n, p), y(n, s))
open(5, file = 'xfortran.txt', status = 'old', form = 'formatted', action = 'read')
open(6, file = 'yfortran.txt', status = 'old', form = 'formatted', action = 'read')
do i = 1, n
read(5, *) (x(i, j), j = 1, p)
read(6, *) (y(i, j), j = 1, s)
end do
close(5)
close(6)
now the error is:
input conversion error, unit 5...
Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Input conversion error means that the data read isn't valid for numeric list-directed input. Without also seeing the data files, I can't comment more specifically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! You are right, the first row of the data contains strings of column names. How can I read the data from the second row (the numbers)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
add a READ statement with the correct A format to read the first record into a character string of length long enough to contain the whole record. This will position the file ready for you to start your read of the numbers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Anthony. I modified the statement and now it reads fine.
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