- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, this is a rather basic issue, but I would appreciate it if someone could clarify the following.
My problem relates to the following statements, which result in the two Error statements below.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TYPE REG_EXP
integer reg
character(30) name
integer npol
real(dp) SI(3)
real(dp) total
END TYPE REG_EXP
TYPE (REG_EXP) allSI
TYPE (REG_EXP), ALLOCATABLE :: crSI(:)
integer reg
character(30) name
integer npol
real(dp) SI(3)
real(dp) total
END TYPE REG_EXP
TYPE (REG_EXP) allSI
TYPE (REG_EXP), ALLOCATABLE :: crSI(:)
...
ALLOCATE ( crSI (nCresta) )
...
allSI%SI = SUM(crSI%SI, DIM=2) ! ... (1)
Error: A component cannot be an array if the encompassing structure is an array. [SI]
Error: The DIM specification is out-of-range. [2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The intention of statement ... (1) is to aggregate the SI components over all crSI, as per
DO i = 1,nCresta
allSI%SI = allSI%SI + crSI(i)%SI
EN DO
allSI%SI = allSI%SI + crSI(i)%SI
EN DO
ie. I want to determine the 3 components: allSI%SI(1), allSI%SI(2), allSI%SI(3).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At first I thought the first error message was saying a component could not be an array because crSI (the encompassing structure ?) is an array.
Hard to understand why such a restriction was needed, but I have found the Language Reference sections related to derived types a bit obtuse. However, the following example on p. 3-25 appears to suggest it is OK to have an array component
TYPE CHARGE
INTEGER PARTS(40)
REAL LABOR
REAL MILEAGE
END TYPE CHARGE
INTEGER PARTS(40)
REAL LABOR
REAL MILEAGE
END TYPE CHARGE
TYPE(CHARGE) MONTH
TYPE(CHARGE) YEAR(12)
TYPE(CHARGE) YEAR(12)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also, I do not fully understand the following:
p. 3-24: "The number of subscripts in any s-list must equal the rank of the immediately preceding parent or component."
YEAR is a parent? Does that mean that in the above example, PARTS could not be a 2D array, because YEAR is only 1D? But then MONTH (another parent?) has zero rank?
Why does the rank of the "immediately preceding parent" have any thing to do with the number of subscripts a component can have?
Does the above have something to do with the problem I encountered?
It is not clear where my TYPE declaration broke the rules, so I would appreciate it if someone can shed light on what I am doing wrong.
David
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your major problem is the value of the DIM-argument of SUM, because the rank (number of dimensions) of the SI-array is 1.
Further the derived type crSI is an array itself, so the argument in SUM should have a subscript. The first argument of SUM must be an array of type integer, real or complex (page 9.114 of the Language Ref. Manual) and NOT an derived type!
I think, that what you want to do cannot be achieved with SUM. The solution is the DO-loop you already mentioned.
The sentence "immediately preceding parent" is also not clear to me.
I think the compiler will state that DIM=2 does not correspond with the number of subscripts of the the component SI of the derived type.
Guus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes & thanks
As you note, the problem is with the SUM. I have now replaced it with the DO loop ( - with corrected "END DO" !).
I guess I was being thrown by the first error statement ( Error: A component cannot be an array if the encompassing structure is an array. [SI] ).
The Error statement seems misleading. The only change required to make it work is to substitute the DO loop for the SUM.
I prefer to use "matrix notation" in place of DO loops whenever possible, but seems it is not possible in this case. I had assumed the derived type was the equivalent of a 2D array.
David
As you note, the problem is with the SUM. I have now replaced it with the DO loop ( - with corrected "END DO" !).
I guess I was being thrown by the first error statement ( Error: A component cannot be an array if the encompassing structure is an array. [SI] ).
The Error statement seems misleading. The only change required to make it work is to substitute the DO loop for the SUM.
I prefer to use "matrix notation" in place of DO loops whenever possible, but seems it is not possible in this case. I had assumed the derived type was the equivalent of a 2D array.
David

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