next up previous contents
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_inline21746  type  tex2html_wrap_inline21748 [(LEN= tex2html_wrap_inline21746  length-spec  tex2html_wrap_inline21748 )] [,
 tex2html_wrap_inline21746  attribute-list  tex2html_wrap_inline21748 ] [:: ]
 tex2html_wrap_inline21746  variable-list  tex2html_wrap_inline21748  [ = tex2html_wrap_inline21746  value  tex2html_wrap_inline21748  ]

If tex2html_wrap_inline21746  attribute-list tex2html_wrap_inline21748 or = tex2html_wrap_inline21746  value tex2html_wrap_inline21748 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 1.7.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 1.7.4).


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

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.