Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Can gfortran has the function of define the precision of whole program?
In IVF compiler "!DEC$ REAL:8" can define all real value having
attribute of real(8). SO, you have not to wirte (8) very time in the
following.

Can gfortran has the same function(to change default kind by one
command) and how can I do it?


Report this thread to moderator Post Follow-up to this message
Old Post
li.simula@gmail.com
08-21-07 09:33 AM


Re: Can gfortran has the function of define the precision of whole program?
On 21 aug, 09:56, li.sim...@gmail.com wrote:
> In IVF compiler "!DEC$ REAL:8" can define all real value having
> attribute of real(8). SO, you have not to wirte (8) very time in the
> following.
>
> Can gfortran has the same function(to change default kind by one
> command) and how can I do it?

It has that option: -fdefault-real-8

But why would you want to do that? It makes your program rely on
parameters outside the source code. While that is almost
inevitable, it seems to me very bad style not to be able
to see from the source code whether single or double precision
is to be used.

What if you encounter a compiler that has no such option?

I would recommend using a construction like:

use precision
...
real(wp) :: x
...

where the module precision defines the working precision "wp"
like:

integer, parameter :: wp = kind(1.0d0)

or something like that.

It then is a matter of redefining wp to switch to another
precision.

Regards,

Arjen



Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
08-21-07 09:33 AM


Re: Can gfortran has the function of define the precision of whole program?
> But why would you want to do that? It makes your program rely on
> parameters outside the source code. While that is almost
> inevitable, it seems to me very bad style not to be able
> to see from the source code whether single or double precision
> is to be used.

Thanks! Your method is a good choice. However, you must write a
additional "wp" with every real, such as 100.0_wp,25.0wp.....it's a
little inconvenient. If you use "!DEC$ REAL:8" or "-fdefault-
real-8",you can directly write 100.,25. So, very good! And if you want
use real(4),just define it at where you want(it overwrite the "!DEC$
REAL:8)

So, I think it is easy of the method which I mentiond (the only
problem is perhaps it is not easy for compatible with diffrent
operating system. So I ask...).


Report this thread to moderator Post Follow-up to this message
Old Post
li.simula@gmail.com
08-21-07 01:06 PM


Re: Can gfortran has the function of define the precision of whole program?
On 21 aug, 12:11, li.sim...@gmail.com wrote: 
>
> Thanks! Your method is a good choice. However, you must write a
> additional "wp" with every real, such as 100.0_wp,25.0wp.....it's a
> little inconvenient. If you use "!DEC$ REAL:8" or "-fdefault-
> real-8",you can directly write 100.,25. So, very good! And if you want
> use real(4),just define it at where you want(it overwrite the "!DEC$
> REAL:8)
>
> So, I think it is easy of the method which I mentiond (the only
> problem is perhaps it is not easy for compatible with diffrent
> operating system. So I ask...).

Well, real(4) is compiler-dependent too. Not all compilers will
use the kind number 4 to indicate ordinary single-precision
reals. Which is why it is unwise to rely on this notation.

And, yes, it is true that any literal number must be decorated
then with _wp.

Hm, you _could_ combine Glen's solution and mine:

implicit real(wp) a-h,o-z

and leave out declarations that would be covered by the
above statement.

Regards,

Arjen


Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
08-21-07 01:06 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:16 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.