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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flexibile matrix/array dymension declaration acording to loop

Status
Not open for further replies.

Jureee

Programmer
Nov 4, 2011
1
CZ
Hi guys,

thanks to all of you which runs this web site, and please let me ask one stupid question, because im beginner in Fortran.

I would like to ask if Fortran is endowed with functions which I known from Visual Basic (and VBA), as REDIM PRESERVE or ADD ITEM, which I was using for dynamically enlarging matrix/array according to number of cycles in loop. Here is example:

VBA:
Dim Recorder()
For Row = 1 To Number
Results = Number * 5
ReDim Preserve Recorder(1 To Row)
Recorder (Row) = Results
Next Row

... or another example

VB.NET:
Dim Záznamník As New ArrayList
For Row = 1 To Number
Results = Number * 5
Recorder.Add(Results)
Next Row

Point is to simplify code from loop which will be counting future dimension of “recorder” array
Thanks in the advance for your reply
 
Well...that's a silly thing to do and one that will not yield very good performance at all when Number gets larger and larger...

For as long as Number is known BEFORE you enter the loop, you may as well allocate Recorder of the correct dimension BEFORE you enter the loop and request all necessary memory once and for all...requesting memory one byte or two at a time is just wasteful.

So, just follow the typical procedure where you declare your variables at the beginning of the right size and be done with it.

If you do not know your dimension ahead of time, you can use ALLOCATE later in the program once you know it. Or, for many years, the practice was simply to declare an oversize array able to handle all possible inputs and that's it...fortran does not get bothered if you declare an array to be 1000's items long.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top