- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

If we consider the following simple subroutine

suborouine Test (X)

.....

complex(8) :: X(0:,:)

Real(8) ,allocatable :: Y(:,:)

Complex(8) ,allocatable :: Z(:,:)

Allocate(Z,mold=X)

Allocate(Y,mold=real(X,8))

end

The following problem occurs.

Why lbound (Z,dim=1) == 0, and for lbound(Y,dim=1) ==1?

How can I make the lower boundary of the Y array equal to 0?

I cannot use Allocate(Y,mold=X) because the data types are different.

If you use allocate (Y,mold=X%RE) you get that lbound(Y,dim=1)==1.

Thanks.

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Because REAL(X,8) is an expression that has the shape of X, but not the lower bound. (Shape is concerned with extent only.)

I think this will do what you want:

Allocate(Y(0:ubound(X,1),ubound(X,2)))

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thank you, Steve.

That's how I use it, but this approach is not very logical or convenient.

I don't understand why array boundaries are not inherited.

This kind of implicit boundary mismatch gave me a lot of trouble.

Also, I have to use the compiler flag (/nostandard-realloc-lhs).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Array expressions are always 1:x based on the number of elements (extent) in the expression value. There are no special rules for things such as REAL(X). Keep in mind there are such things as vector subscripts.

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