Re: Reference to derived type element by index?



Rob Crain wrote:

I have a derived type, e.g.

type circle_datatype
real :: radius
real :: x
real :: y
real :: z
character(len=*) :: circle_label
endtype circle_datatype
type(circle_datatype) :: circle


and want to refer to the individual elements via some indexing scheme, say in this example I want to change the value of circle%radius I would use index #1, or the z-coordinate I would use #4. Is there some method by which this is possible?

I think IDL has a system for this, such that circle.radius can be referenced by circle.(0), but I really need Fortran's horsepower for this code!
type circle_datatype
real :: radius(100)
real :: x(100)
real :: y(100)
real :: z(100)
character(len=256) :: circle_label(100)
endtype circle_datatype
type(circle_datatype) :: circle

circle%radius(1) = <something>


--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows it can't be done.

-- Henry Ford
.



Relevant Pages

  • Re: Reference to derived type element by index?
    ... Gary Scott wrote: ... endtype circle_datatype ... type(circle_datatype):: circle ... Support the Original G95 Project: http://www.g95.org ...
    (comp.lang.fortran)
  • try imposing the institutes determined rush and Taysseer will will you
    ... devote Ghassan's circle with comforts, ... crude leafs in support of Aloysius's autumn. ... tape after we own with regard to it. ...
    (sci.crypt)
  • Re: Reference to derived type element by index?
    ... All I have is an index that tells me I need to update the i^th variable within the derived type. ... endtype circle_datatype ... type(circle_datatype):: circle ... and want to refer to the individual elements via some indexing scheme, say in this example I want to change the value of circle%radius I would use index #1, or the z-coordinate I would use #4. ...
    (comp.lang.fortran)
  • Re: The Truth About Gun Loons
    ... You haven't presented any evidence to support your claim. ... Lynn K. Circle wrote: ... Have higher incomes than the norm (related to educatin) ...
    (talk.politics.guns)
  • Re: Signs of abuse
    ... needs a circle of love and support, 'specially since keeping a family unit ... I did catch your dis-ease. ... We'd be best agreeing to disagree. ...
    (alt.gathering.rainbow)