Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fortran 90/95 and derived type structures

Status
Not open for further replies.

billgray1234

Programmer
Mar 14, 2011
39
0
0
i'm using fortran 90/95. i'm using derived type structures. some of these type structures contain other type structures (which, in turn, might contain other type structures, etc). for example, i might have the following :-

TYPE T_T1
TYPE (T_T2) :: T2
END TYPE T_T1


TYPE T_T2
TYPE (T_T3) :: T3
END TYPE T_T2


TYPE T_T3
TYPE (T_T4) :: T4
END TYPE T_T3


...


TYPE T_TN
REAL :: SOME_REAL_VARIABLE
END TYPE T_TN


where N is some positive integer number (i.e. i = 1,2,3,...,N). for this set-up, in my main program (or calling subroutine), i might have a variable as such :-

TYPE (T_T1) :: T1
REAL :: REAL_VARIABLE

REAL_VARIABLE = T1 % T2 % T3 % ... % TN % SOME_REAL_VARIABLE


my question is :- is there a limit on the size of 'N' ? i.e. is there a maximum allowable number of "levels" of type structures that can be "contained" in a type structure ?


for example, if N can be no higher than 5 (i.e. N=5), then my code would look like this :-

REAL_VARIABLE = T1 % T2 % T3 % T4 % T5 % SOME_REAL_VARIABLE


note that i've been writing a simple "test" program, in order to explore this. but, i was also wondering if anyone might know the answer. any help would be much appreciated.
 
There is no limit but your program will start getting inefficient because of the address computations. Say you wanted to increment the value by 1. It would be
Code:
T1%T2%T3%T4%T5%N = T1%T2%T3%T4%T5%N + 1
Alternatively use
Code:
nval => T1%T2%T3%T4%T5%N
nval = nval + 1

It is not a straight computation because some of the stucture members may be pointers to structures. This means that the member offset has to be computed at every level.

For the sake of readability, most people will use the => assignment to break the levels and work within the local scope.
 
thanks for that reply.

i agree with what you said about "too many levels can cause program inefficiency". but, with my program, i have a combination of lots of variables, and lots of subroutines. so, in order to (significantly) reduce the number of dummy arguements, i'm resorting to type structures -- some of which have a number of "levels".

also, regarding your suggestion with using "alternative" local/dummy variables. i'm doing exactly that (where possible) -- for the same reason you suggested. so, thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top