Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28808 Discussions

How to change list-directed format of WRITE

Isoshi
Beginner
1,455 Views

We have fortran program that is running on IBM AIX OS, which are written by Fortran77 format.  And we are developing them with Visual Studio 2019 to run the program on Windows OS. But we are having a problem using WRITE statement. It works different behavior between on IBM AIX and on Windows10. We'll show some examples below.

Please let me know how to change default list-directed format of WRITE statement.

 

(a)

Code:

write(6, *) A

Result:

On AIX, we get " 216".

But, on Windows, we get "       216"

 

(b)

Code:

write(6, E10.4) A

Result:

On AIX, we get " .8435E+07".

But, on Windows, we get "0.8435E+07"

Labels (1)
0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
1,445 Views

You cannot do that: list-directed output does not provide any way of controlling the details. That is precisely the reason fr using it: you want the output without fuss and want it in some convenient way, as appropriate for the variables. But with that you relinquish all control that you have with explicit formats.

The only solution is to use explicit formats, because they provide almost all control options that you want.

View solution in original post

4 Replies
Arjen_Markus
Honored Contributor I
1,446 Views

You cannot do that: list-directed output does not provide any way of controlling the details. That is precisely the reason fr using it: you want the output without fuss and want it in some convenient way, as appropriate for the variables. But with that you relinquish all control that you have with explicit formats.

The only solution is to use explicit formats, because they provide almost all control options that you want.

Isoshi
Beginner
1,431 Views

Thank you for your reply! I'll try another way.

0 Kudos
Steve_Lionel
Honored Contributor III
1,405 Views

Arjen is correct in that the Fortran standard leaves a lot up to the implementation for list-directed formatting, but there is a solution now for the first case and in the future for the second.

For the first case, where the Intel compiler adds more than one space for integers, add the compiler option "-assume noold_ldout_format".  You can also use -standard-semantics that includes this option. Example (from Windows):

D:\Projects>type t.f90
implicit none
integer :: a
a = 216
write (*,*) a
end
D:\Projects>ifx /nologo t.f90

D:\Projects>t.exe
         216
D:\Projects>ifx /nologo /assume:noold_ldout_format t.f90

D:\Projects>t.exe
 216

 For the second case, Fortran 2018 makes the leading zero optional for D, E, F and G formats - some compilers put it in, some don't. Fortran 2023, the next standard revision (to be published later this year), gives you control over this with a new LEADING_ZERO= keyword in the OPEN statement (as well as three new format edit descriptors.)  In the future, when this feature gets implemented, you would be able to open your output file with LEADING_ZERO='SUPPRESS' and have the zero omitted.

Isoshi
Beginner
1,361 Views

The compiler option "-assume noold_ldout_format" works, and I can get what I want about case (a)! Thank you very much!

0 Kudos
Reply