- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Defining record structure members as static parameters
Can anyone tell me if members of a record structure can be defined with static values. Can the parameter statement
be used in this regard. For example, let's say you wish to create two variables of the same structure, one containing the base values (which would be static) and one which has varying values. How do you define static values for each of the structure's members?
Structure /XYZ/
Logical BUS_BUSY
Real x_float
Integer y_int
End Structure
Record /XYZ/ XYX_var, XYZ_base
I have used the PARAMETER statement in several dozen different ways without luck.
Has anyone solved this previously??
Thanks in advance.
mjfinney
Can anyone tell me if members of a record structure can be defined with static values. Can the parameter statement
be used in this regard. For example, let's say you wish to create two variables of the same structure, one containing the base values (which would be static) and one which has varying values. How do you define static values for each of the structure's members?
Structure /XYZ/
Logical BUS_BUSY
Real x_float
Integer y_int
End Structure
Record /XYZ/ XYX_var, XYZ_base
I have used the PARAMETER statement in several dozen different ways without luck.
Has anyone solved this previously??
Thanks in advance.
mjfinney
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm. First of all, you can specify initial values for fields in a structure. For example:
Then, any RECORD of this type will get statically (one time) initialized to these values. It is interesting to note that this is one area where STRUCTURE/RECORD is not the same as Fortran 90 derived type - if you had done the same thing with derived types, and the variable was a routine local, it would get reinitialized on every entry to the routine, unless you made the variable SAVE.
Now you CAN create a PARAMETER constant of a structure type, but you have to speak Fortran 90. For example:
I'm not sure exactly what you want - you could define a type (structure) with some fields initialized and then selectively assign to particular fields later (there is no way to create a structure constructor (that's what that PARAMETER value above has) that skips some fields. If you just want a way to assign at run-time a preselected set of fields, then the PARAMETER idea above will work.
Steve
structure /XYZ/ logical BUS_BUSY /.TRUE./ real x_float /3.0/ integer y_int /4/ end structure
Then, any RECORD of this type will get statically (one time) initialized to these values. It is interesting to note that this is one area where STRUCTURE/RECORD is not the same as Fortran 90 derived type - if you had done the same thing with derived types, and the variable was a routine local, it would get reinitialized on every entry to the routine, unless you made the variable SAVE.
Now you CAN create a PARAMETER constant of a structure type, but you have to speak Fortran 90. For example:
type(XYZ), PARAMETER :: my_const = XYZ(.TRUE.,3.0,4) type(XYZ) XYX_VAR XYX_VAR = my_const
I'm not sure exactly what you want - you could define a type (structure) with some fields initialized and then selectively assign to particular fields later (there is no way to create a structure constructor (that's what that PARAMETER value above has) that skips some fields. If you just want a way to assign at run-time a preselected set of fields, then the PARAMETER idea above will work.
Steve

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