Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Important Update: Community Platform Migration​. Learn more​>
29653 Discussions

Allocatable Derived Type Scalar Array Referencing (I think!)

Intel_C_Intel
Employee
1,101 Views
Code:
program typetest

    implicit none

    ! Variables

    type input
        integer*4 :: ival = 0
        logical*4 :: lval = .FALSE.
        real*8 :: dval = 0.D0
        character :: cval*10 = ' '
    end type

    type output
        integer*4 :: ival = 0
        logical*4 :: lval = .FALSE.
        real*8 :: dval = 0.D0
        character :: cval*10 = ' '
    end type

    type(input), allocatable :: inputs(:)
    type(output), allocatable :: outputs(:)

    integer*4 nCount, alloc_err

    integer*4 ivals(3)        / 1, 2, 3 /
    logical*4 lvals(3)        / .TRUE., .FALSE., .TRUE. /
    real*8    	dvals(3)        / 1.D0, 2.D0, 3.D0 /
    character cvals*10(3)     / 'One', 'Two', 'Three' /

    ! Body of typetest

    allocate(inputs(3), STAT=alloc_err)
    allocate(outputs(3), STAT=alloc_err)

    inputs(:).ival = ivals
    inputs(:).lval = lvals
    inputs(:).dval = dvals
    inputs(:).cval = cvals

    call get_dvals(outputs(:).dval)

    call set_dvals(outputs(:).dval)

end program typetest

!-------------------------------------------------

subroutine get_dvals(dvals)

!-------------------------------------------------
    real*8    dvals(*)
    integer*4 i

    do i = 1, 3
        dvals(i) = dble(i)
    end do

end

!-------------------------------------------------
subroutine set_dvals(dvals)

!-------------------------------------------------
    real*8    dvals(*)
    real*8    local_dvals(3)
    integer*4 i

    do i = 1, 3
        local_dvals(i) = dvals(i)
    end do

end
While the above program works as I intend, I just want to confirm that this method of referencing derived type scalar elements as arrays is a standard feature before I use it in production code.
I looked in the 'array', 'derived type' and 'allocatable' sections of the manual but couldn't find anything about it.
Cheers,
Dan
CVF6.6C, WinXP Pro

Message Edited by judd on 07-27-2005 09:32 AM

0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,101 Views
Yes, this is ok. You are creating an "array section", which will cause copy-in/copy-out to be done when you call the routines.

The case where this is not allowed is if anything to the right of the (:) is a pointer or allocatable.
0 Kudos
Intel_C_Intel
Employee
1,101 Views
Thanks Steve - I've now found the section of the help file I was looking for...guess I just didn't know the terminology.
Dan
0 Kudos
Steven_L_Intel1
Employee
1,101 Views
It's a complex language - and it's going to get worse. My copy of the F2003 standard is almost twice the thickness of the F95 standard!
0 Kudos
Reply