Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29229 Discussions

Retrieving a value from an array to use it in an equation, using column value as index

bhvj
Beginner
643 Views

Hi,


I am trying to retrieve a value from an array, using column value as index,
to select the corresponding value from a specified row, and use it in an equation.
Attached is a portion of the array.
In an attempt to do this I am trying to create another subroutine
(with the arguments as row-i and column-j)  for this, and then call it in the equation,
I am going to use. In the subroutine, I tried to read the complete array into temp (i,j).
Is this the right approach, or would there be an efficient way? I also checked the documentation, but
I didn't find Fortran inbuilt functions (also tried to look for lookup function).
Any suggestions or pointers in this regard would be greatly helpful.

Thank you.

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
643 Views

A single array has to be all integers or all reals (or all logical or all user defined type). The data you show in the .txt file, to be one data type would imply they all be real. Thus when fetching the year, as real, you would have to use the int() function to convert it to integer prior to use.

An alternative would be to use two arrays, one as integer for the column of years, the other as real for a 3 by n array holding the H, PotE, and KinE.

If your years are always contiguous, then you only need store the start year and number of years.

Jim Dempsey

0 Kudos
bhvj
Beginner
643 Views

Thank you for the suggestions, Jim.

0 Kudos
bhvj
Beginner
643 Views

Hi Jim,

          As suggested I created two arrays, one as integer for the column of years, the other as real for a 3 by 11 array holding the H, PotE, and KinE. Attached herewith is test program and test input. I am getting segmentation default while compiling. Can you please give me some suggestions in this regard.

Thank you in advance for your suggestions.

0 Kudos
Reply