STRUCTURE [/structure_name/][field_namelist]Where:
field_declaration
[field_declaration]
... [field_declaration]
END STRUCTURE
Field names within the same declaration nesting level must be unique, but an inner structure declaration can include field names used in an outer structure declaration without conflict. Also, because records use periods to separate fields, it is not legal to use relational operators (for example, .EQ., .XOR.), logical constants (.TRUE. or .FALSE.), or logical expressions (.AND., .NOT., .OR.) as field names in structure declarations.
Fields in a structure are aligned as required by hardware; therefore a structure's storage requirements are machine-dependent. Because explicit padding of records is not necessary, the compiler recognizes the %FILL intrinsic, but performs no action in response to it.
Data initialization can occur for the individual fields.
RECORD /structure_name/record_namelistWhere:
[,/structure_name/record_namelist]
... [,/structure_name/record_namelist]
You can access individual fields in a record by combining the parent record name, a period (.), and the field name (for example, recordname.fieldname). For records, a scalar reference means a reference to a name that resolves to a single typed data item (for example, INTEGER), while an aggregate reference means a reference that resolves to a structured data item.
Scalar field references may appear wherever normal variable or array elements may appear with the exception of COMMON, SAVE, NAMELIST, DATA and EQUIVALENCE statements. Aggregate references may only appear in aggregate assignment statements, unformatted I/O statements, and as parameters to subprograms.
The following is an example of RECORD and STRUCTURE usage.
STRUCTURE /person/ ! Declare a structure to define a person
INTEGER id
LOGICAL living
CHARACTER*5 first, last, middle
INTEGER age
END STRUCTURE
! Define population to be an array where each element is of
! type person. Also define a variable, me, of type person.
RECORD /person/ population(2), me
...
me.age = 34 ! Assign values for the variable me to
me.living = .TRUE. ! some of the fields.
me.first = 'Steve'
me.id = 542124822
...
population(1).last = 'Jones' ! Assign the "last" field of
! element 1 of array population.
population(2) = me ! Assign all the values of record
! "me" to the record population(2)
Union declarations are used when one wants to use the same area of memory to alternately contain two or more groups of fields. Whenever one of the fields declared by a union declaration is referenced in a program, that field and any other fields in its map declaration become defined. Then, when a field in one of the other map declarations in the union declaration is referenced, the fields in that map declaration become defined, superseding the fields that were previously defined.
A union declaration is initiated by a UNION statement and terminated by an END UNION statement. Enclosed within these statements are one or more map declarations, initiated and terminated by MAP and END MAP statements, respectively. Each unique field or group of fields is defined by a separate map declaration. The format of a UNION statement is as follows:
UNIONThe format of the map_declaration is as follows:
map_declaration
[map_declaration]
...
[map_declaration]
END UNION
MAPwhere field_declaration is a structure declaration or RECORD statement contained within a union declaration, a union declaration contained within a union declaration, or the declaration of a typed data field within a union.
field_declaration
[field_declaration]
...
[field_declaration]
END MAP
Data can be initialized in field declaration statements in union declarations. Note, however, it is illegal to initialize multiple map declarations in a single union.
Field alignment within multiple map declarations is performed as previously defined in structure declarations.
The size of the shared area for a union declaration is the size of the largest map defined for that union. The size of a map is the sum of the sizes of the field(s) declared within it plus the space reserved for alignment purposes.
Manipulating data using union declarations is similar to what happens using EQUIVALENCE statements. However, union declarations are probably more similar to union declarations for the language C. The main difference is that the language C requires one to associate a name with each "map" (union). Fortran field names must be unique within the same declaration nesting level of maps.
The following is an example of RECORD, STRUCTURE, MAP and UNION usage. The size of each element of the recarr array would be the size of typetag (4 bytes) plus the size of the largest MAP, the employee map (24 bytes).
STRUCTURE /account/
INTEGER typetag ! Tag to determine defined map.
UNION
MAP ! Structure for an employee
CHARACTER*12 ssn ! Social Security Number
REAL*4 salary
CHARACTER*8 empdate ! Employment date
END MAP
MAP ! Structure for a customer
INTEGER*4 acct_cust
REAL*4 credit_amt
CHARACTER*8 due_date
END MAP
MAP ! Structure for a supplier
INTEGER*4 acct_supp
REAL*4 debit_amt
BYTE num_items
BYTE items(12) ! Items supplied
END MAP
END UNION
END STRUCTURE RECORD /account/ recarr(1000)
The syntax of the POINTER statement is:
POINTER (p1, v1) [, (p2, v2) ...]
REAL XC(10)
COMMON IC, XC
POINTER (P, I)
POINTER (Q, X(5))
P = LOC(IC)
I = 0 ! IC gets 0
P = LOC(XC)
Q = P + 20 ! same as LOC(XC(6))
X(1) = 0 ! XC(6) gets 0 ALLOCATE (X) ! Q locates an allocated memory area
'c1c2...cn'OThe form of a hexadecimal constant is:
'a1a2...an'Xwhere ci is a digit in the range 0 to 7 and ai is a digit in the range 0 to 9 or a letter in the range A to F or a to f (case mixing is allowed). You can specify up to 64 bits (22 octal digits or 16 hexadecimal digits).
Octal and hexadecimal constants are stored as either 32-bit or 64-bit quantities. They are padded on the left with zeroes if needed and assume data types based on how they are used.
The following are the rules for converting these data types:
I = '1234'X ! Leftmost Pad with zero.
J = '1234567'X ! Truncate Leftmost 3 hex digits
D = '40000123456789ab'X
D = NEQV(D,'ff'X) ! 64-bit Exclusive Or
A union declaration is initiated by a UNION statement and terminated by an END UNION statement. Enclosed within these statements are one or more map declarations, initiated and terminated by MAP and END MAP statements, respectively. Each unique field or group of fields is defined by a separate map declaration.
Syntax
MAP
field_declaration
[field_declaration]
...
[field_declaration]
END MAP
Description
Data can be initialized in field declaration statements in union declarations. Note, however, it is illegal to initialize multiple map declarations in a single union.
The size of the shared area for a union declaration is the size of the largest map defined for that union. The size of a map is the sum of the sizes of the field(s) declared within it plus the space reserved for alignment purposes.
Manipulating data using union declarations is similar to what happens using EQUIVALENCE statements. However, union declarations are probably more similar to union declarations for the language C. The main difference is that the language C requires one to associate a name with each map (union). Fortran field names must be unique within the same declaration nesting level of maps.
Example
The following is an example of RECORD, STRUCTURE and UNION usage. The size of each element of the recarr array would be the size of typetag (4 bytes) plus the size of the largest MAP - the employee map (24 bytes).
STRUCTURE /account/
INTEGER typetag ! Tag to determine defined map.
UNION
MAP ! Structure for an employee
CHARACTER*12 ssn ! Social Security Number
REAL*4 salary
CHARACTER*8 empdate ! Employment date
END MAP
MAP ! Structure for a customer
INTEGER*4 acct_cust
REAL*4 credit_amt
CHARACTER*8 due_date
END MAP
MAP ! Structure for a supplier
INTEGER*4 acct_supp
REAL*4 debit_amt
BYTE num_items
BYTE items(12) ! Items supplied
END MAP
END UNION
END STRUCTURE RECORD /account/ recarr(1000)
The RECORD statement defines a user-defined aggregate data item.
Syntax
RECORD /structure_name/record_namelist
[,/structure_name/record_namelist]
... [,/structure_name/record_namelist] END RECORD
Description
You create memory storage for a record by specifying a structure name in the RECORD statement. You define the field values in a record either by defining them in the structure declaration or by assigning them with executable code.
You can access individual fields in a record by combining the parent record name, a period (.), and the field name (for example, recordname.fieldname). For records, a scalar reference means a reference to a name that resolves to a single typed data item (for example, INTEGER), while an aggregate reference means a reference that resolves to a structured data item.
Scalar field references may appear wherever normal variable or array elements may appear with the exception of the COMMON, SAVE, NAMELIST, DATA and EQUIVALENCE statements. Aggregate references may only appear in aggregate assignment statements, unformatted I/O statements, and as parameters to subprograms.
Records are allowed in COMMON and DIMENSION statements.
Example
STRUCTURE /PERSON/ ! Declare a structure to define a person
INTEGER ID
LOGICAL LIVING
CHARACTER*5 FIRST, LAST, MIDDLE
INTEGER AGE
END STRUCTURE
! Define population to be an array where each element is of
! type person. Also define a variable, me, of type person.
RECORD /PERSON/ POPULATION(2), ME
...
ME.AGE = 34 ! Assign values for the variable me to
ME.LIVING = .TRUE. ! some of the fields.
ME.FIRST = 'Steve'
ME.ID = 542124822
...
POPULATION(1).LAST = 'Jones' ! Assign the "LAST" field of
! element 1 of array population.
POPULATION(2) = ME ! Assign all the values of record
! "ME" to the record population(2)
The STRUCTURE statement defines an aggregate data type.
Syntax
STRUCTURE [/structure_name/][field_namelist]
field_declaration
[field_declaration]
... [field_declaration]
END STRUCTURE
Description
Fields within structures conform to machine-dependent alignment requirements. Alignment of fields also provides a C-like "struct" building capability and allows convenient inter-language communications.
Field names within the same declaration nesting level must be unique, but an inner structure declaration can include field names used in an outer structure declaration without conflict. Also, because records use periods to separate fields, it is not legal to use relational operators (for example, .EQ., .XOR.), logical constants (.TRUE. or .FALSE.), or logical expressions (.AND., .NOT., .OR.) as field names in structure declarations.
Fields in a structure are aligned as required by hardware and a structure's storage requirements are therefore machine-dependent. Note that VAX/VMS Fortran does no padding. Because explicit padding of records is not necessary, the compiler recognizes the %FILL intrinsic, but performs no action in response to it.
Data initialization can occur for the individual fields.
The UNION and MAP statements are supported.
The following is an example of record and structure usage.
STRUCTURE /account/
INTEGER typetag ! Tag to determine defined map.
UNION
MAP ! Structure for an employee
CHARACTER*12 ssn ! Social Security Number
REAL*4 salary
CHARACTER*8 empdate ! Employment date
END MAP
MAP ! Structure for a customer
INTEGER*4 acct_cust
REAL*4 credit_amt
CHARACTER*8 due_date
END MAP
MAP ! Structure for a supplier
INTEGER*4 acct_supp
REAL*4 debit_amt
BYTE num_items
BYTE items(12) ! Items supplied
END MAP
END UNION
END STRUCTURE RECORD /account/ recarr(1000)
A union declaration is a multistatement declaration defining a data area that can be shared intermittently during program execution by one or more fields or groups of fields. It declares groups of fields that share a common location within a structure. Each group of fields within a union declaration is declared by a map declaration, with one or more fields per map declaration.
Syntax
UNIONThe format of the map_declaration is as follows:
map_declaration
[map_declaration]
...
[map_declaration]
END UNION
MAP
field_declaration
[field_declaration]
...
[field_declaration]
END MAP
Description
Union declarations are used when one wants to use the same area of memory to alternately contain two or more groups of fields. Whenever one of the fields declared by a union declaration is referenced in a program, that field and any other fields in its map declaration become defined. Then, when a field in one of the other map declarations in the union declaration is referenced, the fields in that map declaration become defined, superseding the fields that were previously defined.
A union declaration is initiated by a UNION statement and terminated by an END UNION statement. Enclosed within these statements are one or more map declarations, initiated and terminated by MAP and END MAP statements, respectively. Each unique field or group of fields is defined by a separate map declaration. The format of a UNION statement is as follows:
Data can be initialized in field declaration statements in union declarations. Note, however, it is illegal to initialize multiple map declarations in a single union.
The size of the shared area for a union declaration is the size of the largest map defined for that union. The size of a map is the sum of the sizes of the field(s) declared within it plus the space reserved for alignment purposes.
Manipulating data using union declarations is similar to what happens using EQUIVALENCE statements. However, union declarations are probably more similar to union declarations for the language C. The main difference is that the language C requires one to associate a name with each map (union). Fortran field names must be unique within the same declaration nesting level of maps.
The following is an example of RECORD, STRUCTURE and UNION usage. The size of each element of the recarr array would be the size of typetag (4 bytes) plus the size of the largest MAP - the employee map (24 bytes).
STRUCTURE /account/
INTEGER typetag ! Tag to determine defined map.
UNION
MAP ! Structure for an employee
CHARACTER*12 ssn ! Social Security Number
REAL*4 salary
CHARACTER*8 empdate ! Employment date
END MAP
MAP ! Structure for a customer
INTEGER*4 acct_cust
REAL*4 credit_amt
CHARACTER*8 due_date
END MAP
MAP ! Structure for a supplier
INTEGER*4 acct_supp
REAL*4 debit_amt
BYTE num_items
BYTE items(12) ! Items supplied
END MAP
END UNION
END STRUCTURE RECORD /account/ recarr(1000)
There are three CM Fortran intrinsics which have names identical to their Fortran 90 counterparts but whose calling sequences differ. These are CSHIFT, EOSHIFT, and RESHAPE. If pghpf is invoked with the compiler switch -Mcmf these three intrinsics will be interpreted using the CM Fortran convention rather than the standard Fortran 90 convention. It's worth noting that there are 6 additional non-standard intrinsics in CM Fortran: PROJECT, LASTLOC, FIRSTLOC, RANK, DIAGONAL, and REPLICATE. These non-standard intrinsics are not supported by pghpf. Other features of CM Fortran that are not supported are the layout directives and the utility routines.
Synopsis
CSHIFT(ARRAY, DIM, SHIFT )
Arguments
The argument ARRAY is the array to shift. It may be an array of any type.The argument DIM is an integer representing the dimension to shift. The argument SHIFT is an integer or an array of integers with rank n-1 where n is the rank of ARRAY.
Return Value
The shifted array with the same size and shape as the argument ARRAY.
Synopsis
CSHIFT(ARRAY, DIM, SHIFT, BOUNDARY )
Arguments
The argument ARRAY is the array to shift. It may be an array of any type. The argument DIM is an integer representing the dimension to shift. The argument SHIFT is an integer or an array of integers with rank n-1 where n is the rank of ARRAY. The optional argument BOUNDARY is of the same type as the array, it may be scalar or of rank n-1 where n is the rank of ARRAY. BOUNDARY is the value to fill in the shifted out positions. By default it has the following values for integer, 0, for real, 0.0, for complex, (0.0,0.0), for logical false, for character, the default is blank characters.
Return Value
The shifted array with the same size and shape as the argument ARRAY.
Synopsis
RESHAPE(SHAPE, SOURCE, PAD, ORDER)
Arguments
The argument SHAPE is of type integer, rank one. It must not have more than 7 elements and no values can be negative. The argument SOURCE is an array of any type. The optional argument PAD must be the same size and type as SOURCE. The optional argument ORDER must be of type integer and must have the same shape as SHAPE.
Return Value
The return value is an array of shape SHAPE, with the same type as SOURCE. Array elements are filled into the new array in array element order.
PARAMETER p=c [,p=c]...where p is a symbolic name and c is a constant, symbolic constant, or a compile time constant expression.