0

I am trying to print a long line of integer type variables.

If I do:

            print *,        tape_data(i)%ts%year, tape_data(i)%ts%month, tape_data(i)%ts%day, &
                            tape_data(i)%ts%hour, tape_data(i)%ts%minute, tape_data(i)%ts%second,  &
                            tape_data(i)%value1, tape_data(i)%value2

I get:

     2010           12           30           23            0            1 
   125550            1

If I do:

            print *,        tape_data(i)%ts%year, tape_data(i)%ts%month, tape_data(i)%ts%day, &
                            tape_data(i)%value1, tape_data(i)%value2

Then I get everything in the same line:

     2010           12           30       125550            1

So it seems like print adds a new line at a certain width.

Is that the case? If so, how can I put everything in the same line?

I am using flang and trying to use Fortran 95 (although I do not know how to enforce that in flang).

Note: as it has been asked a few times, I am using Fortran 95 because I want to learn that standard and have a couple of books I am following that cover that standard, once learnt I will probably move to the next one. I also like to understand differences between standards.

M.E.
  • 4,955
  • 4
  • 49
  • 128
  • 1
    print * leaves it up to the compiler it format the output as it wants, and it is free to do more or less anything. If you want control over the output format you have to provide a format string which describes precisely how the output will be laid out. Note I say format string - I would avoid using the format statement in modern code. There must be a duplicate here somewhere. – Ian Bush May 23 '21 at 16:05
  • I try this: `print(*,'I4 I2 I2 I2 I2 I2 I6 I6') tape_data(i)%ts%year, tape_data(i)%ts%month, tape_data(i)%ts%day, tape_data(i)%ts%hour, tape_data(i)%ts%minute, tape_data(i)%ts%second, tape_data(i)%value1, tape_data(i)%value2` and I get `F90-S-0034-Syntax error at or near * (file_parser.f95: 90)` – M.E. May 23 '21 at 16:19
  • I see, this is the right format: `write(*,'(I4xI2xI2xI2xI2xI2xI6xI6)')`. Still wondering about the actual difference between `print *,` and `write(*,FMT=)` – M.E. May 23 '21 at 16:26
  • 1
    Formats are normally written as comma separated lists – Ian Bush May 23 '21 at 16:26
  • 1
    The only difference between print and write is print always writes to what Unix calls standard out, while Write can also write to files. Stylistically I use print to indicate debugging lines I plan to delete before release, and write for "serious" output – Ian Bush May 23 '21 at 16:28
  • but if I try the same format with `print` instead of `write` I get `F90-S-0034-Syntax error at or near * (file_parser.f95: 90)` – M.E. May 23 '21 at 16:29
  • 1
    Sure, the syntax is slightly different. Write uses parentheses for the unit and the format, orint just takes the format without the parenthesis. print fmt, and write(*,FMT=fmt) is exactly the same. – Vladimir F Героям слава May 23 '21 at 17:33

0 Answers0