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

Struggles with Fortran Structures...

Krob__Jeff
Beginner
655 Views

All,

I'm currently having fun attempting to translate the 'GPC General Polygon Clipper library' from C to Fortran. Also, in the process, I'm converting from the abstract Pointer-style of memory/data operations to the more understandable (IMO) Allocatable array/Counter style of memory/data operations. it is just easier for me to understand & follow the flow...especially for future support.

Anyway, came across a section where a location in a data structure is trying to be assigned a value & IVF is erroring out. Here is the module & a snippet of code showing the faulty bit...

MODULE POLYGON_TEST
     
  INTEGER :: FALSE=0
  INTEGER :: TRUE=1

  INTEGER :: LEFT    =0
  INTEGER :: RIGHT    =1

  INTEGER :: ABOVE    =0
  INTEGER :: BELOW    =1

  TYPE :: bundle_state                                !    /* Edge bundle state                 */
    INTEGER :: UNBUNDLED=0                            !    /* Isolated edge not within a bundle */
    INTEGER :: BUNDLE_HEAD=1                        !    /* Bundle head node                  */
    INTEGER :: BUNDLE_TAIL=2                        !    /* Passive bundle tail node          */
  END TYPE

  TYPE :: V_SHAPE !*** gpc only                        !    /* Internal vertex list datatype     */
    REAL(8) :: x                                    !    /* X coordinate component            */
    REAL(8) :: y                                    !    /* Y coordinate component            */
    INTEGER :: next                                 !    /* Pointer to next vertex in list    */
  END TYPE
 
  TYPE :: P_SHAPE !*** gpc only                        !    /* Internal contour / tristrip type  */
    INTEGER :: active                                !    /* Active flag / vertex count        */
    INTEGER :: hole                                    !    /* Hole / external contour flag      */
    TYPE (V_SHAPE) :: v(0:1)                        !    /* Left and right vertex list ptrs   */
    INTEGER :: next                                  !    /* Pointer to next polygon contour   */
    INTEGER :: proxy                                 !    /* Pointer to actual structure used  */
  END TYPE

  TYPE :: EDGE_SHAPE !*** gpc only
    TYPE (POINT) :: vertex                            !    /* Piggy-backed contour vertex data  */
    TYPE (POINT) :: bot                                !    /* Edge lower (x, y) coordinate      */
    INTEGER :: Itype                                !    /* Clip / subject edge flag          */
    INTEGER :: bundle(0:1,0:1)                        !    /* Bundle edge flags                 */
    INTEGER :: bside(0:1)                            !    /* Bundle left / right indicators    */
    TYPE (bundle_state) :: bstate(0:1)                !    /* Edge bundle state                 */
    TYPE (P_SHAPE) :: outp(0:1)                        !    /* Output polygon / tristrip pointer */
  END TYPE

END MODULE

program POLYGONTEST
!
USE POLYGON_TEST

! - - - local declarations - - -
  TYPE (EDGE_SHAPE) :: e(0:100)
  TYPE (bundle_state) :: BS


   e(0)%bstate(BELOW) = BS%UNBUNDLED    !<<<error #6303:

   DO i = 1,10
     e(i)%outp(ABOVE) = 0                !<<<error #6303:
     e(i)%outp(BELOW) = 0                !<<<error #6303:


        *
        *
        *
    < snip rest>

 

POLYGON_TEST.f90(72): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.   [0]


What is the way to get those specific type members assigned a value to please the compiler?

 

Thanks in advance,

Jeff

0 Kudos
4 Replies
mecej4
Honored Contributor III
655 Views

Let us try to understand what the compiler is saying, taking just the first line with an error. The left hand side of the assignment statement is of type BUNDLE_STATE (which is composed of three integers), but the right hand side is an expression of type INTEGER. The following modification will work:

   e(0)%bstate(BELOW) = bundle_state(BS%UNBUNDLED,3,4)

Of course, you have to ask yourself what values to use for the second and third components rather than the place-holders '3' and '4'.

You can fix the other errors in the same way.

0 Kudos
Krob__Jeff
Beginner
655 Views

mecej4,

Thanks for the reply. Hmmm...I believe what the code is trying to achieve is that "e(0)%bstate( )" is a one dimensional, 2 element array with addresses from 0 to 1. "ABOVE" & "BELOW" are the values of the addresses 0 & 1 respectively. The struct "bundle_state" is showing 3 options 0,1,2 for UNBUNDLED, BUNDLE_HEAD & BUNDLE_TAIL respectively. Therefor, the line "e(0)%bstate(BELOW) = BS%UNBUNDLED" is trying to assign bstate array address #1 the value of 0. And, of course, the same solution would apply to the e(i)%outp( ) statements as well.

I don't think your code example will accomplish that...right? Also, sorry - I don't understand your reference to "...place-holders '3' and '4'."

Thanks again,

Jeff

0 Kudos
mecej4
Honored Contributor III
655 Views

Here is a run-down of the types of various entities:

e                         array of type edge_shape
e(i)                      type edge_shape
e(i)%outp                 array of type p_shape
e(i)%outp(1)              type p_shape
e(i)%outp(1)%unbundled    integer
e(i)%outp(1)%bundle_head  integer
e(i)%outp(1)%bundle_tail  integer
 

I don't understand your using the word 'option'. You declared type bundle_state as having three distinct integer components. They are all present simultaneously, whether they have been defined (i.e., had values assigned) or not.

I wonder if you were thinking of C unions? Some versions of Fortran provide unions as a non-standard extension, and there is a specific syntax to declare unions.

By "place-holder" I meant to make it clear that those items have to be present, but the values used are to be selected by you. So, I showed meaningless/incorrect values. You would notice that they are present, and replace '2' and '3' by appropriate integers.

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
655 Views

It might help if you show the original C code as opposed to your interpretation of a Fortran implementation.

Jim Dempsey

0 Kudos
Reply