next up previous
Next: Constants (Parameters) Up: Data Objects Previous: Numeric and Logical Declarations

 

Character Declarations

Character variables can be declared in a similar way to numeric types using a CHARACTER statement. CHARACTER variables can

A simplified syntax follows,

 
 tex2html_wrap_inline21419  type  tex2html_wrap_inline21421 [(LEN= tex2html_wrap_inline21419  length-spec  tex2html_wrap_inline21421 )] [,
 tex2html_wrap_inline21419  attribute-list  tex2html_wrap_inline21421 ] [:: ]
 tex2html_wrap_inline21419  variable-list  tex2html_wrap_inline21421  [ = tex2html_wrap_inline21419  value  tex2html_wrap_inline21421  ]

If tex2html_wrap_inline21419  attribute-list tex2html_wrap_inline21421 or = tex2html_wrap_inline21419  value tex2html_wrap_inline21421 are present then so must be ::.

The following are all valid declarations,

    CHARACTER(LEN=10)  :: name
    CHARACTER          :: sex
    CHARACTER(LEN=32)  :: str

In the same way as the DIMENSION attribute was overridden in the example of Section 11.4 so can the string length declaration (specified by LEN=); this is achieved using the * notation. If a DIMENSION specifier is present it can also be overridden. The length specifier must come after the dimension if both are being overridden.

    CHARACTER(LEN=10) :: name, sex*1, str*32
    CHARACTER(LEN=10), DIMENSION(10,10) :: tom(10)*2, dick, harry(10,10,10)*20
    CHARACTER, POINTER :: P2ch

The first line is exactly the same as the previous declaration.

There is a substantial difference between a character variable of 10 characters (CHARACTER(LEN=10) or CHARACTER*10) and an array of 10 elements; the first is scalar and the second is non-scalar.

Other attributes can be added in the same way as for numeric types (see Section 11.4).


next up previous
Next: Constants (Parameters) Up: Data Objects Previous: Numeric and Logical Declarations

Adam Marshall ©University of Liverpool, 1996
Wed Oct 9 17:57:29 BST 1996