- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
REAL, DIMENSION (:,:), TARGET :: A
REAL, DIMENSION (:), POINTER :: p
REAL, DIMENSION (:,:), POINTER :: t
....
ALLOCATE(A(-3:3,1:3))
p=>A(:,2)
t=>A
then I get
LBOUND(p)=1
UBOUND(p)=7
Is there any way to have p such that
LBOUND(p)=-3 and UBOUND (p)=3.
On the other hand, LBOUND(t,1) is -3. Is there any way that p can inherit the lower and upper bound of the targeted array, when it points to a subset of the array?
Thank you
Alberto
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Alberto,
Unfortunately, what you are seeing is how the Fortran standard specifies the behaviour of UBOUND and LBOUND and our compiler must conform to that. As you probably found from our documentation:
For LBOUND: " ... If array is an array section or an array expression that is not a whole array or array structure component, each element of the result has the value 1. ..."
p is pointing to an array section, a(:,2). In fact, if you
print*, "lbound(a(:,2)) is ", lbound(a(:,2))
this also returns 1. This is what the standard requires.
Similarly for UBOUND " ...If array is an array section or an array expression that is not a whole array or array structure component, UBOUND(array, dim) has a value equal to the number of elements in the given dimension...."
This documentation is pulled from Fortran 95 (or 2003) standard. For example, for UBOUND here is a snippet of the standard from which we derive our behavior:
Result Value.
Case (i): For an array section or for an array expression, other than a whole array or array structure component, UBOUND (ARRAY, DIM) has a value equal to the number of elements in the given dimension; otherwise, it has a value equal to the upper bound for subscript DIM of ARRAY if dimension DIM of ARRAY does not havesize zero and has the value zero if dimension DIM has size zero.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to make one correction so that Steve Lionel doesn't strangle me on his return :)
in my last post I said "This documentation is pulled from the Fortran 95 (or 2003) standard". what I meant to say is that the documentation for the Intel Visual Fortran Compiler for Windows reflects our compliance with the Fortran 95 Standard, or is based onTheStandard - not "pulled from" it. I did not mean to imply that we cut-and-paste bits of The Standard into our documentation. Indeed not, that would NOT be good citizenship.
I should know better than tosubmit posts on my 13th hour of the workday. When will I learn!
cheers
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you're really curious, you probably would get a better answer by asking the readers of the newsgroup comp.lang.fortran, but I'll drag what I can out of my memory:
a. One point is that A(:,2) is a notational shorthand for A(LBOUND(A,1):UBOUND(A,1):1,2) [or A(-3:3:1,2)]. In the special case where the stride is 1 (as it is here), it seems enticing that the lower bound and upper bound should be the start and end values of the triplet, but for any other value for the stride there is no corresponding "obvious" lower and upper bound. In the latter case, a lower bound of 1 and upper bound equal to the size in that dimension were the only bounds the committee could agree upon. Now imagine a compiler is presented with something like A(IB:IE:IS,2). If the rules were different for a stride of 1 and all other strides, a compiler would have to produce code for both cases and decide which one to execute depending on the value if IS. This seemed unreasonable to the committee, so they chose to use the more general rule for all stride values.
b. In case the above didn't seem messy enough for you, consider the LBOUND and UBOUND of expressions. What is lower bound of A(-3:3,2)+A(3:-3:-1,1)? Is it different from the lower bound of A(3:-3:-1,1)+A(-3:3,2)? While it would be possible to devise more complicated rules, the committee felt it would be less confusing if there was a single rule for all expressions other than simple names.
In Fortran 2003, the committee added a feature that allows the programmer to directly control the lower bound of a pointer. To do what you want to do, I believe it would look something like
p(LBOUND(A,1):) => A(:,2)
This explicitly makes the lower bound of p the same as the lower bound of the first dimension of A.
I don't know whether this feature is available in ifort. Perhaps an Intel employee can comment on that. (If it is not yet available, do they have any idea when it might be added?)
-Kurt
P.S. In your example, LBOUND(p) is not 1, but (/1/). That is, it is not the scalar value 1, but rather is one-dimensional array with a single element whose value is 1. If all you're going to do with LBOUND(p) is print it out, that difference doesn't matter to you, but if you plan to do something computational with that value, using a one-element array may prove to be awkward, and you may prefer to use LBOUND(p,1), which is scalar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
unfortunately,
p(LBOUND(A,1):) => A(:,2)
per Fortran 2003 is not yet implemented in the 10.0 compiler. As for when, we will be adding more and more Fortran 2003 features with each release. That's about all I am allowed to say, but you can be assured that we are pushing hard to get most of Fortran 2003 asap. We will keep Intel Fortran moving towards Fortran 2003, then 2008, then ... I still have 20 years until retirement and look forward to keeping this product alive and evolving for years to come. This is a sentiment carried by all of our Fortranteam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am noticing some differences w.r.t UBOUND between Intel 8 and Intel 9.1 compiler.
I have an array Arr( 3, 1000).
and I query UBOUND( Arr(1, :), 1)
In Intel 8, I get the result 1000 as I was expecting
but Intel 9.1 returns 3.
Making me to supsect that it was not passing part of Arr to UBOUND but the entire Array Arr.
So I tried to do UBOUND( Arr(1,:), 2) but that gives compilation error as was expected.
In your example you explain that UBOUND( a(:, 2)) would return 7 and not -3 ( where a is a(-3:3, 1:4). That I understand.
But what would UBOUND( a(2, :), 1) return? Would it return 4 ?
My observation is IVF 8 would return 4 as expected but IF 9.1 seems to incorrectly return 7 (it seems to return the 1st dimension of the entire array not a(2,:)
Could you please clarify?
Bhanu
Alberto,
Unfortunately, what you are seeing is how the Fortran standard specifies the behaviour of UBOUND and LBOUND and our compiler must conform to that. As you probably found from our documentation:
For LBOUND: " ... If array is an array section or an array expression that is not a whole array or array structure component, each element of the result has the value 1. ..."
p is pointing to an array section, a(:,2). In fact, if you
print*, "lbound(a(:,2)) is ", lbound(a(:,2))
this also returns 1. This is what the standard requires.
Similarly for UBOUND " ...If array is an array section or an array expression that is not a whole array or array structure component, UBOUND(array, dim) has a value equal to the number of elements in the given dimension...."
This documentation is pulled from Fortran 95 (or 2003) standard. For example, for UBOUND here is a snippet of the standard from which we derive our behavior:
Result Value.
Case (i): For an array section or for an array expression, other than a whole array or array structure component, UBOUND (ARRAY, DIM) has a value equal to the number of elements in the given dimension; otherwise, it has a value equal to the upper bound for subscript DIM of ARRAY if dimension DIM of ARRAY does not have size zero and has the value zero if dimension DIM has size zero.

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