[comp.lang.fortran] Strange EQUIVALENCES and data inits

morgan@ms.uky.edu (Wes Morgan) (02/13/90)

I am attempting to port the PD MATLAB package to a 3B20 with f77.
The following chunk of code refuses to compile:

      DOUBLE PRECISION MASK(14),XX,MM
      real mas(2,14)
      equivalence (mask(1),mas(1))
      data mas/
     $ z'ffffffff',z'fff0ffff',
     $ z'ffffffff',z'ff00ffff',
     $ z'ffffffff',z'f000ffff',
     $ z'ffffffff',z'0000ffff',
     $ z'ffffffff',z'0000fff0',
     $ z'ffffffff',z'0000ff00',
     $ z'ffffffff',z'0000f000',
     $ z'ffffffff',z'00000000',
     $ z'fff0ffff',z'00000000',
     $ z'ff00ffff',z'00000000',
     $ z'f000ffff',z'00000000',
     $ z'0000ffff',z'00000000',
     $ z'0000fff0',z'00000000',
     $ z'0000ff80',z'00000000'/

My errors have been "initializing noncharacter datum with a character
string" and "invalid types in initialization".

It would appear that the original author is trying to force bit patterns
into a real array.  My first attempt was to change the equivalence args
to (mask(1),mas(1,1)); that crashed and burned.  My second thought was 
to redefine mas as character*32, rather than real. That, too, bit the
dirt.

Could some fortran wizard out there kindly fill me in on
   a) What the author is *really* attempting to do here, and
   b) How to make the f77 compiler swallow this mess? 

Many thanks,
Wes Morgan


-- 
  The opinions expressed above are not those of UKECC unless so noted.
Wes Morgan                 \       {rutgers,rayssd,uunet}!ukma!ukecc!morgan
University of Kentucky      \   or morgan@engr.uky.edu
Engineering Computing Center \  or morgan%engr.uky.edu@UKMA.BITNET

mcqueen@acf4.NYU.EDU (David M. McQueen) (02/15/90)

/* acf4:comp.lang.fortran / morgan@ms.uky.edu (Wes Morgan) /  3:02 pm  Feb 12, 1990 */

> I am attempting to port the PD MATLAB package to a 3B20 with f77.
> The following chunk of code refuses to compile:
> 
>       DOUBLE PRECISION MASK(14),XX,MM
>       real mas(2,14)
>       equivalence (mask(1),mas(1))
>       data mas/
>      $ z'ffffffff',z'fff0ffff',
>      $ z'ffffffff',z'ff00ffff',
>      $ z'ffffffff',z'f000ffff',
>      $ z'ffffffff',z'0000ffff',
>      $ z'ffffffff',z'0000fff0',
>      $ z'ffffffff',z'0000ff00',
>      $ z'ffffffff',z'0000f000',
>      $ z'ffffffff',z'00000000',
>      $ z'fff0ffff',z'00000000',
>      $ z'ff00ffff',z'00000000',
>      $ z'f000ffff',z'00000000',
>      $ z'0000ffff',z'00000000',
>      $ z'0000fff0',z'00000000',
>      $ z'0000ff80',z'00000000'/
> 
> My errors have been "initializing noncharacter datum with a character
> string" and "invalid types in initialization".
> 
> It would appear that the original author is trying to force bit patterns
> into a real array.  My first attempt was to change the equivalence args
> to (mask(1),mas(1,1)); that crashed and burned.  My second thought was 
> to redefine mas as character*32, rather than real. That, too, bit the
> dirt.
> 
> Could some fortran wizard out there kindly fill me in on
>    a) What the author is *really* attempting to do here, and
>    b) How to make the f77 compiler swallow this mess? 
> 
> Many thanks,
> Wes Morgan
> 
> 
> -- 
>   The opinions expressed above are not those of UKECC unless so noted.
> Wes Morgan                 \       {rutgers,rayssd,uunet}!ukma!ukecc!morgan
> University of Kentucky      \   or morgan@engr.uky.edu
> Engineering Computing Center \  or morgan%engr.uky.edu@UKMA.BITNET
> /* ---------- */

I have tried your code on several machines here at NYU's Academic Computing
Facility, each purporting to use f77. I added a small loop below your data
statement to see what appears to be stored in MASK:

      do 100 k=1,14
      write(6,*) MASK(k)
  100 continue

On 3 out of 5 machines, the code compiles and then executes. On two of those
3 (Sun-3, IRIS 4D80GT) the same answers result:
 -NaN              
 -NaN              
 -NaN              
 -NaN              
 -NaN              
 -NaN              
 -NaN              
 -NaN              
 -NaN              
   -5.8290015911177+303
   -3.2990979849457+231
    1.3906499416091-309
    1.3903316422404-309
    1.3879550069546-309

and on the third (a VAX running BSD 4.3):
  -1.7014118346047d+38
  -1.7014118346047d+38
  -1.7014118346046d+38
  -1.7014118346031d+38
  -1.7014118345799d+38
  -1.7014118342086d+38
  -1.7014118282664d+38
  -1.7014117331926d+38
  -1.7014102120119d+38
  -1.7013858731204d+38
  -1.7009964508560d+38
  -1.6947656946258d+38
  -1.5950735949419d+38
  -8.5070591730235d+37

On the fourth machine, (an Astronautics ZS2), execution hangs after printing
three lines of output.

On the fifth (a Stardent, the result of Stellar and Ardent merging),
compilation fails with the error message:

line 5: Error: Syntax Error at "'ffffffff'"

I don't know specifically which vendors have supplied the f77's for each of
my machines, but clearly the results are 'system-dependent'.

calvin@dinkum.sgi.com (Calvin H. Vu) (02/15/90)

In article <13160004@acf4.NYU.EDU> mcqueen@acf4.NYU.EDU (David M. McQueen) writes:

>/* acf4:comp.lang.fortran / morgan@ms.uky.edu (Wes Morgan) /  3:02 pm  Feb 12, 1990 */

>> I am attempting to port the PD MATLAB package to a 3B20 with f77.
>> The following chunk of code refuses to compile:
>> 
>>       DOUBLE PRECISION MASK(14),XX,MM
>>       real mas(2,14)
>>       equivalence (mask(1),mas(1))
>>       data mas/
......................................................
>>   The opinions expressed above are not those of UKECC unless so noted.
>> Wes Morgan                 \       {rutgers,rayssd,uunet}!ukma!ukecc!morgan
>> University of Kentucky      \   or morgan@engr.uky.edu
>> Engineering Computing Center \  or morgan%engr.uky.edu@UKMA.BITNET
>> /* ---------- */

>I have tried your code on several machines here at NYU's Academic Computing
>Facility, each purporting to use f77. I added a small loop below your data
>statement to see what appears to be stored in MASK:

>      do 100 k=1,14
>      write(6,*) MASK(k)
>  100 continue

>On 3 out of 5 machines, the code compiles and then executes. On two of those
>3 (Sun-3, IRIS 4D80GT) the same answers result:
>    .......................................................

>and on the third (a VAX running BSD 4.3):
>  .........................................................

>I don't know specifically which vendors have supplied the f77's for each of
>my machines, but clearly the results are 'system-dependent'.

It is not really system-dependent, only the bit pattern will be interpreted
differently on the different systems.   SGI and SUN uses IEEE format for
floating-point numbers so the results are the same, VAX VMS uses a different
format so you see something different when you try to print out the bit
patterns as decimal numbers.   I suspect that if you had used:

      write(6,10) MASK(k)
10    format(z16)

to print out the bit patterns then the results would have be the same on the
three machines which allow this syntax.

For the machine which do not allow this syntax for hexadeciaml constants, try
the followings:

	'hexstring'x	or 	x'hexstring'
	$hexstring

the form 'hexstring'x is the most popular form and should work on all machines.
Anyway, look at your Fortran Reference Manual to see which form of hex.
constant they support.  They must support one form or another.

Calvin Vu
-----------------------------------------------------------------------------
"Don't flame me.  I never check my guesses and provide no guarantee for them"

fac2@dayton.saic.com (Earle Ake) (02/17/90)

In article <4163@odin.SGI.COM>, calvin@dinkum.sgi.com (Calvin H. Vu) writes:
> In article <13160004@acf4.NYU.EDU> mcqueen@acf4.NYU.EDU (David M. McQueen) writes:
> 
>>/* acf4:comp.lang.fortran / morgan@ms.uky.edu (Wes Morgan) /  3:02 pm  Feb 12, 1990 */
> 
>>> I am attempting to port the PD MATLAB package to a 3B20 with f77.
>>> The following chunk of code refuses to compile:
>>> 
>>>       DOUBLE PRECISION MASK(14),XX,MM
>>>       real mas(2,14)
>>>       equivalence (mask(1),mas(1))
>>>       data mas/
> 
> For the machine which do not allow this syntax for hexadeciaml constants, try
> the followings:
> 
> 	'hexstring'x	or 	x'hexstring'
> 	$hexstring
> 
> the form 'hexstring'x is the most popular form and should work on all machines.
> Anyway, look at your Fortran Reference Manual to see which form of hex.
> constant they support.  They must support one form or another.

On a VAX/VMS machine, the form 'hexstring'x is accepted.  BTW, who is the 
author of the MATLAB package you are modifying?  The person who is working on 
the AMIGA version is Jim Locker and can be reached at:
uunet!dayvb!afitamy!jim.locker if you need to communicate with him directly.
Good luck.

-- 
_____________________________________________________________________________
             ____ ____    ___
Earle Ake   /___ /___/ / /     Science Applications International Corporation
           ____//   / / /__                 Dayton, Ohio
-----------------------------------------------------------------------------
Internet: fac2%dayton.saic.com@uunet.uu.net    uucp: uunet!dayvb!fac2