Software Archive
Read-only legacy content
17061 Discussions

Defining record structure members as static parameters

mjfinney
Beginner
234 Views
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
0 Kudos
1 Reply
Steven_L_Intel1
Employee
234 Views
Hmm. First of all, you can specify initial values for fields in a structure. For example:


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
0 Kudos
Reply