Thank your responses!
According to your ideas, I have resolved this question.
Firstly add new line in my SNL file:
%%#include "math.h"
Secondly change the variables' definition.
float temp;
double da;
float r1;
float r2;
Also there are some changes in state set.
ss test123{
state calctest
{
when(delay(2))
{
r1=1.0;
r2=2.0;
temp=fabs(r1-r2);
printf("fabs: %f\n",temp);
da=exp(r1+r2);
printf("exp: %lf\n", da);
} state calctest
}
}
When I done these modification, and tested it. I got the right result.
---------------------------------------
: [email protected] [mailto:[email protected]] Dirk
Zimoch
: 2011.5.11. 14:31
: Kotturi, Dayle
: [email protected]
: Re: Calculation in SNL/SEQ
Kotturi, Dayle wrote:
> Having just learned about pVar pointer from my colleague Kukhee Kim, I can
also offer that,
> in addition to adding '%%#include "math.h"' and prepending lines with c
function calls with '%%',
> you may also need to help the escaped c code access the SNL variables via
the pVar pointer.
>
> r1=1.0;
> r2=2.0;
> %%pVar->temp=fabs(pVar->r1-pVar->r2);
> printf("fabs: %lf\n",temp);
> %%pVar->temp=exp(pVar->r1+pVar->r2);
> printf("exp: %lf\n", temp);
>
> Without the 'pVar->', you may see these errors:
> error: `temp' undeclared (first use in this function)
> error: `r1' undeclared (first use in this function)
> error: `r2' undeclared (first use in this function)
>
This depends on the +/-r flag. In reentrant mode, all "global variables"
are localized by putting them into a pVar structure.
It is more portable not to access SNL variables from within %%. If
necessary write your own wrapper function within %{...}%, call the
function *without* %% and pass all necessary SNL variables as parameters.
Dirk
> Dayle
>
> On May 10, 2011, at 8:26 PM, Chestnut, Ronald P. wrote:
>
>> 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/>
>> ===================================
>>
>>
>>
>
>
>
- References:
- Re: Calculation in SNL/SEQ Dirk Zimoch
- Navigate by Date:
- Prev:
RE: Area Detector Mark Rivers
- Next:
Pro-Dex OMS MAXv card reading limit-switches junkes
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
<2011>
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: Calculation in SNL/SEQ Dirk Zimoch
- Next:
Re: Calculation in SNL/SEQ Dirk Zimoch
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
<2011>
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|