 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 299
|
Posted: Wed Aug 07, 2019 11:44 pm Post subject: List-directed output |
|
|
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:
Code: | Write (Unit=*, Fmt=*) i |
but as something like the following (which generates and error message):
Code: | cfmt = '*'
Write (Unit=*, Fmt=cfmt) i |
The following also generates an error:
|
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Thu Aug 08, 2019 1:05 am Post subject: |
|
|
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:
Code: | 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
Code: | iunit=*
Write (Unit=iunit,...)
|
|
|
Back to top |
|
 |
simon
Joined: 05 Jul 2006 Posts: 299
|
Posted: Thu Aug 08, 2019 7:27 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|