STRUCTURE/RECORD usage on VAX & SGI 
Author Message
 STRUCTURE/RECORD usage on VAX & SGI

The following code fragment involves usage of RECORD and STRUCTURE we are
trying to port from a VAX to SGI ( IRIX 5.3 ).
The code consists of a MAIN routine and two subroutines ( SUBROU1 & SUBROU2 )
All that is being done is to pass RECORDs in and out of the subroutines.
In SUBROU1 where the RECORD and the instance ( sorry ) created have names
that are different, the code works ( see attached output ).
In SUBROU2 where the RECORD and the instance ( sorry ) created have identical
names , the code fails ( see attached output ).
My question is short in what ahould happen when you have RECORD and STRUCT
definitions per SUBROU2. Which behaviour is correct VAX or SGI.
My own personal inclination would be not to give a type definition the same
name as an instance ( sorry again ) thereof but this is legacy code.

**************
PROGRAM SOURCE
**************

C234567
      PROGRAM   MAIN
      IMPLICIT  NONE

      STRUCTURE / STRUCA /
          INTEGER       TEMPI1
      END STRUCTURE  ! STRUCA
      RECORD / STRUCA / STRUCA_LEFT
      RECORD / STRUCA / STRUCA_RGHT
      COMMON  / STRUCA_LEFT / STRUCA_LEFT
      COMMON  / STRUCA_RGHT / STRUCA_RGHT

      STRUCTURE / STRUCB /
          INTEGER       TEMPI2          ! (frg to bkg)
      END STRUCTURE  ! STRUCB
      RECORD / STRUCB / STRUCB_LEFT
      RECORD / STRUCB / STRUCB_RGHT
      COMMON  / STRUCB_LEFT / STRUCB_LEFT
      COMMON  / STRUCB_RGHT / STRUCB_RGHT

      PARAMETER LEFT    = 0
      PARAMETER RGHT    = 1

      STRUCA_LEFT.TEMPI1                = 1
      STRUCB_LEFT.TEMPI2                = 10
      STRUCA_RGHT.TEMPI1                = 2
      STRUCB_RGHT.TEMPI2                = 20

      WRITE(*,'('' MAIN   :STRUCA_LEFT.TEMPI1 = '',I2)')        STRUCA_LEFT.TEMPI1
      WRITE(*,'(''         STRUCB_LEFT.TEMPI2 = '',I2)')        STRUCB_LEFT.TEMPI2
      WRITE(*,'(''         STRUCA_RGHT.TEMPI1 = '',I2)')        STRUCA_RGHT.TEMPI1
      WRITE(*,'(''  OUT    STRUCB_RGHT.TEMPI2 = '',I2)')        STRUCB_RGHT.TEMPI2

      CALL  SUBROU1( LEFT, STRUCA_LEFT, STRUCB_LEFT )
      CALL  SUBROU1( RGHT, STRUCA_RGHT, STRUCB_RGHT )

      CALL  SUBROU2( LEFT, STRUCA_LEFT, STRUCB_LEFT )
      CALL  SUBROU2( RGHT, STRUCA_RGHT, STRUCB_RGHT )

      WRITE(*,'('' MAIN   :STRUCA_LEFT.TEMPI1 = '',I2)')        STRUCA_LEFT.TEMPI1
      WRITE(*,'(''         STRUCB_LEFT.TEMPI2 = '',I2)')        STRUCB_LEFT.TEMPI2
      WRITE(*,'(''         STRUCA_RGHT.TEMPI1 = '',I2)')        STRUCA_RGHT.TEMPI1
      WRITE(*,'(''  OUT    STRUCB_RGHT.TEMPI2 = '',I2)')        STRUCB_RGHT.TEMPI2

      STOP
      END

      SUBROUTINE  SUBROU1( SIDE, LSTRUCA, LSTRUCB )
      IMPLICIT  NONE

      STRUCTURE / STRUCA /
          INTEGER       TEMPI1
      END STRUCTURE  ! STRUCA

      STRUCTURE / STRUCB /
          INTEGER       TEMPI2          ! (frg to bkg)
      END STRUCTURE  ! STRUCB

      INTEGER SIDE                      ! Input side
      RECORD / STRUCA /  LSTRUCA        ! Input STRUCA
      RECORD / STRUCB /  LSTRUCB        ! Input fg - to - bg struct

C
      WRITE(*,'('' SUBROU1:LSTRUCA.TEMPI1 = '',I2)')    LSTRUCA.TEMPI1
      WRITE(*,'(''   IN    LSTRUCB.TEMPI2 = '',I2)')    LSTRUCB.TEMPI2

      LSTRUCA.TEMPI1            = 5
      LSTRUCB.TEMPI2            = 55

      WRITE(*,'('' SUBROU1:LSTRUCA.TEMPI1 = '',I2)')    LSTRUCA.TEMPI1
      WRITE(*,'(''   OUT   LSTRUCB.TEMPI2 = '',I2)')    LSTRUCB.TEMPI2
C

      RETURN
      END

      SUBROUTINE  SUBROU2( SIDE, STRUCA, STRUCB )
      IMPLICIT  NONE

      STRUCTURE / STRUCA /
          INTEGER       TEMPI1
      END STRUCTURE  ! STRUCA

      STRUCTURE / STRUCB /
          INTEGER       TEMPI2          ! (frg to bkg)
      END STRUCTURE  ! STRUCB

      INTEGER SIDE                      ! Input side
      RECORD / STRUCA / STRUCA          ! Input STRUCA
      RECORD / STRUCB / STRUCB          ! Input fg - to - bg struct

C
      WRITE(*,'('' SUBROU2:STRUCA.TEMPI1 = '',I2)')     STRUCA.TEMPI1
      WRITE(*,'(''   IN    STRUCB.TEMPI2 = '',I2)')     STRUCB.TEMPI2

      STRUCA.TEMPI1             = 9
      STRUCB.TEMPI2             = 99

      WRITE(*,'('' SUBROU2:STRUCA.TEMPI1 = '',I2)')     STRUCA.TEMPI1
      WRITE(*,'(''   OUT   STRUCB.TEMPI2 = '',I2)')     STRUCB.TEMPI2
C

      RETURN
      END

**************
PROGRAM OUTPUT
**************

 MAIN   :STRUCA_LEFT.TEMPI1 =  1
         STRUCB_LEFT.TEMPI2 = 10
         STRUCA_RGHT.TEMPI1 =  2
  OUT    STRUCB_RGHT.TEMPI2 = 20
 SUBROU1:LSTRUCA.TEMPI1 =  1
   IN    LSTRUCB.TEMPI2 = 10
 SUBROU1:LSTRUCA.TEMPI1 =  5
   OUT   LSTRUCB.TEMPI2 = 55
 SUBROU1:LSTRUCA.TEMPI1 =  2
   IN    LSTRUCB.TEMPI2 = 20
 SUBROU1:LSTRUCA.TEMPI1 =  5
   OUT   LSTRUCB.TEMPI2 = 55
 SUBROU2:STRUCA.TEMPI1 =  0
   IN    STRUCB.TEMPI2 =  0
 SUBROU2:STRUCA.TEMPI1 =  9
   OUT   STRUCB.TEMPI2 = 99
 SUBROU2:STRUCA.TEMPI1 =  9
   IN    STRUCB.TEMPI2 = 99
 SUBROU2:STRUCA.TEMPI1 =  9
   OUT   STRUCB.TEMPI2 = 99
 MAIN   :STRUCA_LEFT.TEMPI1 =  5
         STRUCB_LEFT.TEMPI2 = 55
         STRUCA_RGHT.TEMPI1 =  5
  OUT    STRUCB_RGHT.TEMPI2 = 55
--
################ No Times Like The Maritimes, Eh! ######################


# Opinions expressed here are mine, mine, mine.(YOOHOO[PU,PCP,PGP])#####



Sun, 01 Nov 1998 03:00:00 GMT  
 STRUCTURE/RECORD usage on VAX & SGI



Quote:

> The following code fragment involves usage of RECORD and STRUCTURE we are
> trying to port from a VAX to SGI ( IRIX 5.3 ).
> The code consists of a MAIN routine and two subroutines ( SUBROU1 & SUBROU2 )
> All that is being done is to pass RECORDs in and out of the subroutines.
> In SUBROU1 where the RECORD and the instance ( sorry ) created have names
> that are different, the code works ( see attached output ).
> In SUBROU2 where the RECORD and the instance ( sorry ) created have identical
> names , the code fails ( see attached output ).
> My question is short in what ahould happen when you have RECORD and STRUCT
> definitions per SUBROU2. Which behaviour is correct VAX or SGI.

                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        Well, since STRUCTURE/RECORD  was  invented  by  and for VAX/VMS
    fortran,  the  VAX is correct _by definition_.  It seems SGI  didn't
    get it quite right...  And that should be clear  since  neither  the
    STRUCTURE  names  nor  the RECORD names are in any way global.  From
    the current Digital Fortran documentation:

        "Subsequent RECORD  statements  use  the  structure  name to
        refer to the structure.  A _structure name_ must be _unique_
        among  _structure  names_, but structures can _share  names_
        with variables (scalar or array), record  fields,  PARAMETER
        constants,  and common blocks.  So, it is possible to have a
        variable named X, a structure  named  X,  one or more fields
        named  X,  a PARAMETER constant named X, and a common  block
        named X."  [emphasis mine]

    So it's clear that SGI needs  some  help here...  (The code's use of
    RECORDs  in  COMMON might be another interesting compatibility  test
    for SGI, but since the COMMONs aren't referenced in the subroutines,
    they should be irrelevant.)

Quote:
> My own personal inclination would be not to give a type definition the same
> name as an instance ( sorry again ) thereof but this is legacy code.

                                                  ^^^^^^^^^^^^^^^^^^^

        The Digital Fortran  documentation  explicitly allows structures
    to share names with record variables, but I'd agree that the _style_
    is questionable.

        Kind of interesting to call  the use of STRUCTURE/RECORD "legacy
    code",  but I guess any code being ported to the "latest & greatest"
    platform is by definition "legacy".  :-) We  didn't  get  STRUCTURE/
    RECORD  until  VMS  V4.x  (I  think, could have been late in V3) and
    that's only, well, about 7-10 years ago.  Well, OK, 7 to 10 years is
    an eternity in the computer  industry,  but  just the same, this was
    one of the last "new features" or extensions added to Fortran 77 (on
    VMS),  not  counting  the  Fortran 90 features being  added  to  F77
    compilers.  Fortran 90 has  picked  up  the  idea  as  "user-defined
    types",  although  I don't think they've done as nice a job at it as
    the S/R in Digital Fortran...  So this legacy stuff is actually some
    of the latest and greatest stuff in Fortran! :-)

        -Ken
--

 SLAC, P.O.Box 4349, MS 46  |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
 Stanford, CA   94309       |  Voice:    415-926-2924    FAX: 415-926-3515
 -------------------------------------------------------------------------
 These opinions are mine, not SLAC's, Stanford's, nor the DOE's...



Tue, 03 Nov 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Advice on porting to F90 from F77 w/VAX structure record extensions

2. C4B - Declaring & using Record Structure

3. VAX-VMS 2 SGI-Unix port

4. SGI IRIX 5.3 Fortran "Datapool" usage

5. usage of assumed shape and performance on SGI,f90

6. Data structures and porting from VAX to LINUX

7. Will f2c do VAX structures?

8. Emulating VAX structures

9. STRUCTURE in Fortran77 (SGI != IBM) ?

10. VAX Structure Support on IBM RS6K?

11. UNIX and VAX structure implementation similarities

12. Structure Chart for VAX/VMS F77

 

 
Powered by phpBB® Forum Software