forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

List-directed output

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Wed Aug 07, 2019 11:44 pm    Post subject: List-directed output Reply with quote

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:
Code:
cfmt = '(*)'
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Thu Aug 08, 2019 1:05 am    Post subject: Reply with quote

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
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Thu Aug 08, 2019 7:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Sat Aug 10, 2019 10:18 pm    Post subject: Reply with quote

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 ... Smile "
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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