Question about precision
From: Paul Van Delst (paul.vandelst_at_noaa.gov)
Date: 08/25/04
- Next message: Paul Van Delst: "Re: Question about precision"
- Previous message: Stanley Williams: "? Block Data in Lib File - F77"
- Next in thread: Paul Van Delst: "Re: Question about precision"
- Reply: Paul Van Delst: "Re: Question about precision"
- Reply: Keith Refson - real email address in signature: "Re: Question about precision"
- Reply: Mike Walters: "Re: Question about precision"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 25 Aug 2004 10:41:40 -0400
Hello,
Apologies if the subject line is a bit vague.
I have code where I need to interpolate several instrument response functions to the same
frequency grid and begin and end frequencies. The data I read in from file is at a set
spacing, 0.1cm^-1, but after computing that value from the begin and end frequency and the
number of points, the value is always something like 0.1000000000000002cm^-1. This has
caused problems since the extra 0.0000000000000002 makes a test that I use to ensure the
interpolation is alway within the actual data (extrapolation is a no-no here), fail. So,
what I've done is the following:
REAL( fp_kind ), DIMENSION( : ), ALLOCATABLE :: Begin_Frequency
REAL( fp_kind ), DIMENSION( : ), ALLOCATABLE :: End_Frequency
INTEGER, DIMENSION( : ), ALLOCATABLE :: n_Points
REAL( fp_kind ), DIMENSION( : ), ALLOCATABLE :: Max_Delta_Frequency
INTEGER :: dF_Exponent
INTEGER :: dF_Scaled
REAL( fp_kind ) :: dF_Multiplier
where fp_kind == Selected_Real_Kind(15) and all the allocatable arrays have been allocated
to the same size and filled with data and Max_Delta_Frequency is computed using,
Max_Delta_Frequency = ( End_Frequency - Begin_Frequency ) / &
! -----------------------------------
REAL( n_Points - 1, fp_kind )
At this point I get the 0.1000000000000002 value. To ensure I get the
0.1000000000000000cm^-1 I want (printing out to 16dp), I do the following, looping over
every element of Max_Delta_Frequency using the loop index, l,
dF_Exponent = INT( ABS( LOG10( Max_Delta_Frequency(l) ) ) ) + 2
dF_Multiplier = TEN**dF_Exponent
dF_Scaled = INT( Max_Delta_Frequency(l) * dF_Multiplier )
Max_Delta_Frequency(l) = REAL( dF_Scaled, fp_Kind ) / dF_Multiplier
Is there a simpler way of "truncating" the 0.0000000000000002 from the number? When I
compute the actual frequency grid (Frequency array), the last frequency is
695.1000000000001cm-1 rather than the expected 695.1000000000000 (the "End_Frequency").
This is causing the test in the interpolation function
IF ( Frequency(1) < SRF%Begin_Frequency .OR. &
Frequency(n_Frequencies) > SRF%End_Frequency ) THEN
to fail. Printing out the values
print *, Frequency(1), Frequency(n_Frequencies)
print *, SRF%Begin_Frequency, SRF%End_Frequency
gives
665.1000000000000 695.1000000000001
663.7000000000000 695.1000000000000
Is there a
- Next message: Paul Van Delst: "Re: Question about precision"
- Previous message: Stanley Williams: "? Block Data in Lib File - F77"
- Next in thread: Paul Van Delst: "Re: Question about precision"
- Reply: Paul Van Delst: "Re: Question about precision"
- Reply: Keith Refson - real email address in signature: "Re: Question about precision"
- Reply: Mike Walters: "Re: Question about precision"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|