- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, all,
I have declared an array as:
integer a(1.5:2.5)
which will create an array with two elements with subscripts 1.5 and 2.5 respectively, and the stride is 1.So I wonder if I can declare an array with stride 0.5. This can help me create a more readable code.
Best regards,
DONG Li
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The REAL will be converted to integer on the declaration of the array (or report error, requiring integer index).
If you want stride of 0.5 then "declare" in software that the indexes represent 0.5 increments. Then index via function
ingeger function indexByHalves(rIndex)
real :: rIndex
return int(rIndex*2)
end function indexByHalves
You can rename the function if you find it more suitable.
Note, you can also add a bias. e.g. Assume you want to tally a count of temperature measurements in half degree increments through a temperature range of -200:+200 with an array of 801 cells. You would pass in the temperature, add 200, multiply by 2, INT and return the resultant index (with fencing to limit index to within range).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jim,
Thanks for reply. It is a good idea to use a wrapper index function. I will try it out!
Cheers,
DONG Li
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Place the code in a module such that your main line code looks relatively clean. Consider using GENERIC INTERFACES such that you can use the same function name with different arguments. Something like
YourOutput = YourFunction(x) ! read at x
YourOutput = YourFunction(x,y) ! write Y into x, then return value at x (which may or may not be Y)
Unfortunately you cannot place a function on the left side of an equation
Jim Dempsey

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