Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding rows to a matrix.

Status
Not open for further replies.

merev001

Programmer
Dec 1, 2007
3
US
Hi,

I am new to Fortran, and I don't know how to attach new rows to a matrix. I don't know the final size of my matrix, so I can't declare its dimension.
I am doing a do loop and checking a certain condition. If the condition is true, I want to add a vector as a row to a matrix, so that at the end I have all the vectors that satisfy the condition as the rows of a matrix.
Any ideas?
Thanks a bunch,

Ivan
 
1) Which version of Fortran are you using: 77, 90, 95, 2003 or something else?

2) Are you reading the data from a file or is it interactive?

3) If it is from a file, do you have any control over what goes into the file?
 
Hi xbw,
I am using Fortran 90, and the data is interactive.

Ivan
 
Have a look at
That tels you how to input a variable number of values on a line.

Next bit is storing them. There are a few problems here and they are all related to F90 and allocateable arrays. Would be OK if you were using F95.

1) Declare an array with the max number of values you are ever likely to expect. When you input from the user, use this array using the technique in the thread mentioned

2) Next is storing it: there is no reallocation of arrays in Fortran; really wish there was. Use 2 buffers. What you have to do is allocate a new array, copy the old one to the new one, copy the array from 1 to the new line and deallocate the old array. Next time round, new becomes old and old becomes new.

Try that and see how you get on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top