****************************************************************************** BSW Electronic Mail 03-Nov-1997 18:06:11 CET Message Number 0018 ****************************************************************************** Author: James Johnson Subject: Re: linux problem - BAD MATH WITH OPTIMIZER Dear Bernese users: > Independent from the f2c problems mentionned in mail No 15, I have > encountered another problem with Bernese running under Linux. > The conversion from session/year to GPSweek/Dayofweek while using > the BPE is incorrect and this only for Sundays. > For example : > Saturday 144/97 gives GPSweek 906/6 (correct) > Sunday 145/97 gives GPSweek 906/7 (incorrect) should be 907/0 > Monday 146/97 gives GPSweek 907/1 (correct) > When I had a closer look at the BPE files, I saw that the HDR files > have already the incorrect values, the same for datapanel DAT151__.PAN > is the GPSTEMP directory. > > Has someone experienced similar problems? > Information about which routines compose the information in the HDR files > (or DAT151__.PAN) is also very usefull. This is exactly the problem that is seen when Bernese is compiled with a version of fort77 that uses the -ffast-math option when the optimizer is turned on (as mentioned in Mail No. 15). The fort77 is a script that emulates the behavior of f77 in such a way as to make the use of the FORTRAN to C conversion transparent to the user. In most cases, /usr/bin/f77 is a link to this script (or at least a copy if it). The version of fort77 that comes with RedHat 4.2 does this, it is version: [jjohnson@izu jjohnson]$ f77 -v /usr/bin/f77: fort77 Version 1.14a /usr/bin/f77: No input files specified If Bernese is compiled with the -ffast-math option, then the calculation of the GPS week can be incorrect at times. This has been traced to a division of two double precision values whose result is cast to an integer value in the subroutine $LA/MJDGPS.f: C DAYS SINCE STARTING EPOCH OF GPS WEEKS (SUNDAY 06-JAN-80) DELTAT=TJUL-44244.D0 C CURRENT GPS WEEK NWEEK=DELTAT/7.D0 C SECONDS PAST MIDNIGHT OF LAST WEEKEND SECOND=(DELTAT-(NWEEK)*7.D0)*86400.D0 With the -ffast-math option, expressions such as DELTAT/7.D0 seems to suffer from round-off error such that the integer NWEEK is 1 less than what you would expect. This is a little too fast! Here is what to do about it: (1) Don't use -O at all. This is the safest way. (2) Turn off -ffast-math with the compile option -fnofast-math. Here are the compile commands that I use: $X/EXE/CLPGM: "LINUX" ) f77 -o $F $F.f -L$C/LIB ${LIBRARIES} -O2 -fnofast-math $X/EXE/CMPLIB: "LINUX" ) f77 -I${INCL} -c ${F}.f -O2 -fnofast-math [Mailed from: jjohnson@unavco.ucar.edu (James Johnson)]