Dear Liuping,
You have to include the math libraries, as you would for a simple "C" program.
If SNL doesn't parse the libraries correctly, escape them and their use with %%.
%%include math.h
%%temp=fabs(r1-r2);
Ron
On May 10, 2011, at 7:35 PM, liuping wrote:
Hello,
I need your help about the calculation in SNL/SEQ.
In my SNL/SEQ application, I need to execute the mathematical operation: fabs() and exp().
Here is the codes abstracted from the my application:
%%/////////////////////
double temp;
double err;
double r1;
double r2;
ss test123{
state calctest
{
when(delay(2))
{
r1=1.0;
r2=2.0;
temp=fabs(r1-r2);
printf("fabs: %lf\n",temp);
temp=exp(r1+r2);
printf("exp: %lf\n", temp);
} state calctest
}
}
%%//////////////////////////
The operation result is:
fabs: 1.000000
exp: 2287528.000000
fabs: 1.000000
exp: 2287528.000000
fabs: 1.000000
exp: 2287528.000000
……
Obviously, the result of “fabs” is right, and the other is wrong. Then I check the output of compiler. There are two warning and no error (see the bold and incline words).
.....
make[3]: Entering directory `/home/blctrl/watercool-Mono/motorApp/OmsSrc/O.vxWorks-ppc604_long'
converting ../sncExample.stt
/home/blctrl/seq-2.0.11/bin/linux-x86/snc ../sncExample.stt -o sncExample.c.tmp
mv sncExample.c.tmp sncExample.c
/BLC/epics/Tornado2.2/host/x86-linux/bin/ccppc -c -D_POSIX_SOURCE -DCPU=PPC604 -DvxWorks -include /BLC/epics/Tornado2.2/target/h/vxWorks.h -ansi -O3 -Wall -mcpu=604 -mstrict-align -mlongcall -fno-builtin -I. -I.. -I../../../include/os/vxWorks -I../../../include -I/home/blctrl/asyn4-8/include/os/vxWorks -I/home/blctrl/asyn4-8/include -I/home/blctrl/seq-2.0.11/include/os/vxWorks -I/home/blctrl/seq-2.0.11/include -I/BLC/epics/base/include/os/vxWorks -I/BLC/epics/base/include -I/BLC/epics/Tornado2.2/target/h sncExample.c
../sncExample.stt: In function `A_test123_calctest':
../sncExample.stt:38: warning: implicit declaration of function `fabs'
../sncExample.stt:40: warning: implicit declaration of function `exp'
perl /BLC/epics/base/bin/linux-x86/registerRecordDeviceDriver.pl ../O.Common/omsMAXv.dbd omsMAXv_registerRecordDeviceDriver > temp.cpp
mv temp.cpp omsMAXv_registerRecordDeviceDriver.cpp
.....
Again, I tried to do such process:
1)Power off the VME rack,
2)Change the value of r1 and r2: r1=9.0; r2=12.0;
3)make clean
4)make
5)Power on the VME rack
Sadly I saw the result was same to last test:
fabs: 1.000000
exp: 2287528.000000
fabs: 1.000000
exp: 2287528.000000
fabs: 1.000000
exp: 2287528.000000
……
The result of “fabs” and “exp” are both wrong. Who can tell me the reason and how to get the right result?
Any advices are appreciated!
===================================
LIU Ping
Beamline Control Group
Shanghai Synchrotron Radiation Facility
Shanghai Institute of Applied Physics
Chinese Academy of Sciences
Zhangheng Rd 239,Pudong Dist.,
Shanghai 201204
China
Tel:+86-21-33933237(Lab)
http://ssrf.sinap.ac.cn<http://ssrf.sinap.ac.cn/>
===================================