CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

double precision assigning in FRTRAN

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 27, 2001, 13:04
Default double precision assigning in FRTRAN
  #1
R.A.Khurram
Guest
 
Posts: n/a
Dear friends I am working in error analysis of a new stabalized scheme for Darcy Flow problem. I am facing some problem in assigning a double precision. I am using fortran powerstation. i am using implicit*8 command. it is working fine but for the folowing cases it is taking a single precision data; 1)Function Return 2)Assignment of a Double Precision number to a variable. e.g. real*8 a a=0.1234567891234567 write(*,*) a It gives an answer accurate upto single precision. 3)Data command e.g real*8 b data b /0.1234567891234567/ gives the value in single precission.

This is spoiling the overall accuracy of my simulations. I can redesign my code and avoid these three cases by use of subroutine or reading data from a file(which gives double precision data) but i want to know any command(which i believe must be present in fortran).

I appreciate your help
  Reply With Quote

Old   September 27, 2001, 15:07
Default Re: double precision assigning in FRTRAN
  #2
John C. Chien
Guest
 
Posts: n/a
(1). 1.23...D-1 (2). IMPLICIT REAL*8 (A-H,O-Z) at the begining of every subroutines and functions, including the main program.
  Reply With Quote

Old   September 27, 2001, 15:21
Default Re: double precision assigning in FRTRAN
  #3
R.A.Khurram
Guest
 
Posts: n/a
Thanks Chien

1)i do not understand first part of the answer. 2)i have used implicit real*8 in all he subrouines and the main program. But the compiler does not allow me to define the value of the function in double precision e.g

FUNCION F(X) IMPLICIT REAL*8(a:h,o:z) F=X**2 RETURN END

COMMENT: THIS PROGRAM GIVES ERROR. IT CAN NOT ALLOW VARAIBLE F TO BE DEFINED IN THIS MANNER

Thanks for your advice. Looking forward to have more suggestions
  Reply With Quote

Old   September 27, 2001, 15:33
Default Re: double precision assigning in FRTRAN
  #4
John C. Chien
Guest
 
Posts: n/a
(1). Try to add another line after the implicit real*8 (a-h,o-z), REAL*8 F, X . Based on the sample in my book.
  Reply With Quote

Old   September 27, 2001, 15:51
Default Re: double precision assigning in FRTRAN
  #5
John C. Chien
Guest
 
Posts: n/a
(1). Use double precision form of a floating point variable will make sure that it is a double precision variable. (2). Why not use formatted I/O instead of Write(*,*)? In this way, you can control the output. (*,*) normally will print out results in single precision format.
  Reply With Quote

Old   September 27, 2001, 15:54
Default Re: double precision assigning in FRTRAN
  #6
R.A.Khurram
Guest
 
Posts: n/a
Chien

1)Fortran power station does not allow me to use both of these commands.2)I can replace a function by a subroutine and i have done so successfully and gotresults in double precision 3)But my mail problem is assigning a double precision value to a variable. See example;

Real*8 a a=0.1234567891234567 !16 digits print*, a end

OUTPUT of PROGRAM: 0.12345678 !single precison Comment: I was able to get double precison when iwrote the numbers in a seperate file and read and print it in the main program. BUT i can not do it for all the assignments in my program! Same is the problem with asigning array of numbers in DATA comand.

Thanks for your help
  Reply With Quote

Old   September 27, 2001, 16:10
Default Re: double precision assigning in FRTRAN
  #7
Mr. Question
Guest
 
Posts: n/a
------------------------------------------

program junk

double precision A

A=0.1234567891234567

write(*,5)A

5 format(f20.18)

end -----------------------------------------

>>f77 junk.f
:>a.out 0.123456789123456701
  Reply With Quote

Old   September 27, 2001, 19:13
Default Re: double precision assigning in FRTRAN
  #8
R.A.Khurram
Guest
 
Posts: n/a
Dear MR QUESTION

My computer is still giving the answer in single precison.

i got this answer in FORTRAN POWERSTATION

0.123456791043281600

*********** -> Garbage I think this is a compiler problem. Do you have any idea how to fix it. Is there any option in powersation to select the precsion level?
  Reply With Quote

Old   September 27, 2001, 20:38
Default Re: double precision assigning in FRTRAN
  #9
John C. Chien
Guest
 
Posts: n/a
(1). After a=0.1234567891234567, add three lines of code, itrue=0, if ( a .eq. 0.1234567891234567 ) itrue=1, write(*,*) itrue. (2). In this way, you can tell whether a is identical to 0.1234567891234567 or not.
  Reply With Quote

Old   September 28, 2001, 01:48
Default Re: double precision assigning in FRTRAN
  #10
Markus Lummer
Guest
 
Posts: n/a
Try

real*8 a

a = 0.1234567891234567D+00

Hope this helps.

Best regards

Markus

  Reply With Quote

Old   September 28, 2001, 09:57
Default Re: double precision assigning in FRTRAN
  #11
Mr. Question
Guest
 
Posts: n/a
This link is support for precision, specific to your compiler.

http://support.microsoft.com/support.../Q125/0/56.ASP
  Reply With Quote

Old   September 28, 2001, 11:46
Default Re: double precision assigning in FRTRAN
  #12
Dean
Guest
 
Posts: n/a
Double precision can be tricky. Markus is correct in pointing out that you should use d+00 at the end of literals. I.e., 0.12d+00 instead of 0.12. Also, it seems I heard someplace that real*8 is not a good idea with some compilers, use

double precision a

instead of real*8 a. The problem with the function returning single precision can be fixed by using

double precision function x(a)

as the first line of the function rather than

function x(a)

It has been my experience that using switches on the compiler to convert stuff to double precision doesn't always work the way you expect. It is best to tell the compiler explicitly what you want it to do.

Hope this helps.
  Reply With Quote

Old   October 2, 2001, 11:00
Default Re: double precision assigning in FRTRAN
  #13
R.A.Khurram
Guest
 
Posts: n/a
Dean, Markus, MR. ?,John C. Chien

Thanks.

The problem has been solved with your help. For the benifit of other friends I want to give its solution. 1)In Fortran Powerstation, assigning a double precision number is done by adding d0 at the end of the number e.g. x=0.1234567891234567d0 (not as x=0.1234567891234567) 2)Similarly numbers in the data array need to be difined in a similar fashion data a \0.1234567891234567d0\ 3)Function need to be defined(as you suggested) as; Double precision F(x) real*8 x f=x**2 return end //Main Program Real*8 f,y y=0.1234567891234567d0 print*, y,f(y) end

Note: I do not found any difference in Double precision and real*8 command.

Thank you guys. I will be needing more of your help

R.A Khurram UIC
  Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Continuing User Defined Real Gas Model issues aeroman FLUENT 6 April 8, 2016 03:34
Parallel User Defined Real Gas Model aeroman FLUENT 4 July 1, 2015 06:09
Missing math.h header Travis FLUENT 4 January 15, 2009 11:48
what's wrong about my code for 2d burgers equation morxio Main CFD Forum 3 April 27, 2007 10:38
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23


All times are GMT -4. The time now is 22:04.