- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
endWhile 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
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
The case where this is not allowed is if anything to the right of the (:) is a pointer or allocatable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page