On Apr 22, 2016, at 7:41 PM, Vipul Parekh <[log in to unmask]> wrote:
> Hi,
>
> I need to construct an integer array of a named constant using BOZ-literal-constants as in
>
> integer(kind=xx), parameter :: SOME_DATA(*) = [ z'..', z'..', .. ]
>
> but the current standard doesn't seem to allow this.
>
Correct. There was a proposal for Fortran 2008 to include a “BITS” data type that would have enabled something like this. However, in an attempt to reduce the size of the changes to the standard, it was dropped. While there were no actual technical problems with the proposal, it was seen as too much effort for the benefit received. Weighing against it was the difficulty of implementing any change to the typing system.
> The standard states:
>
> C4102 (R463) A boz-literal-constant shall appear only as a data-stmt-constant in a DATA statement, or where
> explicitly allowed in subclause 13.7 as an actual argument of an intrinsic procedure
>
> So it would appear one can do:
>
> integer(kind=xx), parameter :: foo = int( z'0', kind=kind(foo) ) !.. OK
Yes, this should work.
>
> but not
>
> integer(kind=xx), parameter :: bar(*) = int( [ z'0' ], kind=kind(bar) ) !.. Not OK
I do not see any reason for this to fail. INT is an elemental function. INT ( [a,b,c] ) has an array result with the value [ INT(a), INT(b), INT(c) ]. If you have a compiler that is rejecting this, you might contact the vendor.
Cheers,
Bill
>
> Now, of course, one can use INT intrinsic function for each element of the array as in
>
> integer(kind=xx), parameter :: bar2(*) = [ int( z'0', kind=xx), int( z'1', kind=xx) ]
>
> which is acceptable to me but it does seem a tad verbose since I have an array of 2**N elements where N can range from 6 to 12 in different sections of code. So I am wondering if I am overlooking something in the language.
>
> A couple of questions:
>
> 1. Am I correct in my understanding the standard does not allow constructs such as integer, parameter :: bar(*) = int( [ z'0' ], kind=kind(bar) ) ? Meaning prior to invoking the elemental INT intrinsic function, the array will be constructed and BOZ constants are not valid in an array-constructor, even when that array constructor is being passed to an intrinsic procedure?
>
> 2. Any other way to how to construct an integer array named constant using BOZ literals besides what I show above?
>
> Thanks,
> Vipul Parekh
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
|