Silverfrost Forums

Welcome to our forums

List-directed output

7 Aug 2019 10:44 #24162

Is it possible to provide a character variable to the FMT qualifier in a WRITE statement so that the default format (i.e., list-directed) output is used? To illustrate, I want to perform:

Write (Unit=*, Fmt=*) i

but as something like the following (which generates and error message):

cfmt = '*'
Write (Unit=*, Fmt=cfmt) i

The following also generates an error:

cfmt = '(*)'
8 Aug 2019 12:05 #24163

I don't see why you want to do that, but here is a way around the restriction that '*' is not an acceptable format string:

if (cfmt == '*') then
   Write (Unit=*, Fmt=*) i
else
   Write (Unit=*, Fmt=cfmt) i
endif

There are many places in Fortran where '' stands for 'default', 'acceptable subset', etc., but the '' cannot be replaced by a string variable whose value is '', because the '' has to be seen at compile time.

Similarly, in the Write statement above, the first * appears in a place where an integer value or integer variable can be present. However, one cannot write

iunit=*
Write (Unit=iunit,...)
8 Aug 2019 6:27 #24171

The reason I want to be able to use something like cfmt='*' is because I have hundreds of lines of output code. Sometimes I want to be able to output using a specific format, and other times I am content simply with whatever the list-directed output provides. I will have to duplicate all those hundreds of lines if I have to use the 'If ... Else' structure. It would be much easier to manage the code, including making modifications to the output, if I had only one set of Write statements to deal with.

Please login to reply.