1

Here is my fortran 90 program

PROGRAM T2
IMPLICIT NONE

CHARACTER (len=20):: str = 'Testfile.dat'
INTEGER :: i,j

OPEN(UNIT=1, FILE=str, STATUS='REPLACE',ACTION='WRITE')
    DO i=0,9,1
        DO j=0,9,1
            WRITE(1,100) i+j
            100 FORMAT ('+',I10.1)
        END DO
            WRITE (1,110)
            110 FORMAT ('',/)
    END DO

END PROGRAM

I want output as

0 1 2 ...
1 2 3 ...

However I got the output in different format, in which each number is written on the separate line. Culprit is FORMAT statement. If I make these changes:

WRITE(1,100,ADVANCE='NO') i+j
100 FORMAT (1X,I10.1)

I get what I want. However, as per Chapman's book on Fortran, + is format modifier that continues the same line. But I did not get the output using that. Can anyone explain me why is so? Also, the book gives a lot of emphasis on first character on the FORMAT statement. Even when I write 100 FORMAT (1X,I10.1), there seems no effect of 1X in determining the spacing. Can anyone tell what is happening here?

Also, is there a way to decide 'auto width' of the output i+j in the program? Or do I have to write a FORMAT statement to specify width? I mean, we do not write any width separators in C++, it automatically decides width and places the output. Is there anything like that in fortran?

b2850624
  • 153
  • 1
  • 1
  • 6

0 Answers0