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

Fortran Allocate Mold Problem

Andrew_
Beginner
416 Views

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.

0 Kudos
3 Replies
Steve_Lionel
Black Belt Retired Employee
369 Views

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)))

Andrew_
Beginner
303 Views

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).

Steve_Lionel
Black Belt Retired Employee
277 Views

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.

Reply