CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   FORTRAN variable declaration (https://www.cfd-online.com/Forums/main/10129-fortran-variable-declaration.html)

sriram October 20, 2005 11:44

FORTRAN variable declaration
 
HI ALL,

I have written a simulation code in matlab,its working perfectly. Now, I tried to convert it into fortran.For the first time step, both the codes produce the same results. But as the time step increases, the fortran code evaluation is on lower side than that of matlab, this is due to the variable declaration in fortran. For example, i explicitly find out in incrementing the timestep(TI),assuming DT = 0.01 if i evaluated at the 6th time step using (TI=TI+DT) its showing 5.99999e-2. but it should be 0.06. But in Matlab its doing correctly. I hope, similar problem is exist throughout the code in variable declaration.I declared the variable as REAL,I need the code to estimate only FOUR DECIMAL places at every time step. If any one there to help me out in this problem.

Thanks!

-sriram-


agg October 20, 2005 12:28

Re: FORTRAN variable declaration
 
Try running your simulation in double precision.

Jeff Moder October 21, 2005 13:21

Re: FORTRAN variable declaration
 
Floating point numbers (real numbers) are represented as base 2 (binary) fractions in computer hardware. Just because matlab if DISPLAYING 0.06 does not mean it is actually represented exactly as 0.06 when matlab is running. If you only want to see 4 decimal places of accuracy in the output of your Fortran program, then use the format '(ES12.4)'. For the time step you are using (DT=0.01), I personally think single precision is fine, but it is always a good idea to see if running in double precision has a significant effect (judged by you) on your results.

If you want a more information of floating point representation in computer hardware, I think the following is a very nice explanation:

http://docs.python.org/tut/node16.html

(The basic ideas discussed are independent of the computer language).


Vinod Dhiman October 22, 2005 06:08

Re: FORTRAN variable declaration
 
Hi

Yes, Jeff is right. Double Precision is really not going to help you. Even that will show 0.0599999 or 0.0600001 or something like that. Either change the format as Jeff suggested or use a different compiler. Changing the compiler may work out.

Vinod Dhiman


All times are GMT -4. The time now is 15:21.