[Thread Prev][Thread Next][Index]

[ferret_users] differences in conversion of real*4 constants



Dear Ferret users

please try the attached script, which demonstrates that the conversion of float constants may give different results (here using explicit constants an/or the `xa` syntax in definitions of axes). The deviations are small, but definitely larger than is to be expected for real*4 (with a 24 bit mantissa the 7th digit may change, but not the 6th digit). I am wondering how that could happen. It is clear, that a constant assigned to a variable by let is converted into real*4 accuracy. I would assume that the same conversion is done if the constants are specified explicitly in the axis definition because they are assinged to internal buffers. Listing the same constants with Fortran shows, that def_1 is right since no changes appear up to the 7th digit. Thus the conversions by `xa` etc. seem to give erroneous results. Couls that be fixed, please?

Best regards

Torsten

--
Dr. Torsten Seifert
Leibniz-Institut für Ostseeforschung
(Baltic Sea Research Institute)
Seestrasse 15
D-18119 Rostock
Tel. +49 381 5197 118
Fax  +49 381 5197 4812
! sample script to show different conversion of real*4 constants

! def_0: define axes with predefined constants
let nx=577; let ny=257;
let xa=-5.00081; let xe=31.2892
let ya=51.8717;  let ye=68.0006
def axis/x=`xa`:`xe`/npoints=`nx`/units="degrees_east"  xax0
def axis/y=`ya`:`ye`/npoints=`ny`/units="degrees_north" yax0

! def_1: define NOT THE SAME axis with the same explicit constants 
def axis/x=-5.00081:31.2892/npoints=577/units=degrees_east xax1
def axis/y=51.8717:68.0006/npoints=257/units=degrees_north yax1

! def_2: define SAME axis with corrected explicit constants
def axis/x=-5.00080:31.28900/npoints=577/units=degrees_east  xax2
def axis/y=51.87200:68.00100/npoints=257/units=degrees_north yax2

! show systematic deviation of def_1 (xax1,yax1)
! def_2 = def_0 within real*4 accuracy
set view upper; plot x[gx=xax0]-x[gx=xax1], x[gx=xax0]-x[gx=xax2]
set view lower; plot y[gy=yax0]-y[gy=yax1], y[gy=yax0]-y[gy=yax2]

! list prescribed constants with real*4 accuracy
list/prec=7 xa,xe,ya,ye

! show how constants are converted by `xa` etc.
! this explains why def_1 != def_0, but def_2 = def_0
! differences to list/prec=6 xa,xe,ya,ye exceed real*4 accuracy !?
list/prec=7 `xa`,`xe`,`ya`,`ye`

! this list shows that the axes start with exactly the explicit constants
! and are therefore different from def_0
list/prec=7/i=1:5 x[gx=xax0],x[gx=xax1],x[gx=xax2],x[gx=xax0]-x[gx=xax1]
list/prec=7/j=1:5 y[gy=yax0],y[gy=yax1],y[gy=yax2],y[gy=yax0]-y[gy=yax1]
      program real4_conversion

      xa=-5.00081
      xe=31.2892
      ya=51.8717
      ye=68.0006
      
      write(*,'(4f11.5)') -5.00081,31.2892,51.8717,68.0006
      write(*,'(4f11.6)') -5.00081,31.2892,51.8717,68.0006
      write(*,'(4f11.5)') xa,xe,ya,ye
      write(*,'(4f11.6)') xa,xe,ya,ye
      
      stop
      end
      

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement