Документ взят из кэша поисковой машины. Адрес оригинального документа : http://star.arm.ac.uk/f77to90/c4.html
Дата изменения: Sat Feb 17 19:41:00 1996
Дата индексирования: Mon Oct 1 20:58:16 2012
Кодировка:

Поисковые слова: jet
Format

4. Format

The old Fortran programs have used numbering of the format statements. However, that doesn't look very well in pure Fortran 90, where you don't use statement numbers except in a few exceptional cases. Already in Fortran 77 there was a facility, which however was not used very much, to use a format variable (of type CHARACTER ) instead of a numbered format. The Format variable was put directly in the input/output statement. Now we will show three different ways of doing this assignment. They all have both good and bad sides. The program follows

     PROGRAM FORMAT

     IMPLICIT NONE

     REAL                         :: X

     CHARACTER (LEN=11)           :: FORM1

     CHARACTER (LEN=*), PARAMETER :: FORM2 = "( F12.3,A )"

     FORM1 = "( F12.3,A )"

     X = 12.0

     PRINT FORM1, X, ' HELLO '

     WRITE (*, FORM2) 2*X, ' HI '

     WRITE (*, "(F12.3,A )") 3*X, ' HI HI '

     END

In the PRINT statement we use the character string variable FORM1 with the length 11, which is assigned its value in an explicit assignment statement. The difficulty with this method is essentially that you have to count manually the number of characters, if it is too small the NAG compiler will not give a compilation error, but the error will show up at execution.

In the first WRITE statement we use instead a character string constant FORM2. The advantage is that with the PARAMETER statement it is not necessary to give an explicit length of the constant, but it can be given the length with the statement LEN=*. The bad thing is that we can not assign the constant a new value.

In the second WRITE statement we use directly an explicit character string. The difficulty is that the string can not be reused.

Exercises

(4.1) What does this statement give as its output?

     WRITE(*, "( HI )") 

Solution.

(4.2) What does the following statement perform?


     CHARACTER (LEN=9)      :: FILIP

     FILIP = '(1PG14.6)'

     WRITE(*,FILIP) 0.001, 1.0, 1000000.

Solution.


Last modified: 16 November 1995
boein@nsc.liu.se