The A and Aw descriptors are for CHARACTER output. The general form of these descriptors are as follows:
The meaning of r and w are:
Since w is larger than the length of the string, all five characters are printed and right-justified. The result is shown below:WRITE(*,'(A6)') "12345"
Since w is less than the length of the string, only the first six characters are printed. The result is shown below:WRITE(*,'(A6)') "12345678"
Since the A edit descriptor will use the length of the string as the value of w, the above is equivalent to the following:CHARACTER(LEN=5) :: a = "abcde" CHARACTER(LEN=2) :: b = "MI" WRITE(*,'(A)') a WRITE(*,'(A)') b
Therefore, the A edit descriptor is more convenient than Aw.CHARACTER(LEN=5) :: a = "abcde" CHARACTER(LEN=2) :: b = "MI" WRITE(*,'(A5)') a WRITE(*,'(A2)') b
it is equivalent toCHARACTER(LEN=5) :: a = "123" CHARACTER :: b = "*" WRITE(*,"(A,A)") a, b
and the result isCHARACTER(LEN=5) :: a = "123" CHARACTER :: b = "*" WRITE(*,"(A5,A1)") a, b
The first string, a, is of length 5 and hence the first five positions are used. Why are two extra spaces when the string is written as a = "123"? Since the length of a is five and "123" has only three characters, two spaces are added to the right end to make up five characters. Therefore, variable a actually contains five characters: 1, 2, 3 and two spaces. This is why two spaces are between 123 and * in the above output.
In the following table, the WRITE statements are shown at the left and their corresponding output are shown at the right.CHARACTER(LEN=5) :: a = "12345" CHARACTER :: b = "*"