character C or character :: C
For a string of characters, we can specify the length and (optionally) initialize it as
character(len=7) :: LOGIN
Again we see that, if we want to specify more than one attribute (here, character and length) the double colon form is needed.
We can have constant (PARAMETER) characters/strings, in which case we use the declaration
character(len=8), parameter :: LOGIN="johndoe"(the F77 two-statement form is also acceptable). Here the initialization value is 6-character long, so it will be padded by 2 blanks to fit the declared length. Similarly, if the initialization value was too long, it would have been truncated to the declared length.
Alternatively, we may let the character variable assume the length of the initialization string with
character(len=*), parameter :: LOGIN="johndoe", PASSWORD="michigantech"Here LOGIN will be 7-character, and PASSWORD 12-character long.
The following equivalent form of declaration is also accepted (for back-compatibility with F77):
character*8 :: LOGINThe LEN attribute can be overriden by a attribute in a string declaration as follows:
character(len=8) :: LOGIN, PASSWORD*12Here LOGIN is a string of 8 characters, but PASSWORD is a string of 12 characters.
Note that a string is a scalar; in particular it is NOT an array of characters. For example, it is possible to declare a matrix whose elements are 6-character long strings:
character(len=6), dimension(10,10) :: AA string can be split accross lines by adding an ampersand & both at the end of the current line and at the beginning of the next. For example
"michig& \&antech"