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 

WRITE - Format of REALs

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



Joined: 28 Jul 2017
Posts: 69

PostPosted: Mon Sep 11, 2017 6:31 pm    Post subject: WRITE - Format of REALs Reply with quote

Hello, everyone,

Is there a way to get 0.296296238899 to be displayed as 2.962E-1 instead of 0.296E+00

What I'm using now is
Code:
WRITE(*,'(E10.3)')0.296296238899


Thanks!
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Mon Sep 11, 2017 6:40 pm    Post subject: Reply with quote

Use ES10.3 instead of E10.3 in the format. Note also that the literal constant that you showed has far more digits than can be represented in a single-precision real (between 7 and 8 significant digits).
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Mon Sep 11, 2017 7:02 pm    Post subject: Reply with quote

Thanks, mecej4.

All REAL variables in my program are of double precision.

But in some cases (as this one), 3 displayed digits after the decimal point are enough. Technically, this specific variable needn't be double, but I refrain from using different KINDs so I don't get them mixed up somewhere along the way.
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Mon Sep 11, 2017 8:54 pm    Post subject: Reply with quote

Is there also a way to exclude trailing zeros?
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Mon Sep 11, 2017 9:21 pm    Post subject: Re: Reply with quote

viroxa wrote:
All REAL variables in my program are of double precision.

Technically, this specific variable needn't be double, but I refrain from using different KINDs so I don't get them mixed up somewhere along the way.

There were no variables in the WRITE statement that you showed. You had a single-precision real constant. Whether other variables (in the parts of the program that you did not show) are double precision, integer, etc., is not at all relevant to the nature of the WRITE statement.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Mon Sep 11, 2017 9:30 pm    Post subject: Re: Reply with quote

viroxa wrote:
Is there also a way to exclude trailing zeros?

No, and there are good reasons why that should not be done. First of all, it is assumed that when the programmer specifies Ew.d, the number of digits to display after the decimal point is exactly d, not some number <= d. Secondly, when you see the string 3.1400, you know immediately that the number is not Pi. If you replace the 0s by blanks, the number could be Pi. See the problem? Thirdly, the output lines may be ugly because the decimal points in successive lines in a table printed under such a format would not be lined up.

That said, you can always use an internal write to a character string, replace zeros by blanks in that string, and then write the string. You take responsibility, not the Fortran runtime.
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Mon Sep 11, 2017 9:36 pm    Post subject: Reply with quote

Thanks! Now I see a little bit clearer again.
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