View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 268
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
simon
Joined: 05 Jul 2006 Posts: 268
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
John-Silver
![](http://i.postimg.cc/K8HMTnXq/Bart-Unrivalled-Native-Plotting256.jpg)
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Sat Aug 10, 2019 10:18 pm Post subject: |
|
|
couldn't you write a Function/Subroutine to do the write where all the options for the write depending on values of unit and cfmt are inout and all the IF ELSE's (or CASE maybe better ?) are contained in that function, an ìd then just CALL that function sher you curntly have the WRITE statement ?
Thus confining management to that ingle function. _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|