Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Fortran Allocate Mold Problem

Andrew_
Beginner
1,478 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
Honored Contributor III
1,431 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)))

0 Kudos
Andrew_
Beginner
1,365 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).

0 Kudos
Steve_Lionel
Honored Contributor III
1,339 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.

0 Kudos
Reply